From ndbecker2 at gmail.com Thu Jun 1 16:44:16 2006 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 01 Jun 2006 10:44:16 -0400 Subject: [C++-sig] make_constructor + with_custodian_and_ward Message-ID: Any ideas on this? B will hold an 'A const&'. I think I need 'with_custodian_and_ward' to ensure the 'A' object stays alive. This code won't compile: #include #include #include #include #include #include using namespace boost::python; struct A {}; struct B { B (A const& _a) : a (_a) {} A const& a; }; B* make_B (A const& a) { return new B (a); } BOOST_PYTHON_MODULE(test) { class_ ("B", no_init) .def ("__init__", make_constructor (make_B, with_custodian_and_ward_postcall<0,1>(), (arg ("A")))); } [...] /usr/local/src/boost.cvs/boost/python/with_custodian_and_ward.hpp:86: error: invalid initialization of reference of type ?PyObject* const&? from expression of type ?const boost::python::detail::offset_args >? /usr/local/src/boost.cvs/boost/python/detail/caller.hpp:50: error: in passing argument 1 of ?unsigned int boost::python::detail::arity(PyObject* const&)? From yamokosk at ufl.edu Thu Jun 1 21:00:50 2006 From: yamokosk at ufl.edu (J.D. Yamokoski) Date: Thu, 01 Jun 2006 15:00:50 -0400 Subject: [C++-sig] trouble initializing module using Boost Message-ID: <447F3962.8030506@ufl.edu> I have run into a compile error which is probably very easy to fix. I am trying to call PyImport_AppendInittab() to add the initialization of a module I have created with Boost. The exact details are of the call are: // Register the extension module if ( PyImport_AppendInittab("shapes", initshapes) == -1 ) { throw python_exception( "Failed to add shapes to the interpreter's builtin modules" ); } // Initialize the Python interpreter Py_Initialize(); .... I believe the module is defined correctly - I have used the module in the Python command line, just now trying to use it through the C-API. Here is the definition: ---- BoxModule.h ---- #include #include "Box.h" using namespace boost::python; ---- BoxModule.cpp ---- #include "BoxModule.h" BOOST_PYTHON_MODULE(shapes) { class_("MyBox") .add_property("height", &Box::getHeight, &Box::setHeight) .add_property("width", &Box::getWidth, &Box::setWidth) .add_property("length", &Box::getLength, &Box::setLength) .add_property("volume", &Box::getVolume, &Box::setVolume); } And finally, the compile error message is: error C2065: 'initshapes' : undeclared identifier So is initshapes put in a namespace? Or how do I pass this function to PyImport_AppendInittab()? From dfaure at klaralvdalens-datakonsult.se Fri Jun 2 19:10:20 2006 From: dfaure at klaralvdalens-datakonsult.se (David Faure) Date: Fri, 2 Jun 2006 19:10:20 +0200 Subject: [C++-sig] Renaming "" filename for PyRun_String Message-ID: <200606021910.21015.dfaure@klaralvdalens-datakonsult.se> Victor Nakoryakov wrote: > I use PyRun_String to run script stored in some file. I can't use > PyRun_File because of different layouts of FILE struct in my project and > in python lib. So once I get error I see something like: > > Traceback (most recent call last): > File "", line 14, in ? > NameError: ... > > Is it possible somehow to rename "" in this message to the real filename? I just had the same problem, and I solved it by copying some code out of the pythonrun.c sources... [This means it would be nice for the python developers to provide a PyRun_StringFileName(). Just like it would be nice to have a public function that calls tb_printinternal, parse_syntax_error, etc in order to print out all the info about a parsing or runtime error just like python itself does.] Anyway; this code does the job for me: #include // from python // Copied from pythonrun.c static PyObject *run_node(struct _node *n, const char *filename, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) { PyCodeObject *co; PyObject *v; co = PyNode_CompileFlags(n, filename, flags); PyNode_Free(n); if (co == NULL) return NULL; v = PyEval_EvalCode(co, globals, locals); Py_DECREF(co); return v; } // This is missing from python: a PyRun_String that also takes a filename, to show in backtraces static PyObject* MyPyRun_StringFileName(const char *str, const char* filename, int start, PyObject *globals, PyObject *locals) { struct _node* n = PyParser_SimpleParseString(str, start); if (!n) return 0; return run_node( n, filename, globals, locals, 0 ); } -- David Faure -- faure at kde.org, dfaure at klaralvdalens-datakonsult.se KDE/KOffice developer, Qt consultancy projects Klar?lvdalens Datakonsult AB, Platform-independent software solutions From ndbecker2 at gmail.com Sat Jun 3 02:31:03 2006 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 02 Jun 2006 20:31:03 -0400 Subject: [C++-sig] Can developer find true happiness with shared_ptr? Message-ID: Continuing the quest, I'm working on a framework for signal processing. The plan is to create objects in python and then compose them. The components are (in general) polymorphic. From python the components can be configured and controlled. Also, components can be retrieved back to python from the composites. I've been doing some experiments with boost::shared_ptr. It appears that if components are always stored as shared_ptr, and always passed (by value) as shared_ptr, that life is easy. For example: struct cnt { cnt (int _n) : n (_n) {} int n; }; struct A { A (boost::shared_ptr _c) : c (_c) {} boost::shared_ptr c; int get() const { return c->n; } void inc() { c->n++; } }; using namespace boost::python; BOOST_PYTHON_MODULE (testA) { class_ ("cnt", init()); class_ ("A", init >()) .def ("get", &A::get) .def ("inc", &A::inc) .def_readwrite ("c", &A::c) ; } >>> c = cnt (0) >>> a = A(c) >>> b = A(c) >>> a.c >>> b.c It appears that this design meets all the requirements. Not demonstrated above, but also polymorphism works as expected. Note that here only polymorphism of components written in c++ is required, and that is all I tested. I did not test or require that components could be subclassed in python. Just wondering if I am on the right path here? In particular, it seems there is no need for non-default call or return policies to make this work, which makes life a lot simpler. From dave at boost-consulting.com Sun Jun 4 00:27:44 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 03 Jun 2006 18:27:44 -0400 Subject: [C++-sig] trouble initializing module using Boost References: <447F3962.8030506@ufl.edu> Message-ID: "J.D. Yamokoski" writes: > I have run into a compile error which is probably very easy to > fix. I am trying to call PyImport_AppendInittab() to add the > initialization of a module I have created with Boost. The exact > details are of the call are: > > // Register the extension module > if ( PyImport_AppendInittab("shapes", initshapes) == -1 ) { > throw python_exception( "Failed to add shapes to the interpreter's > builtin modules" ); > } > > // Initialize the Python interpreter > Py_Initialize(); > .... > > I believe the module is defined correctly - I have used the module in > the Python command line, just now trying to use it through the C-API. > Here is the definition: > > ---- BoxModule.h ---- > #include > #include "Box.h" > using namespace boost::python; > > ---- BoxModule.cpp ---- > #include "BoxModule.h" > > BOOST_PYTHON_MODULE(shapes) > { > class_("MyBox") > .add_property("height", &Box::getHeight, &Box::setHeight) > .add_property("width", &Box::getWidth, &Box::setWidth) > .add_property("length", &Box::getLength, &Box::setLength) > .add_property("volume", &Box::getVolume, &Box::setVolume); > } > > And finally, the compile error message is: > > error C2065: 'initshapes' : undeclared identifier > > So is initshapes put in a namespace? Or how do I pass this function to > PyImport_AppendInittab()? You have to make a declaration visible before you can use it. Unless your PyImport_AppendInittab is in BoxModule.cpp after BOOST_PYTHON_MODULE(shapes), you have to write extern "C" initshapes(); somewhere. -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Sun Jun 4 20:59:57 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 4 Jun 2006 21:59:57 +0300 Subject: [C++-sig] Announcement: pygccxml/pyplusplus 0.8.0 Message-ID: <7465b6170606041159u1a254c28l67fe1d0d0a62c117@mail.gmail.com> I'm glad to announce the new version of pygccxml and pyplusplus packages. Next people contributed to the development: Matthias Baas Allen Bierbaum Lakin Wecker Georgiy Dernovoy Thank you! List of changes: 1. We started to use Subversion 2. Query API has been moved from pyplusplus to pygccxml. This change is fully backward compatible. Query API has been documented: http://language-binding.net/pygccxml/query_interface.html 3. pygccxml improves support for template instantiations. This is very important feature. Because, before this feature was introduced GCC-XML reported wrong names for classes and functions. Now the latest CVS version of GCCXML reports class name, mangled and demangled strings. pygccxml uses demangled string for class name. 4. pygccxml.declarations.class_t now has a list of all aliases( typedefs) to the class. pyplusplus will use the list to guess class alias, in case the class is template instantiation. 5. pyplusplus has been improved a lot: It is knows how to export reference and pointer member variables. Few internal changes, that simplifies the implementation and in a near future those changes will allow us to introduce two very important features: 1. call wrappers policy http://language-binding.net/pyplusplus/peps/call_wrapper_policies.html 2. almost fully automated solution for std containers http://language-binding.net/pyplusplus/peps/indexing_suite.html 3. Not all declarations, could be exported to Python. pyplusplus will explain you why and may be will provide a link to full explanation. 4. Not all function could be overridden in Python. pyplusplus will explain you why. 6. Bug fixes. A lot of bugs have been fixed. 7. Documentation has been improved. You can find more information about projects here: http://language-binding.net/index.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun Jun 4 21:42:14 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 4 Jun 2006 22:42:14 +0300 Subject: [C++-sig] Announcement: pyboost package - first release Message-ID: <7465b6170606041242o5c43147br999fcce9de62a7d4@mail.gmail.com> I'm glad to announce the first release of pyboost package. pyboost exports to Python functionality from next libraries: * random - a complete system for random number generation * date_time - date time library designed to provide a basis for performing efficient time calculations * crc - cyclic redundancy code computation objects * rational - rational number class pyboost has good unit tests. Almost all unit tests from the libraries have been re-written in Python. All libraries have some sample programs. All those programs has been rewritten in Python too. The libraries were exposed to Python using pyplusplus. Binaries for Windows and Linux, Python 2.4 are avaiable. You can find more information here: http://language-binding.net/pyplusplus/examples/boost/boost.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Jun 5 06:47:35 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 5 Jun 2006 07:47:35 +0300 Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <7465b6170606041242o5c43147br999fcce9de62a7d4@mail.gmail.com> References: <7465b6170606041242o5c43147br999fcce9de62a7d4@mail.gmail.com> Message-ID: <7465b6170606042147n66f8895u8019df462d972de6@mail.gmail.com> Hi. There is a problem with Linux version - the compressed file is corrupted. I will upload new file this evening. Sorry for inconvenience. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Jun 5 20:55:21 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 5 Jun 2006 21:55:21 +0300 Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <7465b6170606042147n66f8895u8019df462d972de6@mail.gmail.com> References: <7465b6170606041242o5c43147br999fcce9de62a7d4@mail.gmail.com> <7465b6170606042147n66f8895u8019df462d972de6@mail.gmail.com> Message-ID: <7465b6170606051155y5009affexfcb936662b9b58ef@mail.gmail.com> Hi. I just uploaded new Linux binaries of pyboost package. Comments and suggestions are welcome. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rwgk at yahoo.com Tue Jun 6 17:53:14 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 6 Jun 2006 08:53:14 -0700 (PDT) Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <7465b6170606051155y5009affexfcb936662b9b58ef@mail.gmail.com> Message-ID: <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > Hi. I just uploaded new Linux binaries of pyboost package. > > Comments and suggestions are welcome. I was hoping to get the pyplusplus-generated source code, but I can only find .py and .so files in the linux zip file. Is there some place I can see the generated C++ files? Thanks! Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From johnbaronreid at netscape.net Tue Jun 6 22:46:14 2006 From: johnbaronreid at netscape.net (John Reid) Date: Tue, 06 Jun 2006 21:46:14 +0100 Subject: [C++-sig] Boost::Signals Message-ID: Hi, I'm trying to call a python function from C++. I pass the function to C++ as a boost::python::object. I can call functions with no arguments, when I try to pass a C++ created object as an argument I get the following error: Traceback (most recent call last): File "python/test_python.py", line 8, in ? d.connect_new_deal_slot_py_2( f ) TypeError: No to_python (by-value) converter found for C++ type: class module::classname Now the boost.python section (http://tinyurl.com/n3cpv) in the python wiki answers the following question: "Is it is possible to convert pointers to existing classes to PyObjects* and then be able to pass an existing instance of an object directly to and from python?" where the last paragraph says: "If you really want to pass pointers around, it's certainly possible to tell the library to build a Python object around the pointer, but then you need to make sure the lifetime of the C++ object being referenced by the pointer extends past the lifetime of all Python references to the object or your program will crash." This is what I would like to do but cannot find this elsewhere in the documentation. Can anyone let me know how to do this? Thanks in advance, John. From johnbaronreid at netscape.net Tue Jun 6 23:33:24 2006 From: johnbaronreid at netscape.net (John Reid) Date: Tue, 06 Jun 2006 22:33:24 +0100 Subject: [C++-sig] Boost::Signals In-Reply-To: References: Message-ID: John Reid wrote: > Hi, > > I'm trying to call a python function from C++. I pass the function to > C++ as a boost::python::object. I can call functions with no arguments, > when I try to pass a C++ created object as an argument I get the > following error: > > Traceback (most recent call last): > File "python/test_python.py", line 8, in ? > d.connect_new_deal_slot_py_2( f ) > TypeError: No to_python (by-value) converter found for C++ type: class > module::classname > > Now the boost.python section (http://tinyurl.com/n3cpv) in the python > wiki answers the following question: > "Is it is possible to convert pointers to existing classes to PyObjects* > and then be able to pass an existing instance of an object directly to > and from python?" > > where the last paragraph says: > > "If you really want to pass pointers around, it's certainly possible to > tell the library to build a Python object around the pointer, but then > you need to make sure the lifetime of the C++ object being referenced by > the pointer extends past the lifetime of all Python references to the > object or your program will crash." > > This is what I would like to do but cannot find this elsewhere in the > documentation. Can anyone let me know how to do this? > > Thanks in advance, > John. Maybe it is better if I post a small example of what I'd like to do. Here is the C++... #pragma warning( push ) # pragma warning( disable : 4099 ) # pragma warning( disable : 4267 ) # include #pragma warning( pop ) #include using namespace boost::python; using namespace boost; struct test : noncopyable { signal< void ( object ) > _signal; void connect_slot_py( object const & slot ) { _signal.connect( slot ); //call just for testing _signal( object( this ) ); } }; BOOST_PYTHON_MODULE( test_bp ) { class_< test, noncopyable >( "test" ) .def( "connect_slot", &test::connect_slot_py ) ; //register_ptr_to_python< test * >(); } and here is the python... import test_bp def f( arg ): print 'In "f"', arg t = test_bp.test() t.connect_slot( f ) but I still get this error... Traceback (most recent call last): File "", line 1, in ? TypeError: No to_python (by-value) converter found for C++ type: struct test Any help appreciated, John. From roman.yakovenko at gmail.com Wed Jun 7 06:25:17 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 7 Jun 2006 07:25:17 +0300 Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> References: <7465b6170606051155y5009affexfcb936662b9b58ef@mail.gmail.com> <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> Message-ID: <7465b6170606062125k2301cca7h466918b86b6b26fa@mail.gmail.com> On 6/6/06, Ralf W. Grosse-Kunstleve wrote: > --- Roman Yakovenko wrote: > > > Hi. I just uploaded new Linux binaries of pyboost package. > > > > Comments and suggestions are welcome. > > I was hoping to get the pyplusplus-generated source code, but I can only find > .py and .so files in the linux zip file. Is there some place I can see the > generated C++ files? I will upload the whole pyboost project( pyplusplus scripts and generated files ) to SourceForge in few days. I will let you know. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jesus24b at gmail.com Wed Jun 7 18:25:29 2006 From: jesus24b at gmail.com (jesus garcia) Date: Wed, 7 Jun 2006 18:25:29 +0200 Subject: [C++-sig] Exception Translation Message-ID: I like export the follow simple program #define REPORT_ERROR(nerr,ErrorMsg) throw error(nerr,ErrorMsg) where error is a class Class FileName : public string { ... Void compose (const string &str, int no, const string &ext) *this=(FileName) str; if (no!=-1) { char aux_str[5]; sprintf(aux_str,"%05d",no); *this += aux_str; } if (ext!="") *this += "."+ext; else REPORT_ERROR(1005,"compose: need a extension"); } ... I no have any idea for export de class string in C++ to the class string in Python and the error I see the follow page http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exception.html that shows how catch the error but I do it and the problem persist, someone can help, I put the solution in a file who contains the BOOST_PYTHON_MODULE macro like this follow lines" #include using namespace boost::python; struct PodBayDoorException; void brack(PodBayDoorException const& x) {PyErr_SetString(PyExc_UserWarning, x);} extern void port2python_func(); BOOST_PYTHON_MODULE(_nulo) { register_exception_translator(brack); port2python_func(); ... } Thanks, From roman.yakovenko at gmail.com Wed Jun 7 20:19:13 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 7 Jun 2006 21:19:13 +0300 Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <7465b6170606062125k2301cca7h466918b86b6b26fa@mail.gmail.com> References: <7465b6170606051155y5009affexfcb936662b9b58ef@mail.gmail.com> <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> <7465b6170606062125k2301cca7h466918b86b6b26fa@mail.gmail.com> Message-ID: <7465b6170606071119w57145c8bh5307f4d460be791f@mail.gmail.com> On 6/7/06, Roman Yakovenko wrote: > On 6/6/06, Ralf W. Grosse-Kunstleve wrote: > > I was hoping to get the pyplusplus-generated source code, but I can only find > > .py and .so files in the linux zip file. Is there some place I can see the > > generated C++ files? > > I will upload the whole pyboost project( pyplusplus scripts and > generated files ) to SourceForge in few days. Good evening. I just upload almost all source file to SourceForge for pyboost package. You will not be able to create binaries, because I did not upload environment.py script, that contains configuration details: gccxml location boost location python location The main reason for this, is too much work to change location of environment.py file, within pyboost. I plan to move pyboost to be stand alone project. Download page: http://sourceforge.net/project/showfiles.php?group_id=118209 pyboost home page: http://www.language-binding.net/pyplusplus/examples/boost/boost.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From amohr at pixar.com Wed Jun 7 22:22:00 2006 From: amohr at pixar.com (Alex Mohr) Date: Wed, 07 Jun 2006 13:22:00 -0700 Subject: [C++-sig] Overloading & keyword args bug? Message-ID: <44873568.10004@pixar.com> Hi folks, Can someone tell me what's wrong with this? As is, this code crashes in the example below (anytime I try to pass keyword arguments to the first overload). If I reverse the order of the lines marked with ########, everything seems to work fine. Thanks! Alex #include #include #include using namespace boost::python; using std::string; static void f1(string const &a1, int x, int y) { printf("f1 with %s, %d, %d\n", a1.c_str(), x, y); } static void f2(string const &a1, string const &a2, int x, int y) { printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y); } BOOST_PYTHON_MODULE(overload_kw) { def("f", f1, (arg("x")=3, arg("y")=4)); // ######## def("f", f2, (arg("x")=5, arg("y")=6)); // ######## } --------------------------------------- >>> from overload_kw import * >>> f('hello') f1 with hello, 3, 4 >>> f('hello', 'goodbye') f2 with hello, goodbye, 5, 6 >>> f('hello', 1, 2) f1 with hello, 1, 2 >>> f('hello', x=1) Segmentation fault From rwgk at yahoo.com Thu Jun 8 03:44:03 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 7 Jun 2006 18:44:03 -0700 (PDT) Subject: [C++-sig] Overloading & keyword args bug? In-Reply-To: <44873568.10004@pixar.com> Message-ID: <20060608014403.58291.qmail@web31506.mail.mud.yahoo.com> --- Alex Mohr wrote: > #include > #include > #include > > using namespace boost::python; > using std::string; > > static void f1(string const &a1, int x, int y) { > printf("f1 with %s, %d, %d\n", a1.c_str(), x, y); > } > > static void f2(string const &a1, string const &a2, int x, int y) { > printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y); > } > > BOOST_PYTHON_MODULE(overload_kw) { > def("f", f1, (arg("x")=3, arg("y")=4)); // ######## > def("f", f2, (arg("x")=5, arg("y")=6)); // ######## > } I am surprised any of your tests works. AFAIK you need to make several changes: BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3) BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4) you have to give your C++ functions default arguments. you have to define all arg(), i.e something like def("f", f1, f1_overloads((arg("a1"), arg("x")=3, arg("y")=4))); At least this is what I do all the time. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From roman.yakovenko at gmail.com Thu Jun 8 07:40:03 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 8 Jun 2006 08:40:03 +0300 Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> References: <7465b6170606051155y5009affexfcb936662b9b58ef@mail.gmail.com> <20060606155314.44659.qmail@web31502.mail.mud.yahoo.com> Message-ID: <7465b6170606072240s159dc917g5e4185bd03063710@mail.gmail.com> On 6/6/06, Ralf W. Grosse-Kunstleve wrote: > I was hoping to get the pyplusplus-generated source code, but I can only find > .py and .so files in the linux zip file. Is there some place I can see the > generated C++ files? I almost forgot, pyplusplus has simple GUI, that will allow you to see generated code without learning API. There are few users that does not use API at all. You don't have to install anything ( except gccxml, pygccxml and pyplusplus ). http://www.language-binding.net/pyplusplus/tutorials/pyplusplus_demo.png http://www.language-binding.net/pyplusplus/tutorials/tutorials.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Thu Jun 8 07:44:32 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 8 Jun 2006 08:44:32 +0300 Subject: [C++-sig] Distutils: setup script for binary files In-Reply-To: <7465b6170606060502g74cba971ua41241e8e3a1acdd@mail.gmail.com> References: <7465b6170606060502g74cba971ua41241e8e3a1acdd@mail.gmail.com> Message-ID: <7465b6170606072244ld10cca0ya883b88fe8c539d2@mail.gmail.com> Hi. I asked the next question on Python list and did not get the answer. May be I will have more luck here. I want to create setup script, that will install compiled extension module plus few binaries the extension module depends on. For example: I have package X: X: __init__.py _x_.dll ( or so ) some other dll's ( so's ) _x_.dll depends on. I took a look on Python documentation, http://docs.python.org/dist/describing-extensions.html, but it only describes how to create setup script for extension module from source files. I think, I can treat _x_.dll as it was regular Python script. My problem is, that on Linux I should put "some other so's" in some directory, program loader can find. How can I do this? Any help is appreciated. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From amohr at pixar.com Thu Jun 8 18:57:10 2006 From: amohr at pixar.com (Alex Mohr) Date: Thu, 08 Jun 2006 09:57:10 -0700 Subject: [C++-sig] Overloading & keyword args bug? In-Reply-To: <20060608014403.58291.qmail@web31506.mail.mud.yahoo.com> References: <20060608014403.58291.qmail@web31506.mail.mud.yahoo.com> Message-ID: <448856E6.4070406@pixar.com> > I am surprised any of your tests works. > AFAIK you need to make several changes: > > BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3) > BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4) > > you have to give your C++ functions default arguments. Why is this? Suppose I don't want the functions to have default args in C++ -- only in python. Regardless, since I'm providing default values for the keyword arguments at def() time, I think boost.python will always have to call my function with a full set of arguments. > you have to define all arg(), i.e something like > > def("f", f1, f1_overloads((arg("a1"), arg("x")=3, arg("y")=4))); > > At least this is what I do all the time. I don't think that is (or should be) required. Suppose I want some positional-only arguments. According to the documentation for def, you may specify no more keyword arguments than the arity of f, so it seems like if you specify fewer, then they are taken as the last C++ arguments. Note that if I remove one of the overloads (one of the def lines) then everything works as expected. Perhaps David can shed some light. Alex From rwgk at yahoo.com Thu Jun 8 19:22:20 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 8 Jun 2006 10:22:20 -0700 (PDT) Subject: [C++-sig] Announcement: pyboost package - first release In-Reply-To: <7465b6170606072240s159dc917g5e4185bd03063710@mail.gmail.com> Message-ID: <20060608172220.87029.qmail@web31502.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > On 6/6/06, Ralf W. Grosse-Kunstleve wrote: > > I was hoping to get the pyplusplus-generated source code, but I can only > find > > .py and .so files in the linux zip file. Is there some place I can see the > > generated C++ files? > > I almost forgot, pyplusplus has simple GUI, that will allow you to see > generated code > without learning API. There are few users that does not use API at > all. You don't > have to install anything ( except gccxml, pygccxml and pyplusplus ). > > http://www.language-binding.net/pyplusplus/tutorials/pyplusplus_demo.png > > http://www.language-binding.net/pyplusplus/tutorials/tutorials.html I was mainly interested in seeing if you have a better __hash__ method for your rational type than the one I came up with, but I see you haven't gotten to that yet. A few years ago I wanted to use rational number instances as Python dictionary keys. In the rush of time I threw in a quick-and-dirty solution which unfortunately persists to this day: http://phenix-online.org/cctbx_sources/boost_adaptbx/rational_ext.cpp If anyone knows how to implement the hash function in a better way I'd be grateful for advice. Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From christophe.pradal at cirad.fr Thu Jun 8 18:39:13 2006 From: christophe.pradal at cirad.fr (Christophe Pradal) Date: Thu, 08 Jun 2006 18:39:13 +0200 Subject: [C++-sig] Distutils: setup script for binary files In-Reply-To: <7465b6170606072244ld10cca0ya883b88fe8c539d2@mail.gmail.com> References: <7465b6170606060502g74cba971ua41241e8e3a1acdd@mail.gmail.com> <7465b6170606072244ld10cca0ya883b88fe8c539d2@mail.gmail.com> Message-ID: <448852B1.9000104@cirad.fr> Roman Yakovenko a ?crit : > Hi. > > I asked the next question on Python list and did not get the answer. > May be I will > have more luck here. > > I want to create setup script, that will install compiled extension module > plus few binaries the extension module depends on. > > For example: I have package X: > > X: > __init__.py > _x_.dll ( or so ) > some other dll's ( so's ) _x_.dll depends on. > > I took a look on Python documentation, > http://docs.python.org/dist/describing-extensions.html, but it only > describes how to create > setup script for extension module from source files. > > I think, I can treat _x_.dll as it was regular Python script. My > problem is, that on Linux > I should put "some other so's" in some directory, program loader can find. > How can I do this? > There is no good solution. What we do is to install binary dependencies as data. Other solutions is to install first on the system the other so, then your package. > Any help is appreciated. > > Thanks > > -- > 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 > > -- Christophe Pradal Equipe INRIA/CIRAD/INRA Virtual Plants - UMR AMAP TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France http://www-sop.inria.fr/virtualplants tel : (33) 4 67 61 75 63 fax : (33) 4 67 61 56 68 email : christophe.pradal at cirad.fr http://amap.cirad.fr From rwgk at yahoo.com Thu Jun 8 19:26:24 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 8 Jun 2006 10:26:24 -0700 (PDT) Subject: [C++-sig] Overloading & keyword args bug? In-Reply-To: <448856E6.4070406@pixar.com> Message-ID: <20060608172624.51396.qmail@web31505.mail.mud.yahoo.com> --- Alex Mohr wrote: > > I am surprised any of your tests works. > > AFAIK you need to make several changes: > > > > BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3) > > BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4) > > > > you have to give your C++ functions default arguments. > > Why is this? Suppose I don't want the functions to have default args in > C++ -- only in python. I'd simply write a thin C++ wrapper which supplies the default arguments. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From amohr at pixar.com Thu Jun 8 19:45:31 2006 From: amohr at pixar.com (Alex Mohr) Date: Thu, 08 Jun 2006 10:45:31 -0700 Subject: [C++-sig] Overloading & keyword args bug? In-Reply-To: <20060608172624.51396.qmail@web31505.mail.mud.yahoo.com> References: <20060608172624.51396.qmail@web31505.mail.mud.yahoo.com> Message-ID: <4488623B.9010600@pixar.com> Ralf W. Grosse-Kunstleve wrote: > --- Alex Mohr wrote: > >>> I am surprised any of your tests works. >>> AFAIK you need to make several changes: >>> >>> BOOST_PYTHON_FUNCTION_OVERLOADS(f1_overloads, f1, 1, 3) >>> BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, f2, 2, 4) >>> >>> you have to give your C++ functions default arguments. >> Why is this? Suppose I don't want the functions to have default args in >> C++ -- only in python. > > I'd simply write a thin C++ wrapper which supplies the default arguments. Clearly that's potentially a way to work around this, but it seems silly. Another workaround is to swap the order of the defs. But really, if it works with only one of the overloads, why shouldn't it work with both? This really seems like a bug to me. Alex From roman.yakovenko at gmail.com Thu Jun 8 20:07:48 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 8 Jun 2006 21:07:48 +0300 Subject: [C++-sig] Distutils: setup script for binary files In-Reply-To: <448852B1.9000104@cirad.fr> References: <7465b6170606060502g74cba971ua41241e8e3a1acdd@mail.gmail.com> <7465b6170606072244ld10cca0ya883b88fe8c539d2@mail.gmail.com> <448852B1.9000104@cirad.fr> Message-ID: <7465b6170606081107r8338e6eh4a28f7f7cd3f4814@mail.gmail.com> On 6/8/06, Christophe Pradal wrote: > There is no good solution. What we do is to install binary dependencies > as data. > Other solutions is to install first on the system the other so, then > your package. Thanks, I though I missed something very trivial. Actually there is a better way: ask user where he want to put those files. Here is relevant links how to achieve this: http://docs.python.org/dist/node29.html And example http://tinyurl.com/jcvma See doc_cmd class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From sebastian.redl at getdesigned.at Fri Jun 9 14:27:20 2006 From: sebastian.redl at getdesigned.at (Sebastian Redl) Date: Fri, 09 Jun 2006 14:27:20 +0200 Subject: [C++-sig] [Boost.Python] Extracting indirect base. Message-ID: <44896928.20103@getdesigned.at> Hi, I've got a hand-wrapped plugin interface hierarchy for my program allowing implementing plugins in Python. This looks approximately like this: class Plugin { public: virtual void init() = 0; virtual PluginCategory getCategory() = 0; // Subtype of the plugin // ... }; class InputPlugin : public Plugin { public: virtual void loadData(const string &resource, DataBag &target) = 0; }; class OutputPlugin : public Plugin { public: virtual void saveData(const string &resource, const DataBag &source) = 0; }; These are the plugin interfaces. PluginCategory is an enum identifying the concrete subtype of the plugin, i.e. either Input or Output. I've got them wrapped like this: class PluginWrap : public Plugin, public boost::python::wrapper { virtual void init() { this->get_override("init")(); } // ... }; class InputPlugin : public InputPlugin, public boost::python::wrapper { virtual void loadData(...) { ... } }; // ... BOOST_PYTHON_MODULE(myprogram) { class_("Plugin") .def("init", pure_virtual(&Plugin::init)) .def( ... ) ; class_, boost::noncopyable>("InputPlugin") .def("loadData", ...) ; // ... } A plugin file looks like this: from myprogram import * class SomePlugin(InputPlugin): def init(self): // ... // ... plugins = [SomePlugin()] I then attempt to load these modules like this: PythonLoader::load(const path &file) { // Parse file and get namespace object for it. Get the "plugins" list and extract a python::list. Get the length of that list. python::list plugs = ...; int len = // get length of plugs for(int i = 0; i < len; ++i) { try { py::object plug = plugs[i]; Plugin *plugin = py::extract(plug); // <------------- plugins.push_back(plugin); } catch(py::error_already_set &e) { // handle error } } } Finally, my problem: the extract call fails: TypeError: No registered converter was able to extract a C++ pointer to type Plugin from this Python object of type SomePlugin So here are my questions: 1) Is this expected behaviour? Does my wrapping not register the appropriate base pointer extractors? 2) How can I manually register appropriate converters? 3) If 2 is not possible, how can I work around the problem? Thanks in advance Sebastian Redl From dave at boost-consulting.com Mon Jun 12 15:56:08 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jun 2006 09:56:08 -0400 Subject: [C++-sig] [Boost.Python] Extracting indirect base. References: <44896928.20103@getdesigned.at> Message-ID: Sebastian Redl writes: > class_, ^^^^^^ should be just Plugin, I think. > boost::noncopyable>("InputPlugin") > .def("loadData", ...) > ; -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Jun 12 16:08:30 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jun 2006 10:08:30 -0400 Subject: [C++-sig] Exception Translation References: Message-ID: "jesus garcia" writes: > I like export the follow simple program > > #define REPORT_ERROR(nerr,ErrorMsg) throw error(nerr,ErrorMsg) > > where error is a class > > Class FileName : public string { > ... > Void compose (const string &str, int no, const string &ext) > *this=(FileName) str; > if (no!=-1) { > char aux_str[5]; > sprintf(aux_str,"%05d",no); > *this += aux_str; > } > > if (ext!="") *this += "."+ext; > else REPORT_ERROR(1005,"compose: need a extension"); > } > ... Driving from string is a bad idea for many reasons, but anyway. > I no have any idea for export de class string in C++ to the class > string in Python You can't; it's already done automatically, but you can't derive from it, because std::string is mapped into python's "str" type, which isn't a Boost.Python wrapper class. If you derive your C++ exception types from std::exception you'll get automatic translation of the what() string into Python. > and the error I see the follow page > http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exception.html > that shows how catch the error but I do it and the problem persist, You haven't told us what the problem is. > someone can help, > > I put the solution in a file who contains the BOOST_PYTHON_MODULE > macro like this follow lines" > > #include > using namespace boost::python; > > struct PodBayDoorException; > > void brack(PodBayDoorException const& x) > {PyErr_SetString(PyExc_UserWarning, x);} > > extern void port2python_func(); > > BOOST_PYTHON_MODULE(_nulo) { > register_exception_translator(brack); > port2python_func(); > ... > } I'm not sure what you're trying to do here. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Jun 12 16:12:57 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jun 2006 10:12:57 -0400 Subject: [C++-sig] Overloading & keyword args bug? References: <44873568.10004@pixar.com> Message-ID: Alex Mohr writes: > Hi folks, > > Can someone tell me what's wrong with this? As is, this code crashes in > the example below (anytime I try to pass keyword arguments to the first > overload). If I reverse the order of the lines marked with ########, > everything seems to work fine. > > Thanks! > > Alex > > > #include > #include > #include > > using namespace boost::python; > using std::string; > > static void f1(string const &a1, int x, int y) { > printf("f1 with %s, %d, %d\n", a1.c_str(), x, y); > } > > static void f2(string const &a1, string const &a2, int x, int y) { > printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y); > } > > BOOST_PYTHON_MODULE(overload_kw) { > def("f", f1, (arg("x")=3, arg("y")=4)); // ######## > def("f", f2, (arg("x")=5, arg("y")=6)); // ######## > } > > --------------------------------------- > > >>> from overload_kw import * > >>> f('hello') > f1 with hello, 3, 4 > >>> f('hello', 'goodbye') > f2 with hello, goodbye, 5, 6 > >>> f('hello', 1, 2) > f1 with hello, 1, 2 > >>> f('hello', x=1) > Segmentation fault Broken compiler code generation? The enclosed works for me without errors. Got a stack backtrace? -------------- next part -------------- A non-text attachment was scrubbed... Name: alex_mohr.zip Type: application/zip Size: 1875 bytes Desc: not available URL: -------------- next part -------------- myjam -sTOOLS=vc-8_0 --verbose-test test ...found 1671 targets... ...updating 6 targets... vc-C++ c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack.obj quack.cpp vc-Link c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.pyd c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.lib Creating library c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.lib and object c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.exp Microsoft (R) Manifest Tool version 5.2.3790.2014. Copyright (c) Microsoft Corporation 2005. . All rights reserved.. execute-test c:\tmp\build\bin\boost\libs\python\user\quack.test\vc-8_0\debug\threading-multi\quack.run 1 file(s) copied. ====== BEGIN OUTPUT ====== # installing zipimport hook import zipimport # builtin # installed zipimport hook # c:\Python24\lib\site.pyc matches c:\Python24\lib\site.py import site # precompiled from c:\Python24\lib\site.pyc # c:\Python24\lib\os.pyc matches c:\Python24\lib\os.py import os # precompiled from c:\Python24\lib\os.pyc import nt # builtin # c:\Python24\lib\ntpath.pyc matches c:\Python24\lib\ntpath.py import ntpath # precompiled from c:\Python24\lib\ntpath.pyc # c:\Python24\lib\stat.pyc matches c:\Python24\lib\stat.py import stat # precompiled from c:\Python24\lib\stat.pyc # c:\Python24\lib\UserDict.pyc matches c:\Python24\lib\UserDict.py import UserDict # precompiled from c:\Python24\lib\UserDict.pyc # c:\Python24\lib\copy_reg.pyc matches c:\Python24\lib\copy_reg.py import copy_reg # precompiled from c:\Python24\lib\copy_reg.pyc # c:\Python24\lib\types.pyc matches c:\Python24\lib\types.py import types # precompiled from c:\Python24\lib\types.pyc # c:\Python24\lib\locale.pyc matches c:\Python24\lib\locale.py import locale # precompiled from c:\Python24\lib\locale.pyc import _locale # builtin # c:\Python24\lib\codecs.pyc matches c:\Python24\lib\codecs.py import codecs # precompiled from c:\Python24\lib\codecs.pyc import _codecs # builtin import encodings # directory c:\Python24\lib\encodings # c:\Python24\lib\encodings\__init__.pyc matches c:\Python24\lib\encodings\__init__.py import encodings # precompiled from c:\Python24\lib\encodings\__init__.pyc # c:\Python24\lib\encodings\aliases.pyc matches c:\Python24\lib\encodings\aliases.py import encodings.aliases # precompiled from c:\Python24\lib\encodings\aliases.pyc # c:\Python24\lib\encodings\cp1252.pyc matches c:\Python24\lib\encodings\cp1252.py import encodings.cp1252 # precompiled from c:\Python24\lib\encodings\cp1252.pyc # c:\Python24\lib\warnings.pyc matches c:\Python24\lib\warnings.py import warnings # precompiled from c:\Python24\lib\warnings.pyc # c:\Python24\lib\linecache.pyc matches c:\Python24\lib\linecache.py import linecache # precompiled from c:\Python24\lib\linecache.pyc Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import quack_ext # dynamically loaded from c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.pyd # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] locale # cleanup[1] site # cleanup[1] encodings # cleanup[1] quack_ext # cleanup[1] nt # cleanup[1] zipimport # cleanup[1] warnings # cleanup[1] _codecs # cleanup[1] encodings.cp1252 # cleanup[1] codecs # cleanup[1] types # cleanup[1] _locale # cleanup[1] signal # cleanup[1] linecache # cleanup[1] encodings.aliases # cleanup[1] exceptions # cleanup[2] copy_reg # cleanup[2] os.path # cleanup[2] ntpath # cleanup[2] UserDict # cleanup[2] stat # cleanup[2] os # cleanup sys # cleanup __builtin__ # cleanup ints: 7 unfreed ints in 1 out of 5 blocks # cleanup floats f1 with hello, 3, 4 f2 with hello, goodbye, 5, 6 f1 with hello, 1, 2 f1 with hello, 1, 4 EXIT STATUS: 0 ====== END OUTPUT ====== **passed** c:\tmp\build\bin\boost\libs\python\user\quack.test\vc-8_0\debug\threading-multi\quack.test ...updated 6 targets... -- Dave Abrahams Boost Consulting www.boost-consulting.com From amohr at pixar.com Mon Jun 12 19:41:21 2006 From: amohr at pixar.com (Alex Mohr) Date: Mon, 12 Jun 2006 10:41:21 -0700 Subject: [C++-sig] Overloading & keyword args bug? In-Reply-To: References: <44873568.10004@pixar.com> Message-ID: <448DA741.6010705@pixar.com> > Broken compiler code generation? The enclosed works for me without > errors. Got a stack backtrace? Interesting. Thanks for looking at it, David. The stack from gdb is bogus (2 empty frames). This is with gcc 4.0.1 on linux. I'll try with 4.0.1 on OSX and see if it's any different. We're supposed to upgrade to 4.0.3 this week, I think. I'll try that when I can. Anyone else out there with who's willing to try this? I'm particularly interested to confirm/deny with another gcc 4.0.x user. Alex From dave at boost-consulting.com Mon Jun 12 20:48:45 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jun 2006 14:48:45 -0400 Subject: [C++-sig] Overloading & keyword args bug? References: <44873568.10004@pixar.com> <448DA741.6010705@pixar.com> Message-ID: Alex Mohr writes: >> Broken compiler code generation? The enclosed works for me without >> errors. Got a stack backtrace? > > Interesting. Thanks for looking at it, David. > > The stack from gdb is bogus (2 empty frames). This is with gcc 4.0.1 on > linux. I'll try with 4.0.1 on OSX and see if it's any different. > We're supposed to upgrade to 4.0.3 this week, I think. I'll try that > when I can. > > Anyone else out there with who's willing to try this? I'm particularly > interested to confirm/deny with another gcc 4.0.x user. Works for me with g++-4.0.2/4.0.0 on Cygwin also (with the boost CVS HEAD). -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Tue Jun 13 00:25:54 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 12 Jun 2006 23:25:54 +0100 Subject: [C++-sig] Code generation bug in pyplusplus Message-ID: <448DF802.5375.2134119@s_sourceforge.nedprod.com> Back onto getting the python bindings for TnFOX working again. I'm using the latest from SVN. Pyplusplus generates bad code here: FXPrimaryButton_wrapper(::FX::FXComposite * parent, ::FX::FXString const & text, ::FX::FXIcon * icon=0, ::FX::FXObject * tgt=0, ::FX::FXSelector sel=0, ::FX::FXuint opts=::FX::FXuint(::FX::PBUTTON_NORMAL), ::FX::FXint x=0, ::FX::FXint y=0, ::FX::FXint w=0, ::FX::FXint h=0, ::FX::FXint pl=(FX::FXWindow::defaultPadding()() * 4), ::FX::FXint pr=(FX::FXWindow::defaultPadding()() * 4), ::FX::FXint pt=FX::FXWindow::defaultPadding( ), ::FX::FXint pb=FX::FXWindow::defaultPadding( ), ::FX::FXint sr=0 ) : FX::FXPrimaryButton( parent, text, icon, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb, sr ) , bp::wrapper< FX::FXPrimaryButton >() {} It should be: FXPrimaryButton_wrapper(::FX::FXComposite * parent, ::FX::FXString const & text, ::FX::FXIcon * icon=0, ::FX::FXObject * tgt=0, ::FX::FXSelector sel=0, ::FX::FXuint opts=::FX::FXuint(::FX::PBUTTON_NORMAL), ::FX::FXint x=0, ::FX::FXint y=0, ::FX::FXint w=0, ::FX::FXint h=0, ::FX::FXint pl=(FX::FXWindow::defaultPadding() * 4), ::FX::FXint pr=(FX::FXWindow::defaultPadding() * 4), ::FX::FXint pt=FX::FXWindow::defaultPadding( ), ::FX::FXint pb=FX::FXWindow::defaultPadding( ), ::FX::FXint sr=0 ) : FX::FXPrimaryButton( parent, text, icon, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb, sr ) , bp::wrapper< FX::FXPrimaryButton >() {} Note the difference? FXWindow::defaultPadding() has an extra () after it. It seems pyplusplus only makes this mistake when it's an expression eg; when multiplied by 4 as above. Cheers, Niall From s_sourceforge at nedprod.com Tue Jun 13 03:53:00 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 13 Jun 2006 02:53:00 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output Message-ID: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> How do I insert custom code into the BOOST_PYTHON_MODULE() output from pyplusplus? I want: extern void InitialiseTnFOXPython(); BOOST_PYTHON_MODULE(TnFOX){ InitialiseTnFOXPython(); register_enumerations(); register_FXVec3f_class(); ... I can't see any way from the sources on how to do this :( Next bit of custom code: In FXApp::init(), it takes mandatory parameters of void init( int & argc, char * * argv, ::FX::FXbool connect ). Obviously, BPL doesn't know to match a list of strings to a char **argv, so under pyste I inserted the following custom code: DEFINE_MAKECARRAYITER(FXApp, const FX::FXchar *, getArgv, (), c.getArgc()) static void FXApp_init(FXApp &app, int argc, list argv, unsigned char connect=TRUE) { int n, size=PyList_Size(argv.ptr()); static QMemArray array; array.resize(size+1); for(n=0; n()) + .def("getArgv", &FXApp_getArgv) So can pyplusplus be extended to automatically generate this kind of accessor code, if not how can I insert this custom code via pyplusplus? (We are very close to a working TnFOX python bindings. Yay!) Cheers, Niall From roman.yakovenko at gmail.com Tue Jun 13 10:40:19 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 13 Jun 2006 11:40:19 +0300 Subject: [C++-sig] Code generation bug in pyplusplus In-Reply-To: <448DF802.5375.2134119@s_sourceforge.nedprod.com> References: <448DF802.5375.2134119@s_sourceforge.nedprod.com> Message-ID: <7465b6170606130140g4e447d22g4c617705780f3e43@mail.gmail.com> On 6/13/06, Niall Douglas wrote: > Back onto getting the python bindings for TnFOX working again. Good. > I'm using the latest from SVN. It has same functionality and bugs ( :-) ) as 0.8.0 version > Note the difference? FXWindow::defaultPadding() has an extra () after > it. It seems pyplusplus only makes this mistake when it's an > expression eg; when multiplied by 4 as above. I agree that this is a bug, but this is GCC-XML bug. If you will take a look on generated xml file you will find that all "defaultPadding" have extra (). pygccxml aware of such bug ( and some other ) and fixes them. In this case it can do nothing. Fortunately you have the way to fix the bug: mb = module_builder_t( ... ) constr = mb.constructor( 'FXPrimaryButton' , arg_types=[None]*number of arguments ) constr.arguments[x].default_value = new default value If the query, I wrote, does not work for you, you will have to refine it. You can read more about "query interface" here: http://language-binding.net/pygccxml/query_interface.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Jun 13 10:59:10 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 13 Jun 2006 11:59:10 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> Message-ID: <7465b6170606130159n55bba9faw9377ebe74d159c0d@mail.gmail.com> On 6/13/06, Niall Douglas wrote: > How do I insert custom code into the BOOST_PYTHON_MODULE() output > from pyplusplus? > > > I want: > > extern void InitialiseTnFOXPython(); > > BOOST_PYTHON_MODULE(TnFOX){ > InitialiseTnFOXPython(); from pyplusplus import code_creators mb = module_builder_t( ... ) mb.build_code_creator( ... ) code = your code mb.code_creator.body.adopt_creator( code_creators.custom_text_t( code ), 0 ) > I can't see any way from the sources on how to do this :( I will try to document code creators before next release > > Next bit of custom code: > > In FXApp::init(), it takes mandatory parameters of void init( int & > argc, char * * argv, ::FX::FXbool connect ). Obviously, BPL doesn't > know to match a list of strings to a char **argv, so under pyste I > inserted the following custom code: > > DEFINE_MAKECARRAYITER(FXApp, const FX::FXchar *, getArgv, (), > c.getArgc()) > static void FXApp_init(FXApp &app, int argc, list argv, unsigned char > connect=TRUE) > { > int n, size=PyList_Size(argv.ptr()); > static QMemArray array; > array.resize(size+1); > for(n=0; n { > array[n]=PyString_AsString(PyList_GetItem(argv.ptr(), n)); > } > array[n]=0; > app.init(argc, (char **)(array.data()), connect); > } > static void FXApp_init2(FXApp &app, int argc, list argv) > { > FXApp_init(app, argc, argv); > } > > ... and then I replaced: > > - .def("init", &FX::FXApp::init, > &TnFOX::FX_FXApp_Wrapper::default_init_3) > - .def("init", &TnFOX::FX_FXApp_Wrapper::default_init_2) > + .def("init", &FXApp_init) > + .def("init", &FXApp_init2) > > - .def("getArgv", &FX::FXApp::getArgv, > return_internal_reference< 1 >()) > + .def("getArgv", &FXApp_getArgv) > > So can pyplusplus be extended to automatically generate this kind of > accessor code We are working on this: http://language-binding.net/pyplusplus/peps/call_wrapper_policies.html > if not how can I insert this custom code via pyplusplus? 1. You should exclude FXApp::init functions from being exposed, right? mb = module_builder_t( ... _ FXApp = mb.class_( 'FXApp' ) FXApp.member_functions( 'init' ).exclude() init = """def("init", &FX::FXApp::init, &TnFOX::FX_FXApp_Wrapper::default_init_3)""" FXApp.add_code( init ) ... > We are very close to a working TnFOX python bindings. Yay! It is really good news :-). I am glad you find the time to work on this project. I have few ideas about new GUI to pyplusplus. May be I will implement it using Python bindings to TnFOX, we'll see. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mat at matbray.com Tue Jun 13 14:23:37 2006 From: mat at matbray.com (Matthew Bray) Date: Tue, 13 Jun 2006 14:23:37 +0200 Subject: [C++-sig] missing procedure entry point in boost_python.dll Message-ID: I just downloaded the 1.33.1 distribution of the boost libraries for Windows and quickly set up the Boost.Python Hello example in VC++ 6.5 by following the documentation on the boost site. Everything appears to compile well enough in both debug and release versions however when attempting to use the library I get this error: The procedure entry point ??1py_function_impl_base at objects@python at boost@@UAE at XZ could not be located in the dynamic link library boost_python.dll The same error occurs when attempting to use python 2.2.3 and 2.4. The name isn't entirely mangled so perhaps it can be of some help - has anyway has anyone come across this issue before, is it easily solvable? I didnt see this error when using a much older boost 1.29 Regards, Mat. From s_sourceforge at nedprod.com Tue Jun 13 16:15:51 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 13 Jun 2006 15:15:51 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <7465b6170606130159n55bba9faw9377ebe74d159c0d@mail.gmail.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> Message-ID: <448ED6A7.2219.145840@s_sourceforge.nedprod.com> On 13 Jun 2006 at 11:59, Roman Yakovenko wrote: > > So can pyplusplus be extended to automatically generate this kind of > > accessor code > > We are working on this: > http://language-binding.net/pyplusplus/peps/call_wrapper_policies.html You may find the code defining the macro DEFINE_MAKECARRAYITER() very useful in TnFOX. It allows access to dynamic arrays which can be modified and extended by a python list interface. Also, you can't get pyplusplus to generate thread safe code alone. You need alterations to BPL because the iterator interface needs GIL unlocking, and nowhere does BPL pass through pyplusplus code to allow this. The patches required to BPL are moderate however and would cost little in runtime overhead. You basically need two installable function pointers to do the GIL locking and unlocking. Cheers, Niall From s_sourceforge at nedprod.com Tue Jun 13 16:15:51 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 13 Jun 2006 15:15:51 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <7465b6170606130159n55bba9faw9377ebe74d159c0d@mail.gmail.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> Message-ID: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> On 13 Jun 2006 at 11:59, Roman Yakovenko wrote: > > if not how can I insert this custom code via pyplusplus? > > 1. You should exclude FXApp::init functions from being exposed, right? > > mb = module_builder_t( ... _ > FXApp = mb.class_( 'FXApp' ) > FXApp.member_functions( 'init' ).exclude() > init = """def("init", &FX::FXApp::init, > &TnFOX::FX_FXApp_Wrapper::default_init_3)""" > FXApp.add_code( init ) > ... Unfortunately, FXApp::init is a required function for all GUI programs. It also mandatorily takes argc and argv. > > We are very close to a working TnFOX python bindings. Yay! > > It is really good news :-). I am glad you find the time to work on this project. > I have few ideas about new GUI to pyplusplus. May be I will implement it using > Python bindings to TnFOX, we'll see. If pyplusplus doesn't yet support these things, I can also patch them in and supply a diff file to apply on the resulting bindings in the short term. It would be really great if we had a real world user of the TnFOX python bindings. Cheers, Niall From roman.yakovenko at gmail.com Tue Jun 13 20:13:20 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 13 Jun 2006 21:13:20 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> <7465b6170606130159n55bba9faw9377ebe74d159c0d@mail.gmail.com> <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> Message-ID: <7465b6170606131113x39df721ena98821790150ce9f@mail.gmail.com> On 6/13/06, Niall Douglas wrote: > On 13 Jun 2006 at 11:59, Roman Yakovenko wrote: > > > > if not how can I insert this custom code via pyplusplus? > > > > 1. You should exclude FXApp::init functions from being exposed, right? > > > > mb = module_builder_t( ... _ > > FXApp = mb.class_( 'FXApp' ) > > FXApp.member_functions( 'init' ).exclude() > > init = """def("init", &FX::FXApp::init, > > &TnFOX::FX_FXApp_Wrapper::default_init_3)""" > > FXApp.add_code( init ) > > ... > > Unfortunately, FXApp::init is a required function for all GUI > programs. It also mandatorily takes argc and argv. I think I was not clear. I showed you the way to replace code that would be generated by pyplusplus for FXApp::init member function, with your own code. > > > We are very close to a working TnFOX python bindings. Yay! > > > > It is really good news :-). I am glad you find the time to work on this project. > > I have few ideas about new GUI to pyplusplus. May be I will implement it using > > Python bindings to TnFOX, we'll see. > > If pyplusplus doesn't yet support these things, I can also patch them > in and supply a diff file to apply on the resulting bindings in the > short term. It is not as simple as I'd like it to be. I still try to find elegant way to implement this. > It would be really great if we had a real world user of the TnFOX > python bindings. :-) I understand you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From niki at vintech.bg Tue Jun 13 20:08:10 2006 From: niki at vintech.bg (Niki) Date: Tue, 13 Jun 2006 21:08:10 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> Message-ID: <448EFF0A.8010501@vintech.bg> Niall Douglas wrote: > It would be really great if we had a real world user of the TnFOX > python bindings. > > When will they be ready? Niki Spahiev From roman.yakovenko at gmail.com Tue Jun 13 20:19:25 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 13 Jun 2006 21:19:25 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <448ED6A7.2219.145840@s_sourceforge.nedprod.com> References: <448E288C.7303.2D0DF55@s_sourceforge.nedprod.com> <7465b6170606130159n55bba9faw9377ebe74d159c0d@mail.gmail.com> <448ED6A7.2219.145840@s_sourceforge.nedprod.com> Message-ID: <7465b6170606131119o338fe43bl51ae366074b860af@mail.gmail.com> On 6/13/06, Niall Douglas wrote: > On 13 Jun 2006 at 11:59, Roman Yakovenko wrote: > > > > So can pyplusplus be extended to automatically generate this kind of > > > accessor code > > > > We are working on this: > > http://language-binding.net/pyplusplus/peps/call_wrapper_policies.html > > You may find the code defining the macro DEFINE_MAKECARRAYITER() very > useful in TnFOX. It allows access to dynamic arrays which can be > modified and extended by a python list interface. Thank you, I will take a look on the code and will find out how to integrate it with pyplusplus. > Also, you can't get pyplusplus to generate thread safe code alone. > You need alterations to BPL because the iterator interface needs GIL > unlocking, and nowhere does BPL pass through pyplusplus code to allow > this. > > The patches required to BPL are moderate however and would cost > little in runtime overhead. You basically need two installable > function pointers to do the GIL locking and unlocking. I understand this. I just thought that sometimes it will be enough to make some function thread safe. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boost-consulting.com Wed Jun 14 01:11:50 2006 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 13 Jun 2006 19:11:50 -0400 Subject: [C++-sig] missing procedure entry point in boost_python.dll References: Message-ID: Matthew Bray writes: > I just downloaded the 1.33.1 distribution of the boost libraries for > Windows and quickly set up the Boost.Python Hello example in VC++ 6.5 by > following the documentation on the boost site. Everything appears to > compile well enough in both debug and release versions however when > attempting to use the library I get this error: > > The procedure entry point > ??1py_function_impl_base at objects@python at boost@@UAE at XZ could not be > located in the dynamic link library boost_python.dll > > The same error occurs when attempting to use python 2.2.3 and 2.4. > > The name isn't entirely mangled so perhaps it can be of some help - has > anyway has anyone come across this issue before, is it easily solvable? > I didnt see this error when using a much older boost 1.29 Did you use Boost.Build to compile your test? Boost.Python passed all its tests with vc6.5 for the 1.33.1 release, and the tests are all run through Boost.Build. Probably you have the wrong combination of compiler/linker switches. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Wed Jun 14 23:24:48 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 14 Jun 2006 22:24:48 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <7465b6170606131113x39df721ena98821790150ce9f@mail.gmail.com> References: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> Message-ID: <44908CB0.961.968DBF@s_sourceforge.nedprod.com> On 13 Jun 2006 at 21:13, Roman Yakovenko wrote: > > > mb = module_builder_t( ... _ > > > FXApp = mb.class_( 'FXApp' ) > > > FXApp.member_functions( 'init' ).exclude() > > > init = """def("init", &FX::FXApp::init, > > > &TnFOX::FX_FXApp_Wrapper::default_init_3)""" > > > FXApp.add_code( init ) > > > ... > > > > Unfortunately, FXApp::init is a required function for all GUI > > programs. It also mandatorily takes argc and argv. > > I think I was not clear. I showed you the way to replace code that would > be generated by pyplusplus for FXApp::init member function, with your own code. Ah right. I did get that bit, but I didn't see how to custom insert some text before the RegisterFXApp() function. For example, if using the above trying: FXApp.parent.adopt_creator(code_creators.custom_text_t()) ... it turns out FXApp.parent is a namespace, and it wouldn't let me adopt custom code into it. Once again, consulting the source left me pretty clueless :( Cheers, Niall From s_sourceforge at nedprod.com Wed Jun 14 23:24:48 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 14 Jun 2006 22:24:48 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <448EFF0A.8010501@vintech.bg> References: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> Message-ID: <44908CB0.30130.968D13@s_sourceforge.nedprod.com> On 13 Jun 2006 at 21:08, Niki wrote: > Niall Douglas wrote: > > It would be really great if we had a real world user of the TnFOX > > python bindings. > > > > > When will they be ready? It'll be soon. But I'll have to say "when it's done". I'm currently seeing a strange segfault inside python. Going to have to compile my own with debug symbols to find out what's going on. Cheers, Niall From roman.yakovenko at gmail.com Thu Jun 15 07:55:13 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 15 Jun 2006 08:55:13 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <44908CB0.961.968DBF@s_sourceforge.nedprod.com> References: <448ED6A7.3101.1457E2@s_sourceforge.nedprod.com> <7465b6170606131113x39df721ena98821790150ce9f@mail.gmail.com> <44908CB0.961.968DBF@s_sourceforge.nedprod.com> Message-ID: <7465b6170606142255h7e5ccabfha8a64ba9e8ee2120@mail.gmail.com> On 6/15/06, Niall Douglas wrote: > On 13 Jun 2006 at 21:13, Roman Yakovenko wrote: > > > > > mb = module_builder_t( ... _ > > > > FXApp = mb.class_( 'FXApp' ) > > > > FXApp.member_functions( 'init' ).exclude() > > > > init = """def("init", &FX::FXApp::init, > > > > &TnFOX::FX_FXApp_Wrapper::default_init_3)""" > > > > FXApp.add_code( init ) > > > > ... > > > > > > Unfortunately, FXApp::init is a required function for all GUI > > > programs. It also mandatorily takes argc and argv. > > > > I think I was not clear. I showed you the way to replace code that would > > be generated by pyplusplus for FXApp::init member function, with your own code. > > Ah right. I did get that bit, but I didn't see how to custom insert > some text before the RegisterFXApp() function. For example, if using > the above trying: > > FXApp.parent.adopt_creator(code_creators.custom_text_t( replacement definition>)) > > ... it turns out FXApp.parent is a namespace, and it wouldn't let me > adopt custom code into it. > > Once again, consulting the source left me pretty clueless :( I did not write FXApp.parent - this will not work, you already know this. If you want to insert a code in some specific place, then : module.body.adopt_creator( code_creators.custom_text_t( ... ), position ) ( By default the code creator will be appended to the end of the list ) module is top level, root, main code creator. It derives from compound_t code creator. So it keeps a list of other code creators, including module_body_t. If you take a look in debugger on module_t code creator ( mb.code_creator ) you will see something like this: ... #<= it generates BOOST_PYTHON_MODULE macro ... FXApp is not code creator, but declaration. Declarations tree is used as input to code creators factory. They are different beast. Am I clear? If you need more explanation, please ask some specific question, okay? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Thu Jun 15 13:40:37 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 15 Jun 2006 12:40:37 +0100 Subject: [C++-sig] More pyplusplus custom stuff Message-ID: <44915545.5613.272220@s_sourceforge.nedprod.com> The good news is I now have a set of fully working bindings, or at least to the stage of where TnFOX was at the v0.85 release. The next problem is the orphaned child problem. TnFOX's GUI objects, much like most C++ GUI toolkits, manage their own children. If you delete the parent, it deletes all its children. Needless to say, this is a problem for Python. The solution is to upcall any child deletions so BPL can unhook the relevent python object from its C++ sibling. This is done by replacing the virtual functions: virtual void *getPythonObject() const; virtual void decouplePythonObject() const; Therefore, we need to do the following: For every class in the FX namespace which has FXObject as a base class, insert into EVERY constructor of the wrapper class the following code: FXPython::int_pythonObjectCreated((int_decouplingFunctor=Generic::Bind ObjN(*this, &"+wrapper_name+"::decouplePythonObject))); Into private member variables of the wrapper class: Generic::BoundFunctorV *int_decouplingFunctor; Into every destructor of the wrapper class: ~"+wrapper_name+"() { FXPython::int_pythonObjectDeleted(int_decouplingFunctor); using namespace boost::python; using namespace std; PyObject *py_self=get_owner(this); // We must be careful not to reinvoke object destruction! py_self->ob_refcnt=1<<16; { object me(boost::python::handle<>(borrowed(py_self))); auto_ptr<"+wrapper_name+"> &autoptr=extract &>(me); autoptr.release(); } py_self->ob_refcnt=0 } Into every body of the wrapper class: virtual void *getPythonObject() const { return (void *) get_owner(this); } virtual void decouplePythonObject() const { using namespace boost::python; using namespace std; object me(boost::python::handle<>(borrowed(py_self))); auto_ptr<"+wrapper_name+"> &autoptr=extract &>(me); autoptr.reset(0); } So, how does one achieve this then? Cheers, Niall From dave at boost-consulting.com Thu Jun 15 15:15:58 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 15 Jun 2006 09:15:58 -0400 Subject: [C++-sig] More pyplusplus custom stuff References: <44915545.5613.272220@s_sourceforge.nedprod.com> Message-ID: "Niall Douglas" writes: > The solution is to upcall any child deletions so BPL can unhook the > relevent python object from its C++ sibling. You could simplify that system a lot by using shared_ptr to hold the children in C++, and building a new smart pointer around a core weak_ptr, that you use as the HeldType in your Python classes. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Jun 15 17:44:20 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 15 Jun 2006 11:44:20 -0400 Subject: [C++-sig] Boost::Signals References: Message-ID: John Reid writes: > Hi, > > I'm trying to call a python function from C++. I pass the function to > C++ as a boost::python::object. I can call functions with no arguments, > when I try to pass a C++ created object as an argument I get the > following error: > > Traceback (most recent call last): > File "python/test_python.py", line 8, in ? > d.connect_new_deal_slot_py_2( f ) > TypeError: No to_python (by-value) converter found for C++ type: class > module::classname Actually that would be namespacename::classname. It's a C++ class name, most probably of the return type of the C++ function implementing your connect_new_deal_slot_py_2 method. Another possibility is that it's the name of a C++ class of which you're passing an instance to f inside that C++ function implementing connect_new_deal_slot_py_2. Either way, you haven't wrapped that C++ class. > Now the boost.python section (http://tinyurl.com/n3cpv) in the python > wiki answers the following question: > "Is it is possible to convert pointers to existing classes to PyObjects* > and then be able to pass an existing instance of an object directly to > and from python?" > > where the last paragraph says: > > "If you really want to pass pointers around, it's certainly possible to > tell the library to build a Python object around the pointer, but then > you need to make sure the lifetime of the C++ object being referenced by > the pointer extends past the lifetime of all Python references to the > object or your program will crash." I don't see how that relates to the error message you're seeing above. > This is what I would like to do which? "tell the library to build a Python object around the pointer?" http://boost.org/libs/python/doc/v2/ptr.html#examples. Ensuring the appropriate lifetime relationships is a more complicated topic than I can explain here, though. > but cannot find this elsewhere in the > documentation. Can anyone let me know how to do this? > > Thanks in advance, > John. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Thu Jun 15 17:46:58 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 15 Jun 2006 16:46:58 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <7465b6170606142255h7e5ccabfha8a64ba9e8ee2120@mail.gmail.com> References: <44908CB0.961.968DBF@s_sourceforge.nedprod.com> Message-ID: <44918F02.20434.108ABEB@s_sourceforge.nedprod.com> On 15 Jun 2006 at 8:55, Roman Yakovenko wrote: > If you want to insert a code in some specific place, then : > > module.body.adopt_creator( code_creators.custom_text_t( ... ), position ) > ( By default the code creator will be appended to the end of the list ) No, this appends into TnFOX.main.cpp. I need it appended into FXApp.pypp.cpp. If you examine file_writers/multiple_files.py, you can see it writes license, precompiled header, global headers, global namespace aliases, wrapper classes and the register function for the class in question. Nowhere is it letting you write custom text outside the bodies of these items. I suppose you could add a custom form of wrapper code creator, but this seems inflexible - you should be able to insert text anywhere in any output file. Cheers, Niall From roman.yakovenko at gmail.com Thu Jun 15 20:08:07 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 15 Jun 2006 21:08:07 +0300 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <44918F02.20434.108ABEB@s_sourceforge.nedprod.com> References: <44908CB0.961.968DBF@s_sourceforge.nedprod.com> <7465b6170606142255h7e5ccabfha8a64ba9e8ee2120@mail.gmail.com> <44918F02.20434.108ABEB@s_sourceforge.nedprod.com> Message-ID: <7465b6170606151108w561f5883x33fbebd63add0149@mail.gmail.com> On 6/15/06, Niall Douglas wrote: > On 15 Jun 2006 at 8:55, Roman Yakovenko wrote: > > > If you want to insert a code in some specific place, then : > > > > module.body.adopt_creator( code_creators.custom_text_t( ... ), position ) > > ( By default the code creator will be appended to the end of the list ) > > No, this appends into TnFOX.main.cpp. I need it appended into > FXApp.pypp.cpp. If you examine file_writers/multiple_files.py, you > can see it writes license, precompiled header, global headers, global > namespace aliases, wrapper classes and the register function for the > class in question. Nowhere is it letting you write custom text > outside the bodies of these items. I suppose you could add a custom > form of wrapper code creator, but this seems inflexible - you should > be able to insert text anywhere in any output file. :-). This is one of my big problems - I don't know what interface to give to the user. It is not very difficult to implement what you are asking for. I am sure you have an idea, right ? As a temporal solution you can create custom file writer. Or may be to write small script that will add the code to the file. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Thu Jun 15 20:30:14 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 15 Jun 2006 21:30:14 +0300 Subject: [C++-sig] More pyplusplus custom stuff In-Reply-To: <44915545.5613.272220@s_sourceforge.nedprod.com> References: <44915545.5613.272220@s_sourceforge.nedprod.com> Message-ID: <7465b6170606151130l23eb0fan54fd7bf3fa5d8ba9@mail.gmail.com> On 6/15/06, Niall Douglas wrote: > The good news is I now have a set of fully working bindings, or at > least to the stage of where TnFOX was at the v0.85 release. Congratulation !!! >The next problem is the orphaned child problem. > > TnFOX's GUI objects, much like most C++ GUI toolkits, manage their > own children. If you delete the parent, it deletes all its children. > Needless to say, this is a problem for Python. > > The solution is to upcall any child deletions so BPL can unhook the > relevent python object from its C++ sibling. This is done by > replacing the virtual functions: > virtual void *getPythonObject() const; > virtual void decouplePythonObject() const; > > Therefore, we need to do the following: > > For every class in the FX namespace which has FXObject as a base > class, insert into EVERY constructor of the wrapper class the > following code: > > FXPython::int_pythonObjectCreated((int_decouplingFunctor=Generic::Bind > ObjN(*this, &"+wrapper_name+"::decouplePythonObject))); > > Into private member variables of the wrapper class: > > Generic::BoundFunctorV *int_decouplingFunctor; > > Into every destructor of the wrapper class: > > ~"+wrapper_name+"() { > FXPython::int_pythonObjectDeleted(int_decouplingFunctor); > using namespace boost::python; > using namespace std; > PyObject *py_self=get_owner(this); > // We must be careful not to reinvoke object destruction! > py_self->ob_refcnt=1<<16; > { > object me(boost::python::handle<>(borrowed(py_self))); > auto_ptr<"+wrapper_name+"> > &autoptr=extract &>(me); > autoptr.release(); > } > py_self->ob_refcnt=0 > } > > Into every body of the wrapper class: > > virtual void *getPythonObject() const { > return (void *) get_owner(this); > } > > virtual void decouplePythonObject() const { > using namespace boost::python; > using namespace std; > object me(boost::python::handle<>(borrowed(py_self))); > auto_ptr<"+wrapper_name+"> > &autoptr=extract &>(me); > autoptr.reset(0); > } > > > So, how does one achieve this then? Niall, there is pretty simple solution, but I am not sure I want it within pyplusplus. May be as temporal patch, but I will remove it after we will implement "call wrapper policies" ( http://language-binding.net/pyplusplus/peps/call_wrapper_policies.html ) Description: ( solution for destructor ) cls = mb.class_( 'X' ) cls.add_wrapper_code( destructor declaration and definition ) You can do it with your version of pyplusplus Description for constructor: 1. add pyplusplus.decl_wrappers.constructor_t new property body ( string ) 2. add code that insert this member variable into generated code in next classes: pyplusplus.code_creators. constructor_wrapper_t special_constructor_wrapper_t trivial_constructor_wrapper_t 3. initialize the body property > For every class in the FX namespace which has FXObject as a base > class, insert into EVERY constructor of the wrapper class the > following code: mb = module_builder_t( ... ) FX = mb.namespace( 'FX' ) FXObject = FX.class_( 'FXObject' ) classes = FX.classes( lambda decl: pygccxml.declarations.is_based_and_derived( FXObject, decl ) ) for cls in classes: cls.constructors().body = ... cls.add_wrapper_code( ... ) Pretty simple and readable, right :-)? Enjoy -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Fri Jun 16 00:14:04 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 15 Jun 2006 23:14:04 +0100 Subject: [C++-sig] More pyplusplus custom stuff In-Reply-To: Message-ID: <4491E9BC.32342.26B10C6@s_sourceforge.nedprod.com> On 15 Jun 2006 at 9:15, David Abrahams wrote: > > The solution is to upcall any child deletions so BPL can unhook the > > relevent python object from its C++ sibling. > > You could simplify that system a lot by using shared_ptr to hold the > children in C++, and building a new smart pointer around a core > weak_ptr, that you use as the HeldType in your Python classes. Can you elaborate? Doesn't shared_ptr basically hold a lock on a weak_ptr which is held on a main shared_ptr? I suppose this means I can avoid the refcount tricks I was using? Cheers, Niall From j.reid at mail.cryst.bbk.ac.uk Fri Jun 16 09:55:27 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 16 Jun 2006 08:55:27 +0100 Subject: [C++-sig] Boost::Signals In-Reply-To: References: Message-ID: David Abrahams wrote: > John Reid writes: > > >>Hi, >> >>I'm trying to call a python function from C++. I pass the function to >>C++ as a boost::python::object. I can call functions with no arguments, >>when I try to pass a C++ created object as an argument I get the >>following error: >> >>Traceback (most recent call last): >> File "python/test_python.py", line 8, in ? >> d.connect_new_deal_slot_py_2( f ) >>TypeError: No to_python (by-value) converter found for C++ type: class >>module::classname > > > Actually that would be namespacename::classname. It's a C++ class > name, most probably of the return type of the C++ function > implementing your connect_new_deal_slot_py_2 method. Another > possibility is that it's the name of a C++ class of which you're > passing an instance to f inside that C++ function implementing > connect_new_deal_slot_py_2. Either way, you haven't wrapped that C++ > class. > > I was pretty sure I had wrapped it. Was that not what I was doing with the following code? class_< test, noncopyable >( "test" ) .def( "connect_slot", &test::connect_slot_py ) ; Anyhow I tracked the problem down a little more and found out it did not like the noncopyable base class. Without this everything was OK. From the documentation it wasn't clear that this would make it difficult for me to pass C++ objects to python. I'm guessing there is a way to do this even with the noncopyable base class but I couldn't work it out. It is clear that I had some problems understanding what was going wrong. I'm not really sure if that was a problem with me, the error messages or the documentation. Thanks for your help. Best, John. From lee.will at gmail.com Fri Jun 16 16:29:58 2006 From: lee.will at gmail.com (Will Lee) Date: Fri, 16 Jun 2006 09:29:58 -0500 Subject: [C++-sig] Reducing size of binary Message-ID: <7f03db650606160729u4dc6bc7em4bf795d0b0cb1287@mail.gmail.com> Hi, I'm currently using Boost Python in a fairly large project using Linux and g++. The combined .so code that I tried to wrap is around 9MB (-O with no symbol). I got to a point where the python wrapper binary gets pretty big (sometimes the wrapper debug .so with symbols can get to 350 MB and the -O version without symobls would be around 18 MB). Compile time can get up to 15-20 minutes. As far as I see, I'm not doing anything too extraordinary. I am using a lot of add_property and def methods in the wrapper code. Does anyone have hints on reducing the size of the wrapper binary? Thanks, Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From lee.will at gmail.com Fri Jun 16 19:17:26 2006 From: lee.will at gmail.com (Will Lee) Date: Fri, 16 Jun 2006 12:17:26 -0500 Subject: [C++-sig] Bug with custom convertor and stl container? Message-ID: <7f03db650606161017k28035c1dw6ba2a57d2017cf4@mail.gmail.com> It seems like there's a bug when I use a custom converter (as described in the FAQ for the custom string) and a wrapped stl container. If I define a custom converter and use that type in a std::vector or std::map, I'll get an "TypeError: No Python class registered for C++" error for that converted type. For example, in the following case where I'm converting from type A to a python integer, std::vector and std::map are not working propertly. The testMap and testVec unit tests will both fail. This is somewhat a showstopper so it would be great if you have any idea on how to get around this. Thanks! ATest.cpp: #include #include #include #include #include struct A { int value; A() : value(0){}; A(int v) : value(v) {}; }; bool operator==(const A& v1, const A& v2) { return (v1.value == v2.value); } struct B { A a; }; // Converter from A to python int struct AToPython { static PyObject* convert(const A& s) { return boost::python::incref(boost::python::object((int)s.value).ptr()); } }; // Conversion from python int to A struct AFromPython { AFromPython() { boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id< A >()); } static void* convertible(PyObject* obj_ptr) { if (!PyInt_Check(obj_ptr)) return 0; return obj_ptr; } static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { void* storage = ( (boost::python::converter::rvalue_from_python_storage< A >*) data)->storage.bytes; new (storage) A((int)PyInt_AsLong(obj_ptr)); data->convertible = storage; } }; BOOST_PYTHON_MODULE(atest) { using namespace boost::python; to_python_converter< A , AToPython >(); AFromPython(); class_ >("AVec") .def(vector_indexing_suite, false>()) ; class_< std::map >("AMap") .def(map_indexing_suite, false >()) ; class_< B >("B") .add_property("a", make_getter(&B::a, return_value_policy()), make_setter(&B::a, return_value_policy())) ; } ATest.py: #!/usr/bin/env python import unittest import atest class ATest(unittest.TestCase): def testB(self): b = atest.B() self.assert_(b.a == 0) b.a = 35 self.assert_(b.a == 35) def testMap(self): amap = atest.AMap() amap[3] = 4 self.assert_(amap[3] == 4) def testVec(self): amap = atest.AVec() amap.append(4) self.assert_(amap[0] == 4) if __name__ == "__main__": unittest.main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_sourceforge at nedprod.com Fri Jun 16 19:37:46 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 16 Jun 2006 18:37:46 +0100 Subject: [C++-sig] Inserting custom code into pyplusplus output In-Reply-To: <7465b6170606151108w561f5883x33fbebd63add0149@mail.gmail.com> References: <44918F02.20434.108ABEB@s_sourceforge.nedprod.com> Message-ID: <4492FA7A.20748.26B63F7@s_sourceforge.nedprod.com> On 15 Jun 2006 at 21:08, Roman Yakovenko wrote: > > No, this appends into TnFOX.main.cpp. I need it appended into > > FXApp.pypp.cpp. If you examine file_writers/multiple_files.py, you > > can see it writes license, precompiled header, global headers, global > > namespace aliases, wrapper classes and the register function for the > > class in question. Nowhere is it letting you write custom text > > outside the bodies of these items. I suppose you could add a custom > > form of wrapper code creator, but this seems inflexible - you should > > be able to insert text anywhere in any output file. > > :-). This is one of my big problems - I don't know what interface to > give to the user. > It is not very difficult to implement what you are asking for. I am > sure you have an > idea, right ? I was thinking that you should replace the wrapper property in class_t with a more generic code_creators, of which one is the wrapper class (if needed). Call it 'classfilecreators' or something. Then to add things per class file, you simply adopt a custom text creator into it. You'd need to be careful when using the single file writer as some items may duplicate. Of course, this is probably an end user problem. > As a temporal solution you can create custom file writer. Or may be to write > small script that will add the code to the file. I'll wait for your solution and use diff and patch in the meantime. Cheers, Niall From roman.yakovenko at gmail.com Fri Jun 16 19:57:11 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 16 Jun 2006 20:57:11 +0300 Subject: [C++-sig] Reducing size of binary In-Reply-To: <7f03db650606160729u4dc6bc7em4bf795d0b0cb1287@mail.gmail.com> References: <7f03db650606160729u4dc6bc7em4bf795d0b0cb1287@mail.gmail.com> Message-ID: <7465b6170606161057i4bf0c10bjc52ae32e76b3d51c@mail.gmail.com> On 6/16/06, Will Lee wrote: > Hi, > > I'm currently using Boost Python in a fairly large project using Linux and > g++. The combined .so code that I tried to wrap is around 9MB (-O with no > symbol). I got to a point where the python wrapper binary gets pretty big > (sometimes the wrapper debug .so with symbols can get to 350 MB and the -O > version without symobls would be around 18 MB). Compile time can get up to > 15-20 minutes. As far as I see, I'm not doing anything too extraordinary. > I am using a lot of add_property and def methods in the wrapper code. > > Does anyone have hints on reducing the size of the wrapper binary? It could be useful to know your g++ version and compilation line. Meanwhile you can read this: http://www.nedprod.com/programs/gccvisibility.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Fri Jun 16 21:34:17 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 16 Jun 2006 20:34:17 +0100 Subject: [C++-sig] More pyplusplus custom stuff In-Reply-To: <7465b6170606151130l23eb0fan54fd7bf3fa5d8ba9@mail.gmail.com> References: <44915545.5613.272220@s_sourceforge.nedprod.com> Message-ID: <449315C9.9331.2D611F6@s_sourceforge.nedprod.com> On 15 Jun 2006 at 21:30, Roman Yakovenko wrote: > 1. add pyplusplus.decl_wrappers.constructor_t new property > body ( string ) > > 2. add code that insert this member variable into generated code in > next classes: > pyplusplus.code_creators. > constructor_wrapper_t > special_constructor_wrapper_t > trivial_constructor_wrapper_t Firstly, I attach modified pyplusplus source implementing your suggestion. For special_constructor_wrapper_t and trivial_constructor_wrapper_t, self.declaration refers to a decl_wrapper.class_t rather than decl_wrapper.constructor_t. AFAICS trivial constructors are really compiler generated null constructors while special constructors are really copy constructors. Therefore, you'd probably want to be able to set each individually so I split them into a series of properties. I have a new function which sets all constructor bodies. Cheers, Niall -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: calldef.py Date: 16 Jun 2006, 15:03 Size: 48750 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: calldef.py Type: application/octet-stream Size: 48749 bytes Desc: not available URL: -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: class_wrapper.py Date: 16 Jun 2006, 15:02 Size: 5402 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: class_wrapper.py Type: application/octet-stream Size: 5401 bytes Desc: not available URL: -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: calldef_wrapper.py Date: 16 Jun 2006, 14:27 Size: 13426 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: calldef_wrapper.py Type: application/octet-stream Size: 13426 bytes Desc: not available URL: From s_sourceforge at nedprod.com Fri Jun 16 21:34:18 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 16 Jun 2006 20:34:18 +0100 Subject: [C++-sig] Reducing size of binary In-Reply-To: <7f03db650606160729u4dc6bc7em4bf795d0b0cb1287@mail.gmail.com> Message-ID: <449315CA.12403.2D6163C@s_sourceforge.nedprod.com> On 16 Jun 2006 at 9:29, Will Lee wrote: > I'm currently using Boost Python in a fairly large project using Linux and > g++. The combined .so code that I tried to wrap is around 9MB (-O with no > symbol). I got to a point where the python wrapper binary gets pretty big > (sometimes the wrapper debug .so with symbols can get to 350 MB and the -O > version without symobls would be around 18 MB). Compile time can get up to > 15-20 minutes. As far as I see, I'm not doing anything too extraordinary. > I am using a lot of add_property and def methods in the wrapper code. > > Does anyone have hints on reducing the size of the wrapper binary? That's nothing. I'm regularly generating 25Mb release build bindings on Linux. They take several hours to compile. If you're using gcc 4.x, use -fvisibility=hidden. Also optimise for smallest possible size at expense of speed. Use 3.4 or later rather than 3.3 or earlier. Ultimately though, ELF is a fat binary format and how GCC stores typeinfo is space expensive. Mach-O on Apple and PE on Windows are far far smaller for the same source. Cheers, Niall From rwgk at yahoo.com Sat Jun 17 01:48:18 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 16 Jun 2006 16:48:18 -0700 (PDT) Subject: [C++-sig] Bug with custom convertor and stl container? In-Reply-To: <7f03db650606161017k28035c1dw6ba2a57d2017cf4@mail.gmail.com> Message-ID: <20060616234818.62358.qmail@web31501.mail.mud.yahoo.com> --- Will Lee wrote: > It seems like there's a bug when I use a custom converter (as described in > the FAQ for the custom string) and a wrapped stl container. If I define a > custom converter and use that type in a std::vector or std::map, I'll get an > "TypeError: No Python class registered for C++" error for that converted > type. > > For example, in the following case where I'm converting from type A to a > python integer, std::vector and std::map are not working > propertly. The testMap and testVec unit tests will both fail. This is > somewhat a showstopper so it would be great if you have any idea on how to > get around this. You probably have to tell the vector_indexing_suite and the map_indexing_suite to also return the result of getitem by value. I don't know how to do this but I believe it is possible. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From s_sourceforge at nedprod.com Sun Jun 18 05:14:40 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 18 Jun 2006 04:14:40 +0100 Subject: [C++-sig] Another bug in pyplusplus Message-ID: <4494D330.5974.34333B4@s_sourceforge.nedprod.com> If you disable use of keywords using mb.calldefs().use_keywords=False, pyplusplus also stops inserting default argument values into its wrappers eg; int FXDialogBox::execute(int placement=DEFAULT) ... should become virtual ::FX::FXuint execute( ::FX::FXuint placement = FX::DEFAULT ) { if( bp::override func_execute = this->get_override( "execute" ) ) return func_execute( placement ); else return FX::FXDialogBox::execute( placement ); } Unfortunately, it's missing the default argument. To fix this, replace calldef_wrapper_t.args_declaration() with: def args_declaration( self ): args = [] boost_obj = algorithm.create_identifier( self, '::boost::python::object' ) for index, arg in enumerate( self.declaration.arguments ): result = arg.type.decl_string + ' ' + self.argument_name(index) if arg.default_value: if not declarations.is_pointer( arg.type ) or arg.default_value != '0': result += '=%s' % arg.default_value else: result += '=%s()' % boost_obj args.append( result ) if len( args ) == 1: return args[ 0 ] return ', '.join( args ) Another point - I believe the default_X function doesn't need to be virtual. By making it so, you're introducing an unnecessary inefficiency: virtual ::FX::FXuint default_execute( ::FX::FXuint placement ) { return FX::FXDialogBox::execute( placement ); } Cheers, Niall From roman.yakovenko at gmail.com Sun Jun 18 07:44:59 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 18 Jun 2006 08:44:59 +0300 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <4494D330.5974.34333B4@s_sourceforge.nedprod.com> References: <4494D330.5974.34333B4@s_sourceforge.nedprod.com> Message-ID: <7465b6170606172244o80943d4kfd7d6259ca163b1b@mail.gmail.com> On 6/18/06, Niall Douglas wrote: > If you disable use of keywords using > mb.calldefs().use_keywords=False, pyplusplus also stops inserting > default argument values into its wrappers eg; May I correct you? All wrappers have been generated without default arguments, right :-)? It has nothing to do with use_keywords > def args_declaration( self ): > args = [] > boost_obj = algorithm.create_identifier( self, > '::boost::python::object' ) > for index, arg in enumerate( self.declaration.arguments ): > result = arg.type.decl_string + ' ' + > self.argument_name(index) > if arg.default_value: > if not declarations.is_pointer( arg.type ) or > arg.default_value != '0': > result += '=%s' % arg.default_value > else: > result += '=%s()' % boost_obj I could be wrong, but it seems to me that we don't need " if not declarations.is_pointer( arg.type ) or arg.default_value != '0': " condition, just plain "result += '=%s' % arg.default_value" will do the job, right? Am I missing something? > Another point - I believe the default_X function doesn't need to be > virtual. By making it so, you're introducing an unnecessary > inefficiency: Fixed. Thank you! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun Jun 18 08:42:21 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 18 Jun 2006 09:42:21 +0300 Subject: [C++-sig] More pyplusplus custom stuff In-Reply-To: <449315C9.9331.2D611F6@s_sourceforge.nedprod.com> References: <44915545.5613.272220@s_sourceforge.nedprod.com> <7465b6170606151130l23eb0fan54fd7bf3fa5d8ba9@mail.gmail.com> <449315C9.9331.2D611F6@s_sourceforge.nedprod.com> Message-ID: <7465b6170606172342x1d5f32c8g528f46bbcdc43453@mail.gmail.com> On 6/16/06, Niall Douglas wrote: Niall, thank you for patches! I committed them. > For special_constructor_wrapper_t and trivial_constructor_wrapper_t, > self.declaration refers to a decl_wrapper.class_t rather than > decl_wrapper.constructor_t. AFAICS trivial constructors are really > compiler generated null constructors while special constructors are > really copy constructors. I switched to your terminology. > Therefore, you'd probably want to be able > to set each individually so I split them into a series of properties. > I have a new function which sets all constructor bodies. Now class_t have null_constructor_body and copy_constructor_body. If you use set_constructors_body method you should be fine. If you are going to check out latest source code - be careful. Latest version has new feature - indexing suite. http://language-binding.net/pyplusplus/peps/indexing_suite.html - this has been implemented. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Sun Jun 18 14:48:00 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 18 Jun 2006 13:48:00 +0100 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <7465b6170606172244o80943d4kfd7d6259ca163b1b@mail.gmail.com> References: <4494D330.5974.34333B4@s_sourceforge.nedprod.com> Message-ID: <44955990.15451.D1398@s_sourceforge.nedprod.com> On 18 Jun 2006 at 8:44, Roman Yakovenko wrote: > On 6/18/06, Niall Douglas wrote: > > If you disable use of keywords using > > mb.calldefs().use_keywords=False, pyplusplus also stops inserting > > default argument values into its wrappers eg; > > May I correct you? All wrappers have been generated without default > arguments, right :-)? > It has nothing to do with use_keywords It's quite possible. However, I know when use_keywords is true, it puts arg("x")=5 and such into declarations. > > def args_declaration( self ): > > args = [] > > boost_obj = algorithm.create_identifier( self, > > '::boost::python::object' ) > > for index, arg in enumerate( self.declaration.arguments ): > > result = arg.type.decl_string + ' ' + > > self.argument_name(index) > > if arg.default_value: > > if not declarations.is_pointer( arg.type ) or > > arg.default_value != '0': > > result += '=%s' % arg.default_value > > else: > > result += '=%s()' % boost_obj > > I could be wrong, but it seems to me that we don't need > " if not declarations.is_pointer( arg.type ) or arg.default_value != '0': " > condition, just plain > "result += '=%s' % arg.default_value" > will do the job, right? Am I missing something? No you're absolutely right. I wrote that email at something like 3am last night and I hadn't quite tested it properly. What you wrote is correct. > > Another point - I believe the default_X function doesn't need to be > > virtual. By making it so, you're introducing an unnecessary > > inefficiency: > > Fixed. > > Thank you! No problem. I have the imageviewer.py example very nearly working. Once it is working, I would consider the python bindings finished apart from three items: 1. Named parameters do not work which is annoying because BPL throws an exception if its type is as yet unregistered. This problem can't be fixed by pyplusplus - it requires fixing BPL. 2. FXWinShellLink causes pyplusplus to generate bad code. This is because it uses unions. 3. FXImage subclasses don't provide a working getData(). This requires custom body text insertion to be added to pyplusplus. Otherwise, they're finished! Thanks for all the help! Cheers, Niall From roman.yakovenko at gmail.com Sun Jun 18 15:46:41 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 18 Jun 2006 16:46:41 +0300 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <44955990.15451.D1398@s_sourceforge.nedprod.com> References: <4494D330.5974.34333B4@s_sourceforge.nedprod.com> <7465b6170606172244o80943d4kfd7d6259ca163b1b@mail.gmail.com> <44955990.15451.D1398@s_sourceforge.nedprod.com> Message-ID: <7465b6170606180646x6db4b173w635d09287a839407@mail.gmail.com> On 6/18/06, Niall Douglas wrote: > No problem. I have the imageviewer.py example very nearly working. > Once it is working, I would consider the python bindings finished > apart from three items: > > 1. Named parameters do not work which is annoying because BPL throws > an exception if its type is as yet unregistered. This problem can't > be fixed by pyplusplus - it requires fixing BPL. class_t has property - always_expose_using_scope. If you set it to true, then it can help you in next case: struct A{ void do_smth( const A& a=A() ){...} }; Generated code will not throw exception, while registering the function. > 2. FXWinShellLink causes pyplusplus to generate bad code. This is > because it uses unions. Not just unions, but unnamed ones :-) I work on a project that has same problem, you have good chance that I will add missing functionality. > 3. FXImage subclasses don't provide a working getData(). This > requires custom body text insertion to be added to pyplusplus. Can you send short example what pyplusplus generates now and the code you need to be generated, may be I will find a solution. > Otherwise, they're finished! Thanks for all the help! My pleasure :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Sun Jun 18 16:38:23 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 18 Jun 2006 15:38:23 +0100 Subject: [C++-sig] Default arguments in pyplusplus Message-ID: <4495736F.11535.722233@s_sourceforge.nedprod.com> Hmm, pyplusplus doesn't tell BPL about default arguments at all! Surely it should output BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS() for each overloaded function? Needless to say, the TnFOX python bindings won't work without default arguments working :( I did try adding this on my own, but it's complex. I'm afraid the class hierarchy in pyplusplus is fairly complex, complex enough that without a debugger it's hard to modify. So I'll have to leave it to you Roman! Cheers, Niall From s_sourceforge at nedprod.com Sun Jun 18 16:47:28 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 18 Jun 2006 15:47:28 +0100 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <7465b6170606180646x6db4b173w635d09287a839407@mail.gmail.com> References: <44955990.15451.D1398@s_sourceforge.nedprod.com> Message-ID: <44957590.13157.7A707B@s_sourceforge.nedprod.com> On 18 Jun 2006 at 16:46, Roman Yakovenko wrote: > On 6/18/06, Niall Douglas wrote: > > No problem. I have the imageviewer.py example very nearly working. > > Once it is working, I would consider the python bindings finished > > apart from three items: > > > > 1. Named parameters do not work which is annoying because BPL throws > > an exception if its type is as yet unregistered. This problem can't > > be fixed by pyplusplus - it requires fixing BPL. > > class_t has property - always_expose_using_scope. If you set it to true, then > it can help you in next case: > > struct A{ > void do_smth( const A& a=A() ){...} > }; > > Generated code will not throw exception, while registering the function. I already have this set to true. I more meant: void foo(int a=1, int b=2, int c=3) ... and then from python do: foo(c=8) You need to declare parameter names to do this, but BPL faults when the type is (say) an enum defined in the class it's about to declare. > > 3. FXImage subclasses don't provide a working getData(). This > > requires custom body text insertion to be added to pyplusplus. > > Can you send short example what pyplusplus generates now and the code you need > to be generated, may be I will find a solution. All I need is the ability to insert custom code into the body of class files. Put simply, I need to insert DEFINEMAKECARRAYITER at the top of every FXImage.pypp.cpp, FXBMPImage.pypp.cpp, FXJPGImage.pypp.cpp etc. It needs to go before or after the wrapper class. Declared inside the body. If you add an overloads section (see previous email) containing all the BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS declarations (which MUST come after the wrapper class but before the register function), then I could add them there as a custom text code creator. Cheers, Niall From roman.yakovenko at gmail.com Sun Jun 18 19:41:08 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 18 Jun 2006 20:41:08 +0300 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <4495736F.11535.722233@s_sourceforge.nedprod.com> References: <4495736F.11535.722233@s_sourceforge.nedprod.com> Message-ID: <7465b6170606181041n41fd837et4c01db41d978c323@mail.gmail.com> On 6/18/06, Niall Douglas wrote: > Hmm, pyplusplus doesn't tell BPL about default arguments at all! Niall, I just added the tests that check your statement. I can not reproduce the behaviour you are talking about. namespace default_args{ struct data{ int sum( int i=0 ){ return i; } int sum( int i, int j, int k=3 ){ return i + j + k; } }; } pyplusplus will generate next code: namespace bp = boost::python; BOOST_PYTHON_MODULE(default_args){ bp::class_< default_args::data >( "data" ) .def("sum" , (int ( ::default_args::data::* )( int ) )( &::default_args::data::sum ) , ( bp::arg("i")=0 ) , bp::default_call_policies() ) .def("sum" , (int ( ::default_args::data::* )( int,int,int ) )( &::default_args::data::sum ) , ( bp::arg("i"), bp::arg("j"), bp::arg("k")=3 ) , bp::default_call_policies() ); } My test is next: d = module.data() self.failUnless( d.sum() == 0 ) self.failUnless( d.sum( 1, 2 ) == 6 ) I would like to see your use case > Surely it should output BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS() for > each overloaded function? BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS has limit: it can not be used for functions that takes different type of arguments: double sum( int ); double sum( double, double ); You can't not expose them using the macro. > Needless to say, the TnFOX python bindings won't work without default > arguments working :( I agree with you, may be you have some where in the code use_keywords = False? > I did try adding this on my own, but it's complex. I'm afraid the > class hierarchy in pyplusplus is fairly complex, complex enough that > without a debugger it's hard to modify. So I'll have to leave it to > you Roman! Please provide test case and I will try to fix ASAP. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun Jun 18 19:57:43 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 18 Jun 2006 20:57:43 +0300 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <44957590.13157.7A707B@s_sourceforge.nedprod.com> References: <44955990.15451.D1398@s_sourceforge.nedprod.com> <7465b6170606180646x6db4b173w635d09287a839407@mail.gmail.com> <44957590.13157.7A707B@s_sourceforge.nedprod.com> Message-ID: <7465b6170606181057p5abea875h5a6aa17cf0a323be@mail.gmail.com> On 6/18/06, Niall Douglas wrote: > > > 3. FXImage subclasses don't provide a working getData(). This > > > requires custom body text insertion to be added to pyplusplus. > > > > Can you send short example what pyplusplus generates now and the code you need > > to be generated, may be I will find a solution. > > All I need is the ability to insert custom code into the body of > class files. Put simply, I need to insert DEFINEMAKECARRAYITER at the > top of every FXImage.pypp.cpp, FXBMPImage.pypp.cpp, > FXJPGImage.pypp.cpp etc. > > It needs to go before or after the wrapper class. Declared inside the > body. > > If you add an overloads section (see previous email) containing all > the BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS declarations (which MUST > come after the wrapper class but before the register function), then > I could add them there as a custom text code creator. There is a solution. You can generate all code that uses DEFINEMAKECARRAYITER in some header file and then to include it. mb = module_builder_t( ... ) for cls in mb.classes( lambda decl: decl.name.endswith( 'Image' ) ): generate code to some header file mb.build_code_creator( ... ) mb.code_creator.add_include( that header file ) I have another solution, but I don't have time to implement it or even check: pyplusplus can divide every generated cpp file to sections: 1. include 2. space 3. wrapper 4. space 5. class Then, pyplusplus can define next class: class on_cpp_file_write_i: def on_include( self, declaration ): ... def on_first_space def on_wrapper def on_second space def on_class Every function return some text or None. In case method returns None pyplusplus will write the code it have to write. In case method returns some text, this text will be written instead. Thoughts? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Mon Jun 19 02:34:39 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 19 Jun 2006 01:34:39 +0100 Subject: [C++-sig] Another bug in pyplusplus In-Reply-To: <7465b6170606181057p5abea875h5a6aa17cf0a323be@mail.gmail.com> References: <44957590.13157.7A707B@s_sourceforge.nedprod.com> Message-ID: <4495FF2F.6696.103EB1@s_sourceforge.nedprod.com> On 18 Jun 2006 at 20:57, Roman Yakovenko wrote: > There is a solution. You can generate all code that uses DEFINEMAKECARRAYITER > in some header file and then to include it. I was even thinking of just generating the header file from within the python script. > I have another solution, but I don't have time to implement it or even check: > pyplusplus can divide every generated cpp file to sections: > > 1. include > 2. space > 3. wrapper > 4. space > 5. class > > Then, pyplusplus can define next class: > > class on_cpp_file_write_i: > def on_include( self, declaration ): > ... > def on_first_space > def on_wrapper > def on_second space > def on_class > > Every function return some text or None. In case method returns None > pyplusplus will write the code it have to write. In case method returns some > text, this text will be written instead. > > Thoughts? Looks reasonable. Cheers, Niall From s_sourceforge at nedprod.com Mon Jun 19 02:34:38 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 19 Jun 2006 01:34:38 +0100 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <7465b6170606181041n41fd837et4c01db41d978c323@mail.gmail.com> References: <4495736F.11535.722233@s_sourceforge.nedprod.com> Message-ID: <4495FF2E.10980.103E62@s_sourceforge.nedprod.com> On 18 Jun 2006 at 20:41, Roman Yakovenko wrote: > > Needless to say, the TnFOX python bindings won't work without default > > arguments working :( > > I agree with you, may be you have some where in the code use_keywords = False? That's precisely the case. I am talking about default parameters not working when use_keywords is False. Sorry, I thought I mentioned that earlier in a previous bug report. I think surely you will need to use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS() for when keywords are not enabled? > > I did try adding this on my own, but it's complex. I'm afraid the > > class hierarchy in pyplusplus is fairly complex, complex enough that > > without a debugger it's hard to modify. So I'll have to leave it to > > you Roman! > > Please provide test case and I will try to fix ASAP. I think that I have use_keywords as False is enough? Try your unit test with use_keywords as False, if that still works I will modify one of your unit tests to show the behaviour. Cheers, Niall From roman.yakovenko at gmail.com Mon Jun 19 07:17:48 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 19 Jun 2006 08:17:48 +0300 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <4495FF2E.10980.103E62@s_sourceforge.nedprod.com> References: <4495736F.11535.722233@s_sourceforge.nedprod.com> <7465b6170606181041n41fd837et4c01db41d978c323@mail.gmail.com> <4495FF2E.10980.103E62@s_sourceforge.nedprod.com> Message-ID: <7465b6170606182217l2827f921g90ddba239a5e3b8e@mail.gmail.com> On 6/19/06, Niall Douglas wrote: > On 18 Jun 2006 at 20:41, Roman Yakovenko wrote: > > > > Needless to say, the TnFOX python bindings won't work without default > > > arguments working :( > > > > I agree with you, may be you have some where in the code use_keywords = False? > > That's precisely the case. I am talking about default parameters not > working when use_keywords is False. Sorry, I thought I mentioned that > earlier in a previous bug report. > > I think surely you will need to use > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS() for when keywords are not > enabled? As I already said: this macro has limitations. It can not be used in general case. > > > I did try adding this on my own, but it's complex. I'm afraid the > > > class hierarchy in pyplusplus is fairly complex, complex enough that > > > without a debugger it's hard to modify. So I'll have to leave it to > > > you Roman! > > > > Please provide test case and I will try to fix ASAP. > > I think that I have use_keywords as False is enough? Yes this is enough. > Try your unit > test with use_keywords as False, if that still works I will modify > one of your unit tests to show the behaviour. Why don't you resolve the issue with enums. I see few ways to go: To find places where enum used as default arguments and enum still not exported >From here you have 2 solutions: to remove default arguments or to change default arguments to have integer type with value of enum. This should work. Another solution is to move enum to from class to FX namespace. In this case it will be exported earlier. There is third approach: Every function has "overloads" property. You can find all member functions, that are overloaded. Then you can exclude them. After this, generate code that uses the macro in one file ( may be it is a time to implement interface that will allow to edit generated cpp file ). And finally you can add the code to the class using add_code. What do you think? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Jun 19 07:53:04 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 19 Jun 2006 08:53:04 +0300 Subject: [C++-sig] Ogre bindings - good news Message-ID: <7465b6170606182253h64d73148od61cffb0e9272f72@mail.gmail.com> Hi. I just want to share good news. Lakin Wecker recently worked on creating Python bindings for Ogre ( Object-Oriented Graphics Rendering Engine http://www.ogre3d.org/ ) using pyplusplus and boost.python. Ogre project already has Python bindings using SWIG, but maintenance process was and still is a nightmare and very time consuming. But now when he started to use pyplusplus it is a different story. For full story please read: http://lakin.weckers.net/index_ogre_python.html http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1478 -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From lee.will at gmail.com Mon Jun 19 17:33:53 2006 From: lee.will at gmail.com (Will Lee) Date: Mon, 19 Jun 2006 10:33:53 -0500 Subject: [C++-sig] Bug with custom convertor and stl container? In-Reply-To: <20060616234818.62358.qmail@web31501.mail.mud.yahoo.com> References: <7f03db650606161017k28035c1dw6ba2a57d2017cf4@mail.gmail.com> <20060616234818.62358.qmail@web31501.mail.mud.yahoo.com> Message-ID: <7f03db650606190833l578ba5e5h77a1aacc73710453@mail.gmail.com> I have resolved this problem when I set the template NoProxy to true. However, another problem comes up when I try to use the map in python: If I do the following in my unit test: def testMap(self): amap = atest.AMap() amap[3] = 4 self.assert_(amap[3] == 4) # This should not fail? for i in amap: self.assert_(i.data() == 4) I'd get a error that looks like: ====================================================================== ERROR: testMap (__main__.ATest) ---------------------------------------------------------------------- Traceback (most recent call last): File "ATest.py", line 20, in testMap self.assert_(i.data() == 4) TypeError: No Python class registered for C++ class A ---------------------------------------------------------------------- Ran 3 tests in 0.005s FAILED (errors=1) Note the first assert would pass after I set NoProxy to false, but the data() call would get me the same error. The type of "i" is . Is there a bug in the generated entry object if I use a custom converter? Will On 6/16/06, Ralf W. Grosse-Kunstleve wrote: > > --- Will Lee wrote: > > > It seems like there's a bug when I use a custom converter (as described > in > > the FAQ for the custom string) and a wrapped stl container. If I define > a > > custom converter and use that type in a std::vector or std::map, I'll > get an > > "TypeError: No Python class registered for C++" error for that converted > > type. > > > > For example, in the following case where I'm converting from type A to a > > python integer, std::vector and std::map are not working > > propertly. The testMap and testVec unit tests will both fail. This is > > somewhat a showstopper so it would be great if you have any idea on how > to > > get around this. > > You probably have to tell the vector_indexing_suite and the > map_indexing_suite > to also return the result of getitem by value. I don't know how to do this > but > I believe it is possible. > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyril.bazin at info.unicaen.fr Mon Jun 19 17:35:39 2006 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Mon, 19 Jun 2006 17:35:39 +0200 Subject: [C++-sig] ArgumentError... Message-ID: Hello, I am trying to use boost.python in order to bind a library called CGAL (and also to test if it's diffcult to bind such a library ;-). http://www.cgal.org/ This library provide a class CGAL::Delaunay_Triangulation_2 which represent a Delaunay triangulation in two dimensions. I want to build a delaunay triangultion using the "push_back" method (which add a Point to the mesh). Then, I want to iter over the vertexes, the faces and the edges of the mesh using a Python iterator which use the following methods : - Finite_vertices_iterator t.finite_vertices_begin () - Finite_vertices_iterator t.finite_vertices_end () I added the following line in my C++ boost code : class_("Delaunay") //... .def("finite_vertices", range(&Delaunay::finite_vertices_begin, &Delaunay::finite_vertices_end)) And the following code in my unit tests : class TestSequenceFunctions(unittest.TestCase): def init_delaunay(self): d = pygale.Delaunay() for x, y in self.seq: d.push_back(pygale.Point(x, y)) return d def test_delaunay_2(self): d = self.init_delaunay() it = d.finite_vertices() But when I call the method "finite_vertices", I get the following error : Traceback (most recent call last): File "testPygale.py", line 40, in test_delaunay_2 it = d.finite_vertices() ArgumentError: Python argument types in Delaunay.finite_vertices(Delaunay) did not match C++ signature: finite_vertices(boost::python::back_reference, CGAL::Tds2, CGAL::Tdsvb >, CGAL::Tdsfb > >&>) If you can help me to solve this error, please... Thanks in advance. Cyril BAZIN Annexes: The classes to bind The C++ code for boost The python unittests The execution trace --------------------------------------------------------- The classes to bind --------------------------------------------- #include #include #include #include #include #include #include #include #include typedef CGAL::Cartesian Gt; typedef Gt::FT F_T; typedef Gt::RT R_T; typedef Gt::Point_2 Point; typedef Gt::Segment_2 Segment; typedef Gt::Line_2 Line; typedef Gt::Triangle_2 Triangle; ///typedef Gt::Bbox_2 Bbox; typedef CGAL::Delaunay_triangulation_2 Delaunay; typedef Delaunay::Finite_vertices_iterator Finite_vertices_iterator; typedef Delaunay::Vertex_handle Vertex_handle; typedef Delaunay::Vertex Vertex; ----------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------- C++ code for boost -------------------------------------------- #include #include "pygale2.cpp" using namespace boost::python; BOOST_PYTHON_MODULE(pygale2) { //...... class_("Vertex") ; class_("Vertex_handle") ; class_("Finite_vertices_iterator") ; class_("Delaunay") .def(init<>()) .def("number_of_vertices", &Delaunay::number_of_vertices ) .def("number_of_faces", &Delaunay::number_of_faces ) .def("push_back", &Delaunay::push_back ) .def("finite_vertices", range(&Delaunay::finite_vertices_begin, &Delaunay::finite_vertices_end)) ; //..... } ------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------The python unit tests ---------------------------------------------------- import pygale2 as pygale import unittest class TestSequenceFunctions(unittest.TestCase): def setUp(self): self.seq = [(5, 8), (9, 6), (5, 2), (12, 9), (0, 0), (2, 7)] #... def init_delaunay(self): d = pygale.Delaunay() for x, y in self.seq: d.push_back(pygale.Point(x, y)) return d def test_delaunay(self): d = self.init_delaunay() self.assertEqual(d.number_of_vertices(), len(self.seq)) def test_delaunay_2(self): d = self.init_delaunay() it = d.finite_vertices() if __name__ == '__main__': suite = unittest.makeSuite(TestSequenceFunctions) unittest.TextTestRunner(verbosity=2).run(suite) #unittest.main() ----------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------- The execution trace -------------------------------------------------------------- $make all test g++ -I/export/home/cbazin/python/Python-2.4/ -I/usr/include/python2.4 -I/usr/local/include/boost-1_33_1/boost/ -I/usr/local/include pygale2.boost.cpp -c -o pygale2.o g++ pygale2.o -L/usr/local/lib/ -lboost_python -L/usr/lib/CGAL/ -lCGAL -o pygale2.so --shared python testPygale.py test_delaunay (__main__.TestSequenceFunctions) ... ok test_delaunay_2 (__main__.TestSequenceFunctions) ... ERROR test_points (__main__.TestSequenceFunctions) ... ok test_segments (__main__.TestSequenceFunctions) ... ok ====================================================================== ERROR: test_delaunay_2 (__main__.TestSequenceFunctions) ---------------------------------------------------------------------- Traceback (most recent call last): File "testPygale.py", line 40, in test_delaunay_2 it = d.finite_vertices() ArgumentError: Python argument types in Delaunay.finite_vertices(Delaunay) did not match C++ signature: finite_vertices(boost::python::back_reference, CGAL::Tds2, CGAL::Tdsvb >, CGAL::Tdsfb > >&>) ---------------------------------------------------------------------- Ran 4 tests in 0.003s FAILED (errors=1) ---------------------------------------------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Mon Jun 19 23:35:55 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 19 Jun 2006 17:35:55 -0400 Subject: [C++-sig] ArgumentError... References: Message-ID: "Cyril Bazin" writes: > But when I call the method "finite_vertices", I get the following error : > > Traceback (most recent call last): > File "testPygale.py", line 40, in test_delaunay_2 > it = d.finite_vertices() > ArgumentError: Python argument types in > Delaunay.finite_vertices(Delaunay) > did not match C++ signature: > > finite_vertices(boost::python::back_reference, > CGAL::Tds2, CGAL::Tdsvb >, > CGAL::Tdsfb > >&>) > > > If you can help me to solve this error, please... My best guess is that Delaunay is derived from CGAL::Triangulation_2< CGAL::Cartesian , CGAL::Tds2< CGAL::Tvb, CGAL::Tdsvb > , CGAL::Tdsfb > > which supplies finite_vertices_begin and finite_vertices_end. Since you haven't wrapped that, and Boost.Python doesn't know it's a base class of Delaunay, you get the error. You have two choices: 1. pre-assign finite_vertices_end/begin to variables (or cast to temporaries) of type Finite_vertices_iterator (Delaunay::*)() and pass those to range(...) 2. Use the first form of range(...) described here: http://boost.org/libs/python/doc/v2/iterator.html#range-spec HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From joel at boost-consulting.com Tue Jun 20 02:33:31 2006 From: joel at boost-consulting.com (Joel de Guzman) Date: Tue, 20 Jun 2006 08:33:31 +0800 Subject: [C++-sig] Bug with custom convertor and stl container? In-Reply-To: <7f03db650606190833l578ba5e5h77a1aacc73710453@mail.gmail.com> References: <7f03db650606161017k28035c1dw6ba2a57d2017cf4@mail.gmail.com> <20060616234818.62358.qmail@web31501.mail.mud.yahoo.com> <7f03db650606190833l578ba5e5h77a1aacc73710453@mail.gmail.com> Message-ID: <4497425B.2030802@boost-consulting.com> Will Lee wrote: > I have resolved this problem when I set the template NoProxy to true. > However, another problem comes up when I try to use the map in python: That's been fixed sometime ago. To be sure, I added some tests to map_indexing_suite.cpp/py in the test directory. Please check out the CVS. Cheers! -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From s_sourceforge at nedprod.com Tue Jun 20 04:22:30 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 20 Jun 2006 03:22:30 +0100 Subject: [C++-sig] Default arguments in pyplusplus Message-ID: On 19 Jun 2006 at 8:17, Roman Yakovenko wrote: > Why don't you resolve the issue with enums. I see few ways to go: > > To find places where enum used as default arguments and enum still not exported > >From here you have 2 solutions: to remove default arguments or to change default > arguments to have integer type with value of enum. This should work. I tried this one using the following: # Patch default args with enums to be number (to avoid undeclared enum problem) allfuncs = mb.calldefs() for func in allfuncs: print type(func), type(func.parent), func for arg in func.arguments: # Is it an argument with a default value? if arg.default_value: # Is it an enumeration? if isinstance( arg.type, declarations.cpptypes.declarated_t ) and isinstance( arg.type.declaration, declarations.enumeration.enumeration_t ): # Is it an embedded enum rather than global? scopecount = arg.default_value.count('::') - arg.default_value.startswith('::') if scopecount>1: # Be lazy, and just lookup the last part value = arg.default_value[ arg.default_value.rfind('::')+2: ] arg.default_value = arg.type.declaration.values[ value ] + '/*' + arg.default_value + '*/' And this works fine. EXCEPT that class wrappers also take the int converted default parameter, which leads unfortunately to code like this: QBlkSocket_wrapper(::FX::QBlkSocket::Type type=0/*::FX::QBlkSocket::Stream*/, ::FX::FXushort port=0 ) : FX::QBlkSocket( type, port ) , bp::wrapper< FX::QBlkSocket >() { // Normal constructor } Of course, this won't compile. Any ideas? Thanks for the enum idea. If I can get keyword parameters working I'd be very happy. Cheers, Niall From roman.yakovenko at gmail.com Tue Jun 20 07:49:42 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 20 Jun 2006 08:49:42 +0300 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <200606200226.k5K2QjwT025305@smtp-vbr6.xs4all.nl> References: <200606200226.k5K2QjwT025305@smtp-vbr6.xs4all.nl> Message-ID: <7465b6170606192249uf696ff3u4ecd0beeca76a946@mail.gmail.com> On 6/20/06, Niall Douglas wrote: # Is it an enumeration? if isinstance( arg.type, declarations.cpptypes.declarated_t ) \ and isinstance( arg.type.declaration, declarations.enumeration.enumeration_t ): You are working too hard here. pygccxml has functionality similar to boost.type_traits Read more here: http://language-binding.net/pygccxml/design.html#type-traits pygccxml.declarations.is_enum( arg.type ) will do the job > Of course, this won't compile. Any ideas? Obviously we need to supply different default arguments for wrapper and for code that actually exposes the function. The idea is simple we need new class variable on argument_t class default_value_xxx ( I explain later why xxx, but you will have to rename it to something readable ). And then to generate code that in wrapper uses original value, but in boost.python code uses modified one, right? I attached the solution to your problem. I made small refactoring + added new functionality ( enum_declaration ) so you will need the latest version. > Thanks for the enum idea. If I can get keyword parameters working I'd > be very happy. Hope I made you very, very happy :-). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: default_value.py Type: application/x-python Size: 1396 bytes Desc: not available URL: From roman.yakovenko at gmail.com Tue Jun 20 13:56:20 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 20 Jun 2006 14:56:20 +0300 Subject: [C++-sig] [ vector | list ] indexing suite Message-ID: <7465b6170606200456w53eb66ecrad80540888e176@mail.gmail.com> Hi. While working on adding support to pyplusplus for indexing suite, I took a look on vector_indexing_suite. I think that with a small change of code it is possible to make "vector_indexing_suite" class to work with std::list. The change is simple: to replace operator[] and iterator += ( Distance ) with std::advance( iterator, Distance ). I am almost sure that there is no performance penalties for this change. What do you think? Am I missing some trivial reason why this change could not be done? I attach the modified file. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: vector_indexing_suite.hpp Type: application/octet-stream Size: 8335 bytes Desc: not available URL: From cyril.bazin at info.unicaen.fr Tue Jun 20 18:11:10 2006 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Tue, 20 Jun 2006 18:11:10 +0200 Subject: [C++-sig] ArgumentError... In-Reply-To: References: Message-ID: Hello, Thanks, It works!!! > > My best guess is that Delaunay is derived from > > CGAL::Triangulation_2< > CGAL::Cartesian > , CGAL::Tds2< > CGAL::Tvb, CGAL::Tdsvb > > , CGAL::Tdsfb > > > > > > which supplies finite_vertices_begin and finite_vertices_end. Since > you haven't wrapped that, and Boost.Python doesn't know it's a base > class of Delaunay, you get the error. Yes. You are right. You have two choices: > > 1. pre-assign finite_vertices_end/begin to variables (or cast to > temporaries) of type > > Finite_vertices_iterator (Delaunay::*)() > > and pass those to range(...) This method works fine. Thanks !!! 2. Use the first form of range(...) described > here: http://boost.org/libs/python/doc/v2/iterator.html#range-spec The mechanisms of NextPolicies and Terget are a little obscur to me... Today, I don't understand everything about this kind of stuffs. Just a question : Is there a third method where I can define the iterator and member of the class Triangulation2<...> and define the inheritance between Triangulation_2 and Delaunay using boost? That would let the Python binding looks more like the C++ original library... HTH, Happy Being Helped!!! Cyril -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_sourceforge at nedprod.com Tue Jun 20 21:59:51 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 20 Jun 2006 20:59:51 +0100 Subject: [C++-sig] [ vector | list ] indexing suite In-Reply-To: <7465b6170606200456w53eb66ecrad80540888e176@mail.gmail.com> Message-ID: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> On 20 Jun 2006 at 14:56, Roman Yakovenko wrote: > Hi. While working on adding support to pyplusplus for indexing suite, > I took a look on > vector_indexing_suite. > > I think that with a small change of code it is possible to make > "vector_indexing_suite" class > to work with std::list. The change is simple: to replace operator[] > and iterator += ( Distance ) > with std::advance( iterator, Distance ). I am almost sure that there > is no performance > penalties for this change. > > What do you think? Am I missing some trivial reason why this change > could not be done? You would be far better off using the new and improved indexing suite. It's still sitting in CVS on some experimental branch. It is a lot more efficient, already automatically interfaces with std::list and std::vector and also can be easily extended to handle any arbitrary kind of container. TnFOX uses the new indexing suite. Saved me hours of extra work. Search the mailing list archives for Raoul Gough. Cheers, Niall From dave at boost-consulting.com Tue Jun 20 23:16:19 2006 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 20 Jun 2006 17:16:19 -0400 Subject: [C++-sig] ArgumentError... References: Message-ID: "Cyril Bazin" writes: > Just a question : > Is there a third method where I can define the iterator and member of the > class Triangulation2<...> and define the inheritance between Triangulation_2 > and Delaunay using boost? Sure, but if Triangulation_2 is an implementation detail of CGAL, I don't recommend it. > That would let the Python binding looks more like the C++ original > library... It would let the code that _does_ the binding look more like the original C++ library, but is that valuable? -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Tue Jun 20 23:44:54 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 00:44:54 +0300 Subject: [C++-sig] [ vector | list ] indexing suite In-Reply-To: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> References: <7465b6170606200456w53eb66ecrad80540888e176@mail.gmail.com> <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> Message-ID: <7465b6170606201444i7bb6c415oe64fd3d12817985@mail.gmail.com> On 6/20/06, Niall Douglas wrote: > You would be far better off using the new and improved indexing > suite. It's still sitting in CVS on some experimental branch. It is a > lot more efficient, already automatically interfaces with std::list > and std::vector and also can be easily extended to handle any > arbitrary kind of container. Thanks. I found it and it really looks interesting. When this code will be moved to main branch? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From joel at boost-consulting.com Wed Jun 21 02:28:07 2006 From: joel at boost-consulting.com (Joel de Guzman) Date: Wed, 21 Jun 2006 08:28:07 +0800 Subject: [C++-sig] [ vector | list ] indexing suite In-Reply-To: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> References: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> Message-ID: <44989297.6030105@boost-consulting.com> Niall Douglas wrote: > On 20 Jun 2006 at 14:56, Roman Yakovenko wrote: > >> Hi. While working on adding support to pyplusplus for indexing suite, >> I took a look on >> vector_indexing_suite. >> >> I think that with a small change of code it is possible to make >> "vector_indexing_suite" class >> to work with std::list. The change is simple: to replace operator[] >> and iterator += ( Distance ) >> with std::advance( iterator, Distance ). I am almost sure that there >> is no performance >> penalties for this change. >> >> What do you think? Am I missing some trivial reason why this change >> could not be done? > > You would be far better off using the new and improved indexing > suite. It's still sitting in CVS on some experimental branch. It is a > lot more efficient, already automatically interfaces with std::list > and std::vector and also can be easily extended to handle any > arbitrary kind of container. > > TnFOX uses the new indexing suite. Saved me hours of extra work. > Search the mailing list archives for Raoul Gough. I think this is definitely the way to go. It makes perfect sense for Raoul's work to replace the current indexing suite. Last time I heard from Raoul, he was having some problems with VC6 porting. I wonder if VC6 is still relevant for Boost.Python now, Dave? Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From s_sourceforge at nedprod.com Wed Jun 21 03:37:59 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 21 Jun 2006 02:37:59 +0100 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <7465b6170606192249uf696ff3u4ecd0beeca76a946@mail.gmail.com> References: <200606200226.k5K2QjwT025305@smtp-vbr6.xs4all.nl> Message-ID: <4498B107.17031.30F156B@s_sourceforge.nedprod.com> On 20 Jun 2006 at 8:49, Roman Yakovenko wrote: > > Of course, this won't compile. Any ideas? > > Obviously we need to supply different default arguments for wrapper > and for code that > actually exposes the function. The idea is simple we need new class variable on > argument_t class default_value_xxx ( I explain later why xxx, but you > will have to rename it > to something readable ). And then to generate code that in wrapper > uses original value, but > in boost.python code uses modified one, right? > > I attached the solution to your problem. I made small refactoring + added new > functionality ( enum_declaration ) so you will need the latest version. Cool, thanks for that. I've committed it to the TnFOX SVN repository. > > Thanks for the enum idea. If I can get keyword parameters working I'd > > be very happy. > > Hope I made you very, very happy :-). Well, nearly ... Unfortunately, because I am now including all the patch code into every source file, I'm getting compiler limit: internal structure overflow error on some of the more complex files. So I came up with a cunning plan: In file_writers/multiple_files.py create_source(), I added the following: answer = [] if self.extmodule.license: answer.append( self.extmodule.license.create() ) if self.extmodule.precompiled_header: answer.append( self.extmodule.precompiled_header.create() ) answer.append( '#define PYPP_BUILDING_'+file_name.replace( '.', '_').upper() ) answer.append( '#include "%s%s"' % ( file_name, self.HEADER_EXT ) ) # Include all 'global' include files... Now I have a common.h which is the precompiled header and then a patches.cpp.h which uses a series of #ifdef's to decide which patch code to include based on the macro defined above. Achieves what I wanted originally of inserting custom code just to where it's needed. One other thing: I've just discovered you can't do a #pragma hdrstop if it's enclosed by an #if. So that code of: answer.append( '#ifdef _MSC_VER' ) answer.append( self.indent( '#pragma hdrstop' ) ) answer.append( '#endif //_MSC_VER' ) ... I originally suggested is useless. Sorry about that. If you just plain remove it, you can specify on the command where to stop precompiled header inclusion. Cheers, Niall From s_sourceforge at nedprod.com Wed Jun 21 04:17:37 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 21 Jun 2006 03:17:37 +0100 Subject: [C++-sig] bp::arg() also requires types to be declared Message-ID: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> It appears it's not only enums that must be defined before use with boost::python::arg() - also all types. This causes a fault here: typedef bp::class_< TnFXAppEventLoop_wrapper, bp::bases< FX::FXObject >, std::auto_ptr, boost::noncopyable > TnFXAppEventLoop_exposer_t; TnFXAppEventLoop_exposer_t TnFXAppEventLoop_exposer = TnFXAppEventLoop_exposer_t( "TnFXAppEventLoop", bp::init< bp::optional< char const *, FX::TnFXApp * > >(( bp::arg("threadname")="Event Loop thread", bp::arg("app")=FX::TnFXApp::instance( ) )) ); Here TnFXApp has not been declared to BPL before TnFXAppEventLoop. Problem is that TnFXApp needs TnFXAppEventLoop defined before it (in C++). We have a problem therefore. I can only see one should set use_keywords to False on every calldef taking a typed default parameter. Unfortunately, this is most of them and thus renders using bp::arg() useless. Ideas? How hard would it be to patch BPL to let this work usefully? Cheers, Niall From roman.yakovenko at gmail.com Wed Jun 21 07:01:32 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 08:01:32 +0300 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <4498B107.17031.30F156B@s_sourceforge.nedprod.com> References: <200606200226.k5K2QjwT025305@smtp-vbr6.xs4all.nl> <7465b6170606192249uf696ff3u4ecd0beeca76a946@mail.gmail.com> <4498B107.17031.30F156B@s_sourceforge.nedprod.com> Message-ID: <7465b6170606202201n221cc2f7r5563ae5a982a5bde@mail.gmail.com> On 6/21/06, Niall Douglas wrote: > Unfortunately, because I am now including all the patch code into > every source file, I'm getting compiler limit: internal structure > overflow error on some of the more complex files. So I came up with a > cunning plan: > It is so complex, the is a better solution. 1. add new property to class_t - additional_file_text( code ,.... give a better name ) for cls in image classes: cls.additional_file_text = ... 2. derive from multiple_files_t and redefine split_class method. 3. pass the instance of new class to split module. The only code that should be changed it module_builder_t.split_module. I need to add new parameter - file_writer, that by default is None. What do you think? > One other thing: I've just discovered you can't do a #pragma hdrstop > if it's enclosed by an #if. So that code of: > > answer.append( '#ifdef _MSC_VER' ) > answer.append( self.indent( '#pragma hdrstop' ) ) > answer.append( '#endif //_MSC_VER' ) > > ... I originally suggested is useless. Sorry about that. If you just > plain remove it, you can specify on the command where to stop > precompiled header inclusion. Okay. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Wed Jun 21 07:06:42 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 08:06:42 +0300 Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> Message-ID: <7465b6170606202206w3a4f9244jccbe34e8eb447476@mail.gmail.com> On 6/21/06, Niall Douglas wrote: > It appears it's not only enums that must be defined before use with > boost::python::arg() - also all types. This causes a fault here: > > typedef bp::class_< TnFXAppEventLoop_wrapper, bp::bases< > FX::FXObject >, std::auto_ptr, > boost::noncopyable > TnFXAppEventLoop_exposer_t; > > TnFXAppEventLoop_exposer_t TnFXAppEventLoop_exposer = > TnFXAppEventLoop_exposer_t( "TnFXAppEventLoop", bp::init< > bp::optional< char const *, FX::TnFXApp * > >(( > bp::arg("threadname")="Event Loop thread", > bp::arg("app")=FX::TnFXApp::instance( ) )) ); > > Here TnFXApp has not been declared to BPL before TnFXAppEventLoop. > Problem is that TnFXApp needs TnFXAppEventLoop defined before it (in > C++). > > We have a problem therefore. I can only see one should set > use_keywords to False on every calldef taking a typed default > parameter. Unfortunately, this is most of them and thus renders using > bp::arg() useless. > > Ideas? How hard would it be to patch BPL to let this work usefully? Niall, I have an idea, but unfortunately I don't have time to check it. Please take a look on pyplusplus/module_creator/class_organizer.py file. This file contains algorithm - classic topological sort. It is used to define the order of exported classes. I am sure you can improve it, so we will not have this problem. Good luck! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boost-consulting.com Wed Jun 21 07:02:33 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 21 Jun 2006 01:02:33 -0400 Subject: [C++-sig] [ vector | list ] indexing suite References: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> <44989297.6030105@boost-consulting.com> Message-ID: Joel de Guzman writes: >> TnFOX uses the new indexing suite. Saved me hours of extra work. >> Search the mailing list archives for Raoul Gough. > > I think this is definitely the way to go. It makes perfect sense > for Raoul's work to replace the current indexing suite. Last > time I heard from Raoul, he was having some problems with VC6 > porting. I wonder if VC6 is still relevant for Boost.Python > now, Dave? Having trouble forming an opinion. Unfortunately there are serious embedded platforms that are still stuck with vc6. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Jun 21 07:04:07 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 21 Jun 2006 01:04:07 -0400 Subject: [C++-sig] bp::arg() also requires types to be declared References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> Message-ID: "Niall Douglas" writes: > It appears it's not only enums that must be defined before use with > boost::python::arg() - also all types. What do you mean by "used with?" What do you mean by "defined?" Do you mean they need to be complete types (i.e. not forward declared)? -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Wed Jun 21 07:32:56 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 08:32:56 +0300 Subject: [C++-sig] [ vector | list ] indexing suite In-Reply-To: References: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> <44989297.6030105@boost-consulting.com> Message-ID: <7465b6170606202232u19e89e3n8422cfb74aa9a538@mail.gmail.com> On 6/21/06, David Abrahams wrote: > Joel de Guzman writes: > > >> TnFOX uses the new indexing suite. Saved me hours of extra work. > >> Search the mailing list archives for Raoul Gough. > > > > I think this is definitely the way to go. It makes perfect sense > > for Raoul's work to replace the current indexing suite. Last > > time I heard from Raoul, he was having some problems with VC6 > > porting. I wonder if VC6 is still relevant for Boost.Python > > now, Dave? > > Having trouble forming an opinion. Unfortunately there are serious > embedded platforms that are still stuck with vc6. In this case, is it possible to apply the patch? Another question: can both indexing suite co-exists? if so may be it possible to move indexing_v2 to main branch? The main objective to this is easiest install procedure and earlier testing. Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Wed Jun 21 07:35:44 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 08:35:44 +0300 Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> Message-ID: <7465b6170606202235r159d3e7dy1f75c3afd1ddf8f4@mail.gmail.com> On 6/21/06, David Abrahams wrote: > "Niall Douglas" writes: > > > It appears it's not only enums that must be defined before use with > > boost::python::arg() - also all types. > > What do you mean by "used with?" > > What do you mean by "defined?" Do you mean they need to be complete > types (i.e. not forward declared)? In order to use boost::python::arg with default value, the type of default value should be already registered. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From d.bollmann at tu-berlin.de Wed Jun 21 07:52:23 2006 From: d.bollmann at tu-berlin.de (Dietrich Bollmann) Date: Wed, 21 Jun 2006 14:52:23 +0900 Subject: [C++-sig] C integration question - how to get the result of an evaluation with PyEval_EvalCode() Message-ID: <4498DE97.70500@tu-berlin.de> Hi, I am working on a "python command port" for an application (blender) written in C and using python as scripting language. The idea is to let other applications interact with blender via a socket using blender python scripts / commands. I got everything work - but couldn't figure out how to get the result of the evaluation for sending it back over the socket to the client. I am using the following commands: ... /* compile python script / command */ script_compiled = Py_CompileString(script, "", Py_file_input); ... /* evaluate compiled python script / command */ PyObject *result_obj; result_obj = PyEval_EvalCode(script_compiled, dict, dict); ... By "result" I am thinking about something like the messages printed by the python shell as response when executing a command - if possible as string. There are some differences to the python interactive loop though: - `script' might be one command string like `a = 123\n' or a whole script like `def blah(a, b):\n c = a + b\n print c\n\nblah(3, 4)\n\n' - there might be empty lines inside of function or class definitions as the script is entered as one C string and not line by line - I am only interested in the result of the last command (like `7' in the case of the second example) A second wish would be to have something like a `get_value()' function which would return the value of some variable as result - like just entering the name of a variable in the python shell or using a print command like `print variable' from the shell. (In general I would like to let `print' print to the blender stdout though.) Any idea? Thanks for your help & best wishes, Dietrich By the way, when experimenting with "results" I also tried the following snipped (an adapted version from the book "Programming Python" by Mark Lutz): void experiment() { int cval; PyObject *pdict, *pval; /* make a new namespace */ pdict = PyDict_New(); PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); PyDict_SetItemString(pdict, "Y", PyInt_FromLong(2)); /* dict['Y'] = 2 */ PyRun_String("X = 99", Py_file_input, pdict, pdict); /* run statements */ PyRun_String("X = X+Y", Py_file_input, pdict, pdict); /* same X and Y */ pval = PyDict_GetItemString(pdict, "X"); /* fetch dict['X'] */ PyArg_Parse(pval, "i", &cval); /* convert to C */ printf("result: %d\n", cval); /* result=101 */ Py_DECREF(pdict); } But for some reason got the following when executing it: result: -1074019336 What have I done wrong? -- Dietrich Bollmann From rwgk at yahoo.com Wed Jun 21 17:20:26 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 21 Jun 2006 08:20:26 -0700 (PDT) Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: <7465b6170606202235r159d3e7dy1f75c3afd1ddf8f4@mail.gmail.com> Message-ID: <20060621152026.8835.qmail@web31501.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > On 6/21/06, David Abrahams wrote: > > "Niall Douglas" writes: > > > > > It appears it's not only enums that must be defined before use with > > > boost::python::arg() - also all types. > > > > What do you mean by "used with?" > > > > What do you mean by "defined?" Do you mean they need to be complete > > types (i.e. not forward declared)? > > In order to use boost::python::arg with default value, the type of > default value > should be already registered. You can get around this by using BOOST_PYTHON_[MEMBER_]FUNCTION_OVERLOADS, or simply wrap the overloads one by one. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From s_sourceforge at nedprod.com Wed Jun 21 18:01:22 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 21 Jun 2006 17:01:22 +0100 Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: <7465b6170606202206w3a4f9244jccbe34e8eb447476@mail.gmail.com> References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> Message-ID: <44997B62.6825.E7172@s_sourceforge.nedprod.com> On 21 Jun 2006 at 8:06, Roman Yakovenko wrote: > > We have a problem therefore. I can only see one should set > > use_keywords to False on every calldef taking a typed default > > parameter. Unfortunately, this is most of them and thus renders using > > bp::arg() useless. > > > > Ideas? How hard would it be to patch BPL to let this work usefully? > > Niall, I have an idea, but unfortunately I don't have time to check > it. Please take a > look on pyplusplus/module_creator/class_organizer.py file. This file contains > algorithm - classic topological sort. It is used to define the order of exported > classes. I am sure you can improve it, so we will not have this problem. Herein lies a problem: class Foo; class Foo2 { friend class Foo; Foo2(Foo *f=0); }; class Foo { Foo(Foo2 *f=0); inline void somemethod(Foo2 *a) { a->foo(); } }; Here you need to declare Foo and Foo2 to BPL. Problem is, they take constructor args circularly so if I try to declare default args, either one or the other is going to be undeclared to BPL and you get the fault. If, and only if, both Foo and Foo2 have constructors with no default args, you can delay the constructor declaration and declare it later via bp::init<>. Otherwise you are trapped and can't use bp::arg() at all. To fix pyplusplus to correctly order stuff according to all these possibilities, and even then still leaving open the potential of it failing to work in certain rare circumstances - well, the correct thing to do IMHO is to alter the implementation of bp::arg() so it doesn't need to have the type declared to BPL via bp::class_() first. All this said, I am now out of time for the python bindings. I am going to have to cease development once again for the next few months. Sorry, I get windows and these windows get exhausted. I must now begin on a new chaotic economic modelling software I want to base my PhD on. Cheers, Niall From s_sourceforge at nedprod.com Wed Jun 21 18:01:22 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 21 Jun 2006 17:01:22 +0100 Subject: [C++-sig] Default arguments in pyplusplus In-Reply-To: <7465b6170606202201n221cc2f7r5563ae5a982a5bde@mail.gmail.com> References: <4498B107.17031.30F156B@s_sourceforge.nedprod.com> Message-ID: <44997B62.5660.E7115@s_sourceforge.nedprod.com> On 21 Jun 2006 at 8:01, Roman Yakovenko wrote: > On 6/21/06, Niall Douglas wrote: > > Unfortunately, because I am now including all the patch code into > > every source file, I'm getting compiler limit: internal structure > > overflow error on some of the more complex files. So I came up with a > > cunning plan: > > > It is so complex, the is a better solution. > > 1. add new property to class_t - additional_file_text( code ,.... give > a better name ) > for cls in image classes: > cls.additional_file_text = ... > 2. derive from multiple_files_t and redefine split_class method. > 3. pass the instance of new class to split module. > > The only code that should be changed it module_builder_t.split_module. I need to > add new parameter - file_writer, that by default is None. > > What do you think? That looks fine too. Cleaner. Cheers, Niall From lee.will at gmail.com Wed Jun 21 19:59:28 2006 From: lee.will at gmail.com (Will Lee) Date: Wed, 21 Jun 2006 12:59:28 -0500 Subject: [C++-sig] Overriding operator == and = for None Message-ID: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> Is there a way I can override the operator == and = for a wrapped c++ object to take in a Python None type? Essentially, I'd like to define a class where it can do: #NullableInt is a struct that holds an int and a boolean, indicating whether it is valid or not c = NullableInt(3) # NullableInt wraps a C++ std::vector cv = NullableIntVec() cv.append(c) # ok cv[0] = None print cv[0] # should print out "None", and the C++'s struct would hold a boolean that's set to false # Generates an invalid Int cInvalid = NullableInt() # Should be true, it won't remove object but setting the underlying c++ object to None) cv[0] == cInvalid # Should also be true if we can override == cv[0] == None Does anybody know if it is posslbe in Boost.Python to have this behavior? Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Jun 21 20:12:58 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Jun 2006 21:12:58 +0300 Subject: [C++-sig] Overriding operator == and = for None In-Reply-To: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> References: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> Message-ID: <7465b6170606211112y4ea67d68p1d9c2929b4c0f849@mail.gmail.com> On 6/21/06, Will Lee wrote: > Is there a way I can override the operator == and = for a wrapped c++ object > to take in a Python None type? I could be wrong, but you can not change semantic of = ( assignment operator ) As for the ==( equal operator ), you can overload == that takes boost::python::object and then test it for being None. I am almost sure that what you are trying to do should be rethought. For example: x == None will work, but x is None will not. This can lead to bugs. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mail at a-beyer.de Wed Jun 21 11:22:08 2006 From: mail at a-beyer.de (Andreas Beyer) Date: Wed, 21 Jun 2006 11:22:08 +0200 Subject: [C++-sig] Overriding operator == and = for None In-Reply-To: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> References: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> Message-ID: <44990FC0.9040408@a-beyer.de> Hi, I think there are two things to do. First, NullableIntVec has to define a wrapper method for __setattr_(), which would have to accept python objects and either create a new empty NullableInt or a NullableInt initialized with the respective value. Second, you will have to wrap __eq__(), __ne__() and/or __cmp__() of NullableInt in order to get the desired behaviour for ==. I suggest implementing 'rich comparison', because that would allow you to do things like this: >>> c = NullableInt(3) >>> c < 4 >>> True See also here: http://docs.python.org/ref/customization.html http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_operators_special_functions Again, these wrappers will have to accept python objects (i.e. boost::python::object) as arguments, otherwise you can't properly compare against None. Hope that helps, Andreas Will Lee wrote: > Is there a way I can override the operator == and = for a wrapped c++ > object to take in a Python None type? Essentially, I'd like to define > a class where it can do: > > #NullableInt is a struct that holds an int and a boolean, indicating > whether it is valid or not > c = NullableInt(3) > # NullableInt wraps a C++ std::vector > cv = NullableIntVec() > cv.append(c) # ok > cv[0] = None > print cv[0] > # should print out "None", and the C++'s struct would hold a boolean > that's set to false > > # Generates an invalid Int > cInvalid = NullableInt() > # Should be true, it won't remove object but setting the underlying > c++ object to None) > cv[0] == cInvalid > # Should also be true if we can override == > cv[0] == None > > Does anybody know if it is posslbe in Boost.Python to have this behavior? > > Will > ------------------------------------------------------------------------ > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Dr. Andreas Beyer mail at a-beyer.de www.andreas-beyer.de From rwgk at yahoo.com Wed Jun 21 22:49:32 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 21 Jun 2006 13:49:32 -0700 (PDT) Subject: [C++-sig] Overriding operator == and = for None In-Reply-To: <7f03db650606211059h1b424d20j413fc5f347d43eea@mail.gmail.com> Message-ID: <20060621204932.34184.qmail@web31508.mail.mud.yahoo.com> I think you can do what you want based on boost::optional. You may want to look here for an example: http://phenix-online.org/cctbx_sources/boost_adaptbx/ optional_conversions.h optional_ext.cpp tst_optional.py Note that "x is None" works correctly, not just "x == None". The boost::optional documentation is here: http://www.boost.org/libs/optional/doc/optional.html Feel free to copy optional_conversions.h if you are interested. --- Will Lee wrote: > Is there a way I can override the operator == and = for a wrapped c++ object > to take in a Python None type? Essentially, I'd like to define a class > where it can do: > > #NullableInt is a struct that holds an int and a boolean, indicating whether > it is valid or not > c = NullableInt(3) > # NullableInt wraps a C++ std::vector > cv = NullableIntVec() > cv.append(c) # ok > cv[0] = None > print cv[0] > # should print out "None", and the C++'s struct would hold a boolean that's > set to false > > # Generates an invalid Int > cInvalid = NullableInt() > # Should be true, it won't remove object but setting the underlying c++ > object to None) > cv[0] == cInvalid > # Should also be true if we can override == > cv[0] == None > > Does anybody know if it is posslbe in Boost.Python to have this behavior? > > Will __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From abierbaum at gmail.com Wed Jun 21 23:53:36 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Wed, 21 Jun 2006 16:53:36 -0500 Subject: [C++-sig] Protected destructor compile error Message-ID: I have run into a compiler error with boost.python and I would like to understand what is causing it so I can try to fix the problem. This is coming up in several places in the binding I am working on, so I am hopeful if I can understand what is happening with one case I can fix it everywhere. Background: I am wrapping a class, Camera, the method that is causing problems is: bool Camera::calcViewRay (Line &line, Int32 x, Int32 y, const Viewport &port); I am wrapping it (using pyplusplus) with this def: Camera_exposer.def("calcViewRay" , &::osg::Camera::calcViewRay , ( bp::arg("line"), bp::arg("x"), bp::arg("y"), bp::arg("port") ) , bp::default_call_policies() ); I get this error when building with boost 1.33.1 on fedora core 4 (gcc 4.0.2): /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp: In static member function 'static void boost::python::detail::value_destroyer::execute(const volatile T*) [with T = osg::Viewport]': /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:90: instantiated from 'void boost::python::detail::destroy_referent_impl(void*, T& (*)()) [with T = const osg::Viewport]' /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:101: instantiated from 'void boost::python::detail::destroy_referent(void*, T (*)()) [with T = const osg::Viewport&]' /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/converter/rvalue_from_python_data.hpp:135: instantiated from 'boost::python::converter::rvalue_from_python_data::~rvalue_from_python_data() [with T = const osg::Viewport&]' /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/converter/arg_from_python.hpp:108: instantiated from 'PyObject* boost::python::detail::caller_arity<5u>::impl::operator()(PyObject*, PyObject*) [with F = bool (osg::Camera::*)(osg::Line&, osg::Int32, osg::Int32, const osg::Viewport&), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector6]' /home/allenb/Source/boost/installed/include/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 >]' src/osg_module2/Camera.pypp.cpp:459: instantiated from here /home/allenb/Source/OpenSG/Builds/i686-pc-linux-gnu-g++/include/OpenSG/OSGViewport.h:126: error: 'virtual osg::Viewport::~Viewport()' is protected /home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:33: error: within this context It looks like there is a problem with the "const Viewport& port" argument being passed. For some reason the generated code seems to want to be able to destroy instances of the Viewport class. This class has protected constructor and destructor as it is reference counted and the user can only create them using a helper function (Camera::create()). Can anyone describe what is happening here and what prerequisites exist for this call to work? Is there some call policy that I should be using to make this work? Thanks, Allen From diresu at web.de Thu Jun 22 05:37:44 2006 From: diresu at web.de (Dietrich Bollmann) Date: Thu, 22 Jun 2006 12:37:44 +0900 Subject: [C++-sig] C integration question - how to get the result of an evaluation with PyEval_EvalCode() Message-ID: <449A1088.3060703@web.de> Hi, I am working on a "python command port" for an application (blender) written in C and using python as scripting language. The idea is to let other applications interact with blender via a socket using blender python scripts / commands. I got everything work - but couldn't figure out how to get the result of the evaluation for sending it back over the socket to the client. I am using the following commands: ... /* compile python script / command */ script_compiled = Py_CompileString(script, "", Py_file_input); ... /* evaluate compiled python script / command */ PyObject *result_obj; result_obj = PyEval_EvalCode(script_compiled, dict, dict); ... By "result" I am thinking about something like the messages printed by the python shell as response when executing a command - if possible as string. There are some differences to the python interactive loop though: - `script' might be one command string like `a = 123\n' or a whole script like `def blah(a, b):\n c = a + b\n print c\n\nblah(3, 4)\n\n' - there might be empty lines inside of function or class definitions as the script is entered as one C string and not line by line - I am only interested in the result of the last command (like `7' in the case of the second example) A second wish would be to have something like a `get_value()' function which would return the value of some variable as result - like just entering the name of a variable in the python shell or using a print command like `print variable' from the shell. (In general I would like to let `print' print to the blender stdout though.) Any idea? Thanks for your help & best wishes, Dietrich By the way, when experimenting with "results" I also tried the following snipped (an adapted version from the book "Programming Python" by Mark Lutz): void experiment() { int cval; PyObject *pdict, *pval; /* make a new namespace */ pdict = PyDict_New(); PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); PyDict_SetItemString(pdict, "Y", PyInt_FromLong(2)); /* dict['Y'] = 2 */ PyRun_String("X = 99", Py_file_input, pdict, pdict); /* run statements */ PyRun_String("X = X+Y", Py_file_input, pdict, pdict); /* same X and Y */ pval = PyDict_GetItemString(pdict, "X"); /* fetch dict['X'] */ PyArg_Parse(pval, "i", &cval); /* convert to C */ printf("result: %d\n", cval); /* result=101 */ Py_DECREF(pdict); } But for some reason got the following when executing it: result: -1074019336 What have I done wrong? -- Dietrich Bollmann From cyril.bazin at info.unicaen.fr Thu Jun 22 10:46:55 2006 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Thu, 22 Jun 2006 10:46:55 +0200 Subject: [C++-sig] Iterator or not iterator... Message-ID: Hello, I've got a question about the bindings of iterators. Given a C++ code which look more or less like that: template class C { It the_begin() {...} It the_end() {...} It2 foo(it) {...} } template class It { //... define everything that an iterator must define ... } The C++ code to bind a version of the previous class C could be : class MyO { //define some methods } typedef C MyC; typedef It MyIt; class_("MyO") .def(...) ...; //class _("MyIt") // .def(...) // ...; class_("MyC") .def("the_iter", range(&MyC::the_begin , &MyC::the_end)) .def("foo", MyC::foo) As expected, in Python the method MyC.the_iter will return some instances of the class MyO. But, the method MyC::foo expect a MyIt as argument... So, I can't do something like that : myC = MyC() for bar in myC: assert type(bar) == MyO x = myC.foo(bar) ... In other words, Is there a way to define MyC like that : class_("MyC") .def("the_iter", range_bis(&MyC::the_begin , &MyC::the_end)) Which could allow me to do something like: myC = MyC() for bar in myC: assert type(bar) == MyIt x = myC.foo(bar) ... If you have any suggestion... Thanks in advance. Cyril -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Thu Jun 22 12:39:15 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Thu, 22 Jun 2006 11:39:15 +0100 Subject: [C++-sig] boost::python std::vector< std::string > crash Message-ID: Hi, I'm using boost/python/suite/indexing/vector_indexing_suite.hpp from the cvs_head version of boost python on MSVC 8. I'm getting a runtime assertion failure when appending to a vector of strings. I define a module with a vector of strings with the following code: #include #include #include using namespace boost; using namespace boost::python; using namespace std; typedef vector< string > string_vec; BOOST_PYTHON_MODULE( _bptest ) { /** A vector of strings. */ class_< string_vec >( "StringVec" ) .def( vector_indexing_suite< string_vec >() ) ; } I use this python code: import sys print 'Importing bptest' _path_to_module = '../bin/Bio/Biopsy/_bptest.pyd/vc-8_0/debug/threading-multi' sys.path.append( _path_to_module ) import _bptest print 'Creating string vec' strings = _bptest.StringVec() print 'Appending string' strings.append( 'a' ) and it crashes in "strings.append( 'a' )" There seems to be very little in the documenation about how std::strings are handled. They seem to work fine when used outside containers. Also containers of user-defined classes (as in the vector indexing example, struct X) and containers of doubles, ints, etc.. seem to work fine. What am I missing here? Eventually I want to use a C++ method that accepts a const std::vector< std::string > & as an argument. The FAQ it suggests there are two methods to do this: vector_indexing and also using custom rvalue converters. Unfortunately this documentation seems rather out of date. The instructions to log in to cvs to see the example code don't appear to work. I did manage to find the code but it is not clear how it could help me. Any help would be much appreciated. Thanks, John. P.S. here is the stack trace: > _biopsy.pyd!boost::python::detail::value_destroyer<0>::execute,std::allocator > >(const std::basic_string,std::allocator > * p="") Line 34 C++ _biopsy.pyd!boost::python::detail::destroy_referent_impl,std::allocator > const >(void * p=0x0021fbc8, const std::basic_string,std::allocator > & (void)* __formal=0x00000000) Line 95 + 0x9 bytes C++ _biopsy.pyd!boost::python::detail::destroy_referent,std::allocator > const &>(void * p=0x0021fbc8, const std::basic_string,std::allocator > & (void)* __formal=0x00000000) Line 101 + 0xb bytes C++ _biopsy.pyd!boost::python::converter::rvalue_from_python_data,std::allocator > const &>::~rvalue_from_python_data,std::allocator > const &>() Line 135 + 0xe bytes C++ _biopsy.pyd!boost::python::converter::arg_rvalue_from_python,std::allocator > const &>::~arg_rvalue_from_python,std::allocator > const &>() + 0xf bytes C++ _biopsy.pyd!boost::python::arg_from_python,std::allocator > const &>::~arg_from_python,std::allocator > const &>() + 0xf bytes C++ _biopsy.pyd!boost::python::detail::caller_arity<2>::impl,std::allocator >,std::allocator,std::allocator > > > &,std::basic_string,std::allocator > const &),boost::python::default_call_policies,boost::mpl::vector3,std::allocator >,std::allocator,std::allocator > > > &,std::basic_string,std::allocator > const &> >::operator()(_object * args_=0x009d58a0, _object * __formal=0x00000000) Line 201 + 0x2a bytes C++ _biopsy.pyd!boost::python::objects::caller_py_function_impl,std::allocator >,std::allocator,std::allocator > > > &,std::basic_string,std::allocator > const &),boost::python::default_call_policies,boost::mpl::vector3,std::allocator >,std::allocator,std::allocator > > > &,std::basic_string,std::allocator > const &> > >::operator()(_object * args=0x009d58a0, _object * kw=0x00000000) Line 39 C++ From dave at boost-consulting.com Thu Jun 22 14:20:13 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 22 Jun 2006 08:20:13 -0400 Subject: [C++-sig] [ vector | list ] indexing suite References: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> <44989297.6030105@boost-consulting.com> <7465b6170606202232u19e89e3n8422cfb74aa9a538@mail.gmail.com> Message-ID: "Roman Yakovenko" writes: > On 6/21/06, David Abrahams wrote: >> Joel de Guzman writes: >> >> >> TnFOX uses the new indexing suite. Saved me hours of extra work. >> >> Search the mailing list archives for Raoul Gough. >> > >> > I think this is definitely the way to go. It makes perfect sense >> > for Raoul's work to replace the current indexing suite. Last >> > time I heard from Raoul, he was having some problems with VC6 >> > porting. I wonder if VC6 is still relevant for Boost.Python >> > now, Dave? >> >> Having trouble forming an opinion. Unfortunately there are serious >> embedded platforms that are still stuck with vc6. > > In this case, is it possible to apply the patch? > > Another question: can both indexing suite co-exists? > if so may be it possible to move indexing_v2 to main branch? > The main objective to this is easiest install procedure and earlier testing. FYI, I'm on vacation right now, so I won't be making any heavy decisions :) -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Jun 22 14:27:33 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 22 Jun 2006 08:27:33 -0400 Subject: [C++-sig] Protected destructor compile error References: Message-ID: "Allen Bierbaum" writes: > It looks like there is a problem with the "const Viewport& port" > argument being passed. For some reason the generated code seems to > want to be able to destroy instances of the Viewport class. This > class has protected constructor and destructor as it is reference > counted and the user can only create them using a helper function > (Camera::create()). > > Can anyone describe what is happening here Boost.Python assumes that a const reference argument means that the function can accept "rvalues", e.g. objects implicitly converted from other python types. The generated converter thus has storage for a temporary Viewport object which potentially needs to be destroyed after the wrapped function is called. > and what prerequisites > exist for this call to work? Is there some call policy that I should > be using to make this work? Nope, but a thin wrapper that exposes Viewport& instead of Viewport const& will help you. -- Dave Abrahams Boost Consulting www.boost-consulting.com From abierbaum at gmail.com Thu Jun 22 15:28:41 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Thu, 22 Jun 2006 08:28:41 -0500 Subject: [C++-sig] Protected destructor compile error In-Reply-To: References: Message-ID: On 6/22/06, David Abrahams wrote: > "Allen Bierbaum" writes: > > > It looks like there is a problem with the "const Viewport& port" > > argument being passed. For some reason the generated code seems to > > want to be able to destroy instances of the Viewport class. This > > class has protected constructor and destructor as it is reference > > counted and the user can only create them using a helper function > > (Camera::create()). > > > > Can anyone describe what is happening here > > Boost.Python assumes that a const reference argument means that the > function can accept "rvalues", e.g. objects implicitly converted from > other python types. The generated converter thus has storage for a > temporary Viewport object which potentially needs to be destroyed > after the wrapped function is called. Ok. This makes sense although I still don't fully understand what is happening behind the scenes but from this description I should be able to look at the code to find out. > > > and what prerequisites > > exist for this call to work? Is there some call policy that I should > > be using to make this work? > > Nope, but a thin wrapper that exposes Viewport& instead of Viewport > const& will help you. This makes sense as well. Unfortunately there could be hundreds of places in the code where I would need to do this so it will be difficult but I will do it. One additional question: Is there any metafunction (something like pointee<>) that could be specialized to tell boost.python that when it sees a const& of this type it should not assume that it can make a temporary? In effect some way to tell it to choose to use the path that the thin wrapper would use instead. If there isn't a metafunction like this, would it be difficult to implement something like this? (if not, I am willing to work on it if you give me some direction on where to look and what to look for) To help with cases like mine, it would be nice to make the default version use type traits to detect if the type has a public destructor (and anything else it needs to make the temporary). Thanks again for the quick response. -Allen > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From joel at boost-consulting.com Thu Jun 22 16:06:09 2006 From: joel at boost-consulting.com (Joel de Guzman) Date: Thu, 22 Jun 2006 22:06:09 +0800 Subject: [C++-sig] boost::python std::vector< std::string > crash In-Reply-To: References: Message-ID: <449AA3D1.1080805@boost-consulting.com> John Reid wrote: > Hi, > > I'm using boost/python/suite/indexing/vector_indexing_suite.hpp from the > cvs_head version of boost python on MSVC 8. I'm getting a runtime > assertion failure when appending to a vector of strings. > [snips] > > There seems to be very little in the documenation about how std::strings > are handled. They seem to work fine when used outside containers. Also > containers of user-defined classes (as in the vector indexing example, > struct X) and containers of doubles, ints, etc.. seem to work fine. > > What am I missing here? That's odd. I can't reproduce your results. To be sure, I added your test in libs/python/test/vector_indexing_suite.cpp/py. I'm getting no crash. Please check out the test suite and run it. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From j.reid at mail.cryst.bbk.ac.uk Thu Jun 22 17:59:51 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Thu, 22 Jun 2006 16:59:51 +0100 Subject: [C++-sig] boost::python std::vector< std::string > crash In-Reply-To: <449AA3D1.1080805@boost-consulting.com> References: <449AA3D1.1080805@boost-consulting.com> Message-ID: Joel de Guzman wrote: > > [snips] > > That's odd. I can't reproduce your results. To be sure, I added > your test in libs/python/test/vector_indexing_suite.cpp/py. > I'm getting no crash. Please check out the test suite and run it. > > Regards, The test suite crashes in the same place as my code. I guess there's something wrong in my build set up. I'm on XP with Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86 and Python 2.4.3 I've tried various set ups to build python extensions, perhaps I bungled something up somewhere. I'm going to try doing a complete refresh from cvs and running the python test again unless anyone has something better to suggest. Thanks, John. From j.reid at mail.cryst.bbk.ac.uk Thu Jun 22 19:12:29 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Thu, 22 Jun 2006 18:12:29 +0100 Subject: [C++-sig] boost::python std::vector< std::string > crash In-Reply-To: References: <449AA3D1.1080805@boost-consulting.com> Message-ID: John Reid wrote: > Joel de Guzman wrote: > >>[snips] >> >>That's odd. I can't reproduce your results. To be sure, I added >>your test in libs/python/test/vector_indexing_suite.cpp/py. >>I'm getting no crash. Please check out the test suite and run it. >> >>Regards, > > I've investigated further. I wasn't aware of the correct way to run the python tests. Now I've recompiled a clean version of boost cvs_head everything works ok if I run the tests using 'bjam -sPYTHON_TEST_ARGS= test' in the 'boost\libs\python\test' directory. What might be relevant is that if I run 'bjam' with no arguments, I can generate 'vector_indexing_suite_ext.pyd' in the 'boost\bin\boost\libs\python\test\vector_indexing_suite_ext.pyd\vc-8_0\debug\threading-multi' directory. When I manually set PYTHONPATH to this directory and run 'python vector_indexing_suite.py' I get the crash as before. Is this expected, relevant and/or interesting? I would have thought this would just have run that particular test. Any help appreciated as always. Thanks, John. From roman.yakovenko at gmail.com Thu Jun 22 21:12:32 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 22 Jun 2006 22:12:32 +0300 Subject: [C++-sig] Protected destructor compile error In-Reply-To: References: Message-ID: <7465b6170606221212i5d8a5f80mec3591e0b4ed6bf5@mail.gmail.com> On 6/22/06, David Abrahams wrote: > Boost.Python assumes that a const reference argument means that the > function can accept "rvalues", e.g. objects implicitly converted from > other python types. I am sure I am missing something trivial. Why Boost.Python does such assumption? In my opinion Boost.Python, in this case does not have to make any assumption. If user want to enjoy from conversion he should register it, right? He does this using: 1. implicitly_convertible 2. register_ptr_to_python 3. class_::bases If none of those has been used, Boost.Python can safely assume that the class could not be built from other python types. Would you mind to explain, please? Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Thu Jun 22 21:19:37 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 22 Jun 2006 22:19:37 +0300 Subject: [C++-sig] [ vector | list ] indexing suite In-Reply-To: References: <449861C7.15757.1D9833D@s_sourceforge.nedprod.com> <44989297.6030105@boost-consulting.com> <7465b6170606202232u19e89e3n8422cfb74aa9a538@mail.gmail.com> Message-ID: <7465b6170606221219k59d1d97eh61ae2730cca23ac8@mail.gmail.com> On 6/22/06, David Abrahams wrote: > FYI, I'm on vacation right now, so I won't be making any heavy > decisions :) When I am on vacation the only heavy decisions I have to make are: 1. where and what to eat 2. to go to the pool or to the sea :-) Enjoy your vacation! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From hpj at urpla.net Thu Jun 22 22:30:07 2006 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 22 Jun 2006 22:30:07 +0200 Subject: [C++-sig] boost/python 1.33.1 breaks aliasing rules Message-ID: <200606222230.07791.hpj@urpla.net> Hi Philipp, since you seem the originator of that boost patch: http://mail.python.org/pipermail/c++-sig/2005-December/009895.html you might want to know, that this broke boost 1.33.1 compilation on SuSE 9.3: "c++" -O2 -g -march=i586 -mcpu=i686 -fmessage-length=0 -c -Wall -ftemplate-depth-255 -DNDEBUG -DNDEBUG -DBOOST_PYTHON_DYNAMIC_LIB -DBOOST_PYTHON_SOURCE -O2 -finline-functions -Wno-inline -fPIC -I"bin/boost/libs/python/build" -I "/usr/include/python2.4" -I "/usr/src/packages/BUILD/boost_1_33_1" -o "bin/boost/libs/python/build/libboost_python.so/gcc/release/shared-linkable-true/long.o" "/usr/src/packages/BUILD/boost_1_33_1/libs/ python/build/../src/long.cpp" /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp: In constructor `boost::python::detail::long_base::long_base()': /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp:27: error: `new_reference' specified as declarator-id /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp:27: error: multiple declarations `int' and `boost::python::api::object' /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp:27: error: invalid conversion from `PyObject*' to `int' /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp:27: warning: unused variable `int boost::python::detail::new_reference' /usr/src/packages/BUILD/boost_1_33_1/libs/python/src/long.cpp:27: confused by earlier errors, bailing out ...failed gcc-C++-action bin/boost/libs/python/build/libboost_python.so/gcc/release/shared-linkable-true/long.o... which led to a broken packman package boost-1.33.1-17.pm.1.i586.rpm for that release (at least): # rpm -V boost missing /usr/lib/libboost_python-gcc-1_33.so.1.33.0 missing /usr/lib/libboost_python-gcc-1_33_1.so.1.33.1 It's a pity, that rpm doesn't check for dangling symlinks, otherwise this failure would have been caught. Why the boost build system bjam doesn't propagate errors properly escapes me at the moment.. Essentially reverting your patch to long_base::long_base() fixed it for me, see attached patch for reference. Manfred, you might want to apply it to your boost build in order to avoid unspecific "boost doesn't work with python", "libboost_python*.so* missing" complains.. Cheers, Pete -------------- next part -------------- A non-text attachment was scrubbed... Name: boost-fix_python_build.patch Type: text/x-diff Size: 652 bytes Desc: not available URL: From rwgk at yahoo.com Fri Jun 23 01:22:09 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 22 Jun 2006 16:22:09 -0700 (PDT) Subject: [C++-sig] Protected destructor compile error In-Reply-To: <7465b6170606221212i5d8a5f80mec3591e0b4ed6bf5@mail.gmail.com> Message-ID: <20060622232209.90938.qmail@web31514.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > On 6/22/06, David Abrahams wrote: > > Boost.Python assumes that a const reference argument means that the > > function can accept "rvalues", e.g. objects implicitly converted from > > other python types. > > I am sure I am missing something trivial. > > Why Boost.Python does such assumption? In my opinion Boost.Python, in this > case > does not have to make any assumption. > > If user want to enjoy from conversion he should register it, right? He > does this using: > > 1. implicitly_convertible > 2. register_ptr_to_python > 3. class_::bases > > If none of those has been used, Boost.Python can safely assume that > the class could not be built from other python types. Boost.Python also supports custom rvalue converters. See the FAQ for examples. You'd need two different mechanisms for types that allow custom from_python conversions (involving the construction and destruction of temporaries) and those that don't. I am guessing David considered that extra effort not worthwhile or impractical. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Fri Jun 23 05:12:50 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 22 Jun 2006 23:12:50 -0400 Subject: [C++-sig] Protected destructor compile error References: <7465b6170606221212i5d8a5f80mec3591e0b4ed6bf5@mail.gmail.com> <20060622232209.90938.qmail@web31514.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- Roman Yakovenko wrote: > >> On 6/22/06, David Abrahams wrote: >> > Boost.Python assumes that a const reference argument means that >> > the function can accept "rvalues", e.g. objects implicitly >> > converted from other python types. >> >> I am sure I am missing something trivial. >> >> Why Boost.Python does such assumption? Because that's the way it works in C++. The aim of Boost.Python is to make the Python interface reflect the C++ interface. Probably "assumes" was the wrong word. I should have said "is designed so." >> In my opinion Boost.Python, in this case does not have to make any >> assumption. >> >> If user want to enjoy from conversion he should register it, right? >> He does this using: >> >> 1. implicitly_convertible >> 2. register_ptr_to_python >> 3. class_::bases bases<...> has nothing to do with it; they don't enable rvalue conversions. Nor does register_ptr_to_python. We're talking about from-python conversions here. >> If none of those has been used, Boost.Python can safely assume that >> the class could not be built from other python types. > > Boost.Python also supports custom rvalue converters. See the FAQ for > examples. And there are built-in rvalue conversions, e.g., Python str to std::string, Python float to C++ float, etc. You definitely don't want the temporary string or float binding to a non-const reference. > You'd need two different mechanisms for types that allow > custom from_python conversions (involving the construction and > destruction of temporaries) and those that don't. I am guessing > David considered that extra effort not worthwhile or impractical. Not really; I actually never considered treating types nonuniformly in this way, and I don't think it would be tenable to do so based on whether custom from_python conversions are allowed. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Jun 23 05:36:33 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 22 Jun 2006 23:36:33 -0400 Subject: [C++-sig] Protected destructor compile error References: Message-ID: "Allen Bierbaum" writes: > One additional question: Is there any metafunction (something like > pointee<>) that could be specialized to tell boost.python that when > it sees a const& of this type it should not assume that it can make > a temporary? In effect some way to tell it to choose to use the > path that the thin wrapper would use instead. > > If there isn't a metafunction like this, would it be difficult to > nimplement something like this? I think the answer to both questions is no. It sounds like a reasonable thing to do, though. > (if not, I am willing to work on it if you give me some direction on > where to look and what to look for) To help with cases like mine, it > would be nice to make the default version use type traits to detect > if the type has a public destructor (and anything else it needs to > make the temporary). It's not possible to detect that, unfortunately. And _making_ the temporary is a completely separate issue from destroying it. The part of the converter that makes the temporary is looked up dynamically based on the source Python type and in this case of course, nothing is ever found. The fact that the destruction code is instantiated unconditionally by the static part of the is really a sort of optimization. The simplest way to make this work for everyone would be to make the dynamic part of the converter responsible for destroying the temporary. That would make your case work without the need for any traits. However, there's a tradeoff; there would be an extra function pointer indirection, at least. In the case of converting to a C++ type with a trivial destructor, that no-op call through a function pointer would replace an "inline no-op" (i.e., nothing at all). Other minor costs include storage for that function pointer. Also there's the issue that this would cause a hard incompatibility with extension modules built against an earlier Boost.Python (their dynamic converters don't supply that destruction code). Did I mention I'm not making any heavy decisions while I'm on vacation? Why don't y'all discuss the tradeoffs here and decide whether it's worth it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From hans_meine at gmx.net Fri Jun 23 17:35:00 2006 From: hans_meine at gmx.net (Hans Meine) Date: Fri, 23 Jun 2006 17:35:00 +0200 Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: <44997B62.6825.E7172@s_sourceforge.nedprod.com> References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> <44997B62.6825.E7172@s_sourceforge.nedprod.com> Message-ID: <200606231735.02769.hans_meine@gmx.net> On Wednesday 21 June 2006 18:01, Niall Douglas wrote: > If, and only if, both Foo and Foo2 have constructors with no default > args, you can delay the constructor declaration and declare it later > via bp::init<>. Otherwise you are trapped and can't use bp::arg() at > all. That's not the whole truth. AFAICS, you can use no_init to delay constructor declaration in any case, create all class_<...> instantiations and then later add the methods. Maybe that helps? Ciao, / / /--/ / / ANS From roman.yakovenko at gmail.com Fri Jun 23 20:04:31 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 23 Jun 2006 21:04:31 +0300 Subject: [C++-sig] bp::arg() also requires types to be declared In-Reply-To: <200606231735.02769.hans_meine@gmx.net> References: <4498BA51.13536.3335777@s_sourceforge.nedprod.com> <44997B62.6825.E7172@s_sourceforge.nedprod.com> <200606231735.02769.hans_meine@gmx.net> Message-ID: <7465b6170606231104g14eb042fy3f57e99e322209d4@mail.gmail.com> On 6/23/06, Hans Meine wrote: > On Wednesday 21 June 2006 18:01, Niall Douglas wrote: > > If, and only if, both Foo and Foo2 have constructors with no default > > args, you can delay the constructor declaration and declare it later > > via bp::init<>. Otherwise you are trapped and can't use bp::arg() at > > all. > > That's not the whole truth. AFAICS, you can use no_init to delay constructor > declaration in any case, create all class_<...> instantiations and then later > add the methods. Maybe that helps? Thanks for idea. I am aware of this work around. Boost.Python contains functionality that helps to use such approach - def_visitor. I can change pyplusplus to generate code, that implements this idea. But right now it is too much work, that should be done + generated code will be less readable ( IMHO ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Jun 23 20:26:44 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 23 Jun 2006 21:26:44 +0300 Subject: [C++-sig] rvalue custom converters ( was Protected destructor compile error ) Message-ID: <7465b6170606231126o7d2e6543x7b577b16fa4a19a0@mail.gmail.com> On 6/23/06, Ralf W. Grosse-Kunstleve wrote: > Boost.Python also supports custom rvalue converters. See the FAQ for examples. > You'd need two different mechanisms for types that allow custom from_python > conversions (involving the construction and destruction of temporaries) and > those that don't. It seems that I can not find documentation about custom rvalue converters. How does this work? What happen if I register custom rvalue converter, for example for vector< MyClassX > and also class_< vector< MyClassX > > using indexing suite. Can you point me to the documentation? Thank you! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From abierbaum at gmail.com Fri Jun 23 20:29:28 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Fri, 23 Jun 2006 13:29:28 -0500 Subject: [C++-sig] Protected destructor compile error In-Reply-To: References: Message-ID: On 6/22/06, David Abrahams wrote: > "Allen Bierbaum" writes: > > > One additional question: Is there any metafunction (something like > > pointee<>) that could be specialized to tell boost.python that when > > it sees a const& of this type it should not assume that it can make > > a temporary? In effect some way to tell it to choose to use the > > path that the thin wrapper would use instead. > > > > If there isn't a metafunction like this, would it be difficult to > > nimplement something like this? > > I think the answer to both questions is no. It sounds like a > reasonable thing to do, though. > > > (if not, I am willing to work on it if you give me some direction on > > where to look and what to look for) To help with cases like mine, it > > would be nice to make the default version use type traits to detect > > if the type has a public destructor (and anything else it needs to > > make the temporary). > > It's not possible to detect that, unfortunately. It would not be possible to do in C++, but it would be possible to have a code generator like pyplusplus detect this case and automatically set some metafunction/flag/whatever to tell the system that it can't destruct the type so it should not allow creation of a temporary. Now that I think about my case it more detail I am starting to wonder if there is a problem with the API I a binding. For example the reason this method: bool Camera::calcViewRay (Line &line, Int32 x, Int32 y, const Viewport &port); is not working is because Viewport objects are only supposed to be handled using ViewportPtrs (custom ref-counted shared pointer). Since they are not handled this way in this case it causes these problems. This API would cause problems even in pure C++ code if someone passed in an object of another type that is implicitly convertible to a Viewport. If Viewport had a constructor that took an std::string for example and they tried to pass that in C++ would attempt to create a temporary behind the scenes and have the same problem at compile time. So I guess this is a case of valid (but possibly questionable) C++ that boost.python fails to wrap by default. (I should note that in my case the API does not allow implicit conversion to Viewport or any of the other types that have protected destructors. They are all created only by calling a static creation method that returns a smart ptr.) It is worth mentioning that the other methods where this is a problem in the current library I am binding are things like operator==(const&), operator<(const&), and operator!=(const&). > And _making_ the > temporary is a completely separate issue from destroying it. The part > of the converter that makes the temporary is looked up dynamically > based on the source Python type and in this case of course, nothing is > ever found. The fact that the destruction code is instantiated > unconditionally by the static part of the is really a sort of > optimization. > > The simplest way to make this work for everyone would be to make the > dynamic part of the converter responsible for destroying the > temporary. That would make your case work without the need for any > traits. However, there's a tradeoff; there would be an extra function > pointer indirection, at least. In the case of converting to a C++ > type with a trivial destructor, that no-op call through a function > pointer would replace an "inline no-op" (i.e., nothing at all). Other > minor costs include storage for that function pointer. > > Also there's the issue that this would cause a hard incompatibility > with extension modules built against an earlier Boost.Python (their > dynamic converters don't supply that destruction code). > > Did I mention I'm not making any heavy decisions while I'm on > vacation? Why don't y'all discuss the tradeoffs here and decide > whether it's worth it. Has anyone else ever ran into this problem? If not, then maybe it is not worth the effort and performance cost to try to fix generically. I could always just try to make some smart wrapper code with pyplusplus that automatically detects this case and creates a thin wrapper for me. (any ideas here Roman?) David: Thanks for replying while on vacation. I wouldn't even be reading my e-mail if I was on vacation. :) -Allen > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From roman.yakovenko at gmail.com Fri Jun 23 20:56:42 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 23 Jun 2006 21:56:42 +0300 Subject: [C++-sig] Protected destructor compile error In-Reply-To: References: Message-ID: <7465b6170606231156u79114a6dlf0dc06c6380ad093@mail.gmail.com> On 6/23/06, Allen Bierbaum wrote: > I could always just try to make some smart wrapper code with > pyplusplus that automatically detects this case and creates a thin > wrapper for me. (any ideas here Roman?) Actually yes. You have 2 ways to go: 1. Contribute to pyplusplus: 1. Add code to pyplusplus.decl_wrappers.calldef_t.has_wrapper. This code should "understand", that function takes an argument const reference to non-destructable object. 2. Add code that generates wrapper code to code_creators/calldef.py relevant classes. This is not should be very difficult. If you need more information, please ask on pyplusplus mailing list. 2. Easy and quick. Build custom small code generator, that will generate function wrapper, for every function, that takes as argument "const Viewport&". After this, exclude all original functions and replace them with new functions. This should work and it should take less then an hour to implement it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rwgk at yahoo.com Fri Jun 23 21:54:24 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 23 Jun 2006 12:54:24 -0700 (PDT) Subject: [C++-sig] rvalue custom converters ( was Protected destructor compile error ) In-Reply-To: <7465b6170606231126o7d2e6543x7b577b16fa4a19a0@mail.gmail.com> Message-ID: <20060623195424.73729.qmail@web31509.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > On 6/23/06, Ralf W. Grosse-Kunstleve wrote: > > Boost.Python also supports custom rvalue converters. See the FAQ for > examples. > > You'd need two different mechanisms for types that allow custom from_python > > conversions (involving the construction and destruction of temporaries) and > > those that don't. > > It seems that I can not find documentation about custom rvalue converters. > How does this work? What happen if I register custom rvalue converter, > for example for vector< MyClassX > and also class_< vector< MyClassX > > > using > indexing suite. > > Can you point me to the documentation? The info in the FAQ is all there is. A couple of times David mentioned that the mechanics could be simplified (and then formally documented), but it never happened. -- It doesn't seem all that important to me. I find the examples fully sufficient. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From roman.yakovenko at gmail.com Fri Jun 23 22:06:46 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 23 Jun 2006 23:06:46 +0300 Subject: [C++-sig] rvalue custom converters ( was Protected destructor compile error ) In-Reply-To: <20060623195424.73729.qmail@web31509.mail.mud.yahoo.com> References: <7465b6170606231126o7d2e6543x7b577b16fa4a19a0@mail.gmail.com> <20060623195424.73729.qmail@web31509.mail.mud.yahoo.com> Message-ID: <7465b6170606231306r642c299esec28696c58bc5804@mail.gmail.com> On 6/23/06, Ralf W. Grosse-Kunstleve wrote: > > How does this work? What happen if I register custom rvalue converter, > > for example for vector< MyClassX > and also class_< vector< MyClassX > > > > using > > indexing suite. > > > > Can you point me to the documentation? > > The info in the FAQ is all there is. A couple of times David mentioned that the > mechanics could be simplified (and then formally documented), but it never > happened. -- It doesn't seem all that important to me. I find the examples > fully sufficient. I will study the examples. I and Lakin Wecker work on Python bindings for Ogre. That library contains few classes like Matrix3 or Matrix4( Vector3, Vector4 ). Those classes have constructors from regular C++ arrays. It could be nice if we can create Python bindings, where user could pass Python list or tuple instead of [Matrix|Vector][3|4] as argument to functions. If I understand right, custom rvalue converters is the way to go, right? The only question I have is how it will work in presents of registration of [Matrix|Vector][3|4] classes? Thank you for your help. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Bruce_Sherwood at ncsu.edu Sat Jun 24 02:23:24 2006 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Fri, 23 Jun 2006 20:23:24 -0400 Subject: [C++-sig] VPython uses Boost Message-ID: <449C85FC.30202@ncsu.edu> VPython is an extension for Python to allow easy, "pythonic" 3D. It is used in education for various purposes, including teaching physics and programming, but it has also been used by research scientists to visualize systems or data in 3D. See vpython.org. VPython uses the Boost python and thread libraries. Bruce Sherwood From rwgk at yahoo.com Sat Jun 24 07:02:59 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 23 Jun 2006 22:02:59 -0700 (PDT) Subject: [C++-sig] rvalue custom converters ( was Protected destructor compile error ) In-Reply-To: <7465b6170606231306r642c299esec28696c58bc5804@mail.gmail.com> Message-ID: <20060624050259.97442.qmail@web31510.mail.mud.yahoo.com> --- Roman Yakovenko wrote: > I will study the examples. I and Lakin Wecker work on Python bindings for > Ogre. > That library contains few classes like Matrix3 or Matrix4( Vector3, Vector4 > ). > Those classes have constructors from regular C++ arrays. It could be nice if > we can create Python bindings, where user could pass Python list or > tuple instead > of [Matrix|Vector][3|4] as argument to functions. > > If I understand right, custom rvalue converters is the way to go, right? > The only question I have is how it will work in presents of registration of > [Matrix|Vector][3|4] classes? Situation 1 a: class_(...) .def(init()) // wrap the copy constructor ; Also define custom from_python converters converting Python sequences (e.g. list, tuple, iter) to matrix. This way any function expecting a matrix const& will also accept a Python sequence, including the copy constructor above. Situation 1 b: If you don't want all function to convert sequences on the fly (e.g. because you are afraid your users don't understand the impact on runtime performance), don't define the custom from_python converters. Instead of wrapping the copy constructor, use make_constructor to inject a constructor converting Python sequences. Situation 2: Define both custom to_python and from_python conversions, don't use class_. Examples: http://cctbx.cvs.sourceforge.net/cctbx/scitbx/include/scitbx/boost_python/container_conversions.h?view=markup Which enables, e.g.: tuple_mapping_fixed_size(); // situation 2 above http://cctbx.cvs.sourceforge.net/cctbx/scitbx/include/scitbx/stl/vector_wrapper.h?revision=1.4&view=markup This also uses container_conversions.h, but only to define from_python conversions. The copy constructor is wrapped. This is situation 1 a above. http://cctbx.cvs.sourceforge.net/cctbx/scitbx/array_family/boost_python/flex_double.cpp?revision=1.31&view=markup Look for from_list_or_tuple_of_lists_or_tuples() which is used with make_constructor. This is situation 1 b above. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From rwgk at yahoo.com Sat Jun 24 07:44:08 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 23 Jun 2006 22:44:08 -0700 (PDT) Subject: [C++-sig] boost/python 1.33.1 breaks aliasing rules Message-ID: <20060624054408.52339.qmail@web31507.mail.mud.yahoo.com> Coincidentally, on Python-Dev Scott David Daniels just suggested this trick to get rid of the "will break strict-aliasing rules" warnings: > PyObject_CallFunction((PyObject*) (void *) &PyRange_Type, > "lll", start, start+len*step, step) I.e. the trick is to insert an intermediate (void *) cast. It works with g++ 4.1.0 at least. Could this be a general solution? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From roman.yakovenko at gmail.com Sat Jun 24 12:41:05 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 24 Jun 2006 13:41:05 +0300 Subject: [C++-sig] rvalue custom converters ( was Protected destructor compile error ) In-Reply-To: <20060624050259.97442.qmail@web31510.mail.mud.yahoo.com> References: <7465b6170606231306r642c299esec28696c58bc5804@mail.gmail.com> <20060624050259.97442.qmail@web31510.mail.mud.yahoo.com> Message-ID: <7465b6170606240341w28f3aed2l5c242ae4e53f31f2@mail.gmail.com> On 6/24/06, Ralf W. Grosse-Kunstleve wrote: > ... Thank you very much! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boost-consulting.com Sat Jun 24 15:21:56 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 24 Jun 2006 09:21:56 -0400 Subject: [C++-sig] boost/python 1.33.1 breaks aliasing rules References: <20060624054408.52339.qmail@web31507.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > Coincidentally, on Python-Dev Scott David Daniels just suggested this trick to > get rid of the "will break strict-aliasing rules" warnings: > >> PyObject_CallFunction((PyObject*) (void *) &PyRange_Type, >> "lll", start, start+len*step, step) > > I.e. the trick is to insert an intermediate (void *) cast. It works with g++ > 4.1.0 at least. Could this be a general solution? There's no such thing as a general solution to a warning (they're implementation specific), and these "strict aliasing rules" are a C99 thing, and C++ is based on C89 (or C90, I forget which), and the code above does the so it's hard to say what should be done. Maybe reading http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html would help. -- Dave Abrahams Boost Consulting www.boost-consulting.com From abierbaum at gmail.com Sat Jun 24 16:10:47 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Sat, 24 Jun 2006 09:10:47 -0500 Subject: [C++-sig] Protected destructor compile error In-Reply-To: <7465b6170606231156u79114a6dlf0dc06c6380ad093@mail.gmail.com> References: <7465b6170606231156u79114a6dlf0dc06c6380ad093@mail.gmail.com> Message-ID: On 6/23/06, Roman Yakovenko wrote: > On 6/23/06, Allen Bierbaum wrote: > > I could always just try to make some smart wrapper code with > > pyplusplus that automatically detects this case and creates a thin > > wrapper for me. (any ideas here Roman?) > > Actually yes. You have 2 ways to go: > 1. Contribute to pyplusplus: > 1. Add code to pyplusplus.decl_wrappers.calldef_t.has_wrapper. > This code should > "understand", that function takes an argument const reference to > non-destructable object. > 2. Add code that generates wrapper code to > code_creators/calldef.py relevant > classes. > This is not should be very difficult. If you need more > information, please ask on > pyplusplus mailing list. Sounds interesting but I don't know that code nearly as well as you. :) > 2. Easy and quick. > Build custom small code generator, that will generate function > wrapper, for every > function, that takes as argument "const Viewport&". After this, exclude all > original functions and replace them with new functions. This > should work and it > should take less then an hour to implement it. This one sounds more approachable to me right now. The question I have though is how to add the function wrapper code to the generated code. Is this something I can do to the class decl wrapper? What method do I use to add it? (if you provide pseudo code I can fill in all the details and debug it) Thanks for the quick reply. -Allen > > -- > 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 ngoodspeed at solidworks.com Sat Jun 24 16:26:34 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Sat, 24 Jun 2006 10:26:34 -0400 Subject: [C++-sig] Publish a big C++ vector to Python Message-ID: I'm interested by the recent discussion about the new indexing suite: http://mail.python.org/pipermail/c++-sig/2006-June/010830.html I will soon want to be able to pass very large volumes of numeric data from C++ into a Python module. From the Python point of view, we can treat it as read-only. The C++ code internally uses std::vector, where each Vector3 object contains -- surprise -- double c[3]. We'd like to be able to export it to various different file formats. So I expect the Python code to have to make at least one pass over the data. But I want to avoid requiring the Python code to make an additional pass solely for the purpose of copying to another memory structure. If we must do that, we should do it on the C++ side beforehand. (Yes, the memory penalty is of some concern as well.) What approach would you recommend? I imagine a few different possibilities, none of which I've researched yet: 1. Use the existing indexing suite to publish std::vector, if it would suffice for our purposes. 2. Use the new indexing suite to publish std::vector. Perhaps fortunately, we're still using Boost 1.31. But it sounds as if there are other hurdles to jump? 3. Make a preliminary C++ pass to construct a Python array object containing doubles, three array entries per Vector3. (I don't yet know how to construct a Python 'array' of appropriate size in C++.) 4. Make a preliminary C++ pass to construct a NumPy array containing doubles, as above. (I don't yet know how to do that either.) 5. Abstract away the whole problem by publishing a little proxy class with access methods. (Could that possibly be as fast, within an order of magnitude? For our purposes, "fast enough" means that memory access time is still swamped by disk-write time.) 6. Other suggestions? We'll be adding this to a large existing hand-coded boost::python module, so -- although I'm intrigued -- converting to pyplusplus doesn't seem like the short path. Thanks for your suggestions! From roman.yakovenko at gmail.com Sat Jun 24 20:43:26 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 24 Jun 2006 21:43:26 +0300 Subject: [C++-sig] Protected destructor compile error In-Reply-To: References: <7465b6170606231156u79114a6dlf0dc06c6380ad093@mail.gmail.com> Message-ID: <7465b6170606241143l564a098av91273c1d05483aa2@mail.gmail.com> On 6/24/06, Allen Bierbaum wrote: > On 6/23/06, Roman Yakovenko wrote: > > On 6/23/06, Allen Bierbaum wrote: > > > I could always just try to make some smart wrapper code with > > > pyplusplus that automatically detects this case and creates a thin > > > wrapper for me. (any ideas here Roman?) > > > > Actually yes. You have 2 ways to go: > > 1. Contribute to pyplusplus: > > 1. Add code to pyplusplus.decl_wrappers.calldef_t.has_wrapper. > > This code should > > "understand", that function takes an argument const reference to > > non-destructable object. > > 2. Add code that generates wrapper code to > > code_creators/calldef.py relevant > > classes. > > This is not should be very difficult. If you need more > > information, please ask on > > pyplusplus mailing list. > > Sounds interesting but I don't know that code nearly as well as you. :) I will guide you :-). > > 2. Easy and quick. > > Build custom small code generator, that will generate function > > wrapper, for every > > function, that takes as argument "const Viewport&". After this, exclude all > > original functions and replace them with new functions. This > > should work and it > > should take less then an hour to implement it. > > This one sounds more approachable to me right now. The question I > have though is how to add the function wrapper code to the generated > code. Is this something I can do to the class decl wrapper? What > method do I use to add it? (if you provide pseudo code I can fill in > all the details and debug it) struct X{ void do_smth( const Viewport& ); }; wrapper_code_example = """ static void do_smth( X& x, Viewport& v){ x.do_smth( v ); }; """ mb = module_builder_t( ... ) for cls in mb.classes(): for f in cls.member_functions( function=contains const Viewport& as arg ) f.exclude() #Next code you will have to replace with something that actually deals with f cls.add_wrapper_code ( wrapper_code_example ) cls.add_code( 'def( "do_smth", &X_wrapper::do_smth )' ) cls.wrapper_alias will give you the name of the generated class wrapper name code_creators/calldef.py - calldef_wrapper_t.args_declaration will help you to get idea how to generate function wrapper code There is another approach. In this approach you don't generate code, but modify code creators tree. I can explain you if you are interested. > Thanks for the quick reply. My pleasure. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 24 21:01:51 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 24 Jun 2006 22:01:51 +0300 Subject: [C++-sig] Publish a big C++ vector to Python In-Reply-To: References: Message-ID: <7465b6170606241201i607e718flc58f7f4acbb2d381@mail.gmail.com> On 6/24/06, Nat Goodspeed wrote: > We'll be adding this to a large existing hand-coded boost::python > module, so -- although I'm intrigued -- converting to pyplusplus doesn't > seem like the short path. You never know: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1478&sid=c7b74a8f74f265dc204f30446a64dc0d 20 - 30 hours from start to working Python bindings. Almost zero knowledge in Boost.Python and sure zero knowledge in pyplusplus. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From gleizesd at gmail.com Mon Jun 26 09:58:53 2006 From: gleizesd at gmail.com (Damien Gleizes) Date: Mon, 26 Jun 2006 07:58:53 +0000 (UTC) Subject: [C++-sig] boost.python automatic policies Message-ID: Hello, I am currently using boost.Python for binding C++ code. In fact, I'am parsing a sort of container wich stores all classes I need to bind, including their methods and members (methods signatures, arguments types). While parsing these classes, I generates CPP files containing the binding code (wich uses boost.Python). The problem I'am confronted to concerns the use of policies. Is there a way to know wich policies to use without knowing what the function exactly do? Without policies the code does not compile, so I wonder if it is possible to know wich policies to use just with the decoration of arguments and return value (types, reference, pointer, const etc). Thanks for your suggestions! From roman.yakovenko at gmail.com Mon Jun 26 11:20:01 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 26 Jun 2006 12:20:01 +0300 Subject: [C++-sig] boost.python automatic policies In-Reply-To: References: Message-ID: <7465b6170606260220s4f2b1a60hd2db3bd73d1a4a24@mail.gmail.com> On 6/26/06, Damien Gleizes wrote: > Hello, > > I am currently using boost.Python for binding C++ code. In fact, I'am parsing a > sort of container wich stores all classes I need to bind, including their > methods and members (methods signatures, arguments types). While parsing these > classes, I generates CPP files containing the binding code (wich uses > boost.Python). The problem I'am confronted to concerns the use of policies. Is > there a way to know wich policies to use without knowing what the function > exactly do? Without policies the code does not compile, so I wonder if it is > possible to know wich policies to use just with the decoration of arguments and > return value (types, reference, pointer, const etc). The short answer is no. The long answer is here: http://www.boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies You can describe, what your function is doing, so it will be possible to suggest best call policies -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From markus.schoepflin at comsoft.de Mon Jun 26 11:29:40 2006 From: markus.schoepflin at comsoft.de (=?ISO-8859-1?Q?Markus_Sch=F6pflin?=) Date: Mon, 26 Jun 2006 11:29:40 +0200 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? Message-ID: Hello, I am wondering which version of gccxml is recommended for use with pyplusplus? Use of gccxml-0.6.0 is discouraged by the gccxml homepage, so are there any known-to-be-good CVS snapshot tar balls available? Thanks, Markus From gleizesd at gmail.com Mon Jun 26 11:45:04 2006 From: gleizesd at gmail.com (Damien Gleizes) Date: Mon, 26 Jun 2006 09:45:04 +0000 (UTC) Subject: [C++-sig] boost.python automatic policies References: <7465b6170606260220s4f2b1a60hd2db3bd73d1a4a24@mail.gmail.com> Message-ID: Yes it's confirm what I was thinking, I will try to do it differently. Thank you for your answer, I am now sure that what I wanted to do was in fact impossible! From roman.yakovenko at gmail.com Mon Jun 26 15:59:58 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 26 Jun 2006 16:59:58 +0300 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: References: Message-ID: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> On 6/26/06, Markus Sch?pflin wrote: > Hello, > > I am wondering which version of gccxml is recommended for use with > pyplusplus? Use of gccxml-0.6.0 is discouraged by the gccxml homepage, so > are there any known-to-be-good CVS snapshot tar balls available? > pygccxml works with latest/current version of gcc xml. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From markus.schoepflin at comsoft.de Mon Jun 26 16:14:50 2006 From: markus.schoepflin at comsoft.de (=?ISO-8859-1?Q?Markus_Sch=F6pflin?=) Date: Mon, 26 Jun 2006 16:14:50 +0200 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On 6/26/06, Markus Sch?pflin wrote: >> I am wondering which version of gccxml is recommended for use with >> pyplusplus? Use of gccxml-0.6.0 is discouraged by the gccxml homepage, so >> are there any known-to-be-good CVS snapshot tar balls available? >> > > pygccxml works with latest/current version of gcc xml. > I am sorry to insist, but would this be 0.6.0 or latest CVS? Markus From roman.yakovenko at gmail.com Mon Jun 26 19:36:45 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 26 Jun 2006 20:36:45 +0300 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> Message-ID: <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> On 6/26/06, Markus Sch?pflin wrote: > Roman Yakovenko wrote: > > On 6/26/06, Markus Sch?pflin wrote: > > >> I am wondering which version of gccxml is recommended for use with > >> pyplusplus? Use of gccxml-0.6.0 is discouraged by the gccxml homepage, so > >> are there any known-to-be-good CVS snapshot tar balls available? > >> > > > > pygccxml works with latest/current version of gcc xml. > > > > I am sorry to insist, but would this be 0.6.0 or latest CVS? Sorry, I was not clear - latest CVS version. I am subsribed to GCCXML commit mailing list, so pygccxml ( Subversion ) will always work with latest CVS version of GCCXML. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From kleistereimer at gmx.de Tue Jun 27 04:18:02 2006 From: kleistereimer at gmx.de (Kleistereimer) Date: Tue, 27 Jun 2006 02:18:02 +0000 Subject: [C++-sig] extending a c++ object by overriding it's virtual functions.. Message-ID: <44A0955A.8060008@gmx.de> hi! i've a question about virtual functions and boost::python. i use it with a boost c++ extended python which is embeeded in c++. i have a virtual function that's going to be overridden in Python and called polymorphically from C++. (so i'm not wrapping c++ for use from python) for instance i want to allow users of my software to override the virtual void Login::OnLog(std::string) function using python. that's what 'wrapper' and 'get_override' is used for, right? if i would use it in python only, overriding works without these stuff too. so i duplicated the example at http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations and it works fine inside python as advertised: >>> base.f() 0 >>> derived.f() 42 but for this i wont need 'wrapper' and 'get_override'. This works for any boost c++ extension. now for the interesting stuff: (ak the problem) after running the script i do: Base *b = new BaseWrap; int result = b->f(); delete b; now i would expect the result to be 42, but i got 0. ==================================================== so how to put 'wrapper' and 'get_override' to any use? my sollution is to obtain the PyObject* of 'derived' and to force it manualy into m_ptr of 'wrapper' using 'detail::initialize_wrapper' then 'get_override' worked as expected and i got 42. so i need to hardcode the name of the instantiated class ('derived') into the BaseWrap class to be able to initialize the wrapper with it if someone instantiated a c++ object and used f()... that's ugly but my understanding of 'virtual function that's going to be overridden in Python' is: write a c++ class and a corresponding derived class in python, and then use one or more instantiations of the c++ class without creating and maintaining python instances etc. or did i understood something completely wrong? regards kl From markus.schoepflin at comsoft.de Tue Jun 27 09:16:06 2006 From: markus.schoepflin at comsoft.de (=?ISO-8859-1?Q?Markus_Sch=F6pflin?=) Date: Tue, 27 Jun 2006 09:16:06 +0200 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On 6/26/06, Markus Sch?pflin wrote: ... >>> pygccxml works with latest/current version of gcc xml. >>> >> I am sorry to insist, but would this be 0.6.0 or latest CVS? > > Sorry, I was not clear - latest CVS version. I am subsribed to GCCXML > commit mailing > list, so pygccxml ( Subversion ) will always work with latest CVS > version of GCCXML. Thank you. Maybe you could add a little note to that effect to the documentation of pygccxml. And do you know of any tarballs of this being available? Markus From roman.yakovenko at gmail.com Tue Jun 27 09:25:25 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 27 Jun 2006 10:25:25 +0300 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> Message-ID: <7465b6170606270025o2a30510claee3bc5915a48a49@mail.gmail.com> On 6/27/06, Markus Sch?pflin wrote: > Thank you. Maybe you could add a little note to that effect to the > documentation of pygccxml. I will do that. > And do you know of any tarballs of this being available? > No, but if you follow instructions published here( http://gccxml.org/HTML/Download.html ) and here( http://gccxml.org/HTML/Install.html ) you will be able to setup it pretty quickly. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From markus.schoepflin at comsoft.de Tue Jun 27 09:35:31 2006 From: markus.schoepflin at comsoft.de (=?ISO-8859-1?Q?Markus_Sch=F6pflin?=) Date: Tue, 27 Jun 2006 09:35:31 +0200 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: <7465b6170606270025o2a30510claee3bc5915a48a49@mail.gmail.com> References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> <7465b6170606270025o2a30510claee3bc5915a48a49@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On 6/27/06, Markus Sch?pflin wrote: >> Thank you. Maybe you could add a little note to that effect to the >> documentation of pygccxml. > > I will do that. > >> And do you know of any tarballs of this being available? > > No, but if you follow instructions published here( > http://gccxml.org/HTML/Download.html ) > and here( http://gccxml.org/HTML/Install.html ) you will be able to > setup it pretty quickly. Yes, I did read these pages. The only problem is that I'm firewalled, therefore I was asking about the tarball. I will have to figure something out, then... Thanks for your help, Markus From Naceur.Meskini at sophia.inria.fr Tue Jun 27 11:56:29 2006 From: Naceur.Meskini at sophia.inria.fr (Naceur Meskini) Date: Tue, 27 Jun 2006 11:56:29 +0200 Subject: [C++-sig] KeyboardInterrupt with boost?! In-Reply-To: References: <7465b6170606260659u72855de7xbb37a6b0dfaca6b4@mail.gmail.com> Message-ID: <44A100CD.3020204@sophia.inria.fr> Hi every body, I have one question about how boost-python deal with Keyboard interrupting I have exposed a collection of functions and I would like to be able to interupt the execution of some of them in the python side. Thank you in advance. Naceur. INRIA Sophia Antipolis From s_sourceforge at nedprod.com Tue Jun 27 15:15:14 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 27 Jun 2006 14:15:14 +0100 Subject: [C++-sig] [pyplusplus] Which version of gccxml should I use? In-Reply-To: <7465b6170606261036u17bc4e0fk4c9c7156ce88f289@mail.gmail.com> References: Message-ID: <44A13D72.21808.4A2C86@s_sourceforge.nedprod.com> On 26 Jun 2006 at 20:36, Roman Yakovenko wrote: > > >> I am wondering which version of gccxml is recommended for use with > > >> pyplusplus? Use of gccxml-0.6.0 is discouraged by the gccxml homepage, so > > >> are there any known-to-be-good CVS snapshot tar balls available? > > >> > > > > > > pygccxml works with latest/current version of gcc xml. > > > > > > > I am sorry to insist, but would this be 0.6.0 or latest CVS? > > Sorry, I was not clear - latest CVS version. I am subsribed to GCCXML > commit mailing > list, so pygccxml ( Subversion ) will always work with latest CVS > version of GCCXML. It should be noted however that 0.6.0 works just fine for the majority of code. I'm still using it with TnFOX's python bindings. There are some bugs in the generated XML, but they can usually be ignored or if not, it's very easy to tell pyplusplus to fix the output code. Cheers, Niall From rwgk at yahoo.com Tue Jun 27 18:31:50 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 27 Jun 2006 09:31:50 -0700 (PDT) Subject: [C++-sig] KeyboardInterrupt with boost?! In-Reply-To: <44A100CD.3020204@sophia.inria.fr> Message-ID: <20060627163150.19467.qmail@web31506.mail.mud.yahoo.com> --- Naceur Meskini wrote: > I have one question about how boost-python deal with Keyboard interrupting > I have exposed a collection of functions and I would like to be able to > interupt the execution of some of them in the python side. I am not aware of an elegant way to handle this situation. If you find out please let us know. It is not a Boost.Python specific problem btw. All C/C++ extensions have the same problem. My solution is a very simple one: Almost all of our (very many) C++ functions typically return after a few seconds at the most, most in fractions of a second. Then Python gets a chance to handle the KeybordInterrupt. You don't have to do anything special. I.e. simply leave that outermost loop in Python if you can. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Tue Jun 27 19:42:46 2006 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 27 Jun 2006 13:42:46 -0400 Subject: [C++-sig] extending a c++ object by overriding it's virtual functions.. References: <44A0955A.8060008@gmx.de> Message-ID: Kleistereimer writes: > hi! > > i've a question about virtual functions and boost::python. > i use it with a boost c++ extended python which is embeeded in c++. > > i have a virtual function that's going to be overridden in Python and > called polymorphically from C++. (so i'm not wrapping c++ for use from > python) Huh? It sounds like that's exactly what you're doing. > for instance i want to allow users of my software to override the > virtual void Login::OnLog(std::string) function using python. > > > that's what 'wrapper' and 'get_override' is used for, right? Right. > if i would use it in python only, overriding works without these > stuff too. > > so i duplicated the example at > http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations > > and it works fine inside python as advertised: >>>> base.f() > 0 >>>> derived.f() > 42 > > but for this i wont need 'wrapper' and 'get_override'. This works for > any boost c++ extension. > now for the interesting stuff: (ak the problem) > > after running the script i do: > > Base *b = new BaseWrap; BaseWrap is purely for the use of the Python class Called Base, which is generated by class_. You shouldn't be using it directly. > int result = b->f(); > delete b; > > now i would expect the result to be 42, but i got 0. > ==================================================== You have no right to expect anything in particular from that. Of course that doesn't build a Python derived object. Just imagine you had several Python classes derived from the Python class called Base. Which one would it choose? > so how to put 'wrapper' and 'get_override' to any use? What you really seem to be asking is how do you construct an instance of derived (a class defined in Python) from C++. > my sollution is to obtain the PyObject* of 'derived' > and to force it manualy into m_ptr of 'wrapper' using > 'detail::initialize_wrapper' Stuff in detail namespaces is undocumented and not for user consumption. You shouldn't be using it directly. > then 'get_override' worked as expected and i got 42. // substitute the module name where "derived" is defined for "__main__" python::object module = python::import("__main__"); python::object derived = module.attr("derived"); python::object b = derived( /* arguments to __init__ here */ ); int result = b.f(); The import function is not documented for 1.33.1 but you can see it at http://boost-consulting.com/boost/libs/python/doc/v2/reference.html#embedding (otherwise you have to use the Python 'C' API to do something similar). [Joel, any chance of getting http://www.boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html updated with the facilities described in http://boost-consulting.com/boost/libs/python/doc/v2/reference.html#embedding?] HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From joel at boost-consulting.com Wed Jun 28 11:12:26 2006 From: joel at boost-consulting.com (Joel de Guzman) Date: Wed, 28 Jun 2006 17:12:26 +0800 Subject: [C++-sig] extending a c++ object by overriding it's virtual functions.. In-Reply-To: References: <44A0955A.8060008@gmx.de> Message-ID: <44A247FA.9070404@boost-consulting.com> David Abrahams wrote: > > [Joel, any chance of getting > http://www.boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html > updated with the facilities described in > http://boost-consulting.com/boost/libs/python/doc/v2/reference.html#embedding?] I added this in my TODO list. I'm neck deep with tasks to do though, so I'm not sure when I can get to this. I'd appreciate it if someone can do it ahead of me. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From kleistereimer at gmx.de Wed Jun 28 11:43:57 2006 From: kleistereimer at gmx.de (Kleistereimer) Date: Wed, 28 Jun 2006 09:43:57 +0000 Subject: [C++-sig] extending a c++ object by overriding it's virtual functions.. Message-ID: <44A24F5D.5010404@gmx.de> hi dave, thankyou for your explanations and sourcecode. i have some more questions about it thought. first here is the sourcecode again: //Python >>> class Derived(Base): ... def f(self): ... return 42 >>> base = Base() >>> derived = Derived() >>> base.f() 0 >>> derived.f() 42 //C++ code from your answer >1: // substitute the module name where "derived" is defined for "__main__" >2: python::object module = python::import("__main__"); >3: python::object derived = module.attr("derived"); >4: python::object b = derived( /* arguments to __init__ here */ ); >5: int result = b.f(); 1) the mentioned include file is not in boost 1.33.1. where can i get it? is it in cvs? does it suffice if i get this .hpp file only, or do i need the complete cvs version? for now i used the c api.. instead of this line. 2) what does the above code exactly? i think it instantiates a python 'Derived' class to object 'derived', so line 3 has to be: 3 python::object derived = module.attr("Derived"); //capital 'D' and at line 5 'f' is called on this instance. this gives me a compiler error: "f is no element of ..::api::object". how to solve this? i guess it involves something like: python::call_method(b.ptr(),"f") but this fails in arg_to_python.hpp:181 "cannot_convert_raw_PyObject::to_python_use_handle_instead();" how to do it corectly? 3) so this scheme is not 'overwriting c++ virtual functions with python code' directly, instead it's 'deriving a python class from a c++ class, overwriting virtual functions, and then making an instance of this python class and access it from c++' right? this means if i have some heavily used c++ class which needs only some minor functions tweakable from python, i should better do it like so: class py_MyClass: def Log(self): ... class MyClass { MyClass() {m_PyObject = Instantiate("py_MyClass");} //using line 3 and 4 ~MyClass() {delete m_PyObject;} ... ... void Log(std::string) {python::call_method(m_PyObject, "Log"); } }; because this calls into python only if one of the 'pythonized' functions is needed (which is seldom) but not if other c++ functions are used (which is extremely often) did i understood it right? regards kl From dave at boost-consulting.com Wed Jun 28 14:40:59 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 28 Jun 2006 08:40:59 -0400 Subject: [C++-sig] extending a c++ object by overriding it's virtual functions.. References: <44A24F5D.5010404@gmx.de> Message-ID: Kleistereimer writes: > hi dave, > > thankyou for your explanations and sourcecode. > > i have some more questions about it thought. > > > > first here is the sourcecode again: > > > //Python >>>> class Derived(Base): > ... def f(self): > ... return 42 >>>> base = Base() >>>> derived = Derived() >>>> base.f() > 0 >>>> derived.f() > 42 > > //C++ code from your answer >>1: // substitute the module name where "derived" is defined for "__main__" >>2: python::object module = python::import("__main__"); >>3: python::object derived = module.attr("derived"); >>4: python::object b = derived( /* arguments to __init__ here */ ); >>5: int result = b.f(); Whoops: int result = b.attrib("f")(); > 1) > the mentioned include file is not in boost > 1.33.1. where can i get it? is it in cvs? Yes. Get the RC_1_34_0 branch. > does it suffice if i get this > .hpp file only, or do i need the complete cvs version? I can't guarantee it works without the complete CVS > for now i used the c api.. instead of this line. > > 2) > what does the above code exactly? i think it instantiates a python > 'Derived' class to object 'derived', No, creates a reference to the Python class object called "derived." > so line 3 has to be: > 3 python::object derived = module.attr("Derived"); //capital 'D' Your post mixes case ["so i need to hardcode the name of the instantiated class ('derived')"] so I used lowercase, but if you define it as Derived, obviously, capitalize. > and at line 5 'f' is called on this instance. this gives me a compiler > error: > "f is no element of ..::api::object". how to solve this? > i guess it involves something like: > python::call_method(b.ptr(),"f") > but this fails in arg_to_python.hpp:181 > "cannot_convert_raw_PyObject::to_python_use_handle_instead();" > how to do it corectly? int result = b.attrib("f")(); > 3) > so this scheme is not 'overwriting c++ virtual functions with python I assume you mean "overriding" > code' directly, instead it's 'deriving a python class from a c++ class, > overwriting virtual functions, One can only override member functions by deriving in C++, so I don't see where your expectations for a more "direct" overriding could come from. > and then making an instance of this python class and access it from > c++' right? That's what you seemed to be wanting to do. > this means if i have some heavily used c++ class which needs only some > minor functions tweakable from python, i should better do it like so: > > > class py_MyClass: > def Log(self): > ... > > class MyClass > { > MyClass() {m_PyObject = Instantiate("py_MyClass");} //using line 3 and 4 > ~MyClass() {delete m_PyObject;} > ... > ... > void Log(std::string) {python::call_method(m_PyObject, "Log"); } > }; > > because this calls into python only if one of the 'pythonized' functions > is needed (which is seldom) but not if other c++ functions are used > (which is extremely often) > > > did i understood it right? Not really. If you want to use derived polymorphically from C++, you can also do this: python::object d = derived( /*args*/ ); Base& b = python::extract( d ); b.f(); Now only the functions you've made overridable in Python (e.g. f) will use any part of the Python API at all, and those that aren't actually overridden will only do a fast lookup, find nothing, and continue with C++ code, without interpreting any bytecode. -- Dave Abrahams Boost Consulting www.boost-consulting.com From austin.bingham at gmail.com Thu Jun 29 23:31:01 2006 From: austin.bingham at gmail.com (Austin Bingham) Date: Thu, 29 Jun 2006 16:31:01 -0500 Subject: [C++-sig] Another project using boost.python Message-ID: The boost.python website asks for submissions of projects using boost.python, so here's another one. pyxiph (http://sourceforge.net/projects/pyxiph) is a set of bindings to several of the xiph.org libraries (currently ao, ogg, and vorbis). Compared to python extensions I've written in the past using the standard C API, this was a breeze! I find the boost.python approach easier to reason with, easier to modify, much easier to get correct, and easier to explain. Count me as one happy customer. -- Austin Bingham "If I were creating the world I wouldn't mess about with butterflies and daffodils. I would have started with lasers, eight o'clock, Day One!" Evil From j.reid at mail.cryst.bbk.ac.uk Fri Jun 30 15:13:33 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 30 Jun 2006 14:13:33 +0100 Subject: [C++-sig] boost::python std::vector< std::string > crash In-Reply-To: References: <449AA3D1.1080805@boost-consulting.com> Message-ID: Ok this seems to be a crash in debug mode when I am picking up the release version of boost_python.dll in my path. How to make boost build v1 install boost_python.dll next to my extension? Or do I need to manually copy the correct (debug/release) version every time I want to debug or run the release version? I've tried adding @boost/libs/build/boost_python to my stage target to no avail. I have followed the 'Creating Packages' guidelines in the 'General Techniques' documentation but could not find any documentation on how to set up a build environment where I can alternate between debug and release builds easily. John. John Reid wrote: > > John Reid wrote: > >>Joel de Guzman wrote: >> >> >>>[snips] >>> >>>That's odd. I can't reproduce your results. To be sure, I added >>>your test in libs/python/test/vector_indexing_suite.cpp/py. >>>I'm getting no crash. Please check out the test suite and run it. >>> >>>Regards, >> >> > > I've investigated further. I wasn't aware of the correct way to run the > python tests. Now I've recompiled a clean version of boost cvs_head > everything works ok if I run the tests using 'bjam -sPYTHON_TEST_ARGS= > test' in the 'boost\libs\python\test' directory. > > What might be relevant is that if I run 'bjam' with no arguments, I can > generate 'vector_indexing_suite_ext.pyd' in the > 'boost\bin\boost\libs\python\test\vector_indexing_suite_ext.pyd\vc-8_0\debug\threading-multi' > directory. When I manually set PYTHONPATH to this directory and run > 'python vector_indexing_suite.py' I get the crash as before. Is this > expected, relevant and/or interesting? I would have thought this would > just have run that particular test. > > Any help appreciated as always. Thanks, > John.