From dave at boostpro.com Mon Dec 1 18:50:58 2008 From: dave at boostpro.com (David Abrahams) Date: Mon, 01 Dec 2008 12:50:58 -0500 Subject: [C++-sig] shared_ptr with custom destructor In-Reply-To: <95291a80811241326g25a0a4f6tc819acce47928816@mail.gmail.com> (Renato Araujo's message of "Mon, 24 Nov 2008 18:26:09 -0300") References: <95291a80811241326g25a0a4f6tc819acce47928816@mail.gmail.com> Message-ID: <87hc5n7pj1.fsf@mcbain.luannocracy.com> on Mon Nov 24 2008, "Renato Araujo" wrote: > Hi all, > I would like to specify during the class_ declaration use a shared_ptr > with custom release function. > > shared_ptr has a constructor where you can pass a function to call in > the release, I would like to use this in a generic form. > > I already tried some like that: > > shared_ptr _custom_constructor() > { > return shared_ptr(new BaseClass(), _release_func); > } > > class_ > > ("BaseClass").def("__init__", make_constructor(_custom_constructor)); > > but this not work to class derived from BaseClass: my Derived in C++ or in Python? > _custom_constructor is not called to others class. > > I would like something more generic where I can declare in class_ > template, something like that: > > class_ ("MyObject") > ....... > > There is something like that? How is the best way to do this? Write a function template that you can use with make_constructor, e.g.: make_constructor(&_custom_constructor) HTH, -- Dave Abrahams BoostPro Computing http://www.boostpro.com From alanbaljeu at yahoo.com Mon Dec 1 22:29:49 2008 From: alanbaljeu at yahoo.com (Alan Baljeu) Date: Mon, 1 Dec 2008 13:29:49 -0800 (PST) Subject: [C++-sig] gccxml Message-ID: <384576.93432.qm@web58307.mail.re3.yahoo.com> I'm lost getting the right gccxml for use with pygccxml. And of course that would be used in Pybindgen and/or py++. The links point to a gccxml page which advertises version 0.6, but docs talk about versions 0.7 and 0.9. Anyhow, I downloaded 0.6 and didn't have much success. But then I'm not sure what I'm supposed to do to get a proper scan. I also don't get where I would find 0.7 or 0.9 versions. Ideally I'd just like a documented package that gives me everything together that I can test out. Please advise. Alan Baljeu http://www.collaborative-systems.org Intelligent software that works _with_ you. __________________________________________________________________ Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/ From roman.yakovenko at gmail.com Tue Dec 2 08:37:46 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 09:37:46 +0200 Subject: [C++-sig] gccxml In-Reply-To: <384576.93432.qm@web58307.mail.re3.yahoo.com> References: <384576.93432.qm@web58307.mail.re3.yahoo.com> Message-ID: <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> On Mon, Dec 1, 2008 at 11:29 PM, Alan Baljeu wrote: > I'm lost getting the right gccxml for use with pygccxml. And of course that would be used in Pybindgen and/or py++. > > The links point to a gccxml page which advertises version 0.6, but docs talk about versions 0.7 and 0.9. Anyhow, I downloaded 0.6 and didn't have much success. But then I'm not sure what I'm supposed to do to get a proper scan. I also don't get where I would find 0.7 or 0.9 versions. Ideally I'd just like a documented package that gives me everything together that I can test out. Unfortunately there is no GUI to install gccxml. http://gccxml.org/HTML/Install.html contains set of simple instructions to install latest GCCXML. It takes only few minutes to install it. If you use Ubuntu Linux, that you can install it using Synaptic. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From macke at yar.nu Tue Dec 2 09:46:21 2008 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 02 Dec 2008 09:46:21 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created Message-ID: <4934F5DD.2060102@yar.nu> Hi all, I'm trying to get OpenSG's python-bindings to work on Windows (and contruibuting that back to the project), and trying to track down an exception that get's thrown when running it's gen_bindings.py. (see attached log.txt for output) The source for gen_bindings.py is here, for reference: https://realityforge.vrsource.org/trac/pyopensg/browser/branches/trunk_update/src/gen_bindings.py From what I can see, the exception is thrown, as can be seen, in read_gccxml_file in pygccxml/parser/source_reader.py. The generation of the temp xml file (self.create_xml_file( ffname )) creates an empty file, which then gets a syntax error when read back. As I'm rather new to py++ (being old on c++ and average on python) I don't really know where to look when hunting for this bug. The PyOpenSG-devs have only used linux, and have maybe seen this before, earlier, but can't recall what and when. They also have used a earlier py++-version, but I'm using 1.0. I might be shooting myself in the foot with that, but I hope not. All help gratefully recieved. :) Cheers, /Marcus -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: log.txt URL: From roman.yakovenko at gmail.com Tue Dec 2 10:08:34 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 11:08:34 +0200 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <4934F5DD.2060102@yar.nu> References: <4934F5DD.2060102@yar.nu> Message-ID: <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> 2008/12/2 Marcus Lindblom : > Hi all, > > I'm trying to get OpenSG's python-bindings to work on Windows (and > contruibuting that back to the project), and trying to track down an > exception that get's thrown when running it's gen_bindings.py. (see attached > log.txt for output) > > The source for gen_bindings.py is here, for reference: > > https://realityforge.vrsource.org/trac/pyopensg/browser/branches/trunk_update/src/gen_bindings.py > > > From what I can see, the exception is thrown, as can be seen, in > read_gccxml_file in pygccxml/parser/source_reader.py. The generation of the > temp xml file (self.create_xml_file( ffname )) creates an empty file, which > then gets a syntax error when read back. > > As I'm rather new to py++ (being old on c++ and average on python) I don't > really know where to look when hunting for this bug. > > The PyOpenSG-devs have only used linux, and have maybe seen this before, > earlier, but can't recall what and when. They also have used a earlier > py++-version, but I'm using 1.0. I might be shooting myself in the foot with > that, but I hope not. There were few changes here and there, but it should not be too dificcult to upgrade, The output contains the following command: ""C:\program files\bin\gccxml.exe" /IJ:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include /IC:\Program Files oost oost_1_36_0 -DBOOST_PYTHON_MAX_ARITY=21 -I"." -I"osg_module" -I"J:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include" -I"J:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include\OpenSG" -I"j:\3rd\boost\boost_1_36_0" -I"c:\dev\python26\include" "osg_module\osgmodule_mainheader.h" -fxml="c:\users\marcusl\appdata\local\temp\tmp1e92ik.xml"" Can you run the command, from cmd and check that file was created and contains data. If I remember right, PyOpenSG project uses some tricky configuration to suppress GCCXML warnings and\or errors. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From macke at yar.nu Tue Dec 2 14:15:38 2008 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 02 Dec 2008 14:15:38 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> Message-ID: <493534FA.1020703@yar.nu> Roman Yakovenko wrote: > 2008/12/2 Marcus Lindblom : >> Hi all, >> >> I'm trying to get OpenSG's python-bindings to work on Windows (and >> contruibuting that back to the project), and trying to track down an >> exception that get's thrown when running it's gen_bindings.py. (see attached >> log.txt for output) [snip] >> The PyOpenSG-devs have only used linux, and have maybe seen this before, >> earlier, but can't recall what and when. They also have used a earlier >> py++-version, but I'm using 1.0. I might be shooting myself in the foot with >> that, but I hope not. > > There were few changes here and there, but it should not be too > dificcult to upgrade, That's what I'm hoping for. :) > The output contains the following command: > > ""C:\program files\bin\gccxml.exe" > /IJ:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include > /IC:\Program Files oost oost_1_36_0 -DBOOST_PYTHON_MAX_ARITY=21 > -I"." -I"osg_module" > -I"J:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include" > -I"J:\3rd\OpenSG\opensg2_trunk\build.win32.cl.9.0\instlinks\include\OpenSG" > -I"j:\3rd\boost\boost_1_36_0" -I"c:\dev\python26\include" > "osg_module\osgmodule_mainheader.h" > -fxml="c:\users\marcusl\appdata\local\temp\tmp1e92ik.xml"" > > Can you run the command, from cmd and check that file was created and > contains data. Ok. It came right back at me: pyopensg/src> ** the above ** Could not determine compiler setting. Could not determine GCCXML_FLAGS setting. pyopensg/src> So, I changed it to run my compiled gccxml (pretty recent cvs head) and added "--gccxml-compiler cl" (I use VS9 and python 2.6) and fixed the include paths (pyopensg retrieves includepaths from the osg2-config python script, which used /I instead of /I and also had some non-escaped backslashes (turing 'c:\program files\boost' into 'c:\program files oost' as can be seen above :) Running the modified cmd-line made gccxml run and print a whole lot, starting with: j:/3rd/OpenSG/opensg2_trunk/build.win32.cl.9.0/instlinks/include/OpenSG/OSGConfig.h:135:2: error: #error Endian determination : could not guess your plattform and ending up with an ICE. It seems as I have to add a few defines and such to get the opensg-sources to identify the compiler correctly. I can handle the osg2-config script myself, and probably figure out what defines are necessary, but where do I set compiler-arg + defines that are used when doing the cache-step that calls the above command? Is this cache stuff in PyOpenSG or Py++? (because I can't seem to find any such call in gen_bindings.main() nor nearby related modules, unless I've missed something). Cheers, /Marcus From kmihail at rocketmail.com Tue Dec 2 14:33:14 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 13:33:14 +0000 (GMT) Subject: [C++-sig] boost.python: private copy constructor problem Message-ID: <262531.34155.qm@web28402.mail.ukl.yahoo.com> Hello, I am still in the early process of learning boost.python. I have reduced my problem to the following code: #include using namespace boost::python; class A{ private: A(const A&){}; //no public copy constructor }; class B: public A{ public: B(){}; }; BOOST_PYTHON_MODULE(boost_ext) { class_("A",init<>()); class_ >("B",init<>()); } When running bjam on this example, I get "boost.cpp:6: error: ?A::A(const A&)? is private" as the first error among a long list of hints from the compiler. How can I expose the classes with their constructors to python? Thank you Mihail From roman.yakovenko at gmail.com Tue Dec 2 14:28:05 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 15:28:05 +0200 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <493534FA.1020703@yar.nu> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> Message-ID: <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> On Tue, Dec 2, 2008 at 3:15 PM, Marcus Lindblom wrote: > Ok. It came right back at me: > > pyopensg/src> ** the above ** > Could not determine compiler setting. > Could not determine GCCXML_FLAGS setting. > pyopensg/src> > > So, I changed it to run my compiled gccxml (pretty recent cvs head) and > added "--gccxml-compiler cl" (I use VS9 and python 2.6) and fixed the > include paths (pyopensg retrieves includepaths from the osg2-config python > script, which used /I instead of /I and also had some non-escaped > backslashes (turing 'c:\program files\boost' into 'c:\program files oost' as > can be seen above :) > > Running the modified cmd-line made gccxml run and print a whole lot, > starting with: > > j:/3rd/OpenSG/opensg2_trunk/build.win32.cl.9.0/instlinks/include/OpenSG/OSGConfig.h:135:2: > error: #error Endian determination : could not guess your plattform > > and ending up with an ICE. > > It seems as I have to add a few defines and such to get the opensg-sources > to identify the compiler correctly. > > I can handle the osg2-config script myself, and probably figure out what > defines are necessary, but where do I set compiler-arg + defines that are > used when doing the cache-step that calls the above command? gen_bindings.py file contains the following lines: 813 mb = ModuleBuilder([main_header_filename], 814 working_directory = ".", 815 include_paths=inc_path, 816 cache=cache_file+".module", 817 define_symbols=defines, 818 ignore_gccxml_output=True, 819 optimize_queries=use_query_opt, 820 #start_with_declarations=["OSG",], 821 cflags=opensg_cflags + " " + boost_cflags) opensg_cflags, boost_cflags variables contains the configuration flags > Is this cache stuff in PyOpenSG or Py++? (because I can't seem to find any > such call in gen_bindings.main() nor nearby related modules, unless I've > missed something). I don't understand the question, sorry :-( -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From kmihail at rocketmail.com Tue Dec 2 14:39:19 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 13:39:19 +0000 (GMT) Subject: [C++-sig] boost.python: private copy constructor problem References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> Message-ID: <534641.33799.qm@web28407.mail.ukl.yahoo.com> Sorry, the public A::A() constructor was missing. The corrected class A, which caused the described problem, is: class A{ private: A(const A&){}; //no public copy constructor public: A(){}; }; From seefeld at sympatico.ca Tue Dec 2 14:43:12 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Dec 2008 08:43:12 -0500 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <262531.34155.qm@web28402.mail.ukl.yahoo.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> Message-ID: <49353B70.1070103@sympatico.ca> Mihail Konstantinov wrote: > Hello, > I am still in the early process of learning boost.python. > I have reduced my problem to the following code: > > #include > using namespace boost::python; > class A{ > private: > A(const A&){}; //no public copy constructor > }; > class B: public A{ > public: > B(){}; > }; > BOOST_PYTHON_MODULE(boost_ext) > { > class_("A",init<>()); > class_ >("B",init<>()); > } > > When running bjam on this example, I get > "boost.cpp:6: error: ?A::A(const A&)? is private" > as the first error among a long list of hints from the compiler. > In this case you want to tell Python that your object is non-copyable: class_ a("A", init<>); ... See http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/class.html#class_-spec for details. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From macke at yar.nu Tue Dec 2 15:01:25 2008 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 02 Dec 2008 15:01:25 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> Message-ID: <49353FB5.20809@yar.nu> Roman Yakovenko wrote: > On Tue, Dec 2, 2008 at 3:15 PM, Marcus Lindblom wrote: >> Ok. It came right back at me: >> >> pyopensg/src> ** the above ** >> Could not determine compiler setting. >> Could not determine GCCXML_FLAGS setting. >> pyopensg/src> >> >> So, I changed it to run my compiled gccxml (pretty recent cvs head) and >> added "--gccxml-compiler cl" (I use VS9 and python 2.6) and fixed the >> include paths (pyopensg retrieves includepaths from the osg2-config python >> script, which used /I instead of /I and also had some non-escaped >> backslashes (turing 'c:\program files\boost' into 'c:\program files oost' as >> can be seen above :) >> >> Running the modified cmd-line made gccxml run and print a whole lot, >> starting with: >> >> j:/3rd/OpenSG/opensg2_trunk/build.win32.cl.9.0/instlinks/include/OpenSG/OSGConfig.h:135:2: >> error: #error Endian determination : could not guess your plattform >> >> and ending up with an ICE. >> >> It seems as I have to add a few defines and such to get the opensg-sources >> to identify the compiler correctly. >> >> I can handle the osg2-config script myself, and probably figure out what >> defines are necessary, but where do I set compiler-arg + defines that are >> used when doing the cache-step that calls the above command? > > gen_bindings.py file contains the following lines: > > 813 mb = ModuleBuilder([main_header_filename], > 814 working_directory = ".", > 815 include_paths=inc_path, > 816 cache=cache_file+".module", > 817 define_symbols=defines, > 818 ignore_gccxml_output=True, > 819 optimize_queries=use_query_opt, > 820 #start_with_declarations=["OSG",], > 821 cflags=opensg_cflags + " " + boost_cflags) > > opensg_cflags, boost_cflags variables contains the configuration flags Yes, but IIUC, this is way after the call to gccxml that I ran above, since the follwing is printed after the 'INFO gccxml cmd: ...' in the log-file in my first post: 566 print "Auto-building list of node cores using .fcd files... " >> Is this cache stuff in PyOpenSG or Py++? (because I can't seem to find any >> such call in gen_bindings.main() nor nearby related modules, unless I've >> missed something). > > I don't understand the question, sorry :-( No worries. :) The call to gccxml that you asked me to run does not produce a valid ouput file, because it's needs fixing. So, I'm guessing a bit here, but since the log contains stuff about cache file load failure and cache creation, which does the gccxml-call that I need to augment with defines and --gccxml-compiler option, I assumed I need to fix the gccxml call in the cache-creation thingy, not the call to ModuleBuilder way below. (which tries to use the empty file that gccxml failed to create earlier.) So, my question is, where does that gccxml call come from, and how do I change it's parameters? (Is even a py++ thing, or does it come from a pyopensg somewhere I've missed?) (I don't think the gccxml-call happens because of the call to the ModuleBuilder at line 813, although I might be wrong?) Does that make sense? I'll tinker with the ModuleBuilder a bit anyway.. to see if it helps, but the order of output makes me think the problem is somewhere else. Cheers, /Marcus P.S. Thanks for helping out! I'm ping-pong:ing a bit between the opensg-list and this one, so if I need to address my questions the other way, let me know. From kmihail at rocketmail.com Tue Dec 2 15:03:02 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 14:03:02 +0000 (GMT) Subject: [C++-sig] boost.python: private copy constructor problem References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> Message-ID: <993348.632.qm@web28403.mail.ukl.yahoo.com> > Stefan Seefeld wrote: > > In this case you want to tell Python that your object is non-copyable: I followed your suggestion and still get the same error message: boost.cpp:6: error: ?A::A(const A&)? is private (full bjam output is appended to this email) Could you check this modified code? boost_ext.cpp: #include using namespace boost::python; class A{ private: A(const A&){}; //no public copy constructor public: A(){}; }; class B: public A{ public: B(){}; }; BOOST_PYTHON_MODULE(boost_ext) { class_ a("A",init<>()); class_ >("B",init<>()); } Thank you Mihail Compilation output: $bjam boost_ext ...patience... ...found 1202 targets... ...updating 2 targets... gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o boost.cpp: In copy constructor ?B::B(const B&)?: boost.cpp:11: instantiated from ?boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper, Value = B]? /home/mihail/temporary/boost_1_37_0/boost/python/object/make_instance.hpp:68: instantiated from ?static Holder* boost::python::objects::make_instance::construct(void*, PyObject*, boost::reference_wrapper) [with T = B, Holder = boost::python::objects::value_holder]? /home/mihail/temporary/boost_1_37_0/boost/python/object/make_instance.hpp:42: instantiated from ?static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = const boost::reference_wrapper, T = B, Holder = boost::python::objects::value_holder, Derived = boost::python::objects::make_instance >]? /home/mihail/temporary/boost_1_37_0/boost/python/object/class_wrapper.hpp:29: instantiated from ?static PyObject* boost::python::objects::class_cref_wrapper::convert(const Src&) [with Src = B, MakeInstance = boost::python::objects::make_instance >]? /home/mihail/temporary/boost_1_37_0/boost/python/converter/as_to_python_function.hpp:27: instantiated from ?static PyObject* boost::python::converter::as_to_python_function::convert(const void*) [with T = B, ToPython = boost::python::objects::class_cref_wrapper > >]? /home/mihail/temporary/boost_1_37_0/boost/python/to_python_converter.hpp:87: instantiated from ?boost::python::to_python_converter::to_python_converter() [with T = B, Conversion = boost::python::objects::class_cref_wrapper > >, bool has_get_pytype = true]? /home/mihail/temporary/boost_1_37_0/boost/python/object/class_wrapper.hpp:26: instantiated from ?static void boost::python::objects::class_metadata::maybe_register_class_to_python(T2*, mpl_::false_) [with T2 = B, T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:229: instantiated from ?static void boost::python::objects::class_metadata::register_aux2(T2*, Callback) [with T2 = B, Callback = boost::integral_constant, T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:219: instantiated from ?static void boost::python::objects::class_metadata::register_aux(void*) [with T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:205: instantiated from ?static void boost::python::objects::class_metadata::register_() [with T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? /home/mihail/temporary/boost_1_37_0/boost/python/class.hpp:496: instantiated from ?void boost::python::class_::initialize(const DefVisitor&) [with DefVisitor = boost::python::init_base >, W = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? /home/mihail/temporary/boost_1_37_0/boost/python/class.hpp:208: instantiated from ?boost::python::class_::class_(const char*, const boost::python::init_base&) [with DerivedT = boost::python::init, W = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? boost.cpp:19: instantiated from here boost.cpp:6: error: ?A::A(const A&)? is private boost.cpp:11: error: within this context /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp: In constructor ?boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper, Value = B]?: /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:134: note: synthesized method ?B::B(const B&)? first required here "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -I"/home/mihail/temporary/boost_1_37_0" -I"/usr/include/python2.5" -c -o "bin/gcc-4.1.2/debug/boost.o" "boost.cpp" ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o.... ...skipped boost_ext.so for lack of boost.o... ...failed updating 1 target... ...skipped 1 target.... From renatox at gmail.com Tue Dec 2 15:11:09 2008 From: renatox at gmail.com (Renato Araujo) Date: Tue, 2 Dec 2008 11:11:09 -0300 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <993348.632.qm@web28403.mail.ukl.yahoo.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> Message-ID: <95291a80812020611g43190de5n47f0bd84c1c086a1@mail.gmail.com> try use boost::noncopyable to B or implemente a copy constructor in B without call A copy contructor. BR On Tue, Dec 2, 2008 at 11:03 AM, Mihail Konstantinov wrote: >> Stefan Seefeld wrote: > >> >> In this case you want to tell Python that your object is non-copyable: > > I followed your suggestion and still get the same error message: > boost.cpp:6: error: 'A::A(const A&)' is private > (full bjam output is appended to this email) > > Could you check this modified code? boost_ext.cpp: > #include > using namespace boost::python; > > class A{ > private: > A(const A&){}; //no public copy constructor > public: > A(){}; > }; > > class B: public A{ > public: > B(){}; > }; > > BOOST_PYTHON_MODULE(boost_ext) > { > class_ a("A",init<>()); > class_ >("B",init<>()); > } > > Thank you > Mihail > > Compilation output: > > $bjam boost_ext > ...patience... > ...found 1202 targets... > ...updating 2 targets... > gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o > boost.cpp: In copy constructor 'B::B(const B&)': > boost.cpp:11: instantiated from 'boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper, Value = B]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/make_instance.hpp:68: instantiated from 'static Holder* boost::python::objects::make_instance::construct(void*, PyObject*, boost::reference_wrapper) [with T = B, Holder = boost::python::objects::value_holder]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/make_instance.hpp:42: instantiated from 'static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = const boost::reference_wrapper, T = B, Holder = boost::python::objects::value_holder, Derived = boost::python::objects::make_instance >]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/class_wrapper.hpp:29: instantiated from 'static PyObject* boost::python::objects::class_cref_wrapper::convert(const Src&) [with Src = B, MakeInstance = boost::python::objects::make_instance >]' > /home/mihail/temporary/boost_1_37_0/boost/python/converter/as_to_python_function.hpp:27: instantiated from 'static PyObject* boost::python::converter::as_to_python_function::convert(const void*) [with T = B, ToPython = boost::python::objects::class_cref_wrapper > >]' > /home/mihail/temporary/boost_1_37_0/boost/python/to_python_converter.hpp:87: instantiated from 'boost::python::to_python_converter::to_python_converter() [with T = B, Conversion = boost::python::objects::class_cref_wrapper > >, bool has_get_pytype = true]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/class_wrapper.hpp:26: instantiated from 'static void boost::python::objects::class_metadata::maybe_register_class_to_python(T2*, mpl_::false_) [with T2 = B, T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:229: instantiated from 'static void boost::python::objects::class_metadata::register_aux2(T2*, Callback) [with T2 = B, Callback = boost::integral_constant, T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:219: instantiated from 'static void boost::python::objects::class_metadata::register_aux(void*) [with T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > /home/mihail/temporary/boost_1_37_0/boost/python/object/class_metadata.hpp:205: instantiated from 'static void boost::python::objects::class_metadata::register_() [with T = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > /home/mihail/temporary/boost_1_37_0/boost/python/class.hpp:496: instantiated from 'void boost::python::class_::initialize(const DefVisitor&) [with DefVisitor = boost::python::init_base >, W = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > /home/mihail/temporary/boost_1_37_0/boost/python/class.hpp:208: instantiated from 'boost::python::class_::class_(const char*, const boost::python::init_base&) [with DerivedT = boost::python::init, W = B, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' > boost.cpp:19: instantiated from here > boost.cpp:6: error: 'A::A(const A&)' is private > boost.cpp:11: error: within this context > /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp: In constructor 'boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper, Value = B]': > /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:134: note: synthesized method 'B::B(const B&)' first required here > > "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -I"/home/mihail/temporary/boost_1_37_0" -I"/usr/include/python2.5" -c -o "bin/gcc-4.1.2/debug/boost.o" "boost.cpp" > > ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o.... > ...skipped boost_ext.so for lack of boost.o... > ...failed updating 1 target... > ...skipped 1 target.... > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -- Renato Araujo Oliveira Filho From macke at yar.nu Tue Dec 2 15:12:12 2008 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 02 Dec 2008 15:12:12 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <49353FB5.20809@yar.nu> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> Message-ID: <4935423C.4030203@yar.nu> Marcus Lindblom wrote: > (I don't think the gccxml-call happens because of the call to the > ModuleBuilder at line 813, although I might be wrong?) Waitaminute. When I'm rerunning it now, the order makes more sense, and the cache-calls come up after the calls to ModuleBuilder. Probably the log-file merging of stdout and stderr was playing tricks on me. I'll look augmenting the ModuleBuilder call, just as you said. Sorry for the confusion. :-/ cheers /Marcus From macke at yar.nu Tue Dec 2 15:15:23 2008 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 02 Dec 2008 15:15:23 +0100 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <993348.632.qm@web28403.mail.ukl.yahoo.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> Message-ID: <493542FB.2090200@yar.nu> Mihail Konstantinov wrote: >> Stefan Seefeld wrote: > >> In this case you want to tell Python that your object is non-copyable: > > I followed your suggestion and still get the same error message: [snip] > /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp: In constructor ?boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper, Value = B]?: > /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:134: note: synthesized method ?B::B(const B&)? first required here Seems like B needs to be noncopyable too? /Marcus From roman.yakovenko at gmail.com Tue Dec 2 15:16:36 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 16:16:36 +0200 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <95291a80812020611g43190de5n47f0bd84c1c086a1@mail.gmail.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> <95291a80812020611g43190de5n47f0bd84c1c086a1@mail.gmail.com> Message-ID: <7465b6170812020616r85fa951pe421b7a5bfdeaa33@mail.gmail.com> On Tue, Dec 2, 2008 at 4:11 PM, Renato Araujo wrote: > try use boost::noncopyable to B or implemente a copy constructor in B > without call A copy contructor. He is right. The following code was generated by Py++: #include "boost/python.hpp" namespace bp = boost::python; BOOST_PYTHON_MODULE(pyplusplus){ bp::class_< A, boost::noncopyable >( "A", bp::init< >() ); bp::class_< B, bp::bases< A >, boost::noncopyable >( "B", bp::init< >() ); } Py++ has some GUI too ( http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html ) - no need to learn API -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From seefeld at sympatico.ca Tue Dec 2 15:19:03 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Dec 2008 09:19:03 -0500 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <993348.632.qm@web28403.mail.ukl.yahoo.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> Message-ID: <493543D7.90904@sympatico.ca> Mihail Konstantinov wrote: > > gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o > boost.cpp: In copy constructor ?B::B(const B&)?: > As this error message suggests: as B derives from A, it is (by default) non-copyable, too. That you have to tell python, too, thus: class_ a("A", init<>); class_, noncopyable> b("B", init<>); ... HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From kmihail at rocketmail.com Tue Dec 2 15:25:47 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 14:25:47 +0000 (GMT) Subject: [C++-sig] boost.python: private copy constructor problem References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> <95291a80812020611g43190de5n47f0bd84c1c086a1@mail.gmail.com> Message-ID: <68970.45747.qm@web28404.mail.ukl.yahoo.com> > try use boost::noncopyable to B or implemente a copy constructor in B > without call A copy contructor. Thank you. This works: BOOST_PYTHON_MODULE(boost_ext) { class_ a("A",init<>()); class_, boost::noncopyable >("B",init<>()); } One more question about the syntax. You cited http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/class.html#class_-spec which specifies the syntax as "class_" so that I thought I have to include all 4 template arguments. But when I used instead of the above (working!) solution: class_, A, boost::noncopyable> a("A",init<>()); class_, B, boost::noncopyable >("B",init<>()); I get the error: >/home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:159: error: no matching function for call to >?B::B(PyObject*&)? >boost.cpp:13: note: candidates are: B::B() >boost.cpp:11: note: B::B(const B&) Why does the abbreviated template argument list work, and why not the complete argument list? Thank you Mihail From seefeld at sympatico.ca Tue Dec 2 15:33:27 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Dec 2008 09:33:27 -0500 Subject: [C++-sig] boost.python: private copy constructor problem In-Reply-To: <68970.45747.qm@web28404.mail.ukl.yahoo.com> References: <262531.34155.qm@web28402.mail.ukl.yahoo.com> <49353B70.1070103@sympatico.ca> <993348.632.qm@web28403.mail.ukl.yahoo.com> <95291a80812020611g43190de5n47f0bd84c1c086a1@mail.gmail.com> <68970.45747.qm@web28404.mail.ukl.yahoo.com> Message-ID: <49354737.4040703@sympatico.ca> Mihail Konstantinov wrote: > One more question about the syntax. You cited > http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/class.html#class_-spec > which specifies the syntax as "class_" > so that I thought I have to include all 4 template arguments. But when > I used instead of the above (working!) solution: > class_, A, boost::noncopyable> a("A",init<>()); > class_, B, boost::noncopyable >("B",init<>()); > I get the error: > >> /home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:159: error: no matching function for call to >> ?B::B(PyObject*&)? >> boost.cpp:13: note: candidates are: B::B() >> boost.cpp:11: note: B::B(const B&) >> > > Why does the abbreviated template argument list work, and why not the complete argument list? > As the docs say, all but the first template argument are optional. And, thanks to some meta-programming magic, their order doesn't matter. The above link also discusses requirements on the HeldType, such as "its exposed constructor(s) must accept an initial |PyObject*| argument..." Again, may not actually need to care about the HeldType if the defaults work fine for you. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From alanbaljeu at yahoo.com Tue Dec 2 16:26:21 2008 From: alanbaljeu at yahoo.com (Alan Baljeu) Date: Tue, 2 Dec 2008 07:26:21 -0800 (PST) Subject: [C++-sig] gccxml References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> Message-ID: <255255.48164.qm@web58306.mail.re3.yahoo.com> This is getting out of hand :-( All I wanted to do was parse some simple C++ function declarations to generate a corresponding py-callable wrapper. To do this I need to get pygccxml. Then I need gccxml to use pygccxml. To get that I need WinCVS or some equivalent (which version, and learn how CVS works) or Cygwin. Then I need to choose the preferred version of gccxml. And then I need to obtain CMake to install it? I think I'd rather just do my own thing, except that C++ is so warty it's difficult to come up with anything reasonable that will serve the purpose. Alan Baljeu ----- Original Message ---- From: Roman Yakovenko To: Development of Python/C++ integration Sent: Tuesday, December 2, 2008 2:37:46 AM Subject: Re: [C++-sig] gccxml On Mon, Dec 1, 2008 at 11:29 PM, Alan Baljeu wrote: > I'm lost getting the right gccxml for use with pygccxml. And of course that would be used in Pybindgen and/or py++. > > The links point to a gccxml page which advertises version 0.6, but docs talk about versions 0.7 and 0.9. Anyhow, I downloaded 0.6 and didn't have much success. But then I'm not sure what I'm supposed to do to get a proper scan. I also don't get where I would find 0.7 or 0.9 versions. Ideally I'd just like a documented package that gives me everything together that I can test out. Unfortunately there is no GUI to install gccxml. http://gccxml.org/HTML/Install.html contains set of simple instructions to install latest GCCXML. It takes only few minutes to install it. If you use Ubuntu Linux, that you can install it using Synaptic. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig __________________________________________________________________ Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/ From seefeld at sympatico.ca Tue Dec 2 16:41:45 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Dec 2008 10:41:45 -0500 Subject: [C++-sig] gccxml In-Reply-To: <255255.48164.qm@web58306.mail.re3.yahoo.com> References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> Message-ID: <49355739.40106@sympatico.ca> Alan Baljeu wrote: > This is getting out of hand :-( > > I think I'd rather just do my own thing, except that C++ is so warty it's difficult to come up with anything reasonable that will serve the purpose. > How many functions and objects do you want to export, anyway ? I have so far always preferred to write my boost.python code manually. Not only because installing the prerequisites for the alternate tools is so cumbersome, but mainly because I want the python API to look a little more pythonic than the equivalent C++ code I'm wrapping. You can always move 'back' to auto-generated wrapper code later if you find it is worth it. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From roman.yakovenko at gmail.com Tue Dec 2 16:58:33 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 17:58:33 +0200 Subject: [C++-sig] gccxml In-Reply-To: <255255.48164.qm@web58306.mail.re3.yahoo.com> References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> Message-ID: <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> On Tue, Dec 2, 2008 at 5:26 PM, Alan Baljeu wrote: > This is getting out of hand :-( > > All I wanted to do was parse some simple C++ function declarations to generate a corresponding py-callable wrapper. To do this I need to get pygccxml. Then I need gccxml to use pygccxml. To get that I need WinCVS or some equivalent (which version, and learn how CVS works) or Cygwin. Then I need to choose the preferred version of gccxml. And then I need to obtain CMake to install it? > > I think I'd rather just do my own thing, except that C++ is so warty it's difficult to come up with anything reasonable that will serve the purpose. How much effort did you put to improve the situation? Did you contribute to GCCXML project in someway or another? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From alanbaljeu at yahoo.com Tue Dec 2 17:14:34 2008 From: alanbaljeu at yahoo.com (Alan Baljeu) Date: Tue, 2 Dec 2008 08:14:34 -0800 (PST) Subject: [C++-sig] gccxml References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> Message-ID: <136637.36945.qm@web58304.mail.re3.yahoo.com> I would make a contribution to some projects. GCC-XML is not one of them, seeing how it's not even worth my effort to try to install and configure this stuff. If I were involved with these packages, I would make it easy for others to get involved. As it isn't easy I'm going to look elsewhere. Alan Baljeu ----- Original Message ---- From: Roman Yakovenko To: Development of Python/C++ integration Sent: Tuesday, December 2, 2008 10:58:33 AM Subject: Re: [C++-sig] gccxml On Tue, Dec 2, 2008 at 5:26 PM, Alan Baljeu wrote: > This is getting out of hand :-( > > All I wanted to do was parse some simple C++ function declarations to generate a corresponding py-callable wrapper. To do this I need to get pygccxml. Then I need gccxml to use pygccxml. To get that I need WinCVS or some equivalent (which version, and learn how CVS works) or Cygwin. Then I need to choose the preferred version of gccxml. And then I need to obtain CMake to install it? > > I think I'd rather just do my own thing, except that C++ is so warty it's difficult to come up with anything reasonable that will serve the purpose. How much effort did you put to improve the situation? Did you contribute to GCCXML project in someway or another? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig __________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at http://ca.toolbar.yahoo.com. From gjcarneiro at gmail.com Tue Dec 2 17:47:42 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 2 Dec 2008 16:47:42 +0000 Subject: [C++-sig] gccxml In-Reply-To: <136637.36945.qm@web58304.mail.re3.yahoo.com> References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> <136637.36945.qm@web58304.mail.re3.yahoo.com> Message-ID: 2008/12/2 Alan Baljeu > I would make a contribution to some projects. GCC-XML is not one of them, > seeing how it's not even worth my effort to try to install and configure > this stuff. If I were involved with these packages, I would make it easy > for others to get involved. As it isn't easy I'm going to look elsewhere. Unfortunately you will soon find out there is no real alternative to GCC-XML if you have to do serious parsing of C++ headers. The time invested in getting GCC-XML to work for you will pay off in the end in case your project has multi-year scope and large API set to wrap. If on the other hand your project is small, you can get by if you just manually write your wrappers (both boost.python and pybindgen support this manual wrapping method). Either way, know that wrapping C/C++ for Python is usually hard for beginners, but don't give up, it gets easier with practice :-) -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmihail at rocketmail.com Tue Dec 2 18:04:58 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 17:04:58 +0000 (GMT) Subject: [C++-sig] boost.python: implicit type conversion Message-ID: <220240.21313.qm@web28405.mail.ukl.yahoo.com> Dear all, thanks a lot for your immediate responses that lead to a fast solution for my previous problem. Here comes the next one. In the example below both classes A and B are derived from std::string. Class B can be implicitly converted to A by means of 'B::operator const A()'. So the function printme(const A&) can also be called with an argument of class B (see main function). My aim is to be able to call in python: >>>import boost_ext >>>b=boost_ext.B("hello world") >>>boost_ext.printme(b) but it produces the error: > : Python argument types in boost_ext.printme(B) > did not match C++ signature: > printme(A) Can I modify the declaration inside BOOST_PYTHON_MODULE so that the implicit conversion is recognized and the above call boost_ext.printme(b) succeeds? Thank you Mihail BTW, in the code below I'm using a preprocessor definition __BJAM__ which I had to define explicitly in the Jamroot. Is there some variable defined by default which I can use to distinguish between bjam builds and other (testing) calls to g++? boost.cpp: #ifdef __BJAM__ // I define __BJAM__ in the Jamroot file.. #include #endif #include #include class A: public std::string{ public: A(const std::string&s,int i):std::string(s){} }; class B: public std::string{ public: B(const std::string&s):std::string(s){} operator const A(){return A(*this,-1);} }; void printme(const A &a){std::cout<("string"); class_ > ("A",init()); class_ > ("B",init()); def("printme",&printme); } #endif From mathieu.malaterre at gmail.com Tue Dec 2 18:37:18 2008 From: mathieu.malaterre at gmail.com (Mathieu Malaterre) Date: Tue, 2 Dec 2008 18:37:18 +0100 Subject: [C++-sig] gccxml In-Reply-To: References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> <136637.36945.qm@web58304.mail.re3.yahoo.com> Message-ID: 2008/12/2 Gustavo Carneiro : > 2008/12/2 Alan Baljeu >> >> I would make a contribution to some projects. GCC-XML is not one of them, >> seeing how it's not even worth my effort to try to install and configure >> this stuff. If I were involved with these packages, I would make it easy >> for others to get involved. As it isn't easy I'm going to look elsewhere. > > Unfortunately you will soon find out there is no real alternative to GCC-XML > if you have to do serious parsing of C++ headers. The time invested in > getting GCC-XML to work for you will pay off in the end in case your project > has multi-year scope and large API set to wrap. Switch to a debian based system: $ sudo apt-get install gccxml Approx ~1min of time invested (+ time to write this email). -- Mathieu From gjcarneiro at gmail.com Tue Dec 2 19:06:23 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 2 Dec 2008 18:06:23 +0000 Subject: [C++-sig] gccxml In-Reply-To: References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> <136637.36945.qm@web58304.mail.re3.yahoo.com> Message-ID: 2008/12/2 Mathieu Malaterre > 2008/12/2 Gustavo Carneiro : > > 2008/12/2 Alan Baljeu > >> > >> I would make a contribution to some projects. GCC-XML is not one of > them, > >> seeing how it's not even worth my effort to try to install and configure > >> this stuff. If I were involved with these packages, I would make it > easy > >> for others to get involved. As it isn't easy I'm going to look > elsewhere. > > > > Unfortunately you will soon find out there is no real alternative to > GCC-XML > > if you have to do serious parsing of C++ headers. The time invested in > > getting GCC-XML to work for you will pay off in the end in case your > project > > has multi-year scope and large API set to wrap. > > Switch to a debian based system: > > $ sudo apt-get install gccxml > > Approx ~1min of time invested (+ time to write this email). Sure, but how current is this debian gccxml? Is it a CVS snapshot, or the years old official release that does not work well with pygccxml? -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From mathieu.malaterre at gmail.com Tue Dec 2 19:17:42 2008 From: mathieu.malaterre at gmail.com (Mathieu Malaterre) Date: Tue, 2 Dec 2008 19:17:42 +0100 Subject: [C++-sig] gccxml In-Reply-To: References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> <136637.36945.qm@web58304.mail.re3.yahoo.com> Message-ID: 2008/12/2 Gustavo Carneiro : > > > 2008/12/2 Mathieu Malaterre >> >> 2008/12/2 Gustavo Carneiro : >> > 2008/12/2 Alan Baljeu >> >> >> >> I would make a contribution to some projects. GCC-XML is not one of >> >> them, >> >> seeing how it's not even worth my effort to try to install and >> >> configure >> >> this stuff. If I were involved with these packages, I would make it >> >> easy >> >> for others to get involved. As it isn't easy I'm going to look >> >> elsewhere. >> > >> > Unfortunately you will soon find out there is no real alternative to >> > GCC-XML >> > if you have to do serious parsing of C++ headers. The time invested in >> > getting GCC-XML to work for you will pay off in the end in case your >> > project >> > has multi-year scope and large API set to wrap. >> >> Switch to a debian based system: >> >> $ sudo apt-get install gccxml >> >> Approx ~1min of time invested (+ time to write this email). > > Sure, but how current is this debian gccxml? Is it a CVS snapshot, or the > years old official release that does not work well with pygccxml? > From: http://packages.debian.org/lenny/gccxml ... Package: gccxml (0.9.0+cvs20080525-1) ... I do not know if you call that /recent/ or not... -- Mathieu From gjcarneiro at gmail.com Tue Dec 2 19:36:57 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 2 Dec 2008 18:36:57 +0000 Subject: [C++-sig] gccxml In-Reply-To: References: <384576.93432.qm@web58307.mail.re3.yahoo.com> <7465b6170812012337gd1896ddyf47dcb956bfc5c02@mail.gmail.com> <255255.48164.qm@web58306.mail.re3.yahoo.com> <7465b6170812020758r1d85a7f6oc13bb06b118b47c3@mail.gmail.com> <136637.36945.qm@web58304.mail.re3.yahoo.com> Message-ID: 2008/12/2 Mathieu Malaterre > 2008/12/2 Gustavo Carneiro : > > > > > > 2008/12/2 Mathieu Malaterre > >> > >> 2008/12/2 Gustavo Carneiro : > >> > 2008/12/2 Alan Baljeu > >> >> > >> >> I would make a contribution to some projects. GCC-XML is not one of > >> >> them, > >> >> seeing how it's not even worth my effort to try to install and > >> >> configure > >> >> this stuff. If I were involved with these packages, I would make it > >> >> easy > >> >> for others to get involved. As it isn't easy I'm going to look > >> >> elsewhere. > >> > > >> > Unfortunately you will soon find out there is no real alternative to > >> > GCC-XML > >> > if you have to do serious parsing of C++ headers. The time invested > in > >> > getting GCC-XML to work for you will pay off in the end in case your > >> > project > >> > has multi-year scope and large API set to wrap. > >> > >> Switch to a debian based system: > >> > >> $ sudo apt-get install gccxml > >> > >> Approx ~1min of time invested (+ time to write this email). > > > > Sure, but how current is this debian gccxml? Is it a CVS snapshot, or > the > > years old official release that does not work well with pygccxml? > > > > From: > http://packages.debian.org/lenny/gccxml > > ... > Package: gccxml (0.9.0+cvs20080525-1) > ... > > I do not know if you call that /recent/ or not... Goodie! That should work with pygccxml 0.9.5, in theory. And to my surprise Ubuntu 8.04 now has that same snapshot as well. Kids these days have it too easy... :P Unfortunately Debian/Ubuntu have no pygccxml package, what a shame! :-( -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Dec 2 19:54:45 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 20:54:45 +0200 Subject: [C++-sig] boost.python: implicit type conversion In-Reply-To: <220240.21313.qm@web28405.mail.ukl.yahoo.com> References: <220240.21313.qm@web28405.mail.ukl.yahoo.com> Message-ID: <7465b6170812021054g6099040j29d742e3b41ec266@mail.gmail.com> On Tue, Dec 2, 2008 at 7:04 PM, Mihail Konstantinov wrote: > Dear all, > thanks a lot for your immediate responses that lead to a fast solution for my previous problem. > > Here comes the next one. > > In the example below both classes A and B are derived from std::string. It is not a good idea. Python string is immutable. May be you should consider custom converter. http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string >Class B can be implicitly converted to A by means of 'B::operator const A()'. So the function printme(const A&) can also be called with an argument of class B (see main function). > > My aim is to be able to call in python: >>>>import boost_ext >>>>b=boost_ext.B("hello world") >>>>boost_ext.printme(b) > but it produces the error: >> : Python argument types in boost_ext.printme(B) >> did not match C++ signature: >> printme(A) > > Can I modify the declaration inside BOOST_PYTHON_MODULE so that the implicit conversion is recognized and the above call boost_ext.printme(b) succeeds? Yes: http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/implicit.html > Thank you > Mihail > > BTW, in the code below I'm using a preprocessor definition __BJAM__ which I had to define explicitly in the Jamroot. Is there some variable defined by default which I can use to distinguish between bjam builds and other (testing) calls to g++? You can separate your source code to different files. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From kmihail at rocketmail.com Tue Dec 2 20:20:44 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 19:20:44 +0000 (GMT) Subject: [C++-sig] boost.python: implicit type conversion References: <220240.21313.qm@web28405.mail.ukl.yahoo.com> <7465b6170812021054g6099040j29d742e3b41ec266@mail.gmail.com> Message-ID: <479726.59172.qm@web28413.mail.ukl.yahoo.com> > Roman Yakovenko wrote: > > It is not a good idea. Python string is immutable. May be you should > consider custom converter. > http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string I don't see why it is not a good idea. I am nowhere accessing any string derived classes in a mutable fashion, am I? Also I have no option to change the class hierarchy. The code fragments I am posting are simplified from a large project that I try to pythonify, reduced to what I think is the cause of the problems. I want to avoid modifying the underlying project under all circumstances. > > Can I modify the declaration inside BOOST_PYTHON_MODULE so that the implicit > conversion is recognized and the above call boost_ext.printme(b) succeeds? > > Yes: http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/implicit.html This looks very helpful. But I don't understand the C++ module definition example on that page. It ends with > implicitly_convertible(); > implicitly_convertible(); >} I see that an int can be implicitly converted to X. But how can an X be converted to an int? I can't believe that boost.python searches all implemented functions to find that make_x is capable of converting an int to X? Thank you Mihail From kmihail at rocketmail.com Tue Dec 2 20:31:02 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Tue, 2 Dec 2008 19:31:02 +0000 (GMT) Subject: [C++-sig] boost.python: implicit type conversion References: <220240.21313.qm@web28405.mail.ukl.yahoo.com> <7465b6170812021054g6099040j29d742e3b41ec266@mail.gmail.com> <479726.59172.qm@web28413.mail.ukl.yahoo.com> Message-ID: <620254.92061.qm@web28411.mail.ukl.yahoo.com> > > implicitly_convertible(); > > implicitly_convertible(); > >} > I see that an int can be implicitly converted to X. But how can an X be > converted to an int? I can't believe that boost.python searches all implemented > functions to find that make_x is capable of converting an int to X? Found it. X::operator int() const. Apparently I need some sleep. Thank you Mihail From roman.yakovenko at gmail.com Tue Dec 2 20:32:47 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Dec 2008 21:32:47 +0200 Subject: [C++-sig] boost.python: implicit type conversion In-Reply-To: <479726.59172.qm@web28413.mail.ukl.yahoo.com> References: <220240.21313.qm@web28405.mail.ukl.yahoo.com> <7465b6170812021054g6099040j29d742e3b41ec266@mail.gmail.com> <479726.59172.qm@web28413.mail.ukl.yahoo.com> Message-ID: <7465b6170812021132p4bb988aaj4c52e0393b2ff0c@mail.gmail.com> On Tue, Dec 2, 2008 at 9:20 PM, Mihail Konstantinov wrote: >> Roman Yakovenko wrote: >> It is not a good idea. Python string is immutable. May be you should >> consider custom converter. >> http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string > > I don't see why it is not a good idea. I am nowhere accessing any string derived classes in a mutable fashion, am I? May in the code you posted you don't. May be you don't change it in the whole project. But if you do, it breaks too many Python assumptions. > Also I have no option to change the class hierarchy. The code fragments I am posting are simplified from a large project that I try to pythonify, reduced to what I think is the cause of the problems. I want to avoid modifying the underlying project under all circumstances. I understand. I suggest you to reconsider registration of std::string as a base class of your classes. Also, Boost.Python has built-in functionality to convert Python string and std::basic_string. I don't know what effect class_< std::string > registration will have. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From seefeld at sympatico.ca Tue Dec 2 20:32:57 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Dec 2008 14:32:57 -0500 Subject: [C++-sig] boost.python: implicit type conversion In-Reply-To: <479726.59172.qm@web28413.mail.ukl.yahoo.com> References: <220240.21313.qm@web28405.mail.ukl.yahoo.com> <7465b6170812021054g6099040j29d742e3b41ec266@mail.gmail.com> <479726.59172.qm@web28413.mail.ukl.yahoo.com> Message-ID: <49358D69.4080000@sympatico.ca> Mihail Konstantinov wrote: >> Roman Yakovenko wrote: >> > > >> It is not a good idea. Python string is immutable. May be you should >> consider custom converter. >> http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string >> > > I don't see why it is not a good idea. I am nowhere accessing any string derived classes in a mutable fashion, am I? > Also I have no option to change the class hierarchy. The code fragments I am posting are simplified from a large project that I try to pythonify, reduced to what I think is the cause of the problems. I want to avoid modifying the underlying project under all circumstances. > You are attempting to make Python aware of the inheritance relationship between std::string and your own class. That is what doesn't work, not your own deriving from std::string. In order to make 'bases' work, you would have to export the std::string class to Python first. But as that isn't what you actually want, you may as well remove the 'bases' from your code, and instead rely on (implicit) conversion. > >>> Can I modify the declaration inside BOOST_PYTHON_MODULE so that the implicit >>> >> conversion is recognized and the above call boost_ext.printme(b) succeeds? >> >> Yes: http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/implicit.html >> > > This looks very helpful. But I don't understand the C++ module definition example on that page. It ends with > > >> implicitly_convertible(); >> implicitly_convertible(); >> } >> > I see that an int can be implicitly converted to X. But how can an X be converted to an int? I can't believe that boost.python searches all implemented functions to find that make_x is capable of converting an int to X? > I believe it simply expects an 'operator int ()' to be available in that case. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Matthew.Scouten at tradingtechnologies.com Tue Dec 2 21:23:39 2008 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Tue, 2 Dec 2008 14:23:39 -0600 Subject: [C++-sig] Pickle an enum from c++ Message-ID: <32490DFF7774554A85D65D23A9F0F938099CB568@chiex01> I have an enum in my c++ library. In fact I have a crap load of them. 169 to be exact. I need them to be pickle-able. The enum_ object does not have a .def_pickle function, so I cannot use the pickle suite. I tried to just up and pickle it but that does not work either. enum box {cardboard, cereal, toy}; BOOST_PYTHON_MODULE(busybox) { enum_("box") .value("cardboard",cardboard ) .value("cereal",cereal ) .value("toy", toy); } C:\Documents and Settings\mscouten>cd C:\tt-dev\manticore\ C:\tt-dev\manticore>call setpath.bat Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pickle, busybox >>> >>> b = busybox.box.toy >>> >>> bs = pickle.dumps(b) Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "C:\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python25\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "C:\Python25\lib\pickle.py", line 401, in save_reduce save(args) File "C:\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python25\lib\pickle.py", line 562, in save_tuple save(element) File "C:\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python25\lib\pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle : it's not found as __main__.busybox.box >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmihail at rocketmail.com Wed Dec 3 11:03:42 2008 From: kmihail at rocketmail.com (Mihail Konstantinov) Date: Wed, 3 Dec 2008 10:03:42 +0000 (GMT) Subject: [C++-sig] pure class, to expose or not to expose? Message-ID: <721544.61664.qm@web28401.mail.ukl.yahoo.com> Hello, I need help again. In the example below I either get the error message during compilation: > ... >/home/mihail/temporary/boost_1_37_0/boost/python/object/value_holder.hpp:66: error: cannot declare field >?boost::python::objects::value_holder::m_held? to be of abstract type ?A0? >boost.cpp:5: note: because the following virtual functions are pure within ?A0?: >boost.cpp:7: note: virtual void A0::pure() or, if I don't expose class A0 (as it is currently commented out), when importing the module in python: > : extension class wrapper for base class A0 has not been created yet How can I fix the problem? I don't need to expose A0, well, exposing pure classes doesn't make sense anyway, does it? But I need to be able to call in python boost_ext.B(boost_ext.A()), so that I think I have to declare the A0<-A inheritance relationship somehow. Thank you Mihail boost.cpp: // A is a concrete implementation of the abstract class A0. // the constructor of B takes the abstract class A0 class A0{ public: virtual void pure()=0; virtual ~A0(){}; }; class A: public A0{ public: void pure(){}; ~A(){}; }; template class B{ T value; public: B(const A0&){}; }; typedef B Lumi; BOOST_PYTHON_MODULE(boost_ext) { using namespace boost::python; //class_("A0"); class_ >("A"); class_("Lumi",init()); } From renatox at gmail.com Wed Dec 3 19:04:31 2008 From: renatox at gmail.com (Renato Araujo) Date: Wed, 3 Dec 2008 15:04:31 -0300 Subject: [C++-sig] PyObject RefCount Message-ID: <95291a80812031004v7d1276afl66a86b09b19996d2@mail.gmail.com> Hi all, I'm trying check if have someone using my object in python, but I got some problems I think I'm not doing this in the correct way: I have a function like that: voi MyClass::~MyClass() { for(int i=0; i < childCount(); i++) { BaseClass *child = child_at(i); python::object py_obj(pyhton::ptr(child)); //I can't this without ptr because my object no have copy constructor //Whats happen here?? ^^^ - How this work when the object already exists? and whats happen when the object not exists? - There is a better way to verify if already have a python object associate with my child c++ object? if (py_obj.ptr()->ob_refcnt == 1) delete child; else { //do nothing python GC will destroy this } } } How I can fix this?? How is the best way to do this? Thanks -- Renato Araujo Oliveira Filho From seefeld at sympatico.ca Wed Dec 3 20:16:44 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 03 Dec 2008 14:16:44 -0500 Subject: [C++-sig] PyObject RefCount In-Reply-To: <95291a80812031004v7d1276afl66a86b09b19996d2@mail.gmail.com> References: <95291a80812031004v7d1276afl66a86b09b19996d2@mail.gmail.com> Message-ID: <4936DB1C.7010104@sympatico.ca> Renato Araujo wrote: > Hi all, > > I'm trying check if have someone using my object in python, but I got > some problems I think I'm not doing this in the correct way: > First of all, I'm not sure I understand what you are trying to achieve. Why do you want to manually delete reference-counted objects, instead of letting Python's runtime do this ? > I have a function like that: > > voi MyClass::~MyClass() > { > for(int i=0; i < childCount(); i++) > { > BaseClass *child = child_at(i); > > python::object py_obj(pyhton::ptr(child)); //I can't this > without ptr because my object no have copy constructor > //Whats happen here?? ^^^ > By default, the object would be passed by-value, i.e. a copy would be made, and assigned to the python wrapper object. python::ptr() is basically a marker to tell boost.python to copy by-reference (by-pointer, as it stands) instead. > - How this work when the object already exists? and > whats happen when the object not exists? > In both cases, I believe a new python wrapper object is created. This, of course, is problematic if the object is already ref-counted elsewhere, since now you have got two reference counters, both attempting to delete the object once they drop down to 0. > - There is a better way to verify if already have a > python object associate with my child c++ object? > I don't think there is any way to get from the wrapped object to the wrapper, as I don't know of any place that would provide this mapping. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From renatox at gmail.com Wed Dec 3 20:39:12 2008 From: renatox at gmail.com (Renato Araujo) Date: Wed, 3 Dec 2008 16:39:12 -0300 Subject: [C++-sig] PyObject RefCount In-Reply-To: <4936DB1C.7010104@sympatico.ca> References: <95291a80812031004v7d1276afl66a86b09b19996d2@mail.gmail.com> <4936DB1C.7010104@sympatico.ca> Message-ID: <95291a80812031139l55285ab7y3dc79d05a5a0207a@mail.gmail.com> Thanks for your points, I will try explain my problem better: In my library I have a parent->child control then when the parent is deleted all children is deleted too. but in python I would like change this behavior, if there is some python object using my child I will not delete this object. The problem here is, some children is created in c++ code without communicate to python. Then during the parent destructor I would like to know which child are create in c++ and which is created in python, for check this I'm using refcount, if recount > 1 then there is some python object using this else I can delete this. But after some tests this way to create python object using "obj(ptr(my_object))" if the object is new (not exists in python) the refcount is 1 and if there is only 1 python object using this the refcount is 1 too, then this cause me a problem. On Wed, Dec 3, 2008 at 4:16 PM, Stefan Seefeld wrote: > Renato Araujo wrote: >> >> Hi all, >> >> I'm trying check if have someone using my object in python, but I got >> some problems I think I'm not doing this in the correct way: >> > > First of all, I'm not sure I understand what you are trying to achieve. Why > do you want to manually delete reference-counted objects, instead of letting > Python's runtime do this ? Renato Araujo Oliveira Filho From seefeld at sympatico.ca Wed Dec 3 20:53:04 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 03 Dec 2008 14:53:04 -0500 Subject: [C++-sig] PyObject RefCount In-Reply-To: <95291a80812031139l55285ab7y3dc79d05a5a0207a@mail.gmail.com> References: <95291a80812031004v7d1276afl66a86b09b19996d2@mail.gmail.com> <4936DB1C.7010104@sympatico.ca> <95291a80812031139l55285ab7y3dc79d05a5a0207a@mail.gmail.com> Message-ID: <4936E3A0.1030208@sympatico.ca> Renato Araujo wrote: > Thanks for your points, I will try explain my problem better: > > In my library I have a parent->child control then when the parent is > deleted all children is deleted too. > > but in python I would like change this behavior, if there is some > python object using my child I will not delete this object. > I see. What if your parent held its children via shared_ptr<> objects ? If you then export the child's type with shared_ptr<> as HeldType, i.e. class_, ...> you should get what you want, since now all the communication across the language boundary is using shared_ptr<>, and the ref counts are correctly shared. With that, when the Python wrapper itself gets deleted by the Python runtime, it will decrement the shared_ptr<> counter you passed it. As your parents do the same, they can happily coexist with python references to the same objects. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From paniq at paniq.org Wed Dec 3 22:27:51 2008 From: paniq at paniq.org (Leonard Ritter) Date: Wed, 3 Dec 2008 22:27:51 +0100 Subject: [C++-sig] wrapper and shared_ptr - how to combine? In-Reply-To: <87skpaldg7.fsf@mcbain.luannocracy.com> References: <32c88000811150811p545ccfaaqc8a566ee1301dbc1@mail.gmail.com> <491EF6B0.3000208@sympatico.ca> <32c88000811151007r1ef9d422x2d9a6a80ca993002@mail.gmail.com> <32c88000811151148j737fc2a2m9d6a2905b3ea63a@mail.gmail.com> <32c88000811151258h7ba10e1aif18ab013db4434df@mail.gmail.com> <87skpaldg7.fsf@mcbain.luannocracy.com> Message-ID: <32c88000812031327i420c8880s6dbd27dd1c638057@mail.gmail.com> On Sat, Nov 29, 2008 at 5:11 PM, David Abrahams wrote: > Yoiks! You clearly need gSTLFilt. Please post such things as > attachments or in some other way that doesn't insert linebreaks. oh, awesome suggestion, thank you very much! gcc/eclipse outputs that stuff this way, and gmail inserts the linebreaks. > So the problem is that you're trying to wrap PyActor in a way that > implies it is default-constructible. But it's not; it's an abstract > class. You need no_init. See > thank you, i will remember your advice when i have that issue again. i solved the problem by writing the add/remove methods in python, which does fine so far. of all binding sets available, boost.python, although intellectually challenging, leaves no wishes open and provides the most coherent way to do C++ bindings. you have done extraordinary work there. what will you do when PyPy grows mature? ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From kekela at gmx.net Fri Dec 5 11:48:02 2008 From: kekela at gmx.net (kekela at gmx.net) Date: Fri, 05 Dec 2008 11:48:02 +0100 Subject: [C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial Message-ID: <20081205104802.172990@gmx.net> Hi, I'm new to boost and aiming to use boost:python and I am experiencing difficulties with the boost:python tutorial. While running bjam plain (i.e. with test targets and without --preserve-test-target or -n -a) creates nice test results (i.e. hello, hello.output and hello.test are created with "hello, world\n\nEXIT STATUS: 0" as well as "passed"), I cannot import hello_ext in python, when bjamming without test targets etc. But then again, maybe I shouldn't try to import hello_ext.so but have some kind of hello_ext.pyd? Well, what happens is this: [XXXX release]$ ls hello_ext.so hello.o [XXXX release]$ python Python 2.4.3 (#1, May 24 2008, 13:57:05) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hello_ext Traceback (most recent call last): File "", line 1, in ? ImportError: libboost_python-gcc41-1_37.so.1.37.0: cannot open shared object file: No such file or directory Actually I wasn't able to locate any libboost* files yet, but since the tests are passed, I'm probably doing something wrong. Please guide me! Thank you very much. From kekela at gmx.net Fri Dec 5 13:39:44 2008 From: kekela at gmx.net (kekela at gmx.net) Date: Fri, 05 Dec 2008 13:39:44 +0100 Subject: [C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial In-Reply-To: References: <20081205104802.172990@gmx.net> Message-ID: <20081205123944.274100@gmx.net> > Maybe your library path is incorrect. You may try (with bash) > export LD_LIBRARY_PATH=path_to_your_libboost_python-gcc41-1_37.so.1.37.0 Now it works. Well, yes, there were 3 issues. First, I had skipped the "make install" part in "getting started with boost", i.e. I didn't have any libboost* files (of which I know explicitly). Second, LD_LIBRARY_PATH was not set and, third, libboost_python-gcc41-1_37.so.1.37.0 didn't exist after making. I just copied "libboost_python-gcc41-mt-1_37.so.1.37.0" to "libboost_python-gcc41-1_37.so.1.37.0" in $LD_LIBRARY_PATH/. Thank you very much for your quick response. From pyplusplus at assumetheposition.nl Fri Dec 5 13:39:23 2008 From: pyplusplus at assumetheposition.nl (pyplusplus at assumetheposition.nl) Date: Fri, 5 Dec 2008 13:39:23 +0100 (CET) Subject: [C++-sig] Custom from-python converter (almost working) Message-ID: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> I'm trying to add some custom from-python converters to my bindings (see code at the end of the mail). These basically should convert Python 3-tuples of floats to a C++ vec3f instance. I can't seem to find reference docs on classes related to conversion, e.g. boost::python::converter::registry, so after some googling and experimenting I think the code at the end of this mail is a pretty clean implementation of what I want, and it almost fully works: Python 2.4.3 (#1, Jun 13 2006, 16:41:18) [GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import doh >>> doh.f((1,2,3)) 1.000000, 2.000000, 3.000000 >>> doh.p((1,2,3)) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in doh.p(tuple) did not match C++ signature: p(vec3f*) >>> So the implicit conversion to a pointer to a vec3f doesn't work. After some more googling I came across the thread [1], which seemed to suggest that there is another way of registering a converter, i.e. """ Don't try to convert to pointers; there are no pointers in Boost.Python; only lvalues and rvalues ;-) void* extract_foo(PyObject* op) { return FooObject_ptr(op); } boost::python::converter::registry::insert( &extractor_foo, boost::python::type_id()); """ In the February 2002 progress report [2] (does that reflect the current situation in 1.37 w.r.t. to/from-python converters, b.t.w?) it says: """There are basically two categories of from_python conversions: those which lvalues stored within or held by the Python object (essentially extractions), like what happens when an instance of a C++ class exposed with class_ is used as the target of a wrapped member function), and those in which a new rvalue gets created, as when a Python Float is converted to a C++ complex or a Python tuple is converted to a C++ std::vector<>""" It seems my non-working case of conversion to a vec3f* is of the latter category. Can I assume that the two different ways of registering a converter reflect these categories? If so, then I don't see a way to make this work, as I need actual conversion, not extraction, i.e. I need to create a new object that doesn't exist yet. Or should I register my converter in both ways to the registry? Any help is greatly appreciated, Regards, Paul [1] http://mail.python.org/pipermail/cplusplus-sig/2006-November/011269.html [2] http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/feb2002.html #include namespace bp = boost::python; struct vec3f { vec3f(): x(0), y(0), z(0) {} vec3f(float xx, float yy, float zz) { x = xx; y = yy; z = zz; } float x, y, z; }; struct convert_py_tuple_to_vec3f { convert_py_tuple_to_vec3f() { bp::converter::registry::push_back( &convertible, &construct, bp::type_id()); } // Check if given Python object is convertible to a vec3f. // If so, return obj, otherwise return 0 static void* convertible(PyObject* obj) { if (PyTuple_Check(obj)) return obj; return 0; } // Construct a vec3f object from the given Python object, and // store it in the stage1 (?) data. static void construct(PyObject* obj, bp::converter::rvalue_from_python_stage1_data* data) { // Fill in values float x, y, z; if (!PyArg_ParseTuple(obj, "fff", &x, &y, &z)) { // Raise exception, error will have been set by PyArg_ParseTuple boost::python::throw_error_already_set(); } typedef bp::converter::rvalue_from_python_storage vec3f_storage; void* const storage = reinterpret_cast(data)->storage.bytes; vec3f *v = new (storage) vec3f(x, y, z); data->convertible = storage; } }; void f(vec3f v) { printf("%f, %f, %f\n", v.x, v.y, v.z); } void p(vec3f *v) { printf("%f, %f, %f\n", v->x, v->y, v->z); } BOOST_PYTHON_MODULE(doh) { bp::class_< vec3f >("vec3f") .def(bp::init()) ; bp::def("f", &f); bp::def("p", &p); convert_py_tuple_to_vec3f(); } From macke at yar.nu Fri Dec 5 16:01:09 2008 From: macke at yar.nu (Marcus Lindblom) Date: Fri, 05 Dec 2008 16:01:09 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <4935423C.4030203@yar.nu> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> <4935423C.4030203@yar.nu> Message-ID: <49394235.5030909@yar.nu> Marcus Lindblom wrote: > Marcus Lindblom wrote: > >> (I don't think the gccxml-call happens because of the call to the >> ModuleBuilder at line 813, although I might be wrong?) > > Waitaminute. When I'm rerunning it now, the order makes more sense, and > the cache-calls come up after the calls to ModuleBuilder. Probably the > log-file merging of stdout and stderr was playing tricks on me. > > I'll look augmenting the ModuleBuilder call, just as you said. Sorry for > the confusion. :-/ I've gotten it to work. :) Now I just have to try to make it parse successfully, which it doesn't. :-/ How does gccxml work in compiler-work-alike mode? I've built with VS9, and am going to compile the wrappers with VS9, so I suppose I have to tell gccxml and the code to behave like that, with defines and all? (Or should that happen automatically?) Namely, I get some compile errors from gccxml on code that VS9 accepted, so I'm trying to figure out how to approach the problem, before going into specifics. Cheers, /Marcus From rwgk at yahoo.com Fri Dec 5 18:42:45 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 5 Dec 2008 09:42:45 -0800 (PST) Subject: [C++-sig] Custom from-python converter (almost working) References: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> Message-ID: <190802.95882.qm@web111403.mail.gq1.yahoo.com> > void > p(vec3f *v) > { > printf("%f, %f, %f\n", v->x, v->y, v->z); > } This is indeed not supported, since it would require "converters with write-back". vec3f const* v should work, but ve3f* v doesn't because the missing const indicates that you want to modify the pointee in place. For a Python tuple this can definitely not work since tuples are immutable. It could in theory work for a Python list, but Boost.Python doesn't support this. A few years ago we had extensive discussions about this, but it was too hard to implement. Ralf P.S.: I'm using this seasoned file for all "list/tuple/iter <-> small C++ array" conversions: http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/boost_python/container_conversions.h?view=markup Probably, all you need is tuple_mapping_fixed_capacity From roman.yakovenko at gmail.com Fri Dec 5 20:09:49 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 5 Dec 2008 21:09:49 +0200 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <49394235.5030909@yar.nu> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> <4935423C.4030203@yar.nu> <49394235.5030909@yar.nu> Message-ID: <7465b6170812051109x7d24c823l8ddcf89bcd8ff0c@mail.gmail.com> On Fri, Dec 5, 2008 at 5:01 PM, Marcus Lindblom wrote: > How does gccxml work in compiler-work-alike mode? I am not sure what you mean by this. GCC-XML doesn't tries to emulate other compilers. The configuration is used to find system and C++ header files. > I've built with VS9, and am going to compile the wrappers with VS9, so I > suppose I have to tell gccxml and the code to behave like that, with defines > and all? (Or should that happen automatically?) In your case, it doesn't really matter. Just select the compiler GCCXML supports better. I think this is one of Visual Studio 2003 or 2005. > Namely, I get some compile errors from gccxml on code that VS9 accepted, so > I'm trying to figure out how to approach the problem, before going into > specifics. The bottom line - you will have to change the code. GCCXML defines __GCCXML__ define. (http://gccxml.org/HTML/Running.html ). So you can introduce the changes for this compiler only. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From macke at yar.nu Fri Dec 5 16:01:09 2008 From: macke at yar.nu (Marcus Lindblom) Date: Fri, 05 Dec 2008 16:01:09 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <4935423C.4030203@yar.nu> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> <4935423C.4030203@yar.nu> Message-ID: <49394235.5030909@yar.nu> Marcus Lindblom wrote: > Marcus Lindblom wrote: > >> (I don't think the gccxml-call happens because of the call to the >> ModuleBuilder at line 813, although I might be wrong?) > > Waitaminute. When I'm rerunning it now, the order makes more sense, and > the cache-calls come up after the calls to ModuleBuilder. Probably the > log-file merging of stdout and stderr was playing tricks on me. > > I'll look augmenting the ModuleBuilder call, just as you said. Sorry for > the confusion. :-/ I've gotten it to work. :) Now I just have to try to make it parse successfully, which it doesn't. :-/ How does gccxml work in compiler-work-alike mode? I've built with VS9, and am going to compile the wrappers with VS9, so I suppose I have to tell gccxml and the code to behave like that, with defines and all? (Or should that happen automatically?) Namely, I get some compile errors from gccxml on code that VS9 accepted, so I'm trying to figure out how to approach the problem, before going into specifics. Cheers, /Marcus From adrien at saladin.fr Fri Dec 5 22:54:41 2008 From: adrien at saladin.fr (Adrien Saladin) Date: Fri, 5 Dec 2008 22:54:41 +0100 Subject: [C++-sig] ImportError...'No such file' etc. when importing hello_ext from tutorial In-Reply-To: <20081205123944.274100@gmx.net> References: <20081205104802.172990@gmx.net> <20081205123944.274100@gmx.net> Message-ID: > Now it works. Well, yes, there were 3 issues. First, I had skipped the "make install" part in "getting started with boost", i.e. I didn't have any libboost* files (of which I know explicitly). Second, LD_LIBRARY_PATH was not set and, third, libboost_python-gcc41-1_37.so.1.37.0 didn't exist after making. I just copied "libboost_python-gcc41-mt-1_37.so.1.37.0" to "libboost_python-gcc41-1_37.so.1.37.0" in $LD_LIBRARY_PATH/. > > Thank you very much for your quick response. You're welcome. I remember that you mentioned bjam, and if you like it then continue with it, but don't trust the documentation website: many other tools can compile and link with boost.python, not only bjam. I'm using SCons but make and cmake works as well. I'm telling that because I really dislike bjam syntax and when I began with boost.python I thought that boost.python was not for me just because of this building tool. Also if you begin with boost.python you must have a look at pyplusplus (or Py++), it's a very convenient tool that parses your C++ headers and generates boost.python code almost automatically. I'm using it for two years now and I'm really happy with it. There is also one problem with boost.python in general: library tends to become bigger and bigger with the number of functions and classes that you interface. Compile-time may also become an issue at some point. My library (~7000 lines of C++, 15 classes) now takes 50sec on a 8 cores 3Ghz computer. About 45sec are for the boost.python bindings... I'm now considering switching to pybindgen, but it's still a very new project that lacks some features of boost.python. Just curious, for what type of project do you wish to learn boost.python ? Best, Adrien From macke at yar.nu Sat Dec 6 10:52:50 2008 From: macke at yar.nu (Marcus Lindblom) Date: Sat, 06 Dec 2008 10:52:50 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <7465b6170812051109x7d24c823l8ddcf89bcd8ff0c@mail.gmail.com> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> <4935423C.4030203@yar.nu> <49394235.5030909@yar.nu> <7465b6170812051109x7d24c823l8ddcf89bcd8ff0c@mail.gmail.com> Message-ID: <493A4B72.8030707@yar.nu> Roman Yakovenko wrote: > On Fri, Dec 5, 2008 at 5:01 PM, Marcus Lindblom wrote: >> How does gccxml work in compiler-work-alike mode? [snip] > I am not sure what you mean by this. GCC-XML doesn't tries to emulate > other compilers. The configuration is used to find system and C++ > header files. [snip] > The bottom line - you will have to change the code. GCCXML defines > __GCCXML__ define. (http://gccxml.org/HTML/Running.html ). So you can > introduce the changes for this compiler only. That was exactly what I needed to know. Thanks a lot! /Marcus From macke at yar.nu Sat Dec 6 10:52:50 2008 From: macke at yar.nu (Marcus Lindblom) Date: Sat, 06 Dec 2008 10:52:50 +0100 Subject: [C++-sig] [py++] Problem: empty xml file created In-Reply-To: <7465b6170812051109x7d24c823l8ddcf89bcd8ff0c@mail.gmail.com> References: <4934F5DD.2060102@yar.nu> <7465b6170812020108x3520eedeq37a802152802c156@mail.gmail.com> <493534FA.1020703@yar.nu> <7465b6170812020528y2834955bp3a09b8c0a18026cc@mail.gmail.com> <49353FB5.20809@yar.nu> <4935423C.4030203@yar.nu> <49394235.5030909@yar.nu> <7465b6170812051109x7d24c823l8ddcf89bcd8ff0c@mail.gmail.com> Message-ID: <493A4B72.8030707@yar.nu> Roman Yakovenko wrote: > On Fri, Dec 5, 2008 at 5:01 PM, Marcus Lindblom wrote: >> How does gccxml work in compiler-work-alike mode? [snip] > I am not sure what you mean by this. GCC-XML doesn't tries to emulate > other compilers. The configuration is used to find system and C++ > header files. [snip] > The bottom line - you will have to change the code. GCCXML defines > __GCCXML__ define. (http://gccxml.org/HTML/Running.html ). So you can > introduce the changes for this compiler only. That was exactly what I needed to know. Thanks a lot! /Marcus From pyplusplus at assumetheposition.nl Mon Dec 8 10:34:28 2008 From: pyplusplus at assumetheposition.nl (pyplusplus at assumetheposition.nl) Date: Mon, 8 Dec 2008 10:34:28 +0100 (CET) Subject: [C++-sig] Custom from-python converter (almost working) In-Reply-To: <190802.95882.qm@web111403.mail.gq1.yahoo.com> References: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> <190802.95882.qm@web111403.mail.gq1.yahoo.com> Message-ID: <48434.146.50.22.50.1228728868.squirrel@www.assumetheposition.nl> Hi, >> void >> p(vec3f *v) >> { >> printf("%f, %f, %f\n", v->x, v->y, v->z); >> } > > This is indeed not supported, since it would require "converters with > write-back". Ok, that makes sense. > vec3f const* v > > should work, but > > ve3f* v > > doesn't because the missing const indicates that you want to modify the > pointee in place. Unfortunately I don't control the API. The actual use case I'm working on (the vec3f was just a simplified example) is a class method that takes a non-const pointer, but it does not modify the pointee. The pointee is basically stored in the instance and is used as a data array. As such I wanted a conversion from Python list of tuples to a C++ instance. > For a Python tuple this can definitely not work since tuples are > immutable. > It could in theory work for a Python list, but Boost.Python doesn't > support this. > A few years ago we had extensive discussions about this, but it was too > hard to > implement. I think I can imagine some obstacles :) In SWIG it is possible to simply define an extra class method that takes a PyObject* and perform any conversion you want in that method (although this means having to add that extra method for all cases where the non-const pointer is used). Would something similar work in Boost.Python, e.g. void extra_method(C& self, PyObject *obj) { } class_("C") > > Ralf > > P.S.: I'm using this seasoned file for all "list/tuple/iter <-> small C++ > array" conversions: > > http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/boost_python/container_conversions.h?view=markup > > Probably, all you need is > > tuple_mapping_fixed_capacity > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From pyplusplus at assumetheposition.nl Mon Dec 8 10:37:58 2008 From: pyplusplus at assumetheposition.nl (pyplusplus at assumetheposition.nl) Date: Mon, 8 Dec 2008 10:37:58 +0100 (CET) Subject: [C++-sig] Custom from-python converter (almost working) In-Reply-To: <48434.146.50.22.50.1228728868.squirrel@www.assumetheposition.nl> References: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> <190802.95882.qm@web111403.mail.gq1.yahoo.com> <48434.146.50.22.50.1228728868.squirrel@www.assumetheposition.nl> Message-ID: <49804.146.50.22.50.1228729078.squirrel@www.assumetheposition.nl> Dang, my mailer got in the way and sent this before I finished it ... > Hi, > >>> void >>> p(vec3f *v) >>> { >>> printf("%f, %f, %f\n", v->x, v->y, v->z); >>> } >> >> This is indeed not supported, since it would require "converters with >> write-back". > > Ok, that makes sense. > >> vec3f const* v >> >> should work, but >> >> ve3f* v >> >> doesn't because the missing const indicates that you want to modify the >> pointee in place. > > Unfortunately I don't control the API. The actual use case I'm working on > (the vec3f was just a simplified example) is a class method that takes a > non-const pointer, but it does not modify the pointee. The pointee is > basically stored in the instance and is used as a data array. As such I > wanted a conversion from Python list of tuples to a C++ instance. > >> For a Python tuple this can definitely not work since tuples are >> immutable. >> It could in theory work for a Python list, but Boost.Python doesn't >> support this. >> A few years ago we had extensive discussions about this, but it was too >> hard to >> implement. > > I think I can imagine some obstacles :) > In SWIG it is possible to simply define an extra class method that takes a PyObject* and perform any conversion you want in that method (although this means having to add that extra method for all cases where the non-const pointer is used). Would something similar work in Boost.Python, e.g. class C { public: void set_data(data* d); }; void extra_method(C& self, PyObject *obj) { // if obj is list of tuples, convert to // data* and // call self.set_data(d) } class_("C") .def("set_data", &C::set_data) .def("set_data", &C::extra_method) ; Or will this completely muck up the way Python objects are handled on the interface? >> Ralf >> >> P.S.: I'm using this seasoned file for all "list/tuple/iter <-> small >> C++ >> array" conversions: >> >> http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/boost_python/container_conversions.h?view=markup >> >> Probably, all you need is >> >> tuple_mapping_fixed_capacity Thanks for the hint, Paul From pyplusplus at assumetheposition.nl Mon Dec 8 15:23:50 2008 From: pyplusplus at assumetheposition.nl (pyplusplus at assumetheposition.nl) Date: Mon, 8 Dec 2008 15:23:50 +0100 (CET) Subject: [C++-sig] Getting address of wrapped instance? Message-ID: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> Is there are way to get the address of the C++ instance pointed to by a given Boost.Python wrapper object? I don't need a real pointer, the address alone suffices. The use case is to deduce interrelations between C++ objects (think a DAG) from Python. As different Python wrapper objects might reference the same C++ instance I can't use id() or repr() of the Python object. Thanks, Paul From renatox at gmail.com Mon Dec 8 15:36:15 2008 From: renatox at gmail.com (Renato Araujo) Date: Mon, 8 Dec 2008 11:36:15 -0300 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> Message-ID: <95291a80812080636s6cc9acddm34d800cfee5fe5b1@mail.gmail.com> Hi Paul, Maybe this can help you: http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#xref I use: python::object o(python::ptr(my_cpp_pointer)); then I got the python object. BR On Mon, Dec 8, 2008 at 11:23 AM, wrote: > Is there are way to get the address of the C++ instance pointed to by a > given Boost.Python wrapper object? I don't need a real pointer, the > address alone suffices. > > The use case is to deduce interrelations between C++ objects (think a DAG) > from Python. As different Python wrapper objects might reference the same > C++ instance I can't use id() or repr() of the Python object. > > Thanks, > Paul > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Renato Araujo Oliveira Filho From pyplusplus at assumetheposition.nl Mon Dec 8 16:04:41 2008 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Mon, 8 Dec 2008 16:04:41 +0100 (CET) Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <95291a80812080636s6cc9acddm34d800cfee5fe5b1@mail.gmail.com> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <95291a80812080636s6cc9acddm34d800cfee5fe5b1@mail.gmail.com> Message-ID: <46765.146.50.22.50.1228748681.squirrel@www.assumetheposition.nl> Hello Renato, On Mon, December 8, 2008 3:36 pm, Renato Araujo wrote: > Maybe this can help you: > http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#xref > > I use: > python::object o(python::ptr(my_cpp_pointer)); > > then I got the python object. Unfortunately, I need the (address of) the wrapped C++ instance from a Python wrapper object, not a Python wrapper object for a C++ instance. Paul > > BR > > On Mon, Dec 8, 2008 at 11:23 AM, wrote: >> Is there are way to get the address of the C++ instance pointed to by a >> given Boost.Python wrapper object? I don't need a real pointer, the >> address alone suffices. >> >> The use case is to deduce interrelations between C++ objects (think a >> DAG) >> from Python. As different Python wrapper objects might reference the >> same >> C++ instance I can't use id() or repr() of the Python object. >> >> Thanks, >> Paul >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > > -- > Renato Araujo Oliveira Filho > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From seefeld at sympatico.ca Mon Dec 8 16:12:06 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 08 Dec 2008 10:12:06 -0500 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> Message-ID: <493D3946.3030801@sympatico.ca> pyplusplus at assumetheposition.nl wrote: > Is there are way to get the address of the C++ instance pointed to by a > given Boost.Python wrapper object? I don't need a real pointer, the > address alone suffices. > You may try using type const &ref = extract(object); HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From pyplusplus at assumetheposition.nl Mon Dec 8 16:23:49 2008 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Mon, 8 Dec 2008 16:23:49 +0100 (CET) Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <493D3946.3030801@sympatico.ca> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <493D3946.3030801@sympatico.ca> Message-ID: <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> On Mon, December 8, 2008 4:12 pm, Stefan Seefeld wrote: > pyplusplus at assumetheposition.nl wrote: >> Is there are way to get the address of the C++ instance pointed to by a >> given Boost.Python wrapper object? I don't need a real pointer, the >> address alone suffices. >> > > You may try using > > type const &ref = extract(object); Hmmm, reading my own post I now see I wasn't completely clear. I need this *in Python*. So for a given Python instance that wraps a C++ instance I need the address of the wrapped C++ instance. Paul > > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From meine at informatik.uni-hamburg.de Mon Dec 8 17:33:11 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 8 Dec 2008 17:33:11 +0100 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <493D3946.3030801@sympatico.ca> <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> Message-ID: <200812081733.12323.meine@informatik.uni-hamburg.de> On Monday 08 December 2008 16:23:49 Paul Melis wrote: > On Mon, December 8, 2008 4:12 pm, Stefan Seefeld wrote: > > You may try using > > > > type const &ref = extract(object); > > Hmmm, reading my own post I now see I wasn't completely clear. > > I need this *in Python*. So for a given Python instance that wraps a C++ > instance I need the address of the wrapped C++ instance. How about adding an id() method (returning this) to the C++ class and exporting that? HTH, Hans From seefeld at sympatico.ca Mon Dec 8 17:42:53 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 08 Dec 2008 11:42:53 -0500 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <200812081733.12323.meine@informatik.uni-hamburg.de> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <493D3946.3030801@sympatico.ca> <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> <200812081733.12323.meine@informatik.uni-hamburg.de> Message-ID: <493D4E8D.7000700@sympatico.ca> Hans Meine wrote: > How about adding an id() method (returning this) to the C++ class and > exporting that? > Well, this 'id' isn't really a property of the wrapped type / object, but the wrapper. So, I think there is little sense in adding such a tautological 'id' function to the class itself. A free-standing type const *id(type const *t) { return t;} function would be more clean, IMO. my 2 cents, Stefan -- ...ich hab' noch einen Koffer in Berlin... From gjcarneiro at gmail.com Mon Dec 8 17:49:00 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Mon, 8 Dec 2008 16:49:00 +0000 Subject: [C++-sig] ANN: PyBindGen 0.10 released Message-ID: PyBindGen is a Python module that is geared to generating C/C++ code that binds a C/C++ library for Python. It does so without extensive use of either C++ templates or C pre-processor macros. It has modular handling of C/C++ types, and can be easily extended with Python plugins. The generated code is almost as clean as what a human programmer would write. It can be downloaded from: http://code.google.com/p/pybindgen/ Bug reports should be filed here: https://bugs.launchpad.net/pybindgen === pybindgen 0.10 === - New null_ok, default_value options for pointer-to-class parameters; - Thread safety fixes; - Map C++ operator() into Python's tp_call (__call__); - Initial support for std containers (except mapping containers); - Generate __copy__ methods for classes with copy constructor; - Add 'wrapper registry' optional feature (off by default): allows C++ instances returned by pointer to be consistently wrapped always by the same Python wrapper, so that the 'is' operator can be used for identity testing; - New C type expression parser, is_const not longer needed for parameter types, just put const in the type string as appropriate; - Sort the declarations returned by (py)gccxml. If generating python script files from gccxml scanning, now the output file becomes more stable and less prone to move declarations up and down with different people scanning and the output file is under version control; - Map binary comparison operators (< <= == >= >) from C++ to Python; - Map some binary numeric operators (+ - * /) from C++ to Python; - Allow installation of pybindgen even if no C/C++ compiler is detected; - Fix compatibility with older Python versions (tested with 2.3, 2.4, and 2.5) -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Mon Dec 8 18:11:09 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 8 Dec 2008 09:11:09 -0800 (PST) Subject: [C++-sig] Custom from-python converter (almost working) References: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> <190802.95882.qm@web111403.mail.gq1.yahoo.com> <48434.146.50.22.50.1228728868.squirrel@www.assumetheposition.nl> <49804.146.50.22.50.1228729078.squirrel@www.assumetheposition.nl> Message-ID: <2754.79036.qm@web111402.mail.gq1.yahoo.com> > In SWIG it is possible to simply define an extra class method that takes a > PyObject* and perform any conversion you want in that method (although > this means having to add that extra method for all cases where the > non-const pointer is used). Would something similar work in Boost.Python, > e.g. > > class C > { > public: > void set_data(data* d); > }; > > void > extra_method(C& self, PyObject *obj) > { > // if obj is list of tuples, convert to > // data* and > // call self.set_data(d) > } > > class_("C") > .def("set_data", &C::set_data) > .def("set_data", &C::extra_method) > ; Yes, this should work if you use boost::python::object: void extra_method(C& self, boost::python::object obj) The conversion code in the body of this function will probably be similar to what you see in the container_conversion.h file. You could also use void extra_method(C& self, boost::python::list list_of_tuples) which will save you one manual conversion step. Ralf From Matthew.Scouten at tradingtechnologies.com Mon Dec 8 18:16:00 2008 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Mon, 8 Dec 2008 11:16:00 -0600 Subject: [C++-sig] Pickle an enum from c++ Message-ID: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01> >From the lack of response I assume that no one has any clever ideas to make an enum pickleable. Thank you to anyone who put thought into this. If I come up anything that works, I will let the group know. From: Matthew Scouten (TT) Sent: Tuesday, December 02, 2008 2:24 PM To: Development of Python/C++ integration Subject: Pickle an enum from c++ I have an enum in my c++ library. In fact I have a crap load of them. 169 to be exact. I need them to be pickle-able. The enum_ object does not have a .def_pickle function, so I cannot use the pickle suite. I tried to just up and pickle it but that does not work either. enum box {cardboard, cereal, toy}; BOOST_PYTHON_MODULE(busybox) { enum_("box") .value("cardboard",cardboard ) .value("cereal",cereal ) .value("toy", toy); } C:\Documents and Settings\mscouten>cd C:\tt-dev\manticore\ C:\tt-dev\manticore>call setpath.bat Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pickle, busybox >>> >>> b = busybox.box.toy >>> >>> bs = pickle.dumps(b) Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "C:\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python25\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "C:\Python25\lib\pickle.py", line 401, in save_reduce save(args) File "C:\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python25\lib\pickle.py", line 562, in save_tuple save(element) File "C:\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python25\lib\pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle : it's not found as __main__.busybox.box >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Mon Dec 8 19:34:45 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 8 Dec 2008 20:34:45 +0200 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <493D4E8D.7000700@sympatico.ca> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <493D3946.3030801@sympatico.ca> <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> <200812081733.12323.meine@informatik.uni-hamburg.de> <493D4E8D.7000700@sympatico.ca> Message-ID: <7465b6170812081034y4a67f08aobcfc69b41738d209@mail.gmail.com> On Mon, Dec 8, 2008 at 6:42 PM, Stefan Seefeld wrote: > Hans Meine wrote: >> >> How about adding an id() method (returning this) to the C++ class and >> exporting that? >> > > Well, this 'id' isn't really a property of the wrapped type / object, but > the wrapper. So, I think there is little sense in adding such a tautological > 'id' function to the class itself. A free-standing > > type const *id(type const *t) { return t;} > > function would be more clean, IMO. I think he wants size_t as return type: template< class type > size_t id( const type* t ){ return size_t( t ); } class_< XXX >(....) .def( "id", &id ); Py++ has this and other functionality to allow better experience, while exposing "C" libraries: http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html http://language-binding.net/pyplusplus/documentation/ctypes/this_and_sizeof.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Dec 8 20:02:41 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 8 Dec 2008 21:02:41 +0200 Subject: [C++-sig] Pickle an enum from c++ In-Reply-To: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01> References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01> Message-ID: <7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com> 2008/12/8 Matthew Scouten (TT) : > From the lack of response I assume that no one has any clever ideas to make > an enum pickleable. Thank you to anyone who put thought into this. :-). I thought about work around: you can define your enums in Python. May be youcan add this functionality from Python? Also did you see the following discussion? http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From meine at informatik.uni-hamburg.de Tue Dec 9 13:40:17 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Tue, 9 Dec 2008 13:40:17 +0100 Subject: [C++-sig] Pickle an enum from c++ In-Reply-To: <7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com> References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01> <7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com> Message-ID: <200812091340.17902.meine@informatik.uni-hamburg.de> On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote: > 2008/12/8 Matthew Scouten (TT) : > > From the lack of response I assume that no one has any clever ideas to > > make an enum pickleable. Thank you to anyone who put thought into this. > > > :-). > > I thought about work around: you can define your enums in Python. May > be youcan add this functionality from Python? > > Also did you see the following discussion? > http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html Oh, this is continued here: http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html Looks like there was a solution in 2006; Ralf even wanted to have a test case for check-in. Ralf, did you receive stuff from Shashank back then? (Or did you wait until today with committing the fix?) Greetings, Hans From rwgk at yahoo.com Tue Dec 9 17:02:36 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 9 Dec 2008 08:02:36 -0800 (PST) Subject: [C++-sig] Pickle an enum from c++ References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01> <7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com> <200812091340.17902.meine@informatik.uni-hamburg.de> Message-ID: <947038.27443.qm@web111408.mail.gq1.yahoo.com> Indeed (I had forgotten this already...): ------------------------------------------------------------------------ r36256 | rwgk | 2006-12-03 12:43:48 -0800 (Sun, 03 Dec 2006) | 2 lines fixes to support pickling of enums (by Shashank Bapat) ------------------------------------------------------------------------ And there is this test (boost/libs/python/test/enum.py): # pickling of enums only works with Python 2.3 or higher exercise_pickling = ''' >>> import pickle >>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL) >>> l = pickle.loads(p) >>> identity(l) enum_ext.color.green ''' So this is supposed to work. ----- Original Message ---- From: Hans Meine To: Development of Python/C++ integration Cc: Ralf W. Grosse-Kunstleve Sent: Tuesday, December 9, 2008 4:40:17 AM Subject: Re: [C++-sig] Pickle an enum from c++ On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote: > 2008/12/8 Matthew Scouten (TT) : > > From the lack of response I assume that no one has any clever ideas to > > make an enum pickleable. Thank you to anyone who put thought into this. > > > :-). > > I thought about work around: you can define your enums in Python. May > be youcan add this functionality from Python? > > Also did you see the following discussion? > http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html Oh, this is continued here: http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html Looks like there was a solution in 2006; Ralf even wanted to have a test case for check-in. Ralf, did you receive stuff from Shashank back then? (Or did you wait until today with committing the fix?) Greetings, Hans From pyplusplus at assumetheposition.nl Tue Dec 9 20:10:37 2008 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Tue, 09 Dec 2008 20:10:37 +0100 Subject: [C++-sig] Custom from-python converter (almost working) In-Reply-To: <2754.79036.qm@web111402.mail.gq1.yahoo.com> References: <34319.146.50.22.50.1228480763.squirrel@www.assumetheposition.nl> <190802.95882.qm@web111403.mail.gq1.yahoo.com> <48434.146.50.22.50.1228728868.squirrel@www.assumetheposition.nl> <49804.146.50.22.50.1228729078.squirrel@www.assumetheposition.nl> <2754.79036.qm@web111402.mail.gq1.yahoo.com> Message-ID: <493EC2AD.4040603@assumetheposition.nl> Ralf W. Grosse-Kunstleve wrote: >> In SWIG it is possible to simply define an extra class method that takes a >> PyObject* and perform any conversion you want in that method (although >> this means having to add that extra method for all cases where the >> non-const pointer is used). Would something similar work in Boost.Python, >> e.g. >> >> class C >> { >> public: >> void set_data(data* d); >> }; >> >> void >> extra_method(C& self, PyObject *obj) >> { >> // if obj is list of tuples, convert to >> // data* and >> // call self.set_data(d) >> } >> >> class_("C") >> .def("set_data", &C::set_data) >> .def("set_data", &C::extra_method) >> ; >> > > Yes, this should work if you use boost::python::object: > > void > extra_method(C& self, boost::python::object obj) > > The conversion code in the body of this function will probably be > similar to what you see in the container_conversion.h file. > > You could also use > > void > extra_method(C& self, boost::python::list list_of_tuples) > > which will save you one manual conversion step. > Hey, that's really nice! I'll try that... Thanks, Paul From pyplusplus at assumetheposition.nl Tue Dec 9 20:11:20 2008 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Tue, 09 Dec 2008 20:11:20 +0100 Subject: [C++-sig] Getting address of wrapped instance? In-Reply-To: <7465b6170812081034y4a67f08aobcfc69b41738d209@mail.gmail.com> References: <46613.146.50.22.50.1228746230.squirrel@www.assumetheposition.nl> <493D3946.3030801@sympatico.ca> <46846.146.50.22.50.1228749829.squirrel@www.assumetheposition.nl> <200812081733.12323.meine@informatik.uni-hamburg.de> <493D4E8D.7000700@sympatico.ca> <7465b6170812081034y4a67f08aobcfc69b41738d209@mail.gmail.com> Message-ID: <493EC2D8.7070001@assumetheposition.nl> Roman Yakovenko wrote: > On Mon, Dec 8, 2008 at 6:42 PM, Stefan Seefeld wrote: > >> Hans Meine wrote: >> >>> How about adding an id() method (returning this) to the C++ class and >>> exporting that? >>> >>> >> Well, this 'id' isn't really a property of the wrapped type / object, but >> the wrapper. So, I think there is little sense in adding such a tautological >> 'id' function to the class itself. A free-standing >> >> type const *id(type const *t) { return t;} >> >> function would be more clean, IMO. >> > > I think he wants size_t as return type: > > template< class type > > size_t id( const type* t ){ return size_t( t ); } > > class_< XXX >(....) > .def( "id", &id ); > > This is indeed what I was looking for, thanks! Paul > Py++ has this and other functionality to allow better experience, > while exposing "C" libraries: > > http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html > http://language-binding.net/pyplusplus/documentation/ctypes/this_and_sizeof.html > > From jeremie.delaitre at technogerma.fr Wed Dec 10 17:08:55 2008 From: jeremie.delaitre at technogerma.fr (=?ISO-8859-1?Q?J=E9r=E9mie_Delaitre?=) Date: Wed, 10 Dec 2008 17:08:55 +0100 Subject: [C++-sig] Dynamic resolution of members and methods Message-ID: <493FE997.2050005@technogerma.fr> Hello, I have a C++ class that use a custom property system. This property system allows me to add and remove properties at runtime. I want to expose this class into Python. The problem is: I want "a dynamic resolution" of the properties in Python. For example: # import my python extension import myModule # get an instance of my C++ class t = myModule.newInstance() # access the property 'myProperty' print(t.myProperty) When I access the property, I want python to call a "callback" of mine (written in the C++ extension) which will check if the requested property exists, and if it does, return the corresponding value, otherwise generate an exception. By looking at the python C API, I did not find a way to achieve this. It seems that declaring a new type requires to have static arrays for members and methods (yes, my property system allows me to declare new methods too, so I want to expose them with a similar system). Any idea how I could resolve this (with Python3.0) ? Regards, J?r?mie Delaitre From amohr at pixar.com Wed Dec 10 18:55:48 2008 From: amohr at pixar.com (Alex Mohr) Date: Wed, 10 Dec 2008 09:55:48 -0800 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <493FE997.2050005@technogerma.fr> References: <493FE997.2050005@technogerma.fr> Message-ID: <494002A4.5070101@pixar.com> Override the python special methods __getattr__ or __getattribute__. http://docs.python.org/reference/datamodel.html#attribute-access Alex J?r?mie Delaitre wrote: > Hello, > > I have a C++ class that use a custom property system. > This property system allows me to add and remove properties at runtime. > > I want to expose this class into Python. > > The problem is: I want "a dynamic resolution" of the properties in Python. > > For example: > > # import my python extension > import myModule > > # get an instance of my C++ class > t = myModule.newInstance() > > # access the property 'myProperty' > print(t.myProperty) > > When I access the property, I want python to call a "callback" of mine > (written > in the C++ extension) which will check if the requested property exists, > and > if it does, return the corresponding value, otherwise generate an > exception. > > By looking at the python C API, I did not find a way to achieve this. It > seems > that declaring a new type requires to have static arrays for members and > methods > (yes, my property system allows me to declare new methods too, so I want > to expose > them with a similar system). > > Any idea how I could resolve this (with Python3.0) ? > > Regards, > > J?r?mie Delaitre > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From luca.sbardella at gmail.com Thu Dec 11 16:29:34 2008 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Thu, 11 Dec 2008 15:29:34 +0000 Subject: [C++-sig] conversion problem Message-ID: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> My authomatic conversion function from std::pair does not work when one of the pair type is a boost::python::object. Template for conversion template struct pair_to_tuple { typedef pair_to_tuple converter; typedef std::pair ctype; static PyObject* convert(ctype const& v) { using namespace boost::python; return incref(make_tuple(v.first,v.second).ptr()); } static void register_to_python() { boost::python::to_python_converter(); } }; using namespace boost::python; pair_to_tuple::register_to_python(); <--------- FAILED pair_to_tuple::register_to_python(); <--------- OK The error I get is *error C2668: 'boost::python::make_tuple' : ambiguous call to overloaded function could be 'boost::python::tuple boost::python::make_tuple<_Ty1,_Ty2>(const A0 &,const A1 &)'** or 'boost::tuples::tuple boost::tuples::make_tuple<_Ty1,_Ty2>(const T0 &,const T1 &)' [found using argument-dependent lookup] * What I'm I doing wrong?* * -------------- next part -------------- An HTML attachment was scrubbed... URL: From paniq at paniq.org Thu Dec 11 17:18:26 2008 From: paniq at paniq.org (Leonard Ritter) Date: Thu, 11 Dec 2008 17:18:26 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set Message-ID: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> hi everyone, i'm having a problem where a boost::python::throw_error_already_set is being thrown and causes a segfault (linux). unfortunately the error happens from within python, when reaching the end of an iteration through a vector array, which was exported using the vector indexing suite. is there any possibility to catch the previous exception? -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Thu Dec 11 17:32:49 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 11 Dec 2008 11:32:49 -0500 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> Message-ID: <494140B1.1040200@sympatico.ca> Leonard Ritter wrote: > hi everyone, > > i'm having a problem where a boost::python::throw_error_already_set is > being thrown and causes a segfault (linux). unfortunately the error > happens from within python, when reaching the end of an iteration > through a vector array, which was exported using the vector indexing > suite. > > is there any possibility to catch the previous exception? That's hard to tell without more context: Who is doing the iteration, for example ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From sipickles at hotmail.com Fri Dec 12 10:00:11 2008 From: sipickles at hotmail.com (Simon Pickles) Date: Fri, 12 Dec 2008 09:00:11 +0000 Subject: [C++-sig] Need help with inheritance problem Message-ID: Hi, I am trying to expose part of the bullet dynamics library to my python code. I simply need to expose a few accessors of a type btVector3. This inherits from a class which is itself derived. I seem to be struggling to get this right. Here is my attempt: BOOST_PYTHON_MODULE(HybridZone) { using namespace boost::python; class_("btQuadWordStorage") ; // I am trying to expose getX() class_ >("btQuadWord") .def("getX", &btQuadWord::getX, return_internal_reference<1, with_custodian_and_ward<1, 2> >()); //.add_property("x", &btQuadWord::x) // doesn't compile either ; class_ >("btVector3", init()) ; } You can see my structure is an attempt to mimic the inheritance diagram found here http://www.continuousphysics.com/Bullet/BulletFull/classbtVector3.html I am trying to expose btVector3::getX(), inherited from btQuadWord Thanks for your time and advice. Simon ps: heres the error message, on gcc4.2.4, Ubuntu 8.04: ...updating 3 targets... gcc.compile.c++ bin/gcc-4.2.4/debug/HybridZone.o /home/simon/Source/boost_1_37_0/boost/python/object/make_instance.hpp: In static member function \u2018static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = float*, T = float, Holder = boost::python::objects::pointer_holder, Derived = boost::python::objects::make_ptr_instance >]\u2019: /home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:106: instantiated from \u2018static PyObject* boost::python::detail::make_reference_holder::execute(T*) [with T = float]\u2019 /home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:70: instantiated from \u2018PyObject* boost::python::to_python_indirect::execute(const U&, mpl_::false_) const [with U = float, T = const float&, MakeHolder = boost::python::detail::make_reference_holder]\u2019 /home/simon/Source/boost_1_37_0/boost/python/to_python_indirect.hpp:41: instantiated from \u2018PyObject* boost::python::to_python_indirect::operator()(const U&) const [with U = float, T = const float&, MakeHolder = boost::python::detail::make_reference_holder]\u2019 /home/simon/Source/boost_1_37_0/boost/python/detail/invoke.hpp:88: instantiated from \u2018PyObject* boost::python::detail::invoke(boost::python::detail::invoke_tag_, const RC&, F&, TC&) [with RC = boost::python::to_python_indirect, F = const btScalar& (btQuadWord::*)()const, TC = boost::python::arg_from_python]\u2019 /home/simon/Source/boost_1_37_0/boost/python/detail/caller.hpp:223: instantiated from \u2018PyObject* boost::python::detail::caller_arity<1u>::impl::operator()(PyObject*, PyObject*) [with F = const btScalar& (btQuadWord::*)()const, Policies = boost::python::return_internal_reference<1u, boost::python::with_custodian_and_ward<1u, 2u, boost::python::default_call_policies> >, Sig = boost::mpl::vector2]\u2019 /home/simon/Source/boost_1_37_0/boost/python/object/py_function.hpp:38: instantiated from \u2018PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller >, boost::mpl::vector2 >]\u2019 HybridZone.cpp:88: instantiated from here /home/simon/Source/boost_1_37_0/boost/python/object/make_instance.hpp:24: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018boost::STATIC_ASSERTION_FAILURE\u2019 "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -DBOOST_DATE_TIME_DYN_LINK=1 -DDATE_TIME_INLINE -I"/home/simon/Source/boost_1_37_0" -I"/home/simon/Source/bullet-2.72/src" -I"/usr/local/include/python2.5" -c -o "bin/gcc-4.2.4/debug/HybridZone.o" "HybridZone.cpp" ...failed gcc.compile.c++ bin/gcc-4.2.4/debug/HybridZone.o... ...skipped HybridZone.so for lack of HybridZone.o... ...skipped HybridZone.so for lack of HybridZone.so... ...failed updating 1 target... ...skipped 2 targets... -- Linux Counter: User# 424693 From nico_ml at mgdesign.org Fri Dec 12 10:48:35 2008 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Fri, 12 Dec 2008 10:48:35 +0100 Subject: [C++-sig] Bug and patch for boost.python withenable_shared_from_this References: <229148.259.qm@web31108.mail.mud.yahoo.com> Message-ID: <006501c95c3e$cd570610$d100a8c0@nicopc> Hi, > Could you at least ask Peter Dimov if he thinks the > dont_enable_shared_from_this patch could be generally useful? > Maybe he's OK adding it, then it wouldn't be a big deal > fixing Boost.Python, which would probably prevent a lot of > confusion and lost time in the future. I stumbled once again on this problem, so I took some time to bother Peter Dimov with the patch suggestion. Here, is a copy of our exchange : Hello Peter, I wanted to contact you about a problem that was raised, on february, on c++-sig mailing list about a problem happening when wrapping classes derived from 'enable_shared_from_this' using boost.python library. The problem is briefly described in this post - including a patch to boost/shared_ptr.hpp that would allow to fix the problem. http://mail.python.org/pipermail/cplusplus-sig/2008-February/012973.html The original poster was encouraged by Ralf W. Grosse-Kunstleve to contact you about this, but we never heard from him on the list (http://mail.python.org/pipermail/cplusplus-sig/2008-February/013003.html). To make it short, boost.python creates shared_ptr objects, holding the wrapped c++ objects, with a custom deleter managing the python object reference count. This leads to something like that : #include namespace { class A : public boost::enable_shared_from_this { public: ~A() {}; }; void my_deleter(void*) { } }; BOOST_AUTO_TEST_CASE( test_enable_shared_from_this ) { boost::shared_ptr a( new A ); { boost::shared_ptr ater = boost::shared_ptr( a.get(), my_deleter ); // OP patch proposal :: boost::shared_ptr ater = boost::shared_ptr( a.get(), my_deleter // , boost::dont_enable_shared_from_this() ); BOOST_CHECK( a == ater ); } boost::shared_ptr abug = a->shared_from_this(); // this throws bad_weak_ptr } Did you hear about this problem ? Do you think this patch is viable and could be applied in boost trunk ? Do you happen to have another idea of workaround that could be applied in client code and/or in shared_ptr ? Thanks for your time, best regards, Nicolas Lelong mgdesign Followed by Peter's answer that lead to Trac ticket #2584 : Yes, I am aware of this problem. It is possible today to emulate the proposed functionality by using the aliasing constructor, but I think that a more proper fix for the issue is to make enable_shared_from_this more intelligent so that it doesn't reinitialize itself in such scenarios. I'll appreciate it if you file a Trac ticket for this and assign it to me. I've a few pending enable_shared_from_this issues anyway, and I'll try to find the time to address them before the next release ships. -- Peter Dimov http://www.pdplayer.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From luca.sbardella at gmail.com Fri Dec 12 12:54:20 2008 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Fri, 12 Dec 2008 11:54:20 +0000 Subject: [C++-sig] conversion problem In-Reply-To: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> References: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> Message-ID: <8315652a0812120354y38388043o68e8a4dbd84d9311@mail.gmail.com> I substituted the convert method in pair_to_tuple with the following static PyObject* convert(ctype const& v) { using namespace boost::python; list values; values.append(v.first); values.append(v.second); return incref(tuple(values).ptr()); } And this works in all situations. However, I admit it is not a great solution. 2008/12/11 Luca Sbardella > My authomatic conversion function from std::pair does not work when one of > the pair type is a boost::python::object. > > Template for conversion > > template > struct pair_to_tuple { > typedef pair_to_tuple converter; > typedef std::pair ctype; > > static PyObject* convert(ctype const& v) { > using namespace boost::python; > return incref(make_tuple(v.first,v.second).ptr()); > } > static void register_to_python() { > boost::python::to_python_converter(); > } > }; > > > > > using namespace boost::python; > pair_to_tuple::register_to_python(); <--------- > FAILED > pair_to_tuple::register_to_python(); <--------- OK > > The error I get is > *error C2668: 'boost::python::make_tuple' : ambiguous call to overloaded > function > could be 'boost::python::tuple boost::python::make_tuple<_Ty1,_Ty2>(const > A0 &,const A1 &)'** > or 'boost::tuples::tuple > boost::tuples::make_tuple<_Ty1,_Ty2>(const T0 &,const T1 &)' [found using > argument-dependent lookup] > * > What I'm I doing wrong?* > * -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeremie.delaitre at technogerma.fr Fri Dec 12 13:02:00 2008 From: jeremie.delaitre at technogerma.fr (=?ISO-8859-1?Q?J=E9r=E9mie_Delaitre?=) Date: Fri, 12 Dec 2008 13:02:00 +0100 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <494002A4.5070101@pixar.com> References: <493FE997.2050005@technogerma.fr> <494002A4.5070101@pixar.com> Message-ID: <494252B8.4040608@technogerma.fr> It works ! Thanks a lot. J?r?mie Alex Mohr a ?crit : > Override the python special methods __getattr__ or __getattribute__. > > http://docs.python.org/reference/datamodel.html#attribute-access > > Alex > > J?r?mie Delaitre wrote: >> Hello, >> >> I have a C++ class that use a custom property system. >> This property system allows me to add and remove properties at runtime. >> >> I want to expose this class into Python. >> >> The problem is: I want "a dynamic resolution" of the properties in >> Python. >> >> For example: >> >> # import my python extension >> import myModule >> >> # get an instance of my C++ class >> t = myModule.newInstance() >> >> # access the property 'myProperty' >> print(t.myProperty) >> >> When I access the property, I want python to call a "callback" of >> mine (written >> in the C++ extension) which will check if the requested property >> exists, and >> if it does, return the corresponding value, otherwise generate an >> exception. >> >> By looking at the python C API, I did not find a way to achieve this. >> It seems >> that declaring a new type requires to have static arrays for members >> and methods >> (yes, my property system allows me to declare new methods too, so I >> want to expose >> them with a similar system). >> >> Any idea how I could resolve this (with Python3.0) ? >> >> Regards, >> >> J?r?mie Delaitre >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From meine at informatik.uni-hamburg.de Fri Dec 12 13:23:04 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 12 Dec 2008 13:23:04 +0100 Subject: [C++-sig] conversion problem In-Reply-To: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> References: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> Message-ID: <200812121323.05522.meine@informatik.uni-hamburg.de> On Thursday 11 December 2008 16:29:34 Luca Sbardella wrote: > The error I get is > *error C2668: 'boost::python::make_tuple' : ambiguous call to overloaded > function > could be 'boost::python::tuple boost::python::make_tuple<_Ty1,_Ty2>(const > A0 &,const A1 &)'** > or 'boost::tuples::tuple > boost::tuples::make_tuple<_Ty1,_Ty2>(const T0 &,const T1 &)' [found using > argument-dependent lookup] Did you try explicitly writing boost::python::make_tuple instead of just make_tuple? -> The above error msg. shows that the second function is from a completely different namespace (boost::tuples). That should be more proper than your list-solution. Greetings, Hans From renatox at gmail.com Fri Dec 12 13:48:59 2008 From: renatox at gmail.com (Renato Araujo) Date: Fri, 12 Dec 2008 09:48:59 -0300 Subject: [C++-sig] take ownership in a call policy Message-ID: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> Hi guys, I'm creating a 2 new call_policy to my functions where I need take and give back the ownership of my object. I would like reproduce this in my precall or postcall function policy functions. http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#ownership How I can do this? How I can get a ref to auto_ptr or shared_ptr from my PyObject? Thanks -- Renato Araujo Oliveira Filho From luca.sbardella at gmail.com Fri Dec 12 15:11:04 2008 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Fri, 12 Dec 2008 14:11:04 +0000 Subject: [C++-sig] conversion problem In-Reply-To: <200812121323.05522.meine@informatik.uni-hamburg.de> References: <8315652a0812110729q7bb7fddfo8288e6db7a665ec9@mail.gmail.com> <200812121323.05522.meine@informatik.uni-hamburg.de> Message-ID: <8315652a0812120611q6136a662i573f67239156e5ae@mail.gmail.com> you are right, that was silly. thanks a lot 2008/12/12 Hans Meine > On Thursday 11 December 2008 16:29:34 Luca Sbardella wrote: > > The error I get is > > *error C2668: 'boost::python::make_tuple' : ambiguous call to overloaded > > function > > could be 'boost::python::tuple boost::python::make_tuple<_Ty1,_Ty2>(const > > A0 &,const A1 &)'** > > or 'boost::tuples::tuple > > boost::tuples::make_tuple<_Ty1,_Ty2>(const T0 &,const T1 &)' [found using > > argument-dependent lookup] > > Did you try explicitly writing boost::python::make_tuple instead of just > make_tuple? -> The above error msg. shows that the second function is from > a > completely different namespace (boost::tuples). > > That should be more proper than your list-solution. > > Greetings, > Hans > > _______________________________________________ > 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 nico_ml at mgdesign.org Fri Dec 12 15:55:16 2008 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Fri, 12 Dec 2008 15:55:16 +0100 Subject: [C++-sig] Bug and patch for boost.pythonwithenable_shared_from_this References: <229148.259.qm@web31108.mail.mud.yahoo.com> <006501c95c3e$cd570610$d100a8c0@nicopc> Message-ID: <17fe01c95c69$a505c4f0$d100a8c0@nicopc> FWIW, it seems I can't reproduce the problem with current boost svn trunk code, the problem still existed in boost_1_37_0 though. I could not spot the changes made that fixed the problem. I took a look at the shared_ptr aliasing constructor, and made a patch to my boost_1_37_0 that solves the problem without altering shared_ptr code. All boost.python tests still pass after that. It may be useful to someone (the test case from Chad is attached) --- python_1_37\converter\shared_ptr_from_python.hpp 2008-12-12 15:49:04.156250000 +0100 +++ python\converter\shared_ptr_from_python.hpp 2008-12-12 14:24:24.781250000 +0100 @@ -45,10 +45,14 @@ if (data->convertible == source) new (storage) shared_ptr(); else + { + boost::shared_ptr hold_convertible_ref_count( (void*)0, shared_ptr_deleter(handle<>(borrowed(source))) ); + // use aliasing constructor new (storage) shared_ptr( - static_cast(data->convertible), - shared_ptr_deleter(handle<>(borrowed(source))) + hold_convertible_ref_count, + static_cast(data->convertible) ); + } data->convertible = storage; } --- to include the test in python test pass : Index: libs/python/test/Jamfile.v2 =================================================================== --- libs/python/test/Jamfile.v2 (revision 72) +++ libs/python/test/Jamfile.v2 (working copy) @@ -75,6 +75,7 @@ [ bpl-test return_arg ] [ bpl-test staticmethod ] [ bpl-test shared_ptr ] +[ bpl-test enable_shared_from_this ] [ bpl-test andreas_beyer ] [ bpl-test polymorphism ] [ bpl-test polymorphism2 ] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: enable_shared_from_this.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: enable_shared_from_this.py Type: application/octet-stream Size: 600 bytes Desc: not available URL: From Matthew.Scouten at tradingtechnologies.com Fri Dec 12 16:55:32 2008 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Fri, 12 Dec 2008 09:55:32 -0600 Subject: [C++-sig] Pickle an enum from c++ In-Reply-To: <947038.27443.qm@web111408.mail.gq1.yahoo.com> References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01><7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com><200812091340.17902.meine@informatik.uni-hamburg.de> <947038.27443.qm@web111408.mail.gq1.yahoo.com> Message-ID: <32490DFF7774554A85D65D23A9F0F93809AF0663@chiex01> Is there something I am supposed to do to the enum_ to make it work? If I try to 'dumps()' my enum I still get the exception I included in my earlier email. Funny thing, dumps-ing it with cPickle just gets the exception, while dumps-ing it with regular pickle also produces a crash from within the bowels of Python25.dll. -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Tuesday, December 09, 2008 10:03 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Pickle an enum from c++ Indeed (I had forgotten this already...): ------------------------------------------------------------------------ r36256 | rwgk | 2006-12-03 12:43:48 -0800 (Sun, 03 Dec 2006) | 2 lines fixes to support pickling of enums (by Shashank Bapat) ------------------------------------------------------------------------ And there is this test (boost/libs/python/test/enum.py): # pickling of enums only works with Python 2.3 or higher exercise_pickling = ''' >>> import pickle >>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL) >>> l = pickle.loads(p) >>> identity(l) enum_ext.color.green ''' So this is supposed to work. ----- Original Message ---- From: Hans Meine To: Development of Python/C++ integration Cc: Ralf W. Grosse-Kunstleve Sent: Tuesday, December 9, 2008 4:40:17 AM Subject: Re: [C++-sig] Pickle an enum from c++ On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote: > 2008/12/8 Matthew Scouten (TT) : > > From the lack of response I assume that no one has any clever ideas to > > make an enum pickleable. Thank you to anyone who put thought into this. > > > :-). > > I thought about work around: you can define your enums in Python. May > be youcan add this functionality from Python? > > Also did you see the following discussion? > http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html Oh, this is continued here: http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html Looks like there was a solution in 2006; Ralf even wanted to have a test case for check-in. Ralf, did you receive stuff from Shashank back then? (Or did you wait until today with committing the fix?) Greetings, Hans _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From rwgk at yahoo.com Fri Dec 12 17:29:02 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 12 Dec 2008 08:29:02 -0800 (PST) Subject: [C++-sig] Pickle an enum from c++ References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01><7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com><200812091340.17902.meine@informatik.uni-hamburg.de> <947038.27443.qm@web111408.mail.gq1.yahoo.com> <32490DFF7774554A85D65D23A9F0F93809AF0663@chiex01> Message-ID: <714948.24769.qm@web111404.mail.gq1.yahoo.com> > Is there something I am supposed to do to the enum_ to make it work? Did you look at thid test? boost/libs/python/test/enum.cpp Do you have the .export_values()? (Not sure if that's important; I never use enum.) Ralf From Matthew.Scouten at tradingtechnologies.com Fri Dec 12 19:01:26 2008 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Fri, 12 Dec 2008 12:01:26 -0600 Subject: [C++-sig] Pickle an enum from c++ In-Reply-To: <714948.24769.qm@web111404.mail.gq1.yahoo.com> References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01><7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com><200812091340.17902.meine@informatik.uni-hamburg.de><947038.27443.qm@web111408.mail.gq1.yahoo.com><32490DFF7774554A85D65D23A9F0F93809AF0663@chiex01> <714948.24769.qm@web111404.mail.gq1.yahoo.com> Message-ID: <32490DFF7774554A85D65D23A9F0F93809AF0748@chiex01> No, that didn't make a difference. -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Friday, December 12, 2008 10:29 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Pickle an enum from c++ > Is there something I am supposed to do to the enum_ to make it work? Did you look at thid test? boost/libs/python/test/enum.cpp Do you have the .export_values()? (Not sure if that's important; I never use enum.) Ralf _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From rwgk at yahoo.com Fri Dec 12 19:23:21 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 12 Dec 2008 10:23:21 -0800 (PST) Subject: [C++-sig] Pickle an enum from c++ References: <32490DFF7774554A85D65D23A9F0F93809A51DA7@chiex01><7465b6170812081102m3236d3d5w5b7634abbe77a8b@mail.gmail.com><200812091340.17902.meine@informatik.uni-hamburg.de><947038.27443.qm@web111408.mail.gq1.yahoo.com><32490DFF7774554A85D65D23A9F0F93809AF0663@chiex01> <714948.24769.qm@web111404.mail.gq1.yahoo.com> <32490DFF7774554A85D65D23A9F0F93809AF0748@chiex01> Message-ID: <913058.62639.qm@web111402.mail.gq1.yahoo.com> Could you try if the enum test works with your version of boost? What version do you have? I just tried it out (using the current boost svn trunk) and it works for me. I think it should work with any boost version after Dec 2006. Note that you have to use pickle.HIGHEST_PROTOCOL as in the test, otherwise it crashes. ----- Original Message ---- From: Matthew Scouten (TT) To: Development of Python/C++ integration Sent: Friday, December 12, 2008 10:01:26 AM Subject: Re: [C++-sig] Pickle an enum from c++ No, that didn't make a difference. -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Friday, December 12, 2008 10:29 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Pickle an enum from c++ > Is there something I am supposed to do to the enum_ to make it work? Did you look at thid test? boost/libs/python/test/enum.cpp Do you have the .export_values()? (Not sure if that's important; I never use enum.) Ralf From hugo.lima at openbossa.org Fri Dec 12 20:39:13 2008 From: hugo.lima at openbossa.org (Hugo Lima) Date: Fri, 12 Dec 2008 16:39:13 -0300 Subject: [C++-sig] take ownership in a call policy In-Reply-To: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> References: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> Message-ID: <7ebf1b2a0812121139h3ba149e2rb16ee96c18a701f9@mail.gmail.com> On Fri, Dec 12, 2008 at 9:48 AM, Renato Araujo wrote: > Hi guys, > > I'm creating a 2 new call_policy to my functions where I need take and > give back the ownership of my object. I would like reproduce this in > my precall or postcall function policy functions. > > http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#ownership > > How I can do this? How I can get a ref to auto_ptr or shared_ptr from > my PyObject? Good question! > > > Thanks > -- > Renato Araujo Oliveira Filho > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From smnemeth at gmail.com Fri Dec 12 22:13:03 2008 From: smnemeth at gmail.com (Rocketman@JSC) Date: Fri, 12 Dec 2008 13:13:03 -0800 (PST) Subject: [C++-sig] boost::python::throw_error_already_set not in library Message-ID: <20983772.post@talk.nabble.com> Seems like this function only gets built into the debug version. We built the gcc library for 1.35 and it only appears in the libboost_python_gcc32-mt-d-1_35 version. Does anyone know why this does not get built into the non-debug version or how to make it get built in? TIA, Scott -- View this message in context: http://www.nabble.com/boost%3A%3Apython%3A%3Athrow_error_already_set-not-in-library-tp20983772p20983772.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From dave at boostpro.com Fri Dec 12 23:45:30 2008 From: dave at boostpro.com (David Abrahams) Date: Fri, 12 Dec 2008 17:45:30 -0500 Subject: [C++-sig] boost::python::throw_error_already_set not in library In-Reply-To: <20983772.post@talk.nabble.com> (smnemeth@gmail.com's message of "Fri, 12 Dec 2008 13:13:03 -0800 (PST)") References: <20983772.post@talk.nabble.com> Message-ID: <87hc59au7p.fsf@mcbain.luannocracy.com> on Fri Dec 12 2008, "Rocketman-AT-JSC" wrote: > Seems like this function only gets built into the debug version. Are you certain? It's hard to imagine that's actually the case. > We built the gcc library for 1.35 and it only appears in the > libboost_python_gcc32-mt-d-1_35 version. How did you do the build? > Does anyone know why this does not get built into the non-debug version or > how to make it get built in? There's nothing different about that function from many of the other functions that are compiled into the library. You can see it for yourself in the source. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From smnemeth at gmail.com Sat Dec 13 00:08:20 2008 From: smnemeth at gmail.com (Rocketman@JSC) Date: Fri, 12 Dec 2008 15:08:20 -0800 (PST) Subject: [C++-sig] boost::python::throw_error_already_set not in library In-Reply-To: <87hc59au7p.fsf@mcbain.luannocracy.com> References: <20983772.post@talk.nabble.com> <87hc59au7p.fsf@mcbain.luannocracy.com> Message-ID: <20985178.post@talk.nabble.com> Yes it's probably user error--but I have no clue why this is happening. I did not do the build and the guy doing the build is not an expert boost user either. We have two builds one with gcc and one with intel. Notice the non-debug versions don't have the symbol. Here are the results from objdump: /ips/fd/analysis2/proto/oss/lib $ ls libboost_python-* libboost_python-gcc32-mt-1_35.so libboost_python-gcc32-mt-d.so libboost_python-il-mt-1_36.so.1.36.0 libboost_python-gcc32-mt-1_35.so.1.35.0 libboost_python-gcc32-mt.so libboost_python-il-mt.a libboost_python-gcc32-mt-d-1_35.so libboost_python-il-mt-1_36.a libboost_python-il-mt.so libboost_python-gcc32-mt-d-1_35.so.1.35.0 libboost_python-il-mt-1_36.so /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-il-mt*.so | grep throw_error_already_set /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-gcc32-mt.so | grep throw_error_already_set /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-gcc32-mt-d.so | grep throw_error_already_set 0009cd14 g F .text 0000007c _ZN5boost6python23throw_error_already_setEv -- View this message in context: http://www.nabble.com/boost%3A%3Apython%3A%3Athrow_error_already_set-not-in-library-tp20983772p20985178.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From dave at boostpro.com Sat Dec 13 02:05:23 2008 From: dave at boostpro.com (David Abrahams) Date: Fri, 12 Dec 2008 20:05:23 -0500 Subject: [C++-sig] boost::python::throw_error_already_set not in library In-Reply-To: <20985178.post@talk.nabble.com> (smnemeth@gmail.com's message of "Fri, 12 Dec 2008 15:08:20 -0800 (PST)") References: <20983772.post@talk.nabble.com> <87hc59au7p.fsf@mcbain.luannocracy.com> <20985178.post@talk.nabble.com> Message-ID: <87oczganqk.fsf@mcbain.luannocracy.com> on Fri Dec 12 2008, "Rocketman-AT-JSC" wrote: > Yes it's probably user error--but I have no clue why this is happening. I > did not do the build and the guy doing the build is not an expert boost user > either. Did he use bjam? You can verify the build by following the Boost.Python tutorial to make sure that build/test works. The library you build and the one linked to by the tutorial should be identical, apart from SONAME and associated mangling. > We have two builds one with gcc and one with intel. Notice the > non-debug versions don't have the symbol. Here are the results from > objdump: > > /ips/fd/analysis2/proto/oss/lib $ ls libboost_python-* > libboost_python-gcc32-mt-1_35.so libboost_python-gcc32-mt-d.so > libboost_python-il-mt-1_36.so.1.36.0 > libboost_python-gcc32-mt-1_35.so.1.35.0 libboost_python-gcc32-mt.so > libboost_python-il-mt.a > libboost_python-gcc32-mt-d-1_35.so libboost_python-il-mt-1_36.a > libboost_python-il-mt.so > libboost_python-gcc32-mt-d-1_35.so.1.35.0 libboost_python-il-mt-1_36.so > > /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-il-mt*.so | > grep throw_error_already_set > > /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-gcc32-mt.so | > grep throw_error_already_set > > /ips/fd/analysis2/proto/oss/lib $ objdump -t libboost_python-gcc32-mt-d.so | > grep throw_error_already_set > 0009cd14 g F .text 0000007c > _ZN5boost6python23throw_error_already_setEv This doesn't make any sense to me. I don't see the string "throw_error_already_set" in the grep output. is this really what came up on your console? Anyway, I think you need to use objdump -T/--dynamic-syms, not objdump -t/--syms. The non-debug ones don't show /any/ symbols if you use -t. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From dave at boostpro.com Sat Dec 13 02:08:51 2008 From: dave at boostpro.com (David Abrahams) Date: Fri, 12 Dec 2008 20:08:51 -0500 Subject: [C++-sig] take ownership in a call policy In-Reply-To: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> (Renato Araujo's message of "Fri, 12 Dec 2008 09:48:59 -0300") References: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> Message-ID: <87fxksanks.fsf@mcbain.luannocracy.com> on Fri Dec 12 2008, "Renato Araujo" wrote: > Hi guys, > > I'm creating a 2 new call_policy to my functions where I need take and > give back the ownership of my object. I would like reproduce this in > my precall or postcall function policy functions. > > http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#ownership > > How I can do this? How I can get a ref to auto_ptr or shared_ptr from > my PyObject? I'm sorry, I don't understand the question. Could you please show the function signature you're trying to wrap and describe the ownership semantics required? Thanks, -- Dave Abrahams BoostPro Computing http://www.boostpro.com From renatox at gmail.com Sat Dec 13 03:52:37 2008 From: renatox at gmail.com (Renato Araujo) Date: Fri, 12 Dec 2008 21:52:37 -0500 Subject: [C++-sig] take ownership in a call policy In-Reply-To: <87fxksanks.fsf@mcbain.luannocracy.com> References: <95291a80812120448u502fd079ja803c734b4b15040@mail.gmail.com> <87fxksanks.fsf@mcbain.luannocracy.com> Message-ID: <95291a80812121852s713d6d05u5bfb3782447001cd@mail.gmail.com> Thanks David I will try explain more about my problems with ownership: I already expose this problem before here the ideas not fit yet. This is my problem. attention: I can't change the c++ code; struct object { object(object *parent=0) { //if (parent): append myself in parent child list (parent take ownership of object, parent will delete this object) } void set_parent(object *parent) { //the same case of constructor: if parent is null remove old parent } void add_child(object *child) { //add child in my children list get ownership } void remove_child(object *child) { //remove child from my list, give back the ownership to the child object } ~object() { // destroy all children; } private: list children; } this is a simple example how c++ code works, we have allot of others functions to get ownership of a object, then is impossible rewrite all functions like in the boost python FAQ example: (http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#ownership) I thinking about create a call policy to do this for me. One for take ownership and another to restore ownership. I'm trying do something like that, I don't know if this is the best idea, sugestions are welcome: class("object", init< optional >()[parent_child_policy_add<2,1>()]) .def("set_parent", &object::set_parent, parent_child_policy_add<2,1>()) //this case (index 2 = arg1) = parent object, (index 1 = self) = child object .def("remove_child", &object::remove_child, parent_child_policy_remove<1,2>() //this case self is the parent and arg1 is the child I know how implement a call policy and get access to PyObject from child and parent. What I don't know is how inform to boost to not delete c++ object during the python object destructor (in parent_child_policy_add) because this will be done by the parent, or inform to boost to delete the c++ object (in parent_child_policy_remove) because the object no have parent. On Fri, Dec 12, 2008 at 8:08 PM, David Abrahams wrote: > > on Fri Dec 12 2008, "Renato Araujo" wrote: > >> Hi guys, >> >> I'm creating a 2 new call_policy to my functions where I need take and >> give back the ownership of my object. I would like reproduce this in >> my precall or postcall function policy functions. >> >> http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#ownership >> >> How I can do this? How I can get a ref to auto_ptr or shared_ptr from >> my PyObject? > > I'm sorry, I don't understand the question. Could you please show the > function signature you're trying to wrap and describe the ownership > semantics required? > > Thanks, > > -- > Dave Abrahams > BoostPro Computing > http://www.boostpro.com > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Renato Araujo Oliveira Filho From dave at boostpro.com Sun Dec 14 20:47:26 2008 From: dave at boostpro.com (David Abrahams) Date: Sun, 14 Dec 2008 19:47:26 -0000 Subject: [C++-sig] Passing C++ instance to embedded py In-Reply-To: <20081120161605.1C4E.FILEOFFSET@gmail.com> (fileoffset@gmail.com's message of "Thu, 20 Nov 2008 16:29:49 +1100") References: <20081120161605.1C4E.FILEOFFSET@gmail.com> Message-ID: <87k5a2ilo9.fsf@mcbain.luannocracy.com> on Thu Nov 20 2008, fileoffset wrote: > To best explain my problem, here is some code: > > struct A > { > A() > { > mTest = 1; > > std::cout << "Test: " << mTest; > > Py_Initialize(); > object main_module = import("__main__"); > object main_namespace = main_module.attr("__dict__"); > > main_namespace["A_Instance"] = this; > > object result = exec_file(str("test.py"), main_namespace, > main_namespace); > > std::cout << "Test: " << mTest; > } > > int mTest; > } > > in main.cpp or similar: > > BOOST_PYTHON_MODULE(MyModule) > { > class_("A", init<>()) > .def_readwrite("Test", &A::mTest) > ; > } > > test.py: > > from MyModule import * > > A_Instance.Test = 5 > > > Essentially I want to be able to access and modify the properties of an instance of a > C++ class > at runtime. > > When I try code similar to above, python excepts, as I believe it > attempts to copy-construct the A class instead of just pass the > reference (this) so that i can modify it. Correct. > > Is what I want possible? If not what would be a better way to do it? main_module.attr("A_Instance") = ptr(this); object d = main_module.attr("__dict__"); object result = exec_file(str("test.py"), d, d); main_module.attr("A_Instance") = object(); // don't leave a dangling reference (http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/callbacks.html#argument_handling) -- Dave Abrahams BoostPro Computing http://www.boostpro.com From paniq at paniq.org Sun Dec 14 23:22:51 2008 From: paniq at paniq.org (Leonard Ritter) Date: Sun, 14 Dec 2008 23:22:51 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <494140B1.1040200@sympatico.ca> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> Message-ID: <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> On Thu, Dec 11, 2008 at 5:32 PM, Stefan Seefeld wrote: > Leonard Ritter wrote: > >> hi everyone, >> >> i'm having a problem where a boost::python::throw_error_already_set is >> being thrown and causes a segfault (linux). unfortunately the error happens >> from within python, when reaching the end of an iteration through a vector >> array, which was exported using the vector indexing suite. >> >> is there any possibility to catch the previous exception? >> > > That's hard to tell without more context: Who is doing the iteration, for > example ? python code. i don't have the feeling that the issue is really related to your library. some machines do not cause that exception. the problem is that this is very hard to track for me. this is not meant to sound rough, but i would prefer if you would not try to find the problem for me, but give me instructions how i can deal with such problems myself. this is not the only situation where i get throw_error_already_set exceptions, and i have no idea how to track them down. is such stuff unusual? did no one else get these? thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeremie.delaitre at technogerma.fr Mon Dec 15 13:58:29 2008 From: jeremie.delaitre at technogerma.fr (=?ISO-8859-1?Q?J=E9r=E9mie_Delaitre?=) Date: Mon, 15 Dec 2008 13:58:29 +0100 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <494252B8.4040608@technogerma.fr> References: <493FE997.2050005@technogerma.fr> <494002A4.5070101@pixar.com> <494252B8.4040608@technogerma.fr> Message-ID: <49465475.5090205@technogerma.fr> Hi, When defining my new type in C++, I have set the "tp_getattro" field to point to a function (say "mytype_getattro"). This function determine dynamically if the requested attribute exists or not, and if it does, return its value. So, it works well for attributes/properties. But, "mytype_getattro" is also called when, in Python, I do a function call 'myobject.myfct(...)'. It allows me to determine dynamically if the requested function "myfct" is available or not. But if it does, I need to return a callable object to allow python to process the call. I succeeded to make Python to call a function of mine using a PyMethodDef array and using the Py_FindMethod function to get a callable PyObject*. But it is not a good solution for at least two reasons : 1 - Py_FindMethod is not supported in Python 3.0 2 - I need to declare each possible function in the array (which is impossible has I need to determine them at runtime) What I have tried to do is to declare only one "dipatch" function in the array which will call the right C++ function. This way, in "mytype_getattro" I do a "return Py_FindMethod(myarray, self, "dispatch")". Thus, python call my dispatching method. The problem is that I need to attach additionnal values to the function (like the name of the function which must be called in reality). In Lua, I used the closure mechanism, but I did not success with Python closures. Any hints ? Is closure the right approach (If so, how I should use it ?)? Do I need to set another field when defining my type ? Regards, J?r?mie Delaitre J?r?mie Delaitre a ?crit : > > It works ! Thanks a lot. > > J?r?mie > > Alex Mohr a ?crit : >> Override the python special methods __getattr__ or __getattribute__. >> >> http://docs.python.org/reference/datamodel.html#attribute-access >> >> Alex >> >> J?r?mie Delaitre wrote: >>> Hello, >>> >>> I have a C++ class that use a custom property system. >>> This property system allows me to add and remove properties at runtime. >>> >>> I want to expose this class into Python. >>> >>> The problem is: I want "a dynamic resolution" of the properties in >>> Python. >>> >>> For example: >>> >>> # import my python extension >>> import myModule >>> >>> # get an instance of my C++ class >>> t = myModule.newInstance() >>> >>> # access the property 'myProperty' >>> print(t.myProperty) >>> >>> When I access the property, I want python to call a "callback" of >>> mine (written >>> in the C++ extension) which will check if the requested property >>> exists, and >>> if it does, return the corresponding value, otherwise generate an >>> exception. >>> >>> By looking at the python C API, I did not find a way to achieve >>> this. It seems >>> that declaring a new type requires to have static arrays for members >>> and methods >>> (yes, my property system allows me to declare new methods too, so I >>> want to expose >>> them with a similar system). >>> >>> Any idea how I could resolve this (with Python3.0) ? >>> >>> Regards, >>> >>> J?r?mie Delaitre >>> >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From renatox at gmail.com Mon Dec 15 15:17:16 2008 From: renatox at gmail.com (Renato Araujo) Date: Mon, 15 Dec 2008 11:17:16 -0300 Subject: [C++-sig] custom constructor problems Message-ID: <95291a80812150617x7b727926keeccdf8b813ccecc@mail.gmail.com> Hi again :D, To solve my old problem, I'm trying create custom constructor which return a shared_ptr like that code: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class my_class_wrapper : my_class, python::wrapper { ...... } shared_ptr _create_object(parent *p) { return shared_ptr(new my_class_wrapper(p), _my_delete_function); } shared_ptr _create_object2() { return shared_ptr(new my_class_wrapper(0), _my_delete_function); } class_("MyClass", python::no_init) .def("__init__", python::make_constructor(_create_object)) .def("__init__", python::make_constructor(_create_object2)) .def("get_parent", &MyClass:getParent, return_value_policy()); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- but during my python test, the function get_parent not return the same python object created in the object constructor. my test is: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- parent = MyClass() child = MyClass(parent) if (child.get_parent() != parent) print "FAIL" else print "OK" -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Always I got the "FAIL" message, but if I remove the custom constructor the test pass. What I doing wrong all my classes inherit from "python::wrapper". Then I think all classes have implicit conversion to "shared_ptr" correct? BR -- Renato Araujo Oliveira Filho From paniq at paniq.org Mon Dec 15 16:39:12 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 16:39:12 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> Message-ID: <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> On Sun, Dec 14, 2008 at 11:22 PM, Leonard Ritter wrote: > That's hard to tell without more context: Who is doing the iteration, for >> example ? > > I'm sorry. I was a bit stressed out yesterday. I recognize that you only want to help, and I should be more patient. Here is the top part of a stack trace, as it usually occurs: #0 0xb65593dc in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6 #1 0xb6a85a9e in boost::python::throw_error_already_set () from /usr/lib/libboost_python-gcc42-1_34_1-py25.so.1.34.1 #2 0xb6a88ab1 in boost::python::objects::stop_iteration_error () from /usr/lib/libboost_python-gcc42-1_34_1-py25.so.1.34.1 #3 0xb6ca38c3 in boost::python::objects::iterator_range, __gnu_cxx::__normal_iterator > > >::next::operator() (this=0x9931cec, self=@0x91fcfcc) at /usr/include/boost/python/object/iterator.hpp:64 This problem occurred first when iterating an array that was exported through the indexing suite. I do not have anything else that uses StopIteration, so I can't say if it's really a problem of the indexing suite. My guess is: no. When I rewrote the offending code to be a simple get-by-index operation, the next (above) part where an iteration would be caused inside C++ code created a problem. So somehow I end up with an unhandled python exception in boost that does not get forwarded - my guess. Could this in some way relate to assertions (put by assert()) put in the C++ code? Something like: boost catches these assertions, converts them into exceptions, then iterates a bit, hits a StopIteration and has the previously unhandled exception still active? I am just wildly guessing here. Please help! -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Mon Dec 15 17:09:03 2008 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 15 Dec 2008 11:09:03 -0500 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> Message-ID: <4946811F.5010505@resophonic.com> Hey Leonard, Here's a short doc about running python scripts that load boost::python bindings under gdb: http://software.icecube.wisc.edu/offline-software.trunk/gdb_python.html In short (i'm guessing this is more or less what you'll need): gdb --args /usr/bin/python /path/to/my/python/script.py run # it runs, throws an exception, but the stacktrace isn't helpful catch throw # this only works after the first run run # jackpot, you're at the point of the throw -t Leonard Ritter wrote: > On Sun, Dec 14, 2008 at 11:22 PM, Leonard Ritter wrote: > >> That's hard to tell without more context: Who is doing the iteration, for >>> example ? >> > I'm sorry. I was a bit stressed out yesterday. I recognize that you only > want to help, and I should be more patient. > > Here is the top part of a stack trace, as it usually occurs: > > #0 0xb65593dc in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6 > #1 0xb6a85a9e in boost::python::throw_error_already_set () > from /usr/lib/libboost_python-gcc42-1_34_1-py25.so.1.34.1 > #2 0xb6a88ab1 in boost::python::objects::stop_iteration_error () > from /usr/lib/libboost_python-gcc42-1_34_1-py25.so.1.34.1 > #3 0xb6ca38c3 in > boost::python::objects::iterator_range boost::python::default_call_policies>, > __gnu_cxx::__normal_iterator std::vector > > >> ::next::operator() (this=0x9931cec, > self=@0x91fcfcc) at /usr/include/boost/python/object/iterator.hpp:64 > > This problem occurred first when iterating an array that was exported > through the indexing suite. I do not have anything else that uses > StopIteration, so I can't say if it's really a problem of the indexing > suite. My guess is: no. When I rewrote the offending code to be a simple > get-by-index operation, the next (above) part where an iteration would be > caused inside C++ code created a problem. So somehow I end up with an > unhandled python exception in boost that does not get forwarded - my guess. > > Could this in some way relate to assertions (put by assert()) put in the C++ > code? Something like: boost catches these assertions, converts them into > exceptions, then iterates a bit, hits a StopIteration and has the previously > unhandled exception still active? I am just wildly guessing here. > > Please help! > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From seefeld at sympatico.ca Mon Dec 15 17:27:28 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 15 Dec 2008 11:27:28 -0500 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <4946811F.5010505@resophonic.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> Message-ID: <49468570.4010808@sympatico.ca> troy d. straszheim wrote: > > In short (i'm guessing this is more or less what you'll need): > > gdb --args /usr/bin/python /path/to/my/python/script.py > run > # it runs, throws an exception, but the stacktrace isn't helpful > catch throw # this only works after the first run > run > # jackpot, you're at the point of the throw The throw point isn't very interesting in this case: In Python, iteration is terminated by means of a 'StopIteration' exception. The question is why this exception manages to escape uncaught. FWIW, Stefan -- ...ich hab' noch einen Koffer in Berlin... From paniq at paniq.org Mon Dec 15 17:29:57 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 17:29:57 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <49468570.4010808@sympatico.ca> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> Message-ID: <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> On Mon, Dec 15, 2008 at 5:27 PM, Stefan Seefeld wrote: > The throw point isn't very interesting in this case: In Python, iteration > is terminated by means of a 'StopIteration' exception. The question is why > this exception manages to escape uncaught. i tried both 1.34.1 and 1.35.0 available in my distribution (ubuntu), same problem. i am fetching through the boost.python code to see if i can find something interesting. -------------- next part -------------- An HTML attachment was scrubbed... URL: From paniq at paniq.org Mon Dec 15 17:33:28 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 17:33:28 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> Message-ID: <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> On Mon, Dec 15, 2008 at 5:29 PM, Leonard Ritter wrote: > On Mon, Dec 15, 2008 at 5:27 PM, Stefan Seefeld wrote: > >> The throw point isn't very interesting in this case: In Python, iteration >> is terminated by means of a 'StopIteration' exception. The question is why >> this exception manages to escape uncaught. > > > i tried both 1.34.1 and 1.35.0 available in my distribution (ubuntu), same > problem. i am fetching through the boost.python code to see if i can find > something interesting. > i should add that this problem does not happen on other machines with the SAME distribution installed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From paniq at paniq.org Mon Dec 15 17:38:09 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 17:38:09 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> Message-ID: <32c88000812150838j678e598fh1badf15351a6b8bd@mail.gmail.com> On Mon, Dec 15, 2008 at 5:33 PM, Leonard Ritter wrote: > On Mon, Dec 15, 2008 at 5:29 PM, Leonard Ritter wrote: > >> On Mon, Dec 15, 2008 at 5:27 PM, Stefan Seefeld wrote: >> >>> The throw point isn't very interesting in this case: In Python, iteration >>> is terminated by means of a 'StopIteration' exception. The question is why >>> this exception manages to escape uncaught. >> >> >> i tried both 1.34.1 and 1.35.0 available in my distribution (ubuntu), same >> problem. i am fetching through the boost.python code to see if i can find >> something interesting. >> > > i should add that this problem does not happen on other machines with the > SAME distribution installed. > ...and the error generated is a segfault, no standard exception! -------------- next part -------------- An HTML attachment was scrubbed... URL: From paniq at paniq.org Mon Dec 15 17:48:30 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 17:48:30 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150838j678e598fh1badf15351a6b8bd@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> <32c88000812150838j678e598fh1badf15351a6b8bd@mail.gmail.com> Message-ID: <32c88000812150848g541b3fa1vb36445b7b1b26f42@mail.gmail.com> On Mon, Dec 15, 2008 at 5:38 PM, Leonard Ritter wrote: > i tried both 1.34.1 and 1.35.0 available in my distribution (ubuntu), same >>> problem. i am fetching through the boost.python code to see if i can find >>> something interesting. >>> >> >> i should add that this problem does not happen on other machines with the >> SAME distribution installed. >> > > ...and the error generated is a segfault, no standard exception! > searching for __cxa_allocate_exception segfault i got quite a few hits in different projects, of which this wiki entry devotes a whole page to the issue: http://wiki.fifengine.de/Segfault_in_cxa_allocate_exception The funny thing is: I never got the problem on a machine with an nVidia driver. The two machines who have the reported error run a virtual video card driver and I'm currently asking for the other one, but I bet it's also pure mesa-based or ATI. -------------- next part -------------- An HTML attachment was scrubbed... URL: From paniq at paniq.org Mon Dec 15 17:53:35 2008 From: paniq at paniq.org (Leonard Ritter) Date: Mon, 15 Dec 2008 17:53:35 +0100 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150848g541b3fa1vb36445b7b1b26f42@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> <32c88000812150838j678e598fh1badf15351a6b8bd@mail.gmail.com> <32c88000812150848g541b3fa1vb36445b7b1b26f42@mail.gmail.com> Message-ID: <32c88000812150853t53b1157clad7f915fc38be01f@mail.gmail.com> solved! On Mon, Dec 15, 2008 at 5:48 PM, Leonard Ritter wrote: > searching for __cxa_allocate_exception segfault i got quite a few hits in > different projects, of which this wiki entry devotes a whole page to the > issue: > > http://wiki.fifengine.de/Segfault_in_cxa_allocate_exception > > The funny thing is: I never got the problem on a machine with an nVidia > driver. The two machines who have the reported error run a virtual video > card driver and I'm currently asking for the other one, but I bet it's also > pure mesa-based or ATI. > > I solved the problem by linking to libstdc++ before linking to anything else as described in the above Wiki-page. The exception does no longer occur. Gentlemen! I rest my case! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Mon Dec 15 17:58:07 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 15 Dec 2008 08:58:07 -0800 (PST) Subject: [C++-sig] custom constructor problems References: <95291a80812150617x7b727926keeccdf8b813ccecc@mail.gmail.com> Message-ID: <631913.99242.qm@web111402.mail.gq1.yahoo.com> I think this is related: http://mail.python.org/pipermail/cplusplus-sig/2006-March/010092.html http://mail.python.org/pipermail/cplusplus-sig/2006-March/010095.html I gave up on the obj1 == obj2 comparison idea and added a ..memory_id() method, which returns the memory location (cast to Python int). ----- Original Message ---- From: Renato Araujo To: Development of Python/C++ integration Sent: Monday, December 15, 2008 6:17:16 AM Subject: [C++-sig] custom constructor problems Hi again :D, To solve my old problem, I'm trying create custom constructor which return a shared_ptr like that code: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class my_class_wrapper : my_class, python::wrapper { ....... } shared_ptr _create_object(parent *p) { return shared_ptr(new my_class_wrapper(p), _my_delete_function); } shared_ptr _create_object2() { return shared_ptr(new my_class_wrapper(0), _my_delete_function); } class_("MyClass", python::no_init) .def("__init__", python::make_constructor(_create_object)) .def("__init__", python::make_constructor(_create_object2)) .def("get_parent", &MyClass:getParent, return_value_policy()); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- but during my python test, the function get_parent not return the same python object created in the object constructor. my test is: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- parent = MyClass() child = MyClass(parent) if (child.get_parent() != parent) print "FAIL" else print "OK" -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Always I got the "FAIL" message, but if I remove the custom constructor the test pass. What I doing wrong all my classes inherit from "python::wrapper". Then I think all classes have implicit conversion to "shared_ptr" correct? BR -- Renato Araujo Oliveira Filho _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From seefeld at sympatico.ca Mon Dec 15 17:58:22 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 15 Dec 2008 11:58:22 -0500 Subject: [C++-sig] preventing boost::python::throw_error_already_set In-Reply-To: <32c88000812150848g541b3fa1vb36445b7b1b26f42@mail.gmail.com> References: <32c88000812110818q21289c79i94a42ca8a0b6f09c@mail.gmail.com> <494140B1.1040200@sympatico.ca> <32c88000812141422l51e0ae0blbb074049904af71c@mail.gmail.com> <32c88000812150739i35b5ff43n72eb6f07c30d21f6@mail.gmail.com> <4946811F.5010505@resophonic.com> <49468570.4010808@sympatico.ca> <32c88000812150829s76142dbj6c0317fda05fc222@mail.gmail.com> <32c88000812150833v7bd2c8f4ve9dc483186a41346@mail.gmail.com> <32c88000812150838j678e598fh1badf15351a6b8bd@mail.gmail.com> <32c88000812150848g541b3fa1vb36445b7b1b26f42@mail.gmail.com> Message-ID: <49468CAE.4050908@sympatico.ca> Leonard Ritter wrote: > > searching for __cxa_allocate_exception segfault i got quite a few hits > in different projects, of which this wiki entry devotes a whole page > to the issue: > > http://wiki.fifengine.de/Segfault_in_cxa_allocate_exception > > The funny thing is: I never got the problem on a machine with an > nVidia driver. The two machines who have the reported error run a > virtual video card driver and I'm currently asking for the other one, > but I bet it's also pure mesa-based or ATI. The first thing to do in order to confirm this (or in fact in any case to better understand the issue) is to write a minimal complete test case exhibiting the error. If you can indeed confirm that *any* exception will cause this segfault you have already eliminated boost (and python), which should make a further drill-down much easier. Good luck, Stefan -- ...ich hab' noch einen Koffer in Berlin... From smnemeth at gmail.com Mon Dec 15 21:22:27 2008 From: smnemeth at gmail.com (Rocketman@JSC) Date: Mon, 15 Dec 2008 12:22:27 -0800 (PST) Subject: [C++-sig] boost::python::throw_error_already_set not in library In-Reply-To: <87oczganqk.fsf@mcbain.luannocracy.com> References: <20983772.post@talk.nabble.com> <87hc59au7p.fsf@mcbain.luannocracy.com> <20985178.post@talk.nabble.com> <87oczganqk.fsf@mcbain.luannocracy.com> Message-ID: <21021185.post@talk.nabble.com> Problem Solved: The symbols are in the shared object, and as David mentioned, one must use the -T to see them in a debug library. The problem was with the intel linker (via eclipse). Apparently the linker will not tell you whether a shared library is actually included using -l to add to a shared object. One could put in anything and it will just build the .so without mentioning it could not find . Thanks for your help. Scott -- View this message in context: http://www.nabble.com/boost%3A%3Apython%3A%3Athrow_error_already_set-not-in-library-tp20983772p21021185.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From jeremie.delaitre at technogerma.fr Wed Dec 17 10:07:14 2008 From: jeremie.delaitre at technogerma.fr (=?ISO-8859-1?Q?J=E9r=E9mie_Delaitre?=) Date: Wed, 17 Dec 2008 10:07:14 +0100 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <49465475.5090205@technogerma.fr> References: <493FE997.2050005@technogerma.fr> <494002A4.5070101@pixar.com> <494252B8.4040608@technogerma.fr> <49465475.5090205@technogerma.fr> Message-ID: <4948C142.8030508@technogerma.fr> Ok, I have find a way to resolve all of my problem. I simply declare a new custom type which is callable. This way, when the user type in python 'myObj.myFunc(...)', mytype_getattro is called with 'myObj' as self and 'myFunc' as arg. Then, I return a new instance of the callable type which is fill with all the information I need to identify the function. Then python simply call the functor. J?r?mie Delaitre J?r?mie Delaitre a ?crit : > > Hi, > > When defining my new type in C++, I have set the "tp_getattro" field > to point to a function (say "mytype_getattro"). > This function determine dynamically if the requested attribute exists > or not, and if it does, return its value. > So, it works well for attributes/properties. > > But, "mytype_getattro" is also called when, in Python, I do a function > call 'myobject.myfct(...)'. It allows me to determine > dynamically if the requested function "myfct" is available or not. But > if it does, I need to return a callable object to allow > python to process the call. > > I succeeded to make Python to call a function of mine using a > PyMethodDef array and using the Py_FindMethod function > to get a callable PyObject*. > But it is not a good solution for at least two reasons : > 1 - Py_FindMethod is not supported in Python 3.0 > 2 - I need to declare each possible function in the array (which is > impossible has I need to determine them at runtime) > > What I have tried to do is to declare only one "dipatch" function in > the array which will call the right C++ function. > This way, in "mytype_getattro" I do a "return Py_FindMethod(myarray, > self, "dispatch")". Thus, python call my > dispatching method. The problem is that I need to attach additionnal > values to the function (like the name of the function > which must be called in reality). In Lua, I used the closure > mechanism, but I did not success with Python closures. > > Any hints ? > Is closure the right approach (If so, how I should use it ?)? Do I > need to set another field when defining my type ? > > Regards, > > J?r?mie Delaitre > > > J?r?mie Delaitre a ?crit : >> >> It works ! Thanks a lot. >> >> J?r?mie >> >> Alex Mohr a ?crit : >>> Override the python special methods __getattr__ or __getattribute__. >>> >>> http://docs.python.org/reference/datamodel.html#attribute-access >>> >>> Alex >>> >>> J?r?mie Delaitre wrote: >>>> Hello, >>>> >>>> I have a C++ class that use a custom property system. >>>> This property system allows me to add and remove properties at >>>> runtime. >>>> >>>> I want to expose this class into Python. >>>> >>>> The problem is: I want "a dynamic resolution" of the properties in >>>> Python. >>>> >>>> For example: >>>> >>>> # import my python extension >>>> import myModule >>>> >>>> # get an instance of my C++ class >>>> t = myModule.newInstance() >>>> >>>> # access the property 'myProperty' >>>> print(t.myProperty) >>>> >>>> When I access the property, I want python to call a "callback" of >>>> mine (written >>>> in the C++ extension) which will check if the requested property >>>> exists, and >>>> if it does, return the corresponding value, otherwise generate an >>>> exception. >>>> >>>> By looking at the python C API, I did not find a way to achieve >>>> this. It seems >>>> that declaring a new type requires to have static arrays for >>>> members and methods >>>> (yes, my property system allows me to declare new methods too, so I >>>> want to expose >>>> them with a similar system). >>>> >>>> Any idea how I could resolve this (with Python3.0) ? >>>> >>>> Regards, >>>> >>>> J?r?mie Delaitre >>>> >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From seefeld at sympatico.ca Wed Dec 17 12:35:16 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 17 Dec 2008 06:35:16 -0500 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <4948C142.8030508@technogerma.fr> References: <493FE997.2050005@technogerma.fr> <494002A4.5070101@pixar.com> <494252B8.4040608@technogerma.fr> <49465475.5090205@technogerma.fr> <4948C142.8030508@technogerma.fr> Message-ID: <4948E3F4.7020204@sympatico.ca> J?r?mie Delaitre wrote: > Ok, I have find a way to resolve all of my problem. > I simply declare a new custom type which is callable. > This way, when the user type in python 'myObj.myFunc(...)', > mytype_getattro is called > with 'myObj' as self and 'myFunc' as arg. Then, I return a new > instance of the callable type > which is fill with all the information I need to identify the > function. Then python simply call the > functor. From this and your previous mail it doesn't sound as if you used any boost.python for this. Any reason for that ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jeremie.delaitre at technogerma.fr Wed Dec 17 13:21:26 2008 From: jeremie.delaitre at technogerma.fr (=?ISO-8859-1?Q?J=E9r=E9mie_Delaitre?=) Date: Wed, 17 Dec 2008 13:21:26 +0100 Subject: [C++-sig] Dynamic resolution of members and methods In-Reply-To: <4948E3F4.7020204@sympatico.ca> References: <493FE997.2050005@technogerma.fr> <494002A4.5070101@pixar.com> <494252B8.4040608@technogerma.fr> <49465475.5090205@technogerma.fr> <4948C142.8030508@technogerma.fr> <4948E3F4.7020204@sympatico.ca> Message-ID: <4948EEC6.2050109@technogerma.fr> Stefan Seefeld a ?crit : > J?r?mie Delaitre wrote: >> Ok, I have find a way to resolve all of my problem. >> I simply declare a new custom type which is callable. >> This way, when the user type in python 'myObj.myFunc(...)', >> mytype_getattro is called >> with 'myObj' as self and 'myFunc' as arg. Then, I return a new >> instance of the callable type >> which is fill with all the information I need to identify the >> function. Then python simply call the >> functor. > > From this and your previous mail it doesn't sound as if you used any > boost.python for this. Any reason for that ? > > Regards, > Stefan > We are not using boost.python because we already have a system which allow us to bind members, methods, ... into a metaclass. We just want to publish these metaclasses into Python. As we already declare our bindings, we do not want to declare another one for Python. Moreover, we want to support other script engine. Thus, we do not want to declare bindings for each but rather give to the script engines an access to our custom system. Regards, J?r?mie Delaitre From hugo.lima at openbossa.org Wed Dec 17 17:35:56 2008 From: hugo.lima at openbossa.org (Hugo Lima) Date: Wed, 17 Dec 2008 13:35:56 -0300 Subject: [C++-sig] Enums with duplicated values. Message-ID: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> Hi; I need wrap enums with duplicated values, but boost::python do not support it. At the boost website you can find the quote: "Scott Snyder provided a patch; Dave was dissatisfied for some reason, but maybe it should just be applied if no further action occurs http://aspn.activestate.com/ASPN/Mail/Message/1824616." Why this patch was not been accepted since 2003? What can we do to get this patch accepted, so we do not have to maintain a boost-copy on our repositories? From yunlin07 at gmail.com Thu Dec 18 01:59:43 2008 From: yunlin07 at gmail.com (lin yun) Date: Wed, 17 Dec 2008 16:59:43 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? Message-ID: Hi, folks: I am trying to wrap a c++ function that returns a boost::shared_ptr type using boost.python, is that possible? BTW, I used the call policy return_range included in Py++ for returning a pointer to a vector. It worked ! My question is that which side is responsible for releasing the memory of the vector, python side or C++ side? Thank you for your help very much! Yun -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Dec 18 07:41:43 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 18 Dec 2008 08:41:43 +0200 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: References: Message-ID: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> 2008/12/18 lin yun : > Hi, folks: > > I am trying to wrap a c++ function that returns a boost::shared_ptr class> type using boost.python, is that possible? Yes. I believe Py++ deals with boost::shared_ptr without invoking the user. Just use default call policy. > BTW, I used the call policy return_range included in Py++ for returning a > pointer to a vector. It worked ! My question is that which side is > responsible for releasing the memory of the vector, python side or C++ side? Can you provide small example of what you are trying to do? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From yunlin07 at gmail.com Thu Dec 18 07:58:49 2008 From: yunlin07 at gmail.com (lin yun) Date: Wed, 17 Dec 2008 22:58:49 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> Message-ID: > Yes. I believe Py++ deals with boost::shared_ptr without invoking the > user. Just use default call policy. That's good news! How about vector> ? > Can you provide small example of what you are trying to do? I have a C++ function "imgreader" which reads an image and return a "unsigned short *" pointer. I have another piece of Python code that calls imgreader and gets the pointer to the image data. Where should I release the memory of the image data when it is not needed any more? in python side or C++ side? Thanks a lot ! Yun On Wed, Dec 17, 2008 at 10:41 PM, Roman Yakovenko wrote: > 2008/12/18 lin yun : > > Hi, folks: > > > > I am trying to wrap a c++ function that returns a boost::shared_ptr > class> type using boost.python, is that possible? > > Yes. I believe Py++ deals with boost::shared_ptr without invoking the > user. Just use default call policy. > > > BTW, I used the call policy return_range included in Py++ for returning a > > pointer to a vector. It worked ! My question is that which side is > > responsible for releasing the memory of the vector, python side or C++ > side? > > Can you provide small example of what you are trying to do? > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > 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 roman.yakovenko at gmail.com Thu Dec 18 08:32:51 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 18 Dec 2008 09:32:51 +0200 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> Message-ID: <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> 2008/12/18 lin yun : >> Yes. I believe Py++ deals with boost::shared_ptr without invoking the >> user. Just use default call policy. > That's good news! How about vector> ? No :-(, unsigned short is immutable type. You will have too write wrapper. Take a look on Py++ - ctypes functionality: http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html >> Can you provide small example of what you are trying to do? > > I have a C++ function "imgreader" which reads an image and return a > "unsigned short *" pointer. I have another piece of Python code that calls > imgreader and gets the pointer to the image data. Where should I release the > memory of the image data when it is not needed any more? in python side or > C++ side? return_range call policy doesn't manage the memory. It assumes that the buffer is owned by C++ class. I guess you should use "as_tuple" call policy, with memory_managers::delete_ memory manager. This way you don't need to force user to manage the memory. May be you will have to create new call policy - hybrid of return_range and as_tuple: * efficiency of return_range * memory management ability of as_tuple HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From yunlin07 at gmail.com Thu Dec 18 08:44:11 2008 From: yunlin07 at gmail.com (lin yun) Date: Wed, 17 Dec 2008 23:44:11 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> Message-ID: Actually I used return_range with element type of unsigned short. Python interprets the element as int. You mean it is not difficult to wrap a function that returns vector> then? OK. Then the C++ class needs to take care of the memory when using return_range. I am still a newbie in boost python. I am learning and making progress. I hope I could write new call policies in the future like you did for py++.:) Thanks. On Wed, Dec 17, 2008 at 11:32 PM, Roman Yakovenko wrote: > 2008/12/18 lin yun : > >> Yes. I believe Py++ deals with boost::shared_ptr without invoking the > >> user. Just use default call policy. > > That's good news! How about vector> ? > > No :-(, unsigned short is immutable type. You will have too write > wrapper. Take a look on Py++ - ctypes functionality: > > > http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html > > >> Can you provide small example of what you are trying to do? > > > > I have a C++ function "imgreader" which reads an image and return a > > "unsigned short *" pointer. I have another piece of Python code that > calls > > imgreader and gets the pointer to the image data. Where should I release > the > > memory of the image data when it is not needed any more? in python side > or > > C++ side? > > return_range call policy doesn't manage the memory. It assumes that > the buffer is owned by C++ class. > > I guess you should use "as_tuple" call policy, with > memory_managers::delete_ memory manager. > This way you don't need to force user to manage the memory. > > May be you will have to create new call policy - hybrid of > return_range and as_tuple: > * efficiency of return_range > * memory management ability of as_tuple > > HTH > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > 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 roman.yakovenko at gmail.com Thu Dec 18 09:37:33 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 18 Dec 2008 10:37:33 +0200 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> Message-ID: <7465b6170812180037vc897c10wb343532dab43f3bc@mail.gmail.com> 2008/12/18 lin yun : > Actually I used return_range with element type of unsigned short. Python > interprets the element as int. > > You mean it is not difficult to wrap a function that returns > vector> then? Yes. Take a look on example: http://language-binding.net/pyplusplus/documentation/functions/transformation/output_static_array.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From ndbecker2 at gmail.com Thu Dec 18 13:19:35 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 18 Dec 2008 07:19:35 -0500 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> <7465b6170812180037vc897c10wb343532dab43f3bc@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > 2008/12/18 lin yun : >> Actually I used return_range with element type of unsigned short. Python >> interprets the element as int. >> >> You mean it is not difficult to wrap a function that returns >> vector> then? > > Yes. Take a look on example: > http://language-binding.net/pyplusplus/documentation/functions/transformation/output_static_array.html > This link seems to be broken. I keep getting 'server closed connection' From ndbecker2 at gmail.com Thu Dec 18 13:20:10 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 18 Dec 2008 07:20:10 -0500 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> <7465b6170812180037vc897c10wb343532dab43f3bc@mail.gmail.com> Message-ID: I'm curious about 'return_range'. What does it do? Is there any doc? From yunlin07 at gmail.com Thu Dec 18 18:08:41 2008 From: yunlin07 at gmail.com (lin yun) Date: Thu, 18 Dec 2008 09:08:41 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> <7465b6170812180037vc897c10wb343532dab43f3bc@mail.gmail.com> Message-ID: The link is alive to me... I can open it. Thanks Roman. On Thu, Dec 18, 2008 at 4:19 AM, Neal Becker wrote: > Roman Yakovenko wrote: > > > 2008/12/18 lin yun : > >> Actually I used return_range with element type of unsigned short. Python > >> interprets the element as int. > >> > >> You mean it is not difficult to wrap a function that returns > >> vector> then? > > > > Yes. Take a look on example: > > > http://language-binding.net/pyplusplus/documentation/functions/transformation/output_static_array.html > > > > This link seems to be broken. I keep getting 'server closed connection' > > _______________________________________________ > 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 yunlin07 at gmail.com Thu Dec 18 18:10:10 2008 From: yunlin07 at gmail.com (lin yun) Date: Thu, 18 Dec 2008 09:10:10 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <7465b6170812172332r768f921aj6f93f8e892fc7b50@mail.gmail.com> <7465b6170812180037vc897c10wb343532dab43f3bc@mail.gmail.com> Message-ID: Here it is: http://www.language-binding.net/pyplusplus/documentation/functions/call_policies/return_range.html return_range is a call policy that is used to wrap a C++ function which returns a pointer to an array. On Thu, Dec 18, 2008 at 4:20 AM, Neal Becker wrote: > I'm curious about 'return_range'. What does it do? Is there any doc? > > _______________________________________________ > 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 dave at boostpro.com Thu Dec 18 19:17:32 2008 From: dave at boostpro.com (David Abrahams) Date: Thu, 18 Dec 2008 09:17:32 -0900 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> (Roman Yakovenko's message of "Thu, 18 Dec 2008 08:41:43 +0200") References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> Message-ID: <87r645s5z7.fsf@mcbain.luannocracy.com> on Wed Dec 17 2008, "Roman Yakovenko" wrote: > 2008/12/18 lin yun : >> Hi, folks: >> >> I am trying to wrap a c++ function that returns a boost::shared_ptr> class> type using boost.python, is that possible? > > Yes. I believe Py++ deals with boost::shared_ptr without invoking the > user. Just use default call policy. Boost.Python itself also deals with shared_ptr without involving the user. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From dave at boostpro.com Thu Dec 18 19:18:16 2008 From: dave at boostpro.com (David Abrahams) Date: Thu, 18 Dec 2008 09:18:16 -0900 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: (lin yun's message of "Wed, 17 Dec 2008 22:58:49 -0800") References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> Message-ID: <87myets5xz.fsf@mcbain.luannocracy.com> on Wed Dec 17 2008, "lin yun" wrote: >> Yes. I believe Py++ deals with boost::shared_ptr without invoking the >> user. Just use default call policy. > That's good news! How about vector> ? If you use the facilities of http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/iterator.html, everything *should* "just work." -- Dave Abrahams BoostPro Computing http://www.boostpro.com From roman.yakovenko at gmail.com Thu Dec 18 20:20:13 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 18 Dec 2008 21:20:13 +0200 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: <87myets5xz.fsf@mcbain.luannocracy.com> References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <87myets5xz.fsf@mcbain.luannocracy.com> Message-ID: <7465b6170812181120l7b21aaa0t84f35fd68a05b684@mail.gmail.com> On Thu, Dec 18, 2008 at 8:18 PM, David Abrahams wrote: > > on Wed Dec 17 2008, "lin yun" wrote: > >>> Yes. I believe Py++ deals with boost::shared_ptr without invoking the >>> user. Just use default call policy. >> That's good news! How about vector> ? > > If you use the facilities of > http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/iterator.html, > everything *should* "just work." Do you mean to "redefine" class_< std::vector< ... > > "get" function, so it will return the iterators range? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boostpro.com Fri Dec 19 03:13:05 2008 From: dave at boostpro.com (David Abrahams) Date: Thu, 18 Dec 2008 17:13:05 -0900 Subject: [C++-sig] Enums with duplicated values. In-Reply-To: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> (Hugo Lima's message of "Wed, 17 Dec 2008 13:35:56 -0300") References: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> Message-ID: <87ljuclxou.fsf@mcbain.luannocracy.com> on Wed Dec 17 2008, "Hugo Lima" wrote: > Hi; > > I need wrap enums with duplicated values, but boost::python do not > support it. At the boost website you can find the quote: > > "Scott Snyder provided a patch; Dave was dissatisfied for some reason, I think I didn't really like the asymmetry of the "othervalues" field; I would probably prefer to store all values in a dict of lists. > but maybe it should just be applied if no further action occurs > http://aspn.activestate.com/ASPN/Mail/Message/1824616." > > Why this patch was not been accepted since 2003? Well, I suppose it's a lot better than no patch at all, so it should be applied. > What can we do to get this patch accepted, so we do not have to > maintain a boost-copy on our repositories? You can run the Boost.Python test suite with the patch in place against trunk, and assure me that all the tests pass. If you do that, I'll be inclined to apply it and move it to the release branch. Thanks for the bump, -- Dave Abrahams BoostPro Computing http://www.boostpro.com From yunlin07 at gmail.com Fri Dec 19 04:28:44 2008 From: yunlin07 at gmail.com (lin yun) Date: Thu, 18 Dec 2008 19:28:44 -0800 Subject: [C++-sig] bjam: undefined Symbol Error Message-ID: Hi, folks: I am having headache with bjam... I am getting undefined symbol error. Part of the Jamroot file is shown as below. multithread_lib is defined as a system library which is used in generating my own library img_lib. Bag_wrapper.cpp wraps a C++ class which uses img_lib. I am getting importError: libimg_lib.so has undefined symbol. I have tried for a whole day. Still have not found a way out... Could you please help? Thanks a lot, Yun #system library MTPATH = /root/boost_1_36_0/bin.v2/libs/thread/build/gcc-4.1.2/release/threading-multi ; lib multithread_lib : : boost_thread-gcc41-mt-1_36 $(MTPATH) shared ; #Generate library lib img_lib : read_write.cpp label_slice.cpp Region3d.cpp collapse_mappings.cpp ObjectRegions.cpp Bag.cpp Volume.cpp label_utilities.cpp multithread_lib : $(IPPINCLUDE) ; # Declare a Python extension called volReader python-extension Bag_ext : Bag_wrapper.cpp img_lib ; -------------- next part -------------- An HTML attachment was scrubbed... URL: From yunlin07 at gmail.com Fri Dec 19 04:30:19 2008 From: yunlin07 at gmail.com (lin yun) Date: Thu, 18 Dec 2008 19:30:19 -0800 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: <87myets5xz.fsf@mcbain.luannocracy.com> References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <87myets5xz.fsf@mcbain.luannocracy.com> Message-ID: Would you please elaborate your idea a little more? On Thu, Dec 18, 2008 at 10:18 AM, David Abrahams wrote: > > on Wed Dec 17 2008, "lin yun" wrote: > > >> Yes. I believe Py++ deals with boost::shared_ptr without invoking the > >> user. Just use default call policy. > > That's good news! How about vector> ? > > If you use the facilities of > http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/iterator.html, > everything *should* "just work." > > -- > Dave Abrahams > BoostPro Computing > http://www.boostpro.com > _______________________________________________ > 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 yunlin07 at gmail.com Fri Dec 19 04:42:15 2008 From: yunlin07 at gmail.com (lin yun) Date: Thu, 18 Dec 2008 19:42:15 -0800 Subject: [C++-sig] bjam: undefined Symbol Error In-Reply-To: References: Message-ID: To me, the "undefined symbols" are from the multithread_lib which img_lib does not get connected to. But why? On Thu, Dec 18, 2008 at 7:28 PM, lin yun wrote: > Hi, folks: > > I am having headache with bjam... I am getting undefined symbol error. > > Part of the Jamroot file is shown as below. multithread_lib is defined as > a system library which is used in generating my own library img_lib. > Bag_wrapper.cpp wraps a C++ class which uses img_lib. > > I am getting importError: libimg_lib.so has undefined symbol. I have tried > for a whole day. Still have not found a way out... > > Could you please help? > > Thanks a lot, > > Yun > > > #system library > MTPATH = > /root/boost_1_36_0/bin.v2/libs/thread/build/gcc-4.1.2/release/threading-multi > ; > lib multithread_lib : : boost_thread-gcc41-mt-1_36 $(MTPATH) > shared ; > > #Generate library > lib img_lib : read_write.cpp label_slice.cpp Region3d.cpp > collapse_mappings.cpp ObjectRegions.cpp Bag.cpp Volume.cpp > label_utilities.cpp multithread_lib : $(IPPINCLUDE) ; > > # Declare a Python extension called volReader > python-extension Bag_ext : Bag_wrapper.cpp img_lib ; > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boostpro.com Fri Dec 19 09:16:44 2008 From: dave at boostpro.com (David Abrahams) Date: Thu, 18 Dec 2008 23:16:44 -0900 Subject: [C++-sig] Wrap a c++ function that returns boost::shared_ptr<> type? In-Reply-To: (lin yun's message of "Thu, 18 Dec 2008 19:30:19 -0800") References: <7465b6170812172241y3ea8fabi75fdce2efac9c7ef@mail.gmail.com> <87myets5xz.fsf@mcbain.luannocracy.com> Message-ID: <877i5wk2ab.fsf@mcbain.luannocracy.com> on Thu Dec 18 2008, "lin yun" wrote: > Would you please elaborate your idea a little more? > > > On Thu, Dec 18, 2008 at 10:18 AM, David Abrahams wrote: > >> >> on Wed Dec 17 2008, "lin yun" wrote: >> >> >> Yes. I believe Py++ deals with boost::shared_ptr without invoking the >> >> user. Just use default call policy. >> > That's good news! How about vector> ? >> >> If you use the facilities of >> http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/iterator.html,> everything *should* "just work." If all you need to do is iterate over the objects pointed to by the elements of a container of shared_ptrs, then expose the iterators using one of the functions in that header. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From python at foxcub.org Sat Dec 20 21:01:36 2008 From: python at foxcub.org (Dmitriy Morozov) Date: Sat, 20 Dec 2008 12:01:36 -0800 Subject: [C++-sig] pyste and compressed_pair Message-ID: <2fd72fb20812201201n11be49bah76aeb106cb28d2dd@mail.gmail.com> Hi, If I have the simplest header file that includes compressed_pair.hpp, and I run pyste on it, pyste crashes complaining about is_abstract.hpp included from compressed_pair.hpp. An example and error messages are below. I was wondering if this was a known problem, and if there are any workarounds. I'm trying this right now with Boost 1.36.0, but I believe the same problem occurs with 1.37.0 (I tried it earlier). Thanks in advance for your help. Dmitriy test.h: #include struct A { int a; }; test.pyste: Class("A", "test.h") When running "pyste.py test.pyste" I get: In file included from /usr/include/boost/type_traits/is_convertible.hpp:25, from /usr/include/boost/type_traits/is_empty.hpp:12, from /usr/include/boost/detail/compressed_pair.hpp:26, from /usr/include/boost/compressed_pair.hpp:21, from test.h:1: /usr/include/boost/type_traits/is_abstract.hpp:72: error: expected primary-expression before ')' token /usr/include/boost/type_traits/is_abstract.hpp:72: error: a function call cannot appear in a constant-expression In file included from /usr/include/boost/type_traits/is_empty.hpp:19, from /usr/include/boost/detail/compressed_pair.hpp:26, from /usr/include/boost/compressed_pair.hpp:21, from test.h:1: /usr/include/boost/type_traits/is_class.hpp:122: error: expected primary-expression before ')' token /usr/include/boost/type_traits/is_class.hpp:122: error: a function call cannot appear in a constant-expression Traceback (most recent call last): File "/usr/bin/pyste.py", line 8, in pyste.main() File "/usr/lib/python2.5/site-packages/Pyste/pyste.py", line 418, in main status = Begin() File "/usr/lib/python2.5/site-packages/Pyste/pyste.py", line 257, in Begin return GenerateCode(parser, module, out, interfaces, multiple) File "/usr/lib/python2.5/site-packages/Pyste/pyste.py", line 376, in GenerateCode declarations, parsed_header = parser.Parse(header, interface, tail) File "/usr/lib/python2.5/site-packages/Pyste/CppParser.py", line 165, in Parse declarations = self.ParseWithGCCXML(header, tail) File "/usr/lib/python2.5/site-packages/Pyste/CppParser.py", line 126, in ParseWithGCCXML raise CppParserError, 'Error executing gccxml' Pyste.CppParser.CppParserError: Error executing gccxml From timprepscius at gmail.com Sat Dec 20 21:09:33 2008 From: timprepscius at gmail.com (Tim Prepscius) Date: Sat, 20 Dec 2008 15:09:33 -0500 Subject: [C++-sig] custom constructor with embedded back reference Message-ID: <6fcb94430812201209u4f59b54esfaeb881ce3806ebb@mail.gmail.com> I just wanted to thank http://mail.python.org/pipermail/cplusplus-sig/2007-July/012293.html I've extended what he wrote.. I needed late binding for c++ to python objects. Hope this is useful for someone else. Maybe there was some other way I was supposed to do this, but I couldn't find it. Um.. And yes this code was just cobbled together.. BasePtr is a horrible name I know. :-) #define BOOST_PYTHON_STATIC_LIB #include #include #include #include #include namespace python = boost::python; class Base; //------------------------------------------------------ #define IMPLEMENT_PYTHON_ACCESSOR_H \ public: \ static void setClass (boost::python::object _clazz) { clazz = _clazz; } \ static boost::python::object getClass() { return clazz; } \ virtual void reflectBind (boost::python::object object) \ { \ ::bind(this, object); \ } \ private: \ static boost::python::object clazz; \ #define IMPLEMENT_PYTHON_ACCESSOR_CPP(x) \ boost::python::object x::clazz; //------------------------------------------------------ template void bind (T *self, boost::python::object object) { // Insert new S object pointer into python object typedef boost::python::objects::pointer_holder holder; typedef boost::python::objects::instance instance_t; void* memory = holder::allocate( object.ptr(), offsetof(instance_t, storage), sizeof(holder) ); try { (new (memory) holder(self))->install(object.ptr()); } catch(...) { holder::deallocate(object.ptr(), memory); throw; } } //------------------------------------------------------ class BasePtr { public: BasePtr() { std::cout << this; }; virtual ~BasePtr () { }; virtual void reflectBind (boost::python::object pyobject) { } void bind (boost::python::object pyobject) { reflectBind (pyobject); this->object = pyobject; } python::object object; python::object getObject () const { return object; } void doBind (python::object o) { bind( o); } static python::object nowhere (python::object); } ; //---------------------------------------------------- class Base : public BasePtr { IMPLEMENT_PYTHON_ACCESSOR_H public: virtual ~Base() { }; Base () { } virtual std::string hello() { std::cout << this; return "Base says hello"; } virtual Base *myself () { return this; } }; IMPLEMENT_PYTHON_ACCESSOR_CPP (Base); class Inherited : public Base { IMPLEMENT_PYTHON_ACCESSOR_H public: Inherited () { } virtual ~Inherited () { } std::string hello() { std::cout << this; return "Inherited says hello"; } } ; IMPLEMENT_PYTHON_ACCESSOR_CPP (Inherited); /* Not needed after all template struct BaseToReference { static PyObject* convert(const T &x) { if (&x == 0) return python::incref(python::object().ptr()); return python::incref(x.getObject().ptr()); } }; */ python::object BasePtr::nowhere (python::object pyobject) { return python::object(); } //--------------------------------------------------- BOOST_PYTHON_MODULE(embedded_hello) { Base::setClass( python::class_ ("Base", python::no_init) .def("__init__", &BasePtr::nowhere) .def ("hello", &Base::hello, python::return_value_policy()) .def ("myself", &Base::myself, python::return_value_policy()) ); Inherited::setClass ( python::class_, boost::noncopyable> ("Inherited", python::no_init) .def("__init__", &BasePtr::nowhere) .def ("hello", &Inherited::hello, python::return_value_policy()) ); // not needed after all // python::to_python_converter >(); } //--------------------------------------------------- int main(int argc, char **argv) { // Initialize the interpreter Py_Initialize(); bool error_expected = false; if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1) throw std::runtime_error("Failed to add embedded_hello to the interpreter's " "builtin modules"); PyObject *z2 = PyImport_ImportModule ("embedded_hello"); python::object module (python::handle<>(PyImport_ImportModule ("embedded_hello"))); python::object dict = module.attr("__dict__"); // Retrieve the main module python::object main = python::import("__main__"); // Retrieve the main module's namespace python::object global(main.attr("__dict__")); python::object result1 = python::exec( "from embedded_hello import * \n" "class PythonDerived(Base): \n" " def __init__(self): \n" " Base.__init__(self); \n" "\n" " def hello(self): \n" " print 'hello from python' \n" " print Base.hello(self) \n" " return 'Hello from Python!' \n" "\n" " def test(self): \n" " print 'test1 says ' \n" " print self.myself().hello()\n" , global, global); Base b; b.doBind(global["PythonDerived"]()); python::object o(b.object); ; python::object r = o.attr("hello")(); o.attr("test")(); python::object result2 = python::exec( "from embedded_hello import * \n" "class PythonDerived2(Inherited): \n" " def __init__(self): \n" " Inherited.__init__(self); \n" "\n" " def hello(self): \n" " print 'hello from python' \n" " print Inherited.hello(self) \n" " return 'Hello from Python!' \n" "\n" " def test(self): \n" " print 'test2 says ' \n" " print self.myself().hello()\n" , global, global); Inherited c; c.doBind(global["PythonDerived2"]()); python::object oc(c.object); ; python::object rc = oc.attr("hello")(); oc.attr("test")(); std::cout << "success!" << std::endl; } From timprepscius at gmail.com Mon Dec 22 04:48:11 2008 From: timprepscius at gmail.com (Tim Prepscius) Date: Sun, 21 Dec 2008 22:48:11 -0500 Subject: [C++-sig] custom constructor with embedded back reference Message-ID: <6fcb94430812211948xf30c055p42fca104a4e228e9@mail.gmail.com> I just wanted to add one more clarification, because actually there is a bug in the code I posted.. For this late binding to work properly.. You really want to have something like this (sorry, ripping from non-test code): template struct PAccessorConverter { static PyObject* convert(const T &x) { if (x==0) // i believe this is sending back None, not sure have to verify return boost::python::incref(boost::python::object().ptr()); return boost::python::incref(x->getPtr().ptr()); } }; and have that instantiated something like #define IMPLEMENT_PYTHON_CONVERTER(x) \ boost::python::to_python_converter >(); IMPLEMENT_PYTHON_CONVERTER(myclass) and then when you're doing a class.def, don't return the "existing_reference" because that will somehow cause boost python not to look up the converter.. instead do a return by value... something like: .def("getParentUser", &PCamera::getParentUser, return_value_policy()) this return_value_policy queues boost python to search the converters.. which will eventually hit the converter that uses the embedded python object.. (which allows you to have a 1-to-1 relationship between python and c++) -tim From rwgk at yahoo.com Tue Dec 23 08:58:51 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 22 Dec 2008 23:58:51 -0800 (PST) Subject: [C++-sig] Bug and patch for boost.pythonwithenable_shared_from_this References: <229148.259.qm@web31108.mail.mud.yahoo.com> <006501c95c3e$cd570610$d100a8c0@nicopc> <17fe01c95c69$a505c4f0$d100a8c0@nicopc> Message-ID: <201094.63149.qm@web111410.mail.gq1.yahoo.com> Thanks for the patches! They are now in the boost trunk: ------------------------------------------------------------------------ r50368 | rwgk | 2008-12-22 23:55:33 -0800 (Mon, 22 Dec 2008) | 4 lines Boost.Python enable_shared_from_this patches by Nicolas Lelong and Chad Austin: http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html http://mail.python.org/pipermail/cplusplus-sig/2008-February/013003.html ------------------------------------------------------------------------ From dave at boostpro.com Tue Dec 23 10:10:33 2008 From: dave at boostpro.com (David Abrahams) Date: Tue, 23 Dec 2008 00:10:33 -0900 Subject: [C++-sig] Bug and patch for boost.pythonwithenable_shared_from_this In-Reply-To: <201094.63149.qm@web111410.mail.gq1.yahoo.com> (Ralf W. Grosse-Kunstleve's message of "Mon, 22 Dec 2008 23:58:51 -0800 (PST)") References: <229148.259.qm@web31108.mail.mud.yahoo.com> <006501c95c3e$cd570610$d100a8c0@nicopc> <17fe01c95c69$a505c4f0$d100a8c0@nicopc> <201094.63149.qm@web111410.mail.gq1.yahoo.com> Message-ID: <87hc4vdzp2.fsf@mcbain.luannocracy.com> on Mon Dec 22 2008, "Ralf W. Grosse-Kunstleve" wrote: > Thanks for the patches! They are now in the boost trunk: > > ------------------------------------------------------------------------ > r50368 | rwgk | 2008-12-22 23:55:33 -0800 (Mon, 22 Dec 2008) | 4 lines > > Boost.Python enable_shared_from_this patches by Nicolas Lelong and Chad Austin: > http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html > http://mail.python.org/pipermail/cplusplus-sig/2008-February/013003.html FYI, Ralf, trunk changes don't get merged automatically to release, so we now need a mechanism to make sure changes we want released are actually released. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From rwgk at yahoo.com Tue Dec 23 22:27:30 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 23 Dec 2008 13:27:30 -0800 (PST) Subject: [C++-sig] Bug and patch for boost.pythonwithenable_shared_from_this References: <229148.259.qm@web31108.mail.mud.yahoo.com> <006501c95c3e$cd570610$d100a8c0@nicopc> <17fe01c95c69$a505c4f0$d100a8c0@nicopc> <201094.63149.qm@web111410.mail.gq1.yahoo.com> <87hc4vdzp2.fsf@mcbain.luannocracy.com> Message-ID: <341728.23668.qm@web111406.mail.gq1.yahoo.com> Oh, that's new to me. Thanks! Is there a web page describing the release procedure? (A quick search didn't get me to the right place.) ----- Original Message ---- From: David Abrahams To: Development of Python/C++ integration Sent: Tuesday, December 23, 2008 1:10:33 AM Subject: Re: [C++-sig] Bug and patch for boost.pythonwithenable_shared_from_this on Mon Dec 22 2008, "Ralf W. Grosse-Kunstleve" wrote: > Thanks for the patches! They are now in the boost trunk: > > ------------------------------------------------------------------------ > r50368 | rwgk | 2008-12-22 23:55:33 -0800 (Mon, 22 Dec 2008) | 4 lines > > Boost.Python enable_shared_from_this patches by Nicolas Lelong and Chad Austin: > http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html > http://mail.python.org/pipermail/cplusplus-sig/2008-February/013003.html FYI, Ralf, trunk changes don't get merged automatically to release, so we now need a mechanism to make sure changes we want released are actually released. -- Dave Abrahams BoostPro Computing http://www.boostpro.com _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig