From divinekid at gmail.com Tue Sep 1 06:19:20 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Tue, 1 Sep 2009 12:19:20 +0800 Subject: [C++-sig] [GSoC] Boost.Python py3k support project final report Message-ID: <3eb99a590908312119g7530e517m39870eaf059464ad@mail.gmail.com> Hi, As GSoC is officially finished, this is the final report of the Boost.Python py3k(Python 3) support project. The goal of this project is to provide seamless support for Python 2 and 3 in Boost.Python. So extension modules using Boost.Python can be easily migrated to Python 3. The SVN branch is located at: https://svn.boost.org/svn/boost/sandbox-branches/bhy/py3k/ Status ===== Currently, all the BPL test cases passed when running under Python 3, and there are almost no change for most of the test cases. To support the Python 3 unicode string, some of the default converts between PyString and C/C++ strings are changed to convert between PyUnicode and C/C++ strings. Support for py3k in Boost.Build is done. Also, a piece of document is written in the "News" part of BPL document. API Changes ========== There are some minor API changes: 1) Introduced object.contains where x.contains(y) is equivalent to Python code y in x. Now dict.has_key is just a wrapper of object.contains. 2) When building against Python 3, str.decode will be removed. 3) When building against Python 3, the original signature of list.sort, which is: void sort(object_cref cmpfunc); will change to: void sort(args_proxy const &args, kwds_proxy const &kwds); This is because in Python 3 list.sort requires all its arguments be keyword argument. So you should call it like this: x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true)))); // This is equivalent to the Python call x.sort(reverse=true) 4) When building Boost.Python against Python older than 2.6, the following macros will be defined in Boost.Python header: # define Py_TYPE(o) (((PyObject*)(o))->ob_type) # define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt) # define Py_SIZE(o) (((PyVarObject*)(o))->ob_size) These are macros defined in Python >=2.6 header. We defined for Python < 2.6 so when you are using Boost.Python, these macros will be always available. Please refer to PEP 3123 (http://www.python.org/dev/peps/pep-3123/) for details about these macro. Building and Testing =============== To build Boost.Python with Python 3, first write your user-config.jam contains these line: using python : 2.6 ; using python : 3.2 ; where the "2.6" and "3.2" should be replaced by the actual version of Python 2 and Python 3 on your system, respectively. Then call "bjam", it will build out a "libboost_python.so" and a "libboost_python3.so". The latter one is the Boost.Python library built against Python 3. To run test cases against Python 3, what you need to do is to switch into the libs/python/test, then run: bjam python=3.2 It will automatically call the "2to3" tool to convert the Python source code in test case to Python 3 syntax. So we only need to maintain the test cases in Python 2. Further Works =========== I'm going to merge the py3k branch back to trunk. After the merge, more tests can be done to check is there any regression, also some people may want to start to use it to make your projects run on Python 3. Then I can get some bug report and feedback, thus more improvement is expected. Thanks! -- Haoyu BAI School of Computing, National University of Singapore. From gjcarneiro at gmail.com Tue Sep 1 16:36:21 2009 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 1 Sep 2009 15:36:21 +0100 Subject: [C++-sig] ANN: PyBindGen 0.12 released Message-ID: PyBindGen is a Python module that is geared to generating C/C++ code that binds a C/C++ library for Python. It does so without extensive use of either C++ templates or C pre-processor macros. It has modular handling of C/C++ types, and can be easily extended with Python plugins. The generated code is almost as clean as what a human programmer would write. It can be downloaded from: http://code.google.com/p/pybindgen/ Bug reports should be filed here: https://bugs.launchpad.net/pybindgen === pybindgen 0.12 === - Now we can catch C++ exceptions and translate them into Python - New API to add container iteration powers to wrapped C++ classes - Unary minus operator support (J. Michael Owen) - CppMethod: is_pure_virtual=True should imply is_virtual=True - More polish for numeric operators with non-class right operand - Virtual methods regressions fixed - gccxmlparser: don't try to wrap private/protected operators - MSVC compilation fix - unsigned long type handlers (J. Michael Owen) - tp_len/__len__ works now with overloaded methods (J. Michael Owen) - Add foreign_cpp_namespace option to Function wrappers - Misc. cleanup and bug fixes -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From renatox at gmail.com Tue Sep 1 17:10:16 2009 From: renatox at gmail.com (Renato Araujo) Date: Tue, 1 Sep 2009 12:10:16 -0300 Subject: [C++-sig] [GSoC] Boost.Python py3k support project final report In-Reply-To: <3eb99a590908312119g7530e517m39870eaf059464ad@mail.gmail.com> References: <3eb99a590908312119g7530e517m39870eaf059464ad@mail.gmail.com> Message-ID: <95291a80909010810n67996b66pec14a690d73f703e@mail.gmail.com> Congratulations, I will wait for get this merged in mainline for start some work in PySide. Renato Araujo Oliveira Filho On Tue, Sep 1, 2009 at 1:19 AM, Haoyu Bai wrote: > Hi, > > As GSoC is officially finished, this is the final report of the > Boost.Python py3k(Python 3) support project. The goal of this project > is to provide seamless support for Python 2 and 3 in Boost.Python. So > extension modules using Boost.Python can be easily migrated to Python > 3. > > The SVN branch is located at: > https://svn.boost.org/svn/boost/sandbox-branches/bhy/py3k/ > > Status > ===== > > Currently, all the BPL test cases passed when running under Python 3, > and there are almost no change for most of the test cases. To support > the Python 3 unicode string, some of the default converts between > PyString and C/C++ strings are changed to convert between PyUnicode > and C/C++ strings. Support for py3k in Boost.Build is done. Also, a > piece of document is written in the "News" part of BPL document. > > > API Changes > ========== > > There are some minor API changes: > > 1) Introduced object.contains where x.contains(y) ?is equivalent to > Python code y in x. Now dict.has_key is just a wrapper of > object.contains. > > 2) When building against Python 3, str.decode will be removed. > > 3) When building against Python 3, the original signature of > list.sort, which is: > > ? ?void sort(object_cref cmpfunc); > > will change to: > > ? ?void sort(args_proxy const &args, kwds_proxy const &kwds); > > This is because in Python 3 list.sort requires all its arguments be > keyword argument. So you should call it like this: > > ? ?x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true)))); > // This is equivalent to the Python call x.sort(reverse=true) > > 4) When building Boost.Python against Python older than 2.6, the > following macros will be defined in Boost.Python header: > > ?# define Py_TYPE(o) ? ?(((PyObject*)(o))->ob_type) > ?# define Py_REFCNT(o) ?(((PyObject*)(o))->ob_refcnt) > ?# define Py_SIZE(o) ? ?(((PyVarObject*)(o))->ob_size) > > These are macros defined in Python >=2.6 header. We defined for Python > < 2.6 so when you are using Boost.Python, these macros will be always > available. Please refer to PEP 3123 > (http://www.python.org/dev/peps/pep-3123/) for details about these > macro. > > > Building and Testing > =============== > > To build Boost.Python with Python 3, first write your user-config.jam > contains these line: > > using python : 2.6 ; > using python : 3.2 ; > > where the "2.6" and "3.2" should be replaced by the actual version of > Python 2 and Python 3 on your system, respectively. > > Then call "bjam", it will build out a "libboost_python.so" and a > "libboost_python3.so". The latter one is the Boost.Python library > built against Python 3. > > To run test cases against Python 3, what you need to do is to switch > into the libs/python/test, then run: > > bjam python=3.2 > > It will automatically call the "2to3" tool to convert the Python > source code in test case to Python 3 syntax. So we only need to > maintain the test cases in Python 2. > > > Further Works > =========== > > I'm going to merge the py3k branch back to trunk. After the merge, > more tests can be done to check is there any regression, also some > people may want to start to use it to make your projects run on Python > 3. Then I can get some bug report and feedback, thus more improvement > is expected. > > > Thanks! > -- > Haoyu BAI > School of Computing, > National University of Singapore. > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From admin at lodle.net Wed Sep 2 02:51:22 2009 From: admin at lodle.net (Mark Chandler) Date: Wed, 2 Sep 2009 08:51:22 +0800 Subject: [C++-sig] python extended object to native c++ pointer In-Reply-To: <4A9BCC27.6020807@lodle.net> References: <4A9BB928.6000603@lodle.net> <4A9BC35E.8030908@sympatico.ca> <4A9BC8CC.50003@lodle.net> <4A9BCB7E.10802@sympatico.ca> <4A9BCC27.6020807@lodle.net> Message-ID: <228BABC2-C866-4D60-A791-C8ED33127BB3@lodle.net> I worked out what was causing it. I was using a diff dict for global and local thus locals couldnt see globals and globals couldnt see locals. Thanks for your help On 31/08/2009, at 9:12 PM, Mark Chandler wrote: > im using boost 1_36_0 as the latest has compile issues. > > im loading it via the boost call: > return boost::python::exec_file(file, GetGloablDict(), GetLocalDict > ()); > > where GetGloablDict is the main dict and GetLocalDict is a copy for > this instant > > Stefan Seefeld wrote: >> On 08/31/2009 08:57 AM, Mark Chandler wrote: >>> Stefan i spent sooooo long on this thank you! >>> >>> I got another quick question, how do i define the class in the >>> global namespace but still refer to it in functions? I want to do >>> something like this but keep getting compile errors. >> >> The script itself looks fine (apart from some indentation quirks, >> which may stem from your use of tabs). >> I seem to remember some issues with global and local namespaces in >> boost::python::exec(), which may relate to this. What version of >> boost are you using ? How do you call exec() from C++ ? >> >> Regards, >> Stefan >> >> > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From constant.dupuis at gmail.com Thu Sep 3 09:12:07 2009 From: constant.dupuis at gmail.com (Constant Dupuis) Date: Thu, 3 Sep 2009 09:12:07 +0200 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ Message-ID: Hi, I would like to expose a dictionary object instanciated in C++ to a Python code, which manipulate the dictoinary. And after extract the resulting modified dictionary back in C++. I try this : try { Py_Initialize(); std::cout << "Hello, World!\n"; dict d; d["Headline"] = "Titre"; object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); main_namespace["iptc"] = ptr(&d); object ignored = exec("print('Headline')\n" "print(iptc['Headline'])\n", main_namespace); } catch( error_already_set ) { PyErr_Print(); } And here is hte output : Hello, World! Headline Traceback (most recent call last): File "", line 2, in TypeError: 'NoneType' object is unsubscriptable What did I missed ? Thanks en regards, Constant From admin at lodle.net Thu Sep 3 09:22:47 2009 From: admin at lodle.net (Mark Chandler) Date: Thu, 3 Sep 2009 15:22:47 +0800 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: Message-ID: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> when you do the exec add the main_namespace twice > object ignored = exec("print('Headline')\n print(iptc['Headline']) > \n", main_namespace,main_namespace); On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: > Hi, > > I would like to expose a dictionary object instanciated in C++ to a > Python code, which manipulate the dictoinary. > And after extract the resulting modified dictionary back in C++. > > I try this : > > try { > > Py_Initialize(); > > std::cout << "Hello, World!\n"; > > dict d; > d["Headline"] = "Titre"; > > object main_module = import("__main__"); > object main_namespace = main_module.attr("__dict__"); > > main_namespace["iptc"] = ptr(&d); > > object ignored = exec("print('Headline')\n" > "print(iptc['Headline'])\n", > main_namespace); > > > } catch( error_already_set ) { > PyErr_Print(); > } > > And here is hte output : > > Hello, World! > Headline > Traceback (most recent call last): > File "", line 2, in > TypeError: 'NoneType' object is unsubscriptable > > What did I missed ? > > Thanks en regards, > > Constant > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From constant.dupuis at gmail.com Thu Sep 3 09:41:36 2009 From: constant.dupuis at gmail.com (Constant Dupuis) Date: Thu, 3 Sep 2009 09:41:36 +0200 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> References: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> Message-ID: Ok, thanks, Now I got a "Segmentation fault" error message when I try "print iptc['Headline']". Is the dict object directly exposable ? Or do I have to create a std::map base class ? Constant 2009/9/3 Mark Chandler : > when you do the exec add the main_namespace twice > >> object ignored = exec("print('Headline')\n print(iptc['Headline'])\n", >> main_namespace,main_namespace); > > > On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: > >> Hi, >> >> I would like to expose a dictionary object instanciated in C++ to a >> Python code, which manipulate the dictoinary. >> And after extract the resulting modified dictionary back in C++. >> >> I try this : >> >> try { >> >> ? Py_Initialize(); >> >> ? ? ? ?std::cout << "Hello, World!\n"; >> >> ? ? ? ?dict d; >> ? ? ? ?d["Headline"] = "Titre"; >> >> ? ? ? ?object main_module = import("__main__"); >> ? ? ? ?object main_namespace = main_module.attr("__dict__"); >> >> ? ? ? ?main_namespace["iptc"] = ptr(&d); >> >> ? ? ? ?object ignored = exec("print('Headline')\n" >> >> ?"print(iptc['Headline'])\n", >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?main_namespace); >> >> >> } catch( error_already_set ) { >> ? PyErr_Print(); >> } >> >> And here is hte output : >> >> Hello, World! >> Headline >> Traceback (most recent call last): >> ?File "", line 2, in >> TypeError: 'NoneType' object is unsubscriptable >> >> What did I missed ? >> >> Thanks en regards, >> >> Constant >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From admin at lodle.net Thu Sep 3 09:44:47 2009 From: admin at lodle.net (Mark Chandler) Date: Thu, 3 Sep 2009 15:44:47 +0800 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> Message-ID: Can you print iptc by it self? On 03/09/2009, at 3:41 PM, Constant Dupuis wrote: > Ok, thanks, > > Now I got a "Segmentation fault" error message when I try "print > iptc['Headline']". > > Is the dict object directly exposable ? Or do I have to create a > std::map base class ? > > Constant > > 2009/9/3 Mark Chandler : >> when you do the exec add the main_namespace twice >> >>> object ignored = exec("print('Headline')\n print(iptc['Headline']) >>> \n", >>> main_namespace,main_namespace); >> >> >> On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: >> >>> Hi, >>> >>> I would like to expose a dictionary object instanciated in C++ to a >>> Python code, which manipulate the dictoinary. >>> And after extract the resulting modified dictionary back in C++. >>> >>> I try this : >>> >>> try { >>> >>> Py_Initialize(); >>> >>> std::cout << "Hello, World!\n"; >>> >>> dict d; >>> d["Headline"] = "Titre"; >>> >>> object main_module = import("__main__"); >>> object main_namespace = main_module.attr("__dict__"); >>> >>> main_namespace["iptc"] = ptr(&d); >>> >>> object ignored = exec("print('Headline')\n" >>> >>> "print(iptc['Headline'])\n", >>> main_namespace); >>> >>> >>> } catch( error_already_set ) { >>> PyErr_Print(); >>> } >>> >>> And here is hte output : >>> >>> Hello, World! >>> Headline >>> Traceback (most recent call last): >>> File "", line 2, in >>> TypeError: 'NoneType' object is unsubscriptable >>> >>> What did I missed ? >>> >>> Thanks en regards, >>> >>> Constant >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From constant.dupuis at gmail.com Thu Sep 3 09:56:24 2009 From: constant.dupuis at gmail.com (Constant Dupuis) Date: Thu, 3 Sep 2009 09:56:24 +0200 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> Message-ID: nop, i got a Segmentation fault I forget to say that I'm on Mac, I don't knwo if this can change somethings. 2009/9/3 Mark Chandler : > Can you print iptc by it self? > > > > On 03/09/2009, at 3:41 PM, Constant Dupuis wrote: > >> Ok, thanks, >> >> Now I got a "Segmentation fault" error message when I try "print >> iptc['Headline']". >> >> Is the dict object directly exposable ? Or do I have to create a >> std::map base class ? >> >> Constant >> >> 2009/9/3 Mark Chandler : >>> >>> when you do the exec add the main_namespace twice >>> >>>> object ignored = exec("print('Headline')\n print(iptc['Headline'])\n", >>>> main_namespace,main_namespace); >>> >>> >>> On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: >>> >>>> Hi, >>>> >>>> I would like to expose a dictionary object instanciated in C++ to a >>>> Python code, which manipulate the dictoinary. >>>> And after extract the resulting modified dictionary back in C++. >>>> >>>> I try this : >>>> >>>> try { >>>> >>>> ?Py_Initialize(); >>>> >>>> ? ? ? std::cout << "Hello, World!\n"; >>>> >>>> ? ? ? dict d; >>>> ? ? ? d["Headline"] = "Titre"; >>>> >>>> ? ? ? object main_module = import("__main__"); >>>> ? ? ? object main_namespace = main_module.attr("__dict__"); >>>> >>>> ? ? ? main_namespace["iptc"] = ptr(&d); >>>> >>>> ? ? ? object ignored = exec("print('Headline')\n" >>>> >>>> ?"print(iptc['Headline'])\n", >>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? main_namespace); >>>> >>>> >>>> } catch( error_already_set ) { >>>> ?PyErr_Print(); >>>> } >>>> >>>> And here is hte output : >>>> >>>> Hello, World! >>>> Headline >>>> Traceback (most recent call last): >>>> ?File "", line 2, in >>>> TypeError: 'NoneType' object is unsubscriptable >>>> >>>> What did I missed ? >>>> >>>> Thanks en regards, >>>> >>>> Constant >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From constant.dupuis at gmail.com Thu Sep 3 10:01:25 2009 From: constant.dupuis at gmail.com (Constant Dupuis) Date: Thu, 3 Sep 2009 10:01:25 +0200 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> Message-ID: I try with the sample given here http://wiki.python.org/moin/boost.python/EmbeddingPython With a C++ Class and this works, so I guess something "wrong" with the c++ dict object .... 2009/9/3 Constant Dupuis : > nop, i got a Segmentation fault > > I forget to say that I'm on Mac, I don't knwo if this can change somethings. > > > 2009/9/3 Mark Chandler : >> Can you print iptc by it self? >> >> >> >> On 03/09/2009, at 3:41 PM, Constant Dupuis wrote: >> >>> Ok, thanks, >>> >>> Now I got a "Segmentation fault" error message when I try "print >>> iptc['Headline']". >>> >>> Is the dict object directly exposable ? Or do I have to create a >>> std::map base class ? >>> >>> Constant >>> >>> 2009/9/3 Mark Chandler : >>>> >>>> when you do the exec add the main_namespace twice >>>> >>>>> object ignored = exec("print('Headline')\n print(iptc['Headline'])\n", >>>>> main_namespace,main_namespace); >>>> >>>> >>>> On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: >>>> >>>>> Hi, >>>>> >>>>> I would like to expose a dictionary object instanciated in C++ to a >>>>> Python code, which manipulate the dictoinary. >>>>> And after extract the resulting modified dictionary back in C++. >>>>> >>>>> I try this : >>>>> >>>>> try { >>>>> >>>>> ?Py_Initialize(); >>>>> >>>>> ? ? ? std::cout << "Hello, World!\n"; >>>>> >>>>> ? ? ? dict d; >>>>> ? ? ? d["Headline"] = "Titre"; >>>>> >>>>> ? ? ? object main_module = import("__main__"); >>>>> ? ? ? object main_namespace = main_module.attr("__dict__"); >>>>> >>>>> ? ? ? main_namespace["iptc"] = ptr(&d); >>>>> >>>>> ? ? ? object ignored = exec("print('Headline')\n" >>>>> >>>>> ?"print(iptc['Headline'])\n", >>>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? main_namespace); >>>>> >>>>> >>>>> } catch( error_already_set ) { >>>>> ?PyErr_Print(); >>>>> } >>>>> >>>>> And here is hte output : >>>>> >>>>> Hello, World! >>>>> Headline >>>>> Traceback (most recent call last): >>>>> ?File "", line 2, in >>>>> TypeError: 'NoneType' object is unsubscriptable >>>>> >>>>> What did I missed ? >>>>> >>>>> Thanks en regards, >>>>> >>>>> Constant >>>>> _______________________________________________ >>>>> Cplusplus-sig mailing list >>>>> Cplusplus-sig at python.org >>>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > From constant.dupuis at gmail.com Thu Sep 3 13:40:50 2009 From: constant.dupuis at gmail.com (Constant Dupuis) Date: Thu, 3 Sep 2009 13:40:50 +0200 Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: <1D8C569E-0B06-4717-90CD-25D1B39E9F5E@lodle.net> Message-ID: Do you known an other way to do that ? 2009/9/3 Constant Dupuis : > I try with the sample given here > http://wiki.python.org/moin/boost.python/EmbeddingPython > > With a C++ Class and this works, so I guess something "wrong" with the > c++ dict object .... > > > > 2009/9/3 Constant Dupuis : >> nop, i got a Segmentation fault >> >> I forget to say that I'm on Mac, I don't knwo if this can change somethings. >> >> >> 2009/9/3 Mark Chandler : >>> Can you print iptc by it self? >>> >>> >>> >>> On 03/09/2009, at 3:41 PM, Constant Dupuis wrote: >>> >>>> Ok, thanks, >>>> >>>> Now I got a "Segmentation fault" error message when I try "print >>>> iptc['Headline']". >>>> >>>> Is the dict object directly exposable ? Or do I have to create a >>>> std::map base class ? >>>> >>>> Constant >>>> >>>> 2009/9/3 Mark Chandler : >>>>> >>>>> when you do the exec add the main_namespace twice >>>>> >>>>>> object ignored = exec("print('Headline')\n print(iptc['Headline'])\n", >>>>>> main_namespace,main_namespace); >>>>> >>>>> >>>>> On 03/09/2009, at 3:12 PM, Constant Dupuis wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I would like to expose a dictionary object instanciated in C++ to a >>>>>> Python code, which manipulate the dictoinary. >>>>>> And after extract the resulting modified dictionary back in C++. >>>>>> >>>>>> I try this : >>>>>> >>>>>> try { >>>>>> >>>>>> ?Py_Initialize(); >>>>>> >>>>>> ? ? ? std::cout << "Hello, World!\n"; >>>>>> >>>>>> ? ? ? dict d; >>>>>> ? ? ? d["Headline"] = "Titre"; >>>>>> >>>>>> ? ? ? object main_module = import("__main__"); >>>>>> ? ? ? object main_namespace = main_module.attr("__dict__"); >>>>>> >>>>>> ? ? ? main_namespace["iptc"] = ptr(&d); >>>>>> >>>>>> ? ? ? object ignored = exec("print('Headline')\n" >>>>>> >>>>>> ?"print(iptc['Headline'])\n", >>>>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? main_namespace); >>>>>> >>>>>> >>>>>> } catch( error_already_set ) { >>>>>> ?PyErr_Print(); >>>>>> } >>>>>> >>>>>> And here is hte output : >>>>>> >>>>>> Hello, World! >>>>>> Headline >>>>>> Traceback (most recent call last): >>>>>> ?File "", line 2, in >>>>>> TypeError: 'NoneType' object is unsubscriptable >>>>>> >>>>>> What did I missed ? >>>>>> >>>>>> Thanks en regards, >>>>>> >>>>>> Constant >>>>>> _______________________________________________ >>>>>> Cplusplus-sig mailing list >>>>>> Cplusplus-sig at python.org >>>>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>>>> >>>>> _______________________________________________ >>>>> Cplusplus-sig mailing list >>>>> Cplusplus-sig at python.org >>>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> > From iacobcatalin at gmail.com Thu Sep 3 14:59:50 2009 From: iacobcatalin at gmail.com (Catalin Iacob) Date: Thu, 3 Sep 2009 14:59:50 +0200 Subject: [C++-sig] Problem with combined Boost.Python, shared_ptr and enable_shared_from_this Message-ID: <6427f0390909030559q2b1cbd5m1962ade24978d05b@mail.gmail.com> Hello everybody, We're using Boost.Python to embed an interpreter for our application. We're having trouble with some code that I reduced to the following: -------------------------------------------------------------------- #include #include #include #include using namespace boost; using namespace boost::python; template bool are_equal_using_less(const T& x, const T& y) { return (!(x < y)) && (!(y < x)); } template void hold_python(shared_ptr& x) { x = extract >(object(x)); } class A : public enable_shared_from_this { public: shared_ptr get_shared_from_this() { return shared_from_this(); } }; int main() { Py_Initialize(); class_ >("A") .def("get_shared_from_this", &A::get_shared_from_this) ; shared_ptr a(new A); shared_ptr first_shared_from_this = a->get_shared_from_this(); if (are_equal_using_less(first_shared_from_this, a)) std::cout << "first_shared_from_this is equal to a - OK" << std::endl; else std::cout << "first_shared_from_this is NOT equal to a - BUG" << std::endl; hold_python(a); if (are_equal_using_less(first_shared_from_this, a)) std::cout << "first_shared_from_this is still equal to a" << std::endl; else std::cout << "now first_shared_from_this is not equal to a since a was changed by hold_python - OK I think" << std::endl; shared_ptr second_shared_from_this = a->get_shared_from_this(); if (are_equal_using_less(second_shared_from_this, a)) std::cout << "second_shared_from_this - OK" << std::endl; else std::cout << "we just called shared_from_this on a but we get back a shared_ptr object that is not equal to a - isn't this a BUG?" << std::endl; return 0; } -------------------------------------------------------------------- In both 1.39.0 and 1.40.0 the result is: first_shared_from_this is equal to a - OK now first_shared_from_this is not equal to a since a was changed by hold_python - OK I think we just called shared_from_this on a but we get back a shared_ptr object that is not equal to a - isn't this a BUG? While in 1.34.0 we get: first_shared_from_this is equal to a - OK now first_shared_from_this is not equal to a since a was changed by hold_python - OK I think second_shared_from_this - OK It probably doesn't matter but this is on Windows, with Visual Studio 2005 and Python 2.4. The hold_python function in the code above comes from combining ideas in 2 older threads on this list. At http://mail.python.org/pipermail/cplusplus-sig/2006-January/009671.html my colleague asks how to get a reference to the same Python object rather than having Boost.Python always create a new wrapper (if you read the discussion above notice that it is unfortunately split in 2 threads). One of the answers references a message by David Abrahams here http://mail.python.org/pipermail/cplusplus-sig/2005-April/008537.html. So my colleague chose to call hold_python after the allocation of the object, just like shared_ptr a(new A); hold_python(a) in the example above. This worked for us until upgrading from 1.34 to 1.39. It could very well be that the problem is on our side not in Boost but given that Boost.Python is quite esoteric any help from somebody who has more insight into it is very valuable. Thank you, Catalin From rwgk at yahoo.com Thu Sep 3 19:04:42 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 3 Sep 2009 10:04:42 -0700 (PDT) Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ In-Reply-To: References: Message-ID: <625020.46336.qm@web111401.mail.gq1.yahoo.com> Hi, I'm not sure this is relevant (sorry, no time to look closely), but a couple weeks ago I fixed a bug in exec.cpp: ------------------------------------------------------------------------ r55639 | rwgk | 2009-08-17 17:24:54 -0700 (Mon, 17 Aug 2009) | 8 lines libs/python/src/exec.cpp: bug fixes Remark: operator!() for boost::python::object invokes PyObject_IsTrue() and is therefore not equivalent to "is None". In this particular case !global or !local returns true for an empty dict. (Changes to libs/python/test/exec.cpp just helped in debugging.) ------------------------------------------------------------------------ This made it into the 1.40.0 release. I recommend you work with the current trunk or the latest release. Ralf ----- Original Message ---- From: Constant Dupuis To: cplusplus-sig at python.org Sent: Thursday, September 3, 2009 12:12:07 AM Subject: [C++-sig] Embending : Expose and Extract a dictionary object To/From C++ Hi, I would like to expose a dictionary object instanciated in C++ to a Python code, which manipulate the dictoinary. And after extract the resulting modified dictionary back in C++. I try this : try { Py_Initialize(); std::cout << "Hello, World!\n"; dict d; d["Headline"] = "Titre"; object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); main_namespace["iptc"] = ptr(&d); object ignored = exec("print('Headline')\n" "print(iptc['Headline'])\n", main_namespace); } catch( error_already_set ) { PyErr_Print(); } And here is hte output : Hello, World! Headline Traceback (most recent call last): File "", line 2, in TypeError: 'NoneType' object is unsubscriptable What did I missed ? Thanks en regards, Constant _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From freyr.magnusson at gmail.com Mon Sep 7 01:25:45 2009 From: freyr.magnusson at gmail.com (=?ISO-8859-1?Q?Freyr_Magn=FAsson?=) Date: Sun, 6 Sep 2009 23:25:45 +0000 Subject: [C++-sig] get_overload raising cannot convert from 'boost::python::detail::method_result' to 'MMOT::Geometry &' Message-ID: <1e08064e0909061625t7ad4fb0fp99fc7fb150c66852@mail.gmail.com> I trying to create an interface wrapper for a class and I get an error: cannot convert from 'boost::python::detail::method_result' to 'MMOT::Geometry &' The code is like this: struct SelectQueryWrap : SelectQuery, wrapper { bool queryNodeBefore(QueryContext* context, OctreeNode *node, const AABBox& region) { return this->get_override("queryNodeBefore")(context, node, region); } // removed working members // >>>>>>>>>>>>>>>>>>>>> this failes <<<<<<<<<<<<<<<<<<< Geometry& getGeometry() { return this->get_override("getGeometry")(); } }; Geometry is another wrapped interface which is working fine and is defined like so: struct GeometryWrap : Geometry, wrapper { int intersectNode(const MMOT::AABBox &box) { return this->get_override("intersectNode")(box); } float volume() const { return this->get_override("volume")(); } void prepare() { if (override prepare = this->get_override("prepare")) prepare(); else Geometry::prepare(); } void default_prepare() { this->Geometry::prepare(); } }; I'm a bit lost here. Can't I return a reference to the object or is my wrapping getting too convoluted (well something is wrong anyway)? Any help appreciated. Freyr -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Mon Sep 7 06:41:08 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 07 Sep 2009 00:41:08 -0400 Subject: [C++-sig] get_overload raising cannot convert from 'boost::python::detail::method_result' to 'MMOT::Geometry &' In-Reply-To: <1e08064e0909061625t7ad4fb0fp99fc7fb150c66852@mail.gmail.com> References: <1e08064e0909061625t7ad4fb0fp99fc7fb150c66852@mail.gmail.com> Message-ID: <4AA48EE4.2020707@resophonic.com> Freyr Magn?sson wrote: > I trying to create an interface wrapper for a class and I get an error: > > cannot convert from 'boost::python::detail::method_result' to > 'MMOT::Geometry &' > Checking the code, I see method_result has a workaround for the conversion-operator-to-reference: class method_result { // ... # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) || BOOST_WORKAROUND(BOOST_INTEL_WIN, >= 900) // No operator T& # else template operator T&() const { converter::return_from_python converter; return converter(const_cast&>(m_obj).release()); } # endif }; If this is why this: > Geometry& getGeometry() > { > return this->get_override("getGeometry")(); > } Doesn't work (I don't know what that workaround means offhand but I'm going to guess it refers to old MSVC platforms), you could try Geometry* result = this->get_override("getGeometry")(); return *result; So... what compiler are you using? -t From freyr.magnusson at gmail.com Mon Sep 7 10:20:21 2009 From: freyr.magnusson at gmail.com (=?ISO-8859-1?Q?Freyr_Magn=FAsson?=) Date: Mon, 7 Sep 2009 08:20:21 +0000 Subject: [C++-sig] get_overload raising cannot convert from 'boost::python::detail::method_result' to 'MMOT::Geometry &' In-Reply-To: <4AA48EE4.2020707@resophonic.com> References: <1e08064e0909061625t7ad4fb0fp99fc7fb150c66852@mail.gmail.com> <4AA48EE4.2020707@resophonic.com> Message-ID: <1e08064e0909070120u51838bb5ye6374d745d047d53@mail.gmail.com> I'm using mscv8 from vs2005. I'll test your solutuion when I get the chance later today. Thanks, Freyr On Mon, Sep 7, 2009 at 4:41 AM, troy d. straszheim wrote: > Freyr Magn?sson wrote: > >> I trying to create an interface wrapper for a class and I get an error: >> >> cannot convert from 'boost::python::detail::method_result' to >> 'MMOT::Geometry &' >> >> > Checking the code, I see method_result has a workaround for the > conversion-operator-to-reference: > > class method_result { > // ... > # if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) || > BOOST_WORKAROUND(BOOST_INTEL_WIN, >= 900) > // No operator T& > # else > > template > operator T&() const > { > converter::return_from_python converter; > return converter(const_cast&>(m_obj).release()); > } > # endif > }; > > If this is why this: > > Geometry& getGeometry() >> { >> return this->get_override("getGeometry")(); >> } >> > > Doesn't work (I don't know what that workaround means offhand but I'm going > to guess it refers to old MSVC platforms), you could try > > Geometry* result = this->get_override("getGeometry")(); > return *result; > > So... what compiler are you using? > > -t > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From amruta.rs at gmail.com Mon Sep 7 11:21:07 2009 From: amruta.rs at gmail.com (Amruta Chaudhari) Date: Mon, 7 Sep 2009 14:51:07 +0530 Subject: [C++-sig] Your confirmation is required to join the Cplusplus-sig mailing list In-Reply-To: References: Message-ID: cplusplus-sig-confirm+36e1dc99c23a2f349b7576eb72ee1e88429813a6 at python.org On Mon, Sep 7, 2009 at 2:40 PM, < cplusplus-sig-confirm+36e1dc99c23a2f349b7576eb72ee1e88429813a6 at python.org > wrote: > Mailing list subscription confirmation notice for mailing list > Cplusplus-sig > > We have received a request from 125.18.59.225 for subscription of your > email address, "amruta.rs at gmail.com", to the cplusplus-sig at python.org > mailing list. To confirm that you want to be added to this mailing > list, simply reply to this message, keeping the Subject: header > intact. Or visit this web page: > > > http://mail.python.org/mailman/confirm/cplusplus-sig/36e1dc99c23a2f349b7576eb72ee1e88429813a6 > > > Or include the following line -- and only the following line -- in a > message to cplusplus-sig-request at python.org: > > confirm 36e1dc99c23a2f349b7576eb72ee1e88429813a6 > > Note that simply sending a `reply' to this message should work from > most mail readers, since that usually leaves the Subject: line in the > right form (additional "Re:" text in the Subject: is okay). > > If you do not wish to be subscribed to this list, please simply > disregard this message. If you think you are being maliciously > subscribed to the list, or have any other questions, send them to > cplusplus-sig-owner at python.org. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jean-sebastien.guay at cm-labs.com Tue Sep 8 05:10:11 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Mon, 07 Sep 2009 23:10:11 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing Message-ID: <4AA5CB13.40506@cm-labs.com> Hi all, Thanks to previous help (a while ago) I was able to make considerable progress wrapping a pretty complex library (OpenSceneGraph) with boost.python. I've been working on this a bit more lately in my free time, and I've been able to wrap pretty much everything I wanted to. It's starting to look really good. But I've got a problem overriding classes with python code. The overridden method gets called, but when (from python code) it calls some other C++ method using the arguments it was given, the arguments are sliced to the base type. I'll give some example code, but unfortunately I have to give a lot for it to make sense... Sorry about that. The definitions below are just for context: class osg::Node { public: //... // does nothing in base class virtual void traverse(NodeVisitor& nv) {} // ... }; class osg::Group { public: //... // overridden to traverse children virtual void traverse(NodeVisitor& nv) {...} // ... }; class osg::NodeVisitor { public: // ... virtual void apply(osg::Node& node) { traverse(node); } virtual void apply(osg::Group& node) { apply(static_cast(node); } // ... versions for other subclasses of osg::Node and osg::Group inline void traverse(osg::Node& node) { // ... node.traverse(*this); } // ... } This is a classic visitor double-dispatch implementation, which in C++ is used like this: class DerivedVisitor : public osg::NodeVisitor { public: DerivedVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} // Override the version of apply you want to do the work. void apply(osg::Node& node) { // ... Do something // method must call traverse(node) to continue traversal. traverse(node); } }; main() { osg::Group* g1 = new osg::Group; g1->setName("g1"); osg::Group* g2 = new osg::Group; g2->setName("g2"); g1->addChild(g2); osg::Node* n = new osg::Node; n->setName("n"); g2->addChild(n); DerivedVisitor v; g1->accept(v); } This will call apply(osg::Node&) 3 times, because the first two times, traverse(node) will call osg::Group's version of traverse(NodeVisitor&) which traverses its children. (note that NodeVisitor's default implementation of apply(Group&) is to call apply(Node&) and the same for all other subclasses which call their parent class's apply() ) Now, the problem I'm having with this in boost.python is that apply_Node (which is the name I've given my wrapped apply(Node&) so that python knows which version to call) is being called only once (at the parent-most node). So it seems that it's osg::Node's version of traverse(NodeVisitor&) that's being called since it's not traversing to its children. I've got another example of this with NodeCallback, where a method traverse(Node*) should traverse to its children, but it doesn't and I can see that because if it did, a certain 3D model would get drawn to the screen, but it doesn't (and it does if I remove my python-overridden NodeCallback). My wrapper code is mostly based on the example here: http://wiki.python.org/moin/boost.python/OverridableVirtualFunctions struct NodeVisitor_wrapper : public NodeVisitor { // NodeVisitor constructors storing initial self parameter NodeVisitor_wrapper(PyObject *p, NodeVisitor::TraversalMode tm = NodeVisitor::TRAVERSE_NONE) : NodeVisitor(tm), self(p) {} NodeVisitor_wrapper(PyObject *p, NodeVisitor::VisitorType type, NodeVisitor::TraversalMode tm = NodeVisitor::TRAVERSE_NONE) : NodeVisitor(type, tm), self(p) {} // In case NodeVisitor is returned by-value from a wrapped function NodeVisitor_wrapper(PyObject *p, const NodeVisitor& x) : NodeVisitor(x), self(p) {} // Override apply to call back into Python void apply(Node& node) { //std::cout << "in apply(Node&)" << std::endl; try { //std::cout << "Calling override" << std::endl; call_method(self, "apply_Node", node); } // Catch boost::python exception, means method was not // overridden in subclass. catch (error_already_set) { NodeVisitor::apply(node); } } // Supplies the default implementation of apply void default_apply_Node(NodeVisitor& self_, Node& node) { //std::cout << "in default_apply(Node&)" << std::endl; self_.NodeVisitor::apply(node); } // Override apply to call back into Python void apply(Group& node) { //std::cout << "in apply(Group&)" << std::endl; try { //std::cout << "Calling override" << std::endl; call_method(self, "apply_Group", node); } // Catch boost::python exception, means method was not // overridden in subclass. catch (error_already_set) { NodeVisitor::apply(node); } } // Supplies the default implementation of apply void default_apply_Group(NodeVisitor& self_, Group& node) { //std::cout << "in default_apply(Group&)" << std::endl; self_.NodeVisitor::apply(node); } private: PyObject* self; }; BOOST_PYTHON_MODULE(_osg) { // ... { scope in_NodeVisitor = class_, ref_ptr > ("NodeVisitor") .def(init()) .def(init()) .def("traverse", &NodeVisitor::traverse) .def("apply_Node", &NodeVisitor_wrapper::default_apply_Node) .def("apply_Group", &NodeVisitor_wrapper::default_apply_Group) .add_property("traversalMode", &NodeVisitor::getTraversalMode, &NodeVisitor::setTraversalMode) ; enum_("TraversalMode") .value("TRAVERSE_NONE", NodeVisitor::TRAVERSE_NONE) .value("TRAVERSE_PARENTS", NodeVisitor::TRAVERSE_PARENTS) .value("TRAVERSE_ALL_CHILDREN", NodeVisitor::TRAVERSE_ALL_CHILDREN) .value("TRAVERSE_ACTIVE_CHILDREN", NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) ; enum_("VisitorType") .value("NODE_VISITOR", NodeVisitor::NODE_VISITOR) .value("UPDATE_VISITOR", NodeVisitor::UPDATE_VISITOR) .value("EVENT_VISITOR", NodeVisitor::EVENT_VISITOR) .value("COLLECT_OCCLUDER_VISITOR", NodeVisitor::COLLECT_OCCLUDER_VISITOR) .value("CULL_VISITOR", NodeVisitor::CULL_VISITOR) ; } // ... } Note a few things about this: 1. I couldn't use the method for wrapping a class which you want to override in python code that's given here: http://www.boost.org/doc/libs/1_40_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions because I would always get crashes at the get_override() line. But the above technique works well (apart from the slicing problem). I'm using boost 1.35 if that helps explain that. 2. I'm using try { ... } catch (error_already_set) { ... } because in the library, all the virtual methods are optional to override. call_method() bombs if my python subclass didn't have the method overridden, so that's the way I found to make that work. If there's a better way (perhaps to check if the method was indeed overridden or not in the subclass, which is that the get_override() line I referred to above does I know) please let me know. Finally, my python code is: class DerivedVisitor(osg.NodeVisitor): def __init__(self): # call parent class constructor with argument, as in C++ osg.NodeVisitor.__init__(self, osg.NodeVisitor.TraversalMode.TRAVERSE_ALL_CHILDREN) def apply_Node(self, node): print "python apply_Node - node name:", node.name # call traverse(node) as in C++ to continue traversal. self.traverse(node) g1 = osg.Group() g1.name = "g1" g2 = osg.Group() g2.name = "g2" g1.addChild(g2) n = osg.Node() n.name = "n" g2.addChild(n) nv = DerivedVisitor() g1.accept(nv) Note that the code is quasi-identical to the C++ version, right down to the need to call the base class constructor with the right traversal mode. That's what I want. Now, if I provide overridden versions of both apply_Node() and apply_Group(), I get correct results, but not when I only override apply_Node(). So it would seem the slicing happens when call_method calls that method with the osg::Node& argument. Considering when I override osg::NodeVisitor in C++ (and only override apply(Node&) ) it works as it should, why does the boost.python version slice off the derived parts of objects? I can see nowhere where objects are passed by value, so (IIRC) no slicing should occur... In fact, no pass-by-value could occur, because all osg::Referenced subclasses (which includes osg::Node and osg::Group) have protected destructors so they can't be constructed on the stack. If it helps, here's the top part of my osg::Node and osg::Group wrappers: using namespace osg; namespace boost { namespace python { template struct pointee< ref_ptr > { typedef T type; }; } } BOOST_PYTHON_MODULE(_osg) // repeated just for context { class_ >("Referenced") ; { scope in_Object = class_, ref_ptr, boost::noncopyable >("Object", no_init) // ... ; // ... } { scope in_Node = class_, ref_ptr >("Node") // ... ; // ... } class_, ref_ptr >("Group") // ... ; } All this (in theory) works, in the sense that I can make hierarchies of nodes, groups, geodes, geometry, etc. all in Python code, also assign textures, start a viewer to see all that, etc. Apart from another related problem (which I'll start a separate thread to get help for) this is the only part that's giving me problems for now. Any help would be appreciated. Sorry for the length of this message, I wanted to be thorough so the problem would be clear (and perhaps the solution easy to see?). I hope it's not something too simple though, or I'll have wasted a lot of time and a lot of your time too... Thanks in advance, J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From troy at resophonic.com Tue Sep 8 12:19:00 2009 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 08 Sep 2009 06:19:00 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA5CB13.40506@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> Message-ID: <4AA62F94.90100@resophonic.com> Jean-S?bastien Guay wrote: > Hi all, > > Thanks to previous help (a while ago) I was able to make considerable > progress wrapping a pretty complex library (OpenSceneGraph) with > boost.python. Hey Jean-Sebatien, I've been doing a bunch of work with osg recently. I like it and badly miss some boost.python bindings. I'd be very interested to have a look at the code here, maybe pitch in a bit. Is there a git archive I can clone, and a failing test I can run? > But I've got a problem overriding classes with python code. [snip lots of code] -t From meine at informatik.uni-hamburg.de Mon Sep 7 16:13:17 2009 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 7 Sep 2009 16:13:17 +0200 Subject: [C++-sig] Trouble optimizing Boost.python integration In-Reply-To: <4A945C12.2020406@gmail.com> References: <4A945C12.2020406@gmail.com> Message-ID: <200909071613.17415.meine@informatik.uni-hamburg.de> On Tuesday 25 August 2009 23:48:02 Dan Sanduleac wrote: > The thing is, it proves to be kind of slow compared to Cython/Pyrex code > that does the same. I think it should run faster than Cython code. I think this is because your vectors are too small. I think for such small objects, the implementation of vector operations is much faster than the overhead of BPL's argument/return type conversion, and the latter accounts for the slowdown. HTH, Hans From gjcarneiro at gmail.com Tue Sep 8 16:51:14 2009 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 8 Sep 2009 15:51:14 +0100 Subject: [C++-sig] Trouble optimizing Boost.python integration In-Reply-To: <4A945C12.2020406@gmail.com> References: <4A945C12.2020406@gmail.com> Message-ID: 2009/8/25 Dan Sanduleac > Hi, > > I'm trying to compare different python-C wrapping techniques to see which > would be faster and also more suited to game development. > If your project does not use multiple inheritance, I may suggest you also try with PyBindGen: http://code.google.com/p/pybindgen/ Yes, me being the pybindgen author, I am biased, but still... I am curious to comparisons of pybindgen performance to other python wrapping tools. Regards, -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Tue Sep 8 17:00:24 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 08 Sep 2009 11:00:24 -0400 Subject: [C++-sig] Trouble optimizing Boost.python integration In-Reply-To: References: <4A945C12.2020406@gmail.com> Message-ID: <4AA67188.4010107@sympatico.ca> On 09/08/2009 10:51 AM, Gustavo Carneiro wrote: > 2009/8/25 Dan Sanduleac > > > Hi, > > I'm trying to compare different python-C wrapping techniques to > see which would be faster and also more suited to game development. > > > If your project does not use multiple inheritance, I may suggest you > also try with PyBindGen: http://code.google.com/p/pybindgen/ > > Yes, me being the pybindgen author, I am biased, but still... I am > curious to comparisons of pybindgen performance to other python > wrapping tools. That's a strange line of argument. Didn't the original poster ask for advice ? It's your turn to do your homework and show why using PyBindGen is the better choice, instead of inviting people to use it and report back to you whether it was any good. :-) Stefan -- ...ich hab' noch einen Koffer in Berlin... From gjcarneiro at gmail.com Tue Sep 8 17:20:51 2009 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 8 Sep 2009 16:20:51 +0100 Subject: [C++-sig] Trouble optimizing Boost.python integration In-Reply-To: <4AA67188.4010107@sympatico.ca> References: <4A945C12.2020406@gmail.com> <4AA67188.4010107@sympatico.ca> Message-ID: 2009/9/8 Stefan Seefeld > On 09/08/2009 10:51 AM, Gustavo Carneiro wrote: > >> 2009/8/25 Dan Sanduleac > sanduleac.dan at gmail.com>> >> >> Hi, >> >> I'm trying to compare different python-C wrapping techniques to >> see which would be faster and also more suited to game development. >> >> >> If your project does not use multiple inheritance, I may suggest you also >> try with PyBindGen: http://code.google.com/p/pybindgen/ >> >> Yes, me being the pybindgen author, I am biased, but still... I am >> curious to comparisons of pybindgen performance to other python wrapping >> tools. >> > > That's a strange line of argument. Didn't the original poster ask for > advice ? It's your turn to do your homework and show why using PyBindGen is > the better choice, instead of inviting people to use it and report back to > you whether it was any good. > Hm.. but each person knows best the environment they work for. It would be presumptuous of me to tell him pybindgen is the better choice. I don't have the full benchmarking setup, but here's how to wrap that example (attached). I had to add a default Vec3 constructor, since pybindgen does not like very much classes without default constructors. You generate the module with: python vec3-gen.py > vec3module.cc Compile with something like: g++ -O2 -fPIC -shared -I /usr/include/python2.6 vec3module.cc vec3.cpp -o vec3.so As for the benchmarking stuff, I leave to the original poster. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: vec3-gen.py Type: text/x-python Size: 573 bytes Desc: not available URL: From jean-sebastien.guay at cm-labs.com Tue Sep 8 20:31:57 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 14:31:57 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA62F94.90100@resophonic.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> Message-ID: <4AA6A31D.6010507@cm-labs.com> Hello Troy, > I've been doing a bunch of work with osg recently. I like it and badly > miss some boost.python bindings. I'd be very interested to have a look > at the code here, maybe pitch in a bit. Is there a git archive I can > clone, and a failing test I can run? I was thinking of setting up a googlecode project for this work, because there is at least one other person who might be interested in working with me on it (Paul Melis). I'll see if I can do that soon. I prefer to work with svn though (used to be CVS was oldschool, now it's SVN, I know I'm behind the times), hope that's not a problem for you. I would have liked to get the basic functionality working before setting that up because there's already another project trying to wrap OSG to python (osgSwig), so I'd like to be able to prove that my solution is competitive with that one. For reference, osgSwig have been having trouble lately wrapping the classes derived (multiply) from osg::MixinVector, and have relied on patches to OSG that remove that derivation (essentially going back to the OSG 2.6 versions of those classes). On the other hand, using boost.python I can wrap things as I want, and I don't have any problem wrapping classes derived from MixinVector, so I think it's a better route in the long run. Anyways, yeah, I'll set up that project so you can run the actual code and see the problem firsthand, hopefully that will make it easier to help out. Thanks for the offer, J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From rfritz at u.washington.edu Tue Sep 8 20:35:08 2009 From: rfritz at u.washington.edu (R Fritz) Date: Tue, 8 Sep 2009 11:35:08 -0700 Subject: [C++-sig] Boost.Python & OpenSceneGraph Message-ID: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> I am working on an OpenSceneGraph/Python project and have had to abandon the OSG/SWIG tools--they are not developed enough for my purpose. So I am planning on writing special purpose code to that end. Does anyone have suggestions for someone starting out on this path? Randolph Fritz design machine group architecture department university of washington rfritz at u.washington.edu From roman.yakovenko at gmail.com Tue Sep 8 21:27:46 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 8 Sep 2009 22:27:46 +0300 Subject: [C++-sig] Boost.Python & OpenSceneGraph In-Reply-To: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> References: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> Message-ID: <7465b6170909081227g5fdb1e22ofd211aa8662040d8@mail.gmail.com> On Tue, Sep 8, 2009 at 9:35 PM, R Fritz wrote: > I am working on an OpenSceneGraph/Python project and have had to abandon the > OSG/SWIG tools--they are not developed enough for my purpose. ?So I am > planning on writing special purpose code to that end. ?Does anyone have > suggestions for someone starting out on this path? May I suggest Py++? Py++ was proven to be useful in few big projects ( http://language-binding.net/pyplusplus/quotes.html ). Some of them are related to the graphics engine ( Python-Ogre and PyOpenSG ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From troy at resophonic.com Tue Sep 8 21:28:13 2009 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 08 Sep 2009 15:28:13 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6A31D.6010507@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> Message-ID: <4AA6B04D.4030507@resophonic.com> Jean-S?bastien Guay wrote: > Hello Troy, > >> I've been doing a bunch of work with osg recently. I like it and >> badly miss some boost.python bindings. I'd be very interested to >> have a look at the code here, maybe pitch in a bit. Is there a git >> archive I can clone, and a failing test I can run? > > I was thinking of setting up a googlecode project for this work, because > there is at least one other person who might be interested in working > with me on it (Paul Melis). I'll see if I can do that soon. > > I prefer to work with svn though (used to be CVS was oldschool, now it's > SVN, I know I'm behind the times), hope that's not a problem for you. Doesn't really matter to me. > I would have liked to get the basic functionality working before setting > that up because there's already another project trying to wrap OSG to > python (osgSwig), so I'd like to be able to prove that my solution is > competitive with that one. Competitive isn't an issue, as swig and boost.python bindings aren't really compatible (or is that 'sip' bindings that aren't compatible?). Personally I prefer a manual approach over automatically generated bindings; apparently for the same reasons that some compiler writers insist on handwritten recursive descent parsers. I know there are smart people around that have worked long and hard on generators, I don't want to start any fights. YMMV. > For reference, osgSwig have been having trouble lately wrapping the > classes derived (multiply) from osg::MixinVector, and have relied on > patches to OSG that remove that derivation (essentially going back to > the OSG 2.6 versions of those classes). On the other hand, using > boost.python I can wrap things as I want, and I don't have any problem > wrapping classes derived from MixinVector, so I think it's a better > route in the long run. Yes exactly. Being intrusive is just not an option, for one. More examples are easy to come up with, e.g. wants fine-grained control over the python interface to provide things like conversions to native python types (datetime, numpy arrays), or to provide slicing notation and iterators on a node's children, say node.children[2:7] > Anyways, yeah, I'll set up that project so you can run the actual code > and see the problem firsthand, hopefully that will make it easier to > help out. Looking forward to it. -t From jean-sebastien.guay at cm-labs.com Tue Sep 8 21:41:03 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 15:41:03 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6A31D.6010507@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> Message-ID: <4AA6B34F.3020307@cm-labs.com> Hi again Troy, > I was thinking of setting up a googlecode project for this work, because > there is at least one other person who might be interested in working > with me on it (Paul Melis). I'll see if I can do that soon. It's done now, here: http://code.google.com/p/osgboostpython/ Note that I do my work on Windows, I've tried to make my boost-build.jam and Jamroot as platform-independent as possible but you may have to tweak some things to make it build/run. You'll need OSG_ROOT and BOOST_ROOT pointing at the right places for it to build. Once the python modules are built, copy them into lib/osg, lib/osgGA, lib/osgDB and lib/osgViewer (I've scripted that for Windows but I should really make a "stage" rule in the jam script, feel free to do it if you want). Then run python test/osg/test.py 9 (the 9 runs test #9 only, the file contains 10 different tests) That will work, it will print the following: python apply_Group - node name: g1 python apply_Group - node name: g2 python apply_Node - node name: n You'll see the problem if you comment out the apply_Group method of the DerivedVisitor class in test/osg/test.py. Then it will only print out: python apply_Node - node name: g1 when it should print out: python apply_Node - node name: g1 python apply_Node - node name: g2 python apply_Node - node name: n which is what the C++ code attached does. You'll also see in test/osgViewer/test.py the other test I was referring to, the NodeCallback test. If you change the code to set the callback as CullCallback instead of UpdateCallback, you'll see that the model will no longer be displayed, even though traverse() is being called. The C++ code attached also demonstrates that this should not happen - the model should still be displayed after setting a CullCallback as long as the callback calls traverse(). (you can comment out traverse() in the callback's operator() method to see that the model will no longer be displayed). I hope this helps you help me :-) I just had a thought, maybe I need to wrap the traverse() methods in osg::Node and osg::Group? Would that allow call_method to call the right one and not slice off the argument? I had not wrapped them because in general I don't think they'd be useful in python code, but maybe they're necessary for this to work? I'll try that and see. Thanks in advance, J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test.cpp URL: From jean-sebastien.guay at cm-labs.com Tue Sep 8 21:52:17 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 15:52:17 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6B04D.4030507@resophonic.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B04D.4030507@resophonic.com> Message-ID: <4AA6B5F1.1010100@cm-labs.com> Hi Troy, > Competitive isn't an issue, as swig and boost.python bindings aren't > really compatible (or is that 'sip' bindings that aren't compatible?). > Personally I prefer a manual approach over automatically generated > bindings; apparently for the same reasons that some compiler writers > insist on handwritten recursive descent parsers. I know there are smart > people around that have worked long and hard on generators, I don't want > to start any fights. YMMV. Well it's not a matter of being compatible with osgSwig, I know it's one or the other, but I prefer manual to automatically generated for the same reasons you do (see below). > Yes exactly. Being intrusive is just not an option, for one. More > examples are easy to come up with, e.g. wants fine-grained control over > the python interface to provide things like conversions to native python > types (datetime, numpy arrays), or to provide slicing notation and > iterators on a node's children, say > > node.children[2:7] Heh, I've got some types of slicing working for Vec*Array :-) Other forms I haven't gotten to. But yeah, I want to give a python-esque view of the OSG data structures as much as possible. Note that I'm a C++ programmer writing python, so in most cases I don't know what python-esque is without reading the python tutorial, but I still have that goal :-) J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From troy at resophonic.com Tue Sep 8 21:55:56 2009 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 08 Sep 2009 15:55:56 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6B34F.3020307@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> Message-ID: <4AA6B6CC.5040809@resophonic.com> Jean-S?bastien Guay wrote: > Hi again Troy, > >> I was thinking of setting up a googlecode project for this work, >> because there is at least one other person who might be interested in >> working with me on it (Paul Melis). I'll see if I can do that soon. > > It's done now, here: > > http://code.google.com/p/osgboostpython/ > > Note that I do my work on Windows, I've tried to make my boost-build.jam > and Jamroot as platform-independent as possible but you may have to > tweak some things to make it build/run. You'll need OSG_ROOT and > BOOST_ROOT pointing at the right places for it to build. > > Once the python modules are built, copy them into lib/osg, lib/osgGA, > lib/osgDB and lib/osgViewer (I've scripted that for Windows but I should > really make a "stage" rule in the jam script, feel free to do it if you > want). [reply taken offlist] I work mostly on linux, so I suppose we can clean up after one another. but why mess with boost.build? Are you familar with / do you prefer cmake? Boost 1.38-40 build fine with cmake. I'll look a little further... -t > > Then run > > python test/osg/test.py 9 > > (the 9 runs test #9 only, the file contains 10 different tests) > > That will work, it will print the following: > > python apply_Group - node name: g1 > python apply_Group - node name: g2 > python apply_Node - node name: n > > You'll see the problem if you comment out the apply_Group method of the > DerivedVisitor class in test/osg/test.py. Then it will only print out: > > python apply_Node - node name: g1 > > when it should print out: > > python apply_Node - node name: g1 > python apply_Node - node name: g2 > python apply_Node - node name: n > > which is what the C++ code attached does. > > You'll also see in test/osgViewer/test.py the other test I was referring > to, the NodeCallback test. If you change the code to set the callback as > CullCallback instead of UpdateCallback, you'll see that the model will > no longer be displayed, even though traverse() is being called. The C++ > code attached also demonstrates that this should not happen - the model > should still be displayed after setting a CullCallback as long as the > callback calls traverse(). (you can comment out traverse() in the > callback's operator() method to see that the model will no longer be > displayed). > > I hope this helps you help me :-) > > I just had a thought, maybe I need to wrap the traverse() methods in > osg::Node and osg::Group? Would that allow call_method to call the right > one and not slice off the argument? I had not wrapped them because in > general I don't think they'd be useful in python code, but maybe they're > necessary for this to work? I'll try that and see. > > Thanks in advance, > > J-S > > > ------------------------------------------------------------------------ > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From jean-sebastien.guay at cm-labs.com Tue Sep 8 21:56:11 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 15:56:11 -0400 Subject: [C++-sig] Boost.Python & OpenSceneGraph In-Reply-To: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> References: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> Message-ID: <4AA6B6DB.60808@cm-labs.com> Hi Randolph, > I am working on an OpenSceneGraph/Python project and have had to abandon > the OSG/SWIG tools--they are not developed enough for my purpose. So I > am planning on writing special purpose code to that end. Does anyone > have suggestions for someone starting out on this path? Heh, if you can wait a bit, I just put my own boost.python bindings for OSG on the web (today, actually) : http://code.google.com/p/osgboostpython/ They're not complete and I'm struggling with slicing problems in NodeCallback and NodeVisitor derived in python code, but it's promising. In their current state I can create node hierarchies, geometry, vertex/normal/texcoord/color arrays, assign textures, do some basic state manipulation (rendering hint etc.) and run a viewer. See the *.py files in test/** , most of what the wrappers can do is tested there. And if you want to help, you're welcome to do so :-) J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From troy at resophonic.com Tue Sep 8 21:58:05 2009 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 08 Sep 2009 15:58:05 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6B6CC.5040809@resophonic.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA6B6CC.5040809@resophonic.com> Message-ID: <4AA6B74D.4020406@resophonic.com> > > [reply taken offlist] > oops, apparently not, apologies. -t From admin at lodle.net Wed Sep 9 04:33:12 2009 From: admin at lodle.net (Mark Chandler) Date: Wed, 9 Sep 2009 10:33:12 +0800 Subject: [C++-sig] Subset of default python library In-Reply-To: <4AA6B74D.4020406@resophonic.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA6B6CC.5040809@resophonic.com> <4AA6B74D.4020406@resophonic.com> Message-ID: <8B3235BE-5B4C-4594-9109-7C74ED67A38E@lodle.net> Is there a small subset of the default python library that i can use for our embedded instance. Since this is part of a larger app that doesnt expect to have python installed thus we are including it with the program data. How ever there is alot of stuff in there that we are not going to use (all the server stuff) and dont want clients using as well. From jean-sebastien.guay at cm-labs.com Wed Sep 9 04:41:07 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 22:41:07 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA6B34F.3020307@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> Message-ID: <4AA715C3.1070805@cm-labs.com> Hi all, I found an post from earlier this year to this list where David Abrahams said: -------------------- If you want to pass an object by reference to a python function, you have to wrap it in boost::ref(). Otherwise, it will try to copy the object and the resulting copy will have to be destroyed after the call. -------------------- http://mail.python.org/pipermail/cplusplus-sig/2009-February/014251.html This made me think that perhaps the problem was that the object was being copied, which will of course only copy according to the static type. And yes, wrapping the arguments to call_method in boost::ref() fixes the problem! Yay! And in fact, this fixed the problem for NodeCallback as well. In that case though, the argument is a pointer: void operator()(Node* node, NodeVisitor* nv) { try { call_method(self, "call", boost::ref(node), boost::ref(nv)); } catch (error_already_set) { NodeCallback::operator()(node, nv); } } so I don't understand why a copy is being made by call_method, but hey, it works so I'm happy... J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From renatox at gmail.com Wed Sep 9 05:06:50 2009 From: renatox at gmail.com (Renato Araujo) Date: Wed, 9 Sep 2009 00:06:50 -0300 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <4AA715C3.1070805@cm-labs.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA715C3.1070805@cm-labs.com> Message-ID: <95291a80909082006s3d3b7978i99e4fff16ced612@mail.gmail.com> Hi Jean, You can use "boost::python::ptr(your_cpp_cpointer)" this avoid create unecessary copies. BR Renato Araujo Oliveira Filho On Tue, Sep 8, 2009 at 11:41 PM, Jean-S?bastien Guay wrote: > Hi all, > > I found an post from earlier this year to this list where David Abrahams > said: > > -------------------- > If you want to pass an object by reference to a python function, you > have to wrap it in boost::ref(). ?Otherwise, it will try to copy the > object and the resulting copy will have to be destroyed after the call. > -------------------- > > http://mail.python.org/pipermail/cplusplus-sig/2009-February/014251.html > > This made me think that perhaps the problem was that the object was being > copied, which will of course only copy according to the static type. > > And yes, wrapping the arguments to call_method in boost::ref() fixes the > problem! Yay! > > And in fact, this fixed the problem for NodeCallback as well. In that case > though, the argument is a pointer: > > ? ?void operator()(Node* node, NodeVisitor* nv) > ? ?{ > ? ? ? ?try { > ? ? ? ? ? ?call_method(self, "call", boost::ref(node), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?boost::ref(nv)); > ? ? ? ?} > ? ? ? ?catch (error_already_set) { > ? ? ? ? ? ?NodeCallback::operator()(node, nv); > ? ? ? ?} > ? ?} > > so I don't understand why a copy is being made by call_method, but hey, it > works so I'm happy... > > J-S > -- > ______________________________________________________ > Jean-Sebastien Guay ? ?jean-sebastien.guay at cm-labs.com > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://www.cm-labs.com/ > ? ? ? ? ? ? ? ? ? ? ? ?http://whitestar02.webhop.org/ > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From jean-sebastien.guay at cm-labs.com Wed Sep 9 05:23:12 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 23:23:12 -0400 Subject: [C++-sig] boost.python - C++ class overridden in python causes slicing In-Reply-To: <95291a80909082006s3d3b7978i99e4fff16ced612@mail.gmail.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA715C3.1070805@cm-labs.com> <95291a80909082006s3d3b7978i99e4fff16ced612@mail.gmail.com> Message-ID: <4AA71FA0.105@cm-labs.com> Hi Renato, > You can use "boost::python::ptr(your_cpp_cpointer)" this avoid create > unecessary copies. Thanks for the tip, boost::ref() for references and boost::python::ptr() for pointers, makes sense. J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From jean-sebastien.guay at cm-labs.com Wed Sep 9 05:30:22 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 08 Sep 2009 23:30:22 -0400 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions Message-ID: <4AA7214E.1060405@cm-labs.com> Hi all, This may be an FAQ, but if so I haven't seen it in the FAQs (on the wiki and in the docs). Say I have this: class A {}; class B { public: A* getA(); const A* getA() const; }; If I just add .def("getA", &B::getA, some_return_policy) to my class_ wrapper, on compile it will complain that it doesn't know which version of B::getA() I want. Up until now the way I wrapped this was to make a trivial wrapper function: A* (B::*B_getA1)() = &B::getA; and then used .def("getA", B_getA1, some_return_policy). But as I wrap many classes, I wind up with lost of these trivial wrappers at the top of my source files, they're hard to read when skimming and just plain look bad. Is there some template or preprocessor magic I could use to generate these automatically, or even better, to allow me to specify in the .def() which version I want? Thanks in advance, J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From seefeld at sympatico.ca Wed Sep 9 05:48:19 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 08 Sep 2009 23:48:19 -0400 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions In-Reply-To: <4AA7214E.1060405@cm-labs.com> References: <4AA7214E.1060405@cm-labs.com> Message-ID: <4AA72583.9030701@sympatico.ca> On 09/08/2009 11:30 PM, Jean-S?bastien Guay wrote: > > If I just add .def("getA", &B::getA, some_return_policy) to my class_ > wrapper, on compile it will complain that it doesn't know which > version of B::getA() I want. Up until now the way I wrapped this was > to make a trivial wrapper function: > > A* (B::*B_getA1)() = &B::getA; This is not a wrapper function, but an alias. You create a new variable 'B_getA1', and make this point to B::getA (the non-const version). This works, since by means of the variable type you disambiguate, so using that in the call to def() works unambiguously. > > and then used .def("getA", B_getA1, some_return_policy). But as I wrap > many classes, I wind up with lost of these trivial wrappers at the top > of my source files, they're hard to read when skimming and just plain > look bad. Is there some template or preprocessor magic I could use to > generate these automatically, or even better, to allow me to specify > in the .def() which version I want? You may disambiguate by using a cast inside .def(), such as .def("getA", (A*(B::*)())B::getA); Whether that's actually more readable is arguable, however. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jean-sebastien.guay at cm-labs.com Wed Sep 9 07:00:50 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Wed, 09 Sep 2009 01:00:50 -0400 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions In-Reply-To: <4AA72583.9030701@sympatico.ca> References: <4AA7214E.1060405@cm-labs.com> <4AA72583.9030701@sympatico.ca> Message-ID: <4AA73682.9040506@cm-labs.com> Hi Stefan, > This is not a wrapper function, but an alias. You create a new variable > 'B_getA1', and make this point to B::getA (the non-const version). > This works, since by means of the variable type you disambiguate, so > using that in the call to def() works unambiguously. Sorry, thanks for correcting my terminology. :-) > You may disambiguate by using a cast inside .def(), such as > > .def("getA", (A*(B::*)())B::getA); > > Whether that's actually more readable is arguable, however. Yeah, that's true, and it will be especially ugly when the method has arguments (I guess the cast will then have to include all the argument types too...) Thanks, J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From nico_ml at mgdesign.org Wed Sep 9 12:15:09 2009 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Wed, 9 Sep 2009 12:15:09 +0200 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions References: <4AA7214E.1060405@cm-labs.com> <4AA72583.9030701@sympatico.ca> Message-ID: <074f01ca3136$69482050$d100a8c0@nicopc> > You may disambiguate by using a cast inside .def(), such as > > .def("getA", (A*(B::*)())B::getA); > > Whether that's actually more readable is arguable, however. IMHO, this is quite dangerous as the explicit cast prevents the compiler to give you a proper error if the signature of B::getA changes at some point in time. The original approach ( A* (B::*B_getA1)() = &B::getA; ) requires extra typing but provides a safety net for refactoring B::getA. Cheers, Nicolas. From ndbecker2 at gmail.com Wed Sep 9 16:43:00 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 09 Sep 2009 10:43 -0400 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions References: <4AA7214E.1060405@cm-labs.com> <4AA72583.9030701@sympatico.ca> <4AA73682.9040506@cm-labs.com> Message-ID: Jean-S?bastien Guay wrote: > Hi Stefan, > >> This is not a wrapper function, but an alias. You create a new variable >> 'B_getA1', and make this point to B::getA (the non-const version). >> This works, since by means of the variable type you disambiguate, so >> using that in the call to def() works unambiguously. > > Sorry, thanks for correcting my terminology. :-) > >> You may disambiguate by using a cast inside .def(), such as >> >> .def("getA", (A*(B::*)())B::getA); >> >> Whether that's actually more readable is arguable, however. > > Yeah, that's true, and it will be especially ugly when the method has > arguments (I guess the cast will then have to include all the argument > types too...) > > Thanks, > > J-S One other difference (which I just found the hard way when updating from boost-1.39 to boost-1.40): The cast will stop working if a minor change is made to the function signature, while the 'alias' will not break so easily. From troy at resophonic.com Wed Sep 9 18:44:05 2009 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 09 Sep 2009 12:44:05 -0400 Subject: [C++-sig] Quick question about wrapping methods that have multiple versions In-Reply-To: <074f01ca3136$69482050$d100a8c0@nicopc> References: <4AA7214E.1060405@cm-labs.com> <4AA72583.9030701@sympatico.ca> <074f01ca3136$69482050$d100a8c0@nicopc> Message-ID: <4AA7DB55.9040003@resophonic.com> Nicolas Lelong wrote: >> You may disambiguate by using a cast inside .def(), such as >> >> .def("getA", (A*(B::*)())B::getA); >> >> Whether that's actually more readable is arguable, however. > > IMHO, this is quite dangerous as the explicit cast prevents the compiler > to give you a proper error if the signature of B::getA changes at some > point in time. The original approach ( A* (B::*B_getA1)() = &B::getA; ) > requires extra typing but provides a safety net for refactoring B::getA. > This is an interesting subtlety. I'd be advocating the C-style cast for its conciseness; as it turns out (with gcc 4.3 at least) I can only get dangerous behavior if I cast a function which is *not* overloaded. For overloaded functions, if you cast to a function type which is not in the overload set, the C-style cast fails (as we would like it to), since there is incomplete type information. So in the situation where you're using c-style casts to resolve overloads, and later in the wrapped class an overload set is reduced to one function, you have undefined behavior. (example below... sanity-check, please? Maybe there are other compilers on which this C-style casting is more dangerous than recent gcc.) I was curious about this, as I have a def() syntax working that was suggested at boostcon: struct C { void f(float); void f(bool); }; class_("C") .def("f", f) .def("f", f) ; Wherein the conversion is done via some boost::function_types trickery. I'll have to go back and check if it handles this case. Here is the example: // can you make the C-style casts of f, which select // particular overloads, result in undefined behavior? #include void f(int i) { std::cout << "f(int) called with " << i <<" \n"; } void f(double d) { std::cout << "f(double) called with" << d << "\n"; } // // You can do this, cast a function to an int, but only if // the function is not overloaded: // void g(const char* thing) { std::cout << "g(const char*) called with " << thing << "\n"; } int g_casted = (int) g; // this works but we wish it didnt // Here the alias won't work: catches the error as we want, good // void (*gptr)(float) = &g; // Doesn't work: overloaded function with no textual type information // int f_casted = (int) f; // this works, but is a degenerate case imho, first you cast to a // function type, so that you have a type, then you can munge // it into an int int f_casted = (int) (void(*)(double)) f; template void def(const char* name, const F& f) { std::cout << name << "\t --> "; f(true); } // void (*f_bool_alias)(bool) = &f; void (*f_int_alias)(int) = &f; // void (*f_float_alias)(float) = &f; void (*f_double_alias)(double) = &f; int main(int, char**) { // def(" via cast f(bool)", (void(*)(bool))f); // wont compile def(" via cast f(int)", (void(*)(int))f); // def(" via cast f(float)", (void(*)(float))f); // wont compile def(" via cast f(double)", (void(*)(double))f); // def("via alias f(bool)", f_bool_alias); // wont compile def("via alias f(int)", f_int_alias); // def("via alias f(float)", f_float_alias); // wont compile def("via alias f(double)", f_double_alias); // def("via cast from g", (void(*)(float)) g); // kaboom } From rfritz at u.washington.edu Wed Sep 9 22:55:56 2009 From: rfritz at u.washington.edu (R Fritz) Date: Wed, 9 Sep 2009 13:55:56 -0700 Subject: [C++-sig] Boost.Python & OpenSceneGraph In-Reply-To: <7465b6170909081227g5fdb1e22ofd211aa8662040d8@mail.gmail.com> References: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> <7465b6170909081227g5fdb1e22ofd211aa8662040d8@mail.gmail.com> Message-ID: <5026E2BF-4F71-4F04-B4EA-840DC6AB8A0D@u.washington.edu> Thanks for the suggestion--I may give this a try. Randolph On Sep 8, 2009, at 12:27 PM, Roman Yakovenko wrote: > On Tue, Sep 8, 2009 at 9:35 PM, R Fritz > wrote: >> I am working on an OpenSceneGraph/Python project and have had to >> abandon the >> OSG/SWIG tools--they are not developed enough for my purpose. So I >> am >> planning on writing special purpose code to that end. Does anyone >> have >> suggestions for someone starting out on this path? > > May I suggest Py++? > > Py++ was proven to be useful in few big projects ( > http://language-binding.net/pyplusplus/quotes.html ). > Some of them are related to the graphics engine ( Python-Ogre and > PyOpenSG ). > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From rfritz at u.washington.edu Wed Sep 9 22:34:28 2009 From: rfritz at u.washington.edu (R Fritz) Date: Wed, 9 Sep 2009 13:34:28 -0700 Subject: [C++-sig] Boost.Python & OpenSceneGraph In-Reply-To: <4AA6B6DB.60808@cm-labs.com> References: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> <4AA6B6DB.60808@cm-labs.com> Message-ID: <7B0F8D70-7AAF-463E-89E0-0041456FEC4F@u.washington.edu> J-S, I wish you and your work well, but I don't see how I can do this. NodeCallback and NodeVisitor are exactly where I ran into problems with osgswig--they are important, and hard to get right. As with osgswig, I'd be testing your bindings, rather than concentrating on my thesis work. I'm sorry, but no. Randolph On Sep 8, 2009, at 12:56 PM, Jean-S?bastien Guay wrote: > Hi Randolph, > >> I am working on an OpenSceneGraph/Python project and have had to >> abandon the OSG/SWIG tools--they are not developed enough for my >> purpose. So I am planning on writing special purpose code to that >> end. Does anyone have suggestions for someone starting out on this >> path? > > Heh, if you can wait a bit, I just put my own boost.python bindings > for OSG on the web (today, actually) : > > http://code.google.com/p/osgboostpython/ > > They're not complete and I'm struggling with slicing problems in > NodeCallback and NodeVisitor derived in python code, but it's > promising. In their current state I can create node hierarchies, > geometry, vertex/normal/texcoord/color arrays, assign textures, do > some basic state manipulation (rendering hint etc.) and run a > viewer. See the *.py files in test/** , most of what the wrappers > can do is tested there. > > And if you want to help, you're welcome to do so :-) > > J-S From jean-sebastien.guay at cm-labs.com Thu Sep 10 02:03:44 2009 From: jean-sebastien.guay at cm-labs.com (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Wed, 09 Sep 2009 20:03:44 -0400 Subject: [C++-sig] Boost.Python & OpenSceneGraph In-Reply-To: <7B0F8D70-7AAF-463E-89E0-0041456FEC4F@u.washington.edu> References: <8057C092-3F76-4940-AD01-FAC8CB62601B@u.washington.edu> <4AA6B6DB.60808@cm-labs.com> <7B0F8D70-7AAF-463E-89E0-0041456FEC4F@u.washington.edu> Message-ID: <4AA84260.1040907@cm-labs.com> Hi Randolph, > I wish you and your work well, but I don't see how I can do this. > NodeCallback and NodeVisitor are exactly where I ran into problems with > osgswig--they are important, and hard to get right. Actually I don't know if you saw my messages from last night, but it works fine now. But: > As with osgswig, > I'd be testing your bindings, rather than concentrating on my thesis > work. I'm sorry, but no. I totally understand your feelings on this. Unfortunately, I think if you want a python binding to OSG, your choices are rather limited. Using another generator such as Py++ might work out, but you'd be doing much of the same work as osgSwig did, you'd need to do lots of prep work before being able to move on to your own work, with no guarantee of better results. So as I see it, you'll either end up working in C++, or spending some amount of time getting wrappers working the way you want them. Whether that's with osgSwig (which seem to have hit some roadblocks lately), with Py++ or some other generator (where you'd be starting pretty much from scratch) or with osgBoostPython (where you may have to help wrap more classes but where progress is almost constant and doesn't seem to have hit any major snags up until now). Of course I'm biased, what do you expect? :-) J-S -- ______________________________________________________ Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ From david.roy.perso at gmail.com Thu Sep 10 12:20:17 2009 From: david.roy.perso at gmail.com (David Roy) Date: Thu, 10 Sep 2009 03:20:17 -0700 (PDT) Subject: [C++-sig] Boost.Python: wrapping classes instead of functions??? Message-ID: <25380730.post@talk.nabble.com> Hi, I'm facing a very strange behavior that I cannot manage to explane. I'm currently working on a project of re-implementing Python functions in C++ in order to improve performance and I'm then creating Python extensions thanks to Boost. I implemented quite a heavy function that calculates tangents and binormals this way: class GeomUtils { private: // some functions... public: AddTangentAndBinormals(); } GeomUtils::AddtangentAndBinormals() { // call some functions... } BOOST_PYTHON_MODULE(geom_utils) { class_("GeomUtils", init<>()) .def("AddTangentAndBinormals", &GeomUtils::AddTangentAndBinormals) ; } This was very successful, decreasing the computation time from 54.0 seconds to less than 1.0 second. Then I decided this wasn't worth a class and that I should directly export the function : AddTangentAndBinormals() { // call some functions... } BOOST_PYTHON_MODULE(geom_utils) { def("AddTangentAndBinormals", &AddTangentAndBinormals); } and the profile was back to 54.0 seconds!!! Please could someone help me understand what's the difference and the mechanism underlying that? Thanks -David -- View this message in context: http://www.nabble.com/Boost.Python%3A-wrapping-classes-instead-of-functions----tp25380730p25380730.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From nat at lindenlab.com Thu Sep 10 16:05:55 2009 From: nat at lindenlab.com (Nat Goodspeed) Date: Thu, 10 Sep 2009 10:05:55 -0400 Subject: [C++-sig] Subset of default python library In-Reply-To: <8B3235BE-5B4C-4594-9109-7C74ED67A38E@lodle.net> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA6B6CC.5040809@resophonic.com> <4AA6B74D.4020406@resophonic.com> <8B3235BE-5B4C-4594-9109-7C74ED67A38E@lodle.net> Message-ID: <4AA907C3.3090903@lindenlab.com> Mark Chandler wrote: > Is there a small subset of the default python library that i can use for > our embedded instance. Since this is part of a larger app that doesnt > expect to have python installed thus we are including it with the > program data. How ever there is alot of stuff in there that we are not > going to use (all the server stuff) and dont want clients using as > well. Have you looked at the distutils tools? I know there's functionality to start from a "root set" of referenced Python library modules and produce an exhaustive list of recursively-referenced modules. I haven't directly used those tools myself because my experience is more with py2exe and py2app: http://www.py2exe.org/ http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html In our case, instead of embedding the Python interpreter into our C++ application, we started with a Python main program and wrapped our C++ code as extension modules. This structure works well with py2exe and py2app. Both tools package the minimum subset of the Python standard library needed for your specific application, and that functionality is available via distutils. From troy at resophonic.com Thu Sep 10 16:44:09 2009 From: troy at resophonic.com (troy d. straszheim) Date: Thu, 10 Sep 2009 10:44:09 -0400 Subject: [C++-sig] Boost.Python: wrapping classes instead of functions??? In-Reply-To: <25380730.post@talk.nabble.com> References: <25380730.post@talk.nabble.com> Message-ID: <4AA910B9.40406@resophonic.com> David Roy wrote: > > and the profile was back to 54.0 seconds!!! > Please could someone help me understand what's the difference and the > mechanism underlying that? Probably that you're not running the code that you think you are. There should be no difference between member function and free function in this case, unless you're not telling us something. Run python with the -v option to be sure that the code you are running comes from where you expect it to. -t From troy at resophonic.com Thu Sep 10 16:46:05 2009 From: troy at resophonic.com (troy d. straszheim) Date: Thu, 10 Sep 2009 10:46:05 -0400 Subject: [C++-sig] Subset of default python library In-Reply-To: <4AA907C3.3090903@lindenlab.com> References: <4AA5CB13.40506@cm-labs.com> <4AA62F94.90100@resophonic.com> <4AA6A31D.6010507@cm-labs.com> <4AA6B34F.3020307@cm-labs.com> <4AA6B6CC.5040809@resophonic.com> <4AA6B74D.4020406@resophonic.com> <8B3235BE-5B4C-4594-9109-7C74ED67A38E@lodle.net> <4AA907C3.3090903@lindenlab.com> Message-ID: <4AA9112D.30605@resophonic.com> Nat Goodspeed wrote: > Mark Chandler wrote: > >> Is there a small subset of the default python library that i can use >> for our embedded instance. Since this is part of a larger app that >> doesnt expect to have python installed thus we are including it with >> the program data. How ever there is alot of stuff in there that we are >> not going to use (all the server stuff) and dont want clients using as >> well. > > Have you looked at the distutils tools? I know there's functionality to > start from a "root set" of referenced Python library modules and produce > an exhaustive list of recursively-referenced modules. You can also try running python with the -v flag, it will give you a list of everything it imports. You probably can get your minimum distribution from this info... -t From david.roy.perso at gmail.com Fri Sep 11 10:17:23 2009 From: david.roy.perso at gmail.com (David Roy) Date: Fri, 11 Sep 2009 01:17:23 -0700 (PDT) Subject: [C++-sig] Boost.Python: wrapping classes instead of functions??? In-Reply-To: <4AA910B9.40406@resophonic.com> References: <25380730.post@talk.nabble.com> <4AA910B9.40406@resophonic.com> Message-ID: <25396895.post@talk.nabble.com> Thanks for the reply. Unfortunately I'm sure that it's the C++ code that's being called in both cases (I put a pdb.set_trace() in the Python code that shouldn't be called and a TRACE in the C++ code that should be called). Some more information: - there are 148 calls to the function AddTangentAndBinormal(), 0.00625 s per call in the first case and 0.39 s per call in the second case). - in the case of a class, the instance is not persisted, i.e. the following python code is called 148 times: geom_utils = GeomUtils() geom_utils.AddTangentAndBinormal() - I'm using a std::map that will be filled with more than 10000 entries: it's a private member of the class in the first case and a global in the second case - I'm allocating about 10000 vector3 of float each call - I'm interacting with Panda3D game engine in this function Don't know if some of these additional info is useful... Thanks -David troy d. straszheim wrote: > > David Roy wrote: >> >> and the profile was back to 54.0 seconds!!! >> Please could someone help me understand what's the difference and the >> mechanism underlying that? > > Probably that you're not running the code that you think you are. There > should be no difference between member function and free function in > this case, unless you're not telling us something. Run python with the > -v option to be sure that the code you are running comes from where you > expect it to. > > -t > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > -- View this message in context: http://www.nabble.com/Boost.Python%3A-wrapping-classes-instead-of-functions----tp25380730p25396895.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From nico_ml at mgdesign.org Fri Sep 11 16:03:54 2009 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Fri, 11 Sep 2009 16:03:54 +0200 Subject: [C++-sig] Boost.Python: wrapping classes instead of functions??? References: <25380730.post@talk.nabble.com> <4AA910B9.40406@resophonic.com> <25396895.post@talk.nabble.com> Message-ID: <01e101ca32e8$b30a7950$d100a8c0@nicopc> David wrote: > - I'm using a std::map that will be filled with more than 10000 entries: > it's a private member of the class in the first case and a global in the > second case That may be dumb, but are you sure that you reset your global data structures before or after your free function call. When using the class approach, your cleanup is automatic, but you may have forgotten something when switching to globals. troy wrote: >> Probably that you're not running the code that you think you are. There >> should be no difference between member function and free function in >> this case, unless you're not telling us something. FWIW, I also don't have any performance problems when using free functions, and I'd tend to agree with troy. From troy at resophonic.com Fri Sep 11 17:18:06 2009 From: troy at resophonic.com (troy d. straszheim) Date: Fri, 11 Sep 2009 11:18:06 -0400 Subject: [C++-sig] Boost.Python: wrapping classes instead of functions??? In-Reply-To: <25396895.post@talk.nabble.com> References: <25380730.post@talk.nabble.com> <4AA910B9.40406@resophonic.com> <25396895.post@talk.nabble.com> Message-ID: <4AAA6A2E.4050402@resophonic.com> David Roy wrote: > Don't know if some of these additional info is useful... > Not really. Without runnable examples we'd just be guessing. -t From pertti.kellomaki at tut.fi Wed Sep 16 17:36:55 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Wed, 16 Sep 2009 18:36:55 +0300 Subject: [C++-sig] Py++ and protected destructors Message-ID: <4AB10617.4080708@tut.fi> Hi, Just a quick check. I am using py++, and I've run into the problem with protected destructors. Is the following advice still valid? -- Pertti From roman.yakovenko at gmail.com Wed Sep 16 20:20:49 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 16 Sep 2009 21:20:49 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <4AB10617.4080708@tut.fi> References: <4AB10617.4080708@tut.fi> Message-ID: <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> 2009/9/16 Pertti Kellom?ki : > Hi, > > Just a quick check. I am using py++, and I've run into the problem > with protected destructors. Is the following advice still valid? It should be, but today there is a better way to solve this problem - Function Transformation: http://language-binding.net/pyplusplus/documentation/functions/transformation/modify_type.html?highlight=function%20transformation I just checked, "modify type" transformation doesn't generate optimal code for the following conversion: from "const T&" to "T&". Before I modified the code, I suggest you to submit a small working example which shows the problem, so we can solve the right problem. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Wed Sep 16 21:44:39 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Wed, 16 Sep 2009 22:44:39 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> Message-ID: <4AB14027.1010301@tut.fi> Hi Roman, > Before I modified the code, I suggest you to submit a small working > example which shows the problem, so we can solve the right problem. Sounds good, I'll do some code distillation tomorrow. -- Pertti From pertti.kellomaki at tut.fi Thu Sep 17 11:23:33 2009 From: pertti.kellomaki at tut.fi (=?windows-1252?Q?Pertti_Kellom=E4ki?=) Date: Thu, 17 Sep 2009 12:23:33 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> Message-ID: <4AB20015.2090407@tut.fi> Roman Yakovenko wrote: > Before I modified the code, I suggest you to submit a small working > example which shows the problem, so we can solve the right problem. Ok, here's a distilled code example. Running python dest.pypp && gcc -c -I/usr/include/python2.6 dest_bindings.cpp yields the error message dest.hh:3: virhe: ?virtual A::~A()? is protected This is with the latest svn version of py++. -- Pertti -------------- next part -------------- A non-text attachment was scrubbed... Name: dest.hh Type: text/x-c++hdr Size: 87 bytes Desc: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: dest.pypp URL: From roman.yakovenko at gmail.com Thu Sep 17 11:30:59 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 17 Sep 2009 12:30:59 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <4AB20015.2090407@tut.fi> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> <4AB20015.2090407@tut.fi> Message-ID: <7465b6170909170230j6310ab7ck5a34d2172fcb411c@mail.gmail.com> 2009/9/17 Pertti Kellom?ki : > Roman Yakovenko wrote: >> >> Before I modified the code, I suggest you to submit a small working >> example which shows the problem, so we can solve the right problem. > > Ok, here's a distilled code example. Running > > ?python dest.pypp && gcc -c -I/usr/include/python2.6 dest_bindings.cpp > > yields the error message > > ?dest.hh:3: virhe: ?virtual A::~A()? is protected > > This is with the latest svn version of py++. Okey. You should use "modify_type" function transformation with "remove_const" type traits function. Untested: from pygccxml import declarations from pyplusplus import module_builder from pyplusplus import function_transformers as FT mb = module_builder_( ... ) f = mb.mem_fun( 'f' ) f.add_transformation( FT.modify_type(0, declarations.remove_const ) ) #0 - argument index HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Thu Sep 17 12:39:01 2009 From: pertti.kellomaki at tut.fi (=?windows-1252?Q?Pertti_Kellom=E4ki?=) Date: Thu, 17 Sep 2009 13:39:01 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <7465b6170909170230j6310ab7ck5a34d2172fcb411c@mail.gmail.com> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> <4AB20015.2090407@tut.fi> <7465b6170909170230j6310ab7ck5a34d2172fcb411c@mail.gmail.com> Message-ID: <4AB211C5.4060103@tut.fi> Roman Yakovenko wrote: > Okey. You should use "modify_type" function transformation with > "remove_const" type traits function. Thanks. This does not quite solve the problem, as remove_const will turn "const A" to "A" but leave "A const &" as it is. I modified remove_const to convert "A const &" to "A &" and it is only a few lines. However, I'm not sure whether this really is the semantics you want for remove const. Maybe I should create my own function remove_const_ref and use that as a transformation instead? -- Pertit From roman.yakovenko at gmail.com Thu Sep 17 12:43:00 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 17 Sep 2009 13:43:00 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <4AB211C5.4060103@tut.fi> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> <4AB20015.2090407@tut.fi> <7465b6170909170230j6310ab7ck5a34d2172fcb411c@mail.gmail.com> <4AB211C5.4060103@tut.fi> Message-ID: <7465b6170909170343w5b9f095by399b26f9c93e3f7a@mail.gmail.com> 2009/9/17 Pertti Kellom?ki : > Roman Yakovenko wrote: >> >> Okey. You should use "modify_type" function transformation with >> "remove_const" type traits function. > > Thanks. This does not quite solve the problem, as remove_const > will turn "const A" to "A" but leave "A const &" as it is. Right, I forgot about that. Actually the type composition looks like: ref( const( A ) ) > I modified remove_const to convert "A const &" to "A &" and it is > only a few lines. However, I'm not sure whether this really is the > semantics you want for remove const. Maybe I should create my own > function remove_const_ref and use that as a transformation instead? Yes you should create and pass your own function. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Thu Sep 17 12:44:53 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Thu, 17 Sep 2009 13:44:53 +0300 Subject: [C++-sig] Py++ and protected destructors In-Reply-To: <7465b6170909170343w5b9f095by399b26f9c93e3f7a@mail.gmail.com> References: <4AB10617.4080708@tut.fi> <7465b6170909161120k5369349fq66d92153d55c22b9@mail.gmail.com> <4AB20015.2090407@tut.fi> <7465b6170909170230j6310ab7ck5a34d2172fcb411c@mail.gmail.com> <4AB211C5.4060103@tut.fi> <7465b6170909170343w5b9f095by399b26f9c93e3f7a@mail.gmail.com> Message-ID: <4AB21325.2000709@tut.fi> Roman Yakovenko wrote: > Yes you should create and pass your own function. Ok. Thanks once again for your prompt help! -- Pertti From pertti.kellomaki at tut.fi Fri Sep 18 11:03:20 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Fri, 18 Sep 2009 12:03:20 +0300 Subject: [C++-sig] Problems with virtualness and py++ Message-ID: <4AB34CD8.4020400@tut.fi> I made some progress with the removing constness issue, but now I'm having problems that seem to be related to some kind of interaction between virtualness, function transformation and return value policies. The attached .hh and .pypp files illustrate the problem. The transformation is applied correctly to a non-virtual member function, but something goes wrong when the function is virtual. -- Pertti -------------- next part -------------- A non-text attachment was scrubbed... Name: virtual_const.hh Type: text/x-c++hdr Size: 215 bytes Desc: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: virtual_const.pypp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: compiler_error.txt URL: From roman.yakovenko at gmail.com Sat Sep 19 08:10:01 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 19 Sep 2009 09:10:01 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <4AB34CD8.4020400@tut.fi> References: <4AB34CD8.4020400@tut.fi> Message-ID: <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> I will take a look on both problems this evening P.S. I am celebrating new year :-) On 9/18/09, Pertti Kellom?ki wrote: > I made some progress with the removing constness issue, > but now I'm having problems that seem to be related to > some kind of interaction between virtualness, function > transformation and return value policies. > > The attached .hh and .pypp files illustrate the problem. > The transformation is applied correctly to a non-virtual > member function, but something goes wrong when the function > is virtual. > -- > Pertti > -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From seefeld at sympatico.ca Sat Sep 19 14:59:21 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sat, 19 Sep 2009 08:59:21 -0400 Subject: [C++-sig] Python 3 support has landed on boost trunk Message-ID: <4AB4D5A9.5060909@sympatico.ca> Hi there, as some of you may know, Haoyu Bai has worked over the summer on Python 3 support for Boost.Python. This work happened on a branch, which I merged back into trunk last night. Now we need to set up testers to run the testsuite with some Python 3 variant, as that is a new platform to track. I will see whether I can set one up on one of my machines. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From troy at resophonic.com Sat Sep 19 20:52:26 2009 From: troy at resophonic.com (troy d. straszheim) Date: Sat, 19 Sep 2009 14:52:26 -0400 Subject: [C++-sig] stl_input_iterator and std::distance fix Message-ID: <4AB5286A.20703@resophonic.com> I'm going through some bugs, I can't seem to find the thread where this bug report originated: https://svn.boost.org/trac/boost/ticket/3450 The fix is on my python branch: http://gitorious.org/~straszheim/boost/straszheim/commit/a8979df969fd44bfaa649599293ccb173f6c29c7 I haven't closed the bug as the code isn't in SVN yet. -t From roman.yakovenko at gmail.com Sat Sep 19 21:01:10 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 19 Sep 2009 22:01:10 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> References: <4AB34CD8.4020400@tut.fi> <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> Message-ID: <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> > On 9/18/09, Pertti Kellom?ki wrote: >> I made some progress with the removing constness issue, >> but now I'm having problems that seem to be related to >> some kind of interaction between virtualness, function >> transformation and return value policies. >> >> The attached .hh and .pypp files illustrate the problem. >> The transformation is applied correctly to a non-virtual >> member function, but something goes wrong when the function >> is virtual. Can you try revision: http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1757&view=rev ? I believe the bug is fixed and new issues were not introduced :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From troy at resophonic.com Sun Sep 20 16:28:29 2009 From: troy at resophonic.com (troy d. straszheim) Date: Sun, 20 Sep 2009 10:28:29 -0400 Subject: [C++-sig] Fw: g++ compiler limitations otherthan -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ? In-Reply-To: <008b01c9ee38$68ac9590$5f8a1093@dhcp.ess.us.ray.com> References: <003a01c9eaf2$91a27c60$5f8a1093@dhcp.ess.us.ray.com> <4A36C495.7030707@sympatico.ca> <008b01c9ee38$68ac9590$5f8a1093@dhcp.ess.us.ray.com> Message-ID: <4AB63C0D.6050800@resophonic.com> Christopher A Mejia wrote: > Stefan, > > OK--it's in the system as #3183. Thanks again for your help, and anyone > should feel free to let me know if they need more information about this > issue. > > --Chris > Hey Chris, Steven Watanabe points out that this is due to a hardcoded limit of 24 arguments in type_traits' is_member_function_pointer. I've put a test that demonstrates a workaround on my python branch: http://gitorious.org/~straszheim/boost/straszheim/commit/02776bcf430aa1dd6325c564965bca2a3c11f358 Which will make its way back up to svn at some point. I don't really think there is a good argument for increasing the arity of type_traits for this case, so I'm going to close the ticket. Get back to me with any questions... -t From pertti.kellomaki at tut.fi Mon Sep 21 08:29:52 2009 From: pertti.kellomaki at tut.fi (=?windows-1252?Q?Pertti_Kellom=E4ki?=) Date: Mon, 21 Sep 2009 09:29:52 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> References: <4AB34CD8.4020400@tut.fi> <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> Message-ID: <4AB71D60.2000306@tut.fi> Hi Roman, > Can you try revision: > http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1757&view=rev ? > > I believe the bug is fixed and new issues were not introduced :-) There is a small snag still: virtual_const_bindings.cpp:27: virhe: ?result? declared as reference but not initialized This comes from the following piece of code: static boost::python::object default_h( ::B & inst, ::A & x ){ C & result; if( dynamic_cast< B_wrapper * >( boost::addressof( inst ) ) ){ result = inst.::B::h(x); } else{ result = inst.h(x); } typedef bp::return_internal_reference< > call_policies_t; return bp::object( pyplusplus::call_policies::make_object< call_policies_t, ::C & >( result ) ); } -- Pertti From roman.yakovenko at gmail.com Mon Sep 21 12:21:50 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 21 Sep 2009 13:21:50 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <4AB71D60.2000306@tut.fi> References: <4AB34CD8.4020400@tut.fi> <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> <4AB71D60.2000306@tut.fi> Message-ID: <7465b6170909210321r71b2fc61nc49dd360fe136556@mail.gmail.com> 2009/9/21 Pertti Kellom?ki : > Hi Roman, > >> Can you try revision: >> http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1757&view=rev ? >> >> I believe the bug is fixed and new issues were not introduced :-) > > There is a small snag still: > > virtual_const_bindings.cpp:27: virhe: ?result? declared as reference > but not initialized > > This comes from the following piece of code: > > ? ?static boost::python::object default_h( ::B & inst, ::A & x ){ > ? ? ? ?C & result; > ? ? ? ?if( dynamic_cast< B_wrapper * >( boost::addressof( inst ) ) ){ > ? ? ? ? ? ?result = inst.::B::h(x); > ? ? ? ?} > ? ? ? ?else{ > ? ? ? ? ? ?result = inst.h(x); > ? ? ? ?} > ? ? ? ?typedef bp::return_internal_reference< > call_policies_t; > ? ? ? ?return bp::object( pyplusplus::call_policies::make_object< > call_policies_t, ::C & >( result ) ); > ? ?} :-(. I will take a look on it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boostpro.com Mon Sep 21 18:51:43 2009 From: dave at boostpro.com (David Abrahams) Date: Mon, 21 Sep 2009 12:51:43 -0400 Subject: [C++-sig] Python 3 support has landed on boost trunk In-Reply-To: <4AB4D5A9.5060909@sympatico.ca> (Stefan Seefeld's message of "Sat, 19 Sep 2009 08:59:21 -0400") References: <4AB4D5A9.5060909@sympatico.ca> Message-ID: on Sat Sep 19 2009, Stefan Seefeld wrote: > Hi there, > > as some of you may know, Haoyu Bai has worked over the summer on Python 3 support for > Boost.Python. This work happened on a branch, which I merged back into trunk last > night. Whoo hoo! > Now we need to set up testers to run the testsuite with some Python 3 > variant, as that is a new platform to track. I will see whether I can > set one up on one of my machines. Thanks, Stefan and Haoyu! -- Dave Abrahams BoostPro Computing http://www.boostpro.com From roman.yakovenko at gmail.com Mon Sep 21 21:22:42 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 21 Sep 2009 22:22:42 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <7465b6170909210321r71b2fc61nc49dd360fe136556@mail.gmail.com> References: <4AB34CD8.4020400@tut.fi> <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> <4AB71D60.2000306@tut.fi> <7465b6170909210321r71b2fc61nc49dd360fe136556@mail.gmail.com> Message-ID: <7465b6170909211222i1a405089sb4c41d838dd5bc17@mail.gmail.com> On Mon, Sep 21, 2009 at 1:21 PM, Roman Yakovenko wrote: >> There is a small snag still: >> >> virtual_const_bindings.cpp:27: virhe: ?result? declared as reference >> but not initialized >> >> This comes from the following piece of code: >> >> ? ?static boost::python::object default_h( ::B & inst, ::A & x ){ >> ? ? ? ?C & result; >> ? ? ? ?if( dynamic_cast< B_wrapper * >( boost::addressof( inst ) ) ){ >> ? ? ? ? ? ?result = inst.::B::h(x); >> ? ? ? ?} >> ? ? ? ?else{ >> ? ? ? ? ? ?result = inst.h(x); >> ? ? ? ?} >> ? ? ? ?typedef bp::return_internal_reference< > call_policies_t; >> ? ? ? ?return bp::object( pyplusplus::call_policies::make_object< >> call_policies_t, ::C & >( result ) ); >> ? ?} > > > :-(. I will take a look on it. I hope it is fixed now: http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1759&view=rev A new test case was added. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Tue Sep 22 10:44:33 2009 From: pertti.kellomaki at tut.fi (=?windows-1252?Q?Pertti_Kellom=E4ki?=) Date: Tue, 22 Sep 2009 11:44:33 +0300 Subject: [C++-sig] Problems with virtualness and py++ In-Reply-To: <7465b6170909211222i1a405089sb4c41d838dd5bc17@mail.gmail.com> References: <4AB34CD8.4020400@tut.fi> <7465b6170909182310r6f56691cp849e6b31892e7874@mail.gmail.com> <7465b6170909191201r1a5fc49ai3d30a7b5de2d0a77@mail.gmail.com> <4AB71D60.2000306@tut.fi> <7465b6170909210321r71b2fc61nc49dd360fe136556@mail.gmail.com> <7465b6170909211222i1a405089sb4c41d838dd5bc17@mail.gmail.com> Message-ID: <4AB88E71.9050604@tut.fi> Roman Yakovenko wrote: > I hope it is fixed now: > http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1759&view=rev > > A new test case was added. Yes, this fixed it, thanks. I have some more problems but I'll take them to the pygccxml-development list. -- Pertti From austin.bingham at gmail.com Fri Sep 25 15:01:18 2009 From: austin.bingham at gmail.com (Austin Bingham) Date: Fri, 25 Sep 2009 15:01:18 +0200 Subject: [C++-sig] Fwd: [boost-python] Making a reference to the PyObject* in construct() In-Reply-To: References: Message-ID: I'm trying to figure out an issue that seems to have to do with the construct() method in a from-python conversion. I'm converting from a python string to a custom C++ string class. The c++ string just holds a reference to a python string using a boost::python::object. My construct() function looks like this: ?struct String_from_python_str ?{ ? ?. . . ? ?static void construct( ? ? ?PyObject* obj_ptr, ? ? ?boost::python::converter::rvalue_from_python_stage1_data* data) ? ? ?{ ? ? ? ?using namespace boost::python; ? ? ? ?void* storage = ( ? ? ? ? ? ?(converter::rvalue_from_python_storage*) ? ? ? ? ? ? data)->storage.bytes; ? ? ? ? ?new (storage) String(object(handle<>(obj_ptr))); ?// <---- Is this correct? Should it be borrowed? ? ? ? ? ?data->convertible = storage; ? ? ?} ?}; My program has started seeing occasional python reference counting problems and what appear to be memory corruption problems. I find that if I use a borrowed() handle when constructing my string, the problems go away. Is this correct? Or am I doing something totally else wrong here? I can't find any documentation re: the "borrowed" nature of obj_ptr, so I really just assumed that it was a normal, pre-incremented reference. Any help on this would be great. Thanks. Austin Bingham From troy at resophonic.com Sat Sep 26 18:07:15 2009 From: troy at resophonic.com (troy d. straszheim) Date: Sat, 26 Sep 2009 12:07:15 -0400 Subject: [C++-sig] Fwd: [boost-python] Making a reference to the PyObject* in construct() In-Reply-To: References: Message-ID: <4ABE3C33.1040108@resophonic.com> Austin Bingham wrote: > > I can't find any documentation re: the "borrowed" nature of obj_ptr, > so I really just assumed that it was a normal, pre-incremented > reference. Any help on this would be great. Thanks. > Here's a good thread on this, thanks to Alex Mohr: http://mail.python.org/pipermail/cplusplus-sig/2009-February/014294.html -t From austin.bingham at gmail.com Sun Sep 27 07:30:35 2009 From: austin.bingham at gmail.com (Austin Bingham) Date: Sun, 27 Sep 2009 07:30:35 +0200 Subject: [C++-sig] Fwd: [boost-python] Making a reference to the PyObject* in construct() In-Reply-To: <4ABE3C33.1040108@resophonic.com> References: <4ABE3C33.1040108@resophonic.com> Message-ID: Thanks for the link, but I think I misspoke a bit. I do understand borrowed vs. owned references in general, but I'm not sure about the pointer in the specific context of the construct() call. Is it borrowed or pre-incremented? However, a little poking around the boost.python source seems to indicate that it the pointers in that context are borrowed. The evidence I have is that boost.python's own shared_ptr converter, python/converter/shared_ptr_from_python.hpp, is using 'borrowed' when it forms a reference to the PyObject. So, can anyone verify that this is correct? Austin On Sat, Sep 26, 2009 at 6:07 PM, troy d. straszheim wrote: > Austin Bingham wrote: >> >> I can't find any documentation re: the "borrowed" nature of obj_ptr, >> so I really just assumed that it was a normal, pre-incremented >> reference. Any help on this would be great. Thanks. >> > > Here's a good thread on this, thanks to Alex Mohr: > > http://mail.python.org/pipermail/cplusplus-sig/2009-February/014294.html > > -t > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From cmbruns at stanford.edu Tue Sep 29 00:44:41 2009 From: cmbruns at stanford.edu (Christopher Bruns) Date: Mon, 28 Sep 2009 15:44:41 -0700 Subject: [C++-sig] [Py++] Help with wrapping setter methods Message-ID: Please help. I am just a beginner with pyplusplus and am not smart enough to see how to create certain complex rules. How would I create a pyplusplus rule for setting the return policy to "return internal reference" for all member functions that meet the following criteria: * method name begins with "set" * return type is a reference to the parent class or to one of its base classes I would sincerely appreciate an example that could do this. Then perhaps I might be able to figure out how to perform other clever manipulations. Thanks in advance for your help. ################################# struct Foo { // example of the sort of method I mean Foo& setBaz(int baz); // returns reference to self }; ################################# from pyplusplus import module_builder from pyplusplus.module_builder.call_policies import * mb = module_builder(...) # want "something" below... mb.decls().call_policies = return_internal_reference() ################################# --Chris Bruns From roman.yakovenko at gmail.com Tue Sep 29 10:27:09 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Sep 2009 10:27:09 +0200 Subject: [C++-sig] [Py++] Help with wrapping setter methods In-Reply-To: References: Message-ID: <7465b6170909290127oa3d9ccke6416b599634b035@mail.gmail.com> On Tue, Sep 29, 2009 at 12:44 AM, Christopher Bruns wrote: > Please help. ?I am just a beginner with pyplusplus and am not smart > enough to see how to create certain complex rules. > > How would I create a pyplusplus rule for setting the return policy to > "return internal reference" for all member functions that meet the > following criteria: > ?* method name begins with "set" > ?* return type is a reference to the parent class or to one of its base classes > > I would sincerely appreciate an example that could do this. ?Then > perhaps I might be able to figure out how to perform other clever > manipulations. ?Thanks in advance for your help. I suggest you to read the following document: http://language-binding.net/pygccxml/query_interface.html It should clarify few things > ################################# > struct Foo { > ? ?// example of the sort of method I mean > ? ?Foo& setBaz(int baz); // returns reference to self > }; > ################################# > from pyplusplus import module_builder > from pyplusplus.module_builder.call_policies import * > mb = module_builder(...) > # want "something" below... > mb.decls().call_policies = return_internal_reference() > ################################# from pygccxml import declarations def is_my_case( f ): if not f.name.startswith( 'set' ): return False rt = f.return_type if not rt: return False parent_ref = declarations.reference_t( declarations.declarated_t( f.parent ) ) return declarations.is_same( parent_ref, rt ) mb.member_functions(is_my_case).call_policies = return_internal_reference() Untested, but you should get the idea. It is also possible to write this query in more efficient form, but this I will leave to you :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Tue Sep 29 20:29:47 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 29 Sep 2009 21:29:47 +0300 Subject: [C++-sig] Boost Python objects and object identity Message-ID: <4AC2521B.6040700@tut.fi> I have Python bindings for a C++ library that among other things contains classes for describing the static structure of a microprocessor. My background is in Lisp, so I am used to using object identities (references) as keys. The C++ library can be used in this fashion, e.g. looking up a register file by name always returns the same object reference. However, the C++ to Python mapping does not preserve object identity, as a new Python object is created for every query, even if the underlying C++ reference is the same. Is there any easy way to preserve object identity in this sense with Boost Python? My first thought was to use some kind of caching scheme so that consequent queries with a particular name return the same object, but the problem is that objects are not only looked up by name, they can also be returned e.g. by asking for a parent object in a containment hierarchy. -- Pertti From renatox at gmail.com Tue Sep 29 20:42:39 2009 From: renatox at gmail.com (Renato Araujo) Date: Tue, 29 Sep 2009 15:42:39 -0300 Subject: [C++-sig] Boost Python objects and object identity In-Reply-To: <4AC2521B.6040700@tut.fi> References: <4AC2521B.6040700@tut.fi> Message-ID: <95291a80909291142w5b1e0d59ib4a0adc34f191f27@mail.gmail.com> Hi Pertti I had the same problem as you in my binding implementation, then I solve the problem using this function: // // a generator with an execute() function which, given a source type // and a pointer to an object of that type, returns its most-derived // /reachable/ type identifier and object pointer. // // first, the case where T has virtual functions template struct polymorphic_id_generator { static dynamic_id_t execute(void* p_) { T* p = static_cast(p_); return std::make_pair(dynamic_cast(p), class_id(typeid(*p))); } }; I use this function to get a pointer to most-derived type and use this as key in my hash table. BR Renato Araujo Oliveira Filho 2009/9/29 Pertti Kellom?ki : > I have Python bindings for a C++ library that among other > things contains classes for describing the static structure > of a microprocessor. > > My background is in Lisp, so I am used to using object > identities (references) as keys. The C++ library can > be used in this fashion, e.g. looking up a register file > by name always returns the same object reference. > However, the C++ to Python mapping does not preserve object > identity, as a new Python object is created for every query, > even if the underlying C++ reference is the same. > > Is there any easy way to preserve object identity in this > sense with Boost Python? My first thought was to use some > kind of caching scheme so that consequent queries with a > particular name return the same object, but the problem is > that objects are not only looked up by name, they can also > be returned e.g. by asking for a parent object in a containment > hierarchy. > -- > Pertti > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From roman.yakovenko at gmail.com Tue Sep 29 20:57:38 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Sep 2009 20:57:38 +0200 Subject: [C++-sig] Boost Python objects and object identity In-Reply-To: <4AC2521B.6040700@tut.fi> References: <4AC2521B.6040700@tut.fi> Message-ID: <7465b6170909291157w503790dby6df9755fe333f033@mail.gmail.com> 2009/9/29 Pertti Kellom?ki : > I have Python bindings for a C++ library that among other > things contains classes for describing the static structure > of a microprocessor. > > My background is in Lisp, so I am used to using object > identities (references) as keys. The C++ library can > be used in this fashion, e.g. looking up a register file > by name always returns the same object reference. > However, the C++ to Python mapping does not preserve object > identity, as a new Python object is created for every query, > even if the underlying C++ reference is the same. > > Is there any easy way to preserve object identity in this > sense with Boost Python? My first thought was to use some > kind of caching scheme so that consequent queries with a > particular name return the same object, but the problem is > that objects are not only looked up by name, they can also > be returned e.g. by asking for a parent object in a containment > hierarchy. A while ago I introduce to Py++ some kind of functionality, which integrates with CTYPES package. For example, you can expose "this" pointer to Python and use it as your id: http://language-binding.net/pyplusplus/documentation/ctypes/this_and_sizeof.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From amohr at pixar.com Tue Sep 29 20:48:05 2009 From: amohr at pixar.com (Alex Mohr) Date: Tue, 29 Sep 2009 11:48:05 -0700 Subject: [C++-sig] Boost Python objects and object identity In-Reply-To: <95291a80909291142w5b1e0d59ib4a0adc34f191f27@mail.gmail.com> References: <4AC2521B.6040700@tut.fi> <95291a80909291142w5b1e0d59ib4a0adc34f191f27@mail.gmail.com> Message-ID: <4AC25665.1090002@pixar.com> Renato Araujo wrote: > I had the same problem as you in my binding implementation, then I > solve the problem using this function: > > // > // a generator with an execute() function which, given a source type > // and a pointer to an object of that type, returns its most-derived > // /reachable/ type identifier and object pointer. > // > > // first, the case where T has virtual functions > template > struct polymorphic_id_generator > { > static dynamic_id_t execute(void* p_) > { > T* p = static_cast(p_); > return std::make_pair(dynamic_cast(p), class_id(typeid(*p))); > } > }; > > I use this function to get a pointer to most-derived type and use this > as key in my hash table. Cool -- how do you clean the table when an object is destroyed? Alex From pertti.kellomaki at tut.fi Tue Sep 29 22:04:29 2009 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 29 Sep 2009 23:04:29 +0300 Subject: [C++-sig] Boost Python objects and object identity In-Reply-To: <7465b6170909291157w503790dby6df9755fe333f033@mail.gmail.com> References: <4AC2521B.6040700@tut.fi> <7465b6170909291157w503790dby6df9755fe333f033@mail.gmail.com> Message-ID: <4AC2684D.4060906@tut.fi> Roman Yakovenko wrote: > For example, you can expose "this" pointer to Python and use it as your id: Thanks, this sounds like what I was looking for. -- Pertti From shetlandbob at hotmail.com Tue Sep 29 23:43:08 2009 From: shetlandbob at hotmail.com (Bob Cumming) Date: Tue, 29 Sep 2009 21:43:08 +0000 Subject: [C++-sig] Installing Boost VC9.0Express and Python 2.5.2 - import PYD complains about python26.dll!!?? Message-ID: Hello, I'm new to this list and have been trying to install boost to workk with C++ code in python. I downloaded the boost 1.39 windows installer and that worked ok. I followed the tutorials I found online at boost and the python wiki. All seemed to go ok. In directory: C:\boost\boost_1_39\libs\python\example\tutorial command bjam --preserve-test-target However I tried to run the hello example, at first I got the erros about the boost_python-vc90-mt-1_39.dll files so I copied them to the output directory, so I cd to the directory, then launch python and try to import the pyd file. I get the error (message box) "The application has failed to start because python26.dll was not found. Re-installing the applicaiton may fix this problem" Recall I have python 2.5.2 installed!? I tried re-running the bjam command and I get this: ...patience... ...found 1279 targets... ...updating 2 targets... capture-output bin\hello.test\msvc-9.0express\debug\threading-multi\hello ====== BEGIN OUTPUT ====== Traceback (most recent call last): File "hello.py", line 6, in import hello_ext ImportError: DLL load failed: The specified module could not be found. EXIT STATUS: 1 ====== END OUTPUT ====== set Path=C:\Python25;C:\Python25\libs;C:\boost\boost_1_39\bin.v2\libs\python\build\msvc-9.0express\debug\threading-multi;C:\boost\boost_1_39\libs\python\example\tutorial\bin\msvc-9.0express\debug\threading-multi;%Path% set PYTHONPATH=bin\msvc-9.0express\debug\threading-multi "C://Python25\python" "hello.py" > "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" 2>&1 set status=%ERRORLEVEL% echo. >> "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" echo EXIT STATUS: %status% >> "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" if %status% EQU 0 ( copy "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" "bin\hello.test\msvc-9.0express\debug\threading-multi\hello" ) set verbose=0 if %status% NEQ 0 ( set verbose=1 ) if %verbose% EQU 1 ( echo ====== BEGIN OUTPUT ====== type "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" echo ====== END OUTPUT ====== ) exit %status% ...failed capture-output bin\hello.test\msvc-9.0express\debug\threading-multi\hello... ...failed updating 1 target... ...skipped 1 target... C:\boost\boost_1_39\libs\python\example\tutorial>bjam --preserve-test-target ...patience... ...found 1279 targets... ...updating 2 targets... capture-output bin\hello.test\msvc-9.0express\debug\threading-multi\hello ====== BEGIN OUTPUT ====== Traceback (most recent call last): File "hello.py", line 6, in import hello_ext ImportError: DLL load failed: The specified module could not be found. EXIT STATUS: 1 ====== END OUTPUT ====== set Path=C:\Python25;C:\Python25\libs;C:\boost\boost_1_39\bin.v2\libs\python\build\msvc-9.0express\debug\threading-multi;C:\boost\boost_1_39\libs\python\example\tutorial\bin\msvc-9.0express\debug\threading-multi;%Path% set PYTHONPATH=bin\msvc-9.0express\debug\threading-multi "C://Python25\python" "hello.py" > "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" 2>&1 set status=%ERRORLEVEL% echo. >> "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" echo EXIT STATUS: %status% >> "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" if %status% EQU 0 ( copy "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" "bin\hello.test\msvc-9.0express\debug\threading-multi\hello" ) set verbose=0 if %status% NEQ 0 ( set verbose=1 ) if %verbose% EQU 1 ( echo ====== BEGIN OUTPUT ====== type "bin\hello.test\msvc-9.0express\debug\threading-multi\hello.output" echo ====== END OUTPUT ====== ) exit %status% ...failed capture-output bin\hello.test\msvc-9.0express\debug\threading-multi\hello... ...failed updating 1 target... JAMROOT: # Copyright David Abrahams 2006. Distributed under the Boost # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # Specify the path to the Boost project. If you move this project, # adjust this path to refer to the Boost root directory. use-project boost : C:/boost/boost_1_39 ; # Set up the project-wide requirements that everything uses the # boost_python library from the project whose global ID is # /boost/python. project : requirements /boost/python//boost_python ; # Declare the three extension modules. You can specify multiple # source files after the colon separated by spaces. python-extension hello_ext : hello.cpp ; # A little "rule" (function) to clean up the syntax of declaring tests # of these extension modules. local rule run-test ( test-name : sources + ) { import testing ; testing.make-test run-pyd : $(sources) : : $(test-name) ; } # Declare test targets run-test hello : hello_ext hello.py ; user-config # MSVC configuration using msvc : 9.0express ; # Python configuration using python : 2.5 : C://Python25 ; Sorry if this is a very long message, but thought more info should help the understanding. I have done this on two PC's, and got the same results.... Can anyone suggest any ideas on how to get this to work? Thanks for reading and any advice greatefully recieved. Cheers _________________________________________________________________ Get the best of MSN on your mobile http://clk.atdmt.com/UKM/go/147991039/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rfritz333 at gmail.com Wed Sep 30 00:34:22 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Tue, 29 Sep 2009 22:34:22 +0000 (UTC) Subject: [C++-sig] Anyone have Py++ working on a Mac? Message-ID: As the title says. From roman.yakovenko at gmail.com Wed Sep 30 07:44:23 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 30 Sep 2009 07:44:23 +0200 Subject: [C++-sig] Anyone have Py++ working on a Mac? In-Reply-To: References: Message-ID: <7465b6170909292244u777e810dh6864dca3f62fb2d1@mail.gmail.com> 2009/9/30 Randolph Fritz : > As the title says. Do you have a problem? In the past, few people reported that they successfully used Py++ and pygccxml on this platform. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rfritz333 at gmail.com Wed Sep 30 21:49:35 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Wed, 30 Sep 2009 19:49:35 +0000 (UTC) Subject: [C++-sig] Anyone have Py++ working on a Mac? References: <7465b6170909292244u777e810dh6864dca3f62fb2d1@mail.gmail.com> Message-ID: On 2009-09-30, Roman Yakovenko wrote: > 2009/9/30 Randolph Fritz : >> As the title says. > > Do you have a problem? > > In the past, few people reported that they successfully used Py++ and > pygccxml on this platform. > Do you have any specifics? I was hoping to learn from other people's experience before I tried to use it. There's no Mac release or instructions, so I'm not even sure I can get it to work. Randolph From roman.yakovenko at gmail.com Wed Sep 30 21:55:04 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 30 Sep 2009 21:55:04 +0200 Subject: [C++-sig] Anyone have Py++ working on a Mac? In-Reply-To: References: <7465b6170909292244u777e810dh6864dca3f62fb2d1@mail.gmail.com> Message-ID: <7465b6170909301255gb7290e8p339cea3471fdbf48@mail.gmail.com> On Wed, Sep 30, 2009 at 9:49 PM, Randolph Fritz wrote: > On 2009-09-30, Roman Yakovenko wrote: >> 2009/9/30 Randolph Fritz : >>> As the title says. >> >> Do you have a problem? >> >> In the past, few people reported that they successfully used Py++ and >> pygccxml on this platform. >> > > Do you have any specifics? No > I was hoping to learn from other people's > experience before I tried to use it. ?There's no Mac release or > instructions, so I'm not even sure I can get it to work. I don't have instructions for Linux and Windows. Both Py++ and pygccxml are pure Python packages and should work "ok" on any platform. I suggest you to start with GCCXML. If you will be able to install it, I am sure you will success with the rest. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rfritz333 at gmail.com Wed Sep 30 22:05:58 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Wed, 30 Sep 2009 20:05:58 +0000 (UTC) Subject: [C++-sig] Anyone have Py++ working on a Mac? References: <7465b6170909292244u777e810dh6864dca3f62fb2d1@mail.gmail.com> <7465b6170909301255gb7290e8p339cea3471fdbf48@mail.gmail.com> Message-ID: Oh, well. Thanks. Randolph On 2009-09-30, Roman Yakovenko wrote: > On Wed, Sep 30, 2009 at 9:49 PM, Randolph Fritz wrote: >> On 2009-09-30, Roman Yakovenko wrote: >>> 2009/9/30 Randolph Fritz : >>>> As the title says. >>> >>> Do you have a problem? >>> >>> In the past, few people reported that they successfully used Py++ and >>> pygccxml on this platform. >>> >> >> Do you have any specifics? > > No > >> I was hoping to learn from other people's >> experience before I tried to use it. ?There's no Mac release or >> instructions, so I'm not even sure I can get it to work. > > I don't have instructions for Linux and Windows. Both Py++ and > pygccxml are pure Python packages and should work "ok" on any > platform. I suggest you to start with GCCXML. If you will be able to > install it, I am sure you will success with the rest. > From amundson at fnal.gov Wed Sep 30 23:40:29 2009 From: amundson at fnal.gov (James Amundson) Date: Wed, 30 Sep 2009 16:40:29 -0500 Subject: [C++-sig] boost python to/from python type conversion Message-ID: <4AC3D04D.805@fnal.gov> Hi, I'm trying to write to/from type converters for my code, and I'm stuck. My case doesn't map well to any of those in the boost python documentation. I'm trying to pass objects of type MPI_Comm (really a C type!) back and forth with mpi4py (which uses cython internally.) The mpi4py author has provided a working example using manual wrapping. I am attaching it to the end of this message. On the C++ side I can extract a point to the MPI_Comm object from a Python object like so: PyObject* py_obj; // obviously, the value of py_obj has to be set somewhere... MPI_Comm *comm_p = PyMPIComm_Get(py_obj); I thought it would be simple to write a type converter to do that, but I don't understand the mechanics. This example doesn't seem to map onto the lvalue_from_pytype paradigm, or the scitbx container_conversion paradigm. Any suggestions? Thanks, Jim Amundson ----------------------------------- // working example with manual conversion #include #include static void sayhello(MPI_Comm comm) { if (comm == MPI_COMM_NULL) { std::cout << "You passed MPI_COMM_NULL !!!" << std::endl; return; } int size; MPI_Comm_size(comm, &size); int rank; MPI_Comm_rank(comm, &rank); int plen; char pname[MPI_MAX_PROCESSOR_NAME]; MPI_Get_processor_name(pname, &plen); std::cout << "Hello, World! " << "I am process " << rank << " of " << size << " on " << pname << "." << std::endl; } #include #include using namespace boost::python; static void hw_sayhello(object py_comm) { PyObject* py_obj = py_comm.ptr(); MPI_Comm *comm_p = PyMPIComm_Get(py_obj); if (comm_p == NULL) throw_error_already_set(); sayhello(*comm_p); } BOOST_PYTHON_MODULE(helloworld) { if (import_mpi4py() < 0) return; /* Python 2.X */ def("sayhello", hw_sayhello); } From cmbruns at stanford.edu Wed Sep 30 18:18:17 2009 From: cmbruns at stanford.edu (Christopher Bruns) Date: Wed, 30 Sep 2009 09:18:17 -0700 Subject: [C++-sig] [Py++] Does pyplusplus respect explicit constructors? Message-ID: Single-argument C++ constructors in pyplusplus seem to generate a boost::python::implicitly_convertible tag, even when the constructor is declared "explicit" in C++. That doesn't sound right to me. Shouldn't a pair of types that are not implicitly convertible in C++, also not be implicitly convertible in python? I suspect I can manually adjust the implicitly_convertible tag generation using the "allow_implicit_conversion" flag in pyplusplus. Is there a way to tell pyplusplus to avoid generating an implicitly_convertible tag for all explicit constructors? ########## test.h input source ############ class Foo { public: Foo() {} }; class Bar { public: // explicit constructor means don't implicitly convert Foo to Bar in C++ explicit Bar(Foo&) {} }; ############################### ########## wrap.py wrapping code #### from pyplusplus import module_builder mb = module_builder.module_builder_t(["test.h"] , gccxml_path = "C:\\Program Files\\gccxml_sherm\\bin\\gccxml.exe") mb.build_code_creator( module_name='test' ) mb.write_module( 'test_explicit.cpp' ) ################################## ##### generated test_explicit.cpp ###### // This file has been generated by Py++. #include "boost/python.hpp" #include "test.h" namespace bp = boost::python; BOOST_PYTHON_MODULE(test){ { //::Bar typedef bp::class_< Bar > Bar_exposer_t; Bar_exposer_t Bar_exposer = Bar_exposer_t( "Bar", bp::init< Foo & >(( bp::arg("arg0") )) ); bp::scope Bar_scope( Bar_exposer ); bp::implicitly_convertible< Foo &, Bar >(); // <-- *** I'm surprised by this *** } bp::class_< Foo >( "Foo", bp::init< >() ); } ##################################