From jonas at MIT.EDU Sun Feb 1 16:37:51 2009 From: jonas at MIT.EDU (Eric Jonas) Date: Sun, 01 Feb 2009 10:37:51 -0500 Subject: [C++-sig] Shared pointers and new objects Message-ID: <1233502671.6844.3.camel@hermitian> I am trying to return a shared pointer to a class Foo and then test the results in python for equality, but they always seem to fail. I've created the following two trivial classes: class Foo : public boost::noncopyable { }; typedef boost::shared_ptr pFoo_t; class FooCreator { public: pFoo_t createFoo() { pFoo_t ft(new Foo); intfoo = ft; return ft; } pFoo_t getFoo() { return intfoo; } pFoo_t intfoo; }; That I expose with boost::python via: class_("Foo", no_init); class_("FooCreator") .def("createFoo", &FooCreator::createFoo) .def("getFoo", &FooCreator::getFoo); Yet the following assert fails: fc = FooCreator() foo = fc.createFoo() foo2 = fc.getFoo() assert_equal(foo, foo2) The above assert fails. I've tried using the newest boost::python, I've looked through the mailing list archives and even asked on IRC, but I still can't figure out which part of this process I'm doing incorrectly. I've spent about 20 hours reducing my problem to this test case, and am really stumped. ...Eric From rwgk at yahoo.com Sun Feb 1 21:01:36 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 1 Feb 2009 12:01:36 -0800 (PST) Subject: [C++-sig] Shared pointers and new objects References: <1233502671.6844.3.camel@hermitian> Message-ID: <461651.92664.qm@web111404.mail.gq1.yahoo.com> I had trouble with this myself a few years ago: http://mail.python.org/pipermail/cplusplus-sig/2006-March/010095.html (My reaction was a redesign of my parent/child types, so shared pointers don't explicitly appear in the interfaces anymore.) ----- Original Message ---- From: Eric Jonas To: cplusplus-sig at python.org Sent: Sunday, February 1, 2009 7:37:51 AM Subject: [C++-sig] Shared pointers and new objects I am trying to return a shared pointer to a class Foo and then test the results in python for equality, but they always seem to fail. I've created the following two trivial classes: class Foo : public boost::noncopyable { }; typedef boost::shared_ptr pFoo_t; class FooCreator { public: pFoo_t createFoo() { pFoo_t ft(new Foo); intfoo = ft; return ft; } pFoo_t getFoo() { return intfoo; } pFoo_t intfoo; }; That I expose with boost::python via: class_("Foo", no_init); class_("FooCreator") .def("createFoo", &FooCreator::createFoo) .def("getFoo", &FooCreator::getFoo); Yet the following assert fails: fc = FooCreator() foo = fc.createFoo() foo2 = fc.getFoo() assert_equal(foo, foo2) The above assert fails. I've tried using the newest boost::python, I've looked through the mailing list archives and even asked on IRC, but I still can't figure out which part of this process I'm doing incorrectly. I've spent about 20 hours reducing my problem to this test case, and am really stumped. ...Eric _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From hugo.lima at openbossa.org Mon Feb 2 13:21:09 2009 From: hugo.lima at openbossa.org (Hugo Lima) Date: Mon, 2 Feb 2009 10:21:09 -0200 Subject: [C++-sig] virtual functions and bind size reduction In-Reply-To: <587097.45029.qm@web111404.mail.gq1.yahoo.com> References: <95291a80901301252p1525ef0paf631578d7f70e1f@mail.gmail.com> <587097.45029.qm@web111404.mail.gq1.yahoo.com> Message-ID: <7ebf1b2a0902020421s53a469e7i15cc52a90e762a10@mail.gmail.com> On Fri, Jan 30, 2009 at 11:13 PM, Ralf W. Grosse-Kunstleve wrote: >> This apparently works fine when running in same module but if I create a class > >> derived from Base in another module (another library), this stop >> working because the dynamic_cast fails. > > Simple idea: is the other module imported before the dynamic_cast is executed? > That's probably important. > (Not sure that's it; I hardly ever work with virtual functions.) The second module is linked against the first one, so I think that the linker should load all shared libraries before any python::boost code get executed. > Ralf > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From sardana.yamini at gmail.com Mon Feb 2 17:08:49 2009 From: sardana.yamini at gmail.com (yamini sardana) Date: Mon, 2 Feb 2009 16:08:49 +0000 Subject: [C++-sig] Passing pointer to c++ functions. Message-ID: <4bac06a0902020808u716b0ec7rfbc30355480aca82@mail.gmail.com> Hi, How do we pass a pointer to a c++ function from python. I have to call the below mentioned function from python long afSigGenDll_Manual_LevelMax_Get(afSigGenInstance_t sigGenId, double* pLevelMax); When i am calling the function with the second argument as pLevelMax = pointer(c_double()) its giving me an error: Traceback (most recent call last): File "", line 1, in TypeError: in method 'afSigGenDll_Manual_LevelMax_Get', argument 2 of type 'double *' Please le me know what is the correct way to pass pointers as arguments to c++ functions. Thanks in advance Regards, Yamini -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Mon Feb 2 19:52:59 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 2 Feb 2009 10:52:59 -0800 (PST) Subject: [C++-sig] virtual functions and bind size reduction References: <95291a80901301252p1525ef0paf631578d7f70e1f@mail.gmail.com> <587097.45029.qm@web111404.mail.gq1.yahoo.com> <7ebf1b2a0902020421s53a469e7i15cc52a90e762a10@mail.gmail.com> Message-ID: <449608.36553.qm@web111411.mail.gq1.yahoo.com> > The second module is linked against the first one, so I think that the > linker should load all shared libraries before any python::boost code > get executed. Python needs to execute the init function in the first module. I.e. you have to have an import from Python. You could do the Python import from the init of the second module, but for quick testing, just insert the import somewhere so that it appears before you expect the dynamic_cast to work. From hugo.lima at openbossa.org Tue Feb 3 18:55:49 2009 From: hugo.lima at openbossa.org (Hugo Lima) Date: Tue, 3 Feb 2009 15:55:49 -0200 Subject: [C++-sig] Enums with duplicated values. In-Reply-To: <87ljuclxou.fsf@mcbain.luannocracy.com> References: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> <87ljuclxou.fsf@mcbain.luannocracy.com> Message-ID: <7ebf1b2a0902030955v37eee756g63cde8fdd7fc4d10@mail.gmail.com> On Fri, Dec 19, 2008 at 12:13 AM, David Abrahams wrote: > > 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. I agree, so I'm sending a patch that does exactly this. If the enum does not have duplicated values, all remains the same (the "values" attribute is a dict of value=>enum_type). If it has duplicated values, the duplicated values point to a tuple of enum_types in the values attr dict. Remarks: - Maybe I should use lists instead of tuples to avoid the list <=> tuple conversion - I did not use tuples for all entries in the values attribute to keep the source compatibility. If this patch get accepted, is there any chance to include it in the 1.38.0 release? >> 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 > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- A non-text attachment was scrubbed... Name: enum_with_duplicated_values.patch Type: application/octet-stream Size: 1483 bytes Desc: not available URL: From andras.pap at coventor.com Wed Feb 4 17:46:52 2009 From: andras.pap at coventor.com (Andras Pap) Date: Wed, 04 Feb 2009 11:46:52 -0500 Subject: [C++-sig] "extension class wrapper for base class has not been created yet" error message on Linux for a project that works fine on Windows Message-ID: <4989C67C.60609@coventor.com> I am creating a base class "Base::Foo" in Foo.dll(so) and expose it in the FooWrapper.pyd(so) module. Class "Derived::Bar" derives from Base::Foo and is in the Bar.dll(so) and exposed in the BarWrapper.pyd(so) module. On Windows the following works fine: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import FooWrapper >>> import BarWrapper >>> foo = FooWrapper.Foo() >>> bar = BarWrapper.Bar() >>> foo.sayHello() Hi I am Foo! >>> bar.sayHello() Hi I am Bar! >>> On Linux I get the: RuntimeError: extension class wrapper for base class Base::Foo has not been created yet error: Python 2.4.2 (#1, Jul 2 2008, 10:27:50) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import FooWrapper >>> import BarWrapper Traceback (most recent call last): File "", line 1, in ? RuntimeError: extension class wrapper for base class Base::Foo has not been created yet >>> Instantiating "foo" before trying to import BarWrapper does not help: Python 2.4.2 (#1, Jul 2 2008, 10:27:50) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import FooWrapper >>> foo = FooWrapper.Foo() >>> foo.sayHello() Hi I am Foo! >>> import BarWrapper Traceback (most recent call last): File "", line 1, in ? RuntimeError: extension class wrapper for base class Base::Foo has not been created yet >>> I am hoping that I am missing a simple step, can anyone help what it may be? Here are: Foo.cpp/h, FooWrapper.cpp Bar.cpp/h and BarWrapper.cpp: foo.h: #ifndef BASE_FOO_H #define BASE_FOO_H namespace Base { class TEST_BASE Foo { public: /// ctor Foo(); /// dtor virtual ~Foo(); virtual void sayHello(); }; } // namespace Base #endif //BASE_FOO_H foo.cpp: #include #include "Foo.h" using namespace Base; Foo::Foo() { }; Foo::~Foo() { }; void Foo::sayHello() { std::cout << "Hi I am Foo!" << std:: endl; } FooWrapper.h: #include #include #include #include #include BOOST_PYTHON_MODULE(FooWrapper) { using namespace std; using namespace boost::python; using namespace Base; // Python wrapper for MaterialDocument class_("Foo") .def("sayHello", &Foo::sayHello) ; } Bar.h: #ifndef DERIVED_BAR_H #define DERIVED_BAR_H #include "Foo.h" namespace Derived { class TEST_DERIVED Bar : public Base::Foo { public: /// ctor Bar(); /// dtor virtual ~Bar(); virtual void sayHello(); }; } // namespace Derived #endif //DERIVED_BAR_H Bar.cpp #include #include "Bar.h" using namespace Derived; Bar::Bar() : Base::Foo() { }; Bar::~Bar() { }; void Bar::sayHello() { std::cout << "Hi I am Bar!" << std:: endl; } BarWrapper.cpp #include #include #include #include #include #include #include BOOST_PYTHON_MODULE(BarWrapper) { using namespace std; using namespace boost::python; using namespace Derived; // Python wrapper for MaterialDocument class_ >("Bar") .def("sayHello", &Bar::sayHello) ; } -- ---------------------------------------------- Andras Pap Ph:(617)497-6880x233 Coventor, Inc. Fax: (617)497-6882 apap at coventor.com Cell: (617)512-5768 ---------------------------------------------- From renatox at gmail.com Wed Feb 4 18:08:54 2009 From: renatox at gmail.com (Renato Araujo) Date: Wed, 4 Feb 2009 14:08:54 -0300 Subject: [C++-sig] "extension class wrapper for base class has not been created yet" error message on Linux for a project that works fine on Windows In-Reply-To: <4989C67C.60609@coventor.com> References: <4989C67C.60609@coventor.com> Message-ID: <95291a80902040908k7110cddduee97a8bf9687e83b@mail.gmail.com> Hi, I got a error like this, I solved this fixing the order of the link flags, libboost_python need be the first library. BR On Wed, Feb 4, 2009 at 1:46 PM, Andras Pap wrote: > I am creating a base class "Base::Foo" in Foo.dll(so) and expose it in the > FooWrapper.pyd(so) module. Class "Derived::Bar" derives from Base::Foo and > is in the Bar.dll(so) and exposed in the BarWrapper.pyd(so) module. > > On Windows the following works fine: > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import FooWrapper >>>> import BarWrapper >>>> foo = FooWrapper.Foo() >>>> bar = BarWrapper.Bar() >>>> foo.sayHello() > Hi I am Foo! >>>> bar.sayHello() > Hi I am Bar! >>>> > > On Linux I get the: > RuntimeError: extension class wrapper for base class Base::Foo has not been > created yet error: > Python 2.4.2 (#1, Jul 2 2008, 10:27:50) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import FooWrapper >>>> import BarWrapper > Traceback (most recent call last): > File "", line 1, in ? > RuntimeError: extension class wrapper for base class Base::Foo has not been > created yet >>>> > > Instantiating "foo" before trying to import BarWrapper does not help: > Python 2.4.2 (#1, Jul 2 2008, 10:27:50) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import FooWrapper >>>> foo = FooWrapper.Foo() >>>> foo.sayHello() > Hi I am Foo! >>>> import BarWrapper > Traceback (most recent call last): > File "", line 1, in ? > RuntimeError: extension class wrapper for base class Base::Foo has not been > created yet >>>> > > I am hoping that I am missing a simple step, can anyone help what it may be? > > > Here are: Foo.cpp/h, FooWrapper.cpp Bar.cpp/h and BarWrapper.cpp: > foo.h: > #ifndef BASE_FOO_H > #define BASE_FOO_H > > namespace Base > { > > class TEST_BASE Foo > { > > public: > /// ctor > Foo(); > > /// dtor > virtual ~Foo(); > > virtual void sayHello(); > }; > > } // namespace Base > > #endif //BASE_FOO_H > > foo.cpp: > #include > #include "Foo.h" > > using namespace Base; > > Foo::Foo() > { > }; > > Foo::~Foo() > { > }; > > void Foo::sayHello() > { > std::cout << "Hi I am Foo!" << std:: endl; > } > > FooWrapper.h: > #include > #include > > #include > #include > > #include > > BOOST_PYTHON_MODULE(FooWrapper) > { > using namespace std; > using namespace boost::python; > using namespace Base; > > // Python wrapper for MaterialDocument > class_("Foo") > .def("sayHello", &Foo::sayHello) > ; > } > > Bar.h: > #ifndef DERIVED_BAR_H > #define DERIVED_BAR_H > > #include "Foo.h" > > namespace Derived > { > > class TEST_DERIVED Bar : public Base::Foo > { > > public: > /// ctor > Bar(); > > /// dtor > virtual ~Bar(); > > virtual void sayHello(); > }; > > } // namespace Derived > > #endif //DERIVED_BAR_H > > Bar.cpp > #include > #include "Bar.h" > > using namespace Derived; > > Bar::Bar() : Base::Foo() > { > }; > > Bar::~Bar() > { > }; > > void Bar::sayHello() > { > std::cout << "Hi I am Bar!" << std:: endl; > } > > BarWrapper.cpp > #include > #include > > #include > #include > > #include > #include > > #include > > BOOST_PYTHON_MODULE(BarWrapper) > { > using namespace std; > using namespace boost::python; > using namespace Derived; > > // Python wrapper for MaterialDocument > class_ >("Bar") > .def("sayHello", &Bar::sayHello) > ; > } > > > > > -- > ---------------------------------------------- > Andras Pap Ph:(617)497-6880x233 > Coventor, Inc. Fax: (617)497-6882 > apap at coventor.com Cell: (617)512-5768 > ---------------------------------------------- > > _______________________________________________ > 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 Wed Feb 4 19:49:18 2009 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Wed, 04 Feb 2009 19:49:18 +0100 Subject: [C++-sig] Python-overridable method taking const ref? Message-ID: <4989E32E.1070108@assumetheposition.nl> Hello, Classes with protected destructors (as found when custom reference counting is used) seem to cause some trouble when using bp::wrapper<> containing a method that takes a const reference to a refcounted class. Say I have: #include #include namespace bp = boost::python; class Thing { protected: virtual ~Thing() {} }; class Callback { public: Callback() { } virtual void execute(const Thing& t) { } protected: virtual ~Callback() {} }; And I want to add a wrapper class so that Callback can be derived from in Python and its execute() method overridden. Simply writing struct CallbackWrap : Callback, bp::wrapper { void execute(const Thing& t) { if (bp::override ovr = this->get_override("execute")) { fprintf(stderr, "have override, calling...\n"); ovr(t); fprintf(stderr, "done calling\n"); } else Callback::execute(t); } void default_execute(const Thing& t) { fprintf(stderr, "default\n"); this->Callback::execute(t); } }; BOOST_PYTHON_MODULE(doh) { bp::class_("Thing") ; bp::class_("Callback") .def("execute", &Callback::execute, &CallbackWrap::default_execute) ; } doesn't cut it as I get a compile error due to Thing::~Thing() being protected. I've found in the archive the trick you can use to wrap a normal method taking a const reference, e.g. void Callback_execute(Callback& self, Thing& t) { // Work around the const Thing& parameter self.execute(t); } bp::class_("Callback") .dep("execute", &Callback_execute) ; But I don't see how I can use that in the case of the wrapper class. I tried adding functions that do the equivalent thing but for method Callback::execute() and CallbackWrap::default_execute() but that doesn't compile. And I can't find in the documentation of class_<>::def() the exact requirements for the special case of .def() that is used when the extra default implementation is specified. Is there a way to get wrapper classes to work in this situation? Thanks, Paul From roman.yakovenko at gmail.com Wed Feb 4 20:15:03 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 4 Feb 2009 21:15:03 +0200 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <4989E32E.1070108@assumetheposition.nl> References: <4989E32E.1070108@assumetheposition.nl> Message-ID: <7465b6170902041115k433b8ed3p4c980b42bd557246@mail.gmail.com> On Wed, Feb 4, 2009 at 8:49 PM, Paul Melis wrote: > Hello, > > Classes with protected destructors (as found when custom reference > counting is used) seem to cause some trouble when using bp::wrapper<> > containing a method that takes a const reference to a refcounted class. > > Say I have: > > #include > #include > > namespace bp = boost::python; > > class Thing > { > protected: > virtual ~Thing() {} > }; > > class Callback > { > public: > Callback() { } > virtual void execute(const Thing& t) { } > protected: > virtual ~Callback() {} > }; > > And I want to add a wrapper class so that Callback can be derived from > in Python and its execute() method overridden. Try the following code: #include "boost/python.hpp" namespace bp = boost::python; struct Callback_wrapper : Callback, bp::wrapper< Callback > { Callback_wrapper( ) : Callback( ) , bp::wrapper< Callback >(){ // null constructor } virtual void execute( ::Thing const & t ) { if( bp::override func_execute = this->get_override( "execute" ) ) func_execute( boost::ref(t) ); else this->Callback::execute( boost::ref(t) ); } void default_execute( ::Thing const & t ) { Callback::execute( boost::ref(t) ); } }; BOOST_PYTHON_MODULE(pyplusplus){ bp::class_< Callback_wrapper, boost::noncopyable >( "Callback", bp::no_init ) .def( bp::init< >() ) .def( "execute" , (void ( ::Callback::* )( ::Thing const & ) )(&::Callback::execute) , (void ( Callback_wrapper::* )( ::Thing const & ) )(&Callback_wrapper::default_execute) , ( bp::arg("t") ) ); bp::class_< Thing, boost::noncopyable >( "Thing", bp::no_init ); } It was generated by Py++ and I believe it exposes your use case correctly. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pyplusplus at assumetheposition.nl Wed Feb 4 20:26:16 2009 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Wed, 04 Feb 2009 20:26:16 +0100 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <7465b6170902041115k433b8ed3p4c980b42bd557246@mail.gmail.com> References: <4989E32E.1070108@assumetheposition.nl> <7465b6170902041115k433b8ed3p4c980b42bd557246@mail.gmail.com> Message-ID: <4989EBD8.4070502@assumetheposition.nl> Hi Roman, Roman Yakovenko wrote: > On Wed, Feb 4, 2009 at 8:49 PM, Paul Melis > wrote: > >> Classes with protected destructors (as found when custom reference >> counting is used) seem to cause some trouble when using bp::wrapper<> >> containing a method that takes a const reference to a refcounted class. >> >> Say I have: >> >> #include >> #include >> >> namespace bp = boost::python; >> >> class Thing >> { >> protected: >> virtual ~Thing() {} >> }; >> >> class Callback >> { >> public: >> Callback() { } >> virtual void execute(const Thing& t) { } >> protected: >> virtual ~Callback() {} >> }; >> >> And I want to add a wrapper class so that Callback can be derived from >> in Python and its execute() method overridden. >> > > Try the following code: > > #include "boost/python.hpp" > > namespace bp = boost::python; > > struct Callback_wrapper : Callback, bp::wrapper< Callback > { > > Callback_wrapper( ) > : Callback( ) > , bp::wrapper< Callback >(){ > // null constructor > > } > > virtual void execute( ::Thing const & t ) { > if( bp::override func_execute = this->get_override( "execute" ) ) > func_execute( boost::ref(t) ); > else > this->Callback::execute( boost::ref(t) ); > } > > > void default_execute( ::Thing const & t ) { > Callback::execute( boost::ref(t) ); > } > > }; > > BOOST_PYTHON_MODULE(pyplusplus){ > bp::class_< Callback_wrapper, boost::noncopyable >( "Callback", > bp::no_init ) > .def( bp::init< >() ) > .def( > "execute" > , (void ( ::Callback::* )( ::Thing const & ) )(&::Callback::execute) > , (void ( Callback_wrapper::* )( ::Thing const & ) > )(&Callback_wrapper::default_execute) > , ( bp::arg("t") ) ); > > bp::class_< Thing, boost::noncopyable >( "Thing", bp::no_init ); > } > > It was generated by Py++ and I believe it exposes your use case correctly. > > But it doesn't compile (after adding the classes Thing and Callback at the top). I get another error that Thing::~Thing() is protected: g++ -o doh.so -fPIC -shared -I /usr/include/python2.5 -I /usr/include -L /usr/lib -lboost_python -lpython2.5 t.cc t.cc: In static member function 'static void boost::python::detail::value_destroyer::execute(const volatile T*) [with T = Thing]': /usr/include/boost/python/detail/destroy.hpp:90: instantiated from 'void boost::python::detail::destroy_referent_impl(void*, T& (*)()) [with T = const Thing]' /usr/include/boost/python/detail/destroy.hpp:101: instantiated from 'void boost::python::detail::destroy_referent(void*, T (*)()) [with T = const Thing&]' /usr/include/boost/python/converter/rvalue_from_python_data.hpp:135: instantiated from 'boost::python::converter::rvalue_from_python_data::~rvalue_from_python_data() [with T = const Thing&]' /usr/include/boost/python/converter/arg_from_python.hpp:108: instantiated from 'PyObject* boost::python::detail::caller_arity<2u>::impl::operator()(PyObject*, PyObject*) [with F = void (Callback_wrapper::*)(const Thing&), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector3]' /usr/include/boost/python/object/py_function.hpp:38: instantiated from 'PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller >]' t.cc:54: instantiated from here t.cc:8: error: 'virtual Thing::~Thing()' is protected /usr/include/boost/python/detail/destroy.hpp:33: error: within this context Which isn't surprising as your code uses the same method signatures in Callback_wrapper as mine, and does the same set of def()'s... Paul From roman.yakovenko at gmail.com Wed Feb 4 20:51:13 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 4 Feb 2009 21:51:13 +0200 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <4989EBD8.4070502@assumetheposition.nl> References: <4989E32E.1070108@assumetheposition.nl> <7465b6170902041115k433b8ed3p4c980b42bd557246@mail.gmail.com> <4989EBD8.4070502@assumetheposition.nl> Message-ID: <7465b6170902041151w1c2bde9fv61a73cf4cdd0ff74@mail.gmail.com> On Wed, Feb 4, 2009 at 9:26 PM, Paul Melis wrote: > Hi Roman, Try this one, works for me: // This file has been generated by Py++. // Copyright 2004-2008 Roman Yakovenko. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include "boost/python.hpp" #include "__call_policies.pypp.hpp" #include "__convenience.pypp.hpp" #include "protected_to_be_exported.hpp" namespace bp = boost::python; struct Callback_wrapper : Callback, bp::wrapper< Callback > { Callback_wrapper( ) : Callback( ) , bp::wrapper< Callback >(){ // null constructor } virtual void execute( ::Thing const & t ) { namespace bpl = boost::python; if( bpl::override func_execute = this->get_override( "execute" ) ){ bpl::object py_result = bpl::call( func_execute.ptr(), t ); } else{ Callback::execute( boost::ref(t) ); } } static void default_execute( ::Callback & inst, ::Thing & t ){ if( dynamic_cast< Callback_wrapper * >( boost::addressof( inst ) ) ){ inst.::Callback::execute(t); } else{ inst.execute(t); } } //hhhh }; BOOST_PYTHON_MODULE(protected){ { //::Callback typedef bp::class_< Callback_wrapper, boost::noncopyable > Callback_exposer_t; Callback_exposer_t Callback_exposer = Callback_exposer_t( "Callback", "documentation", bp::no_init ); bp::scope Callback_scope( Callback_exposer ); Callback_exposer.def( bp::init< >("documentation") ); { //::Callback::execute typedef void ( *default_execute_function_type )( ::Callback &,::Thing & ); Callback_exposer.def( "execute" , default_execute_function_type( &Callback_wrapper::default_execute ) , ( bp::arg("inst"), bp::arg("t") ) , "documentation" ); } } { //::Thing typedef bp::class_< Thing, boost::noncopyable > Thing_exposer_t; Thing_exposer_t Thing_exposer = Thing_exposer_t( "Thing", "documentation", bp::no_init ); bp::scope Thing_scope( Thing_exposer ); } } > Which isn't surprising as your code uses the same method signatures in > Callback_wrapper as mine, and does the same set of def()'s... The idea is to remove "const" from Thing argument. This will disallow Boost.Python to create temporal object. Another difference is that the generated code passes arguments by reference: boost::ref. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pyplusplus at assumetheposition.nl Wed Feb 4 21:30:05 2009 From: pyplusplus at assumetheposition.nl (Paul Melis) Date: Wed, 04 Feb 2009 21:30:05 +0100 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <7465b6170902041151w1c2bde9fv61a73cf4cdd0ff74@mail.gmail.com> References: <4989E32E.1070108@assumetheposition.nl> <7465b6170902041115k433b8ed3p4c980b42bd557246@mail.gmail.com> <4989EBD8.4070502@assumetheposition.nl> <7465b6170902041151w1c2bde9fv61a73cf4cdd0ff74@mail.gmail.com> Message-ID: <4989FACD.6030303@assumetheposition.nl> Roman Yakovenko wrote: > On Wed, Feb 4, 2009 at 9:26 PM, Paul Melis > wrote: > >> Hi Roman, >> > > Try this one, works for me: > // This file has been generated by Py++. > > // Copyright 2004-2008 Roman Yakovenko. > // Distributed under the Boost Software License, Version 1.0. (See > // accompanying file LICENSE_1_0.txt or copy at > // http://www.boost.org/LICENSE_1_0.txt) > > #include "boost/python.hpp" > > #include "__call_policies.pypp.hpp" > > #include "__convenience.pypp.hpp" > > #include "protected_to_be_exported.hpp" > > namespace bp = boost::python; > > struct Callback_wrapper : Callback, bp::wrapper< Callback > { > > Callback_wrapper( ) > : Callback( ) > , bp::wrapper< Callback >(){ > // null constructor > > } > > virtual void execute( ::Thing const & t ) { > namespace bpl = boost::python; > if( bpl::override func_execute = this->get_override( "execute" ) ){ > bpl::object py_result = bpl::call( > func_execute.ptr(), t ); > } > else{ > Callback::execute( boost::ref(t) ); > } > } > > static void default_execute( ::Callback & inst, ::Thing & t ){ > if( dynamic_cast< Callback_wrapper * >( boost::addressof( inst ) ) ){ > inst.::Callback::execute(t); > } > else{ > inst.execute(t); > } > } > > //hhhh > > }; > > BOOST_PYTHON_MODULE(protected){ > { //::Callback > typedef bp::class_< Callback_wrapper, boost::noncopyable > > Callback_exposer_t; > Callback_exposer_t Callback_exposer = Callback_exposer_t( > "Callback", "documentation", bp::no_init ); > bp::scope Callback_scope( Callback_exposer ); > Callback_exposer.def( bp::init< >("documentation") ); > { //::Callback::execute > > typedef void ( *default_execute_function_type )( > ::Callback &,::Thing & ); > > Callback_exposer.def( > "execute" > , default_execute_function_type( > &Callback_wrapper::default_execute ) > , ( bp::arg("inst"), bp::arg("t") ) > , "documentation" ); > > } > } > > { //::Thing > typedef bp::class_< Thing, boost::noncopyable > Thing_exposer_t; > Thing_exposer_t Thing_exposer = Thing_exposer_t( "Thing", > "documentation", bp::no_init ); > bp::scope Thing_scope( Thing_exposer ); > } > } > > > >> Which isn't surprising as your code uses the same method signatures in >> Callback_wrapper as mine, and does the same set of def()'s... >> > > > The idea is to remove "const" from Thing argument. This will disallow > Boost.Python to create temporal object. > Right, I knew that was necessary, but just didn't see how to accomplish it. Thanks, this helps! > Another difference is that the generated code passes arguments by > reference: boost::ref. > Why is that? It doesn't seem to be needed Paul From sumeetr at qualcomm.com Thu Feb 5 02:58:08 2009 From: sumeetr at qualcomm.com (Rao, Sumeeth) Date: Wed, 4 Feb 2009 17:58:08 -0800 Subject: [C++-sig] Class scoped enum losing scope Message-ID: Hello I am a newbie in using boost python. I use boost python version 1.33.1, on linux x64 Fedora 9 2.6.26.3-29 kernel. Here is a problem I am facing: C++ code: class Foo{ public: typedef enum { TYPE_A, TYPE_B, TYPE_C }eType; }; class Bar { public: bool barfun(Foo::etype type); }; Boost Python bindings: In foo.pypp.cpp: void register_Foo_class(){ { //::Foo typedef bp::class_< Foo > Foo_exposer_t; Foo_exposer_t Foo_exposer = Foo_exposer_t( "Foo" ); bp::scope Foo_scope( Foo_exposer ); bp::enum_< Foo::eType>("eType") .value("TYPE_A", Foo::TYPE_A) .value("TYPE_B", Foo::TYPE_B) .value("TYPE_C", Foo::TYPE_C) .export_values() ; } In bar.pypp.cpp: struct Bar_wrapper : Bar, bp::wrapper { ...... bool barfun( ::Foo::eType eType,) { if( bp::override func_barfun = this->get_override( "barfun" ) ) return func_barfun( eType); else return this->Bar::barfun( eType); } bool default_barfun( ::Foo::eType eType) { return Bar::barfun( eType); } ..... }; void register_Bar_class(){ bp::class_< Bar_wrapper >( "Bar" ) ..... .def( "barfun" , &::Bar::barfun , &bar_wrapper::default_barfun , ( bp::arg("eType") ) ) ..... }; >python >>> import Boost_FooBar >>> >>> bar = Boost_FooBar.Bar() >>> >>> var = Boost_FooBar.Foo.eType.TYPE_B < --Seems to understand that there is a Foo::etype::TYPE_B value >>> var Boost_FooBar.eType.TYPE_B <------------------ var seems to have "lost" the scope of class Foo! >>> print var TYPE_B >>> >>> stat = bar.barfun(Boost_FooBar.Foo.eType.TYPE_B) Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in Bar.barfun(Bar, Boost_FooBar.eType) < ------ Why is the parameter not of type Boost_FooBar.Foo.eType? did not match C++ signature: barfun(Bar_wrapper {lvalue}, Foo::eType eType) barfun(Bar {lvalue}, Foo::eType eType) Could someone help me in figuring out the problem why the class scope is being "lost" or the reason python is converting Boost_FooBar.Foo.eType to Boost_FooBar.eType Thanks Sumeet -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boostpro.com Thu Feb 5 03:56:12 2009 From: dave at boostpro.com (David Abrahams) Date: Wed, 04 Feb 2009 18:56:12 -0800 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <4989E32E.1070108@assumetheposition.nl> (Paul Melis's message of "Wed, 04 Feb 2009 19:49:18 +0100") References: <4989E32E.1070108@assumetheposition.nl> Message-ID: <87zlh1y4kz.fsf@mcbain.luannocracy.com> on Wed Feb 04 2009, Paul Melis wrote: > Hello, > > Classes with protected destructors (as found when custom reference > counting is used) seem to cause some trouble when using bp::wrapper<> > containing a method that takes a const reference to a refcounted class. > > struct CallbackWrap : Callback, bp::wrapper > { > void execute(const Thing& t) > { > if (bp::override ovr = this->get_override("execute")) > { > fprintf(stderr, "have override, calling...\n"); > ovr(t); ^^^^^^ The problem is here, right? If you want to pass an object by reference to a python function, you have to wrap it in boost::ref(). Otherwise, it will try to copy the object and the resulting copy will have to be destroyed after the call. > fprintf(stderr, "done calling\n"); > } > else > Callback::execute(t); > } > > void default_execute(const Thing& t) > { > fprintf(stderr, "default\n"); > this->Callback::execute(t); > } > }; -- Dave Abrahams BoostPro Computing http://www.boostpro.com From roman.yakovenko at gmail.com Thu Feb 5 06:00:56 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 5 Feb 2009 07:00:56 +0200 Subject: [C++-sig] Python-overridable method taking const ref? In-Reply-To: <87zlh1y4kz.fsf@mcbain.luannocracy.com> References: <4989E32E.1070108@assumetheposition.nl> <87zlh1y4kz.fsf@mcbain.luannocracy.com> Message-ID: <7465b6170902042100i606121dcs9d9bbf237c1dfe62@mail.gmail.com> On Thu, Feb 5, 2009 at 4:56 AM, David Abrahams wrote: > > on Wed Feb 04 2009, Paul Melis wrote: > >> Hello, >> >> Classes with protected destructors (as found when custom reference >> counting is used) seem to cause some trouble when using bp::wrapper<> >> containing a method that takes a const reference to a refcounted class. >> > >> struct CallbackWrap : Callback, bp::wrapper >> { >> void execute(const Thing& t) >> { >> if (bp::override ovr = this->get_override("execute")) >> { >> fprintf(stderr, "have override, calling...\n"); >> ovr(t); > ^^^^^^ > The problem is here, right? Not only. As you know, "const T&" allows Boost.Python to create temporal object and than call the function, so I guess the compilation error was arrived from that functionality. If you take a look on my first answer, this is exactly what I did and it didn't help, at least not on GCC 4.3. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From meine at informatik.uni-hamburg.de Thu Feb 5 09:51:50 2009 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 5 Feb 2009 09:51:50 +0100 Subject: [C++-sig] Class scoped enum losing scope In-Reply-To: References: Message-ID: <200902050951.50864.meine@informatik.uni-hamburg.de> On Thursday 05 February 2009 02:58:08 Rao, Sumeeth wrote: > >>> import Boost_FooBar > >>> > >>> bar = Boost_FooBar.Bar() > >>> > >>> var = Boost_FooBar.Foo.eType.TYPE_B < --Seems to understand > that there is a Foo::etype::TYPE_B value > >>> var > > Boost_FooBar.eType.TYPE_B <------------------ var seems to > have "lost" the scope of class Foo! Yes, that's ugly, and also poses problems with pickling. (The same problem affects other nested types, i.e. classes.) > >>> stat = bar.barfun(Boost_FooBar.Foo.eType.TYPE_B) > > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > Bar.barfun(Bar, Boost_FooBar.eType) < ------ Why is the > parameter not of type Boost_FooBar.Foo.eType? I am not sure that this is the problem; as you demonstrated above, boost will forget about the scope, but you should still be able to use 'var' normally IIRC. Maybe your error is somewhere else? E.g. did you try to expose a global function 'barfun' instead of a Bar member function? (I am unsure, and I never used bp::wrapper so far.) HTH, Hans From william.marie at gmail.com Fri Feb 6 12:56:40 2009 From: william.marie at gmail.com (=?UTF-8?B?V2lsbGlhbSBNYXJpw6k=?=) Date: Fri, 06 Feb 2009 11:56:40 +0000 Subject: [C++-sig] Calling python virtual function from C++ In-Reply-To: <874oziqg07.fsf@mcbain.luannocracy.com> References: <21711534.post@talk.nabble.com> <873af3nmt6.fsf@mcbain.luannocracy.com> <498192AA.9040605@gmail.com> <874oziqg07.fsf@mcbain.luannocracy.com> Message-ID: <498C2578.703@gmail.com> Thank you very much it was exatly that :) David Abrahams a ?crit : > on Thu Jan 29 2009, William Mari? wrote: > > >> Hi David, >> >> Here is the reproducible test ( just change the boost.strap and the python paths in >> the jamroot ) !! >> Thanks for your time >> > > void testVirtualPure( BaseCmp* pBaseCmp ) > { > this->get_override("testVirtualPure")( ptr( pBaseCmp ) ); > } // ^^^^ ^ > > Creating Python objects that reference C++ objects by pointer is > dangerous; if you really want to do that, wrap the C++ pointer in > ptr(...). Otherwise Boost.Python will try to copy it. You declared > BaseCmp to be noncopyable, so no converter was registered that would > copy a BaseCmp object into a new Python object. > > >> David Abrahams a ?crit : >> >>> on Wed Jan 28 2009, William Mari? wrote: >>> >>> >>> >>>> I need to call my testVirtualPure function from C++ side : BaseCmp* bc = BaseCmp(); >>>> Base* b = Base(); >>>> b->testVirtualPure( bc ); >>>> >>>> But this causes an error : TypeError: No to_python (by-value) converter found for >>>> C++ type: class >>>> BaseCmp >>>> >>>> >>> The above doesn't compile, so you can't possibly be getting that >>> TypeError from it. Please post the exact complete, reproducible example >>> that causes youi problems, after reducing it to a minimal test case. >>> >>> Thanks, >>> >>> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > From vadim.macagon at gmail.com Sun Feb 8 12:49:19 2009 From: vadim.macagon at gmail.com (Vadim Macagon) Date: Sun, 08 Feb 2009 21:49:19 +1000 Subject: [C++-sig] built-in submodule creation In-Reply-To: <6fcb94430901151124l40861795t691d7320f8e477ff@mail.gmail.com> References: <6fcb94430901151124l40861795t691d7320f8e477ff@mail.gmail.com> Message-ID: Hi Tim, I haven't been paying much attention to this list lately, so apologies for the late response. If you still haven't figured out a way to do what you wanted perhaps my post on the subject could be of some use: Cheers, Vadim. Tim Prepscius wrote: > I am trying to create built-in sub modules.. I have read everything I > can on this subject.. > =================== > > Is there a better way for me to do this, than executing the python code > segment? > Does anyone know what is going on behind the scenes in the python code > execution? From dave at boostpro.com Sun Feb 8 19:01:03 2009 From: dave at boostpro.com (David Abrahams) Date: Sun, 08 Feb 2009 10:01:03 -0800 Subject: [C++-sig] Shared pointers and new objects In-Reply-To: <1233502671.6844.3.camel@hermitian> (Eric Jonas's message of "Sun, 01 Feb 2009 10:37:51 -0500") References: <1233502671.6844.3.camel@hermitian> Message-ID: <877i40reow.fsf@mcbain.luannocracy.com> on Sun Feb 01 2009, Eric Jonas wrote: > I am trying to return a shared pointer to a class Foo and then > test the results in python for equality, but they always seem to fail. > I've created the following two trivial classes: > > class Foo : public boost::noncopyable > { > }; > > typedef boost::shared_ptr pFoo_t; > > class FooCreator > { > public: > pFoo_t createFoo() { > pFoo_t ft(new Foo); > intfoo = ft; > return ft; > } The key is that you have to associate the python object with the shared_ptr that you're going to return. The original one that wraps the Foo object you created didn't have any relationship to a Python object. Try this: pFoo_t createFoo() { object o(pFoo_t(new Foo)); intFoo = extract(o); return intFoo; } > > pFoo_t getFoo() { > return intfoo; > } > > pFoo_t intfoo; > > }; > > > That I expose with boost::python via: > > class_("Foo", no_init); > > class_("FooCreator") > .def("createFoo", &FooCreator::createFoo) > .def("getFoo", &FooCreator::getFoo); > > Yet the following assert fails: > > fc = FooCreator() > > foo = fc.createFoo() > foo2 = fc.getFoo() > > assert_equal(foo, foo2) > > The above assert fails. I've tried using the newest boost::python, I've > looked through the mailing list archives and even asked on IRC, but I > still can't figure out which part of this process I'm doing incorrectly. > I've spent about 20 hours reducing my problem to this test case, and am > really stumped. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From dave at boostpro.com Sun Feb 8 19:16:41 2009 From: dave at boostpro.com (David Abrahams) Date: Sun, 08 Feb 2009 10:16:41 -0800 Subject: [C++-sig] Passing pointer to c++ functions. In-Reply-To: <4bac06a0902020808u716b0ec7rfbc30355480aca82@mail.gmail.com> (yamini sardana's message of "Mon, 2 Feb 2009 16:08:49 +0000") References: <4bac06a0902020808u716b0ec7rfbc30355480aca82@mail.gmail.com> Message-ID: <87prhspzee.fsf@mcbain.luannocracy.com> on Mon Feb 02 2009, yamini sardana wrote: > Hi, > > How do we pass a pointer to a c++ function from python. > > I have to call the below mentioned function from python > > long afSigGenDll_Manual_LevelMax_Get(afSigGenInstance_t sigGenId, double* > pLevelMax); > > When i am calling the function with the second argument as > pLevelMax = pointer(c_double()) > > its giving me an error: > Traceback (most recent call last): > File "", line 1, in > TypeError: in method 'afSigGenDll_Manual_LevelMax_Get', argument 2 of type > 'double *' > > Please le me know what is the correct way to pass pointers as arguments to > c++ functions. You can't pass a non-const pointer because the python 'Float' type is immutable; changing the double held by the python object (when indeed there is one) would be disastrous. If you want to modify this number youi should wrap your C++ function in something that returns a Python tuple containing a long and a double. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From hugo.lima at openbossa.org Tue Feb 10 13:34:26 2009 From: hugo.lima at openbossa.org (Hugo Lima) Date: Tue, 10 Feb 2009 10:34:26 -0200 Subject: [C++-sig] Enums with duplicated values. In-Reply-To: <7ebf1b2a0902030955v37eee756g63cde8fdd7fc4d10@mail.gmail.com> References: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> <87ljuclxou.fsf@mcbain.luannocracy.com> <7ebf1b2a0902030955v37eee756g63cde8fdd7fc4d10@mail.gmail.com> Message-ID: <7ebf1b2a0902100434r437fbdc4r72e371d0eb4db887@mail.gmail.com> David, any comments about the patch? On Tue, Feb 3, 2009 at 3:55 PM, Hugo Lima wrote: > On Fri, Dec 19, 2008 at 12:13 AM, David Abrahams wrote: >> >> 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. > > I agree, so I'm sending a patch that does exactly this. > If the enum does not have duplicated values, all remains the same (the > "values" attribute is a dict of value=>enum_type). > If it has duplicated values, the duplicated values point to a tuple of > enum_types in the values attr dict. > > Remarks: > - Maybe I should use lists instead of tuples to avoid the list <=> > tuple conversion > - I did not use tuples for all entries in the values attribute to > keep the source compatibility. > > If this patch get accepted, is there any chance to include it in the > 1.38.0 release? > >>> 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 >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > From dave at boostpro.com Tue Feb 10 17:34:23 2009 From: dave at boostpro.com (David Abrahams) Date: Tue, 10 Feb 2009 11:34:23 -0500 Subject: [C++-sig] Enums with duplicated values. In-Reply-To: <7ebf1b2a0902100434r437fbdc4r72e371d0eb4db887@mail.gmail.com> (Hugo Lima's message of "Tue, 10 Feb 2009 10:34:26 -0200") References: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> <87ljuclxou.fsf@mcbain.luannocracy.com> <7ebf1b2a0902030955v37eee756g63cde8fdd7fc4d10@mail.gmail.com> <7ebf1b2a0902100434r437fbdc4r72e371d0eb4db887@mail.gmail.com> Message-ID: <87tz726yk0.fsf@mcbain.luannocracy.com> on Tue Feb 10 2009, Hugo Lima wrote: > David, any comments about the patch? Please attach the patch to a Trac ticket and I'll have a look. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From hugo.lima at openbossa.org Tue Feb 10 18:02:03 2009 From: hugo.lima at openbossa.org (Hugo Lima) Date: Tue, 10 Feb 2009 15:02:03 -0200 Subject: [C++-sig] Enums with duplicated values. In-Reply-To: <87tz726yk0.fsf@mcbain.luannocracy.com> References: <7ebf1b2a0812170835m1816634g8d8fbd8a82cb9849@mail.gmail.com> <87ljuclxou.fsf@mcbain.luannocracy.com> <7ebf1b2a0902030955v37eee756g63cde8fdd7fc4d10@mail.gmail.com> <7ebf1b2a0902100434r437fbdc4r72e371d0eb4db887@mail.gmail.com> <87tz726yk0.fsf@mcbain.luannocracy.com> Message-ID: <7ebf1b2a0902100902n1a8db1fbk6bec73d61e37bd5d@mail.gmail.com> On Tue, Feb 10, 2009 at 2:34 PM, David Abrahams wrote: > > on Tue Feb 10 2009, Hugo Lima wrote: > >> David, any comments about the patch? > > Please attach the patch to a Trac ticket and I'll have a look. Ok, https://svn.boost.org/trac/boost/ticket/2744 > -- > 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 > From rogeeff at gmail.com Tue Feb 10 22:48:13 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Tue, 10 Feb 2009 21:48:13 +0000 (UTC) Subject: [C++-sig] using function objects as getters/setters for the properties Message-ID: Hi, I need to implement some translation in a getter and setter for particular field. I am getting compile time errors, I am not sure how to fix. I am using 1.33.1. Here is what I do: template struct Getter { explicit Getter( MyClass T::* mem ) : m_member( mem ) {} bp::object operator()( T const& obj ) const { return /* conversion here */; } MyClass T::* m_member; }; template Getter make_getter( MyClass T::* mem ) { return Getter( mem ); } .... bp::class_< MyClass >( "MyClass", bp::no_init ) .add_property( "field", make_getter( &MyClass::field ) ) I see following errors: ..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441) : error C2784: 'boost::mpl::vector17::type&, T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> boost::python::detail::get_signature(RT (__thiscall ClassT::* )(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) volatile const,Target *)' : could not deduce template argument for 'T2 (__thiscall T3::* )(T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18) volatile const' from 'const Getter' with [ T=MyClass ] ..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(164): see declaration of 'boost::python::detail::get_signature' ..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(424): see reference to function template instantiation 'boost::python::api::object boost::python::class_:: make_fn_impl(T *,const F &,boost::mpl::false_,void *, boost::mpl::false_)' being compiled with [ W=MyClass, F=Getter, T=MyClass ] ..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(308): see reference to function template instantiation 'boost::python::api::object boost::python::class_:: make_getter(F)' being compiled with [ W=MyClass, Get=Getter, F=Getter ] src\export_riskmgr.cpp(157): see reference to function template instantiation 'boost::python::class_::self &boost::python::class_::add_property> (const char *,Get,const char *)' being compiled with [ W=MyClass, T=MyClass, Get=Getter ] ..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441): error C2780: 'boost::mpl::vector17 boost::python::detail::get_signature(RT (__thiscall ClassT::* )(T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) volatile const)' : expects 1 arguments - 2 provided ..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(146) : see declaration of 'boost::python::detail::get_signature' ..\..\3rdParty\boost-1.33.1\boost\python\class.hpp(441): error C2784: 'boost::mpl::vector17::type&, T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> boost::python::detail::get_signature( RT (__thiscall ClassT::* ) (T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) volatile,Target *)' : could not deduce template argument for 'T2 (__thiscall T3::* ) (T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18) volatile' from 'const Getter' with [ T=MyClass ] ..\..\3rdParty\boost-1.33.1\boost\python\signature.hpp(164) : see declaration of 'boost::python::detail::get_signature' And lots more like this. I've tried to add make_function around. Did not help. Any pointers? Thanks. Gennadiy From dave at boostpro.com Wed Feb 11 02:01:39 2009 From: dave at boostpro.com (David Abrahams) Date: Tue, 10 Feb 2009 20:01:39 -0500 Subject: [C++-sig] using function objects as getters/setters for the properties In-Reply-To: (Gennadiy Rozental's message of "Tue, 10 Feb 2009 21:48:13 +0000 (UTC)") References: Message-ID: <87y6wd3hxo.fsf@mcbain.luannocracy.com> on Tue Feb 10 2009, Gennadiy Rozental wrote: > Hi, > > I need to implement some translation in a getter and setter for particular field. > > I am getting compile time errors, I am not sure how to fix. I am using 1.33.1. > > Here is what I do: > > template > struct Getter { > explicit Getter( MyClass T::* mem ) : m_member( mem ) {} > > bp::object operator()( T const& obj ) const > { > return /* conversion here */; > } > > MyClass T::* m_member; > }; > > template > Getter > make_getter( MyClass T::* mem ) > { > return Getter( mem ); > } > > .... Frankly I'm not sure it's possible to use a function object in that way. Have you tried simply using the data member pointer without the wrapper? bp::class_< MyClass >( "MyClass", bp::no_init ) .add_property( "field", &MyClass::field ) ?? > bp::class_< MyClass >( "MyClass", bp::no_init ) > .add_property( "field", make_getter( &MyClass::field ) ) -- Dave Abrahams BoostPro Computing http://www.boostpro.com From rogeeff at gmail.com Wed Feb 11 07:07:02 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Wed, 11 Feb 2009 06:07:02 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?using_function_objects_as_getters/setters_for?= =?utf-8?q?_the=09properties?= References: <87y6wd3hxo.fsf@mcbain.luannocracy.com> Message-ID: David Abrahams boostpro.com> writes: > Frankly I'm not sure it's possible to use a function object in that way. > Have you tried simply using the data member pointer without the wrapper? > > bp::class_< MyClass >( "MyClass", bp::no_init ) > .add_property( "field", &MyClass::field ) > > ?? Whole point was that the above is not what I want I want the property to have translated value. I found one solution to my problem. template bp::object make_getter( MyClass T::* mem ) { // Unfortunately we have to resort to using function from details, // since public interface is lacking return bp::detail::make_function_aux( Getter( mem ), bp::default_call_policies(), boost::mpl::vector() ); } and this seems to work fine. Ideally get_signature should be updated to work with function objects properly. I am fine with extra typedefs I might be required to make. Also make_function can use named template parameters in most generic form. similar way I was able to create setters: template struct Setter { explicit Setter( MyClass T::* mem ) : m_member( mem ) {} void operator()( T const& obj, bp::object const& val ) const { obj.*m_member = /* reverse conversion here */; } MyClass T::* m_member; }; template bp::object make_setter( MyClass T::* mem ) { // Unfortunately we have to resort to using function from details, // since public interface is lacking return bp::detail::make_function_aux( Setter( mem ), bp::default_call_policies(), boost::mpl::vector() ); } And use it like this: bp::class_< A >( "A", bp::no_init ) .add_property( "fld", make_getter( &A::fld ), make_setter( &A::fld ) ) From sbalasub at qualcomm.com Fri Feb 13 03:21:11 2009 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Thu, 12 Feb 2009 18:21:11 -0800 Subject: [C++-sig] Call Policy for Singleton Message-ID: <3D33964996B3DC489449E5E4D7913750026BB088AD@NALASEXMB11.na.qualcomm.com> HI, The am not sure if which call policy I should be using for this particular use case, class Singleton { public: Singleton* create() { if(!_instance) { _instance = new Singleton(); } return _instance; } static Singleton* _instance; } // Initialization Singleton* _instance=NULL; Is return_value_policy the right call policy to use? Thanks, Shiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaexage at gmail.com Fri Feb 13 04:35:19 2009 From: zaexage at gmail.com (ZaeX) Date: Fri, 13 Feb 2009 11:35:19 +0800 Subject: [C++-sig] Call Policy for Singleton In-Reply-To: <3D33964996B3DC489449E5E4D7913750026BB088AD@NALASEXMB11.na.qualcomm.com> References: <3D33964996B3DC489449E5E4D7913750026BB088AD@NALASEXMB11.na.qualcomm.com> Message-ID: <2c5080560902121935y687004cat6b96dde6bca1f6be@mail.gmail.com> I think reference_existing_object will work. And in my opinion, you'd better be careful if you expect that the c++ code and python code are using the same singleton instance. Because there're two Singleton::_instance if you export the Singleton class to Python. one at c++ side, the other at python side. 2009/2/13 Balasubramanyam, Shivakumar > HI, > > The am not sure if which call policy I should be using for this particular > use case, > > > class Singleton > { > public: > Singleton* create() > { > if(!_instance) > { > _instance = new Singleton(); > } > return _instance; > } > static Singleton* _instance; > } > > // Initialization > Singleton* _instance=NULL; > > Is return_value_policy the right call policy to > use? > > > Thanks, > Shiva > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Time is mana, we must hurry -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Fri Feb 13 10:33:09 2009 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 13 Feb 2009 09:33:09 +0000 Subject: [C++-sig] Call Policy for Singleton In-Reply-To: <2c5080560902121935y687004cat6b96dde6bca1f6be@mail.gmail.com> References: <3D33964996B3DC489449E5E4D7913750026BB088AD@NALASEXMB11.na.qualcomm.com> <2c5080560902121935y687004cat6b96dde6bca1f6be@mail.gmail.com> Message-ID: ZaeX wrote: > And in my opinion, you'd better be careful if you expect that the c++ > code and python code are using the same singleton instance. > Because there're two Singleton::_instance if you export the Singleton > class to Python. one at c++ side, the other at python side. I don't think this is true. What makes you think this? John. From vaclav.haisman at eccam.com Fri Feb 13 15:33:26 2009 From: vaclav.haisman at eccam.com (=?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?=) Date: Fri, 13 Feb 2009 15:33:26 +0100 Subject: [C++-sig] Returning PyObject and return_internal_reference<> Message-ID: <499584B6.6040507@eccam.com> Hi, I am trying to return a new Python buffer that is a view to internals of my Message object. My understanding is that in such case, I should use return_internal_reference<> to make the return value hold reference to the Message class because of this bit of PyBuffer_FromMemory() docs: "The caller is responsible for ensuring that the memory buffer, passed in as ptr, is not deallocated while the returned buffer object exists." The problem is that whatever approach I could think of results into uncompilable code. (See the attached file.) I am using Boost 1.37.0. Is there any other way that I can do this? -- VH -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test.cpp.txt URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 2575 bytes Desc: S/MIME Cryptographic Signature URL: From zaexage at gmail.com Fri Feb 13 16:19:31 2009 From: zaexage at gmail.com (ZaeX) Date: Fri, 13 Feb 2009 23:19:31 +0800 Subject: [C++-sig] Call Policy for Singleton In-Reply-To: References: <3D33964996B3DC489449E5E4D7913750026BB088AD@NALASEXMB11.na.qualcomm.com> <2c5080560902121935y687004cat6b96dde6bca1f6be@mail.gmail.com> Message-ID: <2c5080560902130719n5f38991dndd4c38427172b427@mail.gmail.com> When the Singleton class is linked, the DLL will get the Singleton::_instance as an unique static variable. Well, In my last attempt, it appeared to be like that. On Fri, Feb 13, 2009 at 5:33 PM, John Reid wrote: > ZaeX wrote: > >> And in my opinion, you'd better be careful if you expect that the c++ >> code and python code are using the same singleton instance. >> Because there're two Singleton::_instance if you export the Singleton >> class to Python. one at c++ side, the other at python side. >> > I don't think this is true. What makes you think this? > > John. > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Time is mana, we must hurry -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.russell at fdmgroup.com Tue Feb 17 14:04:11 2009 From: david.russell at fdmgroup.com (David Russell) Date: Tue, 17 Feb 2009 13:04:11 -0000 Subject: [C++-sig] 2 Python C++ projects - Financial Industry Message-ID: Dear Python Group, I have attached two very interesting long term Python projects in the Frankfurt area, Financial industry. I am working exclusively on both requirements, interviews and contracts can be arranged very quickly. If they look interesting to you please feel free to contact me on the contact details below. Thank you for your help, Best Regards David Large Financial Institution - Frankfurt Senior Python C/C++ Developer (f/m) Tasks/Responsibilities Software developer for a complex electronic trading system. The software developer will work in the implementation team of the trading system; tasks include: - Requirements Analysis - Development of a Scripting framework based on Python - Specification - Implementation Target platform will be Linux. Qualifications/Required Skills (Mandatory) Rock Solid Python and C/C++ knowledge Integration of Python with C/C++ libraries Automated Testing Good overview and knowledge of open source software Experience of software development in large projects Good communications skills Ability to work in project teams A good command of English is a must. Additional Domain & Business Skills Knowledge of derivatives trading an advantage, in particular U.S. options. Additional Information: Frankfurt am Main, Germany Start ASAP for a minimum of 6 months Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com //////////////////////////////////////////////////////////////////////// /// Large Financial Institution - Frankfurt am Main Performance / High Availability Test Automation Engineer (f/m) Tasks/Responsibilities Developer of automated test procedures for a high-performance electronic trading system. The engineer will work in the Performance and Technical Test team of the project; tasks include: - Requirements Analysis - Development of distributed transaction feed procedures, mostly in Python - Implementation of automated result analysis - Design and implementation of test procedures for failover/recovery scenarios in a multi-tier environment - Supervision of regular runs of the automated performance test suite. Target platform will be Linux. Qualifications/Required Skills Python scripting Deep (>3 years) knowledge of Linux, with a focus in the areas - Performance monitoring and tuning - Messaging architectures Performance testing experience, for latency and throughput, incl. data aggregation and reporting Good communications skills Experience of software development in large projects Good overview and knowledge of open source software Ability to work in an international project team. A good command of English is a must. Additional Domain & Business Skills Knowledge of statistical data analysis methods would be an advantage. Experience in mechanisms of interfacing C/C++ and Python would also be advantageous. Frankfurt am Main, Germany Start ASAP to 31.12.09 with good extension prospects for 2010 Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com David Russell Account Manager FDM Group Beethoven Strasse 4, 60325 Frankfurt am Main Germany david.russell at fdmgroup.com Tel: + 49 (0) 69 756 0050 Cell: + 49 (0) 173 3592288 Fax: + 49 (0) 69 756 00555 www.fdmgroup.com www.fdmacademy.com BRIGHTON, LONDON, MANCHESTER, LUXEMBOURG, FRANKFURT, ZURICH & NEW YORK This message is from FDM Group Plc, and may contain information that is confidential or privileged. If you are not the intended recipient, please delete the message and any attachments and notify the sender. This email is not intended to create legally binding commitments on behalf of FDM Group Plc, nor do its contents reflect the corporate views or policies of FDM. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. FDM Group Plc is a private limited company registered in England (Reg. No. 2542980). ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 3278 bytes Desc: image001.jpg URL: From david.russell at fdmgroup.com Tue Feb 17 15:15:20 2009 From: david.russell at fdmgroup.com (David Russell) Date: Tue, 17 Feb 2009 14:15:20 -0000 Subject: [C++-sig] 2 very interesting projects - Python / Finance Message-ID: Dear Python Group, First of all sorry for the unsolicited email, I have attached two very interesting long term Python projects in the Frankfurt area, Financial industry. I am working exclusively with the client on both requirements, interviews and contracts can be arranged very quickly. You will be involved in a project to develop the next generation of financial trading systems, this will be the biggest, fastest trading system of its kind in the world and will be used on a global scale. Financial experience is not a must, they are looking more for technical skills here. If the projects look interesting to you please feel free to contact me on the contact details below. Thank you for your help, Best Regards David Large Financial Institution - Frankfurt Senior Python C/C++ Developer (f/m) Tasks/Responsibilities Software developer for a complex electronic trading system. The software developer will work in the implementation team of the trading system; tasks include: - Requirements Analysis - Development of a Scripting framework based on Python - Specification - Implementation Target platform will be Linux. Qualifications/Required Skills (Mandatory) Rock Solid Python and C/C++ knowledge Integration of Python with C/C++ libraries Automated Testing Good overview and knowledge of open source software Experience of software development in large projects Good communications skills Ability to work in project teams A good command of English is a must. Additional Domain & Business Skills Knowledge of derivatives trading an advantage, in particular U.S. options. Additional Information: Frankfurt am Main, Germany Start ASAP for a minimum of 6 months Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com //////////////////////////////////////////////////////////////////////// /// Large Financial Institution - Frankfurt am Main Performance / High Availability Test Automation Engineer (f/m) Tasks/Responsibilities Developer of automated test procedures for a high-performance electronic trading system. The engineer will work in the Performance and Technical Test team of the project; tasks include: - Requirements Analysis - Development of distributed transaction feed procedures, mostly in Python - Implementation of automated result analysis - Design and implementation of test procedures for failover/recovery scenarios in a multi-tier environment - Supervision of regular runs of the automated performance test suite. Target platform will be Linux. Qualifications/Required Skills Python scripting Deep (>3 years) knowledge of Linux, with a focus in the areas - Performance monitoring and tuning - Messaging architectures Performance testing experience, for latency and throughput, incl. data aggregation and reporting Good communications skills Experience of software development in large projects Good overview and knowledge of open source software Ability to work in an international project team. A good command of English is a must. Additional Domain & Business Skills Knowledge of statistical data analysis methods would be an advantage. Experience in mechanisms of interfacing C/C++ and Python would also be advantageous. Frankfurt am Main, Germany Start ASAP to 31.12.09 with good extension prospects for 2010 Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com David Russell Account Manager FDM Group Beethoven Strasse 4, 60325 Frankfurt am Main Germany david.russell at fdmgroup.com Tel: + 49 (0) 69 756 0050 Cell: + 49 (0) 173 3592288 Fax: + 49 (0) 69 756 00555 www.fdmgroup.com www.fdmacademy.com BRIGHTON, LONDON, MANCHESTER, LUXEMBOURG, FRANKFURT, ZURICH & NEW YORK This message is from FDM Group Plc, and may contain information that is confidential or privileged. If you are not the intended recipient, please delete the message and any attachments and notify the sender. This email is not intended to create legally binding commitments on behalf of FDM Group Plc, nor do its contents reflect the corporate views or policies of FDM. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. FDM Group Plc is a private limited company registered in England (Reg. No. 2542980). ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 3278 bytes Desc: image001.jpg URL: From NurEinDummy at gmx.de Thu Feb 19 15:05:43 2009 From: NurEinDummy at gmx.de (Martin Walser) Date: Thu, 19 Feb 2009 15:05:43 +0100 Subject: [C++-sig] Boost.Python app keeps crashing in debug Message-ID: Hi! :) I'm on the best way to become completely insane. I'm trying to set up VS2005 to run Boost Python in debug mode. Sorry for the long text... Problem summary: - applications crash in debug mode - dependencies to python25_d.dll AND python25.dll in boost_python-vc80-mt-gdy-1_35.dll - normal?? Only today I found out that I have to pass a special parameter to REALLY get a debug version. So I went into .\boost_1_35_0\libs\python\example\quickstart and called bjam with: bjam toolset=msvc --verbose-test test python-debugging=on Finally I got my boost_python-vc80-mt-gdy-1_35.dll & .lib files. Yet, simply defining BOOST_DEBUG_PYTHON & BOOST_ALL_NO_LIB in the header didn't work out. Had to put them in the preprocessor to make VC8 use the ...-gdy-... lib instead of the ...-gd-... lib. And to make him stop importing Python25.lib instead of python25_d.lib when building my .pyd C extension. Finally I found out that I have to add a _d to my extension filename as well so that python_d.exe finds the class I want to import. But now... my application crashes right after starting. Even the HelloWorld application from the tutorial crashes instantly: Unhandled exception at ... in python_d.exe And the debugger points to boost_1_35_0\libs\python\src\object\class.cpp's: [...] BOOST_PYTHON_DECL type_handle class_type() { if (class_type_object.tp_dict == 0) { class_type_object.ob_type = incref(class_metatype().get()); class_type_object.tp_base = &PyBaseObject_Type; =>!!! if (PyType_Ready(&class_type_object)) return type_handle(); // class_type_object.tp_setattro = class_setattro; } return type_handle(borrowed(&class_type_object)); } [...] Additionally, when putting boost_python-vc80-mt-gdy-1_35.dll in dependency walker I find dependencies to python25_d.dll AND python25.dll in it. I temporarily deleted python25.lib for testing ... and indeed, bjam demands python25.lib when building. Screenshot: http://i41.tinypic.com/2551g5j.jpg I hope someone with more experience got a clue... I'm lost. :( Thanks, Martin From roman.yakovenko at gmail.com Thu Feb 19 21:03:31 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 19 Feb 2009 22:03:31 +0200 Subject: [C++-sig] Boost.Python app keeps crashing in debug In-Reply-To: References: Message-ID: <7465b6170902191203j34e4a4cemc2aa5b1e6d81cd7d@mail.gmail.com> On Thu, Feb 19, 2009 at 4:05 PM, Martin Walser wrote: > Hi! :) > > > I'm on the best way to become completely insane. Did you try to build empty module and run it? This can help to see whether your environment works at all. Another valid option, is to compile your project in release, with debug information, without optimization. You will not be able to see Python code, but it should not be a problem to debug your own. > Finally I got my boost_python-vc80-mt-gdy-1_35.dll & .lib files. I guess, the problem is a mix of different C-runtimes. Python 2.5 is built using MSVC 7.1 ( VS 2003 ) compiler, while you use VS 2005. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From NurEinDummy at gmx.de Thu Feb 19 23:03:47 2009 From: NurEinDummy at gmx.de (Martin Walser) Date: Thu, 19 Feb 2009 23:03:47 +0100 Subject: [C++-sig] Boost.Python app keeps crashing in debug In-Reply-To: <7465b6170902191203j34e4a4cemc2aa5b1e6d81cd7d@mail.gmail.com> References: <7465b6170902191203j34e4a4cemc2aa5b1e6d81cd7d@mail.gmail.com> Message-ID: Hi Roman! Thanks for replying! :) Roman Yakovenko wrote: > Did you try to build empty module and run it? This can help to see > whether your environment works at all. Just tried... indeed, I can import an empty module. But the little HelloWorld App of the tutorial is already too much and I get the mentioned access violation in the shown position (last mail) right in the first line: BOOST_PYTHON_MODULE(RueCExt) { class_("World", init()) <= crash!! .def("greet", &World::greet) .def("set", &World::set) ; } > > Finally I got my boost_python-vc80-mt-gdy-1_35.dll & .lib files. > > I guess, the problem is a mix of different C-runtimes. > > Python 2.5 is built using MSVC 7.1 ( VS 2003 ) compiler, while you use VS > 2005. > > HTH You point to the python25.dll and the python25_d.dll dependencies in my boost_python-vc80-mt-gdy-1_35.dll? Hm. Well, I didn't build the Release version of Python 2.5. Took it from the installer. I only built the debug version. (As I had to) Already checked the python25_d.dll in dependency walker. This one seems to be okay. No python25.dll dependencies in that one. From dave at boostpro.com Fri Feb 20 02:18:05 2009 From: dave at boostpro.com (David Abrahams) Date: Thu, 19 Feb 2009 20:18:05 -0500 Subject: [C++-sig] Boost.Python app keeps crashing in debug In-Reply-To: (Martin Walser's message of "Thu, 19 Feb 2009 15:05:43 +0100") References: Message-ID: <87ab8hucs2.fsf@mcbain.luannocracy.com> on Thu Feb 19 2009, "Martin Walser" wrote: > Hi! :) > > > I'm on the best way to become completely insane. > > I'm trying to set up VS2005 to run Boost Python in debug mode. > > Sorry for the long text... > > > Problem summary: > > - applications crash in debug mode > - dependencies to python25_d.dll AND python25.dll in > boost_python-vc80-mt-gdy-1_35.dll - normal?? No, that's not normal. Or at least, it's not intended. You might try using BOOST_ALL_NO_LIB to suppress automatic linking altogether. > > > > > Only today I found out that I have to pass a special parameter to REALLY get > a debug version. > > So I went into .\boost_1_35_0\libs\python\example\quickstart > and called bjam with: > > bjam toolset=msvc --verbose-test test python-debugging=on > > Finally I got my boost_python-vc80-mt-gdy-1_35.dll & .lib files. > > Yet, simply defining BOOST_DEBUG_PYTHON & BOOST_ALL_NO_LIB in the header > didn't work out. What header? Why would you do that? python-debugging=on should define BOOST_DEBUG_PYTHON automatically. As for BOOST_ALL_NO_LIB, try adding define=BOOST_ALL_NO_LIB to your bjam command line. > Had to put them in the preprocessor to make VC8 use the ...-gdy-... lib > instead of the ...-gd-... lib. > And to make him stop importing Python25.lib instead of python25_d.lib when > building my .pyd C extension. > > > Finally I found out that I have to add a _d to my extension filename as well > so that python_d.exe finds the class I want to import. python-debugging=on should be handling that as well. > But now... my application crashes right after starting. > Even the HelloWorld application from the tutorial crashes instantly: > > Unhandled exception at ... in python_d.exe > > And the debugger points to boost_1_35_0\libs\python\src\object\class.cpp's: > > > [...] > > BOOST_PYTHON_DECL type_handle class_type() > { > if (class_type_object.tp_dict == 0) > { > class_type_object.ob_type = incref(class_metatype().get()); > class_type_object.tp_base = &PyBaseObject_Type; > =>!!! if (PyType_Ready(&class_type_object)) > return type_handle(); > // class_type_object.tp_setattro = class_setattro; > } > return type_handle(borrowed(&class_type_object)); > } Sounds like something is still linking PYTHON_DEBUGGING code with a non-debug python.dll (or vice-versa). > Additionally, when putting boost_python-vc80-mt-gdy-1_35.dll in dependency > walker I find dependencies to python25_d.dll AND python25.dll in it. > I temporarily deleted python25.lib for testing ... and indeed, bjam demands > python25.lib when building. > > Screenshot: http://i41.tinypic.com/2551g5j.jpg > > > I hope someone with more experience got a clue... > I'm lost. :( Did you follow the directions in http://boost.org/libs/python/doc/building.html ? This used to work. If someone broke it, I'm not sure how or who. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From NurEinDummy at gmx.de Fri Feb 20 09:08:53 2009 From: NurEinDummy at gmx.de (Martin Walser) Date: Fri, 20 Feb 2009 09:08:53 +0100 Subject: [C++-sig] Boost.Python app keeps crashing in debug In-Reply-To: <87ab8hucs2.fsf@mcbain.luannocracy.com> References: <87ab8hucs2.fsf@mcbain.luannocracy.com> Message-ID: <8C15D922939048D390E2EB818DE86DCA@cellardoor> Hi David! David Abrahams wrote: > No, that's not normal. Or at least, it's not intended. You might try > using BOOST_ALL_NO_LIB to suppress automatic linking altogether. Thought so that this is the cause for the trouble. Thx for the hint. Put the parameter in the bjam parameter (as you proposed later). (I still haven't found out how those Jam files work) See below... > What header? Why would you do that? Googling brought me to this approach... uhm... > Did you follow the directions in > http://boost.org/libs/python/doc/building.html > ? > > This used to work. If someone broke it, I'm not sure how or who. I think so... Tried adding in the BOOST_ALL_NO_LIB parameter as you proposed... I made sure that python25.lib won't be used by renaming it to _python25.lib Invoking C:\libs\boost\boost\boost_1_35_0\libs\python\example\quickstart>bjam toolset=msvc --verbose-test test python-debugging=on define=BOOST_ALL_NO_LIB result in: (see last line) C:\libs\boost\boost\boost_1_35_0\libs\python\example\quickstart>bjam toolset=msv c --verbose-test test python-debugging=on define=BOOST_ALL_NO_LIB warning: Graph library does not contain optional GraphML reader. note: to enable GraphML support, set EXPAT_INCLUDE and EXPAT_LIBPATH to the note: directories containing the Expat headers and libraries, respectively. warning: skipping optional Message Passing Interface (MPI) library. note: to enable MPI support, add "using mpi ;" to user-config.jam. note: to suppress this message, pass "--without-mpi" to bjam. note: otherwise, you can safely ignore this message. Building Boost.Regex with the optional Unicode/ICU support disabled. Please refer to the Boost.Regex documentation for more information (don't panic: this is a strictly optional feature). ...patience... ...found 1199 targets... ...updating 6 targets... msvc.link.dll bin\msvc-8.0\debug\python-debugging-on\threading-multi\extending.p yd LINK : fatal error LNK1181: cannot open input file 'python25.lib' From NurEinDummy at gmx.de Sun Feb 22 16:23:55 2009 From: NurEinDummy at gmx.de (Martin Walser) Date: Sun, 22 Feb 2009 16:23:55 +0100 Subject: [C++-sig] Boost.Python app keeps crashing in debug In-Reply-To: <8C15D922939048D390E2EB818DE86DCA@cellardoor> References: <87ab8hucs2.fsf@mcbain.luannocracy.com> <8C15D922939048D390E2EB818DE86DCA@cellardoor> Message-ID: <5EBFFA2CDFF44CC79BD337584F34FFD9@cellardoor> Okay... I found the problem. I used the opportunity to upgrade all my libs. Built Python 2.6.1 debug and release from sources... Downloaded Boost 1.38.0... And as I built Python myself this time, autodetection of python failed when building the Boost.Python libs. So I needed a Jam File. And there was the problem. You REALLY seem to need a Jam file to build the real debug versions. I put a "user-config.jam" in my home path (Windows: ECHO %HOMEDRIVE%%HOMEPATH%) and suddenly I got a working dll: #### user-config.jam ########### using python : 2.6 # Version : C:\\libs\\Python-2.6.1\\python.exe # Python Path : C:\\libs\\Python-2.6.1\\Include # include path(s) - they may be not really needed here : C:\\libs\\Python-2.6.1\\libs # lib path(s) - they may be not really needed here : off ; using python : 2.6 # Version : C:\\libs\\Python-2.6.1\\python_d.exe # Python Path : C:\\libs\\Python-2.6.1\\Include # include path(s) - they may be not really needed here : C:\\libs\\Python-2.6.1\\libs # lib path(s) - they may be not really needed here : on BOOST_ALL_NO_LIB=1 ; ################################ It seems to be absolutely necessary to define on in the jam file. Simply invoking... bjam toolset=msvc --verbose-test test python-debugging=on define=BOOST_ALL_NO_LIB ...won't do the trick. Files will be very well put into a \python-debugging-on subdir... but it seems that you will always end up with a boost_python-vc80-mt-gyd-1_38.dll (or whatever version) containing dependencies to python2x.dll AND python2x_d.dll. No crashes any more now. So: user-config.jam (see above) + bjam toolset=msvc --verbose-test test python-debugging=on define=BOOST_ALL_NO_LIB + BOOST_DEBUG_PYTHON and BOOST_ALL_NO_LIB added to preprocessor (*) = Working debug version under Windows. Yippieh! (*) else: ImportError: Module use of python26.dll conflicts with this version of Python. or LINK : fatal error LNK1104: cannot open file 'boost_python-vc80-mt-gd-1_38.lib' From murrayc at murrayc.com Mon Feb 23 12:39:19 2009 From: murrayc at murrayc.com (Murray Cumming) Date: Mon, 23 Feb 2009 12:39:19 +0100 Subject: [C++-sig] [] subscript notation with boost::python Message-ID: <1235389159.1982.16.camel@murrayc-x61> I'm trying to support this notation in python: something = record["somefieldname"] I had that working with the Python C API, by implementing the len and getitem functions, setting them in the PyTypeObject::tp_as_mapping struct field. I'm now trying to do this with boost::python, like so, because googling has suggested that this should work: boost::python::class_("Record") .def("__getitem__", &Glom::PyGlomRecord::getitem) .def("__len__", &Glom::PyGlomRecord::len) But when I try to use that in Python, I get this error: "Boost.Python.class' object is unsubscriptable" Is there something else that I need to do? -- Murray Cumming murrayc at murrayc.com www.murrayc.com www.openismus.com From beckmann.maik at googlemail.com Mon Feb 23 19:08:32 2009 From: beckmann.maik at googlemail.com (Maik Beckmann) Date: Mon, 23 Feb 2009 19:08:32 +0100 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <1235389159.1982.16.camel@murrayc-x61> References: <1235389159.1982.16.camel@murrayc-x61> Message-ID: <200902231908.33157.Beckmann.Maik@googlemail.com> Murray Cumming schrieb am Montag 23 Februar 2009 um 12:39: > I'm trying to support this notation in python: > something = record["somefieldname"] [snip] > I'm now trying to do this with boost::python, like so, because googling > has suggested that this should work: > > boost::python::class_("Record") > .def("__getitem__", &Glom::PyGlomRecord::getitem) > .def("__len__", &Glom::PyGlomRecord::len) > > But when I try to use that in Python, I get this error: > "Boost.Python.class' object is unsubscriptable" > > Is there something else that I need to do? I assume Glom::PyGlomRecord::getitem hasn't the right signature, which isn't checked at compile time {{{ struct PyGlomRecord { whatever_type getitem(boost::python::object subscriptionObj); }; }}} Here is an working example {{{ #include namespace bp = boost::python; struct Subscriptable { double val; double getitem(bp::object subscriptionObj) { return this->val; } double setitem(bp::object subscriptionObj, double val) { this->val = val; } }; BOOST_PYTHON_MODULE(mypy) { bp::class_("Subscriptable") .def("__getitem__", &Subscriptable::getitem) .def("__setitem__", &Subscriptable::setitem); } }}} HTH, -- Maik From troy at resophonic.com Mon Feb 23 19:15:45 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 23 Feb 2009 13:15:45 -0500 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <200902231908.33157.Beckmann.Maik@googlemail.com> References: <1235389159.1982.16.camel@murrayc-x61> <200902231908.33157.Beckmann.Maik@googlemail.com> Message-ID: <49A2E7D1.2090907@resophonic.com> Maik Beckmann wrote: > Murray Cumming schrieb am Montag 23 Februar 2009 um 12:39: >> I'm trying to support this notation in python: >> something = record["somefieldname"] > [snip] >> I'm now trying to do this with boost::python, like so, because googling >> has suggested that this should work: >> >> boost::python::class_("Record") >> .def("__getitem__", &Glom::PyGlomRecord::getitem) >> .def("__len__", &Glom::PyGlomRecord::len) >> >> But when I try to use that in Python, I get this error: >> "Boost.Python.class' object is unsubscriptable" You're trying to subscript a class, not an instance of a class. I bet you've got something like this: r = Record feh = r['thing'] which is wrong... you want: r = Record() feh = r['thing'] -t From beckmann.maik at googlemail.com Mon Feb 23 19:38:09 2009 From: beckmann.maik at googlemail.com (Maik Beckmann) Date: Mon, 23 Feb 2009 19:38:09 +0100 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <49A2E7D1.2090907@resophonic.com> References: <1235389159.1982.16.camel@murrayc-x61> <200902231908.33157.Beckmann.Maik@googlemail.com> <49A2E7D1.2090907@resophonic.com> Message-ID: <200902231938.09596.Beckmann.Maik@googlemail.com> troy d. straszheim schrieb am Montag 23 Februar 2009 um 19:15: > > Murray Cumming schrieb am Montag 23 Februar 2009 um 12:39: > >> I'm trying to support this notation in python: > >> something = record["somefieldname"] [snip] > You're trying to subscript a class, not an instance of a class. I bet > you've got something like this: > > r = Record > feh = r['thing'] > > which is wrong... you want: > > r = Record() > feh = r['thing'] > Considering what Murray done so far, I really doubt he makes this kind of a mistake. :P -- Maik From troy at resophonic.com Mon Feb 23 19:51:27 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 23 Feb 2009 13:51:27 -0500 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <200902231938.09596.Beckmann.Maik@googlemail.com> References: <1235389159.1982.16.camel@murrayc-x61> <200902231908.33157.Beckmann.Maik@googlemail.com> <49A2E7D1.2090907@resophonic.com> <200902231938.09596.Beckmann.Maik@googlemail.com> Message-ID: <49A2F02F.5010302@resophonic.com> Maik Beckmann wrote: > > Considering what Murray done so far, I really doubt he makes this kind of a > mistake. :P Experts can make this mistake too. I wasn't being condescending. The error message speaks for itself: "Boost.Python.class' object is unsubscriptable" If the problem was what you think it is, I believe the error message would be about c++-to-python conversions, bad function signatures or somesuch... -t From beckmann.maik at googlemail.com Mon Feb 23 20:04:16 2009 From: beckmann.maik at googlemail.com (Maik Beckmann) Date: Mon, 23 Feb 2009 20:04:16 +0100 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <49A2F02F.5010302@resophonic.com> References: <1235389159.1982.16.camel@murrayc-x61> <200902231938.09596.Beckmann.Maik@googlemail.com> <49A2F02F.5010302@resophonic.com> Message-ID: <200902232004.16652.Beckmann.Maik@googlemail.com> troy d. straszheim schrieb am Montag 23 Februar 2009 um 19:51: > Maik Beckmann wrote: > > Considering what Murray done so far, I really doubt he makes this kind of > > a mistake. :P > > Experts can make this mistake too. I wasn't being condescending. The > error message speaks for itself: > > "Boost.Python.class' object is unsubscriptable" > > If the problem was what you think it is, I believe the error message > would be about c++-to-python conversions, bad function signatures or > somesuch... > You are right, the error message looks like this {{{ Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in Subscriptable.__getitem__(Subscriptable, int) did not match C++ signature: __getitem__(Subscriptable {lvalue}) }}} and I am wrong :( Best Regards anyway :) -- Maik From murrayc at murrayc.com Tue Feb 24 15:48:22 2009 From: murrayc at murrayc.com (Murray Cumming) Date: Tue, 24 Feb 2009 15:48:22 +0100 Subject: [C++-sig] [] subscript notation with boost::python In-Reply-To: <200902231938.09596.Beckmann.Maik@googlemail.com> References: <1235389159.1982.16.camel@murrayc-x61> <200902231908.33157.Beckmann.Maik@googlemail.com> <49A2E7D1.2090907@resophonic.com> <200902231938.09596.Beckmann.Maik@googlemail.com> Message-ID: <1235486902.9548.81.camel@murrayc-x61> On Mon, 2009-02-23 at 19:38 +0100, Maik Beckmann wrote: > troy d. straszheim schrieb am Montag 23 Februar 2009 um 19:15: > > > Murray Cumming schrieb am Montag 23 Februar 2009 um 12:39: > > >> I'm trying to support this notation in python: > > >> something = record["somefieldname"] > > [snip] > > > You're trying to subscript a class, not an instance of a class. I bet > > you've got something like this: > > > > r = Record > > feh = r['thing'] > > > > which is wrong... you want: > > > > r = Record() > > feh = r['thing'] Ah, yes. Many thanks. > Considering what Murray done so far, I really doubt he makes this kind of a > mistake. :P Your confidence in me is nice, but unfounded. I don't do as much Python as C++ and I regularly forget the basics. -- Murray Cumming murrayc at murrayc.com www.murrayc.com www.openismus.com From boris.kazakov at gmail.com Thu Feb 26 09:03:23 2009 From: boris.kazakov at gmail.com (=?KOI8-R?B?4s/SydMg68HawcvP1w==?=) Date: Thu, 26 Feb 2009 11:03:23 +0300 Subject: [C++-sig] py++ boost::python::object Message-ID: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> Hi I't trying to parse relatevely simple file with py++ (pyplusplus_gui): here is header file: #pragma once #include typedef boost::python::object pyobject; pyobject gaussian_diffs(pyobject imarray, double sigma); It fails with plenty of errors: Error occured during code generation process! Error: Error occured while running GCC-XML: In file included from /usr/include/boost/type_traits/composite_traits.hpp:17, from /usr/include/boost/function/function_base.hpp:24, from /usr/include/boost/function/detail/prologue.hpp:17, from /usr/include/boost/function/function_template.hpp:13, from /usr/include/boost/function/detail/maybe_include.hpp:13, from /usr/include/boost/function/function0.hpp:11, from /usr/include/boost/python/errors.hpp:13, from /usr/include/boost/python/handle.hpp:11, from /usr/include/boost/python/args_fwd.hpp:10, from /usr/include/boost/python/args.hpp:10, from /usr/include/boost/python.hpp:11, from /home/borsh/workspace/pyitk/gaussian_diffs.hxx:2: and much more. Is this excpected behaviour or should I try to update something? I'm using gccxml-cvs 20081124 pygccxml 1.0.0 py++ 1.0.0 boost 1.37. Thanks, Boris. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Feb 26 09:10:37 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 26 Feb 2009 10:10:37 +0200 Subject: [C++-sig] py++ boost::python::object In-Reply-To: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> References: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> Message-ID: <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> 2009/2/26 ????? ??????? : > Hi I't trying to parse relatevely simple file with py++ (pyplusplus_gui): > > here is header file: > > #pragma once > #include > typedef boost::python::object pyobject; > pyobject gaussian_diffs(pyobject imarray, double sigma); > > It fails with plenty of errors: > > Error occured during code generation process! > Error: > Error occured while running GCC-XML: In file included from > /usr/include/boost/type_traits/composite_traits.hpp:17, > ???????????????? from /usr/include/boost/function/function_base.hpp:24, > ???????????????? from /usr/include/boost/function/detail/prologue.hpp:17, > ???????????????? from /usr/include/boost/function/function_template.hpp:13, > ???????????????? from > /usr/include/boost/function/detail/maybe_include.hpp:13, > ???????????????? from /usr/include/boost/function/function0.hpp:11, > ???????????????? from /usr/include/boost/python/errors.hpp:13, > ???????????????? from /usr/include/boost/python/handle.hpp:11, > ???????????????? from /usr/include/boost/python/args_fwd.hpp:10, > ???????????????? from /usr/include/boost/python/args.hpp:10, > ???????????????? from /usr/include/boost/python.hpp:11, > ???????????????? from /home/borsh/workspace/pyitk/gaussian_diffs.hxx:2: > and much more. > > Is this excpected behaviour or should I try to update something? I'm using > gccxml-cvs 20081124 > pygccxml 1.0.0 > py++ 1.0.0 > boost 1.37. There is nothing to update :-( GCCXML is another compiler and not all Boost code could be compiled under it. You have the following choices: * to create patch and submit it to Boost * to re-arrange your code, so the problematic file is not included. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From boris.kazakov at gmail.com Thu Feb 26 09:28:54 2009 From: boris.kazakov at gmail.com (=?KOI8-R?B?4s/SydMg68HawcvP1w==?=) Date: Thu, 26 Feb 2009 11:28:54 +0300 Subject: [C++-sig] py++ boost::python::object In-Reply-To: <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> References: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> Message-ID: <681c4a70902260028ic0830c9g2cdcadc91197a51c@mail.gmail.com> May be there is a way to instruct gccxml not to parse some include file? B. 2009/2/26 Roman Yakovenko > 2009/2/26 ????? ??????? : > > Hi I't trying to parse relatevely simple file with py++ (pyplusplus_gui): > > > > here is header file: > > > > #pragma once > > #include > > typedef boost::python::object pyobject; > > pyobject gaussian_diffs(pyobject imarray, double sigma); > > > > It fails with plenty of errors: > > > > Error occured during code generation process! > > Error: > > Error occured while running GCC-XML: In file included from > > /usr/include/boost/type_traits/composite_traits.hpp:17, > > from /usr/include/boost/function/function_base.hpp:24, > > from /usr/include/boost/function/detail/prologue.hpp:17, > > from > /usr/include/boost/function/function_template.hpp:13, > > from > > /usr/include/boost/function/detail/maybe_include.hpp:13, > > from /usr/include/boost/function/function0.hpp:11, > > from /usr/include/boost/python/errors.hpp:13, > > from /usr/include/boost/python/handle.hpp:11, > > from /usr/include/boost/python/args_fwd.hpp:10, > > from /usr/include/boost/python/args.hpp:10, > > from /usr/include/boost/python.hpp:11, > > from /home/borsh/workspace/pyitk/gaussian_diffs.hxx:2: > > and much more. > > > > Is this excpected behaviour or should I try to update something? I'm > using > > gccxml-cvs 20081124 > > pygccxml 1.0.0 > > py++ 1.0.0 > > boost 1.37. > > There is nothing to update :-( > > GCCXML is another compiler and not all Boost code could be compiled under > it. > You have the following choices: > * to create patch and submit it to Boost > * to re-arrange your code, so the problematic file is not included. > > 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 Feb 26 09:31:29 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 26 Feb 2009 10:31:29 +0200 Subject: [C++-sig] py++ boost::python::object In-Reply-To: <681c4a70902260028ic0830c9g2cdcadc91197a51c@mail.gmail.com> References: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> <681c4a70902260028ic0830c9g2cdcadc91197a51c@mail.gmail.com> Message-ID: <7465b6170902260031w246f85fxb7d6480946ef6ada@mail.gmail.com> 2009/2/26 ????? ??????? : > May be there is a way to instruct gccxml not to parse some include file? No, GCCXML is almost a complete C++ compiler, with "xml" instead of assembler as the backend. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Thu Feb 26 09:40:20 2009 From: pertti.kellomaki at tut.fi (=?KOI8-R?Q?Pertti_Kelloma=22ki?=) Date: Thu, 26 Feb 2009 10:40:20 +0200 Subject: [C++-sig] py++ boost::python::object In-Reply-To: <7465b6170902260031w246f85fxb7d6480946ef6ada@mail.gmail.com> References: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> <681c4a70902260028ic0830c9g2cdcadc91197a51c@mail.gmail.com> <7465b6170902260031w246f85fxb7d6480946ef6ada@mail.gmail.com> Message-ID: <49A65574.7060600@tut.fi> Roman Yakovenko kirjoitti: > 2009/2/26 ????? ??????? : >> May be there is a way to instruct gccxml not to parse some include file? > > No, GCCXML is almost a complete C++ compiler, with "xml" instead of > assembler as the backend. What might be possible is to provide an alternative include file where the problematic parts are replaced by some dummy code, and use ifdefs to select which file to include. Suppose an include file declares X, Y, and Z, and Z is the problematic part. The alternative file would then declare X and Y in the same way as previously, and provide a dummy declaration of Z, and the py++ code would omit Z from the generated bindings. This involves a lot of manual work and tracking of changes to the original include file, but I think it would work as a last resort. -- Pertti From boris.kazakov at gmail.com Thu Feb 26 10:33:06 2009 From: boris.kazakov at gmail.com (=?KOI8-R?B?4s/SydMg68HawcvP1w==?=) Date: Thu, 26 Feb 2009 12:33:06 +0300 Subject: [C++-sig] py++ boost::python::object In-Reply-To: <49A65574.7060600@tut.fi> References: <681c4a70902260003x27dd9076la87dad0cd95b956d@mail.gmail.com> <7465b6170902260010xe27290eu3379028bcc7ce0ae@mail.gmail.com> <681c4a70902260028ic0830c9g2cdcadc91197a51c@mail.gmail.com> <7465b6170902260031w246f85fxb7d6480946ef6ada@mail.gmail.com> <49A65574.7060600@tut.fi> Message-ID: <681c4a70902260133g5da37015w210a5831322841e2@mail.gmail.com> I was able to solve my problem with the following include file: #pragma once #ifndef __GCCXML__ #include typedef boost::python::object pyobject; #else class pyobject; #endif pyobject gaussian_diffs(pyobject imarray, double sigma); Thanks for your help =) Best regards, Boris. 26 ??????? 2009 ?. 11:40 ???????????? Pertti Kelloma"ki < pertti.kellomaki at tut.fi> ???????: > Roman Yakovenko kirjoitti: > >> 2009/2/26 ????? ??????? : >> >>> May be there is a way to instruct gccxml not to parse some include file? >>> >> >> No, GCCXML is almost a complete C++ compiler, with "xml" instead of >> assembler as the backend. >> > > What might be possible is to provide an alternative include file > where the problematic parts are replaced by some dummy code, > and use ifdefs to select which file to include. Suppose > an include file declares X, Y, and Z, and Z is the problematic > part. The alternative file would then declare X and Y in the > same way as previously, and provide a dummy declaration of Z, > and the py++ code would omit Z from the generated bindings. > > This involves a lot of manual work and tracking of changes to > the original include file, but I think it would work as a last > resort. > -- > Pertti > > _______________________________________________ > 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 murrayc at murrayc.com Fri Feb 27 10:33:10 2009 From: murrayc at murrayc.com (Murray Cumming) Date: Fri, 27 Feb 2009 10:33:10 +0100 Subject: [C++-sig] Getting object for PyObject (reference counting) Message-ID: <1235727190.21945.25.camel@murrayc-desktop> I can't find any definitive documentation that tells me how I should get a boost::python::object to wrap an existing PyObject*. I guess that there's a way to do it that uses an existing reference, and a way that takes an extra reference. -- murrayc at murrayc.com www.murrayc.com www.openismus.com From rwgk at yahoo.com Fri Feb 27 16:35:40 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 27 Feb 2009 07:35:40 -0800 (PST) Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <1235727190.21945.25.camel@murrayc-desktop> References: <1235727190.21945.25.camel@murrayc-desktop> Message-ID: <356172.18310.qm@web111407.mail.gq1.yahoo.com> The trick is to use boost::python::handle: http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/handle.html For example: object python_file((handle<>(borrowed(obj_ptr)))); ----- Original Message ---- From: Murray Cumming To: cplusplus-sig at python.org Sent: Friday, February 27, 2009 1:33:10 AM Subject: [C++-sig] Getting object for PyObject (reference counting) I can't find any definitive documentation that tells me how I should get a boost::python::object to wrap an existing PyObject*. I guess that there's a way to do it that uses an existing reference, and a way that takes an extra reference. -- murrayc at murrayc.com www.murrayc.com www.openismus.com _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From murrayc at murrayc.com Fri Feb 27 16:44:37 2009 From: murrayc at murrayc.com (Murray Cumming) Date: Fri, 27 Feb 2009 16:44:37 +0100 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <356172.18310.qm@web111407.mail.gq1.yahoo.com> References: <1235727190.21945.25.camel@murrayc-desktop> <356172.18310.qm@web111407.mail.gq1.yahoo.com> Message-ID: <1235749477.6354.1.camel@murrayc-x61> On Fri, 2009-02-27 at 07:35 -0800, Ralf W. Grosse-Kunstleve wrote: > The trick is to use boost::python::handle: > > http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/handle.html > > For example: > > object python_file((handle<>(borrowed(obj_ptr)))); Thanks, but like much of the documentation, I find that page very unclear. Is there anything that states more obviously what should be done in the two cases I mentioned. > I can't find any definitive documentation that tells me how I should get > a boost::python::object to wrap an existing PyObject*. I guess that > there's a way to do it that uses an existing reference, and a way that > takes an extra reference. > -- Murray Cumming murrayc at murrayc.com www.murrayc.com www.openismus.com From bruno.lalande at gmail.com Fri Feb 27 17:08:38 2009 From: bruno.lalande at gmail.com (Bruno Lalande) Date: Fri, 27 Feb 2009 17:08:38 +0100 Subject: [C++-sig] [c++-sig] Making a Python tuple from a Boost.Fusion sequence Message-ID: <9bea5ee0902270808t3c17744dn15c1d69c8b5fc0df@mail.gmail.com> Hello, The topic below was opened in the Boost development mailing list, where it's been pointed out to me that it fits better here. You can also read the thread archive: http://thread.gmane.org/gmane.comp.lib.boost.devel/186573 Regards Bruno ---------- Forwarded message ---------- Hello, I have written a little function that converts any Boost.Fusion sequence into a Python tuple (boost::python::tuple). If a sub-sequence is nested in the sequence, the result will also be a nested tuple (for instance, boost::make_tuple(0, std::make_pair(1, 2), 3) will give (0, (1, 2), 3) in Python). The source code is attached to this mail. The principle is that any sequence previously adapted to Boost.Fusion will become a tuple in Python. So, by including the right boost/fusion/adapted/xxx header, one can convert a pair, a tuple, a boost::array, and obviously any of the sequences provided by Boost.Fusion. For example: #include #include #include #include #include "make_tuple_from_fusion_sequence.hpp" using namespace boost::python; tuple from_sequence() { return make_tuple_from_fusion( boost::fusion::make_vector( 1, std::make_pair("first", "second"), 2, boost::make_tuple('a', 'b', 'c'), 3 ) ); } BOOST_PYTHON_MODULE(mymodule) { def("from_sequence", &from_sequence); } In Python we get: >>> import mymodule >>> mymodule.from_sequence() (1, ('first', 'second'), 2, ('a', 'b', 'c'), 3) Is there any interest in adding this function into Boost.Python? If yes, I can write the doc and tests, clean the source and maybe improve the implementation (for example, I feel that I could avoid the use of m_iteration with a better use of Boost.Fusion...). Regards Bruno -------------- next part -------------- A non-text attachment was scrubbed... Name: make_tuple_from_fusion.hpp Type: text/x-c++hdr Size: 1356 bytes Desc: not available URL: From amohr at pixar.com Fri Feb 27 17:34:50 2009 From: amohr at pixar.com (Alex Mohr) Date: Fri, 27 Feb 2009 08:34:50 -0800 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <1235727190.21945.25.camel@murrayc-desktop> References: <1235727190.21945.25.camel@murrayc-desktop> Message-ID: <49A8162A.6060505@pixar.com> Murray Cumming wrote: > I can't find any definitive documentation that tells me how I should get > a boost::python::object to wrap an existing PyObject*. I guess that > there's a way to do it that uses an existing reference, and a way that > takes an extra reference. You can construct a boost::python::object with a boost::python::handle<>. boost::python::handle<> is sort of a "smart" PyObject *. It manages the python object reference count automatically. When you create a boost::python::handle<> you can tell it whether to bump the reference count or not. Given a PyObject *p: // Use with a "new reference" -- *doesn't* bump ref count. handle<>(p); // Use with a "borrowed reference" -- *does* bump ref count. handle<>(borrowed(p)); Alex From AFoglia at princeton.com Fri Feb 27 18:19:12 2009 From: AFoglia at princeton.com (AFoglia at princeton.com) Date: Fri, 27 Feb 2009 12:19:12 -0500 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <1235749477.6354.1.camel@murrayc-x61> References: <1235727190.21945.25.camel@murrayc-desktop> <356172.18310.qm@web111407.mail.gq1.yahoo.com> <1235749477.6354.1.camel@murrayc-x61> Message-ID: <49A82090.7060905@princeton.com> Murray Cumming wrote: > On Fri, 2009-02-27 at 07:35 -0800, Ralf W. Grosse-Kunstleve wrote: >> The trick is to use boost::python::handle: >> >> http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/handle.html >> >> For example: >> >> object python_file((handle<>(borrowed(obj_ptr)))); > > Thanks, but like much of the documentation, I find that page very > unclear. Is there anything that states more obviously what should be > done in the two cases I mentioned. The best documentation I could find was this page on the Python wiki, taken from a email to this list: http://wiki.python.org/moin/boost.python/handle The only error is that references to "null_ok" should be "allow_null". At least that's the way I got it to work. -- Anthony Foglia Princeton Consultants (609) 987-8787 x233 From murrayc at murrayc.com Fri Feb 27 22:25:22 2009 From: murrayc at murrayc.com (Murray Cumming) Date: Fri, 27 Feb 2009 22:25:22 +0100 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <49A8162A.6060505@pixar.com> References: <1235727190.21945.25.camel@murrayc-desktop> <49A8162A.6060505@pixar.com> Message-ID: <1235769922.8034.21.camel@murrayc-x61> On Fri, 2009-02-27 at 08:34 -0800, Alex Mohr wrote: > Murray Cumming wrote: > > I can't find any definitive documentation that tells me how I should get > > a boost::python::object to wrap an existing PyObject*. I guess that > > there's a way to do it that uses an existing reference, and a way that > > takes an extra reference. > > You can construct a boost::python::object with a > boost::python::handle<>. boost::python::handle<> is sort of a "smart" > PyObject *. It manages the python object reference count automatically. Oh, I assumed that boost::python::object did this already. If not, is there any reason not to use boost::python::handle everywhere instead of a boost::python::object? One of my main reasons for using boost::python instead of the C API is to avoid worrying so much about the reference counting. For instance, I don't want to explicitly increment the ref when returning a PyObject, or remember whether I should take a ref when given a PyObject from various functions. > When you create a boost::python::handle<> you can tell it whether to > bump the reference count or not. Given a PyObject *p: > > // Use with a "new reference" -- *doesn't* bump ref count. > handle<>(p); > > // Use with a "borrowed reference" -- *does* bump ref count. > handle<>(borrowed(p)); > > Alex > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -- Murray Cumming murrayc at murrayc.com www.murrayc.com www.openismus.com From AFoglia at princeton.com Fri Feb 27 22:44:46 2009 From: AFoglia at princeton.com (AFoglia at princeton.com) Date: Fri, 27 Feb 2009 16:44:46 -0500 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <1235769922.8034.21.camel@murrayc-x61> References: <1235727190.21945.25.camel@murrayc-desktop> <49A8162A.6060505@pixar.com> <1235769922.8034.21.camel@murrayc-x61> Message-ID: <49A85ECE.2080700@princeton.com> Murray Cumming wrote: > On Fri, 2009-02-27 at 08:34 -0800, Alex Mohr wrote: >> Murray Cumming wrote: >>> I can't find any definitive documentation that tells me how I should get >>> a boost::python::object to wrap an existing PyObject*. I guess that >>> there's a way to do it that uses an existing reference, and a way that >>> takes an extra reference. >> You can construct a boost::python::object with a >> boost::python::handle<>. boost::python::handle<> is sort of a "smart" >> PyObject *. It manages the python object reference count automatically. > > Oh, I assumed that boost::python::object did this already. > > If not, is there any reason not to use > boost::python::handle everywhere instead of a > boost::python::object? > > One of my main reasons for using boost::python instead of the C API is > to avoid worrying so much about the reference counting. For instance, I > don't want to explicitly increment the ref when returning a PyObject, or > remember whether I should take a ref when given a PyObject from various > functions. I believe, but could be wrong, that boost::python::objects must be made from handles. If not that's not a requirement, it's at least a strong suggestion. That way, the underlying handle in the object will handle the reference counting for you. The way I understand it, the handle takes care of the reference counting, and the object is a wrapper to make it easier to interact with the pointer to PyObject in a more OO-like manner. Also, I'm not sure you can make a boost::python::handle. The instance the handle points to should be laid out like a PyObject. (Remember, the underlying Python code is C-based, so pointer layout is required to start the same to approximate inheritance.) I don't think boost::python::object can make that guarantee. -- Anthony Foglia Princeton Consultants (609) 987-8787 x233 From amohr at pixar.com Sat Feb 28 00:18:06 2009 From: amohr at pixar.com (Alex Mohr) Date: Fri, 27 Feb 2009 15:18:06 -0800 Subject: [C++-sig] Getting object for PyObject (reference counting) In-Reply-To: <1235769922.8034.21.camel@murrayc-x61> References: <1235727190.21945.25.camel@murrayc-desktop> <49A8162A.6060505@pixar.com> <1235769922.8034.21.camel@murrayc-x61> Message-ID: <49A874AE.6010306@pixar.com> > Oh, I assumed that boost::python::object did this already. It does. Think of bp::handle<> as a low-level, bare-bones, smart PyObject*. Think of bp::object as that, *plus* all the fancy c++ API that maps to python API (like obj.attr("foo"), []-operator, ()-operator, etc). I believe bp::object holds a handle<> internally. > If not, is there any reason not to use > boost::python::handle everywhere instead of a > boost::python::object? Don't do that. You can't do that. It won't compile. Use bp::object everywhere unless you're convinced you have a good reason to do otherwise. If you have a PyObject *p and you want a bp::object, construct it via: object(handle<>(p)) // when p's a new reference object(handle<>(borrowed(p))) // when p's a borrowed reference > One of my main reasons for using boost::python instead of the C API is > to avoid worrying so much about the reference counting. For instance, I > don't want to explicitly increment the ref when returning a PyObject, or > remember whether I should take a ref when given a PyObject from various > functions. Yup. Just use bp::object everywhere. I recommend you read through the reference manual: http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/object.html http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/handle.html Also look at the tutorials and examples and tests in the boost.python distribution. Alex