From tbrooks.mail at gmail.com Mon Jul 2 00:36:16 2007 From: tbrooks.mail at gmail.com (Tom Brooks) Date: Sun, 1 Jul 2007 18:36:16 -0400 Subject: [C++-sig] Handle class and lifetime In-Reply-To: References: Message-ID: I'm a beginner at this but, I find that it's easiest and most effective to simply use boost::shared_ptr to hold anything. You can get Python to hold it in a boost::shared_ptr, too, by putting boost::shared_ptr into the template of the "graph" class_. Like so: class_ > pyg("graph") Then, just use boost::shared_ptr or boost::weak_ptr everywhere in C++ that you need to reference the graph. It's straight-forward and I find that it eliminates the ownership-struggle between Python and C++ that I frequently get. Hope that helps you. On 6/29/07, Anders Wang Kristensen wrote: > > Hi, > > I'm a little confused by the call policies in boost python. > > I have something like the following situation: > > struct vertex > { > graph* p; > int x; > }; > > struct graph > { > vertex get_vertex(int i); > }; > > and in my python module: > > class_ pyg("graph") > pyg.def("get_vertex", &graph::get_vertex, > with_custodian_and_ward_postcall<0,1>()); > > Is this the right way to make sure that graphs wont be destroyed while > there are still vertices around which reference these graphs? > > Thanks! > > -- Anders > > _______________________________________________ > 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 roman.yakovenko at gmail.com Mon Jul 2 06:15:26 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 2 Jul 2007 07:15:26 +0300 Subject: [C++-sig] Handle class and lifetime In-Reply-To: References: Message-ID: <7465b6170707012115w64670f47v5d13fe0fd66496c8@mail.gmail.com> On 6/30/07, Anders Wang Kristensen wrote: > Hi, > > I'm a little confused by the call policies in boost python. > > I have something like the following situation: > > struct vertex > { > graph* p; > int x; > }; > > struct graph > { > vertex get_vertex(int i); > }; > > and in my python module: > > class_ pyg("graph") > pyg.def("get_vertex", &graph::get_vertex, > with_custodian_and_ward_postcall<0,1>()); > > Is this the right way to make sure that graphs wont be destroyed while > there are still vertices around which reference these graphs? I think that you are right. You always can check yourself be testing reference count sys.getrefcount -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From j.reid at mail.cryst.bbk.ac.uk Mon Jul 2 11:05:03 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Mon, 02 Jul 2007 10:05:03 +0100 Subject: [C++-sig] Raoul Gough's indexing suite Message-ID: I've downloaded Raoul Gough's indexing suite code into my boost/python/suite/indexing directory. I got it from http://svn.boost.org/svn/boost/sandbox/boost/python/suite/indexing/ Now the following code does not compile as advertised on: http://boost-sandbox.sourceforge.net/python/indexing/containers.html #include using namespace boost; using namespace boost::python; using namespace indexing; void export_container() { class_< std::vector > ("vector_int") .def (container_suite< std::vector >()); } The error complains that def does not have the right number of arguments. I'm using VC++ express on XP with Boost 1.34.0 Also I had to add a missing typename to line 75 of container_proxy.hpp: typedef typename container_proxy::value_type value_type; Did I get the wrong version? Where should I get the code from? John. From roman.yakovenko at gmail.com Mon Jul 2 11:17:46 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 2 Jul 2007 12:17:46 +0300 Subject: [C++-sig] Raoul Gough's indexing suite In-Reply-To: References: Message-ID: <7465b6170707020217u3b98aa63k34e353d4841bbca8@mail.gmail.com> On 7/2/07, John Reid wrote: > I've downloaded Raoul Gough's indexing suite code into my > boost/python/suite/indexing directory. I got it from > http://svn.boost.org/svn/boost/sandbox/boost/python/suite/indexing/ > > Now the following code does not compile as advertised on: > http://boost-sandbox.sourceforge.net/python/indexing/containers.html > > > #include > > using namespace boost; > using namespace boost::python; > using namespace indexing; > > void export_container() > { > class_< std::vector > ("vector_int") > .def (container_suite< std::vector >()); > } > > The error complains that def does not have the right number of arguments. > > > > I'm using VC++ express on XP with Boost 1.34.0 > > Also I had to add a missing typename to line 75 of container_proxy.hpp: > typedef typename container_proxy::value_type value_type; > > > Did I get the wrong version? Where should I get the code from? You can get it from me: http://language-binding.net/pyplusplus/documentation/containers.html SVN: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ Pay attention: this is a modified version of the original source code. It contains few bug fixes and support for new containers. If you are going to play with it I suggest you to install Py++ and see what code it generates. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Mark.English at rbccm.com Mon Jul 2 11:23:58 2007 From: Mark.English at rbccm.com (English, Mark) Date: Mon, 2 Jul 2007 10:23:58 +0100 Subject: [C++-sig] Raoul Gough's indexing suite Message-ID: > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org]On > Behalf Of John Reid > Sent: 02 July 2007 10:05 > To: c++-sig at python.org > Subject: [C++-sig] Raoul Gough's indexing suite > > > I've downloaded Raoul Gough's indexing suite code into my > boost/python/suite/indexing directory. I got it from > http://svn.boost.org/svn/boost/sandbox/boost/python/suite/indexing/ > > Now the following code does not compile as advertised on: > http://boost-sandbox.sourceforge.net/python/indexing/containers.html > It doesn't look very up to date, but I did notice it in use in Python-Ogre which is actively maintained. For example here: http://python-ogre.org/browser/trunk/python-ogre/boost/libs/python/src/indexing If you don't get any joy here, you could try asking them. E.g. http://groups.google.com/group/python-ogre-developers Not knowing anything about Python-Ogre or the indexing suite, that could all be misinformation though. Cheers, 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 j.reid at mail.cryst.bbk.ac.uk Mon Jul 2 12:17:01 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Mon, 02 Jul 2007 11:17:01 +0100 Subject: [C++-sig] Raoul Gough's indexing suite In-Reply-To: <7465b6170707020217u3b98aa63k34e353d4841bbca8@mail.gmail.com> References: <7465b6170707020217u3b98aa63k34e353d4841bbca8@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > You can get it from me: > http://language-binding.net/pyplusplus/documentation/containers.html > SVN: > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ > > Pay attention: this is a modified version of the original source code. > It contains few bug fixes and support for new containers. > > If you are going to play with it I suggest you to install Py++ and see > what code it generates. > That works just fine now. I will try and get around to install Py++. Thanks, John. From Lawrence.Spector at CanfieldSci.com Mon Jul 2 15:45:44 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 2 Jul 2007 09:45:44 -0400 Subject: [C++-sig] Multiple Interpreters Using Boost.Python? In-Reply-To: <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> References: <379940.27910.qm@web31106.mail.mud.yahoo.com> <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> Message-ID: Hello again. I know by default, the Python API only supports one interpreter per process, but I believe there is a way to configure it for multiple interpreters. If so, does Boost.Python support this? Is there any additional steps for Boost.Python to do this, or is it automatic? Let me know. Thanks, Lawrence From seefeld at sympatico.ca Mon Jul 2 16:05:57 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 02 Jul 2007 10:05:57 -0400 Subject: [C++-sig] Multiple Interpreters Using Boost.Python? In-Reply-To: References: <379940.27910.qm@web31106.mail.mud.yahoo.com> <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> Message-ID: <46890645.9070609@sympatico.ca> Lawrence Spector wrote: > Hello again. I know by default, the Python API only supports one > interpreter per process, but I believe there is a way to configure it > for multiple interpreters. If so, does Boost.Python support this? Is > there any additional steps for Boost.Python to do this, or is it > automatic? What do you mean by 'interpreter' ? What's your use case, exactly ? There is a single 'python runtime' linked to your program, and some global variables are shared throughout the process (such as the GIL (Global Interpreter Lock)). However, if all you want is execute ('interpret') multiple python scripts from within your application without them interfering with each other, that's quite trivial to do with the existing API. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Lawrence.Spector at CanfieldSci.com Mon Jul 2 16:37:25 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 2 Jul 2007 10:37:25 -0400 Subject: [C++-sig] Multiple Interpreters Using Boost.Python? In-Reply-To: <46890645.9070609@sympatico.ca> References: <379940.27910.qm@web31106.mail.mud.yahoo.com> <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> <46890645.9070609@sympatico.ca> Message-ID: Yes, what I meant by multiple interpreters is that I can execute multiple scripts from the same program with no interference. How can this be done? Also, you meant a global interpreter lock. Does this mean that two different scripts won't technically execute at the same time? I would like this to scale to multiple processors well. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Monday, July 02, 2007 10:06 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Multiple Interpreters Using Boost.Python? Lawrence Spector wrote: > Hello again. I know by default, the Python API only supports one > interpreter per process, but I believe there is a way to configure it > for multiple interpreters. If so, does Boost.Python support this? Is > there any additional steps for Boost.Python to do this, or is it > automatic? What do you mean by 'interpreter' ? What's your use case, exactly ? There is a single 'python runtime' linked to your program, and some global variables are shared throughout the process (such as the GIL (Global Interpreter Lock)). However, if all you want is execute ('interpret') multiple python scripts from within your application without them interfering with each other, that's quite trivial to do with the existing API. Regards, 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 From seefeld at sympatico.ca Mon Jul 2 17:08:33 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 02 Jul 2007 11:08:33 -0400 Subject: [C++-sig] Multiple Interpreters Using Boost.Python? In-Reply-To: References: <379940.27910.qm@web31106.mail.mud.yahoo.com> <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> <46890645.9070609@sympatico.ca> Message-ID: <468914F1.5000501@sympatico.ca> Lawrence Spector wrote: > Yes, what I meant by multiple interpreters is that I can execute > multiple scripts from the same program with no interference. How can > this be done? Look up the docs for boost::python::exec_file(). You pass dictionaries containing the environment to be seen during execution. These can be distinct objects for the different scripts. > Also, you meant a global interpreter lock. Does this mean that two > different scripts won't technically execute at the same time? I would > like this to scale to multiple processors well. http://docs.python.org/api/threads.html Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jeff.webb at nta-inc.net Mon Jul 2 19:58:57 2007 From: jeff.webb at nta-inc.net (Jeff Webb) Date: Mon, 02 Jul 2007 12:58:57 -0500 Subject: [C++-sig] using intrusive_ptr objects with boost python In-Reply-To: <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> References: <46783D75.4050600@nta-inc.net> <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> Message-ID: <46893CE1.3020504@nta-inc.net> Roman Yakovenko wrote: > On 6/19/07, Jeff Webb ...After quite a bit of reading, experimentation, and > contemplation, it appears to me that using reference-counting smart > pointers in C++ would be the most consistent and seamless way to provide > a rich python binding for this type of library. Do others agree with > this assertion? > > This is was my experience. Thanks for taking the time to respond, Roman. I appreciate your input. > > Very nice! Unfortunately, I think the overhead of using a shared_ptr > will be too high, since my library will instantiate many small objects. > > It looks like you know what you are doing, but don't you think this is a > premature optimization? Perhaps, but I wanted to make sure that it was *possible* to achieve similar functionality without using shared_ptr, since I think that this may be an issue down the road. I don't want to code myself into a corner. > Just search this mailing list for "intrusive_ptr" and you will find many > useful posts. After some more digging, I found some useful things, but not exactly what I was looking for. I was eventually able to make boost python do what I wanted, but it took some time and a lot of experimentation to wrap my brain around the template magic. I have coded up a library example using intrusive_ptrs that provides similar functionality to the existing shared_ptr support. I think the behavior suits me better than the shared_ptr behavior, because I can choose whether or not the python wrapping of an object is 'persistent'. (Perhaps 'persistent' is not the best word, but I will try to explain what I mean.) The current shared_ptr behavior is what I call 'persistent', meaning that once an object has been wrapped by python, it will never be unwrapped until all shared_ptr references to that object have been deleted. This is good if you have overridden methods in the python object, since 'unwrapping' the object would remove the override behavior. On the other hand, if your goal is to construct and manipulate wrapped C++ objects using python, and then just run some C++ code, then it would be ideal to get rid of all the python wrappers when you are done manipulating the C++ objects from python. In this case, an object sho uld be 'unwrapped' when all python references to the object are deleted. I have implemented this behavior using intrusive_ptrs, and objects with embedded reference count and pyobject pointer. When constructing an object, the user can specify whether the python wrapping should be 'persistent' or not. I have attached the source code for this library, and a simple test program. The output of the test program is shown below. $ ./itest.py info(p): C['p'] info(c): W['c'] p.child: None p.child = c info(p): C['p']-->W['c'] c2 = p.child c2 is c: True deleting c2 deleting c info(p): C['p']-->W['c'] p.child=None [clearing pyobject pointer] ~C('c') info(p): C['p'] ---------------- info(c3): W['c3'] p.child = c3 info(p): C['p']-->W['c3'] deleting c3 [clearing pyobject pointer] info(p): C['p']-->C['c3'] calling new_C info(c4): C['c4'] p.child = c4 ~C('c3') info(p): C['p']-->C['c4'] done [clearing pyobject pointer] ~C('p') [clearing pyobject pointer] ~C('c4') Note that 'c' is a persistent object and 'c3' is not persistent. Note that when all references to 'c3' are removed, the info method is no longer overridden from python: "info(p): C['p']-->C['c3']". This demonstrates that the python wrapper has been removed, but the C++ object still exists. Perhaps the user should be able to optionally choose the non-persistent behavior for shared_ptr as well. I think it would prove useful for some applications, as I mentioned above. What do you think? I am posting this code with the hope that it will help some other folks who come across this thread. Thanks again for all the work on boost python. -Jeff itest.py ------------------------------------------------ #!/usr/bin/env python from ilib import * class D(C): def info(self): s = "D['%s']" % self.name if self.child: s += '-->' + child.info() return s class W(CWrap): def info(self): s = "W['%s']" % self.name if self.child: s += '-->' + child.info() return s def main(): p = D('p') c = W('c', persistent=True) print 'info(p):', info(p) print 'info(c):', info(c) print 'p.child:', p.child print 'p.child = c'; p.child = c print 'info(p):', info(p) print 'c2 = p.child'; c2 = p.child print 'c2 is c:', c2 is c print 'deleting c2'; del c2 print 'deleting c'; del c print 'info(p):', info(p) print 'p.child=None'; p.child=None print 'info(p):', info(p) print '----------------' c3 = W('c3', persistent=False) print 'info(c3):', info(c3) print 'p.child = c3'; p.child = c3 print 'info(p):', info(p) print 'deleting c3'; del c3 print 'info(p):', info(p) print 'calling new_C'; c4 = new_C('c4') print 'info(c4):', info(c4) print 'p.child = c4'; p.child = c4 print 'info(p):', info(p) print 'done' main() ilib.cpp ----------------------------------------- #include "intrusive_ptr_python_helper.cpp" #include #include #include #include using namespace std; using namespace boost; using namespace boost::python; namespace bp = boost::python; //------------------------------------------------------------------------------ class RefCounted; namespace boost { void intrusive_ptr_add_ref(RefCounted * ptr); void intrusive_ptr_release(RefCounted * ptr); void intrusive_ptr_set_pyobject(RefCounted * ptr, PyObject * pyobject); void intrusive_ptr_clear_pyobject(RefCounted * ptr); PyObject * intrusive_ptr_get_pyobject(RefCounted * ptr); } class RefCounted { public: RefCounted(int ref_count = 0, bool persistent = false) : ref_count(ref_count), persistent(persistent), pyobject(0) { } virtual ~RefCounted() { } protected: int get_ref_count() { return ref_count; } private: friend void boost::intrusive_ptr_add_ref(RefCounted * ptr); friend void boost::intrusive_ptr_release(RefCounted * ptr); friend void boost::intrusive_ptr_set_pyobject(RefCounted * ptr, PyObject * pyobject); friend void boost::intrusive_ptr_clear_pyobject(RefCounted * ptr); friend PyObject * boost::intrusive_ptr_get_pyobject(RefCounted * ptr); int ref_count; bool persistent; PyObject * pyobject; }; namespace boost { void intrusive_ptr_add_ref(RefCounted * ptr) { if (ptr->persistent) { if (ptr->pyobject && (ptr->ref_count > 0)) { incref(ptr->pyobject); } } ++(ptr->ref_count); } void intrusive_ptr_release(RefCounted * ptr) { if (ptr->persistent) { if (ptr->pyobject) { decref(ptr->pyobject); } } if (--(ptr->ref_count) == 0) delete ptr; } void intrusive_ptr_set_pyobject(RefCounted * ptr, PyObject * pyobject) { if (ptr->persistent) { for (int i=0; iref_count-1; i++) incref(pyobject); } ptr->pyobject = pyobject; } void intrusive_ptr_clear_pyobject(RefCounted * ptr) { cout << "[clearing pyobject pointer]" << endl; ptr->pyobject = 0; } PyObject * intrusive_ptr_get_pyobject(RefCounted * ptr) { return ptr->pyobject; } } //------------------------------------------------------------------------------ class C; typedef intrusive_ptr CPtr; class C : public RefCounted { public: C(const string &name, bool persistent = false) : RefCounted(0, persistent), name(name) { } virtual ~C() { cout << "~C('" << name << "')" << endl; } void set_child(CPtr child) { this->child = child; } CPtr get_child() { return child; } string get_name() { return name; } virtual string info() { string s = "C['" + name + "']"; if (child) { s += "-->" + child->info(); } return s; } private: string name; CPtr child; }; //------------------------------------------------------------------------------ class CWrap : public C { public: CWrap(const string &name, bool persistent = false) : C(name, persistent) { } CWrap(PyObject * py_obj, const string &name, bool persistent = false) : C(name, persistent) { intrusive_ptr_set_pyobject(this, py_obj); } string info() { if (intrusive_ptr_get_pyobject(this)) { return call_method(intrusive_ptr_get_pyobject(this), "info"); } else { return C::info(); } } string default_info() { string s = "CWrap['" + get_name() + "']"; CPtr child = get_child(); if (child) { s += "-->" + child->info(); } return s; } }; //------------------------------------------------------------------------------ string info(CPtr c) { return c->info(); } //------------------------------------------------------------------------------ CPtr new_C(string name) { return CPtr(new C(name)); } object init_C(object py_obj, string name) { object return_value = call_method(py_obj.ptr(), "__cons__", name); intrusive_ptr_set_pyobject(extract(py_obj), py_obj.ptr()); return return_value; } namespace boost { namespace python { template <> struct has_back_reference : mpl::true_ {}; }} namespace boost { namespace python { template <> struct has_back_reference : mpl::true_ {}; }} BOOST_PYTHON_MODULE(ilib) { class_, boost::noncopyable> ("RefCounted") ; class_, bases, boost::noncopyable> ("C", no_init) .def("__init__", init_C) .def("__cons__", make_constructor(new_C)) .def("__del__", &intrusive_ptr_clear_pyobject) .def("info", &C::info) .add_property("child", &C::get_child, &C::set_child) .add_property("name", &C::get_name) ; class_, bases, boost::noncopyable > ("CWrap",init((bp::arg("name"), bp::arg("persistent")=false))) .def("info", &C::info, &CWrap::default_info) ; def("new_C", new_C); def("info", info); // I haven't needed this yet, but... //implicitly_convertible,intrusive_ptr >(); boost::python::converter::intrusive_ptr_from_python(); register_ptr_to_python< intrusive_ptr >(); boost::python::converter::intrusive_ptr_from_python(); register_ptr_to_python< intrusive_ptr >(); } intrusive_ptr_python_helper.cpp --------------------------------- //------------------------------------------------------------------------------ #ifndef INTRUSIVE_PTR_PYTHON_HELPER_HPP # include # include //#include //using namespace std; // This code helps to solve the object identity problem for intrusive pointer // objects that hold an embedded reference a corresponding python object. // Note that the object must have a __del__ function that resets the // intrusive_ptr when the python object is deleted to avoid a dangling pointer. // This code was copied from include/boost/python/object/make_instance.hpp // with some minor changes: // // (1) The template was specialized for a T object held by an // intrusive_ptr smart pointer. // (2) A test was added at the beginning of the execute member function to // see if a python object is already associated with the given T // object. If there is an existing association, the function returns // a reference to the python object. // (3) Otherwise, the python object is created as usual, and a pointer to // the python object is saved in the T object. namespace boost { namespace python { namespace objects { template struct make_instance_impl< T, pointer_holder, T>, make_ptr_instance, T> > > { typedef pointer_holder,T> Holder; typedef make_ptr_instance,T> > Derived; typedef objects::instance instance_t; template static inline PyObject* execute(Arg& x) { // If a python wrapper already exists, return a reference to it if (x && intrusive_ptr_get_pyobject(x.get())) { return incref(intrusive_ptr_get_pyobject(x.get())); } BOOST_STATIC_ASSERT(is_class::value); PyTypeObject* type = Derived::get_class_object(x); if (type == 0) return python::detail::none(); PyObject* raw_result = type->tp_alloc( type, objects::additional_instance_size::value); if (raw_result != 0) { python::detail::decref_guard protect(raw_result); instance_t* instance = (instance_t*)raw_result; // construct the new C++ object and install the pointer // in the Python object. Derived::construct(&instance->storage, (PyObject*)instance, x)->install(raw_result); // Note the position of the internally-stored Holder, // for the sake of destruction instance->ob_size = offsetof(instance_t, storage); // Save a pointer to the pyobject for future reference intrusive_ptr_set_pyobject(x.get(), raw_result); // Release ownership of the python object protect.cancel(); } return raw_result; } }; }}} // namespace boost::python::object // This code enables the conversion of a Python None object to a 'null' // intrusive pointer. This code was copied from // include/boost/python/converter/shared_ptr_from_python.hpp with some minor // changes: // // (1) shared_ptr was replaced by intrusive_ptr. // (2) The shared_ptr_deleter argument was left off the pointer constructor. namespace boost { namespace python { namespace converter { template struct intrusive_ptr_from_python { intrusive_ptr_from_python() { converter::registry::insert(&convertible, &construct, type_id >()); } private: static void* convertible(PyObject* p) { if (p == Py_None) return p; return converter::get_lvalue_from_python(p, registered::converters); } static void construct(PyObject* source, rvalue_from_python_stage1_data* data) { void* const storage = ((converter::rvalue_from_python_storage >*)data)->storage.bytes; // Deal with the "None" case. if (data->convertible == source) new (storage) intrusive_ptr(); else new (storage) intrusive_ptr(static_cast(data->convertible)); data->convertible = storage; } }; }}} // namespace boost::python::converter #endif // INTRUSIVE_PTR_PYTHON_HELPER_HPP From Lawrence.Spector at CanfieldSci.com Tue Jul 3 15:30:41 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 3 Jul 2007 09:30:41 -0400 Subject: [C++-sig] Passing a reference to my object to python Message-ID: So far, what I've done is build a Boost.Python extension for my python script to use. It exposes one class for the script to use, let's say called CppClass. This seems to work okay. I'm using Boost.Python and the Python API to interpret the script from C++ code. During this process, I want to pass a reference to an instance of the object that already exists in my C++ code. I tried the following: boost::python::object myObject(CppClass); When I run, I get a first chance exception: boost::python::error_already_set. I'm sure I'm missing something important. Any idea what's going wrong? Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Jul 3 20:53:44 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 3 Jul 2007 21:53:44 +0300 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: References: Message-ID: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> On 7/3/07, Lawrence Spector wrote: > So far, what I've done is build a Boost.Python extension for my python > script to use. It exposes one class for the script to use, let's say called > CppClass. This seems to work okay. I'm using Boost.Python and the Python > API to interpret the script from C++ code. During this process, I want to > pass a reference to an instance of the object that already exists in my C++ > code. I tried the following: > > boost::python::object myObject(CppClass); > > > When I run, I get a first chance exception: > boost::python::error_already_set. > > > > I'm sure I'm missing something important. Any idea what's going wrong? I will try to clarify, but I could be wrong. The default behavior of the object constructor is to copy the object. If you want it to keep reference to existing object, than you should use boost::ref or boost::python::ptr functionality. I also found another method to create object - using call policies: template< typename CallPolicies, class T > bpl::object make_object( T x ){ //constructs object using CallPolicies result_converter typedef BOOST_DEDUCED_TYPENAME CallPolicies::result_converter:: template apply< T >::type result_converter_t; result_converter_t rc; return bpl::object( bpl::handle<>( rc( x ) ) ); } You select call policy and it handles for you the conversion. The method doesn't work in all cases. It will not work if post_call function, of the call policies class does some job. It is not clear to me why you get exception. You should provide additional information. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From achille.talon at gmail.com Wed Jul 4 16:26:21 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 4 Jul 2007 07:26:21 -0700 (PDT) Subject: [C++-sig] Casting operator issue Message-ID: <11431776.post@talk.nabble.com> Hi! I'm currently wrapping a library and I'm having some problems wth call policies. Here is my peace of code that is causing an error. class A { public: virtual char* toString() = 0; operator char*(){return toString();} }; py++ gives me the following warning: Warning: char* A::operator char*() [casting operator] W1050 = The function returns "%s" type. You have to specify a call policies Be sure to take a look on Py++ defined call policies: http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies I checked the tutorials but I can't figure out how to define a call policy for this case... Thank for your help. -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Casting-operator-issue-tf4024690.html#a11431776 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Wed Jul 4 16:51:39 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 4 Jul 2007 17:51:39 +0300 Subject: [C++-sig] Casting operator issue In-Reply-To: <11431776.post@talk.nabble.com> References: <11431776.post@talk.nabble.com> Message-ID: <7465b6170707040751j7c377285s80fb9faf9223f21e@mail.gmail.com> On 7/4/07, Coockie_jr wrote: > > Hi! > I'm currently wrapping a library and I'm having some problems wth call > policies. > Here is my peace of code that is causing an error. > > class A > { > public: > > > virtual char* toString() = 0; > operator char*(){return toString();} > }; > > py++ gives me the following warning: > > > Warning: char* A::operator char*() [casting operator] > W1050 = The function returns "%s" type. You have to specify a call policies > Be sure to take a look on Py++ defined call policies: > http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies > > I checked the tutorials but I can't figure out how to define a call policy > for this case... It depends on what you want: * return Python string - in this case exclude casting operator operator, change return type of toString from "char*" to "const char*" and you'll be fine. Boost.Python will expose the function using default call policies. If you cannot change code, than I suggest you to create small helper function: std::string toString( const A& a ){ return a.toString() } and register it instead of the A::toString function ( http://language-binding.net/pyplusplus/documentation/inserting_code.html ) * If you want user to allow to write to this place, than you should use "return_range"( http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range) call policies HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes at zellner.org Wed Jul 4 21:25:20 2007 From: johannes at zellner.org (Dr. Johannes Zellner) Date: Wed, 4 Jul 2007 21:25:20 +0200 Subject: [C++-sig] mapping std::vector to python list and vice versa Message-ID: <103840bf0707041225j657cbcb3k7659cbfcc4e89c9@mail.gmail.com> Hi, I'm looking for a mapping from python lists to std::vector. Example: class Fred { void setValue(const std::vector&); std::vector getValue(); }; and would like an automatic mapping with sort of the following statements: .def("setValue", &Fred::setValue) .add_property("value", &Fred::getValue, &Fred::getValue) So I could pass python lists (e.g. [1, 2, 3]) like f = Fred() f.value = [1, 2, 3] for x in f.value: print x I looked into the iterator documentation like class_ >("mylist") .def("__iter__", iterator >()) ; But this seems awkward, as 1. I've to define a new python type "mylist" 2. I've to define all the list access myself Any ideas? -- Dr. Johannes Zellner From roman.yakovenko at gmail.com Wed Jul 4 21:37:40 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 4 Jul 2007 22:37:40 +0300 Subject: [C++-sig] mapping std::vector to python list and vice versa In-Reply-To: <103840bf0707041225j657cbcb3k7659cbfcc4e89c9@mail.gmail.com> References: <103840bf0707041225j657cbcb3k7659cbfcc4e89c9@mail.gmail.com> Message-ID: <7465b6170707041237r6a5b3ea8i899a3d5965566145@mail.gmail.com> On 7/4/07, Dr. Johannes Zellner wrote: > > Hi, > > I'm looking for a mapping from python lists to std::vector. It seems that you are looking after automatic conversion: http://language-binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/automatic_conversion.html Pay attention, the performance will degrade. Example: > > class Fred { > void setValue(const std::vector&); > std::vector getValue(); > }; > > and would like an automatic mapping with sort of the > following statements: > > .def("setValue", &Fred::setValue) This will work .add_property("value", &Fred::getValue, &Fred::getValue) Here you will have to use make_function functionality So I could pass python lists (e.g. [1, 2, 3]) like > > f = Fred() > f.value = [1, 2, 3] > for x in f.value: > print x > > I looked into the iterator documentation like > > class_ >("mylist") > .def("__iter__", iterator >()) > ; > > But this seems awkward, as > 1. I've to define a new python type "mylist" but you gain performance and the interface, which is very similar to Python list class 2. I've to define all the list access myself You can use Py++, it will do it for you :-))) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes at zellner.org Wed Jul 4 22:49:50 2007 From: johannes at zellner.org (Dr. Johannes Zellner) Date: Wed, 4 Jul 2007 22:49:50 +0200 Subject: [C++-sig] How can I test if a python object is None Message-ID: <103840bf0707041349u1368827x6d7650d80600a2a1@mail.gmail.com> Hi, suppose I exposed void fred(object o) { } via .def("fred", &fred) How can I test from within the c++ function fred() which type o has? I'm especially interested if o is "None" (or double). -- Dr. Johannes Zellner From roman.yakovenko at gmail.com Thu Jul 5 09:47:58 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 5 Jul 2007 10:47:58 +0300 Subject: [C++-sig] How can I test if a python object is None In-Reply-To: <103840bf0707041349u1368827x6d7650d80600a2a1@mail.gmail.com> References: <103840bf0707041349u1368827x6d7650d80600a2a1@mail.gmail.com> Message-ID: <7465b6170707050047h4a61fb6bseb200b2ad84b9050@mail.gmail.com> On 7/4/07, Dr. Johannes Zellner wrote: > > Hi, > > suppose I exposed > > void fred(object o) > { > } > > via > > .def("fred", &fred) > > How can I test from within the c++ function fred() which type o has? > I'm especially interested if o is "None" (or double). > http://boost.org/libs/python/doc/v2/extract.html Test for None is pretty simple: o == object() -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From achille.talon at gmail.com Thu Jul 5 14:26:39 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 5 Jul 2007 05:26:39 -0700 (PDT) Subject: [C++-sig] Casting operator issue In-Reply-To: <7465b6170707040751j7c377285s80fb9faf9223f21e@mail.gmail.com> References: <11431776.post@talk.nabble.com> <7465b6170707040751j7c377285s80fb9faf9223f21e@mail.gmail.com> Message-ID: <11445525.post@talk.nabble.com> Thank you, I'll be looking at these suggestions ! Roman Yakovenko wrote: > > On 7/4/07, Coockie_jr wrote: >> >> Hi! >> I'm currently wrapping a library and I'm having some problems wth call >> policies. >> Here is my peace of code that is causing an error. >> >> class A >> { >> public: >> >> >> virtual char* toString() = 0; >> operator char*(){return toString();} >> }; >> >> py++ gives me the following warning: >> >> >> Warning: char* A::operator char*() [casting operator] >> W1050 = The function returns "%s" type. You have to specify a call > policies >> Be sure to take a look on Py++ defined call policies: >> > http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies >> >> I checked the tutorials but I can't figure out how to define a call >> policy >> for this case... > > It depends on what you want: > > * return Python string > - in this case exclude casting operator operator, change return type of > toString from "char*" to "const char*" and you'll be fine. Boost.Python > will > expose the function using default call policies. If you cannot change > code, > than I suggest you to create small helper function: > > std::string toString( const A& a ){ > return a.toString() > } > > and register it instead of the A::toString function ( > http://language-binding.net/pyplusplus/documentation/inserting_code.html ) > > * If you want user to allow to write to this place, than you should use > "return_range"( > http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range) > call policies > > 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 > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Casting-operator-issue-tf4024690.html#a11445525 Sent from the Python - c++-sig mailing list archive at Nabble.com. From achille.talon at gmail.com Thu Jul 5 14:44:12 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 5 Jul 2007 05:44:12 -0700 (PDT) Subject: [C++-sig] Boost / Bjam error : LNK1120 Message-ID: <11445734.post@talk.nabble.com> While building with bjam I get the following error, I think It's a jamroot configuration issue but I must admit I'm a bit lost. ----------------------------------------------------------------------- Here's my log Please refer to the Boost.Regex documentation for more information (don't panic: this is a strictly optional feature). warning: No toolsets are configured. warning: Configuring default toolset "msvc". warning: If the default is wrong, you may not be able to build C++ programs. warning: Use the "--toolset=xxxxx" option to override our guess. warning: For more configuration options, please consult warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html ...patience... ...found 1965 targets... ...updating 3 targets... compile-c-c++ bin\msvc-8.0\debug\test.obj test.cpp msvc.link.dll bin\msvc-8.0\debug\test.pyd bin\msvc-8.0\debug\test.lib Creating library bin\msvc-8.0\debug\test.lib et de l'objet bin\msvc-8.0\debug\test.exp test.obj : error LNK2019: unresolved external symbol "public: static void __cdecl test::cleanThread(void)" (?cleanThread at test@@SAXXZ) referenced in function "void __cdecl init_module_test(void)" (?init_module_test@@YAXXZ) test.obj : error LNK2019: unresolved external symbol "public: static void __cdecl test::initialise(bool)" (?initialise at test@@SAX_N at Z) referenced in function "void __cdecl init_module_test(void)" (?init_module_test@@YAXXZ) test.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl test::initialised(void)" (?initialised at test@@SA_NXZ) referenced in function "void __cdecl init_module_test(void)" (?init_module_test@@YAXXZ) test.obj : error LNK2019: unresolved external symbol "public: static void __cdecl test::release(void)" (?release at test@@SAXXZ) referenced in function "void __cdecl init_module_test(void)" (?init_module_test@@YAXXZ) bin\msvc-8.0\debug\test.pyd : fatal error LNK1120: 4 unresolved externals call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 >nul link /NOLOGO /INCREMENTAL:NO /DLL /DEBUG /subsystem:console /out:"bin\msvc-8.0\debug\test.pyd" /IMPLIB:"bin\msvc-8.0\debug\test.lib" /LIBPATH:"D:\Python25\libs" @"bin\msvc-8.0\debug\test.pyd.rsp" if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% if exist "bin\msvc-8.0\debug\test.pyd.manifest" ( mt -nologo -manifest "bin\msvc-8.0\debug\test.pyd.manifest" "-outputresource:bin\msvc-8.0\debug\test.pyd;2" ) ...failed msvc.link.dll bin\msvc-8.0\debug\test.pyd bin\msvc-8.0\debug\test.lib... ...removing bin\msvc-8.0\debug\test.lib ...failed updating 2 targets... ...updated 1 target... ----------------------------------------------------------------------- I'm not really sure if this is the right place to post this request -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Boost---Bjam-error-%3A-LNK1120-tf4029473.html#a11445734 Sent from the Python - c++-sig mailing list archive at Nabble.com. From Lawrence.Spector at CanfieldSci.com Thu Jul 5 18:24:12 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 5 Jul 2007 12:24:12 -0400 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> References: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9741@Pan.domain-01> Sorry for the slow response to this. July 4th and all. Hope everyone had a good fourth of July. Anyway, I guess I'm stuck and I was wondering if someone might be able to supply or direct me to some working sample code. I'm sure I'm missing an important concept. As for providing more information, for one thing, the error was a boost::python::error_already_set. What I want to do is something like this: MyFile.cpp: ... CppClass cppClass; // somehow pass cppClass to Python // Something like: boost::python::object pyClass(cppClass); And from the python side (once pyClass is set): pyClass.callMethod(); What I'm having, when it tries to callMethod() is the exception occurs and seems to be a type exception. All works just fine if I create the object in Python first, e.g.: pyClass = CppClass() So, the problem is in how I'm trying to pass it to Python. Also, I appreciate your suggestions. I'm trying them now to see if they solve my issue, but I think my issue is probably of a more basic level. One other thing is I'm using bjam to build the python extensions, but the other exes and libraries are done strictly in Visual Studio 2005. Thanks in advance, Lawrence From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, July 03, 2007 2:54 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Passing a reference to my object to python On 7/3/07, Lawrence Spector > wrote: > So far, what I've done is build a Boost.Python extension for my python > script to use. It exposes one class for the script to use, let's say called > CppClass. This seems to work okay. I'm using Boost.Python and the Python > API to interpret the script from C++ code. During this process, I want to > pass a reference to an instance of the object that already exists in my C++ > code. I tried the following: > > boost::python::object myObject(CppClass); > > > When I run, I get a first chance exception: > boost::python::error_already_set. > > > > I'm sure I'm missing something important. Any idea what's going wrong? I will try to clarify, but I could be wrong. The default behavior of the object constructor is to copy the object. If you want it to keep reference to existing object, than you should use boost::ref or boost::python::ptr functionality. I also found another method to create object - using call policies: template< typename CallPolicies, class T > bpl::object make_object( T x ){ //constructs object using CallPolicies result_converter typedef BOOST_DEDUCED_TYPENAME CallPolicies::result_converter:: template apply< T >::type result_converter_t; result_converter_t rc; return bpl::object( bpl::handle<>( rc( x ) ) ); } You select call policy and it handles for you the conversion. The method doesn't work in all cases. It will not work if post_call function, of the call policies class does some job. It is not clear to me why you get exception. You should provide additional information. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Jul 5 18:33:27 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 5 Jul 2007 19:33:27 +0300 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F9741@Pan.domain-01> References: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9741@Pan.domain-01> Message-ID: <7465b6170707050933h5141e870j2797746342711f7e@mail.gmail.com> On 7/5/07, Lawrence Spector wrote: > > Anyway, I guess I'm stuck and I was wondering if someone might be able to supply or direct me to some working sample code. I'm sure I'm missing an important concept. Can you create small & complete example which reproduce the error, and attach the error? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From paul at mustagh.com Thu Jul 5 20:07:11 2007 From: paul at mustagh.com (Paul Guse) Date: Thu, 5 Jul 2007 12:07:11 -0600 Subject: [C++-sig] numeric array indexing Message-ID: <082001c7bf2f$504efb30$6901a8c0@paul> I'm looking for some advice on the most efficient way to index an n-dimensional numeric array. If say I have a std::vector that defines the index, what is the best technique to translate that to an index? I have been using a list and a tuple to do so, but with many iterations I believe I'm doing some unnecessary allocations. For a 1d array - > array[i], For a 2d array -> array [(make_tuple (i,j)] For a 3d array -> array [(make_tuple (list)] Any thoughts on how to be more efficient? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lawrence.Spector at CanfieldSci.com Thu Jul 5 20:18:44 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 5 Jul 2007 14:18:44 -0400 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: <7465b6170707050933h5141e870j2797746342711f7e@mail.gmail.com> References: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9741@Pan.domain-01> <7465b6170707050933h5141e870j2797746342711f7e@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F974E@Pan.domain-01> Ok, I went through and created an example. Here's what the code looks like, as of right now: PythonPassReference.cpp: #include #include "TestClass.hpp" #include "TestClassWrap.hpp" #include using namespace boost::python; int main() { try { Py_Initialize(); object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); TestClass testClass(std::cout, 3, 9.6f, 'Q'); { handle<> ignored((PyRun_String( "import PythonInterface" , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } TestClassWrap testClassWrapper(testClass); boost::python::object pyTestClass(testClassWrapper); // Works: pyTestClass.attr("output")(); { handle<> ignored((PyRun_String( // Works: "pyTestClass = PythonInterface.TestClass(6, 8.3, 'W')\n" "pyTestClass.output()\n" // Error unless the previous line is uncommented , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } } catch(boost::python::error_already_set& e) { std::cerr << "Caught error_already_set" << std::endl; if (PyErr_Occurred() != 0) { PyErr_Print(); } // end if } catch(...) { std::cerr << "Caught unknown error" << std::endl; } // end try-catch std::cin.get(); return 0; } // end main TestClass.hpp: #pragma once #include class TestClass { private: std::ostream& m_outStream; int m_x; float m_y; char m_z; public: TestClass(std::ostream& p_outStream, int p_x, float p_y, char p_z) : m_outStream(p_outStream), m_x(p_x), m_y(p_y), m_z(p_z) { } // end TestClass ~TestClass() { } // end TestClass void output() { m_outStream << "x = " << m_x << ", y = " << m_y << ", z = " << m_z << "\n"; } // end callMethod }; // end TestClass TestClassWrap.hpp: #pragma once #include "TestClass.hpp" class TestClassWrap { private: TestClass m_testClass; public: TestClassWrap(const TestClass& p_testClass) : m_testClass(p_testClass) { } // end TestClassWrap TestClassWrap(int p_x, float p_y, char p_z) : m_testClass(std::cout, p_x, p_y, p_z) { } // end TestClass ~TestClassWrap() { } // end TestClass void output() { m_testClass.output(); } // end callMethod }; // end TestClassWrap PythonInterface.cpp (Built with BJam, makes PythonInterface.pyd, PythonInterface.lib): #include #include #include #include "TestClass.hpp" #include "TestClassWrap.hpp" using namespace boost::python; BOOST_PYTHON_MODULE(PythonInterface) { class_("TestClass", init()) .def("output", &TestClassWrap::output) ; } // end module In doing so, one issue was illustrated. I was making a wrapper around the class in my interface code to expose to Python. However, when I put it into a boost::python::object, I used the unwrapped class, instead of the wrapped one. Once I started using the wrapped class in my example, the error I was talking about earlier went away, which is good! So I'm past that point. I ran into a second error, however. As you can see in the example above, I have an object which I wrap and then pass to python as follows: TestClassWrap testClassWrapper(testClass); boost::python::object pyTestClass(testClassWrapper); This works just fine, and I can call methods on the object. However, when I try to run it as a string (as it would be if read from a .py script file), I get an error. Here's the code for that: { handle<> ignored((PyRun_String( "pyTestClass.output()\n" // Error unless the previous line is uncommented , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } Which produces the following error: Caught error_already_set Traceback (most recent call last): File "", line 1, in NameError: name 'pyTestClass' is not defined So, I guess the question is, how do I expose an instance called pyTestClass, in such a way, that I can call methods on it from a script? I'm definitely further along now and I appreciate all the help. If I can get this piece, I think I'll be in good shape. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Thursday, July 05, 2007 12:33 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Passing a reference to my object to python On 7/5/07, Lawrence Spector wrote: > > Anyway, I guess I'm stuck and I was wondering if someone might be able to supply or direct me to some working sample code. I'm sure I'm missing an important concept. Can you create small & complete example which reproduce the error, and attach the error? -- 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 From Lawrence.Spector at CanfieldSci.com Thu Jul 5 22:03:31 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 5 Jul 2007 16:03:31 -0400 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F974E@Pan.domain-01> References: <7465b6170707031153h62c24383ge6fbbd8f03c45288@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9741@Pan.domain-01> <7465b6170707050933h5141e870j2797746342711f7e@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F974E@Pan.domain-01> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9757@Pan.domain-01> As a follow up to this, I'm still having no success in my actual program. I changed it to use the wrapper. I'm going to post a small portion of the code, in hopes it will clarify the situation. I cleaned up some confidental portions, but otherwise, the snippet should be enough to illustrate the issue. The wrapper: using namespace boost::python; struct PythonScriptDebuggerWrap : public PythonScriptMgr, public wrapper { bool default_CheckBreakpoint(const std::wstring& p_file, boost::uint32_t p_line) { return this->PythonScriptMgr::checkBreakpoint(p_file, p_line); } // end defaultCheckBreakpoint virtual bool checkBreakpoint(const std::wstring& p_file, boost::uint32_t p_line) { if (override f = this->get_override("checkBreakpoint")(p_file, p_line)) { return f(); } // end if return default_CheckBreakpoint(p_file, p_line); } virtual void setBreakpoint(const std::wstring& p_file, boost::uint32_t p_line) { return call(this->get_override("setBreakpoint")(p_file, p_line)); } virtual void clearBreakpoint(const std::wstring& p_file, boost::uint32_t p_line) { return call(this->get_override("clearBreakpoint")(p_file, p_line)); } }; The python interface: BOOST_PYTHON_MODULE(_PythonInterface) { class_("PyScriptDebugger", init<>()) .def("checkBreakpoint", &PythonScriptMgr::checkBreakpoint, &PythonScriptDebuggerWrap::default_CheckBreakpoint) ; } // end module Usage (where I get an error): // pass a reference to our object over to the current Python script handle<> ignored((PyRun_String( "import PythonInterface" , Py_file_input , m_mainNamespace.ptr() , m_mainNamespace.ptr()) )); // Throws the error_already_set exception, with: // TypeError: No to_python (by-value) converter found for C++ type: // struct PythonScriptDebuggerWrap boost::python::object pyScriptDebugger(static_cast(m_scriptMgr)); Any idea where I've gone wrong? Let me know. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Thursday, July 05, 2007 2:19 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Passing a reference to my object to python Ok, I went through and created an example. Here's what the code looks like, as of right now: PythonPassReference.cpp: #include #include "TestClass.hpp" #include "TestClassWrap.hpp" #include using namespace boost::python; int main() { try { Py_Initialize(); object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); TestClass testClass(std::cout, 3, 9.6f, 'Q'); { handle<> ignored((PyRun_String( "import PythonInterface" , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } TestClassWrap testClassWrapper(testClass); boost::python::object pyTestClass(testClassWrapper); // Works: pyTestClass.attr("output")(); { handle<> ignored((PyRun_String( // Works: "pyTestClass = PythonInterface.TestClass(6, 8.3, 'W')\n" "pyTestClass.output()\n" // Error unless the previous line is uncommented , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } } catch(boost::python::error_already_set& e) { std::cerr << "Caught error_already_set" << std::endl; if (PyErr_Occurred() != 0) { PyErr_Print(); } // end if } catch(...) { std::cerr << "Caught unknown error" << std::endl; } // end try-catch std::cin.get(); return 0; } // end main TestClass.hpp: #pragma once #include class TestClass { private: std::ostream& m_outStream; int m_x; float m_y; char m_z; public: TestClass(std::ostream& p_outStream, int p_x, float p_y, char p_z) : m_outStream(p_outStream), m_x(p_x), m_y(p_y), m_z(p_z) { } // end TestClass ~TestClass() { } // end TestClass void output() { m_outStream << "x = " << m_x << ", y = " << m_y << ", z = " << m_z << "\n"; } // end callMethod }; // end TestClass TestClassWrap.hpp: #pragma once #include "TestClass.hpp" class TestClassWrap { private: TestClass m_testClass; public: TestClassWrap(const TestClass& p_testClass) : m_testClass(p_testClass) { } // end TestClassWrap TestClassWrap(int p_x, float p_y, char p_z) : m_testClass(std::cout, p_x, p_y, p_z) { } // end TestClass ~TestClassWrap() { } // end TestClass void output() { m_testClass.output(); } // end callMethod }; // end TestClassWrap PythonInterface.cpp (Built with BJam, makes PythonInterface.pyd, PythonInterface.lib): #include #include #include #include "TestClass.hpp" #include "TestClassWrap.hpp" using namespace boost::python; BOOST_PYTHON_MODULE(PythonInterface) { class_("TestClass", init()) .def("output", &TestClassWrap::output) ; } // end module In doing so, one issue was illustrated. I was making a wrapper around the class in my interface code to expose to Python. However, when I put it into a boost::python::object, I used the unwrapped class, instead of the wrapped one. Once I started using the wrapped class in my example, the error I was talking about earlier went away, which is good! So I'm past that point. I ran into a second error, however. As you can see in the example above, I have an object which I wrap and then pass to python as follows: TestClassWrap testClassWrapper(testClass); boost::python::object pyTestClass(testClassWrapper); This works just fine, and I can call methods on the object. However, when I try to run it as a string (as it would be if read from a .py script file), I get an error. Here's the code for that: { handle<> ignored((PyRun_String( "pyTestClass.output()\n" // Error unless the previous line is uncommented , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } Which produces the following error: Caught error_already_set Traceback (most recent call last): File "", line 1, in NameError: name 'pyTestClass' is not defined So, I guess the question is, how do I expose an instance called pyTestClass, in such a way, that I can call methods on it from a script? I'm definitely further along now and I appreciate all the help. If I can get this piece, I think I'll be in good shape. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Thursday, July 05, 2007 12:33 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Passing a reference to my object to python On 7/5/07, Lawrence Spector wrote: > > Anyway, I guess I'm stuck and I was wondering if someone might be able to supply or direct me to some working sample code. I'm sure I'm missing an important concept. Can you create small & complete example which reproduce the error, and attach the error? -- 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 _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From j.reid at mail.cryst.bbk.ac.uk Fri Jul 6 09:40:28 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 06 Jul 2007 08:40:28 +0100 Subject: [C++-sig] numeric array indexing In-Reply-To: <082001c7bf2f$504efb30$6901a8c0@paul> References: <082001c7bf2f$504efb30$6901a8c0@paul> Message-ID: Paul Guse wrote: > I'm looking for some advice on the most efficient way to index an > n-dimensional numeric array. > If say I have a std::vector that defines the index, what is the > best technique to translate that to an index? I have been using a list > and a tuple to do so, but with many iterations I believe I'm doing some > unnecessary allocations. > For a 1d array - > array[i], > For a 2d array -> array [(make_tuple (i,j)] > For a 3d array -> array [(make_tuple (list)] > > Any thoughts on how to be more efficient? I don't know about numeric but I think numpy lets you use any iterable as an index - you could export shared_ptr> and use that instead of a tuple. That would be one allocation overall then. From j.reid at mail.cryst.bbk.ac.uk Fri Jul 6 10:29:12 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 06 Jul 2007 09:29:12 +0100 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: References: Message-ID: Lawrence Spector wrote: > When I run, I get a first chance exception: > boost::python::error_already_set. When I run boost.python extensions in the msvc debugger I frequently get these exceptions thrown. They appear to be handled internally and this seems to me to be normal operation for boost.python. Are you saying that your exceptions aren't handled by boost.python and are propagated up into the python shell? John. From Lawrence.Spector at CanfieldSci.com Fri Jul 6 15:32:21 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Fri, 6 Jul 2007 09:32:21 -0400 Subject: [C++-sig] Passing a reference to my object to python In-Reply-To: References: Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9767@Pan.domain-01> Yes, that's what I'm saying. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of John Reid Sent: Friday, July 06, 2007 4:29 AM To: c++-sig at python.org Subject: Re: [C++-sig] Passing a reference to my object to python Lawrence Spector wrote: > When I run, I get a first chance exception: > boost::python::error_already_set. When I run boost.python extensions in the msvc debugger I frequently get these exceptions thrown. They appear to be handled internally and this seems to me to be normal operation for boost.python. Are you saying that your exceptions aren't handled by boost.python and are propagated up into the python shell? John. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From srossross at gmail.com Fri Jul 6 23:07:57 2007 From: srossross at gmail.com (Sean Ross-Ross) Date: Fri, 6 Jul 2007 14:07:57 -0700 Subject: [C++-sig] Vector array_struct Message-ID: <2E99AE86-C87A-4D72-A95E-B08821438832@gmail.com> Has anyone written a numpy array_struct for the c++ vector class ? ~Sean From zreed1 at gmail.com Sat Jul 7 22:28:36 2007 From: zreed1 at gmail.com (a_python_coder) Date: Sat, 7 Jul 2007 13:28:36 -0700 (PDT) Subject: [C++-sig] weak_ptr/shared_from_this and boost.python Message-ID: <11481937.post@talk.nabble.com> Ive been having a devil of a time trying to get boost python to do the right thing when I try to manipulate C++ objects with weak pointers. Ive narrowed the issue down to a short test case below. Anyone have any ideas? /* *************************************************** */ #include #include #include using namespace std; using namespace boost; using namespace python; struct XYZ : public enable_shared_from_this { static shared_ptr construct() { s_instance = new XYZ; shared_ptr xyz( s_instance ); // return a shared_ptr that manages the python object return extract< shared_ptr >( object(xyz) ); } static shared_ptr get() { return shared_ptr( s_instance->shared_from_this() ); } static XYZ* s_instance; }; XYZ* XYZ::s_instance = 0; BOOST_PYTHON_MODULE( test ) { class_< XYZ , shared_ptr , noncopyable >( "XYZ", no_init ) ; def( "construct", &XYZ::construct ); def( "get", &XYZ::get ); } /* *************************************************** */ n [1]: import test In [2]: x = test.construct() In [3]: x Out[3]: In [4]: y = test.get() --------------------------------------------------------------------------- exceptions.RuntimeError Traceback (most recent call last) /home/ym/tmp/ RuntimeError: tr1::bad_weak_ptr -- View this message in context: http://www.nabble.com/weak_ptr-shared_from_this-and-boost.python-tf4041746.html#a11481937 Sent from the Python - c++-sig mailing list archive at Nabble.com. From ngoodspeed at solidworks.com Sun Jul 8 18:50:47 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Sun, 8 Jul 2007 12:50:47 -0400 Subject: [C++-sig] weak_ptr/shared_from_this and boost.python In-Reply-To: <11481937.post@talk.nabble.com> References: <11481937.post@talk.nabble.com> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B7017454FA@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of a_python_coder > Sent: Saturday, July 07, 2007 4:29 PM > To: c++-sig at python.org > Subject: [C++-sig] weak_ptr/shared_from_this and boost.python > > > Ive been having a devil of a time trying to get boost python to do the > right thing when I try to manipulate C++ objects with weak pointers. [Nat] Maybe I'm missing something, but where in the short test case do you mention weak pointers? > /* *************************************************** */ > #include > #include > #include > > using namespace std; > using namespace boost; > using namespace python; > > struct XYZ > : public enable_shared_from_this > { > > static shared_ptr construct() > { > s_instance = new XYZ; > shared_ptr xyz( s_instance ); > // return a shared_ptr that manages the python object > return extract< shared_ptr >( object(xyz) ); [Nat] I'm floored by the three lines above, especially that last line. This feels like a modified singleton pattern. What do you want the lifespan of the managed XYZ object to be? If you want it to persist for the remainder of the program, why use shared_ptr? If you want it to vanish when the last outstanding reference has been dropped, why make it resemble a singleton? If you're using shared_ptr for some reason other than lifespan management, it might be simpler to declare s_instance as a shared_ptr and simply set and return s_instance. But even if you want to retain the XYZ* s_instance, why wouldn't you code construct() to set s_instance and then return get()? Why does the first case behave so very differently from every other case? > } > > static shared_ptr get() > { > return shared_ptr( s_instance->shared_from_this() ); > } > > static XYZ* s_instance; > > }; > > XYZ* XYZ::s_instance = 0; > > > BOOST_PYTHON_MODULE( test ) > { > class_< > XYZ > , shared_ptr > , noncopyable > >( "XYZ", no_init ) > ; > > def( "construct", &XYZ::construct ); > def( "get", &XYZ::get ); > > } From zreed1 at gmail.com Sun Jul 8 20:09:21 2007 From: zreed1 at gmail.com (a_python_coder) Date: Sun, 8 Jul 2007 11:09:21 -0700 (PDT) Subject: [C++-sig] weak_ptr/shared_from_this and boost.python In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B7017454FA@corp-mail4.solidworks.swk> References: <11481937.post@talk.nabble.com> <94F7A8DD4408D8499C6812FE42E2D4B7017454FA@corp-mail4.solidworks.swk> Message-ID: <11491133.post@talk.nabble.com> >> Ive been having a devil of a time trying to get boost python to do the >> right thing when I try to manipulate C++ objects with weak pointers. >[Nat] Maybe I'm missing something, but where in the short test case do >you mention weak pointers? the enable_shared_from_this template embeds a weak_ptr into XYZ, sorry if that wasnt clear. http://boost.org/libs/smart_ptr/enable_shared_from_this.html >> /* *************************************************** */ >> #include >> #include >> #include >> >> using namespace std; >> using namespace boost; >> using namespace python; >> >> struct XYZ >> : public enable_shared_from_this >> { >> >> static shared_ptr construct() >> { >> s_instance = new XYZ; >> shared_ptr xyz( s_instance ); >> // return a shared_ptr that manages the python object >> return extract< shared_ptr >( object(xyz) ); > >[Nat] I'm floored by the three lines above, especially that last line. a little hackish, i agree. however, since bp does some magic with shared_ptr deleters, the shared_ptr extracted in the the last line is not in general the same as the one created in the line previous. c++ objects instantiated by bp get passed to c++ with the correct deleter set, but in this project objects are instantiated by an abstract factory in c++ and manipulated in python. > >This feels like a modified singleton pattern. What do you want the >lifespan of the managed XYZ object to be? If you want it to persist for >the remainder of the program, why use shared_ptr? If you want it to >vanish when the last outstanding reference has been dropped, why make it >resemble a singleton? in this case im just using s_instance as a place to stick a known-good instance pointer. the "real" code is a complicated subject-observer tree where destruction of an observer causes deregistration from the subject. the problem occurs when it comes time to iterate over elements of the tree - in returning an element to python, it is necessary to pin the embedded weak_ptr. what i see then is a use count of 0, a positive weak count, and an object has not been destroyed. i believe that bp is still creating a new shared_ptr count somewhere even though that shouldnt be necessary (from what i understand) after the way we constructed our initial shared_ptr. >But even if you want to retain the XYZ* s_instance, why wouldn't you >code construct() to set s_instance and then return get()? Why does the >first case behave so very differently from every other case? essentially thats whats happening. except that what we are really initializing is not s_instance, but the embedded weak_ptr. as a side effect of the gymnastics in construct, shared_from_this should return the _python_ weak_ptr thanks zac -- View this message in context: http://www.nabble.com/weak_ptr-shared_from_this-and-boost.python-tf4041746.html#a11491133 Sent from the Python - c++-sig mailing list archive at Nabble.com. From p.jaroszynski at gmail.com Mon Jul 9 02:58:42 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Mon, 9 Jul 2007 02:58:42 +0200 Subject: [C++-sig] docstring in enum In-Reply-To: <200706272121.10588.p.jaroszynski@gmail.com> References: <200706252300.49268.p.jaroszynski@gmail.com> <4682B106.4080405@sympatico.ca> <200706272121.10588.p.jaroszynski@gmail.com> Message-ID: <200707090258.44139.p.jaroszynski@gmail.com> FWIW I have finally found a way to do it: http://www.piotrj.org/index.php?/archives/9-Boost.Python-docstrings-in-enums.html -- Best Regards, Piotr Jaroszy?ski From ngoodspeed at solidworks.com Mon Jul 9 18:38:00 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 12:38:00 -0400 Subject: [C++-sig] weak_ptr/shared_from_this and boost.python In-Reply-To: <11491133.post@talk.nabble.com> References: <11481937.post@talk.nabble.com><94F7A8DD4408D8499C6812FE42E2D4B7017454FA@corp-mail4.solidworks.swk> <11491133.post@talk.nabble.com> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B701745647@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of a_python_coder > Sent: Sunday, July 08, 2007 2:09 PM > To: c++-sig at python.org > Subject: Re: [C++-sig] weak_ptr/shared_from_this and boost.python > > the enable_shared_from_this template embeds a weak_ptr into XYZ, sorry if > that > wasnt clear. http://boost.org/libs/smart_ptr/enable_shared_from_this.html [Nat] Heh, I should probably know that. > the "real" code is a complicated subject-observer tree where > destruction > of an observer causes deregistration from the subject. [Nat] Sorry if the following seems totally off track. You're asking for details of the Boost.Python treatment of shared_ptr and weak_ptr, and frankly I don't know them. But -- forgive me -- from my point of view, if the robustness of your app depends on the difference between return shared_ptr(new XYZ) and return extract< shared_ptr >( object(shared_ptr(new XYZ)) ); then something seems a little wonky. I guess my approach would be to try to avoid the necessity altogether. From Lawrence.Spector at CanfieldSci.com Mon Jul 9 21:05:12 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 9 Jul 2007 15:05:12 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01> When I do something like this: boost::python::object pyClass(MyInstance); What name does it give it? It doesn't appear it to give it pyClass as the name, but it has to pick something to identify itself for the Python-C API. So, what's the name and how do I find out what it is? Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes at zellner.org Mon Jul 9 21:35:59 2007 From: johannes at zellner.org (Dr. Johannes Zellner) Date: Mon, 9 Jul 2007 21:35:59 +0200 Subject: [C++-sig] python file object and std::istream / std::ifstream Message-ID: <103840bf0707091235w14a79ad7y3d5d79a075ae33e0@mail.gmail.com> Hi, I'd like to make a c++ method void read(std::istream& in) { } available for in python so that I can pass python file objects. How would I do that? -- Dr. Johannes Zellner From jeff.webb at nta-inc.net Mon Jul 9 22:07:17 2007 From: jeff.webb at nta-inc.net (Jeff Webb) Date: Mon, 09 Jul 2007 15:07:17 -0500 Subject: [C++-sig] custom constructor with embedded back reference In-Reply-To: <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> References: <46783D75.4050600@nta-inc.net> <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> Message-ID: <46929575.4060002@nta-inc.net> I am wrapping a C++ class using boost python. If a class instance is wrapped using boost python, I want to embed a pointer to the python wrapper object into the C++ object. The 'has_back_reference<>' template allows me to do this if I modify the C++ class constructor. I would like to avoid modifying the C++ class at all. I don't want the C++ class to know anything about python. Assume I am wrapping the following class: #include using namespace std; class S { public: S() { cout << "S" << endl; } virtual ~S() { cout << "~S" << endl; } void hello() { cout << "hello: " << ptr << endl; } void * ptr; }; I have come up with a method for embedding the back reference without modifying the constructor. This is done by creating two extra functions: one for creating an object instance ("__cons__"), and one for embedding the back reference ("__init__"). In my application, I use intrusive_ptr, but the following example uses shared_ptr for simplicity. #include #include using namespace boost; using namespace boost::python; shared_ptr new_S() { return shared_ptr(new S); } object init_S(object pyobject) { // Construct S object call_method(pyobject.ptr(), "__cons__"); // Initialize embedded pyobject pointer in S object S * s = extract(pyobject); s->ptr = pyobject.ptr(); // Return None return object(); } BOOST_PYTHON_MODULE(slib1) { class_, boost::noncopyable>("S", no_init) .def("__init__", init_S) .def("__cons__", make_constructor(new_S)) .def("hello", &S::hello) ; } This seems to work, but I would rather only define one extra function for each of my classes. It seems like this could all be done in the __init__ function, but the syntax for initializing the 'object' passed to __init__ is not obvious, so I resorted to defining an extra function using make_constructor. This eventually lead me to the following approach, which uses a few lines that I found in make_constructor.hpp: // Code taken from make_constructor.hpp object init_S(object pyobject) { // Construct S object shared_ptr s_ptr(new S); // Insert new S object pointer into python object typedef objects::pointer_holder,S> holder; typedef objects::instance instance_t; void* memory = holder::allocate(pyobject.ptr(), offsetof(instance_t, storage), sizeof(holder)); try { (new (memory) holder(s_ptr))->install(pyobject.ptr()); } catch(...) { holder::deallocate(pyobject.ptr(), memory); throw; } // Initialize embedded pyobject pointer in S object s_ptr->ptr = pyobject.ptr(); // Return None return object(); } BOOST_PYTHON_MODULE(slib2) { class_, boost::noncopyable>("S", no_init) .def("__init__", init_S) .def("hello", &S::hello) ; } This seems to work (so far, at least), but I want to make sure I'm not creating a memory leak, or doing something else wrong. Is this legit? Or is there a better way to define a constructor function that has access to the PyObject? Thanks, Jeff From ngoodspeed at solidworks.com Mon Jul 9 22:36:52 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 16:36:52 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Monday, July 09, 2007 3:05 PM To: c++-sig at python.org Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? When I do something like this: boost::python::object pyClass(MyInstance); What name does it give it?? It doesn't appear it to give it pyClass as the name, but it has to pick something to identify itself for the Python-C API.? So, what's the name and how do I find out what it is? [Nat] Should it have a name? If I write in a Python script: class MyInstance(object): pass foo = MyInstance() the object instantiated by the MyInstance() call does not have an embedded name. The script's locals dict acquires an entry mapping "foo" to that new instance, but the name "foo" belongs to the dict rather than to the object. Maybe I don't understand your question. From ngoodspeed at solidworks.com Mon Jul 9 22:48:28 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 16:48:28 -0400 Subject: [C++-sig] python file object and std::istream / std::ifstream In-Reply-To: <103840bf0707091235w14a79ad7y3d5d79a075ae33e0@mail.gmail.com> References: <103840bf0707091235w14a79ad7y3d5d79a075ae33e0@mail.gmail.com> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B701745761@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Dr. Johannes Zellner > Sent: Monday, July 09, 2007 3:36 PM > To: c++-sig at python.org > Subject: [C++-sig] python file object and std::istream / std::ifstream > > I'd like to make a c++ method > > void read(std::istream& in) > { > } > > available for in python so that I can pass python file objects. [Nat] It sounds as though you want Python code to be able to manipulate C++ stream objects. Is that correct? One approach would be to create a wrapper class containing an instance of a stream object. Open the embedded stream object in the wrapper-class constructor. Manage the lifespan of your wrapper-class objects using shared_ptr, and tell Boost.Python about it. Decide what operations you want Python to be able to perform on the underlying stream object, and publish appropriate methods. If you need to be able to reference (e.g.) std::cout and friends using the same machinery, you could instead make the wrapper class capture a pointer/reference to an independent stream object -- but if you go that way, you'll have to explicitly manage the relative lifespans of the wrapper object and the stream object. From Lawrence.Spector at CanfieldSci.com Mon Jul 9 22:51:12 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 9 Jul 2007 16:51:12 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01> In your example, it should have a name of foo, which you can call methods on. The problem I'm having is I want to be able to create the object using the boost::python wrappers around the Python-C API, but access it from a script. So, this works: foo = MyClass() foo.callMethod() However, when I do this in C++: object foo(MyClass()); object result = exec("foo.callMethod()", main_namespace, main_namespace); This fails on the second line, with: NameError: name 'foo' is not defined. I guess, the first question would be is: "object foo(MyClass())" the equivalent to foo = MyClass()? If so, how do I make foo the name that is in the dict. If not, how do I write the equivalent of foo = MyClass() using Boost.Python? Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nat Goodspeed Sent: Monday, July 09, 2007 4:37 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Monday, July 09, 2007 3:05 PM To: c++-sig at python.org Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? When I do something like this: boost::python::object pyClass(MyInstance); What name does it give it? It doesn't appear it to give it pyClass as the name, but it has to pick something to identify itself for the Python-C API. So, what's the name and how do I find out what it is? [Nat] Should it have a name? If I write in a Python script: class MyInstance(object): pass foo = MyInstance() the object instantiated by the MyInstance() call does not have an embedded name. The script's locals dict acquires an entry mapping "foo" to that new instance, but the name "foo" belongs to the dict rather than to the object. Maybe I don't understand your question. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From ngoodspeed at solidworks.com Mon Jul 9 23:05:53 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 17:05:53 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 4:51 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > In your example, it should have a name of foo, which you can call methods > on. > > The problem I'm having is I want to be able to create the object using the > boost::python wrappers around the Python-C API, but access it from a > script. > > So, this works: > > foo = MyClass() > foo.callMethod() > > However, when I do this in C++: > > object foo(MyClass()); > object result = exec("foo.callMethod()", main_namespace, main_namespace); > > This fails on the second line, with: > NameError: name 'foo' is not defined. [Nat] That's what I would expect, yes. Your "object foo(...)" C++ declaration creates a memory location whose name 'foo' is known to the C++ compiler at compile time -- but that name vanishes from the program before it begins execution. It does not create a dict entry "foo" with which the Python interpreter can look up your new instance. > I guess, the first question would be is: "object foo(MyClass())" the > equivalent to foo = MyClass()? If so, how do I make foo the name that is > in the dict. If not, how do I write the equivalent of foo = MyClass() > using Boost.Python? [Nat] Assuming that main_namespace is a boost::python::dict, you should be able to write: object foo(MyClass()); // s.b. 'object(new MyClass())'? haven't tested main_namespace["foo"] = foo; object result = exec("foo.callMethod()", main_namespace, main_namespace); Unless you need subsequent C++ references to the new MyClass object, of course you could abbreviate the above to something like: main_namespace["foo"] = object(MyClass()); // 'object(new MyClass())' ? object result = exec("foo.callMethod()", main_namespace, main_namespace); From Lawrence.Spector at CanfieldSci.com Mon Jul 9 23:15:49 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 9 Jul 2007 17:15:49 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01> Ah ha. Now I see. I quickly tried it and yes, that solved my first issue. Thanks! Now moving on, is there a way to add it to the dict without making a copy, but instead having foo be a reference to the instance of MyClass()? Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nat Goodspeed Sent: Monday, July 09, 2007 5:06 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 4:51 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > In your example, it should have a name of foo, which you can call methods > on. > > The problem I'm having is I want to be able to create the object using the > boost::python wrappers around the Python-C API, but access it from a > script. > > So, this works: > > foo = MyClass() > foo.callMethod() > > However, when I do this in C++: > > object foo(MyClass()); > object result = exec("foo.callMethod()", main_namespace, main_namespace); > > This fails on the second line, with: > NameError: name 'foo' is not defined. [Nat] That's what I would expect, yes. Your "object foo(...)" C++ declaration creates a memory location whose name 'foo' is known to the C++ compiler at compile time -- but that name vanishes from the program before it begins execution. It does not create a dict entry "foo" with which the Python interpreter can look up your new instance. > I guess, the first question would be is: "object foo(MyClass())" the > equivalent to foo = MyClass()? If so, how do I make foo the name that is > in the dict. If not, how do I write the equivalent of foo = MyClass() > using Boost.Python? [Nat] Assuming that main_namespace is a boost::python::dict, you should be able to write: object foo(MyClass()); // s.b. 'object(new MyClass())'? haven't tested main_namespace["foo"] = foo; object result = exec("foo.callMethod()", main_namespace, main_namespace); Unless you need subsequent C++ references to the new MyClass object, of course you could abbreviate the above to something like: main_namespace["foo"] = object(MyClass()); // 'object(new MyClass())' ? object result = exec("foo.callMethod()", main_namespace, main_namespace); _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From ngoodspeed at solidworks.com Mon Jul 9 23:24:09 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 17:24:09 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 5:16 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > is there a way to add it to the dict without making a copy, > but instead having foo be a reference to the instance of MyClass()? [Nat] boost::python::object is a C++ wrapper around a classic-C Python reference pointer. Once you've instantiated a Python-compatible object and captured its reference pointer using boost::python::object, I would expect you to be able to copy the boost::python::object as needed (e.g. into a dict) with every copy of the boost::python::object value referencing the same MyClass instance. If that's not what you're seeing, maybe a complete, minimal code example would help. From Lawrence.Spector at CanfieldSci.com Mon Jul 9 23:34:36 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 9 Jul 2007 17:34:36 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01> Putting a breakpoint in my class, I get the 'this' inside of the instance when it's created is 0x0012ff20, but when the callMethod() is called, the 'this' is 0x00987fc8, so it appears to be a different instance. Any idea why? Does the constructor of boost::python::object make a copy? Thanks, Lawrence -----Original Message----- From: c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org [mailto:c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org] On Behalf Of Nat Goodspeed Sent: Monday, July 09, 2007 5:24 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 5:16 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > is there a way to add it to the dict without making a copy, > but instead having foo be a reference to the instance of MyClass()? [Nat] boost::python::object is a C++ wrapper around a classic-C Python reference pointer. Once you've instantiated a Python-compatible object and captured its reference pointer using boost::python::object, I would expect you to be able to copy the boost::python::object as needed (e.g. into a dict) with every copy of the boost::python::object value referencing the same MyClass instance. If that's not what you're seeing, maybe a complete, minimal code example would help. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From ngoodspeed at solidworks.com Tue Jul 10 02:42:15 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 9 Jul 2007 20:42:15 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 5:35 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > Putting a breakpoint in my class, I get the 'this' inside of the instance > when it's created is 0x0012ff20, but when the callMethod() is called, the > 'this' is 0x00987fc8, so it appears to be a different instance. > > Any idea why? Does the constructor of boost::python::object make a copy? [Nat] Can you reproduce this with a tiny C++ program and a tiny Python script? From j.reid at mail.cryst.bbk.ac.uk Tue Jul 10 14:48:43 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 10 Jul 2007 13:48:43 +0100 Subject: [C++-sig] Pickling with Raoul Gough's container suite Message-ID: Has anyone implemented this? I can only find a reference to it here: http://mail.python.org/pipermail/c++-sig/2003-October/006034.html John. From j.reid at mail.cryst.bbk.ac.uk Tue Jul 10 17:21:48 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 10 Jul 2007 16:21:48 +0100 Subject: [C++-sig] Pickling with Raoul Gough's container suite In-Reply-To: References: Message-ID: Ok so this seems to work for me: template< typename Container > struct vector_pickle_suite : boost::python::pickle_suite { typedef typename Container::value_type value_type; static boost::python::tuple getstate(const Container & c) { return boost::python::tuple( c ); } static void setstate(Container & c, boost::python::tuple state) { const unsigned l = boost::python::len(state); c.resize(l); for( unsigned i = 0; l != i; ++i ) { value_type el = boost::python::extract< value_type >( state[i] ); c[i] = el; } } }; and then def like so: class_< double_vec >( "DoubleVec" ) .def( container_suite< double_vec >() ) .def_pickle( vector_pickle_suite< double_vec >() ) ; I'm sure there are better ways. Any pointers welcome. John. John Reid wrote: > Has anyone implemented this? I can only find a reference to it here: > > http://mail.python.org/pipermail/c++-sig/2003-October/006034.html > > John. From David.A.Wagner at jpl.nasa.gov Tue Jul 10 20:56:16 2007 From: David.A.Wagner at jpl.nasa.gov (David A Wagner) Date: Tue, 10 Jul 2007 11:56:16 -0700 Subject: [C++-sig] boost-python callbacks and GIL lock Message-ID: <4693D650.7010401@jpl.nasa.gov> I'm building an interface between python and a middleware system (DDS) with a C++ API where I want to be able to use event threads in the middleware framework to drive callback events in python. I.e., the python app can register a callback handler object with the API to be notified when messages arrive on a middleware topic. Using boost-python I was able to get this to work with only a few hitches, which I'd like to ask about. First, let me say that boost-python was a HUGE time saver here. Thanks a ton to those who developed it! Basically, I defined a callback interface class in C++ with a virtual callback method: class UpdateHandler { virtual void update(Message&); } where Message is my C++ message data class. I used the boost-python wrappers to export these classes to Python. E.g.,: class_("UpdateHandler") .def("update", pure_virtual(&UpdateHandler::update)) ; with the special callback wrapper function struct UpdateHandlerWrapper : UpdateHandler, boost::python::wrapper { void update(const Message& val) { // Call the virtual function in python this->get_override("update")(val); }} This all worked great as long as I was using test code that triggered the callback from within python. When we tried to use the actual external threads to pump the events, the program crashed. I didn't see anything about this in the boost-python documentation, but I think the problem had to do with thread re-entrance in python. Specifically, since these event threads originate outside of python and its thread management context, extra code is needed in these callback wrappers to acquire python's Global Interpreter Lock (GIL) in order to enter python's interpreter context in a thread-safe manner: PyGILState_STATE gstate = PyGILState_Ensure(); // Call the virtual function in python this->get_override("update")(val); PyGILState_Release(gstate); That seemed to do the trick, but I'd like to get some verification that this was the appropriate thing to do here. Is this right? It also makes sense that a call originating from python would already have this context, but some foreign thread would not. Thanks From duranlef at iro.umontreal.ca Tue Jul 10 21:07:55 2007 From: duranlef at iro.umontreal.ca (=?ISO-8859-1?Q?Fran=E7ois_Duranleau?=) Date: Tue, 10 Jul 2007 15:07:55 -0400 (EDT) Subject: [C++-sig] python file object and std::istream / std::ifstream In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B701745761@corp-mail4.solidworks.swk> References: <103840bf0707091235w14a79ad7y3d5d79a075ae33e0@mail.gmail.com> <94F7A8DD4408D8499C6812FE42E2D4B701745761@corp-mail4.solidworks.swk> Message-ID: On Mon, 9 Jul 2007, Nat Goodspeed wrote: >> -----Original Message----- >> From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] >> On Behalf Of Dr. Johannes Zellner >> >> I'd like to make a c++ method >> >> void read(std::istream& in) >> { >> } >> >> available for in python so that I can pass python file objects. > > [Nat] It sounds as though you want Python code to be able to manipulate > C++ stream objects. Is that correct? [snip] As I understand, it's more like the opposite: the OP wants to manipulate Python file objects on the C++ side with a istream interface. In that case, I would create a source device class (Source concept from Boost.Iostreams) wrapping calls to PyFile_*, and then wrap the func like this: void read_wrap( boost::python::object in_file ) { boost::iostreams::stream< pyfile_device_wrapper > in( pyfile_device_wrapper( in_file ) ) ; read( in ) ; } You can read the documentation on Python file objects and Boost.Iostreams to write the pyfile_device_wrapper. It should fairly simple. -- Fran??ois Duranleau LIGUM, Universit?? de Montr??al From Lawrence.Spector at CanfieldSci.com Tue Jul 10 22:33:04 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 10 Jul 2007 16:33:04 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F981A@Pan.domain-01> Sorry for the late response. I wasn't sure if I could post attachments to the group or not. So, I uploaded it. Here's the link: http://www.slashgames.com/storage/PythonPassReference.zip It's a very minimal example (just a few source and header files) along with a few supplementary files, a project and a solution. I illustrate the issue by printing the 'this' pointer at different sections. Note that the memory locations are different depending on how I call it. Hopefully it makes sense. -Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nat Goodspeed Sent: Monday, July 09, 2007 8:42 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Monday, July 09, 2007 5:35 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > Putting a breakpoint in my class, I get the 'this' inside of the instance > when it's created is 0x0012ff20, but when the callMethod() is called, the > 'this' is 0x00987fc8, so it appears to be a different instance. > > Any idea why? Does the constructor of boost::python::object make a copy? [Nat] Can you reproduce this with a tiny C++ program and a tiny Python script? _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From fullung at gmail.com Wed Jul 11 00:50:15 2007 From: fullung at gmail.com (Albert Strasheim) Date: Wed, 11 Jul 2007 00:50:15 +0200 Subject: [C++-sig] boost-python callbacks and GIL lock References: <4693D650.7010401@jpl.nasa.gov> Message-ID: <004901c7c344$ae77aea0$a885e892@sun.ac.za> Hello I'm no Python threading expert, but I've wrapped similar code to what you describe. You can see the result here: http://pyactivemq.googlecode.com/svn/trunk/src/main/MessageListener.cpp I also found it necessary to call PyEval_InitThreads() in my module's initialization code: http://pyactivemq.googlecode.com/svn/trunk/src/main/pyactivemq.cpp Without this call, the PyGILState_Ensure() seemed to be a no-op. From what I understood from the documentation, PyGILState_Ensure() ensures that your thread gets all the necessary bits to call into Python, even if it is a new native thread. I found the following documentation useful: http://www.python.org/dev/peps/pep-0311/ http://docs.python.org/api/threads.html Hope this helped. :-) Cheers, Albert ----- Original Message ----- From: "David A Wagner" To: Sent: Tuesday, July 10, 2007 8:56 PM Subject: [C++-sig] boost-python callbacks and GIL lock > I'm building an interface between python and a middleware system (DDS) > with a C++ API where I want to > be able to use event threads in the middleware framework to drive > callback events in python. I.e., the python > app can register a callback handler object with the API to be notified > when messages arrive on a middleware > topic. Using boost-python I was able to get this to work with only a > few hitches, which I'd like to ask about. From Lawrence.Spector at CanfieldSci.com Wed Jul 11 21:01:18 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 11 Jul 2007 15:01:18 -0400 Subject: [C++-sig] Py++ - Can't Seem To Get It Working Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> First I tried the Py++ download from sourceforce, along with pygccxml, using "python setup.py install" and a pre-build distribution of gccxml from the website. So, I run pyplusplus_gui.pyw (C:\python25\python C:\python25\Scripts\pyplusplus_gui.pyw). I make a file called TestPy++.h in C:\Temp, direct Py++ to it, and direct Py++ to the gccxml_cc1plus.exe file inside of the GCCXML distribution from Py++ website. TestPy++.h contains: #ifndef TESTPYPLUSPLUS_H #define TESTPYPLUSPLUS_H enum Val { VAL_1, VAL_2, VAL_3 }; #endif I get the following output: Error occured during code generation process! Error: Error occured while running GCC-XML: Execution times (seconds) parser : 0.02 (100%) usr TOTAL : 0.02 ... My first thought is wonderful, no information. I saw one site advocating using Cygwin to do this and rebuilding GCCXML. So, I get on CVS, download the latest from gccxml.org, using the commands as suggested: cvs -d :pserver:anoncvs at www.gccxml.org:/cvsroot/GCC_XML login (just press enter when prompted for a password) Follow this command by checking out the source code: cvs -d :pserver:anoncvs at www.gccxml.org:/cvsroot/GCC_XML co gccxml Great. I have my distribution of gccxml. I build with cmake as per the instructions. I make and make install. Wonderful. I install Py++0.9.0 and pygccxml-0.9.0 under Cygwin. Great. All is looking good so far. As per a small snippet I found online, I found out I have to rebaseall. I rebase, great. Now, I get to running pyplusplus_gui.pyw (/usr/bin/python /usr/bin/pyplusplus_gui.pyw&). I set my file path to: /cygdrive/c/Temp/TestPy++.h (cygwin paths appear to be required). I set my GCC_XML location to /home/LSpector/GCC_XML/bin/gccxml.exe. I click generate code. The Py++ gui/GCCXML/something hangs, never to recover. For the hell of it, I try /home/LSpector/GCC_XML/bin/gccxml_cc1plus.exe instead of gccxml.exe. Why not? I get the following: Error occured during code generation process! Error: Error occured while running GCC-XML: Execution times (seconds) parser : 0.02 (48%) usr 0.00 ( 0%) sys 0.02 (33%) wall name lookup : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.02 (33%) wall TOTAL : 0.03 0.00 0.05 Not good. I can't seem to get this tool working. Can anyone help me? I'm very stuck. Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Jul 11 22:07:37 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 11 Jul 2007 23:07:37 +0300 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> Message-ID: <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> On 7/11/07, Lawrence Spector wrote: > First I tried the Py++ download from sourceforce, along with pygccxml, using > "python setup.py install" and a pre-build distribution of gccxml from the > website. So, I run pyplusplus_gui.pyw (C:\python25\python > C:\python25\Scripts\pyplusplus_gui.pyw). > > I make a file called TestPy++.h in C:\Temp, direct Py++ to it, and direct > Py++ to the gccxml_cc1plus.exe file inside of the GCCXML distribution from > Py++ website. You are supposed to direct Py++ to gccxml.exe > > > TestPy++.h contains: > ... > > > I get the following output: > > > Error occured during code generation process! > > Error: > Error occured while running GCC-XML: > Execution times (seconds) > parser : 0.02 (100%) usr > TOTAL : 0.02 > This just proves that you run the wrong executable :-( > > > > My first thought is wonderful, no information. I saw one site advocating > using Cygwin to do this and rebuilding GCCXML. I never tried this. > I set my file path to: /cygdrive/c/Temp/TestPy++.h (cygwin paths appear to > be required). > > I set my GCC_XML location to > /home/LSpector/GCC_XML/bin/gccxml.exe. > > > > I click generate code. The Py++ gui/GCCXML/something hangs, never to > recover. I am not aware of this bug. I'll be glad if you will help me to fix it. > For the hell of it, I try > /home/LSpector/GCC_XML/bin/gccxml_cc1plus.exe instead of > gccxml.exe. Why not? No, you was supposed to use gccxml.exe > > Not good. I can't seem to get this tool working. Can anyone help me? I'm > very stuck. I try. Just point Py++ GUI to gccxml.exe and try again. It should work. If not I am going to be online for some time, so ... -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Wed Jul 11 22:20:07 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 11 Jul 2007 16:20:07 -0400 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> gccxml.exe didn't show up from what I installed yesterday. I downloaded version 0.60 (which is old, I know) and got things working (sorta). I'm going to play around with the gccxml_windows_installer from the Py++ website and see if I can figure out why it wasn't successfully building gccxml.exe. Anyway, with my current configuration, I generated Py++ code, but I'm having compilation problems now. First, I get compile errors for certain things from Windows. Secondly, I had a boost header in there and during the compile I got an error saying the following: #error "Compile threading support is not turned on. Please set the current command line options for threading: either /MT /MTd /MD or /MDd. As for the cygwin issue, I'll try to take a look at it when I get things more stable on my end. I did just download the latest and greatest Cygwin, because I needed an update for cmake; so I don't know if that may be related. Any help you can provide would be greatly appreciated. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org [mailto:c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org] On Behalf Of Roman Yakovenko Sent: Wednesday, July 11, 2007 4:08 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ - Can't Seem To Get It Working On 7/11/07, Lawrence Spector wrote: > First I tried the Py++ download from sourceforce, along with pygccxml, using > "python setup.py install" and a pre-build distribution of gccxml from the > website. So, I run pyplusplus_gui.pyw (C:\python25\python > C:\python25\Scripts\pyplusplus_gui.pyw). > > I make a file called TestPy++.h in C:\Temp, direct Py++ to it, and direct > Py++ to the gccxml_cc1plus.exe file inside of the GCCXML distribution from > Py++ website. You are supposed to direct Py++ to gccxml.exe > > > TestPy++.h contains: > ... > > > I get the following output: > > > Error occured during code generation process! > > Error: > Error occured while running GCC-XML: > Execution times (seconds) > parser : 0.02 (100%) usr > TOTAL : 0.02 > This just proves that you run the wrong executable :-( > > > > My first thought is wonderful, no information. I saw one site advocating > using Cygwin to do this and rebuilding GCCXML. I never tried this. > I set my file path to: /cygdrive/c/Temp/TestPy++.h (cygwin paths appear to > be required). > > I set my GCC_XML location to > /home/LSpector/GCC_XML/bin/gccxml.exe. > > > > I click generate code. The Py++ gui/GCCXML/something hangs, never to > recover. I am not aware of this bug. I'll be glad if you will help me to fix it. > For the hell of it, I try > /home/LSpector/GCC_XML/bin/gccxml_cc1plus.exe instead of > gccxml.exe. Why not? No, you was supposed to use gccxml.exe > > Not good. I can't seem to get this tool working. Can anyone help me? I'm > very stuck. I try. Just point Py++ GUI to gccxml.exe and try again. It should work. If not I am going to be online for some time, so ... -- 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 From Lawrence.Spector at CanfieldSci.com Wed Jul 11 22:32:43 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 11 Jul 2007 16:32:43 -0400 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03157F9865@Pan.domain-01> I found the problem as to why gccxml_windows_installer wasn't working. After closer inspection and saving a log file... I had one read-only file in my Visual Studio include path. The setup.py flunked after hitting the read-only file, and consequently, failed to fully generate gccxml.exe. Making progress... :) -Lawrence From roman.yakovenko at gmail.com Wed Jul 11 22:49:44 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 11 Jul 2007 23:49:44 +0300 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F9865@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9865@Pan.domain-01> Message-ID: <7465b6170707111349r29089b10x2b725b0791f4baba@mail.gmail.com> On 7/11/07, Lawrence Spector wrote: > I found the problem as to why gccxml_windows_installer wasn't working. After closer inspection and saving a log file... I had one read-only file in my Visual Studio include path. The setup.py flunked after hitting the read-only file, and consequently, failed to fully generate gccxml.exe. > > Making progress... :) Good catch! I will update my installer to remove "read-only" attributes from the files. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From ngoodspeed at solidworks.com Thu Jul 12 02:02:14 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Wed, 11 Jul 2007 20:02:14 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F981A@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F981A@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B7017A1235@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Tuesday, July 10, 2007 4:33 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > I illustrate the issue by printing the 'this' pointer at different > sections. Note that the memory locations are different depending on how I > call it. Hopefully it makes sense. [Nat] These are the key lines: 1. TestClass testClass(std::cout, 3, 9.6f, 'Q'); 2. TestClassWrap testClassWrapper(testClass); 3. boost::python::object pyTestClass(testClassWrapper); 4. main_namespace["pyTestClass"] = pyTestClass; It's clear from the definition of TestClassWrap that testClassWrapper (line 2) instantiates a different TestClass object than testClass (line 1). As you asked earlier, the question is: how should line 3 behave? My copy of the boost::python::object documentation says: template explicit object(T const& x); Effects: converts x to python and manages a reference to it. Throws: error_already_set and sets a Python TypeError exception if no such conversion is possible. So what does it mean to convert x to Python? boost::python::object manages a PyObject*. (object::ptr() returns that PyObject*; object::~object() decrements its ref count.) But your testClassWrapper instance doesn't have a PyObject* or a ref count. My assumption is that object's templated constructor allocates a chunk of Python storage and constructs a fresh TestClassWrap instance there. Once that's in place, though, I'd assume that the assignment on line 4 above would NOT construct yet another instance. I would expect that main_namespace["pyTestClass"] and your C++ variable pyTestClass should both reference the same TestClassWrap instance. If that's not what you're seeing (I haven't run your example) then I'll have to defer to others to account for it. > > -----Original Message----- > > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] > On > > Behalf Of Lawrence Spector > > Sent: Monday, July 09, 2007 5:35 PM > > To: Development of Python/C++ integration > > Subject: Re: [C++-sig] When You Create an Python Object Using > > Boost.Python, How Do You Find Out Its Name? > > > > Any idea why? Does the constructor of boost::python::object make a > copy? From matthieu.brucher at gmail.com Thu Jul 12 11:52:05 2007 From: matthieu.brucher at gmail.com (Matthieu Brucher) Date: Thu, 12 Jul 2007 11:52:05 +0200 Subject: [C++-sig] Moving "decorator" into C++ part of module In-Reply-To: <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> References: <20070521131405.GA12892@dogbert.sdsl.sun.ac.za> <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> Message-ID: Hi, Sorry to unearth this thread, but I'd like convert numpy array as well, but not only for matrices (my lab uses multi-dimensional images in C++ and it could be great to have a non-copying wrapper to Python and from Python). I'm very new to Boost.Python and to the numpy C-API, I hope I'll not ask stupid questions. In your code, Albert, you wrap a uBlas matrix in array_struct__. Is there some kind of reference counting for the memory allocated in the matrix ? Or the matrix must be valid until the python variable is destroyed ? If this is the case, is there a "simple" way of using smart pointers (if the class that must be wrapped uses smart pointers for holding the data) ? Matthieu 2007/5/21, Albert Strasheim : > > Howdy > > On Mon, 21 May 2007, Neal Becker wrote: > > > Albert Strasheim wrote: > > > > > Hello all > > > > > > I have a class with various methods that return uBLAS matrices. I've > > > wrapped various instantiations of these matrices with: > > > > > [...] > > > > I'm very interested in this. > > > > I thought array_interface was only a proposal at this point. You are > using > > it? If I have python2.5, do I need something to try this out? (Like, > > where is the array_interface include file?) > > NumPy's array interface is ready to go. I think you might be thinking > about the enhanced buffer protocol PEP thing. > > > Could you post a complete code that shows how you convert ublas::matrix > to > > numpy? Do you have converters in the other direction? > > Code attached. This is still very much a work in progress. Test it with: > > import numpy as N > import os > > from numpy.testing import * > # directory where you compiled the module > set_local_path(os.path.join('..', 'win_build', 'Debug')) > import pyublas > restore_path() > > at = pyublas.array_test() > print at > print at.ref_return() > print at.const_ref_return() > print at.pointer_return() > print at.const_pointer_return() > > As you can see, I can now convert return types (just haven't implemented > return by-value yet). Now that I understand call policies properly, I'm > going to look at converting arguments. > > Cheers, > > Albert > > _______________________________________________ > 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 ndbecker2 at gmail.com Thu Jul 12 15:02:55 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 12 Jul 2007 09:02:55 -0400 Subject: [C++-sig] type promotion Message-ID: I am using a wrapper that exposes ublas::matrix. I have the following problem. Suppose I have: .def ("__add__", plusScalar) where: template inline ublas::matrix::promote_type > plusScalar(const ublas::matrix &m1, const E2 &m2) { If I also expose: if (not is_complex::value) typedef std::complex U; .def ("__add__", plusScalar) So for matrix::double, we have exposed both matrix+scalar(double), and matrix+scalar(complex). It seems that m+2, will pick (arbitrarily) the complex version. In other words, it seems to be just as happy to convert 2 -> complex as 2->double, and stranger, it it seems just as happy with 2.0 -> complex as 2.0 -> double. What determines these argument matching rules, and what can I do to make sure the right thing happens? From Lawrence.Spector at CanfieldSci.com Thu Jul 12 15:59:52 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 12 Jul 2007 09:59:52 -0400 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B7017A1235@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174574D@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk><8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01><94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F981A@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B7017A1235@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B03158A8938@Pan.domain-01> That's a great point. I definitely had a mistake in my code (which I wasn't seeing). TestClassWrap should've been using a reference/pointer to the initial object. Making this change made TestClass always have the same address -- which makes sense, since even upon a copy, it's just going to copy the address, so it's still pointing to a valid location. Obviously, I could do this better with reference counting, but this was fine for illustration. However, here's the caveat. TestClassWrap has a different address. Here's what I can see from the output of my test program and running the debugger to verify the callstack. TestClassWrap constructor (from C++) - 0x0012FF10 TestClassWrap::output method (from Python code via Boost.Python: pyTestClass.attr("output")() - Python) - 0x993B90 TestClassWrap::output method (via Boost.Python exec() - Python) - 0x993B90 TestClassWrap::output method (via testClassWrapper.output() from C++) - 0x0012FF10 TestClassWrap destructor (from C++) - 0x0012FF10 [Note: TestClassWrap destructor never gets initiated for the Python copy -- most likely because I'm avoiding using Py_Finalize() due to other issues mentioned from a previous post.] Anyway, I think this clearly shows that boost::python::object is making a copy. The good news is, yes, had I done the initial sample properly, I can always just make a wrapper around a class to make sure it's keeps a reference to the initial class, and have it just make copies of the wrapper. Now the question becomes, is there a better way to tell Boost.Python that I want to keep a reference to my initial object, or is it all a manual process where I *must* make a wrapper around every class in order to do the reference counting myself? Please let me know. I appreciate all of your assistance so far. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nat Goodspeed Sent: Wednesday, July 11, 2007 8:02 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Lawrence Spector > Sent: Tuesday, July 10, 2007 4:33 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] When You Create an Python Object Using > Boost.Python, How Do You Find Out Its Name? > > I illustrate the issue by printing the 'this' pointer at different > sections. Note that the memory locations are different depending on how I > call it. Hopefully it makes sense. [Nat] These are the key lines: 1. TestClass testClass(std::cout, 3, 9.6f, 'Q'); 2. TestClassWrap testClassWrapper(testClass); 3. boost::python::object pyTestClass(testClassWrapper); 4. main_namespace["pyTestClass"] = pyTestClass; It's clear from the definition of TestClassWrap that testClassWrapper (line 2) instantiates a different TestClass object than testClass (line 1). As you asked earlier, the question is: how should line 3 behave? My copy of the boost::python::object documentation says: template explicit object(T const& x); Effects: converts x to python and manages a reference to it. Throws: error_already_set and sets a Python TypeError exception if no such conversion is possible. So what does it mean to convert x to Python? boost::python::object manages a PyObject*. (object::ptr() returns that PyObject*; object::~object() decrements its ref count.) But your testClassWrapper instance doesn't have a PyObject* or a ref count. My assumption is that object's templated constructor allocates a chunk of Python storage and constructs a fresh TestClassWrap instance there. Once that's in place, though, I'd assume that the assignment on line 4 above would NOT construct yet another instance. I would expect that main_namespace["pyTestClass"] and your C++ variable pyTestClass should both reference the same TestClassWrap instance. If that's not what you're seeing (I haven't run your example) then I'll have to defer to others to account for it. > > -----Original Message----- > > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] > On > > Behalf Of Lawrence Spector > > Sent: Monday, July 09, 2007 5:35 PM > > To: Development of Python/C++ integration > > Subject: Re: [C++-sig] When You Create an Python Object Using > > Boost.Python, How Do You Find Out Its Name? > > > > Any idea why? Does the constructor of boost::python::object make a > copy? _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From fullung at gmail.com Thu Jul 12 16:21:36 2007 From: fullung at gmail.com (Albert Strasheim) Date: Thu, 12 Jul 2007 16:21:36 +0200 Subject: [C++-sig] Moving "decorator" into C++ part of module In-Reply-To: References: <20070521131405.GA12892@dogbert.sdsl.sun.ac.za> <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> Message-ID: <20070712142135.GA1402@dogbert.sdsl.sun.ac.za> Hello On Thu, 12 Jul 2007, Matthieu Brucher wrote: > Sorry to unearth this thread, but I'd like convert numpy array as well, but > not only for matrices (my lab uses multi-dimensional images in C++ and it > could be great to have a non-copying wrapper to Python and from Python). > I'm very new to Boost.Python and to the numpy C-API, I hope I'll not ask > stupid questions. > > In your code, Albert, you wrap a uBlas matrix in array_struct__. Is there > some kind of reference counting for the memory allocated in the matrix ? Or > the matrix must be valid until the python variable is destroyed ? > If this is the case, is there a "simple" way of using smart pointers (if the > class that must be wrapped uses smart pointers for holding the data) ? The allocation and deallocation of the array is still managed by Boost.Python. You control the management through using the existing Boost.Python call policies. I put it together as follows: 1. The type you want to wrap should expose an __array_struct__. See, for example, my ublas_matrix wrapper: http://pyspkrec.googlecode.com/svn/trunk/numpycpp/ublas_matrix.h and you might want to look at the documentation for the array interface: http://numpy.scipy.org/array_interface.shtml For your multidimensional image class you want want to be more fancy and put something useful in descr. I think you could use this to make your image object behave like a NumPy record array, for example. 2. Functions returning your type are wrapped with return_asarray combined with any Boost.Python call policy, like here: http://pyspkrec.googlecode.com/svn/trunk/numpycpp/src/ublas_matrix_test.cpp so you do something like: def("foo", &foo, return_asarray >()); where py == boost::python. 3. return_asarray is defined here: http://pyspkrec.googlecode.com/svn/trunk/numpycpp/numpycpp.h To understand how it works, you should study the CallPolicies concept: http://www.boost.org/libs/python/doc/v2/CallPolicies.html#CallPolicies-concept What I'm doing is apparently called CallPolicies composition. The line: result = BasePolicy_::postcall(args_, result); gets the PyObject* of the wrapped object which might in turn already be wrapped in some Boost.Python thingy (like a custodian with ward). This object exposes __array_struct__, which is read when we pass it on to NumPy C/API function: return PyArray_FromStructInterface(result); Take a look at that function's source to get a better idea of what it does. This function returns a NumPy array that owns a reference (if that's the right terminology?) to the wrapped object. My tests seem to indicate that this all does what I think it does, but I could be wrong. ;-) Good luck with your wrapping and feel free to contact me if you have any more issues or questions. Cheers, Albert From Lawrence.Spector at CanfieldSci.com Thu Jul 12 17:07:18 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 12 Jul 2007 11:07:18 -0400 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> Message-ID: <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> Is there a way to specific flags to Py++, so that GCCXML can get past this issue? -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Wednesday, July 11, 2007 4:20 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ - Can't Seem To Get It Working gccxml.exe didn't show up from what I installed yesterday. I downloaded version 0.60 (which is old, I know) and got things working (sorta). I'm going to play around with the gccxml_windows_installer from the Py++ website and see if I can figure out why it wasn't successfully building gccxml.exe. Anyway, with my current configuration, I generated Py++ code, but I'm having compilation problems now. First, I get compile errors for certain things from Windows. Secondly, I had a boost header in there and during the compile I got an error saying the following: #error "Compile threading support is not turned on. Please set the current command line options for threading: either /MT /MTd /MD or /MDd. As for the cygwin issue, I'll try to take a look at it when I get things more stable on my end. I did just download the latest and greatest Cygwin, because I needed an update for cmake; so I don't know if that may be related. Any help you can provide would be greatly appreciated. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org [mailto:c++-sig-bounces+lawrence.spector=canfieldsci.com at python.org] On Behalf Of Roman Yakovenko Sent: Wednesday, July 11, 2007 4:08 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ - Can't Seem To Get It Working On 7/11/07, Lawrence Spector wrote: > First I tried the Py++ download from sourceforce, along with pygccxml, using > "python setup.py install" and a pre-build distribution of gccxml from the > website. So, I run pyplusplus_gui.pyw (C:\python25\python > C:\python25\Scripts\pyplusplus_gui.pyw). > > I make a file called TestPy++.h in C:\Temp, direct Py++ to it, and direct > Py++ to the gccxml_cc1plus.exe file inside of the GCCXML distribution from > Py++ website. You are supposed to direct Py++ to gccxml.exe > > > TestPy++.h contains: > ... > > > I get the following output: > > > Error occured during code generation process! > > Error: > Error occured while running GCC-XML: > Execution times (seconds) > parser : 0.02 (100%) usr > TOTAL : 0.02 > This just proves that you run the wrong executable :-( > > > > My first thought is wonderful, no information. I saw one site advocating > using Cygwin to do this and rebuilding GCCXML. I never tried this. > I set my file path to: /cygdrive/c/Temp/TestPy++.h (cygwin paths appear to > be required). > > I set my GCC_XML location to > /home/LSpector/GCC_XML/bin/gccxml.exe. > > > > I click generate code. The Py++ gui/GCCXML/something hangs, never to > recover. I am not aware of this bug. I'll be glad if you will help me to fix it. > For the hell of it, I try > /home/LSpector/GCC_XML/bin/gccxml_cc1plus.exe instead of > gccxml.exe. Why not? No, you was supposed to use gccxml.exe > > Not good. I can't seem to get this tool working. Can anyone help me? I'm > very stuck. I try. Just point Py++ GUI to gccxml.exe and try again. It should work. If not I am going to be online for some time, so ... -- 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 _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From matthieu.brucher at gmail.com Thu Jul 12 17:08:18 2007 From: matthieu.brucher at gmail.com (Matthieu Brucher) Date: Thu, 12 Jul 2007 17:08:18 +0200 Subject: [C++-sig] Moving "decorator" into C++ part of module In-Reply-To: <20070712142135.GA1402@dogbert.sdsl.sun.ac.za> References: <20070521131405.GA12892@dogbert.sdsl.sun.ac.za> <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> <20070712142135.GA1402@dogbert.sdsl.sun.ac.za> Message-ID: Hi again, A big thank you for all the indications, I'll read them and try to understand them. Matthieu 2007/7/12, Albert Strasheim : > > Hello > > On Thu, 12 Jul 2007, Matthieu Brucher wrote: > > > Sorry to unearth this thread, but I'd like convert numpy array as well, > but > > not only for matrices (my lab uses multi-dimensional images in C++ and > it > > could be great to have a non-copying wrapper to Python and from Python). > > I'm very new to Boost.Python and to the numpy C-API, I hope I'll not ask > > stupid questions. > > > > In your code, Albert, you wrap a uBlas matrix in array_struct__. Is > there > > some kind of reference counting for the memory allocated in the matrix ? > Or > > the matrix must be valid until the python variable is destroyed ? > > If this is the case, is there a "simple" way of using smart pointers (if > the > > class that must be wrapped uses smart pointers for holding the data) ? > > The allocation and deallocation of the array is still managed by > Boost.Python. You control the management through using the existing > Boost.Python call policies. > > I put it together as follows: > > 1. The type you want to wrap should expose an __array_struct__. See, > for example, my ublas_matrix wrapper: > > http://pyspkrec.googlecode.com/svn/trunk/numpycpp/ublas_matrix.h > > and you might want to look at the documentation for the array interface: > > http://numpy.scipy.org/array_interface.shtml > > For your multidimensional image class you want want to be more fancy and > put something useful in descr. I think you could use this to make your > image object behave like a NumPy record array, for example. > > 2. Functions returning your type are wrapped with return_asarray > combined with any Boost.Python call policy, like here: > > > http://pyspkrec.googlecode.com/svn/trunk/numpycpp/src/ublas_matrix_test.cpp > > so you do something like: > > def("foo", &foo, > return_asarray >()); > > where py == boost::python. > > 3. return_asarray is defined here: > > http://pyspkrec.googlecode.com/svn/trunk/numpycpp/numpycpp.h > > To understand how it works, you should study the CallPolicies concept: > > > http://www.boost.org/libs/python/doc/v2/CallPolicies.html#CallPolicies-concept > > What I'm doing is apparently called CallPolicies composition. > > The line: > > result = BasePolicy_::postcall(args_, result); > > gets the PyObject* of the wrapped object which might in turn already be > wrapped in some Boost.Python thingy (like a custodian with ward). This > object exposes __array_struct__, which is read when we pass it on to > NumPy C/API function: > > return PyArray_FromStructInterface(result); > > Take a look at that function's source to get a better idea of what > it does. This function returns a NumPy array that owns a reference (if > that's the right terminology?) to the wrapped object. > > My tests seem to indicate that this all does what I think it does, but > I could be wrong. ;-) > > Good luck with your wrapping and feel free to contact me if you have > any more issues or questions. > > Cheers, > > Albert > _______________________________________________ > 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 roman.yakovenko at gmail.com Thu Jul 12 21:13:08 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 12 Jul 2007 22:13:08 +0300 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> Message-ID: <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> On 7/12/07, Lawrence Spector wrote: > Is there a way to specific flags to Py++, so that GCCXML can get past this issue? I don't understand. What issue do you mean? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Thu Jul 12 21:26:33 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 12 Jul 2007 15:26:33 -0400 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> I'm repeatedly getting an error that says the following (from Boost): #error "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd" Reasonable. However, when I go to the gccxml_config file, and add to the GCCXML_CXXFLAGS, it does not seem to apply them. I tried adding /MT, with no effect. So, from what I can tell, the GCCXML_CXXFLAGS option is being ignored. Is there another way to set flags for gccxml? Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Thursday, July 12, 2007 3:13 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ - Can't Seem To Get It Working On 7/12/07, Lawrence Spector wrote: > Is there a way to specific flags to Py++, so that GCCXML can get past this issue? I don't understand. What issue do you mean? -- 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 From roman.yakovenko at gmail.com Thu Jul 12 21:57:35 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 12 Jul 2007 22:57:35 +0300 Subject: [C++-sig] Py++ - Can't Seem To Get It Working In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> Message-ID: <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> On 7/12/07, Lawrence Spector wrote: > I'm repeatedly getting an error that says the following (from Boost): > > #error "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd" > > Reasonable. However, when I go to the gccxml_config file, and add to the GCCXML_CXXFLAGS, it does not seem to apply them. I tried adding /MT, with no effect. So, from what I can tell, the GCCXML_CXXFLAGS option is being ignored. > > Is there another way to set flags for gccxml? Now I understand. What library do you use? module_builder_t.__init__ has cflags as argument, may be you can pass the flags to gccxml compiler using it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Fri Jul 13 00:15:05 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 12 Jul 2007 18:15:05 -0400 Subject: [C++-sig] Py++ - Maximum recursion depth exceeded? In-Reply-To: <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B03158A8972@Pan.domain-01> When using the Pyplusplus_gui.pyw application, I get the following error: Error occurred during code generation process! Error: Maximum recursion depth exceeded Any idea what's going on and how to work around it? Commenting out random method calls from my header file (doesn't seem to matter which ones) seems to resolve the problem, but obviously, it's less than ideal. Thanks, Lawrence From gtang at bcm.edu Fri Jul 13 00:57:17 2007 From: gtang at bcm.edu (Grant) Date: Thu, 12 Jul 2007 17:57:17 -0500 Subject: [C++-sig] manage new object in operator overloading Message-ID: Hi, How can I mange new object in overloading operator? For example I have operator+ for my class: class_< MYData >("MYData", init< >()) .def(self + self) The operator+ is implemented as: MYData * operator+(const MYData & a, const MYData & b) { MYData * r = a.copy(); r->add(b); return r; } This ends up with a memory leak. I can't add "return_value_policy< manage_new_object >()" as I did for other function return a new object. How should I do? Thanks in advance, Grant From roman.yakovenko at gmail.com Fri Jul 13 17:07:22 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 13 Jul 2007 18:07:22 +0300 Subject: [C++-sig] When You Create an Python Object Using Boost.Python, How Do You Find Out Its Name? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03158A8938@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F97CC@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03157F97DE@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B70174577C@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97DF@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B701745791@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F97E1@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B7017A0C7A@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03157F981A@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B7017A1235@corp-mail4.solidworks.swk> <8F737B3BFD630A4380BD0357481D4B03158A8938@Pan.domain-01> Message-ID: <7465b6170707130807m1af9e773t195fb29f219cb12a@mail.gmail.com> On 7/12/07, Lawrence Spector wrote: > Now the question becomes, is there a better way to tell Boost.Python that I want to keep a reference to my initial object, or is it all a manual process where I *must* make a wrapper around every class in order to do the reference counting myself? You can use boost::ref or boost::python::ptr to tell to boost::python::object constructor not to create a copy of your object. Also if you want to share objects the easiest way to go is to use boost::shared_ptr. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Jul 13 17:18:50 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 13 Jul 2007 18:18:50 +0300 Subject: [C++-sig] Py++ - Maximum recursion depth exceeded? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B03158A8972@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8972@Pan.domain-01> Message-ID: <7465b6170707130818s303d7d4dta134cdb12d312ab@mail.gmail.com> On 7/13/07, Lawrence Spector wrote: > When using the Pyplusplus_gui.pyw application, I get the following error: > > Error occurred during code generation process! > Error: > Maximum recursion depth exceeded > > Any idea what's going on and how to work around it? Commenting out random method calls from my header file (doesn't seem to matter which ones) seems to resolve the problem, but obviously, it's less than ideal. It could nice if you can send me the stack. Also can you try the latest SVN version? I fixed bug with infinite recursion right after I released the 0.9 -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Jul 13 17:29:39 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 13 Jul 2007 18:29:39 +0300 Subject: [C++-sig] manage new object in operator overloading In-Reply-To: References: Message-ID: <7465b6170707130829i24e9533bg241e393614b85205@mail.gmail.com> On 7/13/07, Grant wrote: > Hi, > > How can I mange new object in overloading operator? > For example I have operator+ for my class: > > class_< MYData >("MYData", init< >()) > .def(self + self) > > The operator+ is implemented as: > MYData * operator+(const MYData & a, const MYData & b) > { > MYData * r = a.copy(); > r->add(b); > return r; > } > > This ends up with a memory leak. I can't add "return_value_policy< > manage_new_object >()" as I did for other function return a new object. > > How should I do? You have to use regular "def" functions. Just give the right name to it: def( "__add__", ... ) This is exactly what boost.python does. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From t_spens at yahoo.com Fri Jul 13 17:48:25 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 13 Jul 2007 08:48:25 -0700 (PDT) Subject: [C++-sig] importing c++ shared dynamic libraries (.so) Message-ID: <872974.65192.qm@web43133.mail.sp1.yahoo.com> I'm trying to import multiple c++ shared dynamic libraries (.so) with inter-dependencies into python. Then use one of the .so libraries which I've added boost.python wrappers to. Here's the out put from python... using boost 1.33 Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import libxml2 >>> #libxml2.so imported just fine >>> >>> import libboost_thread Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_thread) >>> >>> import libboost_serialization Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_serialization) >>> >>> import libboost_python Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_python) >>> >>> import libX Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibX) >>> libX.so is a c++ dynamic shared library with no boost.python wrappers >>> >>> import libShared Traceback (most recent call last): File "", line 1, in ImportError: libShared.so: undefined symbol: xmlFree >>> libShared.so is a c++ dynamic shared library with no boost.python wrappers >>> >>> import libzee Traceback (most recent call last): File "", line 1, in ImportError: ./libzee.so: undefined symbol: _ZTIN5boost10lock_errorE >>> libzee.so is a c++ dynamic shared library with boost.python wrappers added I've tried using ld.open but it seems to only allow me to call specific functions in the libraries and doesn't allow the libraries to talk to each other. Any help will be greatly appreciated. ____________________________________________________________________________________ Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC From t_spens at yahoo.com Fri Jul 13 17:52:12 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 13 Jul 2007 08:52:12 -0700 (PDT) Subject: [C++-sig] importing issues with c++ shared dynamic libraries (.so) Message-ID: <123326.97388.qm@web43146.mail.sp1.yahoo.com> I'm trying to import multiple c++ shared dynamic libraries (.so) with inter-dependencies into python. Then use one of the .so libraries which I've added boost.python wrappers to. Here's the out put from python... using boost 1.33 Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import libxml2 >>> #libxml2.so imported just fine >>> >>> import libboost_thread Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_thread) >>> >>> import libboost_serialization Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_serialization) >>> >>> import libboost_python Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibboost_python) >>> >>> import libX Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define init function (initlibX) >>> libX.so is a c++ dynamic shared library with no boost.python wrappers >>> >>> import libShared Traceback (most recent call last): File "", line 1, in ImportError: libShared.so: undefined symbol: xmlFree >>> libShared.so is a c++ dynamic shared library with no boost.python wrappers >>> >>> import libzee Traceback (most recent call last): File "", line 1, in ImportError: ./libzee.so: undefined symbol: _ZTIN5boost10lock_errorE >>> libzee.so is a c++ dynamic shared library with boost.python wrappers added I've tried using ld.open but it seems to only allow me to call specific functions in the libraries and doesn't allow the libraries to talk to each other. Any help will be greatly appreciated. ____________________________________________________________________________________Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. http://tv.yahoo.com/ From t_spens at yahoo.com Fri Jul 13 18:41:41 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 13 Jul 2007 09:41:41 -0700 (PDT) Subject: [C++-sig] importing issues with c++ shared dynamic libraries (.so) In-Reply-To: <123326.97388.qm@web43146.mail.sp1.yahoo.com> Message-ID: <922713.47269.qm@web43144.mail.sp1.yahoo.com> --- Tim Spens wrote: > I'm trying to import multiple c++ shared dynamic > libraries (.so) with inter-dependencies into python. > > Then use one of the .so libraries which I've added > boost.python wrappers to. Here's the out put from > python... > > using boost 1.33 > > Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) > [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 > Type "help", "copyright", "credits" or "license" for > more information. > >>> > >>> import libxml2 > >>> #libxml2.so imported just fine > >>> > >>> import libboost_thread > Traceback (most recent call last): > File "", line 1, in > ImportError: dynamic module does not define init > function (initlibboost_thread) > >>> > >>> import libboost_serialization > Traceback (most recent call last): > File "", line 1, in > ImportError: dynamic module does not define init > function (initlibboost_serialization) > >>> > >>> import libboost_python > Traceback (most recent call last): > File "", line 1, in > ImportError: dynamic module does not define init > function (initlibboost_python) > >>> > >>> import libX > Traceback (most recent call last): > File "", line 1, in > ImportError: dynamic module does not define init > function (initlibX) > >>> libX.so is a c++ dynamic shared library with no > boost.python wrappers > >>> > >>> import libShared > Traceback (most recent call last): > File "", line 1, in > ImportError: libShared.so: undefined symbol: xmlFree > >>> libShared.so is a c++ dynamic shared library > with > no boost.python wrappers > >>> > >>> import libzee > Traceback (most recent call last): > File "", line 1, in > ImportError: ./libzee.so: undefined symbol: > _ZTIN5boost10lock_errorE > >>> libzee.so is a c++ dynamic shared library with > boost.python wrappers added > > I've tried using ld.open but it seems to only allow > me > to call specific functions in the libraries and > doesn't allow the libraries to talk to each other. > > Any help will be greatly appreciated. > > I've just learned that I need to only import my wrapped library, and python should find the libraries the wrapped lib is dependent upon when it's loaded? So I added the paths of my c++ libraries and boost libs to the sys.path and env path, but I still have the same problem importing my python wrapped c++ lib because it has dependencies on boost libs. >>> import libzee Traceback (most recent call last): File "", line 1, in ImportError: ./libzee.so: undefined symbol: _ZTIN5boost10lock_errorE ____________________________________________________________________________________ Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 From David.A.Wagner at jpl.nasa.gov Fri Jul 13 19:09:29 2007 From: David.A.Wagner at jpl.nasa.gov (David A Wagner) Date: Fri, 13 Jul 2007 10:09:29 -0700 Subject: [C++-sig] importing issues with c++ shared dynamic libraries (.so) In-Reply-To: <922713.47269.qm@web43144.mail.sp1.yahoo.com> References: <922713.47269.qm@web43144.mail.sp1.yahoo.com> Message-ID: <4697B1C9.8040309@jpl.nasa.gov> Most likely, the dynamic loader is just failing to find the dependent .so files because it doesn't know where to look for them. You have to list the search paths in LD_LIBRARY_PATH (inferring you're using linux) environment variable. More info: man ld.so Tim Spens wrote: > --- Tim Spens wrote: > > >> I'm trying to import multiple c++ shared dynamic >> libraries (.so) with inter-dependencies into python. >> >> Then use one of the .so libraries which I've added >> boost.python wrappers to. Here's the out put from >> python... >> >> using boost 1.33 >> >> Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) >> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 >> Type "help", "copyright", "credits" or "license" for >> more information. >> >>>>> import libxml2 >>>>> #libxml2.so imported just fine >>>>> >>>>> import libboost_thread >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: dynamic module does not define init >> function (initlibboost_thread) >> >>>>> import libboost_serialization >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: dynamic module does not define init >> function (initlibboost_serialization) >> >>>>> import libboost_python >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: dynamic module does not define init >> function (initlibboost_python) >> >>>>> import libX >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: dynamic module does not define init >> function (initlibX) >> >>>>> libX.so is a c++ dynamic shared library with no >>>>> >> boost.python wrappers >> >>>>> import libShared >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: libShared.so: undefined symbol: xmlFree >> >>>>> libShared.so is a c++ dynamic shared library >>>>> >> with >> no boost.python wrappers >> >>>>> import libzee >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: ./libzee.so: undefined symbol: >> _ZTIN5boost10lock_errorE >> >>>>> libzee.so is a c++ dynamic shared library with >>>>> >> boost.python wrappers added >> >> I've tried using ld.open but it seems to only allow >> me >> to call specific functions in the libraries and >> doesn't allow the libraries to talk to each other. >> >> Any help will be greatly appreciated. >> >> >> > > I've just learned that I need to only import my > wrapped library, and python should find the libraries > the wrapped lib is dependent upon when it's loaded? > So I added the paths of my c++ libraries and boost > libs to the sys.path and env path, but I still have > the same problem importing my python wrapped c++ lib > because it has dependencies on boost libs. > > >>>> import libzee >>>> > Traceback (most recent call last): > File "", line 1, in > ImportError: ./libzee.so: undefined symbol: > _ZTIN5boost10lock_errorE > > > > ____________________________________________________________________________________ > Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 > > > _______________________________________________ > 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: -------------- next part -------------- A non-text attachment was scrubbed... Name: David.A.Wagner.vcf Type: text/x-vcard Size: 304 bytes Desc: not available URL: From t_spens at yahoo.com Fri Jul 13 19:52:18 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 13 Jul 2007 10:52:18 -0700 (PDT) Subject: [C++-sig] importing issues with c++ shared dynamic libraries (.so) In-Reply-To: <4697B1C9.8040309@jpl.nasa.gov> Message-ID: <978830.2584.qm@web43131.mail.sp1.yahoo.com> I have listed the paths to the other libraries in LD_LIBRARY_PATH but still have the same problem. --- David A Wagner wrote: > Most likely, the dynamic loader is just failing to > find the dependent > .so files because it doesn't > know where to look for them. You have to list the > search paths in > LD_LIBRARY_PATH > (inferring you're using linux) environment variable. > > More info: man ld.so > > > Tim Spens wrote: > > --- Tim Spens wrote: > > > > > >> I'm trying to import multiple c++ shared dynamic > >> libraries (.so) with inter-dependencies into > python. > >> > >> Then use one of the .so libraries which I've > added > >> boost.python wrappers to. Here's the out put > from > >> python... > >> > >> using boost 1.33 > >> > >> Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) > >> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 > >> Type "help", "copyright", "credits" or "license" > for > >> more information. > >> > >>>>> import libxml2 > >>>>> #libxml2.so imported just fine > >>>>> > >>>>> import libboost_thread > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: dynamic module does not define init > >> function (initlibboost_thread) > >> > >>>>> import libboost_serialization > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: dynamic module does not define init > >> function (initlibboost_serialization) > >> > >>>>> import libboost_python > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: dynamic module does not define init > >> function (initlibboost_python) > >> > >>>>> import libX > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: dynamic module does not define init > >> function (initlibX) > >> > >>>>> libX.so is a c++ dynamic shared library with > no > >>>>> > >> boost.python wrappers > >> > >>>>> import libShared > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: libShared.so: undefined symbol: > xmlFree > >> > >>>>> libShared.so is a c++ dynamic shared library > >>>>> > >> with > >> no boost.python wrappers > >> > >>>>> import libzee > >>>>> > >> Traceback (most recent call last): > >> File "", line 1, in > >> ImportError: ./libzee.so: undefined symbol: > >> _ZTIN5boost10lock_errorE > >> > >>>>> libzee.so is a c++ dynamic shared library with > >>>>> > >> boost.python wrappers added > >> > >> I've tried using ld.open but it seems to only > allow > >> me > >> to call specific functions in the libraries and > >> doesn't allow the libraries to talk to each > other. > >> > >> Any help will be greatly appreciated. > >> > >> > >> > > > > I've just learned that I need to only import my > > wrapped library, and python should find the > libraries > > the wrapped lib is dependent upon when it's > loaded? > > So I added the paths of my c++ libraries and boost > > libs to the sys.path and env path, but I still > have > > the same problem importing my python wrapped c++ > lib > > because it has dependencies on boost libs. > > > > > >>>> import libzee > >>>> > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: ./libzee.so: undefined symbol: > > _ZTIN5boost10lock_errorE > > > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > begin:vcard > fn:David Wagner > n:Wagner;David > org:Caltech/Jet Propulsion Laboratory;Flight > Software Applications Group > adr;dom:;;4800 Oak Grove Drive;Pasadena;CA;91109 > email;internet:David.A.Wagner at jpl.nasa.gov > title:Senior Software Engineer > tel;work:818 354 1148 > x-mozilla-html:TRUE > version:2.1 > end:vcard > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > ____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting From t_spens at yahoo.com Fri Jul 13 20:08:11 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 13 Jul 2007 11:08:11 -0700 (PDT) Subject: [C++-sig] importing issues with c++ shared dynamic libraries (.so) In-Reply-To: <978830.2584.qm@web43131.mail.sp1.yahoo.com> Message-ID: <828175.62745.qm@web43136.mail.sp1.yahoo.com> Thanks for the help you got me on the right path, when I was using the linker to create my lib I didn't know I needed to include all the dependent libraries in the command. ld -Bshareable -o libzee.so *.o -lX -lShared -lboost_python -lboost_serialization -lboost_thread -lxml2 --- Tim Spens wrote: > I have listed the paths to the other libraries in > LD_LIBRARY_PATH but still have the same problem. > > --- David A Wagner > wrote: > > > Most likely, the dynamic loader is just failing to > > find the dependent > > .so files because it doesn't > > know where to look for them. You have to list the > > search paths in > > LD_LIBRARY_PATH > > (inferring you're using linux) environment > variable. > > > > More info: man ld.so > > > > > > Tim Spens wrote: > > > --- Tim Spens wrote: > > > > > > > > >> I'm trying to import multiple c++ shared > dynamic > > >> libraries (.so) with inter-dependencies into > > python. > > >> > > >> Then use one of the .so libraries which I've > > added > > >> boost.python wrappers to. Here's the out put > > from > > >> python... > > >> > > >> using boost 1.33 > > >> > > >> Python 2.5.1 (r251:54863, May 2 2007, > 16:56:35) > > >> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 > > >> Type "help", "copyright", "credits" or > "license" > > for > > >> more information. > > >> > > >>>>> import libxml2 > > >>>>> #libxml2.so imported just fine > > >>>>> > > >>>>> import libboost_thread > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: dynamic module does not define > init > > >> function (initlibboost_thread) > > >> > > >>>>> import libboost_serialization > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: dynamic module does not define > init > > >> function (initlibboost_serialization) > > >> > > >>>>> import libboost_python > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: dynamic module does not define > init > > >> function (initlibboost_python) > > >> > > >>>>> import libX > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: dynamic module does not define > init > > >> function (initlibX) > > >> > > >>>>> libX.so is a c++ dynamic shared library with > > no > > >>>>> > > >> boost.python wrappers > > >> > > >>>>> import libShared > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: libShared.so: undefined symbol: > > xmlFree > > >> > > >>>>> libShared.so is a c++ dynamic shared library > > >>>>> > > >> with > > >> no boost.python wrappers > > >> > > >>>>> import libzee > > >>>>> > > >> Traceback (most recent call last): > > >> File "", line 1, in > > >> ImportError: ./libzee.so: undefined symbol: > > >> _ZTIN5boost10lock_errorE > > >> > > >>>>> libzee.so is a c++ dynamic shared library > with > > >>>>> > > >> boost.python wrappers added > > >> > > >> I've tried using ld.open but it seems to only > > allow > > >> me > > >> to call specific functions in the libraries and > > >> doesn't allow the libraries to talk to each > > other. > > >> > > >> Any help will be greatly appreciated. > > >> > > >> > > >> > > > > > > I've just learned that I need to only import my > > > wrapped library, and python should find the > > libraries > > > the wrapped lib is dependent upon when it's > > loaded? > > > So I added the paths of my c++ libraries and > boost > > > libs to the sys.path and env path, but I still > > have > > > the same problem importing my python wrapped c++ > > lib > > > because it has dependencies on boost libs. > > > > > > > > >>>> import libzee > > >>>> > > > Traceback (most recent call last): > > > File "", line 1, in > > > ImportError: ./libzee.so: undefined symbol: > > > _ZTIN5boost10lock_errorE > > > > > > > > > _______________________________________________ > > > C++-sig mailing list > > > C++-sig at python.org > > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > > > > begin:vcard > > fn:David Wagner > > n:Wagner;David > > org:Caltech/Jet Propulsion Laboratory;Flight > > Software Applications Group > > adr;dom:;;4800 Oak Grove Drive;Pasadena;CA;91109 > > email;internet:David.A.Wagner at jpl.nasa.gov > > title:Senior Software Engineer > > tel;work:818 354 1148 > > x-mozilla-html:TRUE > > version:2.1 > > end:vcard > > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > > ____________________________________________________________________________________ > Building a website is a piece of cake. Yahoo! Small > Business gives you all the tools to get online. > http://smallbusiness.yahoo.com/webhosting > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > ____________________________________________________________________________________ Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php From roman.yakovenko at gmail.com Sat Jul 14 10:33:24 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 14 Jul 2007 11:33:24 +0300 Subject: [C++-sig] importing c++ shared dynamic libraries (.so) In-Reply-To: <872974.65192.qm@web43133.mail.sp1.yahoo.com> References: <872974.65192.qm@web43133.mail.sp1.yahoo.com> Message-ID: <7465b6170707140133q1bf7123aud643767b350ed4fe@mail.gmail.com> On 7/13/07, Tim Spens wrote: > I'm trying to import multiple c++ shared dynamic > libraries (.so) with inter-dependencies into python. > Then use one of the .so libraries which I've added > boost.python wrappers to. Here's the out put from > python... > > using boost 1.33 > > Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) > [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 > Type "help", "copyright", "credits" or "license" for > more information. > >>> > >>> import libxml2 > >>> #libxml2.so imported just fine > >>> > >>> import libboost_thread > Any help will be greatly appreciated. You cannot import raw so's to Python as is. I guess you don't understand something very fundamental about Boost.Python or Python. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Mon Jul 16 15:25:47 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 09:25:47 -0400 Subject: [C++-sig] Py++ - Maximum recursion depth exceeded? In-Reply-To: <7465b6170707130818s303d7d4dta134cdb12d312ab@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8972@Pan.domain-01> <7465b6170707130818s303d7d4dta134cdb12d312ab@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2241@Pan.domain-01> I installed the newest SVN version, and so far the infinite recursion hasn't occurred since installing. So that may have taken care of it. I'll let you know if I encounter it again. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Friday, July 13, 2007 11:19 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ - Maximum recursion depth exceeded? On 7/13/07, Lawrence Spector wrote: > When using the Pyplusplus_gui.pyw application, I get the following error: > > Error occurred during code generation process! > Error: > Maximum recursion depth exceeded > > Any idea what's going on and how to work around it? Commenting out random method calls from my header file (doesn't seem to matter which ones) seems to resolve the problem, but obviously, it's less than ideal. It could nice if you can send me the stack. Also can you try the latest SVN version? I fixed bug with infinite recursion right after I released the 0.9 -- 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 From Lawrence.Spector at CanfieldSci.com Mon Jul 16 16:43:22 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 10:43:22 -0400 Subject: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... In-Reply-To: <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> I'm using Visual Studio 2005 (8). I've spent a significant amount of time trying to get Py++ working, and while I've made progress, this one has had me at its mercy. I've spent days trying to stub out what GCCXML complains about, but each time I stub out a file, I get more errors in the next one and it just goes down the chain. Here's what I've done to demonstrate. There's a sample cpp file, for demonstration, called TestPy++.cpp. This was processed using pyplusplus_gui.pyw. The code is as follows: #include #include int main() { boost::python::object obj; return 0; } Extremely basic, so that all's that happening is just creating a new object, using the Boost.Python library and everything that includes. I set my include paths to boost and the Python API's include directory. Here's the output: Error occured during code generation process! Error: Error occured while running GCC-XML: In file included from D:/3rdparty/boost_1_34_0/boost/python/type_id.hpp:14, from D:/3rdparty/boost_1_34_0/boost/python/instance_holder.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python/object/pointer_holder.hpp:14, from D:/3rdparty/boost_1_34_0/boost/python/to_python_indirect.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/python/object/forward.hpp:20, from D:/3rdparty/boost_1_34_0/boost/python/object/pointer_holder.hpp:16, from D:/3rdparty/boost_1_34_0/boost/python/to_python_indirect.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:33:13: operator "defined" requires an identifier D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:33:13: ("or" is an alternative token for "||" in C++) D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:33:15: missing '(' in expression D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:44:13: operator "defined" requires an identifier D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:44:13: ("or" is an alternative token for "||" in C++) D:/3rdparty/boost_1_34_0/boost/mpl/or.hpp:44:15: missing '(' in expression In file included from D:/3rdparty/boost_1_34_0/boost/type_traits/type_with_alignment.hpp:19, from D:/3rdparty/boost_1_34_0/boost/type_traits/alignment_traits.hpp:13, from D:/3rdparty/boost_1_34_0/boost/python/object/instance.hpp:9, from D:/3rdparty/boost_1_34_0/boost/python/object/make_instance.hpp:9, from D:/3rdparty/boost_1_34_0/boost/python/object/make_ptr_instance.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/to_python_indirect.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/python/converter/to_python_function_type.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/converter/registry.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/converter/registered.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/object/make_instance.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/object/make_ptr_instance.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/to_python_indirect.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/python/converter/rvalue_from_python_data.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python/converter/registry.hpp:9, from D:/3rdparty/boost_1_34_0/boost/python/converter/registered.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/object/make_instance.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/object/make_ptr_instance.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/to_python_indirect.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:10, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/detail/indirect_traits.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python/detail/indirect_traits.hpp:7, from D:/3rdparty/boost_1_34_0/boost/python/converter/object_manager.hpp:13, from D:/3rdparty/boost_1_34_0/boost/python/to_python_value.hpp:16, from D:/3rdparty/boost_1_34_0/boost/python/detail/invoke.hpp:21, from D:/3rdparty/boost_1_34_0/boost/python/detail/caller.hpp:14, from D:/3rdparty/boost_1_34_0/boost/python/object/function_handle.hpp:8, from D:/3rdparty/boost_1_34_0/boost/python/converter/arg_to_python.hpp:19, from D:/3rdparty/boost_1_34_0/boost/python/call.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:12, from D:/3rdparty/boost_1_34_0/boost/python/args.hpp:25, from D:/3rdparty/boost_1_34_0/boost/python.hpp:11, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:32:13: operator "defined" requires an identifier D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:32:13: ("and" is an alternative token for "&&" in C++) D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:32:16: missing '(' in expression D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:43:13: operator "defined" requires an identifier D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:43:13: ("and" is an alternative token for "&&" in C++) D:/3rdparty/boost_1_34_0/boost/mpl/and.hpp:43:16: missing '(' in expression In file included from D:/3rdparty/boost_1_34_0/boost/tuple/tuple.hpp:24, from D:/3rdparty/boost_1_34_0/boost/python/detail/def_helper.hpp:18, from D:/3rdparty/boost_1_34_0/boost/python/class.hpp:29, from D:/3rdparty/boost_1_34_0/boost/python.hpp:18, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/type_traits/is_abstract.hpp:51, from D:/3rdparty/boost_1_34_0/boost/type_traits.hpp:30, from D:/3rdparty/boost_1_34_0/boost/python/detail/defaults_def.hpp:15, from D:/3rdparty/boost_1_34_0/boost/python/overloads.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python.hpp:52, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/python/detail/defaults_def.hpp:18, from D:/3rdparty/boost_1_34_0/boost/python/overloads.hpp:11, from D:/3rdparty/boost_1_34_0/boost/python.hpp:52, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef In file included from D:/3rdparty/boost_1_34_0/boost/python/return_arg.hpp:16, from D:/3rdparty/boost_1_34_0/boost/python.hpp:58, from C:/Work/Py++-Test/TestPy++.cpp:2: D:/3rdparty/boost_1_34_0/boost/static_assert.hpp:14:1: unterminated #ifndef D:/3rdparty/boost_1_34_0/boost/python/object_core.hpp:285: sorry, unimplemented: call_expr cannot be mangled due to a defect in the C++ ABI Any tips on how to resolve this? Like I said, stubbing out headers just gets me into a deeper and deeper hole where I'm basically trying to patch every header file just to convince GCCXML it compiles, so it will actually generate something. Thanks, Lawrence From roman.yakovenko at gmail.com Mon Jul 16 21:26:26 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 16 Jul 2007 22:26:26 +0300 Subject: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> Message-ID: <7465b6170707161226p4b516d69y57b364b1b90a6da9@mail.gmail.com> On 7/16/07, Lawrence Spector wrote: > I'm using Visual Studio 2005 (8). I've spent a significant amount of time trying to get Py++ working, and while I've made progress, this one has had me at its mercy. I've spent days trying to stub out what GCCXML complains about, but each time I stub out a file, I get more errors in the next one and it just goes down the chain. > > Here's what I've done to demonstrate. There's a sample cpp file, for demonstration, called TestPy++.cpp. This was processed using pyplusplus_gui.pyw. The code is as follows: > :-( The truthful answer: GCCXML is too weak to compile code from Boost.Python library on Windows :-((((. Basically there is no "user-space" work around. I am working on integrating another back-end( compiler) to pygccxml, but it will take some time untill it will become "production-ready". The "good" news is that some of the boost libraries treat GCCXML as another compiler and introduce work-around. Another good news is that according to this regression results( http://engineering.meta-comm.com/boost-regression/1_34_0/user/mpl_release.html ) MPL compiles fine under the MinGW ( GCC on Windows ) so may be you will be able to find some define that will allow you to compiler the library. It also worse to report the problem to Boost developers. May be they will help you and tweak their code. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Mon Jul 16 21:41:24 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 15:41:24 -0400 Subject: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... In-Reply-To: <7465b6170707161226p4b516d69y57b364b1b90a6da9@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> <7465b6170707161226p4b516d69y57b364b1b90a6da9@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2267@Pan.domain-01> Hmm... thanks for your quick and honest answer. I'm disappointed to hear this. It's unfortunate that there's no way to tell GCCXML to ignore any errors and just process whatever it figured out, even if it's not a 100% complete set. I guess it's going to come down to doing some major stubbing before it even gets into the boost header files. Out of curiosity, you said that it's too weak to compile code from Boost.Python on Windows. I may be being overly optimistic, but I thought you might be implying that it might work on another platform, like Linux? I have a Linux box at my desk if this is an option. Anyway, Roman, I just wanted to say that I appreciate all of your assistance and hard work. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Monday, July 16, 2007 3:26 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... On 7/16/07, Lawrence Spector wrote: > I'm using Visual Studio 2005 (8). I've spent a significant amount of time trying to get Py++ working, and while I've made progress, this one has had me at its mercy. I've spent days trying to stub out what GCCXML complains about, but each time I stub out a file, I get more errors in the next one and it just goes down the chain. > > Here's what I've done to demonstrate. There's a sample cpp file, for demonstration, called TestPy++.cpp. This was processed using pyplusplus_gui.pyw. The code is as follows: > :-( The truthful answer: GCCXML is too weak to compile code from Boost.Python library on Windows :-((((. Basically there is no "user-space" work around. I am working on integrating another back-end( compiler) to pygccxml, but it will take some time untill it will become "production-ready". The "good" news is that some of the boost libraries treat GCCXML as another compiler and introduce work-around. Another good news is that according to this regression results( http://engineering.meta-comm.com/boost-regression/1_34_0/user/mpl_release.html ) MPL compiles fine under the MinGW ( GCC on Windows ) so may be you will be able to find some define that will allow you to compiler the library. It also worse to report the problem to Boost developers. May be they will help you and tweak their code. -- 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 From Lawrence.Spector at CanfieldSci.com Mon Jul 16 22:17:52 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 16:17:52 -0400 Subject: [C++-sig] Py++ GUI - Bad file descriptor Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> I've been getting this a lot while running with the Py++ GUI lately (mostly today): Error occurred during code generation process! Error: [Errno 9] Bad file descriptor Wasn't sure if this was a known issue or not, but it's happening fairly frequently and I'm not 100% sure what's causing it. Thanks, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lawrence.Spector at CanfieldSci.com Mon Jul 16 22:38:38 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 16:38:38 -0400 Subject: [C++-sig] Py++ - Another GCCXML issue -- GCCXML ignoring defines/issue with exception specifications Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB226D@Pan.domain-01> I have a header file where I define something to the effect of the following: #define THROW_1(X) throw(X) In another header I use it: class MyClass : public ClassWithExceptSpec { public: void myMethod() THROW_1(MyExcept); }; It actually gives me a syntax error at the line of the method declaration. I also tried defining directly from the Py++ Gui, same result. If I replace the usage of THROW_1(MyExcept) to throw(MyExcept), like so: void myMethod() throw(MyExcept); then all is good. I can't explain this behavior, except as a bug. Have anyone encountered this before? Another quirk to add to this. If I #define THROW_1(X) throw(X) in the same file, I get the bad file descriptor issue repeatedly. =( Thanks, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From johan2sson at gmail.com Mon Jul 16 23:04:07 2007 From: johan2sson at gmail.com (Johan Johansson) Date: Mon, 16 Jul 2007 23:04:07 +0200 Subject: [C++-sig] unresolved docstring_options symbols with boost::python 1.34.0 using msvc 8 and 9 Message-ID: Hi I'm having some problems moving from boost 1.33.1 to 1.34.0. More specifically my python extension isn't linking anymore: > Searching W:\boost_1_34_0\stage\lib\boost_python-vc80-mt.lib: >Finished searching libraries >MagicMarker.obj : error LNK2001: unresolved external symbol "private: >static bool volatile boost::python::docstring_options::show_user_defined_" >(?show_user_defined_ at docstring_options@python at boost@@0_NC) >MagicMarker.obj : error LNK2001: unresolved external symbol "private: >static bool volatile boost::python::docstring_options::show_signatures_" >(?show_signatures_ at docstring_options@python at boost@@0_NC) That seems to be statistics however: W:\boost_1_34_0\bin.v2\libs\python\build\msvc-8.0\debug>dumpbin /symbols function.obj | findstr docstring ... 1B4 00000004 SECT7 notype External | ?show_user_defined_ at docstring_options@python at boost@@0_NC (private: static bool volatile boost::python::docstring_options::show_user_defined_) 1B5 00000005 SECT7 notype External | ?show_signatures_ at docstring_options@python at boost@@0_NC (private: static bool volatile boost::python::docstring_options::show_signatures_) ... W:\boost_1_34_0\stage\lib>dumpbin /exports boost_python-vc80-mt.lib | findstr docstring_options ... ?show_signatures_ at docstring_options@python at boost@@0_NC (private: static bool volatile boost::python::docstring_options::show_signatures_) ?show_user_defined_ at docstring_options@python at boost@@0_NC (private: static bool volatile boost::python::docstring_options::show_user_defined_) ... Any ideas? j -------------- next part -------------- An HTML attachment was scrubbed... URL: From Lawrence.Spector at CanfieldSci.com Tue Jul 17 00:10:31 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 16 Jul 2007 18:10:31 -0400 Subject: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> Here's another issue I'm having. I have the following class: #pragma once #include #include class TestClass { private: std::ostream& m_outStream; int m_x; float m_y; char m_z; public: TestClass() : m_outStream(std::cout), m_x(0), m_y(0), m_z(0) {} TestClass(std::ostream& p_outStream, int p_x, float p_y, char p_z) : m_outStream(p_outStream), m_x(p_x), m_y(p_y), m_z(p_z) { std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end TestClass ~TestClass() { std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end TestClass virtual void output() { m_outStream << "x = " << m_x << ", y = " << m_y << ", z = " << m_z << "\n"; std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end callMethod }; // end TestClass Py++ successfully generated the following: namespace bp = boost::python; struct TestClass_wrapper : TestClass, bp::wrapper< TestClass > { TestClass_wrapper( ) : TestClass( ) , bp::wrapper< TestClass >(){ // null constructor } TestClass_wrapper(::std::ostream & p_outStream, int p_x, float p_y, char p_z ) : TestClass( boost::ref(p_outStream), p_x, p_y, p_z ) , bp::wrapper< TestClass >(){ // constructor } virtual void output( ) { if( bp::override func_output = this->get_override( "output" ) ) func_output( ); else this->TestClass::output( ); } void default_output( ) { TestClass::output( ); } }; BOOST_PYTHON_MODULE(PythonInterface){ bp::class_< TestClass_wrapper, boost::noncopyable >( "TestClass" ) .def( bp::init< >() ) .def( bp::init< std::ostream &, int, float, char >(( bp::arg("p_outStream"), bp::arg("p_x"), bp::arg("p_y"), bp::arg("p_z") )) ) .def( "output" , &::TestClass::output , &TestClass_wrapper::default_output ); } Great. I use it in the following way, as a simple test: TestClass testClass(std::cout, 3, 9.6f, 'Q'); boost::python::object pyTestClass(testClass); main_namespace[L"pyTestClass"] = pyTestClass; This throws with the following python error: Caught error_already_set TypeError: No to_python (by-value) converter found for C++ type: class TestClass Any ideas what steps I've missed? I've successfully built a few python extensions without using Boost.Python, but never successfully using a wrapper. Am I missing something? Thanks, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Jul 17 06:52:10 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 07:52:10 +0300 Subject: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2267@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> <7465b6170707161226p4b516d69y57b364b1b90a6da9@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2267@Pan.domain-01> Message-ID: <7465b6170707162152j7420dd99k875a44ca14f478f2@mail.gmail.com> On 7/16/07, Lawrence Spector wrote: > Hmm... thanks for your quick and honest answer. I'm disappointed to hear this. It's unfortunate that there's no way to tell GCCXML to ignore any errors and just process whatever it figured out, even if it's not a 100% complete set. > > I guess it's going to come down to doing some major stubbing before it even gets into the boost header files. > > Out of curiosity, you said that it's too weak to compile code from Boost.Python on Windows. I may be being overly optimistic, but I thought you might be implying that it might work on another platform, like Linux? I have a Linux box at my desk if this is an option. Well, this is the trick I use when I have problem like this. Take a look on boost::date_time example( http://tinyurl.com/3d9fwz ). I generated XML file on Linux, but than I could use it on Windows. The bad news is that in this case it will not work on Linux too :-( -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 17 06:53:45 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 07:53:45 +0300 Subject: [C++-sig] Py++ GUI - Bad file descriptor In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> Message-ID: <7465b6170707162153s38312834kfc5aa29058e48f74@mail.gmail.com> On 7/16/07, Lawrence Spector wrote: > > I've been getting this a lot while running with the Py++ GUI lately (mostly > today): > > Error occurred during code generation process! > > Error: > > [Errno 9] Bad file descriptor > > > > Wasn't sure if this was a known issue or not, but it's happening fairly > frequently and I'm not 100% sure what's causing it. This is the first time I hear about this error. Can you create small example that reproduce the error? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 17 06:59:25 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 07:59:25 +0300 Subject: [C++-sig] Py++ - Another GCCXML issue -- GCCXML ignoring defines/issue with exception specifications In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB226D@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB226D@Pan.domain-01> Message-ID: <7465b6170707162159m76bb03a8oc5824d48e713deb2@mail.gmail.com> On 7/16/07, Lawrence Spector wrote: > I have a header file where I define something to the effect of the > following: > > #define THROW_1(X) throw(X) > In another header I use it: > > class MyClass : public ClassWithExceptSpec > { > public: > > void myMethod() THROW_1(MyExcept); > > }; > > > > It actually gives me a syntax error at the line of the method declaration. > I also tried defining directly from the Py++ Gui, same result. There is something else that cause this issue. I just tried your example and it works as expected. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 17 07:23:06 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 08:23:06 +0300 Subject: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> Message-ID: <7465b6170707162223x38b59b23i5c00e21581d1206@mail.gmail.com> On 7/17/07, Lawrence Spector wrote: > Any ideas what steps I've missed? I've successfully built a few python > extensions without using Boost.Python, but never successfully using a > wrapper. Am I missing something? > You didn't expose std::ostream class. So, when Boost.Python tries to create an instance of your class in Python, it sees some argument type it cannot treat. As a result, you've got an exception. If you intend to create all your class instance in C++ than you can exclude constructors. In this case may be you can pass your object by reference, I am not sure whether this will work: TestClass testClass(std::cout, 3, 9.6f, 'Q'); boost::python::object pyTestClass(boost::ref( testClass) ); -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From ndbecker2 at gmail.com Tue Jul 17 15:42:25 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 Jul 2007 09:42:25 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) Message-ID: I want to call a python iterable from c++. Can I do this? while (true) { T n = extract (o.attr ("next")()); tmp.push_back (n); } How do I (can I?) catch the StopIteration exception? From seefeld at sympatico.ca Tue Jul 17 15:53:35 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 17 Jul 2007 09:53:35 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) In-Reply-To: References: Message-ID: <469CC9DF.3060509@sympatico.ca> Neal Becker wrote: > I want to call a python iterable from c++. Can I do this? > while (true) { > T n = extract (o.attr ("next")()); > tmp.push_back (n); > } > > How do I (can I?) catch the StopIteration exception? Assuming boost.python does not have special provisions for any particular exception type you'd need to catch error_already_set and then query (using the python C API) the exact exception type in order to break out of the loop. It would be worthwhile thinking about better handling of this (as well as adding more exception-related APIs) for 1.35... Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From ndbecker2 at gmail.com Tue Jul 17 16:00:59 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 Jul 2007 10:00:59 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) References: <469CC9DF.3060509@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Neal Becker wrote: >> I want to call a python iterable from c++. Can I do this? >> while (true) { >> T n = extract (o.attr ("next")()); >> tmp.push_back (n); >> } >> >> How do I (can I?) catch the StopIteration exception? > > Assuming boost.python does not have special provisions for > any particular exception type you'd need to catch error_already_set > and then query (using the python C API) the exact exception type in > order to break out of the loop. > It would be worthwhile thinking about better handling of this (as > well as adding more exception-related APIs) for 1.35... > > Regards, > Stefan > Interestingly, this _seems_ to work: try { while (true) { o.attr ("next")()... } } catch (error_already_set) { use result.. } From seefeld at sympatico.ca Tue Jul 17 16:05:55 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 17 Jul 2007 10:05:55 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) In-Reply-To: References: <469CC9DF.3060509@sympatico.ca> Message-ID: <469CCCC3.3000307@sympatico.ca> Neal Becker wrote: > Interestingly, this _seems_ to work: > > try { > while (true) { > o.attr ("next")()... > } > } > catch (error_already_set) { > use result.. > } Yes, it should. Though you will also break out of the loop for other exceptions (which you may want to deal with within the loop...). Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From adrien-ml at wizzi.net Tue Jul 17 16:14:49 2007 From: adrien-ml at wizzi.net (Adrien Saladin) Date: Tue, 17 Jul 2007 16:14:49 +0200 Subject: [C++-sig] [Py++] const-overloading: how to use it ? Message-ID: <200707171614.49714.adrien-ml@wizzi.net> Hi, I have a C++ class that returns reference to internal data. For this I'm using two "get" functions, one returning const and one returning non-const (see below for the explicit code) I'm not sure how I should import them with boost python (and py++). Can both functions (const and non-const) be imported ? This probably doesn't make sense for python ? Thanks, Adrien //-------- this is a code showing what I would like to import : ---- #include #include using std::string ; class A { public: A(string s){mVstr.push_back(s);}; string& getC(uint i) {return mVstr[i]; }; const string& getC(uint i) const {return mVstr[i]; }; private: std::vector mVstr ; }; From ndbecker2 at gmail.com Tue Jul 17 16:31:43 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 Jul 2007 10:31:43 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) References: <469CC9DF.3060509@sympatico.ca> <469CCCC3.3000307@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Neal Becker wrote: > >> Interestingly, this _seems_ to work: >> >> try { >> while (true) { >> o.attr ("next")()... >> } >> } >> catch (error_already_set) { >> use result.. >> } > > Yes, it should. Though you will also break out of the loop for other > exceptions (which you may want to deal with within the loop...). > > Regards, > Stefan > Maybe like this? try { while (true) { T n = extract (o.attr ("next")()); tmp.push_back (n); } } catch (error_already_set) { if (!PyErr_ExceptionMatches (PyExc_StopIteration)) throw_error_already_set(); ... } From Lawrence.Spector at CanfieldSci.com Tue Jul 17 16:34:36 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 17 Jul 2007 10:34:36 -0400 Subject: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ In-Reply-To: <7465b6170707162223x38b59b23i5c00e21581d1206@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> <7465b6170707162223x38b59b23i5c00e21581d1206@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB228A@Pan.domain-01> Ok, I've been playing with it some more, still not getting everything to work though. I tried the things you said; it still wasn't working. I took out the constructors from the python interface and added shared_ptr support. I then pass the shared_ptr through. It still doesn't work upon creating the object -- it throws an exception, saying that there's no converter. TestClass: #pragma once #include #include class TestClass { private: std::ostream& m_outStream; int m_x; float m_y; char m_z; public: TestClass() : m_outStream(std::cout), m_x(0), m_y(0), m_z(0) {} TestClass(std::ostream& p_outStream, int p_x, float p_y, char p_z) : m_outStream(p_outStream), m_x(p_x), m_y(p_y), m_z(p_z) { std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end TestClass ~TestClass() { std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end TestClass virtual void output() { m_outStream << "x = " << m_x << ", y = " << m_y << ", z = " << m_z << "\n"; std::cout << __FUNCTION__ << " called. this = " << this << std::endl; } // end callMethod }; // end TestClass The wrapper: struct TestClass_wrapper : TestClass, bp::wrapper< TestClass > { TestClass_wrapper( ) : TestClass( ) , bp::wrapper< TestClass >(){ // null constructor } TestClass_wrapper(int p_x, float p_y, char p_z ) : TestClass( boost::ref(std::cout), p_x, p_y, p_z ) , bp::wrapper< TestClass >(){ // constructor } virtual void output( ) { if( bp::override func_output = this->get_override( "output" ) ) func_output( ); else this->TestClass::output( ); } void default_output( ) { TestClass::output( ); } }; The Boost.Build Python extension code: #include #include #include #include "TestClass.hpp" #include "TestClassWrap.hpp" namespace bp = boost::python; BOOST_PYTHON_MODULE(PythonInterface){ bp::class_< TestClass_wrapper, boost::shared_ptr, boost::noncopyable >( "TestClass" ) // .def( bp::init< >() ) // .def( bp::init< int, float, char >(( bp::arg("p_x"), bp::arg("p_y"), bp::arg("p_z") )) ) .def( "output" , &::TestClass::output , &TestClass_wrapper::default_output ); } #include #include "TestClass.hpp" #include "TestClassWrap.hpp" #include using namespace boost::python; class Deleter { public: template void operator()(T&) { } }; int main() { try { Py_Initialize(); object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); { handle<> ignored((PyRun_String( "import PythonInterface\n" "print dir(PythonInterface)\n" "print 'HELLO'\n" , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); } TestClass testClass(std::cout, 3, 9.6f, 'Q'); boost::shared_ptr pTestClass(&testClass, Deleter()); boost::python::object pyTestClass(pTestClass); main_namespace[L"pyTestClass"] = pyTestClass; std::cout << "### Calling pyTestClass.attr(\"output\")()" << std::endl; pyTestClass.attr("output")(); std::cout << "### Calling exec(\"pyTestClass.output()\")" << std::endl; { object result = exec( // Works: "pyTestClass = PythonInterface.TestClass(6, 8.3, 'W')\n" "pyTestClass.output()\n", main_namespace, main_namespace); } std::cout << "### Calling testClassWrapper.output()" << std::endl; // testClassWrapper.output(); std::cout << "### Calling testClass.output()" << std::endl; testClass.output(); } catch(boost::python::error_already_set& e) { std::cerr << "Caught error_already_set" << std::endl; if (PyErr_Occurred() != 0) { PyErr_Print(); } // end if } catch(...) { std::cerr << "Caught unknown error" << std::endl; } // end try-catch std::cin.get(); return 0; } // end main Output: ['TestClass', '__doc__', '__file__', '__name__'] HELLO TestClass::TestClass called. this = 0012FF1C TestClass::~TestClass called. this = 0012FF1C Caught error_already_set TypeError: No to_python (by-value) converter found for C++ type: class boost::shared_ptr This is very frustrating. All I want to do is be able to expose classes, create some instances in C++ and use the instances in both C++ and Python. In addition, I want to create some instances in Python, and use those instances from Python and C++. It seems like the wrappers pose a huge problem; I just can't seem to get things working reliably when there's a wrapper involved. I also haven't found enough documentation on the Boost.Python system available in order to get started and be able to actually make use of the system. Any help you can provide would be greatly appreciated. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, July 17, 2007 1:23 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ On 7/17/07, Lawrence Spector wrote: > Any ideas what steps I've missed? I've successfully built a few python > extensions without using Boost.Python, but never successfully using a > wrapper. Am I missing something? > You didn't expose std::ostream class. So, when Boost.Python tries to create an instance of your class in Python, it sees some argument type it cannot treat. As a result, you've got an exception. If you intend to create all your class instance in C++ than you can exclude constructors. In this case may be you can pass your object by reference, I am not sure whether this will work: TestClass testClass(std::cout, 3, 9.6f, 'Q'); boost::python::object pyTestClass(boost::ref( testClass) ); -- 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 From duranlef at iro.umontreal.ca Tue Jul 17 17:13:46 2007 From: duranlef at iro.umontreal.ca (=?ISO-8859-1?Q?Fran=E7ois_Duranleau?=) Date: Tue, 17 Jul 2007 11:13:46 -0400 (EDT) Subject: [C++-sig] call python iterable (handle StopIteration?) In-Reply-To: References: Message-ID: On Tue, 17 Jul 2007, Neal Becker wrote: > I want to call a python iterable from c++. Can I do this? > while (true) { > T n = extract (o.attr ("next")()); > tmp.push_back (n); > } > > How do I (can I?) catch the StopIteration exception? You can also try to use boost::python::stl_input_iterator (from 1.34), e.g.: // here it assumed that the object o is not the iterator object itself but // the iterable objet, that is, an object with a method __iter__ for( stl_input_iterator< T > begin( o ) , end ; begin != end ; ++ begin ) { tmp.push_back( * begin ) ; } or std::copy( stl_input_iterator< T >( o ) , stl_input_iterator< T >() , std::back_inserter( tmp ) ) ; For more info: http://www.boost.org/libs/python/doc/v2/stl_iterator.html -- Fran??ois Duranleau LIGUM, Universit?? de Montr??al From ndbecker2 at gmail.com Tue Jul 17 18:45:56 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 Jul 2007 12:45:56 -0400 Subject: [C++-sig] call python iterable (handle StopIteration?) References: Message-ID: Fran?ois Duranleau wrote: > On Tue, 17 Jul 2007, Neal Becker wrote: > >> I want to call a python iterable from c++. Can I do this? >> while (true) { >> T n = extract (o.attr ("next")()); >> tmp.push_back (n); >> } >> >> How do I (can I?) catch the StopIteration exception? > > You can also try to use boost::python::stl_input_iterator (from 1.34), > e.g.: > > // here it assumed that the object o is not the iterator object itself but > // the iterable objet, that is, an object with a method __iter__ > for( stl_input_iterator< T > begin( o ) , end ; > begin != end ; > ++ begin ) > { > tmp.push_back( * begin ) ; > } > > or > > std::copy( stl_input_iterator< T >( o ) , > stl_input_iterator< T >() , > std::back_inserter( tmp ) ) ; > > For more info: http://www.boost.org/libs/python/doc/v2/stl_iterator.html > Nice! From roman.yakovenko at gmail.com Tue Jul 17 19:30:41 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 20:30:41 +0300 Subject: [C++-sig] [Py++] const-overloading: how to use it ? In-Reply-To: <200707171614.49714.adrien-ml@wizzi.net> References: <200707171614.49714.adrien-ml@wizzi.net> Message-ID: <7465b6170707171030r1ceb24f5p76480cb7f96f227@mail.gmail.com> On 7/17/07, Adrien Saladin wrote: > Hi, > > I have a C++ class that returns reference to internal data. For this I'm using > two "get" functions, one returning const and one returning non-const (see > below for the explicit code) > > I'm not sure how I should import them with boost python (and py++). Can both > functions (const and non-const) be imported ? This probably doesn't make > sense for python ? > > Thanks, > Adrien > > > //-------- this is a code showing what I would like to import : ---- > #include > #include > using std::string ; > > class A > { > public: > A(string s){mVstr.push_back(s);}; > > string& getC(uint i) {return mVstr[i]; }; > const string& getC(uint i) const {return mVstr[i]; }; Well in most cases, it really doesn't make sense. This case is a little bit different, in a sense that it doesn't matter what function you are going to expose, the result will be same. ( hint: Python string is immutable type ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 17 20:14:37 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 17 Jul 2007 21:14:37 +0300 Subject: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB228A@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> <7465b6170707162223x38b59b23i5c00e21581d1206@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB228A@Pan.domain-01> Message-ID: <7465b6170707171114g2e05b24fo6082623c9f30b88b@mail.gmail.com> On 7/17/07, Lawrence Spector wrote: > Ok, I've been playing with it some more, still not getting everything to work though. I tried the things you said; it still wasn't working. I took out the constructors from the python interface and added shared_ptr support. I then pass the shared_ptr through. It still doesn't work upon creating the object -- it throws an exception, saying that there's no converter. I am not sure why your code doesn't work, try to use register_ptr_to_python functionality( http://boost.org/libs/python/doc/v2/register_ptr_to_python.html ) Also did you try boost::ref and boost::python::ptr functionality? I also suggest you to use google :-) This is what I get when I searched for "boost.python share C++ instance" http://wiki.python.org/moin/boost.python/EmbeddingPython HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Tue Jul 17 21:43:46 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 17 Jul 2007 15:43:46 -0400 Subject: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ In-Reply-To: <7465b6170707171114g2e05b24fo6082623c9f30b88b@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B0316DB2272@Pan.domain-01> <7465b6170707162223x38b59b23i5c00e21581d1206@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB228A@Pan.domain-01> <7465b6170707171114g2e05b24fo6082623c9f30b88b@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB22A3@Pan.domain-01> Well, I tried to register_ptr_to_python functionality and it seems to work as long as a I make a modification to the class to make the Python exposed "A" also let boost::python know it inherits from boost::noncopyable. However, I noticed it never called the wrapper when done this way. I guess this makes sense, since it actually is an A in this case. I realized a major part of my problem was the use of Unicode, I think it was causing unpredictable behavior when a Unicode string was passed into Boost.Python. I'll have to go back and try some of the other things that I thought failed for a different reason but where actually failing when I did this: main_namespace[L"pyTestClass"] = ...; // Note the L when main_namespace["pyTestClass"] = ...; would work. Hmmm... anyway, I'm going to try to see how far I can get with this. Thanks for all of your help, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, July 17, 2007 2:15 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Can't get Boost.Python to use extensions generated and wrapped with Py++ On 7/17/07, Lawrence Spector wrote: > Ok, I've been playing with it some more, still not getting everything to work though. I tried the things you said; it still wasn't working. I took out the constructors from the python interface and added shared_ptr support. I then pass the shared_ptr through. It still doesn't work upon creating the object -- it throws an exception, saying that there's no converter. I am not sure why your code doesn't work, try to use register_ptr_to_python functionality( http://boost.org/libs/python/doc/v2/register_ptr_to_python.html ) Also did you try boost::ref and boost::python::ptr functionality? I also suggest you to use google :-) This is what I get when I searched for "boost.python share C++ instance" http://wiki.python.org/moin/boost.python/EmbeddingPython 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 From Lawrence.Spector at CanfieldSci.com Tue Jul 17 22:50:18 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 17 Jul 2007 16:50:18 -0400 Subject: [C++-sig] Py++ GUI - Bad file descriptor In-Reply-To: <7465b6170707162153s38312834kfc5aa29058e48f74@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> <7465b6170707162153s38312834kfc5aa29058e48f74@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB22A6@Pan.domain-01> I'll try to come up with a sample and possibly steps to reproduce when I get some time. Thanks, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, July 17, 2007 12:54 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ GUI - Bad file descriptor On 7/16/07, Lawrence Spector wrote: > > I've been getting this a lot while running with the Py++ GUI lately (mostly > today): > > Error occurred during code generation process! > > Error: > > [Errno 9] Bad file descriptor > > > > Wasn't sure if this was a known issue or not, but it's happening fairly > frequently and I'm not 100% sure what's causing it. This is the first time I hear about this error. Can you create small example that reproduce the error? -- 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 From Lawrence.Spector at CanfieldSci.com Tue Jul 17 22:51:30 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 17 Jul 2007 16:51:30 -0400 Subject: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... In-Reply-To: <7465b6170707162152j7420dd99k875a44ca14f478f2@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B03157F9857@Pan.domain-01> <7465b6170707111307u1d7eed7dtbf034675c5a985da@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03157F9860@Pan.domain-01> <8F737B3BFD630A4380BD0357481D4B03158A8943@Pan.domain-01> <7465b6170707121213k11092058ledbbf5c753f3a3c@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B03158A8967@Pan.domain-01> <7465b6170707121257s38908a1ar5451e28d236d10fe@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2249@Pan.domain-01> <7465b6170707161226p4b516d69y57b364b1b90a6da9@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB2267@Pan.domain-01> <7465b6170707162152j7420dd99k875a44ca14f478f2@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB22A7@Pan.domain-01> Gotcha. Interesting information. Thanks for the tips. -Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, July 17, 2007 12:52 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] [C++-Sig] Py++& GCCXML -- Many levels of compilation errors when compiling code that uses Boost, Microsoft Visual C++ headers, Python API, etc... On 7/16/07, Lawrence Spector wrote: > Hmm... thanks for your quick and honest answer. I'm disappointed to hear this. It's unfortunate that there's no way to tell GCCXML to ignore any errors and just process whatever it figured out, even if it's not a 100% complete set. > > I guess it's going to come down to doing some major stubbing before it even gets into the boost header files. > > Out of curiosity, you said that it's too weak to compile code from Boost.Python on Windows. I may be being overly optimistic, but I thought you might be implying that it might work on another platform, like Linux? I have a Linux box at my desk if this is an option. Well, this is the trick I use when I have problem like this. Take a look on boost::date_time example( http://tinyurl.com/3d9fwz ). I generated XML file on Linux, but than I could use it on Windows. The bad news is that in this case it will not work on Linux too :-( -- 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 From roman.yakovenko at gmail.com Wed Jul 18 06:59:32 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 18 Jul 2007 07:59:32 +0300 Subject: [C++-sig] Py++ GUI - Bad file descriptor In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB22A6@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> <7465b6170707162153s38312834kfc5aa29058e48f74@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB22A6@Pan.domain-01> Message-ID: <7465b6170707172159s792dc3e7sef90dc665133a7af@mail.gmail.com> On 7/17/07, Lawrence Spector wrote: > I'll try to come up with a sample and possibly steps to reproduce when I get some time. Consider to use -E option of gccxml. Thus you can create single file that includes all necessary information -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mapik.ua at gmail.com Wed Jul 18 13:53:33 2007 From: mapik.ua at gmail.com (Markiyan) Date: Wed, 18 Jul 2007 14:53:33 +0300 Subject: [C++-sig] Converting (unpickle) python dictionary into c++ map Message-ID: I have pickled python object as string, could I parse it with boost.python library? If so could you, please, provide some example? From achille.talon at gmail.com Wed Jul 18 14:32:07 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 18 Jul 2007 05:32:07 -0700 (PDT) Subject: [C++-sig] Py++ GUI - Bad file descriptor In-Reply-To: <7465b6170707172159s792dc3e7sef90dc665133a7af@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B0316DB226C@Pan.domain-01> <7465b6170707162153s38312834kfc5aa29058e48f74@mail.gmail.com> <8F737B3BFD630A4380BD0357481D4B0316DB22A6@Pan.domain-01> <7465b6170707172159s792dc3e7sef90dc665133a7af@mail.gmail.com> Message-ID: <11667732.post@talk.nabble.com> I also get this error quite often. It seems to happen when I get a lot of warnings or other outputs when I use the "console" way. Roman Yakovenko wrote: > > On 7/17/07, Lawrence Spector wrote: >> I'll try to come up with a sample and possibly steps to reproduce when I >> get some time. > > Consider to use -E option of gccxml. Thus you can create single file > that includes all necessary information > > > -- > 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 > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Py%2B%2B-GUI---Bad-file-descriptor-tf4090914.html#a11667732 Sent from the Python - c++-sig mailing list archive at Nabble.com. From Lawrence.Spector at CanfieldSci.com Wed Jul 18 21:10:53 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 18 Jul 2007 15:10:53 -0400 Subject: [C++-sig] PyErr_ExceptionMatches not working? Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB22EA@Pan.domain-01> I have code that checks the following (snippet) when an exception is thrown... if (PyErr_ExceptionMatches(PyExc_NameError)) { // do something... } It doesn't get into that block, yet, when I do this: PyErr_Fetch(&errObj, &errData, &errTraceback); std::cout << "Object error" << PyString_AsString(PyObject_Str(errObj)); I get: Object error: What gives? Why isn't PyErr_ExceptionMatches saying that it's a NameError? Does Boost.Python provide a better way to do exception handling than the Python API directly? Thanks, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From zzhao at laika.com Thu Jul 19 21:51:30 2007 From: zzhao at laika.com (ZiZi Zhao) Date: Thu, 19 Jul 2007 12:51:30 -0700 (PDT) Subject: [C++-sig] build boost.python with unusual gcc AND python paths Message-ID: <31951496.298711184874690167.JavaMail.root@zimbra01.laika.com> There are some standard installation in my system: /usr/bin/g++ is v3.4.x and python v2.4.4. There are also installed g++ v4.0.2 and python 2.5.1 installed. I want to build boost.python with g++_4.0.2 and python_2.5.1. But, bjam seems to be unfriendly to unusual paths of g++ and python. I have all -sGCC_ROOT_DIRECTORY, -sGCC_BIN_DIRECTORY, -sGCC -sPYTHON_ROOT, -sPYTHON_VERSION set for 'bjam' with my choices. However, every time when I tried to build boost.python with the unusual g++ and python, I saw bjam being very "smart" to tell me the information: "... you have python 2.4.4 at /... (the python 2.4.4 root)"; and using "g++-in-action" to compile and build everything. How can I make sure I got the Boost.Python from the right versions of g++ and python? Thanks in advance, Z.Z. _____________________________________________________________________ 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 ngoodspeed at solidworks.com Fri Jul 20 00:01:18 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Thu, 19 Jul 2007 18:01:18 -0400 Subject: [C++-sig] PyErr_ExceptionMatches not working? In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB22EA@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB22EA@Pan.domain-01> Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B701861511@corp-mail4.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Wednesday, July 18, 2007 3:11 PM To: Development of Python/C++ integration Subject: [C++-sig] PyErr_ExceptionMatches not working? I have code that checks the following (snippet) when an exception is thrown... if (PyErr_ExceptionMatches(PyExc_NameError)) { ?// do something... } It doesn't get into that block, yet, when I do this: PyErr_Fetch(&errObj, &errData, &errTraceback); std::cout << "Object error" << PyString_AsString(PyObject_Str(errObj)); I get: Object error: What gives?? Why isn't PyErr_ExceptionMatches saying that it's a NameError?? Does Boost.Python provide a better way to do exception handling than the Python API directly? [Nat] I'm unaware of any Boost.Python enhancements to Python exception handling, though I think I remember seeing a mail message indicating interest among the developers. Do you do your PyErr_Fetch() before your PyErr_ExceptionMatches()? Beware that fetching the Python exception clears the exception condition. Here's some code we use to print a Python exception without suppressing it: catch (error_already_set&) { PyObject *type, *value, *traceback; // Save the error state because PyErr_Print() is going to clear // it. That's not what we want. PyErr_Fetch(&type, &value, &traceback); // But whoops, PyErr_Fetch() just cleared the exception flag! If // we now call PyErr_Print(), it thinks there's nothing wrong, and // doesn't print anything! Immediately restore the exception so // PyErr_Print() will see it. PyErr_Restore(type, value, traceback); // Okay, print the traceback to stderr... PyErr_Print(); // then restore (again!) the original exception state. PyErr_Restore(type, value, traceback); // Propagate the exception. throw; } From Lawrence.Spector at CanfieldSci.com Fri Jul 20 00:13:12 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 19 Jul 2007 18:13:12 -0400 Subject: [C++-sig] PyErr_ExceptionMatches not working? In-Reply-To: <94F7A8DD4408D8499C6812FE42E2D4B701861511@corp-mail4.solidworks.swk> References: <8F737B3BFD630A4380BD0357481D4B0316DB22EA@Pan.domain-01> <94F7A8DD4408D8499C6812FE42E2D4B701861511@corp-mail4.solidworks.swk> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2340@Pan.domain-01> Ahh, I didn't realize that fetching caused the exception to clear. Now I've corrected it, done a quick test, and it works. Thanks for the help, Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nat Goodspeed Sent: Thursday, July 19, 2007 6:01 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] PyErr_ExceptionMatches not working? ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Lawrence Spector Sent: Wednesday, July 18, 2007 3:11 PM To: Development of Python/C++ integration Subject: [C++-sig] PyErr_ExceptionMatches not working? I have code that checks the following (snippet) when an exception is thrown... if (PyErr_ExceptionMatches(PyExc_NameError)) { // do something... } It doesn't get into that block, yet, when I do this: PyErr_Fetch(&errObj, &errData, &errTraceback); std::cout << "Object error" << PyString_AsString(PyObject_Str(errObj)); I get: Object error: What gives? Why isn't PyErr_ExceptionMatches saying that it's a NameError? Does Boost.Python provide a better way to do exception handling than the Python API directly? [Nat] I'm unaware of any Boost.Python enhancements to Python exception handling, though I think I remember seeing a mail message indicating interest among the developers. Do you do your PyErr_Fetch() before your PyErr_ExceptionMatches()? Beware that fetching the Python exception clears the exception condition. Here's some code we use to print a Python exception without suppressing it: catch (error_already_set&) { PyObject *type, *value, *traceback; // Save the error state because PyErr_Print() is going to clear // it. That's not what we want. PyErr_Fetch(&type, &value, &traceback); // But whoops, PyErr_Fetch() just cleared the exception flag! If // we now call PyErr_Print(), it thinks there's nothing wrong, and // doesn't print anything! Immediately restore the exception so // PyErr_Print() will see it. PyErr_Restore(type, value, traceback); // Okay, print the traceback to stderr... PyErr_Print(); // then restore (again!) the original exception state. PyErr_Restore(type, value, traceback); // Propagate the exception. throw; } _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From kanand at qualcomm.com Fri Jul 20 02:46:06 2007 From: kanand at qualcomm.com (Anand, Kumar) Date: Thu, 19 Jul 2007 17:46:06 -0700 Subject: [C++-sig] Py++: ArgumentError during calling a function of base clas Message-ID: Hi, I have been getting errors like this: Any idea why this is happening and how to debug it further? 'evTest' is a class that definitely derives from OMEvent and the relationship has been exposed to Python as well: ArgumentError: Python argument types in OMEvent.getSynchronous(evTest) did not match C++ signature: getSynchronous(OMEvent {lvalue}) The complete code is as follows: ----------------------------------------------------------- C++ code: //abstract class. all functions are pure virtual class IOxfEvent { virtual bool getSynchronous() const=0; }; //abstract class. all functions are pure virtual class IOxfTimeout : public IOxfEvent { //other pure virtual functions }; //concrete class but an object of this class is never created. //provides default implementation of the interfaces listed above class OMEvent : public IOxfTimeout { bool getSynchronous() const; }; //final concrete class class evTest : public OMEvent { }; ------------------------------------------------------------------------ Boost Python bindings: bp::class_< IOxfEvent, std::auto_ptr, boost::noncopyable >( "IOxfEvent", bp::no_init ) .def("getId", &IOxfEvent::getId) .def("isTypeOf", &IOxfEvent::isTypeOf); typedef bp::class_< IOxfTimeout, bp::bases< IOxfEvent >, std::auto_ptr , boost::noncopyable > IOxfTimeout_exposer_t; IOxfTimeout_exposer_t IOxfTimeout_exposer = IOxfTimeout_exposer_t( "IOxfTimeout", bp::no_init ); IOxfTimeout_exposer.def("getDelayTime", &IOxfTimeout::getDelayTime); bp::class_< OMEvent, bp::bases< IOxfTimeout >, std::auto_ptr >( "OMEvent", bp::init< bp::optional< short int, IOxfReactive * > >(( bp::arg("eventId")=(short int)(0), bp::arg("dest")=bp::object() )) ) .def("getSynchronous", &OMEvent::getSynchronous); //evTest is exposed to python using Py++. I am pasting only the relevant code. struct evTest_wrapper : evTest, bp::wrapper< evTest > { }; typedef bp::class_< evTest_wrapper, bp::bases< OMEvent >, std::auto_ptr > evTest_exposer_t; ------------------------------------------------------------------------ Thanks Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Fri Jul 20 12:11:41 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 20 Jul 2007 13:11:41 +0300 Subject: [C++-sig] Py++: ArgumentError during calling a function of base clas In-Reply-To: References: Message-ID: <7465b6170707200311o31b181deyd48ab8eb2229b47@mail.gmail.com> On 7/20/07, Anand, Kumar wrote: > Hi, > > I have been getting errors like this: Any idea why this is happening and how > to debug it further? 'evTest' is a class that definitely derives from > OMEvent and the relationship has been exposed to Python as well: > > ArgumentError: Python argument types in > > OMEvent.getSynchronous(evTest) > > did not match C++ signature: > > getSynchronous(OMEvent {lvalue}) It seems that you pass, for some reason one argument, when the function doesn't take any argument. If evTest is instance of OMEvent, than try next code: evTest.getSynchronous() -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pwinston at gmail.com Mon Jul 23 01:01:56 2007 From: pwinston at gmail.com (Philip Winston) Date: Sun, 22 Jul 2007 19:01:56 -0400 Subject: [C++-sig] self-contained embedding Message-ID: <33677e5d0707221601s4e2f4d1asd44858b4076e1d9a@mail.gmail.com> We're embedding python into a windows app. We want our interpreter to be self-contained, to use only the modules we provide in a .zip. Mainly we want it to be okay to use our product if no version of python is installed, but also to be unaffected by any version of python which is installed in case it's a different version or altered. Is there a way to accomplish this via the API? The Python/C API reference manual says "An application that requires total control has to provide its own implementation of Py_GetPath(), Py_GetPrefix(), Py_GetExecPrefix(), and Py_GetProgramFullPath() (all defined in Modules/getpath.c)." And I saw some old message implying this was necessary in various cases. To me naively it seems like a self-contained interpreter would be common situation, so I wanted to double check there wasn't an easy way to do this that I'm missing. If providing our own implementations was needed, would we just maintain a local version of getpath.c or is there some trick to insert your own implementations? Thanks! -Philip From meine at informatik.uni-hamburg.de Mon Jul 23 19:22:15 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 23 Jul 2007 19:22:15 +0200 Subject: [C++-sig] How about class_<...>.enable_copy() ? In-Reply-To: <200706081706.37240.meine@informatik.uni-hamburg.de> References: <200706081706.37240.meine@informatik.uni-hamburg.de> Message-ID: <200707231922.15574.meine@informatik.uni-hamburg.de> Hi! I still have the same problem as last time, that I want to be able to copy.copy(foo) and copy.deepcopy(foo) my BPL-exported objects: Am Freitag, 08. Juni 2007 17:06:36 schrieb Hans Meine: > This works if pickling support has been explicitly coded, by pickling and > unpickling. It would be neat if there was an .enable_copy() or sth. like > that, which would define a __copy__ (or __deepcopy__) method that simply > calls the copy constructor. That would be more efficient than the pickling > approach, both at runtime and in terms of saved LOCs. Have you thought > about such a thing? Is there a common short idiom that does that already? > Is there a rationale for not providing copying support? Ralf answered (thanks BTW) that I should export the copy constructor. I think that is not a bad idea, but I would ideally like to have: foo = Foo(other) # copy constructor as in C++ (1) foo = copy.copy(other) # pythonic copying (2) foo = copy.deepcopy(other) # deepcopying (3) (1) is easy to do by exporting the copy constructor (2) could be implemented by setting __copy__ to the above copy constructor, but one would assume __dict__ to be (non-deep)copied, too. (3) definitely needs its own implementation, which needs to call deepcopy recursively. I would still believe that an .enable_copy() would be very handy. It could possibly be controlled by an enum arg which of the above methods should be exported. I tried to implement (2) and (3) manually today, but failed. Mostly because I am not 100% sure how to mix Python C API and BPL code correctly. I have the following general questions: A) How do I convert a Foo * into a boost::python::object if I exported the Foo class? Back in those days when I first used BPLv2, I wrote the following "nifty" function: template inline PyObject * managingPyObject(T *p) { return typename manage_new_object::apply::type()(p); } Is there a better way? Also, this only gives me a PyObject *, which brings me to my next question: B) How do I convert PyObject * into a boost::python::object if it's a new reference? Is this boost::python::detail::new_reference? Why is this in "detail" then? C) How do I convert PyObject * into a boost::python::object if it's a borrowed reference? I guess that handle(borrowed(...)) helps here? Finally, I wonder whether nobody else tried to implement __deepcopy__ with BPL yet - I could not find anything useful, searching the WWW for >2 hours now. I tried to get the copy.deepcopy function which I need to call recursively like this: PyObject* pyDeepcopy = PyRun_String("import copy\ncopy.deepcopy", Py_file_input, Py_None, Py_None); ... bp::extract(result.attr("__dict__"))().update( bp::call(pyDeepcopy, map.attr("__dict__"), memo)); Unfortunatly, with empty globals and locals, __import__ is not found. :-( Probably I should use PyImport_ImportModule or the new boost::python::import. That seems to work, but the recursive call then fails: File "/software/python-2.4.4/lib/python2.4/copy.py", line 185, in deepcopy y = copier(x, memo) TypeError: No to_python (by-value) converter found for C++ type: boost::python::api::proxy The code (which relies on 1.34.0) now looks like this (see attachment): bp::object Foo__deepcopy__(bp::object foo, bp::dict memo) { bp::object copyMod = bp::import("copy"); bp::object deepcopy = copyMod.attr("deepcopy"); Foo *newFoo(new Foo(bp::extract(foo))); bp::object result(bp::detail::new_reference(managingPyObject(newFoo))); bp::extract(result.attr("__dict__"))().update( deepcopy(foo.attr("__dict__"), memo)); return result; } -- Ciao, / / /--/ / / ANS -------------- next part -------------- A non-text attachment was scrubbed... Name: foo_copying.cxx Type: text/x-c++src Size: 838 bytes Desc: not available URL: From t_spens at yahoo.com Mon Jul 23 20:30:27 2007 From: t_spens at yahoo.com (Tim Spens) Date: Mon, 23 Jul 2007 11:30:27 -0700 (PDT) Subject: [C++-sig] wrapping a vector data member In-Reply-To: <200707231922.15574.meine@informatik.uni-hamburg.de> Message-ID: <156241.43938.qm@web43145.mail.sp1.yahoo.com> I'm not sure why I'm getting this error from the follownig code? // data member from sig_zapv class std::vector zaps_; //boost python wrapper part class_ >("sig_zapv") .def(init<>()) .def(vector_indexing_suite >()); //error ../../SDK/boost_1_33_1/boost/python/with_custodian_and_ward.hpp: In static member function `static PyObject* boost::python::with_custodian_and_ward_postcall::postcall(const ArgumentPackage&, PyObject*) [with ArgumentPackage = PyObject*, unsigned int custodian = 0, unsigned int ward = 1, BasePolicy_ = boost::python::default_call_policies]': ../../SDK/boost_1_33_1/boost/python/detail/caller.hpp:201: instantiated from `PyObject* boost::python::detail::caller_arity<1>::impl::operator()(PyObject*, PyObject*) [with F = boost::python::objects::iterator_range, __gnu_cxx::__normal_iterator > > >::next, Policies = boost::python::return_internal_reference<1, boost::python::default_call_policies>, Sig = boost::mpl::vector2, __gnu_cxx::__normal_iterator > > >&>]' ../../SDK/boost_1_33_1/boost/python/object/py_function.hpp:38: instantiated from `PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller, __gnu_cxx::__normal_iterator > > >::next, boost::python::return_internal_reference<1, boost::python::default_call_policies>, boost::mpl::vector2, __gnu_cxx::__normal_iterator > > >&> >]' ../../SDK/boost_1_33_1/boost/python/object/make_instance.hpp:32: instantiated from here ../../SDK/boost_1_33_1/boost/python/with_custodian_and_ward.hpp:87: warning: comparison of unsigned expression < 0 is always false make[1]: *** [wrapper.o] Error 1 ____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting From kanand at qualcomm.com Mon Jul 23 22:34:11 2007 From: kanand at qualcomm.com (Anand, Kumar) Date: Mon, 23 Jul 2007 13:34:11 -0700 Subject: [C++-sig] Py++: ArgumentError during calling a function of baseclas In-Reply-To: <7465b6170707200311o31b181deyd48ab8eb2229b47@mail.gmail.com> Message-ID: Yes I am doing exactly what you suggested. I get that error message when I call "evTest.getSynchronous()" Thanks Kumar -----Original Message----- From: c++-sig-bounces+kanand=qualcomm.com at python.org [mailto:c++-sig-bounces+kanand=qualcomm.com at python.org] On Behalf Of Roman Yakovenko Sent: Friday, July 20, 2007 3:12 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++: ArgumentError during calling a function of baseclas On 7/20/07, Anand, Kumar wrote: > Hi, > > I have been getting errors like this: Any idea why this is happening and how > to debug it further? 'evTest' is a class that definitely derives from > OMEvent and the relationship has been exposed to Python as well: > > ArgumentError: Python argument types in > > OMEvent.getSynchronous(evTest) > > did not match C++ signature: > > getSynchronous(OMEvent {lvalue}) It seems that you pass, for some reason one argument, when the function doesn't take any argument. If evTest is instance of OMEvent, than try next code: evTest.getSynchronous() -- 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 From meine at informatik.uni-hamburg.de Mon Jul 23 22:56:57 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 23 Jul 2007 22:56:57 +0200 Subject: [C++-sig] How about class_<...>.enable_copy() ? In-Reply-To: <200707231922.15574.meine@informatik.uni-hamburg.de> References: <200706081706.37240.meine@informatik.uni-hamburg.de> <200707231922.15574.meine@informatik.uni-hamburg.de> Message-ID: <200707232257.05883.meine@informatik.uni-hamburg.de> Hi again! I got it working now! (Still, I would be glad if you answered my questions from my last mail and told me of possible better ways to achieve this.) On Montag 23 Juli 2007, Hans Meine wrote: > foo = Foo(other) # copy constructor as in C++ (1) > foo = copy.copy(other) # pythonic copying (2) > foo = copy.deepcopy(other) # deepcopying (3) > > (1) is easy to do by exporting the copy constructor > > (2) could be implemented by setting __copy__ to the above copy constructor, > but one would assume __dict__ to be (non-deep)copied, too. > > (3) definitely needs its own implementation, which needs to call deepcopy > recursively. > > I would still believe that an .enable_copy() would be very handy. It could > possibly be controlled by an enum arg which of the above methods should be > exported. > > I tried to implement (2) and (3) manually today, but failed. [...] > File "/software/python-2.4.4/lib/python2.4/copy.py", line 185, in > deepcopy y = copier(x, memo) > TypeError: No to_python (by-value) converter found for C++ type: > boost::python::api::proxy Obviously, there was another extract missing, since attr("__dict__") does not deliver an object, but this strange proxy. OTOH, passing the proxy to update() in __copy__ works?! Maybe someone is interested in turning my code into a standard BPL facility? (BTW: Is __dict__ created on demand? Then one should probably add a guard to both my __copy__ and __deepcopy__.) On Montag 23 Juli 2007, Hans Meine wrote: > Probably I should use PyImport_ImportModule or the new > boost::python::import. Speaking of the latter, shouldn't the python:: prefix be removed from the code within boost_1_34_0/libs/python/src/import.cpp ? I recently had syntax errors from GCC-4.1.2 within kdelibs-3.5.7 with a similar case: > namespace KABC { > > class KABC_EXPORT Field > { > public: > virtual QString value( const KABC::Addressee & ); Here, I had to remove KABC:: in order to let it compile. (Which I found surprising, but anyways.) Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: foo_copying.cxx Type: text/x-c++src Size: 863 bytes Desc: not available URL: -------------- 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 Lawrence.Spector at CanfieldSci.com Mon Jul 23 23:01:56 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Mon, 23 Jul 2007 17:01:56 -0400 Subject: [C++-sig] Strange Boost.Python-related compile error Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB23BC@Pan.domain-01> So, I have the following typedef: typedef std::vector VecOfStrings; Inside of a class, one of the methods looks like this: virtual const VecOfStrings &getVector() const = 0; The generated Boost.Python bindings for this class have a method which looks like the following inside of the wrapper: virtual ::MyNs::MySuite::TFilterValue const getValue( ) const { if( bp::override func_getValue = this->get_override( "getValue" ) ) { return func_getValue( ); // Compile error } else return this->MyNs::MySuite::CFilterExpression::getValue( ); } This generates the following compile errors: MySuite.cpp D:\3rdparty\boost_1_34_0\boost/variant/variant.hpp(1273) : error C2665: 'boost::detail::variant::make_initializer_node::apply::initializer_node::initialize' : none of the 3 overloads could convert all the argument types with [ BaseIndexPair=boost::mpl::pair>, Iterator=boost::mpl::l_iter,std::allocator>>> ] D:\3rdparty\boost_1_34_0\boost/variant/detail/initializer.hpp(89): could be 'int boost::detail::variant::make_initializer_node::apply::initializer_node::initialize(void *,const long)' with [ BaseIndexPair=boost::mpl::pair>, Iterator=boost::mpl::l_iter,std::allocator>>> ] D:\3rdparty\boost_1_34_0\boost/variant/detail/initializer.hpp(89): or 'int boost::detail::variant::make_initializer_node::apply::initializer_node::initialize(void *,const std::basic_string<_Elem,_Traits,_Ax> &)' with [ BaseIndexPair=boost::mpl::pair>,boost::mpl::l_iter,std::allocator>>>>::initializer_node,boost::mpl::int_<1>>, Iterator=boost::mpl::l_iter,std::allocator>>>, _Elem=wchar_t, _Traits=std::char_traits, _Ax=std::allocator ] while trying to match the argument list '(void *, const boost::python::detail::method_result)' D:\3rdparty\boost_1_34_0\boost/variant/variant.hpp(1342) : see reference to function template instantiation 'void boost::variant::convert_construct(T &,int,boost::mpl::false_)' being compiled with [ T0_=MyNs::MySuite::TFilterValueInt, T1=std::wstring, T=boost::python::detail::method_result ] MySuite.cpp(126) : see reference to function template instantiation 'boost::variant::variant(const T &)' being compiled with [ T0_=MyNs::MySuite::TFilterValueInt, T1=std::wstring, T=boost::python::detail::method_result ] call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 >nul cl /Zm800 -nologo @"bin\msvc-8.0\debug\threading-multi\MySuite.obj.rsp" ...failed compile-c-c++ bin\msvc-8.0\debug\threading-multi\MySuite.obj... ...skipped MySuite.pyd for lack of MySuite.obj... ...skipped MySuite.lib for lack of MySuite.obj... ...failed updating 1 target... ...skipped 2 targets... Any idea what's going on and how to resolve this? Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlisee at gmail.com Tue Jul 24 00:55:11 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Mon, 23 Jul 2007 22:55:11 +0000 (UTC) Subject: [C++-sig] Py++: Threading and Virtual Methods Message-ID: I am trying to use python to develop the AI and GUI for an autonomous robotics project. We use many background threads to carry out periodic, concurrent tasks like sending motor commands, rending sensor data, and processing vision data. My current setup has set of C++ classes which have Py++ created wrappers. All of these classes have virtual methods. Some of them are instantiated from Python and handed off to a C++ object for use in its own background thread. The problem is that the object I am really handing off is the auto-generated wrapper class which calls into the python API everytime the background thread calls a virtual method on the C++ object. This of course produces a crash because the Python C API is not thread safe. What I would like to do is the following: Tell Py++ to generate two wrapper classes, one which wraps the class just like it does now, with all the virtual methods hooked into the Python API, and another which just straight wraps the class. This way I could still run the program single threaded and subclass those if needed, but while running multi-threaded I can just use the underlying C++ classes. Does anyone have any advice on how to accomplish this?, or to get a similar result with a different method. If it helps here is a little more background: I have a set of abstract classes define in C++ (interfaces really), and I use python and a config file to determine which concrete classes I want to instantiate at runtime. This is quicker and easier than doing the factory pattern in C++. When actually running the vehicle I want to use the C++ implementations of these classes, but during single threaded testing I will want to substitute Python versions. -Joseph Lisee From roman.yakovenko at gmail.com Tue Jul 24 07:13:14 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Jul 2007 08:13:14 +0300 Subject: [C++-sig] wrapping a vector data member In-Reply-To: <156241.43938.qm@web43145.mail.sp1.yahoo.com> References: <200707231922.15574.meine@informatik.uni-hamburg.de> <156241.43938.qm@web43145.mail.sp1.yahoo.com> Message-ID: <7465b6170707232213i430436f5kcf1af807ca37ba1c@mail.gmail.com> On 7/23/07, Tim Spens wrote: > I'm not sure why I'm getting this error from the > follownig code? > > // data member from sig_zapv class > std::vector zaps_; What is the definition of zap? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 24 07:21:49 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Jul 2007 08:21:49 +0300 Subject: [C++-sig] Strange Boost.Python-related compile error In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB23BC@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB23BC@Pan.domain-01> Message-ID: <7465b6170707232221u4a7ed9dfud67f92075c9e10ad@mail.gmail.com> On 7/24/07, Lawrence Spector wrote: > > > > > So, I have the following typedef: > > > > typedef std::vector VecOfStrings; > > > > Inside of a class, one of the methods looks like this: > > > > virtual const VecOfStrings &getVector() const = 0; > > > > The generated Boost.Python bindings for this class have a method which looks > like the following inside of the wrapper: > > > > virtual ::MyNs::MySuite::TFilterValue const getValue( ) const { > > if( bp::override func_getValue = this->get_override( "getValue" ) ) > > { > > return func_getValue( ); // Compile error > > } > > else > > return > this->MyNs::MySuite::CFilterExpression::getValue( ); > > } > Can you create small test case that reproduce the problem? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jul 24 07:46:12 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Jul 2007 08:46:12 +0300 Subject: [C++-sig] Py++: Threading and Virtual Methods In-Reply-To: References: Message-ID: <7465b6170707232246h6a1e2513ycfe2b640eb8047c8@mail.gmail.com> On 7/24/07, Joseph Lisee wrote: > I am trying to use python to develop the AI and GUI for an autonomous robotics > project. We use many background threads to carry out periodic, concurrent tasks > like sending motor commands, rending sensor data, and processing vision data. > > My current setup has set of C++ classes which have Py++ created wrappers. All > of these classes have virtual methods. Some of them are instantiated from > Python and handed off to a C++ object for use in its own background thread. The > problem is that the object I am really handing off is the auto-generated wrapper > class which calls into the python API everytime the background thread calls a > virtual method on the C++ object. This of course produces a crash because the > Python C API is not thread safe. Take a look on next methods: add_override_precall_code & add_default_precall_code ( http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.calldef_wrapper.member_function_t-class.html ) I think it could help. Also I don't fully understand a threading model ( Python & Boost.Python & yours ) > What I would like to do is the following: Tell Py++ to generate two wrapper > classes, one which wraps the class just like it does now, with all the virtual > methods hooked into the Python API, and another which just straight wraps the > class. This way I could still run the program single threaded and subclass > those if needed, but while running multi-threaded I can just use the underlying > C++ classes. I am sure I miss something. I don't understand what you mean "straight wrapper". Also it seems to me that you could have single wrapper class, which overrides the virtual functions - just don't use them in the production environment. You can add small piece of code to every override function, which will test that it is called from the "single thread environment" and if not to throw an exception. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From t_spens at yahoo.com Tue Jul 24 16:42:19 2007 From: t_spens at yahoo.com (Tim Spens) Date: Tue, 24 Jul 2007 07:42:19 -0700 (PDT) Subject: [C++-sig] wrapping a vector data member In-Reply-To: <7465b6170707232213i430436f5kcf1af807ca37ba1c@mail.gmail.com> Message-ID: <955661.8555.qm@web43132.mail.sp1.yahoo.com> zap is a class with some getter and setter functions and some protected data members. --- Roman Yakovenko wrote: > On 7/23/07, Tim Spens wrote: > > I'm not sure why I'm getting this error from the > > follownig code? > > > > // data member from sig_zapv class > > std::vector zaps_; > > What is the definition of zap? > > -- > 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 > ____________________________________________________________________________________ Pinpoint customers who are looking for what you sell. http://searchmarketing.yahoo.com/ From Lawrence.Spector at CanfieldSci.com Tue Jul 24 17:01:25 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Tue, 24 Jul 2007 11:01:25 -0400 Subject: [C++-sig] Strange Boost.Python-related compile error In-Reply-To: <7465b6170707232221u4a7ed9dfud67f92075c9e10ad@mail.gmail.com> References: <8F737B3BFD630A4380BD0357481D4B0316DB23BC@Pan.domain-01> <7465b6170707232221u4a7ed9dfud67f92075c9e10ad@mail.gmail.com> Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB23CA@Pan.domain-01> Sorry about that example. I must've been in a daze when I posted that. I copy and pasted from two different parts of code and tried to make the example more generic, but... uhh, anyway what I posted yesterday doesn't make any sense. So, as you requested, here's a sample that demonstrates the problem. // Very simple class to demonstrate issue: #include #include typedef boost::variant ReturnType; class TestClass { public: virtual const ReturnType getValue() const; }; // end Derived // Generated Boost.Python code from Py++ #include "boost/python.hpp" namespace bp = boost::python; struct TestClass_wrapper : TestClass, bp::wrapper< TestClass > { TestClass_wrapper(TestClass const & arg ) : TestClass( arg ) , bp::wrapper< TestClass >(){ // copy constructor } TestClass_wrapper() : TestClass() , bp::wrapper< TestClass >(){ // null constructor } virtual ::ReturnType const getValue( ) const { if( bp::override func_getValue = this->get_override( "getValue" ) ) return func_getValue( ); // **** This is the error line else return this->TestClass::getValue( ); } ::ReturnType const default_getValue( ) const { return TestClass::getValue( ); } }; BOOST_PYTHON_MODULE(pyplusplus){ bp::class_< TestClass_wrapper >( "TestClass" ) .def( "getValue" , &::TestClass::getValue , &TestClass_wrapper::default_getValue ); } Output: 1>------ Build started: Project: VariantCompileError, Configuration: Debug Win32 ------ 1>Compiling... 1>BpErr.cpp 1>c:\3rdparty\boost_1_34_0\boost\python\detail\caller.hpp(52) : warning C4244: 'return' : conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data 1>c:\3rdparty\boost_1_34_0\boost\variant\variant.hpp(1273) : error C2665: 'boost::detail::variant::make_initializer_node::apply::initializer_node::initialize' : none of the 2 overloads could convert all the argument types 1> with 1> [ 1> BaseIndexPair=boost::mpl::pair>, 1> Iterator=boost::mpl::l_iter,std::allocator>>> 1> ] 1> c:\3rdparty\boost_1_34_0\boost\variant\detail\initializer.hpp(89): could be 'int boost::detail::variant::make_initializer_node::apply::initializer_node::initialize(void *,const std::basic_string<_Elem,_Traits,_Ax> &)' 1> with 1> [ 1> BaseIndexPair=boost::mpl::pair>, 1> Iterator=boost::mpl::l_iter,std::allocator>>>, 1> _Elem=wchar_t, 1> _Traits=std::char_traits, 1> _Ax=std::allocator 1> ] 1> while trying to match the argument list '(void *, const boost::python::detail::method_result)' 1> c:\3rdparty\boost_1_34_0\boost\variant\variant.hpp(1342) : see reference to function template instantiation 'void boost::variant::convert_construct(T &,int,boost::mpl::false_)' being compiled 1> with 1> [ 1> T0_=std::wstring, 1> T=boost::python::detail::method_result 1> ] 1> c:\work\sandbox\boost\python\variantcompileerror\src\bperr.cpp(38) : see reference to function template instantiation 'boost::variant::variant(const T &)' being compiled 1> with 1> [ 1> T0_=std::wstring, 1> T=boost::python::detail::method_result 1> ] 1>Build log was saved at "file://c:\Work\Sandbox\Boost\Python\VariantCompileError\VariantCompileErrorVC80\Debug\BuildLog.htm" 1>VariantCompileError - 1 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Any ideas what's going on? Thanks, Lawrence From David.A.Wagner at jpl.nasa.gov Tue Jul 24 18:04:08 2007 From: David.A.Wagner at jpl.nasa.gov (David A Wagner) Date: Tue, 24 Jul 2007 09:04:08 -0700 Subject: [C++-sig] Py++: Threading and Virtual Methods In-Reply-To: References: Message-ID: <46A622F8.7010900@jpl.nasa.gov> We recently implemented a similar system using Boost.Python, finding that it provided pretty good support for the kinds of bidirectional interfaces you need to allow the C++ to call into python, and vice versa. However, none of the available wrapper toolkits really addressed the threading issue. Once python threads are enabled, each python thread has a context the python kernel uses to manage threads. The GIL serializes thread access to the interpreter stack. So, any call coming out of python into your C++ code coming from a python thread already has a thread context, and a lock on the GIL. If that thread then calls back into python, no problem. However, if a thread originates in C++ code, it must first obtain a python context, and a lock on the GIL before it can proceed to call into Python. PyGILState_STATE gstate = PyGILState_Ensure(); // get GIL lock // make your call into python here, after gstate is obtained PyGILState_Release(gstate); // return the lock The APIs are documented here: http://docs.python.org/api/threads.html and you can find more info by googling "python GIL". One note, though: thread access to the python core is serialized by the GIL. To give each thread a fair chance to run, python performs context switches every few byte code instructions. It can't do that while a thread is calling into C++ code, so you have to be really careful to get those threads to return quickly to avoid deadlocking the system. So, it should be possible to do what you describe, but you will have to think through the thread synchronization policies very carefully. Joseph Lisee wrote: > I am trying to use python to develop the AI and GUI for an autonomous robotics > project. We use many background threads to carry out periodic, concurrent tasks > like sending motor commands, rending sensor data, and processing vision data. > > My current setup has set of C++ classes which have Py++ created wrappers. All > of these classes have virtual methods. Some of them are instantiated from > Python and handed off to a C++ object for use in its own background thread. The > problem is that the object I am really handing off is the auto-generated wrapper > class which calls into the python API everytime the background thread calls a > virtual method on the C++ object. This of course produces a crash because the > Python C API is not thread safe. > > What I would like to do is the following: Tell Py++ to generate two wrapper > classes, one which wraps the class just like it does now, with all the virtual > methods hooked into the Python API, and another which just straight wraps the > class. This way I could still run the program single threaded and subclass > those if needed, but while running multi-threaded I can just use the underlying > C++ classes. > > Does anyone have any advice on how to accomplish this?, or to get a similar > result with a different method. > > If it helps here is a little more background: > I have a set of abstract classes define in C++ (interfaces really), and I use > python and a config file to determine which concrete classes I want to > instantiate at runtime. This is quicker and easier than doing the factory > pattern in C++. When actually running the vehicle I want to use the C++ > implementations of these classes, but during single threaded testing I will want > to substitute Python versions. > > -Joseph Lisee > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From roman.yakovenko at gmail.com Tue Jul 24 20:52:12 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Jul 2007 21:52:12 +0300 Subject: [C++-sig] wrapping a vector data member In-Reply-To: <955661.8555.qm@web43132.mail.sp1.yahoo.com> References: <7465b6170707232213i430436f5kcf1af807ca37ba1c@mail.gmail.com> <955661.8555.qm@web43132.mail.sp1.yahoo.com> Message-ID: <7465b6170707241152v1e5485bie19b2f301f9aad0@mail.gmail.com> On 7/24/07, Tim Spens wrote: > zap is a class with some getter and setter functions > and some protected data members. I reviewed one more time your message and I found a few things I don't understand. You export of class vector looks strange: your code class_ >("sig_zapv") .def(init<>()) .def(vector_indexing_suite >()); the code from tutorials( http://boost.org/libs/python/doc/v2/indexing.html ) class_ >("XVec") 1^^^^^^^^ .def(vector_indexing_suite >()) 2^^^^^^^^^ ; Do you see the difference? Same class is used in both cases. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Wed Jul 25 15:18:54 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 25 Jul 2007 06:18:54 -0700 (PDT) Subject: [C++-sig] member operator ugly alias Message-ID: <11782486.post@talk.nabble.com> Hi I'm getting some warnings with some of my operators just like this one. WARNING: bool NeoDate::operator>(NeoDate const & ts) const [member operator] > warning W1043: Py++ created an ugly alias ("operator_grate_") for > template instantiated class. Is there a way to avoid this "ugly alias". And in a more general point of view is there a good way to deal with operators ? Thanks you ! -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--member-operator--ugly-alias-tf4142165.html#a11782486 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Wed Jul 25 16:15:17 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 25 Jul 2007 17:15:17 +0300 Subject: [C++-sig] member operator ugly alias In-Reply-To: <11782486.post@talk.nabble.com> References: <11782486.post@talk.nabble.com> Message-ID: <7465b6170707250715v523e27b9v1e05f8320a31a02e@mail.gmail.com> On 7/25/07, Coockie_jr wrote: > > Hi I'm getting some warnings with some of my operators just like this one. > > WARNING: bool NeoDate::operator>(NeoDate const & ts) const [member operator] > > warning W1043: Py++ created an ugly alias ("operator_grate_") for > > template instantiated class. > > Is there a way to avoid this "ugly alias". Yes, you can change the alias: http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.decl_wrapper.decl_wrapper_t-class.html Take a look on "rename" method or "alias" property > And in a more general point of view is there a good way to deal with > operators ? When I developed this part of code generator, I missed this( http://docs.python.org/ref/customization.html ) part of documentation. I guess if you will give the right alias, than everything will work "as expected". All you need to do is to patch _get_alias method ( http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.calldef_wrapper-pysrc.html#member_operator_t.__init__ ) and send the patch to me :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pwinston at gmail.com Wed Jul 25 19:35:49 2007 From: pwinston at gmail.com (Philip Winston) Date: Wed, 25 Jul 2007 13:35:49 -0400 Subject: [C++-sig] zipimport and bad mtimes Message-ID: <33677e5d0707251035w3737917dnfb5b07bc903683b@mail.gmail.com> I'm loading the standard libs out of a .zip file with an embedded interpreter. With Py_VerboseFlag on I see several "has bad mtime" messages during initialization. I modified zipimport.c to print more details and am now seeing this during init: python25.zip\site.pyc mtime is okay python25.zip\os.pyc mtime is off by 3600 python25.zip\ntpath.pyc mtime is okay python25.zip\stat.pyc mtime is okay python25.zip\UserDict.pyc mtime is off by 3600 python25.zip\copy_reg.pyc mtime is okay python25.zip\types.pyc mtime is okay python25.zip\locale.pyc mtime is okay python25.zip\encodings\__init__.pyc mtime is okay python25.zip\codecs.pyc mtime is off by 3600 python25.zip\encodings\aliases.pyc mtime is okay python25.zip\re.pyc mtime is off by 3600 python25.zip\sre_compile.pyc mtime is okay python25.zip\sre_constants.pyc mtime is okay python25.zip\sre_parse.pyc mtime is okay python25.zip\encodings\cp1252.pyc mtime is okay python25.zip\warnings.pyc mtime is okay python25.zip\linecache.pyc mtime is okay So most mtime's are okay, but the ones that are bad are off by exactly 1 hour. It looks like the internal timestamp in .pyc is one hour *earlier* than the .py timestamp. I created the zip by deleting *all* .pyc files and then using compileall and then zipping up everything (.py and .pyc). Any ideas where bad times could be from, or are they don't really bad? -Philip From Lawrence.Spector at CanfieldSci.com Wed Jul 25 22:37:52 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 25 Jul 2007 16:37:52 -0400 Subject: [C++-sig] Exposing base classes in different Boost.Python modules Message-ID: <8F737B3BFD630A4380BD0357481D4B0316DB2440@Pan.domain-01> Hello again. I'm running into another issue. Based on the Boost.Python tutorial, I have set up a hierarchy to mimic the namespaces that are in our actual C++ code, using a few tricks from the site, including making the module name start with an _ and then the __init__.py trick to make the name what I want. That being said, due to this approach I have multiple modules, since some modules are in different namespaces. Here's a situation I hit today: namespace MyNs { class MyStream : public std::wostream { ... }; } // end MyNs Now, in the Boost.Python source file that is compiled to be a Python extension, I expose the class, but apparently I also need to say that std::wostream is a base if I want it to be used polymorphically. So, I do so, like this: bp::class, boost::noncopyable>("MyStream") ... // etc... It builds fine, but when I import I get a python RuntimeError as the following: RuntimeError: extension class wrapper for base class class std::basic_ostream > has not been created yet. Fine, this makes sense. However, if I'm going to expose this, I want to make a different module called std, so it's in the right namespace. Is there a way to tell Boost.Python to automatically import this one before my other module, so it knows what to do with std::wostream or another way to make this work? Any help anyone can provide would be appreciated. Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From ostiguy at fnal.gov Wed Jul 25 22:34:46 2007 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Wed, 25 Jul 2007 15:34:46 -0500 (CDT) Subject: [C++-sig] overriding a C++ method Message-ID: Hi- I need help with the following problem. Consider a c++ class class A { public: A(); ..... void do_something( std::vector >& arg); ... }; wrapped as follows: class_< A, bases, boost::shared_ptr( "A", init<>() ) ... ; I want to wrap the method do_something, but I would like to avoid introducing a converter for std::vector >. Rather, I would like to be able to call do_something(..) in python using as an argument, a list of 2-tuples, which would be more natural. My first idea was to create a new class AWrapper struct AWrapper: A { .... void do_something( boost::python::list& arg); ... }; extract the c++ arguments from arg and dispatch the call to A::do_something. This implies declaring class_< AWrap, bases, boost::shared_ptr( "A", init<>() ) .def("do_something", &AWrap::do_something) ; This approach almost works; unfortunately, the C++ API is full of methods that expect shared_ptr as argument. As a result, when attempting to wrap such methods I get: TypeError: No to_python (by-value) converter found for C++ type: boost::shared_ptr presumably, because boost.python now only knows how to convert boost::shared_ptr. Any suggestions ? -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Accelerator Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From ngoodspeed at solidworks.com Thu Jul 26 01:30:45 2007 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Wed, 25 Jul 2007 19:30:45 -0400 Subject: [C++-sig] overriding a C++ method In-Reply-To: References: Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B7018B5DB1@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Francois Ostiguy > Sent: Wednesday, July 25, 2007 4:35 PM > To: c++-sig at python.org > Subject: [C++-sig] overriding a C++ method > > I want to wrap the method do_something, but I would like to avoid > introducing a converter for std::vector >. > Rather, I would like to be able to call do_something(..) in python > using as an argument, a list of 2-tuples, which would be more natural. > > My first idea was to create a new class AWrapper [Nat] Another approach, that might sidestep your whole shared_ptr problem, would be to wrap specific methods (do_something() and others) rather than wrapping the entire class A. In our Boost.Python extension module, we define a class Drawable with a method: virtual void addRotation(double angle, const Vector3& axis); Our Vector3 class is not published to Python; instead we want to accept any Python triple. So we define the following: static void Drawable_addRotation(Drawable& drawable, double angle, object axis) { drawable.addRotation(angle, PVector3(axis)); } where PVector3 is defined (in the same module) as follows: /** conversion from (x, y, z) to Vector3 */ struct PVector3: public Vector3 { PVector3(boost::python::object tuple): Vector3(boost::python::extract(tuple[0]), boost::python::extract(tuple[1]), boost::python::extract(tuple[2])) {} }; Then when we publish Drawable::addRotation, we pass &Drawable_addRotation rather than &Drawable::addRotation. The above could probably be streamlined further by registering a converter. My point is simply that you can wrap a method using a free function if it solves a problem for you. From roman.yakovenko at gmail.com Thu Jul 26 06:54:18 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 26 Jul 2007 07:54:18 +0300 Subject: [C++-sig] Exposing base classes in different Boost.Python modules In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2440@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB2440@Pan.domain-01> Message-ID: <7465b6170707252154x2ec416eaob1d4d381c2a2f448@mail.gmail.com> On 7/25/07, Lawrence Spector wrote: > > > > > Hello again. I'm running into another issue. Based on the Boost.Python > tutorial, I have set up a hierarchy to mimic the namespaces that are in our > actual C++ code, using a few tricks from the site, including making the > module name start with an _ and then the __init__.py trick to make the name > what I want. > > > That being said, due to this approach I have multiple modules, since some > modules are in different namespaces. Here's a situation I hit today: > > > > namespace MyNs > > { > > > > class MyStream : public std::wostream > > { > > ? > }; > > > > } // end MyNs > > > > Now, in the Boost.Python source file that is compiled to be a Python > extension, I expose the class, but apparently I also need to say that > std::wostream is a base if I want it to be used polymorphically. So, I do > so, like this: > > > > bp::class, > boost::noncopyable>("MyStream") > > ? // etc? > > > > It builds fine, but when I import I get a python RuntimeError as the > following: > > > > RuntimeError: extension class wrapper for base class class > std::basic_ostream > has not been > created yet. > > > Fine, this makes sense. However, if I'm going to expose this, I want to > make a different module called std, so it's in the right namespace. Is > there a way to tell Boost.Python to automatically import this one before my > other module, so it knows what to do with std::wostream or another way to > make this work? No, such way doesn't exists. You can create package for every ext. module and import the dependencies within it or you can mess with C API and import module before you start to expose your classes. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From meine at informatik.uni-hamburg.de Thu Jul 26 12:46:23 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 26 Jul 2007 12:46:23 +0200 Subject: [C++-sig] Exposing base classes in different Boost.Python modules In-Reply-To: <8F737B3BFD630A4380BD0357481D4B0316DB2440@Pan.domain-01> References: <8F737B3BFD630A4380BD0357481D4B0316DB2440@Pan.domain-01> Message-ID: <200707261246.23757.meine@informatik.uni-hamburg.de> Am Mittwoch, 25. Juli 2007 22:37:52 schrieb Lawrence Spector: > Fine, this makes sense. However, if I'm going to expose this, I want to > make a different module called std, so it's in the right namespace. Is > there a way to tell Boost.Python to automatically import this one before my > other module, so it knows what to do with std::wostream or another way to > make this work? Yes. Have a look at the new boost::python::import() function - I use it to import dependency modules, too. Or, if you are using an older boost version: BOOST_PYTHON_MODULE_INIT(bar) { // import foo to make sure that basic converters are available for // default arguments: { PyObject *fooMod = PyImport_ImportModule("foo"); Py_XDECREF(fooMod); } ... } Ciao, / / /--/ / / ANS From hgroven at emgs.com Fri Jul 27 07:39:50 2007 From: hgroven at emgs.com (=?UTF-8?Q?H=C3=A5kon_Groven?=) Date: Fri, 27 Jul 2007 07:39:50 +0200 (CEST) Subject: [C++-sig] Problem with inheritance Message-ID: <1687443004.2361185514790319.OPEN-XCHANGE.WebMail.tomcat@ox> Hi! In one of my cpp-functions I return a vector with items of type channel*. My channel class is extended by some channel_xxx classes. The instances returned in the vector are actually of type channel_xxx*. In Python I do however only get objects of the super type. One of my other functions return a channel* and here I am able to get objects of the subclasses in Python. I'd be glad if anyone could help! I have pasted parts of my wrapper code below. The two interesting functions are: 1) get_available_channels (inheritance does not work for the returned value) 2) get_channel (inheritance do work for the returned value) Code: // Boost Includes ============================================================ #include #include // Includes ================================================================== #include "../include/channel.h" #include "../include/channel_group.h" . . . // Using ===================================================================== using namespace boost::python; // Declarations ============================================================== namespace { template < typename ContainerType> struct to_tuple { static PyObject* convert ( ContainerType const& a) { using boost::python::incref; using boost::python::list; list result; for(std::size_t i=0;i struct std_vector_to_tuple { std_vector_to_tuple () { to_python_converter < std::vector < T >, to_tuple < std::vector < T > > > (); } }; } // Module ==================================================================== BOOST_PYTHON_MODULE(pyelio) { std_vector_to_tuple < std::string > (); std_vector_to_tuple < float > (); std_vector_to_tuple < channel_group* > (); std_vector_to_tuple < channel* > (); std_vector_to_tuple < sample* > (); std_vector_to_tuple < std::complex > (); class_< channel_group >("channel_group", init< const channel_group& >()) .def(init< boost::shared_ptr, channel_group_type >()) .def("get_available_channels", &channel_group::get_available_channels) .def("get_channel", (channel* (channel_group::*)(channel_type) const) &channel_group::get_channel, return_value_policy()) .def("get_channel", (channel* (channel_group::*)(channel_type, int) const) &channel_group::get_channel, return_value_policy()) .def("get_type", &channel_group::get_type) ; class_< channel >("channel", init< >()) .def(init< const channel& >()) .def("init", (void (channel::*)(boost::shared_ptr, channel_group_type, channel_type, int) ) &channel::init) .def("init", (void (channel::*)(boost::shared_ptr, channel_group_type, channel_type, int, int) )&channel::init) ; class_< channel_emf, bases< channel > >("channel_emf", init< >()) .def(init< const channel_emf& >()) ; } Best wishes Hakon From seefeld at sympatico.ca Fri Jul 27 15:22:55 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 27 Jul 2007 09:22:55 -0400 Subject: [C++-sig] Problem with inheritance In-Reply-To: <1687443004.2361185514790319.OPEN-XCHANGE.WebMail.tomcat@ox> References: <1687443004.2361185514790319.OPEN-XCHANGE.WebMail.tomcat@ox> Message-ID: <46A9F1AF.6030904@sympatico.ca> H?kon Groven wrote: > Hi! > > In one of my cpp-functions I return a vector with items of type > channel*. > > My channel class is extended by some channel_xxx classes. > > The instances returned in the vector are actually of type channel_xxx*. > > In Python I do however only get objects of the super type. This sounds as if it is caused by you passing objects by value, not by reference. To pass by reference you need to explicitly tell boost.python to do so. > > One of my other functions return a channel* and here I am able to get > objects of the subclasses in Python. > > I'd be glad if anyone could help! > > I have pasted parts of my wrapper code below. > > The two interesting functions are: > 1) get_available_channels (inheritance does not work for the returned > value) > 2) get_channel (inheritance do work for the returned value) > > Code: > > // Boost Includes > ============================================================ > #include > #include > > // Includes > ================================================================== > #include "../include/channel.h" > #include "../include/channel_group.h" > . > . > . > > // Using > ===================================================================== > using namespace boost::python; > > // Declarations > ============================================================== > namespace { > > template < typename ContainerType> > struct to_tuple > { > static PyObject* convert ( ContainerType const& a) > { > using boost::python::incref; > using boost::python::list; > list result; > for(std::size_t i=0;i result.append(object(a[i])); Try result.append(object(ptr(a[i]))); instead. See http://boost.org/libs/python/doc/v2/ptr.html As the example on that page explains: "Note: ensuring that *x outlives the argument to f() is up to the user! Failure to do so could result in a crash!" (where *x corresponds to a[i] and f() to the lifetime of the object you insert into result) HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From t_spens at yahoo.com Fri Jul 27 19:46:24 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 27 Jul 2007 10:46:24 -0700 (PDT) Subject: [C++-sig] Importing boost python wrapped libtool .la library into python In-Reply-To: <1687443004.2361185514790319.OPEN-XCHANGE.WebMail.tomcat@ox> Message-ID: <835330.50365.qm@web43139.mail.sp1.yahoo.com> I'm having issues importing my boost python wrapped libtool library into python, I googled around and it seems like gstltihooks.py is the only solution? The problem is when I import the library into python I get an error, when I was using the .so linked library using g++ I didn't have this problem. Anyone know a solution for importing libtool libraries? >>> import gstltihooks >>> import libzee Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/ihooks.py", line 404, in import_module q, tail = self.find_head_package(parent, str(name)) File "/usr/lib/python2.5/ihooks.py", line 440, in find_head_package q = self.import_it(head, qname, parent) File "/usr/lib/python2.5/ihooks.py", line 495, in import_it m = self.loader.load_module(fqname, stuff) File "/usr/lib/python2.5/ihooks.py", line 268, in load_module m = self.hooks.load_dynamic(name, filename, file) File "gstltihooks.py", line 50, in load_dynamic return ihooks.Hooks.load_dynamic(self, name, filename, file) File "/usr/lib/python2.5/ihooks.py", line 172, in load_dynamic return imp.load_dynamic(name, filename, file) ImportError: ./libzee.la: invalid ELF header ____________________________________________________________________________________ Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 From seefeld at sympatico.ca Fri Jul 27 19:58:37 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 27 Jul 2007 13:58:37 -0400 Subject: [C++-sig] Importing boost python wrapped libtool .la library into python In-Reply-To: <835330.50365.qm@web43139.mail.sp1.yahoo.com> References: <835330.50365.qm@web43139.mail.sp1.yahoo.com> Message-ID: <46AA324D.2030001@sympatico.ca> Tim Spens wrote: > I'm having issues importing my boost python wrapped > libtool library into python, I googled around and it > seems like gstltihooks.py is the only solution? The > problem is when I import the library into python I get > an error, when I was using the .so linked library > using g++ I didn't have this problem. Anyone know a > solution for importing libtool libraries? I'm not sure what a "boost python wrapped libtool library" is. The .la file at the end of your stack trace, which is typically produced by libtool, is only a shell-script, so you can't dlopen that. I'm afraid a lot of important context information is missing in order to help you. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From t_spens at yahoo.com Fri Jul 27 20:08:31 2007 From: t_spens at yahoo.com (Tim Spens) Date: Fri, 27 Jul 2007 11:08:31 -0700 (PDT) Subject: [C++-sig] Importing boost python wrapped libtool .la library into python In-Reply-To: <46AA324D.2030001@sympatico.ca> Message-ID: <12574.16876.qm@web43134.mail.sp1.yahoo.com> Let me try to explain better. I have some boost python wrapped c++ files. These files are linked into a libtool library .la. I'm trying to import the libtool library into python via gstltihooks.py. This is when I get the stack trace. My question is basically can I import a libtool generated shared library into python? --- Stefan Seefeld wrote: > Tim Spens wrote: > > I'm having issues importing my boost python > wrapped > > libtool library into python, I googled around and > it > > seems like gstltihooks.py is the only solution? > The > > problem is when I import the library into python I > get > > an error, when I was using the .so linked library > > using g++ I didn't have this problem. Anyone know > a > > solution for importing libtool libraries? > > I'm not sure what a "boost python wrapped libtool > library" is. > The .la file at the end of your stack trace, which > is typically > produced by libtool, is only a shell-script, so you > can't dlopen > that. > I'm afraid a lot of important context information is > missing > in order to help you. > > Regards, > 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 > ____________________________________________________________________________________ Need a vacation? Get great deals to amazing places on Yahoo! Travel. http://travel.yahoo.com/ From seefeld at sympatico.ca Fri Jul 27 20:18:41 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 27 Jul 2007 14:18:41 -0400 Subject: [C++-sig] Importing boost python wrapped libtool .la library into python In-Reply-To: <12574.16876.qm@web43134.mail.sp1.yahoo.com> References: <12574.16876.qm@web43134.mail.sp1.yahoo.com> Message-ID: <46AA3701.4010300@sympatico.ca> Tim Spens wrote: > Let me try to explain better. I have some boost > python wrapped c++ files. These files are linked into > a libtool library .la. I'm trying to import the > libtool library into python via gstltihooks.py. This > is when I get the stack trace. My question is > basically can I import a libtool generated shared > library into python? A "libtool library" is something only libtool understands. So the short answer to your question is "no". Here is a somewhat longer one: libtool is a tool to portably produce shared libraries (mainly). A shared library is on most systems that are supported by libtool an executable ELF file with '.so' extension that can be loaded into a running process (python does that when you 'import' a module.) However, libtool introduces some indirection, attaching metadata to that .so file. Thus, what you actually see when linking a 'libtool library' is a file with .la extension, which is a shell script. (it will point to the corresponding .so file, which typically resides in some hidden .libs/ directory). For the purposes of importing a python module compiled that way, you really need to know the full path to the .so file, and tell python about it (PYTHONPATH). The .la file is of no use in that context. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From kanand at qualcomm.com Sat Jul 28 01:47:25 2007 From: kanand at qualcomm.com (Anand, Kumar) Date: Fri, 27 Jul 2007 16:47:25 -0700 Subject: [C++-sig] Py++: ArgumentError during calling a function of baseclas In-Reply-To: <7465b6170707200311o31b181deyd48ab8eb2229b47@mail.gmail.com> Message-ID: Another data point which might be of some help: Everything works fine if I create the evTest object in python and then call the "getSynchronous" function on that object. However, the error (listed in previous email) happens, whenever this 'evTest' object was actually created in C++ (and stored as a pointer attribute "evTest*" inside another C++ object) and we try to access this pointer attribute from Python and then try to invoke the "getSynchronous" function. Note that 'evTest' is being exposed with held_type as auto_ptr. Just curious, will python actually return the attribute in an auto_ptr and try to take ownership (even though Py++ exposes the attribute's accessor with return_internal_reference policy)? Is the error somehow related to use of auto_ptr as held_type? Thanks Kumar -----Original Message----- From: c++-sig-bounces+kanand=qualcomm.com at python.org [mailto:c++-sig-bounces+kanand=qualcomm.com at python.org] On Behalf Of Roman Yakovenko Sent: Friday, July 20, 2007 3:12 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++: ArgumentError during calling a function of baseclas On 7/20/07, Anand, Kumar wrote: > Hi, > > I have been getting errors like this: Any idea why this is happening and how > to debug it further? 'evTest' is a class that definitely derives from > OMEvent and the relationship has been exposed to Python as well: > > ArgumentError: Python argument types in > > OMEvent.getSynchronous(evTest) > > did not match C++ signature: > > getSynchronous(OMEvent {lvalue}) It seems that you pass, for some reason one argument, when the function doesn't take any argument. If evTest is instance of OMEvent, than try next code: evTest.getSynchronous() -- 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 From roman.yakovenko at gmail.com Sat Jul 28 19:26:00 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 28 Jul 2007 20:26:00 +0300 Subject: [C++-sig] Py++: ArgumentError during calling a function of baseclas In-Reply-To: References: <7465b6170707200311o31b181deyd48ab8eb2229b47@mail.gmail.com> Message-ID: <7465b6170707281026x6baeea7rfc77c190ec36b55d@mail.gmail.com> On 7/28/07, Anand, Kumar wrote: > Another data point which might be of some help: I am sure you will get more help if you will attach small and complete example, that reproduce your problem. > Everything works fine if I create the evTest object in python and then > call the "getSynchronous" function on that object. > > However, the error (listed in previous email) happens, whenever this > 'evTest' object was actually created in C++ (and stored as a pointer > attribute "evTest*" inside another C++ object) and we try to access this > pointer attribute from Python and then try to invoke the > "getSynchronous" function. Interesting, you should show how evTest* member variable is exposed. > Note that 'evTest' is being exposed with > held_type as auto_ptr. Just curious, will python actually return the > attribute in an auto_ptr and try to take ownership (even though Py++ > exposes the attribute's accessor with return_internal_reference policy)? I guess the answer is "no". I could be wrong, but help_type is used when classes are created from Python. > Is the error somehow related to use of auto_ptr as held_type? I don't think so. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From ndbecker2 at gmail.com Sun Jul 29 16:28:31 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 29 Jul 2007 10:28:31 -0400 Subject: [C++-sig] module variable Message-ID: I can create a module variable like this: static func_that_needs_x () { // How do I access the value of x? } BOOST_PYTHON_MODULE () { scope().attr ("x") = 2; def ("func", &func_that_needs_x); } But suppose I have a c++ function that needs to access the value? How do I do this? From dave at boost-consulting.com Sun Jul 29 19:30:22 2007 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 29 Jul 2007 10:30:22 -0700 Subject: [C++-sig] module variable References: Message-ID: <878x8z9ky9.fsf@grogan.peloton> on Sun Jul 29 2007, Neal Becker wrote: > I can create a module variable like this: > > static func_that_needs_x () { > // How do I access the value of x? > } > > BOOST_PYTHON_MODULE () { > scope().attr ("x") = 2; > def ("func", &func_that_needs_x); > } > > But suppose I have a c++ function that needs to access the value? How do I > do this? object module; int get_x() { return extract(module.attr("x")) } BOOST_PYTHON_MODULE () { module = scope() scope().attr ("x") = 2; def ("func", &func_that_needs_x); } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From dave at boost-consulting.com Sun Jul 29 19:40:28 2007 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 29 Jul 2007 10:40:28 -0700 Subject: [C++-sig] overriding a C++ method References: Message-ID: <873az79khf.fsf@grogan.peloton> on Wed Jul 25 2007, Francois Ostiguy wrote: > Hi- > > I need help with the following problem. > > Consider a c++ class > > class A { > public: > A(); > ..... > void do_something( std::vector >& arg); > ... > }; > > wrapped as follows: > > class_< A, bases, boost::shared_ptr( "A", init<>() ) > ... > ; > > I want to wrap the method do_something, but I would like to avoid > introducing a converter for std::vector >. > Rather, I would like to be able to call do_something(..) in python > using as an argument, a list of 2-tuples, which would be more natural. void do_something(A& self, boost::python::object seq) { std::vector > arg; for ( std::size_t i = 0 , len = boost::python::extract(seq.attr("__len__")); i < len; ++i) { arg.push_back( std::make_pair( boost::python::extract(seq[i][0]) , boost::python::extract(seq[i][1]) ) ) } self.do_something(arg) } class_< A, bases, boost::shared_ptr( "A", init<>() ) .def("do_something", do_something) ... ; -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From ndbecker2 at gmail.com Sun Jul 29 22:19:28 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 29 Jul 2007 16:19:28 -0400 Subject: [C++-sig] module variable References: <878x8z9ky9.fsf@grogan.peloton> Message-ID: David Abrahams wrote: > > on Sun Jul 29 2007, Neal Becker wrote: > >> I can create a module variable like this: >> >> static func_that_needs_x () { >> // How do I access the value of x? >> } >> >> BOOST_PYTHON_MODULE () { >> scope().attr ("x") = 2; >> def ("func", &func_that_needs_x); >> } >> >> But suppose I have a c++ function that needs to access the value? How do >> I do this? > > object module; > int get_x() > { > return extract(module.attr("x")) > } > > BOOST_PYTHON_MODULE () { > module = scope() > scope().attr ("x") = 2; > def ("func", &func_that_needs_x); > } > Thanks. I got stuck on the fact that scope has a private assign, so you can't assign to a global scope variable. I guess you avoid this by assigning to an object instead. From hgroven at emgs.com Mon Jul 30 13:10:04 2007 From: hgroven at emgs.com (=?UTF-8?Q?H=C3=A5kon_Groven?=) Date: Mon, 30 Jul 2007 13:10:04 +0200 (CEST) Subject: [C++-sig] C++ function returning float Message-ID: <1707799863.321185793804168.OPEN-XCHANGE.WebMail.tomcat@ox> Hi! I have a c++ function returning a vector of floats. In c++ the returned values are 0.1, 0.3 and 0.5. On the Python side, the values are 0.10000000149011612, 0.30000001192092896 and 0.5 c++ code: ?std::vector get_freqs(void) const; wrapper code: ?template < typename ContainerType> ?struct to_tuple ?{ ???static PyObject* convert ( ContainerType const& a) ???{ ?????using boost::python::incref; ?????using boost::python::list; ?????list result; ?????for(std::size_t i=0;i ?struct std_vector_to_tuple ?{ ???std_vector_to_tuple () ???{ ?????to_python_converter < std::vector < T >, ???to_tuple < std::vector < T > >? > (); ???} ?}; ?std_vector_to_tuple < float > (); ?.def("get_freqs", &survey_result::get_freqs) I'd be glad if anyone could help me out here! By the way, when you receive an answer via digest, how do you reply to it? Haakon. From matthieu.brucher at gmail.com Mon Jul 30 13:49:45 2007 From: matthieu.brucher at gmail.com (Matthieu Brucher) Date: Mon, 30 Jul 2007 13:49:45 +0200 Subject: [C++-sig] C++ function returning float In-Reply-To: <1707799863.321185793804168.OPEN-XCHANGE.WebMail.tomcat@ox> References: <1707799863.321185793804168.OPEN-XCHANGE.WebMail.tomcat@ox> Message-ID: Hi, 2007/7/30, H?kon Groven : > > Hi! > > I have a c++ function returning a vector of floats. > > In c++ the returned values are > 0.1, 0.3 and 0.5. > > On the Python side, the values are > 0.10000000149011612, 0.30000001192092896 and 0.5 They are the same, only in Python the number of significant digits displayed seems to be more than for C++ (although you can change that and see by yourself that both vectors have exactly the same values) Matthieu -------------- next part -------------- An HTML attachment was scrubbed... URL: From meine at informatik.uni-hamburg.de Mon Jul 30 14:16:21 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 30 Jul 2007 14:16:21 +0200 Subject: [C++-sig] C++ function returning float In-Reply-To: <1707799863.321185793804168.OPEN-XCHANGE.WebMail.tomcat@ox> References: <1707799863.321185793804168.OPEN-XCHANGE.WebMail.tomcat@ox> Message-ID: <200707301416.22005.meine@informatik.uni-hamburg.de> Am Montag, 30. Juli 2007 13:10:04 schrieb H?kon Groven: > I have a c++ function returning a vector of floats. > > In c++ the returned values are > 0.1, 0.3 and 0.5. > > On the Python side, the values are > 0.10000000149011612, 0.30000001192092896 and 0.5 See: http://docs.python.org/tut/node16.html Ciao, / / /--/ / / ANS From irnyad at gmail.com Tue Jul 31 09:55:35 2007 From: irnyad at gmail.com (Jason Ward) Date: Tue, 31 Jul 2007 09:55:35 +0200 Subject: [C++-sig] Nasm_with_C++_with_Python Message-ID: <1ea031080707310055x5ee9f264l7674690f389fd8bb@mail.gmail.com> I am interested in writing a library in Nasm and calling it from python. Python can call C++ libraries. Nasm can be made into an inc file and can be included in C++. So I was wondering if this combination is possible or if there is a better way. If it can be done please explain how I can do this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From achille.talon at gmail.com Tue Jul 31 10:49:25 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Tue, 31 Jul 2007 01:49:25 -0700 (PDT) Subject: [C++-sig] Call policies choice Message-ID: <11920334.post@talk.nabble.com> Hi I'l still working on trying to wrap a library with boost.python an py++ but I'm having some difficulties with call policies and a little hint would be nice since the on-line documentation doesn't help me much (or I just don't understand ;) ) I've got this classe class NeoCollection:public NeoMsgType{ public: ... ... virtual NeoMsgType* get(unsigned short index) const= 0; ... ... virtual string toString() const; protected: unsigned short count; }; And boost requires specific call policies get and toString methods. I must say I tried a bit of all but with no success, I know this might seem obvious but not for me ! Thanks for your time and help -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Call-policies-choice-tf4191655.html#a11920334 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Tue Jul 31 11:17:48 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 31 Jul 2007 12:17:48 +0300 Subject: [C++-sig] Call policies choice In-Reply-To: <11920334.post@talk.nabble.com> References: <11920334.post@talk.nabble.com> Message-ID: <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> On 7/31/07, Coockie_jr wrote: > > Hi I'l still working on trying to wrap a library with boost.python an py++ > but I'm having some difficulties with call policies and a little hint would > be nice since the on-line documentation doesn't help me much (or I just > don't understand ;) ) Did you read this: http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies ? > I've got this classe > > class NeoCollection:public NeoMsgType{ > public: > ... > ... > virtual NeoMsgType* get(unsigned short index) const= 0; > ... > ... > virtual string toString() const; > protected: > unsigned short count; > }; To get good answer you should define who is the owner of the returned object? If it is the NeoCollection instance than "return_internal_reference" should be used. > And boost requires specific call policies get and toString methods. What do you try to say? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Tue Jul 31 11:45:56 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Tue, 31 Jul 2007 02:45:56 -0700 (PDT) Subject: [C++-sig] Call policies choice In-Reply-To: <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> Message-ID: <11921152.post@talk.nabble.com> Roman Yakovenko wrote: > > On 7/31/07, Coockie_jr wrote: >> >> Hi I'l still working on trying to wrap a library with boost.python an >> py++ >> but I'm having some difficulties with call policies and a little hint >> would >> be nice since the on-line documentation doesn't help me much (or I just >> don't understand ;) ) > > Did you read this: > http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies > ? > > Actually I did and it was quite helpful. > > >> I've got this classe >> >> class NeoCollection:public NeoMsgType{ >> public: >> ... >> ... >> virtual NeoMsgType* get(unsigned short index) const= 0; >> ... >> ... >> virtual string toString() const; >> protected: >> unsigned short count; >> }; > > To get good answer you should define who is the owner of the returned > object? > If it is the NeoCollection instance than "return_internal_reference" > should be used. > > That is also what I thought but I get this error when using bjam. > > D:\boost_1_34_0\boost/python/detail/caller.hpp(199) : error C2027: use of > undefined type > 'pyplusplus::call_policies::detail::return_pointee_value_requires_a_pointer_return_type > > Full bjam log here (with some French but not that much ...) > http://coockiejrdepot.free.fr/Stage/log_bjam.txt > > In fact it looks more like an issue that isn't directly linked with the > choice of the call policy. > >> And boost requires specific call policies get and toString methods. > > What do you try to say? > > Hmm It seems I fell asleep when typing this sentence. I edited it. > > -- > 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 > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Call-policies-choice-tf4191655.html#a11921152 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Tue Jul 31 11:54:02 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 31 Jul 2007 12:54:02 +0300 Subject: [C++-sig] Call policies choice In-Reply-To: <11921152.post@talk.nabble.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> Message-ID: <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> On 7/31/07, Coockie_jr wrote: > > > To get good answer you should define who is the owner of the returned > > object? > > If it is the NeoCollection instance than "return_internal_reference" > > should be used. > > > > That is also what I thought but I get this error when using bjam. > > > > D:\boost_1_34_0\boost/python/detail/caller.hpp(199) : error C2027: use of > > undefined type > > 'pyplusplus::call_policies::detail::return_pointee_value_requires_a_pointer_return_type > > > > Full bjam log here (with some French but not that much ...) > > http://coockiejrdepot.free.fr/Stage/log_bjam.txt > > > > In fact it looks more like an issue that isn't directly linked with the > > choice of the call policy. I just reviewed the error, what I saw is that you use the wrong call policy: boost::python::return_value_policy P.S. May be you have to rest few hours :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Tue Jul 31 12:36:33 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Tue, 31 Jul 2007 03:36:33 -0700 (PDT) Subject: [C++-sig] Call policies choice In-Reply-To: <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> References: <11920334.post@talk.nabble.com> <7465b6170707310217gd8608c2qbcf31c520aca3cbf@mail.gmail.com> <11921152.post@talk.nabble.com> <7465b6170707310254q6b2c931bq5492a0a61b58f720@mail.gmail.com> Message-ID: <11921781.post@talk.nabble.com> Roman Yakovenko wrote: > > > I just reviewed the error, what I saw is that you use the wrong call > policy: > boost::python::return_value_policy > > P.S. May be you have to rest few hours :-) > > > Not a bad idea :p > I uploaded the wrong log :/ > http://coockiejrdepot.free.fr/Stage/log_bjam_IR.txt > > > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Call-policies-choice-tf4191655.html#a11921781 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Tue Jul 31 13:45:17 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 31 Jul 2007 14:45:17 +0300 Subject: [C++-sig] Call policies choice In-Reply-To: <11921781.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> Message-ID: <7465b6170707310445l482f8864ob87061252a4913c3@mail.gmail.com> On 7/31/07, Coockie_jr wrote: > > > Roman Yakovenko wrote: > > > > > > I just reviewed the error, what I saw is that you use the wrong call > > policy: > > boost::python::return_value_policy > > > > P.S. May be you have to rest few hours :-) > > > > > > Not a bad idea :p > > I uploaded the wrong log :/ > > http://coockiejrdepot.free.fr/Stage/log_bjam_IR.txt In this case there is a difference between the source code you asked to help with and with the error, which refer to function type: std::string (__thiscall NeoCollection::* )(void) const, And in this case you don't have to set any call policies, the default one will be okay. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Mark.English at rbccm.com Tue Jul 31 15:42:26 2007 From: Mark.English at rbccm.com (English, Mark) Date: Tue, 31 Jul 2007 14:42:26 +0100 Subject: [C++-sig] Runtime issues with return_internal_reference and to_python_converter Message-ID: 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". As an example, given a C++ class (Outer) which contains instances of another C++ class (Inner), I want to expose the contained instances by creating PyObjects who's PyTypeObject is external to Boost Python. The lifetime of the contained object is managed by the outer containing object. Working with Boost 1.32.0 on Windows 2000 sp4, with MS Visual Studio 2003 (no service pack) and Python 2.3.6. All debug builds built from source. Moving to a later version of Boost or indeed anything else is unfortunately not an option, and from googling I haven't seen a related fix. A demonstration of the C++/Python code is below. I believe it compiles ok, although I've pasted a couple of files together and tried to remove any Windows specific extraneous matter. The Python test "passes" with the "innerval" attribute, although the lifetime of the returned object isn't tied to its owner so in that sense it's wrong (i.e. return_by_value is incorrect). The Python test fails at runtime with the "inner" attribute (exposed using return_internal_reference) with "TypeError: No Python class registered for C++ class class Inner". Full output appended at the bottom of this mail. Peeking in the debugger return_by_value invokes "to_python_value" using "registry_to_python_value", while return_internal_reference invokes "to_python_indirect" which ultimately calls "make_ptr_instance". I tried specializing "make_ptr_instance::get_class_object" as follows: template <> template <> PyTypeObject * make_ptr_instance >::get_class_object(Inner * const &) { return &typeInner; } This works right up until it starts asserting the returned type is a Boost class_metatype_object (in instance_holder::install()). I did try using a dummy class to get at the class_metatype_object and creating my own metatype/base objects, but that didn't work in ways too convoluted for me to understand, and therefore did not look like a good idea. I read the page on "to_python_indirect" but didn't understand how to persuade Python to use an external implementation. Perhaps that's where I need to provide a specialisation ? On a separate note, it seems wrong to be casting away const in the converter. Is there a non-const converter I should be implementing instead (see the line tagged "// This looks decidedly like a bad idea") ? Possibly related links: http://mail.python.org/pipermail/c++-sig/2007-May/012308.html His next post advocates SWIG which isn't really the direction I want to go in. http://www.language-binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/custom_rvalue.cpp.html This doesn't seem to offer anything relevant to return_internal_reference http://mail.python.org/pipermail/c++-sig/2005-August/009356.html "return_internal_reference doesn't do what you think" Cheers, mE ========== Code ========== // C++ code #include class Inner {}; struct PyInner { PyObject_HEAD Inner *pinner; }; PyTypeObject typeInner = { PyObject_HEAD_INIT(NULL) 0 // ob_size ,"Inner" // tp_name ,sizeof(PyInner) // tp_basicsize ,0 // tp_itemsize ,0 // 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 }; struct convert_inner_to_python { static PyObject * convert(Inner const &rinner) { PyInner *ppyinnerReturn = PyObject_New(PyInner, &typeInner); ppyinnerReturn->pinner = const_cast(&rinner); // This looks decidedly like a bad idea PyObject *ppyobjReturn = reinterpret_cast (ppyinnerReturn); return ppyobjReturn; } }; struct Outer { Inner m_inner; }; // Attempted workaround: // Leads to assertions because Boost Python expects types who's type is // the internal "class_metatype_object" //namespace boost { namespace python { namespace objects { // //template <> //template <> //PyTypeObject * make_ptr_instance >::get_class_object(Inner * const &) //{ // return &typeInner; //} // //}}} namespace ConversionExample { void export() { using namespace boost::python; typeInner.ob_type = &PyType_Type; PyType_Ready(&typeInner); to_python_converter(); 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 doesn't work: "TypeError: No Python class registered for C++ class class Inner" .add_property("inner", make_getter(&Outer::m_inner, return_internal_reference<>()), make_setter(&Outer::m_inner, return_internal_reference<>()));} } // End of namespace ConversionExample BOOST_PYTHON_MODULE("testboostpython") { ConversionExample::export(); class_("Outer") .add_property("inner", make_getter(&Outer::m_inner, return_internal_reference<>()), make_setter(&Outer::m_inner, return_internal_reference<>())); } #Python code 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 def do_test(): outerTest = testboostpython.Outer() inner = outerTest.inner del outerTest return inner #This works, but object lifetime is incorrect innerTestVal = do_test_value() gc.collect() self.assertEqual(type(innerTestVal).__name__, 'Inner') #This doesn't work: #"TypeError: No Python class registered for C++ class class Inner" 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 Output: test_OuterInner (__main__.TestCaseBoostPython) ... ERROR ====================================================================== ERROR: test_OuterInner (__main__.TestCaseBoostPython) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 311, in test_OuterInner innerTest = do_test() File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 303, in do_test inner = outerTest.inner TypeError: No Python class registered for C++ class class Inner ---------------------------------------------------------------------- Ran 1 test in 0.031s FAILED (errors=1) Traceback (most recent call last): File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 344, in ? main() File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 341, in main test() or run() File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 333, in test run_unittest(TestCaseBoostPython, 'test_OuterInner')#'test_runGotABuffer') File "T:\felix_python\felix_python\lib\felix\testing\test_base.py", line 47, in run_unittest test_support.run_suite(suiteTest, testclass) File "C:\Python23\Lib\test\test_support.py", line 247, in run_suite raise TestFailed(err) test.test_support.TestFailed: Traceback (most recent call last): File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 311, in test_OuterInner innerTest = do_test() File "C:\code\python\tests\testBoostPython\testBoostPython.py", line 303, in do_test inner = outerTest.inner TypeError: No Python class registered for C++ class class Inner ========== Ridiculously long email footer ========== ______________________________________________________________________ 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.