From markenglish at freenet.co.uk Fri Aug 3 00:12:08 2007 From: markenglish at freenet.co.uk (Mark English) Date: Thu, 2 Aug 2007 22:12:08 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?Runtime_issues_with_return=5Finternal=5Frefer?= =?utf-8?q?enceand=09to=5Fpython=5Fconverter?= References: Message-ID: English, Mark rbccm.com> writes: > In short I've registered a "to_python_converter" for a C++ type, and it's not being found with > "return_internal_reference" although it is used with "return_by_value". A potential solution. Essentially I ended up cut'n'pasting return_internal_reference and it's surrounding code to call a customised "MakeHolder" model which looks up the C++ type in the converter registry. Since the type ends up in a with_custodian_and_ward_postcall it needs to support weakref, so in the example PyInner got a bit more convoluted too. http://docs.python.org/ext/weakref-support.html I'm sure there are better ways to do this, and I am concerned that my lack of boost python understanding and mpl inexperience may lead to bugs especially with PyObject ref counting, so better approaches or flaws in this approach gratefully received. Regards, Mark ========== Code ========== ---- custom_return_internal_reference.hpp ---- // File: custom_return_internal_reference.hpp // Description: /// custom_call_policies::return_registered_internal_reference /// Customised version of return_internal_reference which allows delegation /// to some externally defined "MakeHolder" class /// (defined as "A class whose static execute() creates an instance_holder") #pragma once # include # include # include # include # include # include namespace custom_call_policies { namespace detail { using namespace boost::python; /// Default "MakeHolder" model based on /// "boost/python/to_python_indirect.hpp - detail::make_reference_holder" and /// "boost/python/to_python_value.hpp - detail::registry_to_python_value" struct make_registered_reference_holder { /// Turns a pointer to a C++ type "T" into a "PyObject *" using registered /// type lookup. This means C++ type must be manually registered for /// conversion /// @param T Parameterised C++ type to convert /// @param p Pointer to instance of C++ type to convert /// @return Python object built from registered conversion code template static PyObject* execute(T* p) { typedef objects::pointer_holder holder_t; T* q = const_cast(p); // Jump into conversion lookup mechanism typedef T argument_type; typedef converter::registered r; # if BOOST_WORKAROUND(__GNUC__, < 3) // suppresses an ICE, somehow (void)r::converters; # endif return converter::registered::converters.to_python(q); } }; /// reference_existing_object replacement allowing use of different /// "MakeHolder" model. /// @param MakeReferenceHolderSubstitute - Class modelling "MakeHolder" /// Defaults to /// make_registered_reference_holder template struct subst_reference_existing_object : boost::python::reference_existing_object { /// Implicitly relies on "detail" namespace implementation, and falls back /// on that implementation if it changes template struct apply { private: typedef typename reference_existing_object::apply::type basetype_; public: typedef typename boost::mpl::if_< boost::is_same > ,boost::python::to_python_indirect ,basetype_ >::type type; }; }; /// return_internal_reference replacement allowing use of different /// "ResultConverterGenerator" model rather than "reference_existing_object" /// Falls back on Boost implementation if it ceases to use /// "reference_existing_object" /// @param ReferenceExistingObjectSubstitute - "ResultConverterGenerator" /// model replacement for /// "reference_existing_object" /// @param owner_arg - See boost documentation /// @param BasePolicy_ - See boost documentation template struct subst_return_internal_reference : boost::python::return_internal_reference { private: typedef boost::python::return_internal_reference basetype_; public: typedef typename boost::mpl::if_< boost::is_same ,ReferenceExistingObjectSubstitute ,typename basetype_::result_converter>::type result_converter; }; } // Ends namespace detail // Typedefs for programmer convenience typedef detail::subst_reference_existing_object< detail::make_registered_reference_holder > reference_registered_existing_object; // In place of a typedef template /// Call policy to create internal references to registered types template struct return_registered_internal_reference : detail::subst_return_internal_reference {}; } // Ends namespace custom_call_policies ---- test.cpp ---- #include #include // PyMemberDef #include "custom_return_internal_reference.hpp" class Inner {}; struct PyInner { PyObject_HEAD PyObject *ppyobjWeakrefList; Inner *pinner; }; // New/Dealloc added to support weakref PyObject * PyInnerNew (PyTypeObject *ptypeNew, PyObject *ppyobjArgs, PyObject *ppyobjKwds) { PyObject *ppyobjNew = PyType_GenericNew(ptypeNew, ppyobjArgs, ppyobjKwds); if (ppyobjNew != NULL && !PyErr_Occurred()) // If created object ok { PyInner *ppyinnerNew = reinterpret_cast(ppyobjNew); ppyinnerNew->ppyobjWeakrefList = NULL; } return ppyobjNew; } static void PyInnerDealloc(PyInner *ppyinnerDealloc) { // Allocate temporaries if needed, but do not begin destruction just yet if (ppyinnerDealloc->ppyobjWeakrefList != NULL) { PyObject_ClearWeakRefs(reinterpret_cast(ppyinnerDealloc)); } ppyinnerDealloc->ob_type->tp_free(ppyinnerDealloc); } static PyMemberDef l_amemberPyInner[] = { {"__weakref__", T_OBJECT, offsetof(PyInner, ppyobjWeakrefList), 0}, {0} }; PyTypeObject typeInner = { PyObject_HEAD_INIT(NULL) 0 // ob_size (?!?!?) ,"Inner" // tp_name ,sizeof(PyInner) // tp_basicsize ,0 // tp_itemsize ,(destructor)&PyInnerDealloc // tp_dealloc ,0 // tp_print ,0 // tp_getattr ,0 // tp_setattr ,0 // tp_compare ,0 // tp_repr ,0 // tp_as_number ,0 // tp_as_sequence ,0 // tp_as_mapping ,0 // tp_hash ,0 // tp_call ,0 // tp_str ,0 // tp_getattro ,0 // tp_setattro ,0 // tp_as_buffer ,Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE // tp_flags |Py_TPFLAGS_HAVE_WEAKREFS ,0 // tp_doc ,0 // tp_traverse ,0 // tp_clear ,0 // tp_richcompare ,offsetof(PyInner, ppyobjWeakrefList) // tp_weaklistoffset ,0 // tp_iter ,0 // tp_iternext ,0 // tp_methods ,l_amemberPyInner // tp_members ,0 // tp_getset ,0 // tp_base ,0 // tp_dict ,0 // tp_descr_get ,0 // tp_descr_set ,0 // tp_dictoffset ,0 // tp_init ,0 // tp_alloc ,PyInnerNew // tp_new }; struct convert_inner_to_python { static PyObject * convert(Inner const &rinner) { PyInner *ppyinnerReturn = PyObject_New(PyInner, &typeInner); ppyinnerReturn->ppyobjWeakrefList = NULL; ppyinnerReturn->pinner = const_cast(&rinner); // This looks decidedly like a bad idea PyObject *ppyobjReturn = reinterpret_cast (ppyinnerReturn); return ppyobjReturn; } }; struct Outer { Inner m_inner; }; namespace ConversionExample { void export() { using namespace boost::python; using custom_call_policies::return_registered_internal_reference; typeInner.ob_type = &PyType_Type; PyType_Ready(&typeInner); to_python_converter(); // convert_python_to_inner(); class_("Outer") // This works but object lifetime is incorrect .add_property("innerval", make_getter(&Outer::m_inner, return_value_policy()), make_setter(&Outer::m_inner, return_value_policy())) //This now also works .add_property("inner", make_getter(&Outer::m_inner, return_registered_internal_reference<>()), make_setter(&Outer::m_inner, return_registered_internal_reference<>())) ; } } // End of namespace ConversionExample namespace { BOOST_PYTHON_MODULE("testboostpython") { ConversionExample::export(); } } // Ends anonymous namespace ---- test.py ---- import unittest class TestCaseBoostPython(unittest.TestCase): def test_OuterInner(self): import testboostpython import gc def do_test_value(): outerTest = testboostpython.Outer() inner = outerTest.innerval del outerTest return inner return inner def do_test(): outerTest = testboostpython.Outer() inner = outerTest.inner del outerTest return inner #This works but wrong lifetime innerTestVal = do_test_value() gc.collect() self.assertEqual(type(innerTestVal).__name__, 'Inner') #This also works innerTest = do_test() gc.collect() self.assertEqual(type(innerTest).__name__, 'Inner') if __name__ == "__main__": from test.test_support import run_unittest run_unittest(TestCaseBoostPython) ========== Output ========== test_OuterInner (__main__.TestCaseBoostPython) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.015s OK From hgroven at emgs.com Fri Aug 3 12:54:58 2007 From: hgroven at emgs.com (=?UTF-8?Q?H=C3=A5kon_Groven?=) Date: Fri, 3 Aug 2007 12:54:58 +0200 (CEST) Subject: [C++-sig] String param from py to c++ by reference? Message-ID: <1371140939.2851186138498137.OPEN-XCHANGE.WebMail.tomcat@ox> I have a c++ function that is defined like this: bool set_version(std::string &version); //pass by reference The wrapper def: .def("set_version", &survey_result::set_version) Python code: b = result.set_version('jalla') This does not work, and I get the following error: Caught Boost.Python.ArgumentError: Python argument types in ???survey_result.set_version(survey_result, str) did not match C++ signature: ???set_version(survey_result {lvalue}, std::string {lvalue}) This works fine if I change the c++ code: bool set_version(std::string version); //pass by value Is it possible to make this work by reference instead of by value? Haakon From duranlef at iro.umontreal.ca Fri Aug 3 17:26:27 2007 From: duranlef at iro.umontreal.ca (=?ISO-8859-1?Q?Fran=E7ois_Duranleau?=) Date: Fri, 3 Aug 2007 11:26:27 -0400 (EDT) Subject: [C++-sig] String param from py to c++ by reference? In-Reply-To: <1371140939.2851186138498137.OPEN-XCHANGE.WebMail.tomcat@ox> References: <1371140939.2851186138498137.OPEN-XCHANGE.WebMail.tomcat@ox> Message-ID: On Fri, 3 Aug 2007, H?kon Groven wrote: > I have a c++ function that is defined like this: > bool set_version(std::string &version); //pass by reference > > The wrapper def: > .def("set_version", &survey_result::set_version) > > Python code: > b = result.set_version('jalla') > > This does not work, and I get the following error: > > Caught Boost.Python.ArgumentError: Python argument types in > ???survey_result.set_version(survey_result, str) > did not match C++ signature: > ???set_version(survey_result {lvalue}, std::string {lvalue}) > > This works fine if I change the c++ code: > bool set_version(std::string version); //pass by value > > Is it possible to make this work by reference instead of by value? Your set_version function, is it intended to set something in the object or to modify the parameter? According to your usage example in Python, it seems like the former case. Then all you need to do is to pass the string by const reference, e.g. bool set_version( const std::string& version ) ; If you can't modify that source code, then wrap it: bool wrap_set_version( const survey_result& sr , const std::string& v ) { return sr.set_version( const_cast< std::string& >( v ) ) ; } and then: //... .def( "set_version" , & wrap_set_version ) //... In the latter case, you will need a different interface on the Python side, because AFAIK, Python's strings are not mutable. You could do: boost::python::tuple wrap_set_version( survey_result& sr , const std::string& v ) { // it could be done more efficiently by taking a boost::python::str // argument instead of const std::string& and then extracting the // string in `version' below std::string version = v ; bool b = sr.set_version( version ) ; return boost::python::make_tuple( version , b ) ; } and then use .def(...) as above, and in Python: v , b = result.set_version( 'jalla' ) Now v contains your modified string and b the boolean value. -- Fran??ois Duranleau LIGUM, Universit?? de Montr??al From markenglish at freenet.co.uk Sat Aug 4 16:34:18 2007 From: markenglish at freenet.co.uk (Mark English) Date: Sat, 4 Aug 2007 14:34:18 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?Runtime_issues_with_return=5Finternal=5Frefer?= =?utf-8?q?enceand=09to=5Fpython=5Fconverter?= References: Message-ID: English, Mark rbccm.com> writes: > In short I've registered a "to_python_converter" for a C++ type, and it's > not being found with "return_internal_reference" although > it is used with "return_by_value". (Reposted because I messed up the subject header before) A potential solution. Essentially I ended up cut'n'pasting return_internal_reference and it's surrounding code to call a customised "MakeHolder" model which looks up the C++ type in the converter registry. Since the type ends up in a with_custodian_and_ward_postcall it needs to support weakref, so in the example PyInner got a bit more convoluted too. http://docs.python.org/ext/weakref-support.html I'm sure there are better ways to do this, and I am concerned that my lack of boost python understanding and mpl inexperience may lead to bugs especially with PyObject ref counting, so better approaches or flaws in this approach gratefully received. Regards, Mark ========== Code ========== ---- custom_return_internal_reference.hpp ---- // File: custom_return_internal_reference.hpp // Description: /// custom_call_policies::return_registered_internal_reference /// Customised version of return_internal_reference which allows delegation /// to some externally defined "MakeHolder" class /// (defined as "A class whose static execute() creates an instance_holder") #pragma once # include # include # include # include # include # include namespace custom_call_policies { namespace detail { using namespace boost::python; /// Default "MakeHolder" model based on /// "boost/python/to_python_indirect.hpp - detail::make_reference_holder" and /// "boost/python/to_python_value.hpp - detail::registry_to_python_value" struct make_registered_reference_holder { /// Turns a pointer to a C++ type "T" into a "PyObject *" using registered /// type lookup. This means C++ type must be manually registered for /// conversion /// @param T Parameterised C++ type to convert /// @param p Pointer to instance of C++ type to convert /// @return Python object built from registered conversion code template static PyObject* execute(T* p) { typedef objects::pointer_holder holder_t; T* q = const_cast(p); // Jump into conversion lookup mechanism typedef T argument_type; typedef converter::registered r; # if BOOST_WORKAROUND(__GNUC__, < 3) // suppresses an ICE, somehow (void)r::converters; # endif return converter::registered::converters.to_python(q); } }; /// reference_existing_object replacement allowing use of different /// "MakeHolder" model. /// @param MakeReferenceHolderSubstitute - Class modelling "MakeHolder" /// Defaults to /// make_registered_reference_holder template struct subst_reference_existing_object : boost::python::reference_existing_object { /// Implicitly relies on "detail" namespace implementation, and falls back /// on that implementation if it changes template struct apply { private: typedef typename reference_existing_object::apply::type basetype_; public: typedef typename boost::mpl::if_< boost::is_same > ,boost::python::to_python_indirect ,basetype_ >::type type; }; }; /// return_internal_reference replacement allowing use of different /// "ResultConverterGenerator" model rather than "reference_existing_object" /// Falls back on Boost implementation if it ceases to use /// "reference_existing_object" /// @param ReferenceExistingObjectSubstitute - "ResultConverterGenerator" /// model replacement for /// "reference_existing_object" /// @param owner_arg - See boost documentation /// @param BasePolicy_ - See boost documentation template struct subst_return_internal_reference : boost::python::return_internal_reference { private: typedef boost::python::return_internal_reference basetype_; public: typedef typename boost::mpl::if_< boost::is_same ,ReferenceExistingObjectSubstitute ,typename basetype_::result_converter>::type result_converter; }; } // Ends namespace detail // Typedefs for programmer convenience typedef detail::subst_reference_existing_object< detail::make_registered_reference_holder > reference_registered_existing_object; // In place of a typedef template /// Call policy to create internal references to registered types template struct return_registered_internal_reference : detail::subst_return_internal_reference {}; } // Ends namespace custom_call_policies ---- test.cpp ---- #include #include // PyMemberDef #include "custom_return_internal_reference.hpp" class Inner {}; struct PyInner { PyObject_HEAD PyObject *ppyobjWeakrefList; Inner *pinner; }; // New/Dealloc added to support weakref PyObject * PyInnerNew (PyTypeObject *ptypeNew, PyObject *ppyobjArgs, PyObject *ppyobjKwds) { PyObject *ppyobjNew = PyType_GenericNew(ptypeNew, ppyobjArgs, ppyobjKwds); if (ppyobjNew != NULL && !PyErr_Occurred()) // If created object ok { PyInner *ppyinnerNew = reinterpret_cast(ppyobjNew); ppyinnerNew->ppyobjWeakrefList = NULL; } return ppyobjNew; } static void PyInnerDealloc(PyInner *ppyinnerDealloc) { // Allocate temporaries if needed, but do not begin destruction just yet if (ppyinnerDealloc->ppyobjWeakrefList != NULL) { PyObject_ClearWeakRefs(reinterpret_cast(ppyinnerDealloc)); } ppyinnerDealloc->ob_type->tp_free(ppyinnerDealloc); } static PyMemberDef l_amemberPyInner[] = { {"__weakref__", T_OBJECT, offsetof(PyInner, ppyobjWeakrefList), 0}, {0} }; PyTypeObject typeInner = { PyObject_HEAD_INIT(NULL) 0 // ob_size (?!?!?) ,"Inner" // tp_name ,sizeof(PyInner) // tp_basicsize ,0 // tp_itemsize ,(destructor)&PyInnerDealloc // tp_dealloc ,0 // tp_print ,0 // tp_getattr ,0 // tp_setattr ,0 // tp_compare ,0 // tp_repr ,0 // tp_as_number ,0 // tp_as_sequence ,0 // tp_as_mapping ,0 // tp_hash ,0 // tp_call ,0 // tp_str ,0 // tp_getattro ,0 // tp_setattro ,0 // tp_as_buffer ,Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE // tp_flags |Py_TPFLAGS_HAVE_WEAKREFS ,0 // tp_doc ,0 // tp_traverse ,0 // tp_clear ,0 // tp_richcompare ,offsetof(PyInner, ppyobjWeakrefList) // tp_weaklistoffset ,0 // tp_iter ,0 // tp_iternext ,0 // tp_methods ,l_amemberPyInner // tp_members ,0 // tp_getset ,0 // tp_base ,0 // tp_dict ,0 // tp_descr_get ,0 // tp_descr_set ,0 // tp_dictoffset ,0 // tp_init ,0 // tp_alloc ,PyInnerNew // tp_new }; struct convert_inner_to_python { static PyObject * convert(Inner const &rinner) { PyInner *ppyinnerReturn = PyObject_New(PyInner, &typeInner); ppyinnerReturn->ppyobjWeakrefList = NULL; ppyinnerReturn->pinner = const_cast(&rinner); // This looks decidedly like a bad idea PyObject *ppyobjReturn = reinterpret_cast (ppyinnerReturn); return ppyobjReturn; } }; struct Outer { Inner m_inner; }; namespace ConversionExample { void export() { using namespace boost::python; using custom_call_policies::return_registered_internal_reference; typeInner.ob_type = &PyType_Type; PyType_Ready(&typeInner); to_python_converter(); // convert_python_to_inner(); class_("Outer") // This works but object lifetime is incorrect .add_property("innerval", make_getter(&Outer::m_inner, return_value_policy()), make_setter(&Outer::m_inner, return_value_policy())) //This now also works .add_property("inner", make_getter(&Outer::m_inner, return_registered_internal_reference<>()), make_setter(&Outer::m_inner, return_registered_internal_reference<>())) ; } } // End of namespace ConversionExample namespace { BOOST_PYTHON_MODULE("testboostpython") { ConversionExample::export(); } } // Ends anonymous namespace ---- test.py ---- import unittest class TestCaseBoostPython(unittest.TestCase): def test_OuterInner(self): import testboostpython import gc def do_test_value(): outerTest = testboostpython.Outer() inner = outerTest.innerval del outerTest return inner return inner def do_test(): outerTest = testboostpython.Outer() inner = outerTest.inner del outerTest return inner #This works but wrong lifetime innerTestVal = do_test_value() gc.collect() self.assertEqual(type(innerTestVal).__name__, 'Inner') #This also works innerTest = do_test() gc.collect() self.assertEqual(type(innerTest).__name__, 'Inner') if __name__ == "__main__": from test.test_support import run_unittest run_unittest(TestCaseBoostPython) ========== Output ========== test_OuterInner (__main__.TestCaseBoostPython) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.015s OK From karl.kobata at syncira.com Mon Aug 6 05:50:36 2007 From: karl.kobata at syncira.com (Karl Kobata) Date: Sun, 5 Aug 2007 20:50:36 -0700 Subject: [C++-sig] python extension - std::set Message-ID: <5p5klh$18u5s1@rrcs-agw-01.hrndva.rr.com> I have created an extension to my python 2.5 installation on winxp and rel3 linux. I have used C++ set and deque constructs in the interface and am looking for help python construct required to access the extension. 1) My interface has the following: class TestApp { public: // constructors, destructors TestApp (); ~ TestApp (); // data members // ====> data members manipulated by C++/Python programs <==== std::string sString1; std::set stSetString1; std::set stSetString2; std::deque dqDequeString; } 2) have used swig 1.3 to create a wrapper 3) this extension was compiled with distutils In python, how will I access and modify the std::set and std::deque? Does anyone have examples to do this? Please help. k -------------- next part -------------- An HTML attachment was scrubbed... URL: From t_spens at yahoo.com Mon Aug 6 17:59:11 2007 From: t_spens at yahoo.com (Tim Spens) Date: Mon, 6 Aug 2007 08:59:11 -0700 (PDT) Subject: [C++-sig] Pointer ownership In-Reply-To: <5p5klh$18u5s1@rrcs-agw-01.hrndva.rr.com> Message-ID: <448687.75657.qm@web43139.mail.sp1.yahoo.com> I have a constructor that takes a pointer as an argument. When I create an instance of this class and the object looses scope in python I get an error glibc detected python: free(): invalid pointer: The class wrapper looks like this class_, boost::noncopyable>("z_command", init()); Do I need a call policy for this pointer? I've looked at the boost python call policies and found nothing for constructors with pointers as arguments. ____________________________________________________________________________________ Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz From t_spens at yahoo.com Mon Aug 6 21:46:24 2007 From: t_spens at yahoo.com (Tim Spens) Date: Mon, 6 Aug 2007 12:46:24 -0700 (PDT) Subject: [C++-sig] Pointer ownership In-Reply-To: <448687.75657.qm@web43139.mail.sp1.yahoo.com> Message-ID: <58287.57753.qm@web43145.mail.sp1.yahoo.com> >From searching around it looks like I need to use return_value_policy() so that I can manage the deletion of the new object. How can I add this to my class z_command? --- Tim Spens wrote: > I have a constructor that takes a pointer as an > argument. When I create an instance of this class > and > the object looses scope in python I get an error > glibc detected python: free(): invalid pointer: > > The class wrapper looks like this > class_, > boost::noncopyable>("z_command", init const &, p *>()); > > Do I need a call policy for this pointer? I've > looked > at the boost python call policies and found nothing > for constructors with pointers as arguments. ____________________________________________________________________________________ Got a little couch potato? Check out fun summer activities for kids. http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz From roman.yakovenko at gmail.com Tue Aug 7 07:30:25 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 7 Aug 2007 08:30:25 +0300 Subject: [C++-sig] Pointer ownership In-Reply-To: <448687.75657.qm@web43139.mail.sp1.yahoo.com> References: <5p5klh$18u5s1@rrcs-agw-01.hrndva.rr.com> <448687.75657.qm@web43139.mail.sp1.yahoo.com> Message-ID: <7465b6170708062230v28db21a9y9bd33411600650d9@mail.gmail.com> On 8/6/07, Tim Spens wrote: > I have a constructor that takes a pointer as an > argument. When I create an instance of this class and > the object looses scope in python I get an error > glibc detected python: free(): invalid pointer: > > The class wrapper looks like this > class_, > boost::noncopyable>("z_command", init const &, p *>()); > > Do I need a call policy for this pointer? I've looked > at the boost python call policies and found nothing > for constructors with pointers as arguments. The description of the problem is not clear. You should be a little bit descriptive about p* lifetime and management. http://boost.org/libs/python/doc/v2/init.html - here you will find how to specify call policies for "init". -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pvicenti at gmail.com Tue Aug 7 21:01:28 2007 From: pvicenti at gmail.com (Paul Vicenti) Date: Tue, 7 Aug 2007 16:01:28 -0300 Subject: [C++-sig] About PyImport_Import Message-ID: <531d9eef0708071201w7b05944an8abc6d61e1d46f04@mail.gmail.com> Hello, I have a code that uses PyImport_Import. When the import module (in this example 'testa') doesn't exist it returns a NULL but when I call Py_Finalize it shows a exception: Exception exceptions.ImportError: 'No module named testa' in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection Anybody knows how to prevent this error in Py_Finalize? Thanks on advance, Paul From achille.talon at gmail.com Wed Aug 8 15:26:03 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 8 Aug 2007 06:26:03 -0700 (PDT) Subject: [C++-sig] Call policies choice In-Reply-To: <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> <11921781.post@talk.nabble.com> <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> Message-ID: <12053112.post@talk.nabble.com> Thanks that helped (and the sleeping part too I guess) ! I've got another issue I'm wrapping a "list" class class NeoList: public NeoCollection{ public: NeoList(); ~NeoList(); virtual void set(unsigned short index,NeoMsgType* pType); virtual NeoMsgType* get(unsigned short index) const; ... }; class NeoText:public NeoMsgType{ public: explicit NeoText(const string& str); virtual string toString()const{return m_string;} ... }; class NeoMsgType { public: explicit NeoMsgType(uint8_t idType = 0xff); virtual ~NeoMsgType(){} virtual string toString() const = 0; }; But there seems to be a problem with the get function because when I test the generated .pyd with python and this example import neolib n = neolib; message1 = n.NeoText('first message'); message2 = n.NeoText('2ndmessage'); l = n.NeoList(); l.set(1,message1); l.set(2,message2); recup1 = l.get(1); recup2 = l.get(2); print "type of recup1 : %s " % recup1; I get that recup1 is a none type. I suppose this is a call policy issue as well. I tried with internal_reference and others but I get the same result. With copy_const_reference the lib doesn't compile. Any clue ? Thank you -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Call-policies-choice-tf4191655.html#a12053112 Sent from the Python - c++-sig mailing list archive at Nabble.com. From oanjao at yahoo.com Wed Aug 8 17:41:26 2007 From: oanjao at yahoo.com (Craig Finch) Date: Wed, 8 Aug 2007 08:41:26 -0700 (PDT) Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: Message-ID: <506057.14293.qm@web30311.mail.mud.yahoo.com> Chris, Your suggestion worked for me. I constructed a simple but complete example of how to handle objects of different types when bringing a Boost.python list into C++ for processing. An explanation and the necessary files are posted on my software development blog at http://www.shocksolution.com/blog/2007/08/08/mixing-objects-of-different-types-in-a-boostpython-list/ for anyone else who wants to know how to do this. Thanks guys! Craig --- Christopher Woods wrote: > Hi Craig, > > I've played with your example and I've got it to work by changing > your > extract and extract into extract > and extract. In the first case (extract) > you were extracting the object in the list into a *copy*, which was > of > type BaseClass, so the "Useless base class" function of that copy was > then called. By extracting into a pointer (via extract) > you aren't performing a copy, and you obtain a polymorphic pointer to > the original object. > > As for the typeid part of the example, I don't know why typeid gets > it > wrong when you use extract. I had to change this to > extract and then do a typeid of the dereference of > the resulting polymorphic pointer. > > Here is the modified version of 'setList' that worked on my box > (linux, gcc 3.4, python 2.3); > > ============================== > void Importer::setList (list l) { > BaseClass *o; > int len = extract(l.attr("__len__")()); > > for (int i=0; i std::cout << typeid( *(extract (l[i])) > ).name() << std::endl; > > o = extract (l[i]); > o->evaluate(); > } > } > ============================== > > This gave output; > > ============================== > 1A > Index is 3 > 1B > Value is 5.234 > ============================== > > I hope this helps, > > Christopher > -------------- Please reply to cfinch at ieee.org ____________________________________________________________________________________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 From roman.yakovenko at gmail.com Wed Aug 8 19:50:33 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 8 Aug 2007 20:50:33 +0300 Subject: [C++-sig] Call policies choice In-Reply-To: <12053112.post@talk.nabble.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> <11921781.post@talk.nabble.com> <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> <12053112.post@talk.nabble.com> Message-ID: <7465b6170708081050m6391e0e5mb8ff88caaaf7020e@mail.gmail.com> On 8/8/07, Coockie_jr wrote: > > Thanks that helped (and the sleeping part too I guess) ! > I've got another issue > > I'm wrapping a "list" class > > > class NeoList: public NeoCollection{ > public: > NeoList(); > ~NeoList(); > virtual void set(unsigned short index,NeoMsgType* pType); > virtual NeoMsgType* get(unsigned short index) const; > ... > }; > > > class NeoText:public NeoMsgType{ > public: > explicit NeoText(const string& str); > virtual string toString()const{return m_string;} > ... > }; > > > class NeoMsgType > { > public: > explicit NeoMsgType(uint8_t idType = 0xff); > virtual ~NeoMsgType(){} > virtual string toString() const = 0; > > }; > > But there seems to be a problem with the get function because when I test > the generated .pyd with python and this example > > import neolib > n = neolib; > message1 = n.NeoText('first message'); > message2 = n.NeoText('2ndmessage'); > l = n.NeoList(); > l.set(1,message1); > l.set(2,message2); > recup1 = l.get(1); > recup2 = l.get(2); > print "type of recup1 : %s " % recup1; > > > I get that recup1 is a none type. > I suppose this is a call policy issue as well. > > I tried with internal_reference and others but I get the same result. > With copy_const_reference the lib doesn't compile. > > Any clue ? *Small* and *complete* example is needed :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mark.english at rbccm.com Thu Aug 9 10:34:06 2007 From: mark.english at rbccm.com (=?utf-8?b?RW5nbGlzaCw=?= Mark) Date: Thu, 9 Aug 2007 08:34:06 +0000 (UTC) Subject: [C++-sig] Call policies choice References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> <11921781.post@talk.nabble.com> <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> <12053112.post@talk.nabble.com> <7465b6170708081050m6391e0e5mb8ff88caaaf7020e@mail.gmail.com> Message-ID: Roman Yakovenko gmail.com> writes: > > On 8/8/07, Coockie_jr gmail.com> wrote: > > I tried with internal_reference and others but I get the same result. > > With copy_const_reference the lib doesn't compile. > > > > Any clue ? > > *Small* and *complete* example is needed > Sorry if this is off topic, but is there was a posting guide for this list (like how small is small and are attachments accepted) ? From achille.talon at gmail.com Thu Aug 9 15:13:17 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 9 Aug 2007 06:13:17 -0700 (PDT) Subject: [C++-sig] Call policies choice In-Reply-To: <7465b6170708081050m6391e0e5mb8ff88caaaf7020e@mail.gmail.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> <11921781.post@talk.nabble.com> <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> <12053112.post@talk.nabble.com> <7465b6170708081050m6391e0e5mb8ff88caaaf7020e@mail.gmail.com> Message-ID: <12072198.post@talk.nabble.com> Hmm sorry about that. I edited my post but forgot to warn you. However I've got another question ... My last python example works (I get the correct output and all) but I get an Assertion fail error when I execute it when it reaches the set function. What is this all about ? Thank you! Roman Yakovenko wrote: > > > *Small* and *complete* example is needed :-) > > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Call-policies-choice-tf4191655.html#a12072198 Sent from the Python - c++-sig mailing list archive at Nabble.com. From zovirl at zovirl.com Mon Aug 13 01:17:42 2007 From: zovirl at zovirl.com (Mark Ivey) Date: Sun, 12 Aug 2007 16:17:42 -0700 Subject: [C++-sig] What determines whether a returned pointer is downcast or not? Message-ID: What determines whether a returned pointer is downcast or not? The simple example below prints . But if I make Base::f virtual and recompile, then it prints . Why doesn't it work for the non-virtual case? I'm actually trying to wrap some 3rd-party code so I'm stuck with the non-virtual case. What other options do I have for doing the downcast? The typical C++ way to use the 3rd-party code is to dynamic_cast the pointer coming back from the factory, but I haven't been able to figure what the python equivalent is. I suppose I could make a large collection of wrapper functions to do the dynamic_cast and return the correct pointer type, but I'm hoping for a more elegant solution. Does one exist? Python: import test x = test.factory(1) print type(x) C++: class Base { void f(){}; }; class Type1: public Base { void x(){} }; class Type2: public Base { void y(){} }; Base *factory(int type) { if (type == 1) return new Type1(); else return new Type2(); } BOOST_PYTHON_MODULE(test) { class_("Base"); class_ >("Type1"); class_ >("Type2"); def("factory", factory, return_value_policy()); } From ckkart at hoc.net Mon Aug 13 10:05:19 2007 From: ckkart at hoc.net (Christian K.) Date: Mon, 13 Aug 2007 17:05:19 +0900 Subject: [C++-sig] import does not return with custom extension Message-ID: Hi, I built an extension with mingw on Windows XP using scons according to a recipe found on this list (SConstruct attached). I use a boost_python.dll which is part of some other project (openalea) as I have not yet understood how to build it myself. I renamed the resulting .dll into .pyd and when I try to import it from a python shell, started from a cygwin shell, the prompt does not come back. If I start python from the DOS prompt, and import the extension, I get an error about 'missing cygwin1.dll/mingw.dll'. After copying those two to the current dir, the import hangs as before. Does anybody have an idea what is going on here? How could I debug that issue? Thanks, Christian -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: SConstruct URL: From hgroven at emgs.com Mon Aug 13 11:14:27 2007 From: hgroven at emgs.com (=?UTF-8?Q?H=C3=A5kon_Groven?=) Date: Mon, 13 Aug 2007 11:14:27 +0200 (CEST) Subject: [C++-sig] manage_new_object on vector items? Message-ID: <2057235865.6031186996467215.OPEN-XCHANGE.WebMail.tomcat@ox> Hi! I have the following two functions: .h: std::vector get_available_ch_groups() const; channel_group* get_channel_group(channel_group_type gr_type) const; wrapper-code: .def("get_available_ch_groups", &survey_result::get_available_ch_groups .def("get_channel_group", &survey_result::get_channel_group, return_value_policy()) The items returned in the vector are not garbage collected, while the object pointed to by get_channel_group's return is. Is it possible to use something like "manage_new_object" on the items in the vector returned from get_available_ch_groups? If this is not possible, is shared_ptr the way to go? I'd be glad if anyone could help! Haakon. From Lawrence.Spector at CanfieldSci.com Wed Aug 15 16:48:34 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 15 Aug 2007 10:48:34 -0400 Subject: [C++-sig] [Boost.Python] Importing twice causes error in MSVS with Boost.Python extension? Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2850@Pan.domain-01> In one case I use "PyImport_ImportModule". Later on, I do "PyRun_String". Either way, same deal. I import the module and the first time it succeeds. The second time it blows up deep down in boost. Ultimately an an assert fails, which can be traced down to boost::python::convert::registry::insert failing on an assertion of slot == 0 (line 160). Before I go any further, has anyone else seen this problem before? It doesn't happen on every module, just one particular one. I even went to the trouble and removing everything it was exposing, with the same effect. One other thing I'm doing is I have an __init__.py file in the directory, which does a "from import *", as described in the tutorial. One other interesting thing of note, is if it do it from IDLE and import this module twice, it seems to work. Any ideas? If not, I'll try to come up with a test case to reproduce. Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From zzhao at laika.com Wed Aug 15 18:52:32 2007 From: zzhao at laika.com (ZiZi Zhao) Date: Wed, 15 Aug 2007 09:52:32 -0700 (PDT) Subject: [C++-sig] import fails for "undefined symbol" Message-ID: <8142733.464461187196752856.JavaMail.root@zimbra01.laika.com> In my embedded boost.python plugin, if I put "import math\nout_foo=math.sin(1.0)" in a string for PyRun_String "code", I got the following: error: executing python code Traceback (most recent call last): File "", line 1, in ? ImportError: /local/prod/python/python_2.4.4/lib/python2.4/lib-dynload/math.so: undefined symbol: PyExc_OverflowError warning: python code did not set output: out_foo The first time, I used static libraries of libpythonxx.a and libboost_python-gcc.a to make my plugin, I got the error message. After changing to use shared libraries, I still got the same error. Googled some info about this error, but they didn't help too much. Hope to get a solution from this group. Thanks in advance, ZiZi LAIKA _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lawrence.Spector at CanfieldSci.com Wed Aug 15 21:57:15 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 15 Aug 2007 15:57:15 -0400 Subject: [C++-sig] [Boost.Python] Importing twice causes error in MSVS with Boost.Python extension? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2850@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB2850@Pan.domain-01> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2872@Pan.domain-01> Actually, I figured this one out after some more testing. Apparently I had set my paths in such a way that this worked. I did the import in two different ways, and effectively, it tried to do both, then had an error because of it. As an example, I was doing the equivalent of this: import Package1.Module1 and then later: import Module1 where Module1 is the same package, but specified differently. I did this in the same script file. That caused a double-import and thus the error. -Lawrence From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Wednesday, August 15, 2007 10:49 AM To: Development of Python/C++ integration Subject: [C++-sig] [Boost.Python] Importing twice causes error in MSVS with Boost.Python extension? In one case I use "PyImport_ImportModule". Later on, I do "PyRun_String". Either way, same deal. I import the module and the first time it succeeds. The second time it blows up deep down in boost. Ultimately an an assert fails, which can be traced down to boost::python::convert::registry::insert failing on an assertion of slot == 0 (line 160). Before I go any further, has anyone else seen this problem before? It doesn't happen on every module, just one particular one. I even went to the trouble and removing everything it was exposing, with the same effect. One other thing I'm doing is I have an __init__.py file in the directory, which does a "from import *", as described in the tutorial. One other interesting thing of note, is if it do it from IDLE and import this module twice, it seems to work. Any ideas? If not, I'll try to come up with a test case to reproduce. Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.jaroszynski at gmail.com Fri Aug 17 15:52:02 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Fri, 17 Aug 2007 15:52:02 +0200 Subject: [C++-sig] bases + wrapper bug? Message-ID: <200708171552.03449.p.jaroszynski@gmail.com> Hello, I might have hit a bug in Boost.Python, but you tell me, simple c++ code - [1] and even simpler Python code - [2]. Running bug.py segfaults for me without the line marked in bug.cc. I think it's because DerivedWrapper uses bases, but Base is exposed through BaseWrapper. [1] - http://dev.gentooexperimental.org/~peper/boost/bug.cc [2] - http://dev.gentooexperimental.org/~peper/boost/bug.py -- Best Regards, Piotr Jaroszy?ski From hans_meine at gmx.net Fri Aug 17 22:50:16 2007 From: hans_meine at gmx.net (Hans Meine) Date: Fri, 17 Aug 2007 22:50:16 +0200 Subject: [C++-sig] (How) can I "attach" code/objects to a standard Python object? Message-ID: <200708172250.25172.hans_meine@gmx.net> Hi! Ultimately, I want to be able to create numpy arrays wrapping existing (2D imagaee) data. I succeeded so far by exposing a function using PyBuffer_FromReadWriteMemory with BPL and then use numpy.frombuffer from Python. The problem I have is that PyBuffer_FromReadWriteMemory returns a PyBuffer object which points to my data, and I have to make sure that my own object (which internally holds a boost::shared_ptr to a Memory object) does not free the memory. (How) can I tie the lifetime of my Image object (or the internal, already shared_ptr'ed Memory object) to the PyBuffer? Is there another, better way to proceed? Thanks in advance, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From roman.yakovenko at gmail.com Sat Aug 18 19:54:55 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 18 Aug 2007 20:54:55 +0300 Subject: [C++-sig] bases + wrapper bug? In-Reply-To: <200708171552.03449.p.jaroszynski@gmail.com> References: <200708171552.03449.p.jaroszynski@gmail.com> Message-ID: <7465b6170708181054h1aec8072r90fd6549f68f3085@mail.gmail.com> On 8/17/07, Piotr Jaroszy?ski wrote: > Hello, > > I might have hit a bug in Boost.Python, but you tell me, simple c++ code - [1] > and even simpler Python code - [2]. Running bug.py segfaults for me without > the line marked in bug.cc. I think it's because DerivedWrapper uses > bases, but Base is exposed through BaseWrapper. > > [1] - http://dev.gentooexperimental.org/~peper/boost/bug.cc > [2] - http://dev.gentooexperimental.org/~peper/boost/bug.py I will try to explain, how I understand this, but of course I could be wrong. bp::class_ ( "Base", bp::init<>() ) .def("f", bp::pure_virtual(&Base::f)) ; bp::class_, boost::noncopyable> ( "Derived", bp::init<>() ) // Without this line the Python code segfaults //.def("f", bp::pure_virtual(&Base::f)) ; At run time, behind PyObject you have holds DerivedWrapper class instance. During the first registration of "f", type of "this" pointer is BaseWrapper. I could be wrong, but the library doesn't scan for registered [pure] virtual functions and re-registers them again with the right "this" pointer. So in your case: you call "f" with "this" pointer type "DerivedWrapper", than library does casting for you from DerivedWrapper to BaseWrapper and than it calls "f". Obviously this cannot work, becase BaseWrapper and DerivedWrapper are not base and derived classes. You can test my explanation by changing DerivedWrapper implementation: struct DerivedWrapper : Derived, BaseWrapper, bp::wrapper { virtual int f() const { if (bp::override f = get_override("f")) f(); else return 1; } }; I think that in this case you don't have to register "f" twice. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Mark.English at rbccm.com Mon Aug 20 10:25:56 2007 From: Mark.English at rbccm.com (English, Mark) Date: Mon, 20 Aug 2007 09:25:56 +0100 Subject: [C++-sig] (How) can I "attach" code/objects to a standard Pythonobject? Message-ID: > -----Original Message----- > Hans Meine > Sent: 17 August 2007 21:50 > Subject: [C++-sig] (How) can I "attach" code/objects to a standard > Pythonobject? > > Hi! > > Ultimately, I want to be able to create numpy arrays wrapping > existing (2D > imagaee) data. I succeeded so far by exposing a function using > PyBuffer_FromReadWriteMemory with BPL and then use > numpy.frombuffer from > Python. > > The problem I have is that PyBuffer_FromReadWriteMemory > returns a PyBuffer > object which points to my data, and I have to make sure that > my own object > (which internally holds a boost::shared_ptr to a Memory > object) does not free > the memory. (How) can I tie the lifetime of my Image object (or the > internal, already shared_ptr'ed Memory object) to the > PyBuffer? Is there > another, better way to proceed? Hi Hans, I managed to achieve something like this but I'm not sure I went about it the right way so your mileage may vary. I should mention the alternatives first since the subsequent explanation is pretty dull and no-one should have to suffer that sort of indignity without alternatives. 1) I can't see a way to associate a given PyObject with a specific conversion mechanism or return policy in Boost without adding your own PyObject style type. Others may. Listen to them. 2) Rather than going through the hoops mentioned below, you might be able simply to register a converter although lifetime management will presumably still be an issue. This example conversion from SWIG might be helpful: http://wiki.python.org/moin/boost%2epython/HowTo#head-2edd46bb30e64d9d76acd7ed480f2318e87bbb5f Let me know if you get anywhere with this. 3) There are postings about numpy and Boost. Some of them might help. E.g.: http://www.nabble.com/-C%2B%2B-sig--more-examples-of-automatic-type-conversion-tf3680314.html#a10348060 In summary here's what I tried: Write a PyObject-style class implementing the PyBufferProcs, and then provide a converter for Boost to handle C++ -> Python, and a new return policy to handle lifetimes... First off I wrote my own PyTypeObject using the PyBufferProcs exposed by using the raw Python C-API http://www.python.org/doc/2.2/api/buffer-structs.html (i.e. not using Boost), and added a corresponding C-style struct as the PyObject. E.g. MyPyBuffer. This contains a pointer to an actual C++ implementation of a buffer class. E.g. MyCplusplusBuffer Having done that I tried to write a new return policy, for which code and an example is posted here: http://article.gmane.org/gmane.comp.python.c%2B%2B/11767 So far this seems successful. If you do write your own PyTypeObject implementing PyBufferProcs which is used by MyPyBuffer, and MyPyBuffer wraps MyCplusplusBuffer pointers, then you can expose classes in Boost Python (e.g. BufferOwner) which contain functions returning MyCplusplusBuffer pointers. The conversion from MyCplusplusBuffer to MyPyBuffer can be exposed via a converter, and the function (e.g. "getBuffer()") can be exposed using the return policy mentioned above (the converter code is pretty standard and is contained in the example code too). The new return policy is based on return_internal_reference which uses a custodian and ward style approach, and should provide the ownership properties you require. In other words in the example code, assuming you've followed this approach, "Outer" becomes your boost class, "Inner" becomes the PyObject style object which implements "PyBufferProcs", and the rest of the code should work as is. Sorta. One (of many) caveat: At the moment I expose raw pointers, so I haven't tried this with any kind of smart pointer since I don't require that right now. It would be an obvious improvement in the future if it took advantage of smart pointers, presumably in the converter. Hope that helps, Mark ______________________________________________________________________ This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential. Unauthorised use or disclosure is prohibited.If you receive This e-mail in error, please advise immediately and delete the original message. This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message. From meine at informatik.uni-hamburg.de Mon Aug 20 11:53:58 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 20 Aug 2007 11:53:58 +0200 Subject: [C++-sig] (How) can I "attach" code/objects to a standard Pythonobject? In-Reply-To: References: Message-ID: <200708201153.58401.meine@informatik.uni-hamburg.de> Hi! Am Montag, 20. August 2007 10:25:56 schrieb English, Mark: > 1) I can't see > a way to associate a given PyObject with a specific conversion mechanism or > return policy in Boost without adding your own PyObject style type. Others > may. Listen to them. Yes, that sounds as if it might be impossible indeed. > 2) Rather than going through the hoops mentioned below, you might be able > simply to register a converter although lifetime management will presumably > still be an issue. Yes, I could register a converter (done that before), but I do not see how that would help here. > In summary here's what I tried: Write a PyObject-style class implementing > the PyBufferProcs, and then provide a converter for Boost to handle C++ -> > Python, and a new return policy to handle lifetimes... OK, I see that this solves my problem. I even think that registering a converter from an arbitrary C++ class (which I would like to avoid introducing) to the standard PyBuffer type would help, too, as long as I can use the return policies. For a brief moment, I thought it was worth trying return policies with my existing function, which looks like this: PyObject * rawImageMemory(PythonImage const & image) { return PyBuffer_FromReadWriteMemory( image.data(), image.width() * image.height() * image.bands() * sizeof(GrayValue)); } [...] class_("PythonImage") .def("_rawBuffer", &rawImageMemory) [...] ..but adding return_internal_reference<>() results in (not surprisingly): .../boost/python/object/pointer_holder.hpp:176: error: 'boost::python::objects::pointer_holder::pointer_holder(PyObject*) [with Pointer = _object*, Value = _object]' cannot be overloaded .../boost/python/object/pointer_holder.hpp:111: error: with 'boost::python::objects::pointer_holder::pointer_holder(Pointer) [with Pointer = _object*, Value = _object]' I think my question arises from my poor understanding of how the return_value_policies actually work. Yes, I do know that they provide some sort of hook mechanism which allows to execute code before and after the function call, but how is this related to the need to run code after the object returned by the object is destroyed? It cannot be done with a destructor, since other functions may return objects of the same type with a different policy. So I assume this has to do with the difference between the exported and the "held type" (which I have only a poor understanding of)? AFAICS, this should also be able to work with PyObject*s, no? -- Ciao, / / /--/ / / ANS From dave at boost-consulting.com Mon Aug 20 16:33:06 2007 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 20 Aug 2007 10:33:06 -0400 Subject: [C++-sig] [Boost.Python] Importing twice causes error in MSVS with Boost.Python extension? References: <8F737B3BFD630A4380BD0357481D4B0316DB2850@Pan.domain-01> Message-ID: <87tzqu6ztp.fsf@grogan.peloton> on Wed Aug 15 2007, Lawrence Spector wrote: > In one case I use ?PyImport_ImportModule?. Later on, I do ?PyRun_String?. Either way, same > deal. I import the module and the first time it succeeds. The second time it blows up deep > down in boost. Ultimately an an assert fails, which can be traced down to > boost::python::convert::registry::insert failing on an assertion of > slot == 0 (line 160). That means the same type converters are being registered twice. Python shouldn't let you actually load the same module twice (i.e. run its init function) unless you do Py_Finalize(), which isn't supported by Boost.Python. If you're not actually loading the same module twice then you've got some code registering type converters in a function that is called multiple times. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From dave at boost-consulting.com Mon Aug 20 16:34:54 2007 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 20 Aug 2007 10:34:54 -0400 Subject: [C++-sig] import fails for "undefined symbol" References: <8142733.464461187196752856.JavaMail.root@zimbra01.laika.com> Message-ID: <87odh26zqp.fsf@grogan.peloton> on Wed Aug 15 2007, ZiZi Zhao wrote: > In my embedded boost.python plugin, if I put "import math\nout_foo=math.sin(1.0)" in a string > for PyRun_String "code", I got the following: > > error: executing python code > Traceback (most recent call last): > File "", line 1, in ? > ImportError: /local/prod/python/python_2.4.4/lib/python2.4/lib-dynload/math.so: undefined > symbol: PyExc_OverflowError > warning: python code did not set output: out_foo > > The first time, I used static libraries of libpythonxx.a and libboost_python-gcc.a to make my > plugin, I got the error message. After changing to use shared libraries, I still got the same > error. Googled some info about this error, but they d idn't help too much. Hope to get a > solution from this group. You need to link your application against libpython24.a -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From Mark.English at rbccm.com Mon Aug 20 17:36:31 2007 From: Mark.English at rbccm.com (English, Mark) Date: Mon, 20 Aug 2007 16:36:31 +0100 Subject: [C++-sig] [Boost.Python] Importing twice causes error in MSVSwith Boost.Python extension? Message-ID: > -----Original Message----- > Behalf Of David Abrahams > Sent: 20 August 2007 15:33 > Subject: Re: [C++-sig] [Boost.Python] Importing twice causes error in > MSVSwith Boost.Python extension? > > on Wed Aug 15 2007, Lawrence Spector > wrote: > > > In one case I use ?PyImport_ImportModule?. Later on, I do > ?PyRun_String?. Either way, same > > deal. I import the module and the first time it succeeds. > That means the same type converters are being registered twice. > Python shouldn't let you actually load the same module twice (i.e. run > its init function) unless you do Py_Finalize(), which isn't supported > by Boost.Python. FWIW confusingly it is possible to import the same module file twice using different relative/absolute paths. This can be avoided by always using absolute import paths. In a sense though it's not the same module due to the different import paths so six of one == half dozen other. For example (not actually tried verbatim but should make the idea clear despite potential typos) assuming there isn't a mod01 or sub01 anywhere on PYTHONPATH: md sub01 touch sub01/__init__.py echo print 'Importing mod01' > sub01/mod01.py python >>> import sys, os >>> sys.path.append(os.path.join(os.getcwd(), 'sub01')) >>> os.chdir('sub01') >>> import mod01 Importing mod01 >>> import mod01 #<--- Note nothing happens here as expected >>> import sub01.mod01 Importing mod01 #<--- Note second import >>> import sub01.mod01 #<-- Nothing again This happens at least on Windows 2000 with Python 2.3.6 up to Python 2.5.1, and I'd expect that at least on all other Windows platforms. If you're uncertain what's importing what, it's also sometimes helpful to run python with the -v flag which shows what imports are occurring. Hope that helps, Mark ________________________________________ This E-Mail (including any attachments) may contain privileged or confidential information. It is intended only for the addressee(s) indicated above. The sender does not waive any of its rights, privileges or other protections respecting this information. Any distribution, copying or other use of this E-Mail or the information it contains, by other than an intended recipient, is not sanctioned and is prohibited. If you received this E-Mail in error, please delete it and advise the sender (by return E-Mail or otherwise) immediately. This E-Mail (including any attachments) has been scanned for viruses. It is believed to be free of any virus or other defect that might affect any computer system into which it is received and opened. However, it is the responsibility of the recipient to ensure that it is virus free. The sender accepts no responsibility for any loss or damage arising in any way from its use. E-Mail received by or sent from RBC Capital Markets is subject to review by Supervisory personnel. Such communications are retained and may be produced to regulatory authorities or others with legal rights to the information. IRS CIRCULAR 230 NOTICE: TO COMPLY WITH U.S. TREASURY REGULATIONS, WE ADVISE YOU THAT ANY U.S. FEDERAL TAX ADVISE INCLUDED IN THIS COMMUNICATION IS NOT INTENDED OR WRITTEN TO BE USED, AND CANNOT BE USED, TO AVOID ANY U.S. FEDERAL TAX PENALTIES OR TO PROMOTE, MARKET, OR RECOMMEND TO ANOTHER PARTY ANY TRANSACTION OR MATTER. From bluescarni at gmail.com Tue Aug 21 19:43:11 2007 From: bluescarni at gmail.com (Francesco Biscani) Date: Tue, 21 Aug 2007 19:43:11 +0200 Subject: [C++-sig] CMake and getting starting with boost.python In-Reply-To: References: Message-ID: <200708211943.11447.bluescarni@gmail.com> On Friday 29 June 2007, Braddock Gaskill wrote: > LINK_LIBRARIES(boost_python) > INCLUDE_DIRECTORIES("/usr/include/python2.5") > LINK_DIRECTORIES("/usr/lib/python2.5") # Not needed? > ADD_LIBRARY(hello SHARED hello.cpp) > EOF > > You WILL have to `mv libhello.so hello.so` after building. > You can avoid renaming the shared object like this: SET_TARGET_PROPERTIES(hello PROPERTIES PREFIX "") This way the shared library won't have the "lib" prefix. BTW, I'm using CMake + Boost.Python and I'm happy about it, the only issue I have is that I can't compile it under Windows (MinGW) because of some dllimport errors. Have you had any experience about it? Regards, Francesco. From cmaynard at gmail.com Wed Aug 22 15:40:20 2007 From: cmaynard at gmail.com (Charles Mark Maynard) Date: Wed, 22 Aug 2007 09:40:20 -0400 Subject: [C++-sig] Boost.Python Examples Message-ID: I know this may seem a stupid question but after scouring the cvs directories and the deb packages I can not find the examples code referenced in the Boost.Python documentation. The docs say the example directory should be found in the installation under python but I can find them nowhere. I really want to try out this package so any help would be greatly appreciated. This was the only contact point I could find, hope it is appropriate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From luca.sbardella at gmail.com Wed Aug 22 19:09:57 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 22 Aug 2007 19:09:57 +0200 Subject: [C++-sig] Py++: Derived class and class templates Message-ID: <8315652a0708221009x1f2ab2cau3fde50e71b7aa7de@mail.gmail.com> Hi, I just started testing Py++ and excuse me if questions are trivial. i) First question. I have the following class class timegrid: public dataserie { public: timegrid() {} timegrid(double T1, double T2, long partitions) {init(T1,T2,partitions);} private: void init(double T1, double T2, long partitions); }; which derives from the class template "dataserie". When I run Py++ (from the gui) I obtain a wrapper class which only include the timegrid methods (in this case the constructors) and no sign of methods derived from the template (and there are quite a lot)!!!! ii) Second question. Running Py++ on a template produce nothing (I guess it make sense). Is there something I'm missing? Thank you. Luca -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Aug 22 19:34:06 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 22 Aug 2007 20:34:06 +0300 Subject: [C++-sig] Py++: Derived class and class templates In-Reply-To: <8315652a0708221009x1f2ab2cau3fde50e71b7aa7de@mail.gmail.com> References: <8315652a0708221009x1f2ab2cau3fde50e71b7aa7de@mail.gmail.com> Message-ID: <7465b6170708221034m2211f32cy67545c7c10ed11c6@mail.gmail.com> On 8/22/07, Luca Sbardella wrote: > Hi, > I just started testing Py++ and excuse me if questions are trivial. > > > i) First question. I have the following class > > class timegrid: public dataserie { > public: > timegrid() {} > timegrid(double T1, double T2, long partitions) > {init(T1,T2,partitions);} > private: > void init(double T1, double T2, long partitions); > }; > > which derives from the class template "dataserie". > When I run Py++ (from the gui) I obtain a wrapper class which only include > the timegrid methods (in this case the constructors) and no sign of methods > derived from the template (and there are quite a lot)!!!! > > > ii) Second question. Running Py++ on a template produce nothing (I guess it > make sense). Is there something I'm missing? The problem is that you cannot expose template functions/classes. Take a look on next FAQ: http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class You can also to take a look on Py++ Boost.Random example. This library is "one big template", still it was very easy to expose it with Py++: Usage example: http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class Source code: http://tinyurl.com/2p8nfd http://tinyurl.com/3cr3ds HTH. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boost-consulting.com Wed Aug 22 22:58:22 2007 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 22 Aug 2007 16:58:22 -0400 Subject: [C++-sig] Boost.Python Examples References: Message-ID: <87bqcz8exd.fsf@grogan.peloton> on Wed Aug 22 2007, "Charles Mark Maynard" wrote: > I know this may seem a stupid question but after scouring the cvs > directories and the deb packages I can not find the examples code > referenced in the Boost.Python documentation. The docs say the > example directory should be found in the installation under python > but I can find them nowhere. I really want to try out this package > so any help would be greatly appreciated. This was the only contact > point I could find, hope it is appropriate. I don't know anything about how your deb packager decided to structure things, but if you download a Boost release tarball from http://www.boost.org, it will have a libs/python/example directory where you can find all that code. HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From cmaynard at gmail.com Thu Aug 23 02:50:27 2007 From: cmaynard at gmail.com (Charles Mark Maynard) Date: Wed, 22 Aug 2007 20:50:27 -0400 Subject: [C++-sig] Boost.Python Examples In-Reply-To: <87bqcz8exd.fsf@grogan.peloton> References: <87bqcz8exd.fsf@grogan.peloton> Message-ID: Thanks for the help, ended up the build was split between usr/share and usr/include and trying to wrangle the code a problem but cmake fixed it. Thanks again. On 8/22/07, David Abrahams wrote: > > > on Wed Aug 22 2007, "Charles Mark Maynard" wrote: > > > I know this may seem a stupid question but after scouring the cvs > > directories and the deb packages I can not find the examples code > > referenced in the Boost.Python documentation. The docs say the > > example directory should be found in the installation under python > > but I can find them nowhere. I really want to try out this package > > so any help would be greatly appreciated. This was the only contact > > point I could find, hope it is appropriate. > > I don't know anything about how your deb packager decided to structure > things, but if you download a Boost release tarball from > http://www.boost.org, it will have a libs/python/example directory > where you can find all that code. > > HTH, > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > The Astoria Seminar ==> http://www.astoriaseminar.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From winkatl1213 at yahoo.com Thu Aug 23 16:27:54 2007 From: winkatl1213 at yahoo.com (Jeff Winkelman) Date: Thu, 23 Aug 2007 07:27:54 -0700 (PDT) Subject: [C++-sig] py++ and templates Message-ID: <157623.14857.qm@web39808.mail.mud.yahoo.com> Hello, I am using py++ for the first time to wrap a decent sized C++ library. We've been using SWIG for this library for several years and have recently discovered some significant memory leaks. I upgraded to the latest version of SWIG which resulted in huge increase in compile times and no resolution to the issue. So, I've decided to see if boost would handle the situation better. I am able to successfully generate a wrapper file using py++, however, some of the template instances that are declared in one of the header files are not exposed in the wrapper. I've read several suggestions on the py++ website, and even tried wrapping these template instances in a pyplusplus::aliases namespace as suggested in the py++ "hints" section. This eliminated some warnings, but didn't result in code being added for these objects. Does anyone have an idea of why these instances are not be wrapped? I've included the header files I'm trying to wrap along with my py++ script that I'm using. My environment is: Windows XP SP2 Py++-0.9.0 pygccxml-0.9.0 gcc-xml - binary build that's posted on the ctypes sourceforge site (version is reported as 0.7.0) Thanks in advance, Jeff ____________________________________________________________________________________ Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545469 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: files.zip Type: application/x-zip-compressed Size: 97461 bytes Desc: not available URL: From roman.yakovenko at gmail.com Thu Aug 23 19:53:39 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 23 Aug 2007 20:53:39 +0300 Subject: [C++-sig] py++ and templates In-Reply-To: <157623.14857.qm@web39808.mail.mud.yahoo.com> References: <157623.14857.qm@web39808.mail.mud.yahoo.com> Message-ID: <7465b6170708231053i244704c6s13e4f9d721510952@mail.gmail.com> On 8/23/07, Jeff Winkelman wrote: > > Hello, > > I am using py++ for the first time to wrap a decent sized C++ library. > We've been using SWIG for this library for several years and have recently > discovered some significant memory leaks. I upgraded to the latest version > of SWIG which resulted in huge increase in compile times and no resolution > to the issue. > > So, I've decided to see if boost would handle the situation better. > > I am able to successfully generate a wrapper file using py++, however, some > of the template instances that are declared in one of the header files are > not exposed in the wrapper. > > I've read several suggestions on the py++ website, and even tried wrapping > these template instances in a pyplusplus::aliases namespace as suggested in > the py++ "hints" section. > > This eliminated some warnings, but didn't result in code being added for > these objects. > > Does anyone have an idea of why these instances are not be wrapped? > > I've included the header files I'm trying to wrap along with my py++ script > that I'm using. What template class(es) you try to expose? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From luca.sbardella at gmail.com Thu Aug 23 19:58:02 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Thu, 23 Aug 2007 19:58:02 +0200 Subject: [C++-sig] Py++: Derived class and class templates In-Reply-To: <7465b6170708221034m2211f32cy67545c7c10ed11c6@mail.gmail.com> References: <8315652a0708221009x1f2ab2cau3fde50e71b7aa7de@mail.gmail.com> <7465b6170708221034m2211f32cy67545c7c10ed11c6@mail.gmail.com> Message-ID: <8315652a0708231058m44ea581en641d3eef8a09a180@mail.gmail.com> Thanks Roman, essentially I need to instantiate a template and Py++ will do the rest.. sweet. On 22/08/07, Roman Yakovenko wrote: > > On 8/22/07, Luca Sbardella wrote: > > Hi, > > I just started testing Py++ and excuse me if questions are trivial. > > > > > > i) First question. I have the following class > > > > class timegrid: public dataserie { > > public: > > timegrid() {} > > timegrid(double T1, double T2, long partitions) > > {init(T1,T2,partitions);} > > private: > > void init(double T1, double T2, long partitions); > > }; > > > > which derives from the class template "dataserie". > > When I run Py++ (from the gui) I obtain a wrapper class which only > include > > the timegrid methods (in this case the constructors) and no sign of > methods > > derived from the template (and there are quite a lot)!!!! > > > > > > ii) Second question. Running Py++ on a template produce nothing (I > guess it > > make sense). Is there something I'm missing? > > The problem is that you cannot expose template functions/classes. Take > a look on next FAQ: > > http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class > > You can also to take a look on Py++ Boost.Random example. This library > is "one big template", still it was very easy to expose it with Py++: > > Usage example: > > http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class > Source code: > http://tinyurl.com/2p8nfd > http://tinyurl.com/3cr3ds > > HTH. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From winkatl1213 at yahoo.com Thu Aug 23 21:18:34 2007 From: winkatl1213 at yahoo.com (Jeff Winkelman) Date: Thu, 23 Aug 2007 12:18:34 -0700 (PDT) Subject: [C++-sig] py++ and templates Message-ID: <791258.17734.qm@web39808.mail.mud.yahoo.com> >On 8/23/07, Jeff Winkelman wrote: >> >> Hello, >> >> I am using py++ for the first time to wrap a decent sized C++ library. >> We've been using SWIG for this library for several years and have recently >> discovered some significant memory leaks. I upgraded to the latest version >> of SWIG which resulted in huge increase in compile times and no resolution >> to the issue. >> >> So, I've decided to see if boost would handle the situation better. >> >> I am able to successfully generate a wrapper file using py++, however, some >> of the template instances that are declared in one of the header files are >> not exposed in the wrapper. >> >> I've read several suggestions on the py++ website, and even tried wrapping >> these template instances in a pyplusplus::aliases namespace as suggested in >> the py++ "hints" section. >> >> This eliminated some warnings, but didn't result in code being added for >> these objects. >> >> Does anyone have an idea of why these instances are not be wrapped? >> >> I've included the header files I'm trying to wrap along with my py++ script >> that I'm using. > >What template class(es) you try to expose? > >-- >Roman Yakovenko >C++ Python language binding >http://www.language-binding.net/ Roman, They are the template instances defined in the bottom of the Easy_EImage.h file. I'll list them here for reference: // Predefined ROI types typedef EROI EROIBW1; typedef EROI EROIBW8; typedef EROI EROIBW16; typedef EROI EROIBW32; typedef EROI EROIC15; typedef EROI EROIC16; typedef EROI EROIC24; typedef EROI EROIYUY2; typedef EROI EROIC24A; typedef EROI EROISubPixel64; typedef EROI EROIComplex64; typedef EROI EROIRaw32; typedef EROI EROIRaw96; typedef EROI EROIFLOAT32; typedef EROI EROIFLOAT64; // Predefined image types typedef EImage EImageBW1; typedef EImage EImageBW8; typedef EImage EImageBW16; typedef EImage EImageBW32; typedef EImage EImageC15; typedef EImage EImageC16; typedef EImage EImageC24; typedef EImage EImageYUY2; typedef EImage EImageC24A; typedef EImage EImageSubPixel64; typedef EImage EImageComplex64; typedef EImage EImageRaw32; typedef EImage EImageRaw96; typedef EImage EImageFLOAT32; typedef EImage EImageFLOAT64; Jeff ____________________________________________________________________________________ Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. http://autos.yahoo.com/carfinder/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Aug 23 21:57:23 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 23 Aug 2007 22:57:23 +0300 Subject: [C++-sig] py++ and templates In-Reply-To: <791258.17734.qm@web39808.mail.mud.yahoo.com> References: <791258.17734.qm@web39808.mail.mud.yahoo.com> Message-ID: <7465b6170708231257r29d25096rd2ebdad6ea7219b@mail.gmail.com> On 8/23/07, Jeff Winkelman wrote: > Roman, > > They are the template instances defined in the bottom of the Easy_EImage.h > file. > > I'll list them here for reference: > > // Predefined ROI types > typedef EROI EROIBW1; > typedef EROI EROIBW8; > typedef EROI EROIBW16; > typedef EROI EROIBW32; > typedef EROI EROIC15; > typedef EROI EROIC16; > typedef EROI EROIC24; > typedef EROI EROIYUY2; > typedef EROI EROIC24A; > typedef EROI EROISubPixel64; > typedef EROI EROIComplex64; > typedef EROI EROIRaw32; > typedef EROI EROIRaw96; > typedef EROI EROIFLOAT32; > typedef EROI EROIFLOAT64; > > // Predefined image types > typedef EImage EImageBW1; > typedef > EImage EImageBW8; > typedef EImage EImageBW16; > typedef EImage EImageBW32; > typedef EImage EImageC15; > typedef EImage EImageC16; > typedef EImage EImageC24; > typedef EImage EImageYUY2; > typedef EImage EImageC24A; > typedef EImage EImageSubPixel64; > typedef EImage EImageComplex64; > typedef EImage EImageRaw32; > typedef EImage EImageRaw96; > typedef EImage EImageFLOAT32; > typedef EImage EImageFLOAT64; If this is the case, than the solution is really simple: use sizeof operator: sizeof( EImageBW16 ); This should help. For starting I suggest you to write sizeof within the code or within other header that you will use as input to Py++. Later, you can generate the template instantiations from the Py++ script. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Mon Aug 27 14:49:41 2007 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 27 Aug 2007 15:49:41 +0300 Subject: [C++-sig] Py++ and nested classes Message-ID: <46D2C865.1020001@tut.fi> Can nested classes be accessed directly from the top level of a module builder, or does one need to traverse the class hierarchy recursively? I need to set the call policy for some members of a nested class. -- Pertti From roman.yakovenko at gmail.com Mon Aug 27 15:49:12 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 27 Aug 2007 16:49:12 +0300 Subject: [C++-sig] Py++ and nested classes In-Reply-To: <46D2C865.1020001@tut.fi> References: <46D2C865.1020001@tut.fi> Message-ID: <7465b6170708270649y3b46a7bet40481d62da612c6e@mail.gmail.com> On 8/27/07, Pertti Kellom?ki wrote: > Can nested classes be accessed directly from the top level > of a module builder, or does one need to traverse the > class hierarchy recursively? I need to set the call policy > for some members of a nested class. Yes of course. mb = module_builder_t(...) mb.class_( class name ) should do the work -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Mon Aug 27 17:52:13 2007 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 27 Aug 2007 18:52:13 +0300 Subject: [C++-sig] Py++ and nested classes In-Reply-To: <7465b6170708270649y3b46a7bet40481d62da612c6e@mail.gmail.com> References: <46D2C865.1020001@tut.fi> <7465b6170708270649y3b46a7bet40481d62da612c6e@mail.gmail.com> Message-ID: <46D2F32D.10605@tut.fi> Roman Yakovenko wrote: > mb = module_builder_t(...) > mb.class_( class name ) > > should do the work Ah, it did not occur to me to use the base name of the class, I was trying to access the inner class as "Outer::Inner". What happens if I have two inner classes with the same name inside two different top level classes? Can I differentiate between them somehow? -- Pertti From roman.yakovenko at gmail.com Mon Aug 27 21:11:50 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 27 Aug 2007 22:11:50 +0300 Subject: [C++-sig] Py++ and nested classes In-Reply-To: <46D2F32D.10605@tut.fi> References: <46D2C865.1020001@tut.fi> <7465b6170708270649y3b46a7bet40481d62da612c6e@mail.gmail.com> <46D2F32D.10605@tut.fi> Message-ID: <7465b6170708271211i2ba2b4fx85b516e0f04ea430@mail.gmail.com> On 8/27/07, Pertti Kellom?ki wrote: > Roman Yakovenko wrote: > > mb = module_builder_t(...) > > mb.class_( class name ) > > > > should do the work > > Ah, it did not occur to me to use the base name of > the class, I was trying to access the inner class as > "Outer::Inner". Internally Py++ uses pygccxml defined "matchers". http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.matchers-module.html In the case you are looking for declaration by name you can specify: * full name, for example ::std::wstring * name only, for example wstring but you cannot specify partial name > What happens if I have two inner classes > with the same name inside two different top level classes? It depends whether the scope you are looking at, includes both classes or not and what API do you use. You can use next API: * "class_" - returns reference to found declaration, if zero or more than one declarations found exception is raised. * "classes" - returns list of all found declarations, you can ask Py++ to raise exception if no declarations were found. Take a look on this API doc: http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.scopedef.scopedef_t-class.html You also can limit the scope: namespace x{ namespace y{ struct z{}; } } mb = module_builder_t( ... ) x = mb.namespace( "x" ) y = x.namespace("y") y.class_( ... ) > Can I differentiate between them somehow? Of course, you can ask "decl_string" property value, which contains declaration full name. HTH. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From luca.sbardella at gmail.com Wed Aug 29 09:23:43 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 29 Aug 2007 09:23:43 +0200 Subject: [C++-sig] template function Message-ID: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> Hi, I have a class template with a function template as follow template class test { public: typedef D key_type; typedef T data_type; typedef keyvaluepair value_type; typedef typename vector_composite::container container; typedef typename container::iterator iterator; typedef typename container::const_iterator const_iterator; dataserie(){} // /// \brief search for a key_type /// @return If the return value is not negative than it represents the index associated with the value_type d, /// otherwise idx = -return-1 representes the index where the element would be inserted if added to the container. qm_long search(const key_type& key) const; /// \brief check whether the value_type d is available bool contains(const key_type& key) const {if(this->search(key)<0) return false; return true;} /// \brief get the index associated with the key_type t qm_Size index(const key_type& t) const; /// @param Time in years @returns the index i such that grid[i] is closest to t qm_Size closestIndex(const key_type& t) const; /// @param Time in years @return closest time on grid const value_type& closestValue(const key_type& t) const { return this->get(this->closestIndex(t));} /// \brief The Add method /// This member function should be used to add new elements to the timeserie /// @param d The date /// @param value The value associated with d void add(const key_type& key, const data_type& value = data_type()); template L keys() const { L list; //for(const_iterator it = this->begin();it!=this->end();++it) list.append(it->key()); return list; } //template //L values() {return m_values.dataToList();} protected: void insert(qm_Size pos, const value_type& kv) { this->vector().insert(this->vector().begin()+pos,kv);} }; -------------- next part -------------- An HTML attachment was scrubbed... URL: From luca.sbardella at gmail.com Wed Aug 29 09:39:40 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 29 Aug 2007 09:39:40 +0200 Subject: [C++-sig] template function In-Reply-To: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> Message-ID: <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> Ops, Sorry disregards previous message...fat fingers... I Hi, I have a class template with a member function template as follow template class test { public: ........ Some member functions template L keys() const { L list; ..... return L; }; I created a function to export the template in the following way template void export_test(string name) { typedef test etest; class_(name.c_str()) ..... Implemented all the member functions .def("keys", &etest::keys) **** trying to implement the member function template ; } and used the export_test class to export to python. For example export_test("test_real"); Everything works fine if I comment .def("keys", &etest::keys) in the export_test. All the member functions of test are available in Python. However if I insert the .def("keys", &etest::keys) the code will not compile!!! Am I missing something? Thanks Luca On 29/08/2007, Luca Sbardella wrote: > > Hi, > I have a class template with a function template as follow > > template > class test { > public: > typedef D > key_type; > typedef T > data_type; > typedef keyvaluepair > value_type; > typedef typename vector_composite::container > container; > typedef typename container::iterator > iterator; > typedef typename container::const_iterator > const_iterator; > > dataserie(){} > // > /// \brief search for a key_type > /// @return If the return value is not negative than it represents > the index associated with the value_type d, > /// otherwise idx = -return-1 representes the index where the > element would be inserted if added to the container. > qm_long search(const key_type& key) const; > /// \brief check whether the value_type d is available > bool contains(const key_type& key) const > {if(this->search(key)<0) return false; return true;} > /// \brief get the index associated with the key_type t > qm_Size index(const key_type& t) const; > /// @param Time in years @returns the index i such that grid[i] is > closest to t > qm_Size closestIndex(const key_type& t) const; > /// @param Time in years @return closest time on grid > const value_type& closestValue(const key_type& t) const { > return this->get(this->closestIndex(t));} > > /// \brief The Add method > /// This member function should be used to add new elements to the > timeserie > /// @param d The date > /// @param value The value associated with d > void add(const key_type& key, const data_type& value = > data_type()); > > template > L keys() const { > L list; > //for(const_iterator it = this->begin();it!=this->end();++it) > list.append(it->key()); > return list; > } > > //template > //L values() {return m_values.dataToList();} > protected: > void insert(qm_Size pos, const value_type& kv) { > this->vector().insert(this->vector().begin()+pos,kv);} > }; > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Aug 29 15:36:36 2007 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 29 Aug 2007 09:36:36 -0400 Subject: [C++-sig] template function References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> Message-ID: <87sl62xy1n.fsf@grogan.peloton> on Wed Aug 29 2007, "Luca Sbardella" wrote: > and used the export_test class to export to python. For example > > export_test("test_real"); > > Everything works fine if I comment > .def("keys", &etest::keys) > in the export_test. All the member functions of test are available in Python. > > However if I insert the .def("keys", &etest::keys) the code will not > compile!!! > > Am I missing something? Yeah, &etest::keys isn't valid C++ unless L is a type. It isn't, in your case. You can't take the address of a (member) function template; you can only take the address of a particular specialization (instance) of that template, so you need to substitute a real, concrete type name for L. HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From basha.jpm at tcs.com Wed Aug 29 16:03:50 2007 From: basha.jpm at tcs.com (Basha J P M) Date: Wed, 29 Aug 2007 19:33:50 +0530 Subject: [C++-sig] regarding extending and embedding Message-ID: <46D57CC6.7080209@tcs.com> hai , Iam using Qt version :: 4.2.3 Python version:: 2.5.1 my problem is that i need to get pop up from python .Front end being Qt and back end being Python for parsing the files.I have embedded python scripts by using python API 's .what i need to do for getting pop up from python. regards, basha. =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you From meine at informatik.uni-hamburg.de Wed Aug 29 16:41:14 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Wed, 29 Aug 2007 16:41:14 +0200 Subject: [C++-sig] regarding extending and embedding In-Reply-To: <46D57CC6.7080209@tcs.com> References: <46D57CC6.7080209@tcs.com> Message-ID: <200708291641.15209.meine@informatik.uni-hamburg.de> Am Mittwoch, 29. August 2007 16:03:50 schrieb Basha J P M: > my problem is that i need to get pop up from python .Front end being Qt > and back end being Python for parsing the files.I have embedded python > scripts by using python API 's .what i need to do for getting pop up > from python. Look into the [Py]Qt tutorial (QMessageBox)? Assuming that you already have a QApplication running, what's the problem? -- Ciao, / / /--/ / / ANS From luca.sbardella at gmail.com Wed Aug 29 16:55:24 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 29 Aug 2007 16:55:24 +0200 Subject: [C++-sig] template function In-Reply-To: <87sl62xy1n.fsf@grogan.peloton> References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> Message-ID: <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> Thanks Dave, but I did put a concrete type in the template argument. My previous email was a bit confusing. Here is the function template used for exporting template void export_test(string name) { typedef test etest; class_(name.c_str()) ..... Implemented all the member functions .def("keys", &etest::keys) ; } So there is a real concrete type in the template argument. However when I try to compile I get a strange error message In function 'void export_test(const std::string&)': error: expected primary-expression before '>' token error: expected primary-expression before ')' token This message is quite strange, infact I get it even if I don't instantiate the function template '' export_test''. Luca On 29/08/2007, David Abrahams wrote: > > > on Wed Aug 29 2007, "Luca Sbardella" wrote: > > > and used the export_test class to export to python. For example > > > > export_test("test_real"); > > > > Everything works fine if I comment > > .def("keys", &etest::keys) > > in the export_test. All the member functions of test are available in > Python. > > > > However if I insert the .def("keys", &etest::keys) the code > will not > > compile!!! > > > > Am I missing something? > > Yeah, &etest::keys isn't valid C++ unless L is a type. It isn't, > in your case. You can't take the address of a (member) function > template; you can only take the address of a particular specialization > (instance) of that template, so you need to substitute a real, concrete > type name for L. > > HTH, > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > The Astoria Seminar ==> http://www.astoriaseminar.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Aug 29 17:04:19 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 29 Aug 2007 11:04:19 -0400 Subject: [C++-sig] template function In-Reply-To: <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> Message-ID: <46D58AF3.5090709@sympatico.ca> Luca Sbardella wrote: > Thanks Dave, > but I did put a concrete type in the template argument. > My previous email was a bit confusing. > Here is the function template used for exporting [...] > In function 'void export_test(const std::string&)': > error: expected primary-expression before '>' token > error: expected primary-expression before ')' token It would be helpful if you would give a full (minimal) source code exhibiting the error, together with a complete error message (in particular, line numbers). Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From luca.sbardella at gmail.com Wed Aug 29 17:48:58 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 29 Aug 2007 17:48:58 +0200 Subject: [C++-sig] template function In-Reply-To: <46D58AF3.5090709@sympatico.ca> References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> <46D58AF3.5090709@sympatico.ca> Message-ID: <8315652a0708290848l7cfdac9cn1c10f3bdd23b4103@mail.gmail.com> Sure, here is a code with the problem #include #include #include #include #include #include template class dataserie { public: typedef T value_type; typedef std::vector container; typedef typename container::iterator iterator; typedef typename container::const_iterator const_iterator; dataserie(){} virtual ~dataserie(){} bool empty() const {return m_data.empty();} unsigned size() const {return m_data.size();} const_iterator begin() const {return m_data.begin();} const_iterator end() const {return m_data.end();} template L tolist() const { L list; for(const_iterator it = m_data.begin();it!=m_data.end();++it) list.append(*it); return list; } private: container m_data; }; template void export_dataserie(const std::string& name) { typedef dataserie container; typedef typename container::value_type value_type; boost::python::class_(name.c_str()) .def("__len__", &container::size) .add_property("size", &container::size) .add_property("empty", &container::empty) .def("list", &container::tolist< boost::python::list > ) ; } BOOST_PYTHON_MODULE(testlib) { export_dataserie("test"); } when I compile the file I get the following make all Building file: ../dataserie.cpp Invoking: GCC C++ Compiler g++ -I/usr/include/python2.5 -I/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"dataserie.d" -MT"dataserie.d" -o"dataserie.o" "../dataserie.cpp" ../dataserie.cpp: In function 'void export_dataserie(const std::string&)': ../dataserie.cpp:45: error: expected primary-expression before '>' token ../dataserie.cpp:45: error: expected primary-expression before ')' token line 45 is the one with .def("list", &container::tolist< boost::python::list > ) Luca On 29/08/2007, Stefan Seefeld wrote: > > Luca Sbardella wrote: > > Thanks Dave, > > but I did put a concrete type in the template argument. > > My previous email was a bit confusing. > > Here is the function template used for exporting > > [...] > > > In function 'void export_test(const std::string&)': > > error: expected primary-expression before '>' token > > error: expected primary-expression before ')' token > > It would be helpful if you would give a full (minimal) > source code exhibiting the error, together with a complete > error message (in particular, line numbers). > > Thanks, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Aug 29 18:15:40 2007 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 29 Aug 2007 12:15:40 -0400 Subject: [C++-sig] template function References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> <46D58AF3.5090709@sympatico.ca> <8315652a0708290848l7cfdac9cn1c10f3bdd23b4103@mail.gmail.com> Message-ID: <871wdm48r7.fsf@grogan.peloton> on Wed Aug 29 2007, "Luca Sbardella" wrote: > Sure, > here is a code with the problem Do what Stefan asked and make the example _minimal_. There's a 95% chance you will find and correct the problem yourself if you do that. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From dave at boost-consulting.com Wed Aug 29 18:17:45 2007 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 29 Aug 2007 12:17:45 -0400 Subject: [C++-sig] template function References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> <46D58AF3.5090709@sympatico.ca> <8315652a0708290848l7cfdac9cn1c10f3bdd23b4103@mail.gmail.com> Message-ID: <87veay2u3a.fsf@grogan.peloton> on Wed Aug 29 2007, "Luca Sbardella" wrote: > .def("list", &container::tolist< boost::python::list > ) ^ container is a dependent type, so ^ you are missing the 'template' keyword----------------^ here. .def("list", &container::template tolist< boost::python::list > ) -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From luca.sbardella at gmail.com Wed Aug 29 18:45:44 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 29 Aug 2007 18:45:44 +0200 Subject: [C++-sig] template function In-Reply-To: <87veay2u3a.fsf@grogan.peloton> References: <8315652a0708290023r177635bes6e99e491ca0faed5@mail.gmail.com> <8315652a0708290039vc8ec3a6w3e707d3b0715b78e@mail.gmail.com> <87sl62xy1n.fsf@grogan.peloton> <8315652a0708290755n50075eb0v1a571b85d3a370c7@mail.gmail.com> <46D58AF3.5090709@sympatico.ca> <8315652a0708290848l7cfdac9cn1c10f3bdd23b4103@mail.gmail.com> <87veay2u3a.fsf@grogan.peloton> Message-ID: <8315652a0708290945i2bcc5281xcdbf7810fc57972d@mail.gmail.com> Thanks a lot!!! I had no idea I could use the template keyword in that place.. Luca On 29/08/2007, David Abrahams wrote: > > > on Wed Aug 29 2007, "Luca Sbardella" wrote: > > > .def("list", &container::tolist< > boost::python::list > ) > ^ > container is a dependent type, so ^ > you are missing the 'template' keyword----------------^ here. > > > .def("list", &container::template tolist< boost::python::list > ) > > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > The Astoria Seminar ==> http://www.astoriaseminar.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.jaroszynski at gmail.com Thu Aug 30 00:18:44 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Thu, 30 Aug 2007 00:18:44 +0200 Subject: [C++-sig] Outstanding problem Message-ID: <200708300018.44762.p.jaroszynski@gmail.com> Hello, seeing David around I would like to resurrect the question about using std::tr1::shared_ptr as boost::shared_ptr - first asked in [1]. [1] - http://mail.python.org/pipermail/c++-sig/2007-April/012243.html -- Best Regards, Piotr Jaroszy?ski From p.jaroszynski at gmail.com Thu Aug 30 00:31:16 2007 From: p.jaroszynski at gmail.com (Piotr =?iso-8859-2?q?Jaroszy=F1ski?=) Date: Thu, 30 Aug 2007 00:31:16 +0200 Subject: [C++-sig] bases + wrapper bug? In-Reply-To: <7465b6170708181054h1aec8072r90fd6549f68f3085@mail.gmail.com> References: <200708171552.03449.p.jaroszynski@gmail.com> <7465b6170708181054h1aec8072r90fd6549f68f3085@mail.gmail.com> Message-ID: <200708300031.16300.p.jaroszynski@gmail.com> On Saturday 18 of August 2007 19:54:55 Roman Yakovenko wrote: > I will try to explain, how I understand this, but of course I could be > wrong. > (snip) > At run time, behind PyObject you have holds DerivedWrapper class instance. > During the first registration of "f", type of "this" pointer is > BaseWrapper. I could be wrong, but the library doesn't scan for > registered [pure] virtual functions and re-registers them again with > the right "this" pointer. So in your case: you call "f" with "this" > pointer type "DerivedWrapper", than library does casting for you from > DerivedWrapper to BaseWrapper and than it calls "f". Obviously this > cannot work, becase BaseWrapper and DerivedWrapper are not base and > derived classes. Thanks a lot, you do seem to be right, but I still wonder whether it can be considered a bug or not. Would the re-registration introduce some unwanted behaviour if implemented? -- Best Regards, Piotr Jaroszy?ski From dave at boost-consulting.com Thu Aug 30 15:28:26 2007 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 30 Aug 2007 09:28:26 -0400 Subject: [C++-sig] Outstanding problem References: <200708300018.44762.p.jaroszynski@gmail.com> Message-ID: <871wdlcft1.fsf@grogan.peloton> on Wed Aug 29 2007, Piotr Jaroszy?ski wrote: > Hello, > > seeing David around I would like to resurrect the question about using > std::tr1::shared_ptr as boost::shared_ptr - first asked in [1]. > > [1] - http://mail.python.org/pipermail/c++-sig/2007-April/012243.html Making std::tr1::shared_ptr work just like boost::shared_ptr in Boost.Python requires changing the Boost.Python source to create support for it. If you search for shared_ptr in the sources, I'm sure you'll find all the relevant spots. If you make sure the code still works when std::tr1::shared_ptr isn't available, I'll happily accept a patch. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From kmcneillie at softwarespecialists.com Thu Aug 30 18:04:17 2007 From: kmcneillie at softwarespecialists.com (Kelley McNeillie) Date: Thu, 30 Aug 2007 12:04:17 -0400 Subject: [C++-sig] Please Read: Assistance needed for 3-6 month Python Development project Message-ID: Hello, I am contacting you from a company called Software Specialists, an IT Placement Firm based in Pittsburgh, PA. We are prepared to make a donation to your organization if you could please help us out with a referral. We are looking for a python developer with web-based application experience. If you know of anyone, or if you would be able to post this opportunity on your site, I would greatly appreciate it. I am finding this skill pretty much impossible to identify locally, and I really would like to be able to assist my client with this position. I am just trying to be creative in my search, I hope I am reaching the right person with this request. If not, I apologize. Thank you in advance for any assistance you may be able to provide. Best Regards, Kelley McNeillie Software Specialists, Inc. 357 Northgate Drive Suite 10 Warrendale, PA 15086 724 933 6100 x 1105 724 933 6106 (F) kmcneillie at softwarespecialists.com www.softwarespecialists.com From desai3 at cooper.edu Thu Aug 30 22:58:28 2007 From: desai3 at cooper.edu (desai3 at cooper.edu) Date: Thu, 30 Aug 2007 16:58:28 -0400 (EDT) Subject: [C++-sig] caller.hpp(199) : error C2027: use of undefined type Message-ID: <17959.159.53.78.140.1188507508.squirrel@wish.cooper.edu> I am trying to expose a C++ function in Python. This function does not take any inputs, and it returns a structure which consists of a string array and a multidimentional integer array. When I try to compile it, it gives me following error: c:\boost\boost/python/detail/caller.hpp(199) : error C2027: use of undefined type 'boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning' with [ T=result_t ] c:\boost\boost/python/detail/caller.hpp(176) : while compiling class template member function 'PyObject *boost::python::detail::caller_arity<1>::impl::operator ()(PyObject *,PyObject *)' with [ F=DQEasy *(__thiscall DQEasy::* )(void), Policies=boost::python::default_call_policies, Sig=boost::mpl::vector2 ] ///////////// My function looks like this: DQEasy* DQEasy::RequestToResponse() { int size(0); std::string user = "O066144"; std::string url = "dataquery-dev.ny.jpmorgan.com:6555"; DQP* request = getBaseRequest(); addValidContext(request, user); std::string expressionList[] = {"DB(FHR,TB3,MIDYLD)","DB(FHR,TB6,MIDYLD)"}; size = sizeof(expressionList)/sizeof(std::string); DQEasy::addExressions(request, expressionList, size); std::string outputTypeArray[] = {"data","stats"}; size = sizeof(outputTypeArray)/sizeof(std::string); DQEasy::addOutputTypes(request, outputTypeArray, size); DQP *response = DQEasy::getResponse(request, url); DQEasy *output = DQEasy::parseDQP(response); return output; } #include #include #include using namespace boost::python; BOOST_PYTHON_MODULE(DQEasy) { //Export the class to Python class_("DQEasy") .def("RequestToResponse", &DQEasy::RequestToResponse) ; } Any clue will be quite helpful. I apologize if the message is too long. Thank you