From Adrian.Baetu at plato-ag.com Tue Nov 2 17:51:27 2010 From: Adrian.Baetu at plato-ag.com (AdrianB) Date: Tue, 2 Nov 2010 16:51:27 +0000 (UTC) Subject: [C++-sig] boost::python executes wrong implementation Message-ID: Hello The Situation: There are three modules involved: a) myapi.pyd b) myapi.dll c) myserver.dll myapi is a VC++ Project which exposes few classes and methods to python. myapi.pyd is a UNICODE build, to be used in python. myapi.dll is a ANSI build, to be used embedded by the myserver.dll myserver.dll runs python embedded, and links myapi.dll UseCase in Python: # ------------------ import myapi # myapi.pyd session = myapi.Session( ) # myapi.pyd::Session # at this moment myserver.dll gets loaded into the python process # along with its embedded python module, called "myembedded" import myembedded # myserver.dll embedded_session = myembedded.Session() # myapi.dll::Session #!! The ISSUE !! embedded_session.myEmbeddedImpl() # should call myapi.dll::Session::myEmbeddedImpl() # -- what happens? -- instead of executing myapi.dll::Session::myEmbeddedImpl() it executes myapi.pyd::Session::myEmbeddedImpl()!!! Why? And how can I avoid this? Anny idea and help is greatly appreciated, best regards, Adrian From nat at lindenlab.com Tue Nov 2 18:04:08 2010 From: nat at lindenlab.com (Nat Linden) Date: Tue, 2 Nov 2010 13:04:08 -0400 Subject: [C++-sig] boost::python executes wrong implementation In-Reply-To: References: Message-ID: On Tue, Nov 2, 2010 at 12:51 PM, AdrianB wrote: import myembedded # myserver.dll > embedded_session = myembedded.Session() # myapi.dll::Session > > #!! The ISSUE !! > embedded_session.myEmbeddedImpl() > # should call myapi.dll::Session::myEmbeddedImpl() > > # -- what happens? -- > instead of executing > myapi.dll::Session::myEmbeddedImpl() > it executes > myapi.pyd::Session::myEmbeddedImpl()!!! > > Why? And how can I avoid this? > Try renaming myapi.dll to myotherapi.dll, or some renaming like that? Since myapi.pyd *is* a .dll file, my guess is that the OS loader thinks: since we've already loaded myapi.pyd, there's no need to load a file called myapi.dll. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simwarg at gmail.com Tue Nov 2 19:04:32 2010 From: simwarg at gmail.com (Simon W) Date: Tue, 2 Nov 2010 19:04:32 +0100 Subject: [C++-sig] Reference count on class object and import() In-Reply-To: References: Message-ID: Alright, it was a couple of days ago since I last had a look on this and it turns out that issue described in my first mail still persists. Although I had a typo. Swap 4 with 3 on the reference count. Also, when Im using PyImport_Import() directly it also shows 2 reference counts? On Tue, Oct 26, 2010 at 11:29 PM, Simon W wrote: > Of course, I did find another reference that I didn't notice. Python > reference works as expected .. hehe! > > > On Mon, Oct 25, 2010 at 7:35 PM, Simon W wrote: > >> Hey again, >> >> I'm trying to implement a load / unload module functionallity. When I >> delete the module in the __main__ dict the module's reference count is still >> > 1. I've been trying to find if I reference it anywhere else in my code but >> I can't find anything! When I did a check in vc++ debugger found something. >> When I run this code: >> >> object obj = import(name.c_str()); >> >> *obj*'s *ob_refcnt* member is 2 when I check in the vc++ debugger. >> Shouldn't it be 1? >> >> After that line, I put it in the __main__ dict like: >> >> mMainNamespace[ name.c_str() ] = obj; >> >> The reference count shows 4, as expected. >> >> When I'm entering my unload() function when I want to remove the module I >> do like: >> void unload() >> { >> object t = mMainNamespace[ name.c_str() ]; >> // reference count in t is now 4 ? >> >> mMainNamespace[ name.c_str() ].del(); // I delete but it's not >> unloaded properly because it's still referenced somewhere .. >> } >> >> What does import() do? It must save some reference somewhere? >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Tue Nov 2 19:34:14 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 02 Nov 2010 11:34:14 -0700 Subject: [C++-sig] Reference count on class object and import() In-Reply-To: References: Message-ID: <4CD059A6.3060606@gmail.com> On 11/02/2010 11:04 AM, Simon W wrote: > Alright, it was a couple of days ago since I last had a look on this and > it turns out that issue described in my first mail still persists. > Although I had a typo. Swap 4 with 3 on the reference count. Also, when > Im using PyImport_Import() directly it also shows 2 reference counts? > Python stores a global list of loaded modules, as a cache to speed up future imports. You can look them up in sys.modules, though I don't think trying to delete things from that list is allowed. To my knowledge, there is no way to unload a Python module, though one can of course force a reload. Jim From Adrian.Baetu at plato-ag.com Wed Nov 3 09:21:48 2010 From: Adrian.Baetu at plato-ag.com (AdrianB) Date: Wed, 3 Nov 2010 08:21:48 +0000 (UTC) Subject: [C++-sig] boost::python executes wrong implementation References: Message-ID: Nat Linden lindenlab.com> writes: > Try renaming myapi.dll ... thanks for the hint. my real life scenario uses: MY-API.DLL myapi.pyd sorry for not mentioning this <:o) best regards Adrian From charlessolar at gmail.com Wed Nov 3 15:22:46 2010 From: charlessolar at gmail.com (Charles Solar) Date: Wed, 3 Nov 2010 09:22:46 -0500 Subject: [C++-sig] Python iterable to std map Message-ID: I have a class interface I expose to python that has methods such as begin, end, rbegin, rend. Its meant to be a class that C++ can iterate over. I now want to make the object defined in python, so python can pass the C++ library an object of python's class and C++ can use it like it would any real C++ object derived from the same interface. Since python does not really have a concept of begin, end, rbegin, rend, I thought a good idea would be to have the python class define a __iter__ method and use that method with stl_input_iterator to pull in the complete list from python to use with begin, end, etc. What I have currently is a python converter for tuples of size 2 to std pairs, then the wrapper class for the interface calls > struct IFooHolder_wrapper : IFooHolder, bp::wrapper< IFooHolder > > { > mutable std::map< std::string, boost::shared_ptr< IFoo > > _map; > const_iterator begin() const > { > std::copy( bp::stl_input_iterator< std::pair< std::string, boost::shared_ptr< IFoo > > >( bp::object( bp::handle<>( bp::borrowed( bp::detail::wrapper_base_::get_owner(*this) ) ) ) ), bp::stl_input_iterator< std::pair< std::string, boost::shared_ptr< IFoo > > >(), std::inserter( _map, _map.begin() ) ); > return _map.begin(); > } to copy all the iterations into a map the wrapper holds. Then the begin, end, rbegin, rend methods return iterations from that map. My main concern is firstly if there is a better way. More elegant solutions like the map indexing suite do not really work on this problem, and google can only help so much. I fear there is not much documentation from others trying to do the same thing. I especially do not like "bp::object( bp::handle<>( bp::borrowed( bp::detail::wrapper_base_::get_owner(*this) ) ) )" >From my understanding of stl_input_iterator, it needs a bp::object that has an "__iter__" attribute. I want to use this->get_override( "__iter__" ) but that does not work. So if someone knows a better way to build a bp::object from a bp::wrapper class that would be a good start. I should mention my solution compiles but does not work. Python crashes when it tries to do the std::copy Thanks for any input -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyberaishu at gmail.com Fri Nov 5 10:35:07 2010 From: cyberaishu at gmail.com (Aishwarya Venkataraman) Date: Fri, 5 Nov 2010 02:35:07 -0700 Subject: [C++-sig] Unable to find -lboost_python Message-ID: Hello, I want to install pydoop to get python talk to hadoop/ hdfs file system. This requires me to have boost installed. I have installed boost using macports. python setup.py build_ext -L/opt/local/lib/ -I/opt/local/include/ When I run the above command to install pydoop, it gives me the following error: g++ -L/Applications/djangostack-1.2.3-0/common/lib -bundle -undefined dynamic_lookup build/temp.macosx-10.4-i386-2.6/src/pipes.o build/temp.macosx-10.4-i386-2.6/src/pipes_context.o build/temp.macosx-10.4-i386-2.6/src/pipes_test_support.o build/temp.macosx-10.4-i386-2.6/src/pipes_serial_utils.o build/temp.macosx-10.4-i386-2.6/src/exceptions.o build/temp.macosx-10.4-i386-2.6/src/_pipes_main.o build/temp.macosx-10.4-i386-2.6/src/SerialUtils.o build/temp.macosx-10.4-i386-2.6/src/HadoopPipes.o build/temp.macosx-10.4-i386-2.6/src/StringUtils.o -L/opt/local/lib/ -lpthread *-lboost_python* -o build/lib.macosx-10.4-i386-2.6/pydoop/_pipes.so *ld: library not found for -lboost_python* Where exactly is lboost_python located on a mac? How do I find this library ? Thanks, Aishwarya -------------- next part -------------- An HTML attachment was scrubbed... URL: From berthet at hi.is Fri Nov 5 11:48:51 2010 From: berthet at hi.is (Jean Claude Berthet) Date: Fri, 05 Nov 2010 10:48:51 +0000 Subject: [C++-sig] Unable to find -lboost_python In-Reply-To: References: Message-ID: <4CD3E113.2010606@hi.is> By default it is in /usr/local/lib/ but you may have to ask for to be compiled explicitly: ./bjam --with-python On 11/5/10 9:35 AM, Aishwarya Venkataraman wrote: > Hello, > > I want to install pydoop to get python talk to hadoop/ hdfs file > system. This requires me to have boost installed. I have installed > boost using macports. > > python setup.py build_ext -L/opt/local/lib/ -I/opt/local/include/ > > When I run the above command to install pydoop, it gives me the > following error: > > g++ -L/Applications/djangostack-1.2.3-0/common/lib -bundle -undefined > dynamic_lookup build/temp.macosx-10.4-i386-2.6/src/pipes.o > build/temp.macosx-10.4-i386-2.6/src/pipes_context.o > build/temp.macosx-10.4-i386-2.6/src/pipes_test_support.o > build/temp.macosx-10.4-i386-2.6/src/pipes_serial_utils.o > build/temp.macosx-10.4-i386-2.6/src/exceptions.o > build/temp.macosx-10.4-i386-2.6/src/_pipes_main.o > build/temp.macosx-10.4-i386-2.6/src/SerialUtils.o > build/temp.macosx-10.4-i386-2.6/src/HadoopPipes.o > build/temp.macosx-10.4-i386-2.6/src/StringUtils.o -L/opt/local/lib/ > -lpthread *-lboost_python* -o > build/lib.macosx-10.4-i386-2.6/pydoop/_pipes.so > *ld: library not found for -lboost_python* > > Where exactly is lboost_python located on a mac? How do I find this > library ? > > Thanks, > Aishwarya > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Fri Nov 5 15:42:16 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 05 Nov 2010 14:42:16 +0000 Subject: [C++-sig] 2 "using python" declarations in user-config.jam not working Message-ID: Hi, I can't get boost.build configured for 2 different python versions, of which one is a debug build. I follow the instructions here: http://www.boost.org/doc/libs/1_44_0/libs/python/doc/building.html My user-config.jam has entries like this # default python - this picks up a standard Ubuntu 2.6 install using python ; # debug python build - this picks up my debug build from source using python : 2.7 : /home/john/local/python-dbg/bin/python2.7 : : : on ; Unfortunately when I build my project bjam -q -j3 debug which is configured thus: project Proj : requirements debug:on : usage-requirements : default-build debug ; It uses a boost.python built against the default python. This libboost_python.so.1.44.0 has an undefined symbol PyUnicodeUCS4_AsUTF8String. If I comment out the line in user-config.jam using python ; so that all my builds use the debug 2.7 python it works ok but presumably then I have a problem with release builds. This looks like a bug to me. How am I supposed to configure this in user-config.jam? Thanks, John. From j.reid at mail.cryst.bbk.ac.uk Fri Nov 5 15:52:08 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 05 Nov 2010 14:52:08 +0000 Subject: [C++-sig] 2 "using python" declarations in user-config.jam not working In-Reply-To: References: Message-ID: On 05/11/10 14:42, John Reid wrote: > Hi, > > I can't get boost.build configured for 2 different python versions, of > which one is a debug build. I follow the instructions here: > http://www.boost.org/doc/libs/1_44_0/libs/python/doc/building.html > > My user-config.jam has entries like this > # default python - this picks up a standard Ubuntu 2.6 install > using python ; > > # debug python build - this picks up my debug build from source > using python : 2.7 : /home/john/local/python-dbg/bin/python2.7 > : > : > : on > ; > > > Unfortunately when I build my project > bjam -q -j3 debug > > which is configured thus: > project Proj > : requirements > debug:on > : usage-requirements > : default-build debug > ; > > It uses a boost.python built against the default python. This > libboost_python.so.1.44.0 has an undefined symbol > PyUnicodeUCS4_AsUTF8String. > > If I comment out the line in user-config.jam > using python ; > > so that all my builds use the debug 2.7 python it works ok but > presumably then I have a problem with release builds. > > This looks like a bug to me. How am I supposed to configure this in > user-config.jam? I have a work-around. If I always remember to put "python=2.7" for the debug builds as a bjam option it works ok. E.g.: bjamc -q -j3 -d+2 debug python=2.7 > > Thanks, > John. From Adrian.Baetu at plato-ag.com Mon Nov 8 10:34:41 2010 From: Adrian.Baetu at plato-ag.com (AdrianB) Date: Mon, 8 Nov 2010 09:34:41 +0000 (UTC) Subject: [C++-sig] boost::python executes wrong implementation References: Message-ID: HI, still hopeing somone could comme up with anny idea for: http://article.gmane.org/gmane.comp.python.c%2B%2B/15036 regards Adrian From simwarg at gmail.com Tue Nov 9 21:31:26 2010 From: simwarg at gmail.com (Simon W) Date: Tue, 9 Nov 2010 21:31:26 +0100 Subject: [C++-sig] Expose c++ class as python module Message-ID: Hi, I want to export my c++ class and make an instance of it and then expose it to python as if it were a python module. Is it possible? // export and create instance class_ [...]; namespace["instance"] = ptr( instanceOfMyClass ); Then in python: import instance instance.someFunction() Thank you! /Simon -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Tue Nov 9 22:09:33 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 09 Nov 2010 13:09:33 -0800 Subject: [C++-sig] Expose c++ class as python module In-Reply-To: References: Message-ID: <4CD9B88D.5070009@gmail.com> On 11/09/2010 12:31 PM, Simon W wrote: > Hi, > I want to export my c++ class and make an instance of it and then expose > it to python as if it were a python module. Is it possible? > > // export and create instance > class_ [...]; > > namespace["instance"] = ptr( instanceOfMyClass ); > > > Then in python: > > import instance > > instance.someFunction() > This is not possible to do directly, as boost::python::class_ makes a Python type object, and that's fundamentally different from a Python module object. You can simulate this by doing tricks on the Python side, however: - Make a regular Boost.Python module. - In your module-that-mimics-a-class (pure Python), instantiate your instance in Python as a hidden module-level variable. - Extract bound methods from the instance and assign them to module-level variables. Jim Bosch From josh.davidson at lmco.com Mon Nov 29 07:36:21 2010 From: josh.davidson at lmco.com (Davidson, Josh) Date: Sun, 28 Nov 2010 23:36:21 -0700 Subject: [C++-sig] pygccxml and inner classes Message-ID: <3602620DAE03994D80A0E6387C1A3B83B9F54870@HDXMSP8.us.lmco.com> I'm wondering if this behavior is correct when using pygccxml. Consider the following two sets of simple class definitions: -------------- SET 1 ---------------------- class inner { protected: unsigned a; unsigned b; unsigned c; }; class Cool { public: Cool(){} protected: int x; int y; int z; inner i; }; -------------- SET 2 ---------------------- class Cool { public: Cool(); protected: class inner { protected: unsigned a; unsigned b; unsigned c; }; int x; int y; int z; inner i; }; -------------- END ---------------------- So you'll notice that the only difference between 1 & 2 is that 2, defines "inner" as an inner class. Now, if I parse a header file containing those classes, obtain a reference to the pygccxml for class Cool and print it's variables like so: for var in classType.variables(): print "var", var.name, var.type This is what I get: SET 1 var x int var y int var z int var i inner SET 2 var x int var y int var z int var i Cool::inner var a unsigned int var b unsigned int var c unsigned int As you can see, when I is an inner class, the inner class's members show up in the parent class in addition to the inner class itself. Is this behavior correct? In SET 2, I would not expect to see a, b, and c show up as members of class Cool. If this behavior is correct, is there a way to filter out those members that belong to the inner class? From roman.yakovenko at gmail.com Mon Nov 29 21:22:39 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 29 Nov 2010 22:22:39 +0200 Subject: [C++-sig] pygccxml and inner classes In-Reply-To: <3602620DAE03994D80A0E6387C1A3B83B9F54870@HDXMSP8.us.lmco.com> References: <3602620DAE03994D80A0E6387C1A3B83B9F54870@HDXMSP8.us.lmco.com> Message-ID: On Mon, Nov 29, 2010 at 8:36 AM, Davidson, Josh wrote: > I'm wondering if this behavior is correct when using pygccxml. Consider > the following two sets of simple class definitions: > > -------------- SET 1 ---------------------- > class inner { > protected: > unsigned a; > unsigned b; > unsigned c; > }; > > class Cool { > public: > Cool(){} > > protected: > int x; > int y; > int z; > > inner i; > }; > > -------------- SET 2 ---------------------- > class Cool { > public: > Cool(); > > protected: > class inner { > protected: > unsigned a; > unsigned b; > unsigned c; > }; > > int x; > int y; > int z; > > inner i; > }; > > -------------- END ---------------------- > > So you'll notice that the only difference between 1 & 2 is that 2, defines > "inner" as an inner class. Now, if I parse a header file containing those > classes, obtain a reference to the pygccxml for class Cool and print it's > variables like so: > > for var in classType.variables(): > print "var", var.name, var.type > > This is what I get: > > SET 1 > var x int > var y int > var z int > var i inner > > SET 2 > var x int > var y int > var z int > var i Cool::inner > var a unsigned int > var b unsigned int > var c unsigned int > > > As you can see, when I is an inner class, the inner class's members show up > in the parent class in addition to the inner class itself. Is this behavior > correct? In SET 2, I would not expect to see a, b, and c show up as members > of class Cool. If this behavior is correct, is there a way to filter out > those members that belong to the inner class? > > This is the current package behavior. Another interesting use case, you can bring, is based classes. You will not see the variables from the base classes. Take a look on this document: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pygccxml_dev/docs/query_interface.rest?revision=1727&view=markup and then on pygccxml/declarations/scopedef.py - variables method. In your case, it is very simple to get the desired variables: class_vars = classType.variables( lambda var: var.parent is classType ) HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: