From trigves at yahoo.com Fri Oct 1 12:57:37 2010 From: trigves at yahoo.com (Trigve Siver) Date: Fri, 1 Oct 2010 03:57:37 -0700 (PDT) Subject: [C++-sig] [python] base::get_override() exception set Message-ID: <619500.83792.qm@web110415.mail.gq1.yahoo.com> Hi, when calling get_override() method while trying to find python overload and overload is not found exception in python is set. This is because PyObject_GetAttrString() is used for retrieving the attribute. If attribute is not found, PyObject_GetAttrString() set the exception. This is using python 3.1. I've created ticket https://svn.boost.org/trac/boost/ticket/4701 with patch. Could anyone look at this? Thanks Trigve From mail at philippmuenzel.de Tue Oct 5 15:41:02 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Tue, 05 Oct 2010 15:41:02 +0200 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux Message-ID: <4CAB2AEE.4050605@philippmuenzel.de> Hi everyone, I'm trying to build a Boost.Python 32bit static library on a 64bit Linux (Suse 11.3). Of course, I have the respective python-devel and python32 packages for my platform installed. I build my minimal work environment of boost-thread, -system and -python with this command: sudo ./bjam install -q --layout=system --with-system --with-thread --with-python toolset=gcc variant=release link=static threading=multi runtime-link=static address-model=32 As long as I don't include the --with-python option, I get the expected result: 32bit static libraries. But with --with-python, I get the following error: gcc.compile.c++ bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o In file included from /usr/include/python2.6/Python.h:58:0, from ./boost/python/detail/wrap_python.hpp:142, from ./boost/python/detail/prefix.hpp:13, from ./boost/python/numeric.hpp:8, from libs/python/src/numeric.cpp:6: /usr/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." "g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pthread -m32 -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -DBOOST_PYTHON_STATIC_LIB -DNDEBUG -I"." -I"/usr/include/python2.6" -c -o "bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o" "libs/python/src/numeric.cpp" ...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o... ...failed updating 1 target... Apparently, my python headers in /usr/include/python2.6 make the assumption that on a 64bit platform one wants to build always 64bit libraries. How can I compile boost.python for 32bit without having to edit the respective header file and hard-coding the word size, which would render it unusable for a native build? Any help is appreciated. Regards, Philipp From charlessolar at gmail.com Tue Oct 5 16:02:33 2010 From: charlessolar at gmail.com (Charles Solar) Date: Tue, 5 Oct 2010 09:02:33 -0500 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux In-Reply-To: <4CAB2AEE.4050605@philippmuenzel.de> References: <4CAB2AEE.4050605@philippmuenzel.de> Message-ID: You need to compile boost python with a 32 bit version of python. The version bjam is finding is 64 bit. If you have a 32 bit python somewhere you need to tell bjam where to find the right headers. See this page http://www.boost.org/doc/libs/1_44_0/libs/python/doc/building.html#configuring-boost-build More than likely you are going to have to compile your own 32 bit version of python because the packages for your system are all going to be 64 bit, but it sounds like you may already have a 32 bit version installed. Also fyi, manually editing the python header file will not work. You may be able to compile but the machine's python will not be able to load the binaries. Charles On Tue, Oct 5, 2010 at 8:41 AM, Philipp M?nzel wrote: > Hi everyone, > > I'm trying to build a Boost.Python 32bit static library on a 64bit Linux > (Suse 11.3). > > Of course, I have the respective python-devel and python32 packages for > my platform installed. > > I build my minimal work environment of boost-thread, -system and -python > with this command: > > sudo ./bjam install -q --layout=system --with-system --with-thread > --with-python toolset=gcc variant=release link=static threading=multi > runtime-link=static address-model=32 > > As long as I don't include the --with-python option, I get the expected > result: ?32bit static libraries. > > But with --with-python, I get the following error: > > gcc.compile.c++ > bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o > In file included from /usr/include/python2.6/Python.h:58:0, > ? ? ? ? ? ? ? ? from ./boost/python/detail/wrap_python.hpp:142, > ? ? ? ? ? ? ? ? from ./boost/python/detail/prefix.hpp:13, > ? ? ? ? ? ? ? ? from ./boost/python/numeric.hpp:8, > ? ? ? ? ? ? ? ? from libs/python/src/numeric.cpp:6: > /usr/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT > definition appears wrong for platform (bad gcc/glibc config?)." > > ? ?"g++" ?-ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall > -pthread -m32 ?-DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE > -DBOOST_PYTHON_STATIC_LIB -DNDEBUG ?-I"." -I"/usr/include/python2.6" -c > -o > "bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o" > "libs/python/src/numeric.cpp" > > ...failed gcc.compile.c++ > bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o... > ...failed updating 1 target... > > Apparently, my python headers in /usr/include/python2.6 make the > assumption that on a 64bit platform one wants to build always 64bit > libraries. > > How can I compile boost.python for 32bit without having to edit the > respective header file and hard-coding the word size, which would render > it unusable for a native build? > > Any help is appreciated. > > Regards, > Philipp > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From mail at philippmuenzel.de Tue Oct 5 17:07:10 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Tue, 05 Oct 2010 17:07:10 +0200 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux In-Reply-To: References: <4CAB2AEE.4050605@philippmuenzel.de> Message-ID: <4CAB3F1E.6030006@philippmuenzel.de> Hi Charles, thanks for the fast answer! So I downloaded python 2.7 source and did: OPT=-m32 LDFLAGS=-m32 ./configure --prefix=/opt/pym32 make Unfortunately, the build fails: /bin/sh: line 1: 23704 Segmentation fault CC='gcc -pthread' LDSHARED='gcc -pthread -shared' LDFLAGS='-m32' OPT='-DNDEBUG -m32' ./python -E ./setup.py build make: *** [sharedmods] Error 139 Any thoughts? Philipp On 10/05/2010 04:02 PM, Charles Solar wrote: > You need to compile boost python with a 32 bit version of python. The > version bjam is finding is 64 bit. If you have a 32 bit python > somewhere you need to tell bjam where to find the right headers. See > this page http://www.boost.org/doc/libs/1_44_0/libs/python/doc/building.html#configuring-boost-build > > More than likely you are going to have to compile your own 32 bit > version of python because the packages for your system are all going > to be 64 bit, but it sounds like you may already have a 32 bit version > installed. > > Also fyi, manually editing the python header file will not work. You > may be able to compile but the machine's python will not be able to > load the binaries. > > Charles > > On Tue, Oct 5, 2010 at 8:41 AM, Philipp M?nzel wrote: >> Hi everyone, >> >> I'm trying to build a Boost.Python 32bit static library on a 64bit Linux >> (Suse 11.3). >> >> Of course, I have the respective python-devel and python32 packages for >> my platform installed. >> >> I build my minimal work environment of boost-thread, -system and -python >> with this command: >> >> sudo ./bjam install -q --layout=system --with-system --with-thread >> --with-python toolset=gcc variant=release link=static threading=multi >> runtime-link=static address-model=32 >> >> As long as I don't include the --with-python option, I get the expected >> result: 32bit static libraries. >> >> But with --with-python, I get the following error: >> >> gcc.compile.c++ >> bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o >> In file included from /usr/include/python2.6/Python.h:58:0, >> from ./boost/python/detail/wrap_python.hpp:142, >> from ./boost/python/detail/prefix.hpp:13, >> from ./boost/python/numeric.hpp:8, >> from libs/python/src/numeric.cpp:6: >> /usr/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT >> definition appears wrong for platform (bad gcc/glibc config?)." >> >> "g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall >> -pthread -m32 -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE >> -DBOOST_PYTHON_STATIC_LIB -DNDEBUG -I"." -I"/usr/include/python2.6" -c >> -o >> "bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o" >> "libs/python/src/numeric.cpp" >> >> ...failed gcc.compile.c++ >> bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o... >> ...failed updating 1 target... >> >> Apparently, my python headers in /usr/include/python2.6 make the >> assumption that on a 64bit platform one wants to build always 64bit >> libraries. >> >> How can I compile boost.python for 32bit without having to edit the >> respective header file and hard-coding the word size, which would render >> it unusable for a native build? >> >> Any help is appreciated. >> >> Regards, >> Philipp >> >> _______________________________________________ >> 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 seefeld at sympatico.ca Tue Oct 5 17:24:32 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 05 Oct 2010 11:24:32 -0400 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux In-Reply-To: <4CAB3F1E.6030006@philippmuenzel.de> References: <4CAB2AEE.4050605@philippmuenzel.de> <4CAB3F1E.6030006@philippmuenzel.de> Message-ID: <4CAB4330.6030301@sympatico.ca> On 10/05/2010 11:07 AM, Philipp M?nzel wrote: > Hi Charles, > > thanks for the fast answer! > So I downloaded python 2.7 source and did: > > OPT=-m32 LDFLAGS=-m32 ./configure --prefix=/opt/pym32 > make > > Unfortunately, the build fails: > > /bin/sh: line 1: 23704 Segmentation fault CC='gcc -pthread' > LDSHARED='gcc -pthread -shared' LDFLAGS='-m32' OPT='-DNDEBUG -m32' > ./python -E ./setup.py build > make: *** [sharedmods] Error 139 > > Any thoughts? I think you should bring this up on a more suitable forum, such as a Python mailing list. Stefan -- ...ich hab' noch einen Koffer in Berlin... From mail at philippmuenzel.de Tue Oct 5 17:33:57 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Tue, 05 Oct 2010 17:33:57 +0200 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux In-Reply-To: <4CAB3F1E.6030006@philippmuenzel.de> References: <4CAB2AEE.4050605@philippmuenzel.de> <4CAB3F1E.6030006@philippmuenzel.de> Message-ID: <4CAB4565.909@philippmuenzel.de> I also tried python 2.6.6 now, getting the same result. The core dump yields this stack trace: Core was generated by `./python -c import sys; print sys.maxint'. Program terminated with signal 11, Segmentation fault. #0 pmerge (type=0x0) at Objects/typeobject.c:1462 1462 to_merge_size = PyList_GET_SIZE(to_merge); (gdb) bt full #0 pmerge (type=0x0) at Objects/typeobject.c:1462 i = empty_cnt = remain = ok = j = to_merge_size = #1 mro_implementation (type=0x0) at Objects/typeobject.c:1589 i = n = 0 ok = -1 bases = 0x0 result = 0xf74ff7ec to_merge = 0x0 bases_aslist = #2 0x08150400 in ?? () No symbol table info available. Backtrace stopped: previous frame inner to this frame (corrupt stack?) Philipp On 10/05/2010 05:07 PM, Philipp M?nzel wrote: > Hi Charles, > > thanks for the fast answer! > So I downloaded python 2.7 source and did: > > OPT=-m32 LDFLAGS=-m32 ./configure --prefix=/opt/pym32 > make > > Unfortunately, the build fails: > > /bin/sh: line 1: 23704 Segmentation fault CC='gcc -pthread' > LDSHARED='gcc -pthread -shared' LDFLAGS='-m32' OPT='-DNDEBUG -m32' > ./python -E ./setup.py build > make: *** [sharedmods] Error 139 > > Any thoughts? > > Philipp > > On 10/05/2010 04:02 PM, Charles Solar wrote: >> You need to compile boost python with a 32 bit version of python. The >> version bjam is finding is 64 bit. If you have a 32 bit python >> somewhere you need to tell bjam where to find the right headers. See >> this page http://www.boost.org/doc/libs/1_44_0/libs/python/doc/building.html#configuring-boost-build >> >> More than likely you are going to have to compile your own 32 bit >> version of python because the packages for your system are all going >> to be 64 bit, but it sounds like you may already have a 32 bit version >> installed. >> >> Also fyi, manually editing the python header file will not work. You >> may be able to compile but the machine's python will not be able to >> load the binaries. >> >> Charles >> >> On Tue, Oct 5, 2010 at 8:41 AM, Philipp M?nzel wrote: >>> Hi everyone, >>> >>> I'm trying to build a Boost.Python 32bit static library on a 64bit Linux >>> (Suse 11.3). >>> >>> Of course, I have the respective python-devel and python32 packages for >>> my platform installed. >>> >>> I build my minimal work environment of boost-thread, -system and -python >>> with this command: >>> >>> sudo ./bjam install -q --layout=system --with-system --with-thread >>> --with-python toolset=gcc variant=release link=static threading=multi >>> runtime-link=static address-model=32 >>> >>> As long as I don't include the --with-python option, I get the expected >>> result: 32bit static libraries. >>> >>> But with --with-python, I get the following error: >>> >>> gcc.compile.c++ >>> bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o >>> In file included from /usr/include/python2.6/Python.h:58:0, >>> from ./boost/python/detail/wrap_python.hpp:142, >>> from ./boost/python/detail/prefix.hpp:13, >>> from ./boost/python/numeric.hpp:8, >>> from libs/python/src/numeric.cpp:6: >>> /usr/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT >>> definition appears wrong for platform (bad gcc/glibc config?)." >>> >>> "g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall >>> -pthread -m32 -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE >>> -DBOOST_PYTHON_STATIC_LIB -DNDEBUG -I"." -I"/usr/include/python2.6" -c >>> -o >>> "bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o" >>> "libs/python/src/numeric.cpp" >>> >>> ...failed gcc.compile.c++ >>> bin.v2/libs/python/build/gcc-4.5/release/address-model-32/link-static/runtime-link-static/threading-multi/numeric.o... >>> ...failed updating 1 target... >>> >>> Apparently, my python headers in /usr/include/python2.6 make the >>> assumption that on a 64bit platform one wants to build always 64bit >>> libraries. >>> >>> How can I compile boost.python for 32bit without having to edit the >>> respective header file and hard-coding the word size, which would render >>> it unusable for a native build? >>> >>> Any help is appreciated. >>> >>> Regards, >>> Philipp >>> >>> _______________________________________________ >>> 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 mail at philippmuenzel.de Tue Oct 5 17:48:19 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Tue, 05 Oct 2010 17:48:19 +0200 Subject: [C++-sig] How to compile Boost.Python for 32bit on 64bit Linux In-Reply-To: <4CAB4330.6030301@sympatico.ca> References: <4CAB2AEE.4050605@philippmuenzel.de> <4CAB3F1E.6030006@philippmuenzel.de> <4CAB4330.6030301@sympatico.ca> Message-ID: <4CAB48C3.6050808@philippmuenzel.de> Nevermind, got the python build problem solved. Apparently, I have to specify CFLAGS=-m32 instead of OPT=-m32 on my platform. Now I have a working 32bit installation of pyhton under /opt/pym32/ I now created a file named user-config.jam with the following content: using python : : /opt/pym32/bin/python ; as in the link posted by Charles. But the build still fails mentioning "In file included from /usr/include/python2.6/Python.h:58:0," so obviously the user-config.jam isn't being observed. Oh well, I just wanted to give boost.python a try and now I'm again spending a whole afternoon figuring out the different platform nightmares :( Philipp On 10/05/2010 05:24 PM, Stefan Seefeld wrote: > On 10/05/2010 11:07 AM, Philipp M?nzel wrote: >> Hi Charles, >> >> thanks for the fast answer! >> So I downloaded python 2.7 source and did: >> >> OPT=-m32 LDFLAGS=-m32 ./configure --prefix=/opt/pym32 >> make >> >> Unfortunately, the build fails: >> >> /bin/sh: line 1: 23704 Segmentation fault CC='gcc -pthread' >> LDSHARED='gcc -pthread -shared' LDFLAGS='-m32' OPT='-DNDEBUG -m32' >> ./python -E ./setup.py build >> make: *** [sharedmods] Error 139 >> >> Any thoughts? > > I think you should bring this up on a more suitable forum, such as a > Python mailing list. > > Stefan > From mail at philippmuenzel.de Wed Oct 6 12:33:55 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Wed, 06 Oct 2010 12:33:55 +0200 Subject: [C++-sig] Using boost.python with Makefile (no bjam) Message-ID: <4CAC5093.4010907@philippmuenzel.de> Hi everyone, thanks to hints on this list I've now got a working build of boost.python. I built the hello world exmaple (using the jam-file) and ran the testsuite with success. Now I want to get used to boost.python by exporting a few functions of a C++ lib I'm working on. This lib uses make as buildtool. Therefore I want to know how to setup a Makefile for boost.python. To start from ground up, I just took the example source code from libs/python/example/tutorial/hello.cpp and tried to compile and link it as a shared library. Unfortunately, there remain undefined symbols, which is why it cannot be loaded as python module. My boost installation is under /usr/local and is built in system layout as static libraries (libboost_x.a). $ cat hello.cpp // Copyright Joel de Guzman 2002-2004. 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) // Hello World Example from the tutorial // [Joel de Guzman 10/9/2002] #include #include char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } $ g++ -I/usr/local/include -I/usr/include/python -fpic -c -o hello.o hello.cpp $ g++ -shared -Wl,-soname,"libhello.so" -o libhello.so hello.o $ nm -u libhello.so U PyString_Type w _Jv_RegisterClasses U _Py_NoneStruct U _Unwind_Resume@@GCC_3.0 U _ZN5boost6python6detail11init_moduleEPKcPFvvE U _ZN5boost6python6detail12gcc_demangleEPKc U _ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_ U _ZN5boost6python7objects15function_objectERKNS1_11py_functionE U _ZN5boost6python7objects21py_function_impl_baseD2Ev U _ZN5boost6python9converter19do_return_to_pythonEPKc U _ZN5boost6python9converter8registry5queryENS0_9type_infoE U _ZNK5boost6python7objects21py_function_impl_base9max_arityEv U _ZNK5boost6python9converter12registration25expected_from_python_typeEv U _ZTIN5boost6python7objects21py_function_impl_baseE U _ZTIPKc@@CXXABI_1.3 U _ZTIc@@CXXABI_1.3 U _ZTVN10__cxxabiv120__si_class_type_infoE@@CXXABI_1.3 U _ZTVN5boost6python7objects21py_function_impl_baseE U _ZdlPv@@GLIBCXX_3.4 U _Znwm@@GLIBCXX_3.4 U __cxa_atexit@@GLIBC_2.2.5 w __cxa_finalize@@GLIBC_2.2.5 U __cxa_guard_abort@@CXXABI_1.3 U __cxa_guard_acquire@@CXXABI_1.3 U __cxa_guard_release@@CXXABI_1.3 w __gmon_start__ U __gxx_personality_v0@@CXXABI_1.3 $ python >>> import libhello Traceback (most recent call last): File "", line 1, in ImportError: ./libhello.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv So what is the big magic of bjam that when bjam links libboost_python.a I get no undefined symbols, but when i do it "by hand" i get these? Regards, Philipp From mail at philippmuenzel.de Wed Oct 6 12:43:09 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Wed, 06 Oct 2010 12:43:09 +0200 Subject: [C++-sig] Using boost.python with Makefile (no bjam) Message-ID: <4CAC52BD.8090304@philippmuenzel.de> Oh crap, the command that links is of course: $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python -o libhello.so hello.o But I get the undefined symbols nevertheless: U PyString_Type w _Jv_RegisterClasses U _Py_NoneStruct U _Unwind_Resume@@GCC_3.0 U _ZN5boost6python6detail11init_moduleEPKcPFvvE U _ZN5boost6python6detail12gcc_demangleEPKc U _ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_ U _ZN5boost6python7objects15function_objectERKNS1_11py_functionE U _ZN5boost6python7objects21py_function_impl_baseD2Ev U _ZN5boost6python9converter19do_return_to_pythonEPKc U _ZN5boost6python9converter8registry5queryENS0_9type_infoE U _ZNK5boost6python7objects21py_function_impl_base9max_arityEv U _ZNK5boost6python9converter12registration25expected_from_python_typeEv U _ZTIN5boost6python7objects21py_function_impl_baseE U _ZTIPKc@@CXXABI_1.3 U _ZTIc@@CXXABI_1.3 U _ZTVN10__cxxabiv120__si_class_type_infoE@@CXXABI_1.3 U _ZTVN5boost6python7objects21py_function_impl_baseE U _ZdlPv@@GLIBCXX_3.4 U _Znwj@@GLIBCXX_3.4 U __cxa_atexit@@GLIBC_2.1.3 w __cxa_finalize@@GLIBC_2.1.3 U __cxa_guard_abort@@CXXABI_1.3 U __cxa_guard_acquire@@CXXABI_1.3 U __cxa_guard_release@@CXXABI_1.3 w __gmon_start__ U __gxx_personality_v0@@CXXABI_1.3 From charlessolar at gmail.com Wed Oct 6 15:30:20 2010 From: charlessolar at gmail.com (Charles Solar) Date: Wed, 6 Oct 2010 08:30:20 -0500 Subject: [C++-sig] Using boost.python with Makefile (no bjam) In-Reply-To: <4CAC52BD.8090304@philippmuenzel.de> References: <4CAC52BD.8090304@philippmuenzel.de> Message-ID: You need to link with libpython as well. libpython should resolve these. On Wed, Oct 6, 2010 at 5:43 AM, Philipp M?nzel wrote: > Oh crap, the command that links is of course: > > $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python > -o libhello.so hello.o > > But I get the undefined symbols nevertheless: > U PyString_Type > ? ? ? ? w _Jv_RegisterClasses > ? ? ? ? U _Py_NoneStruct > ? ? ? ? U _Unwind_Resume@@GCC_3.0 > ? ? ? ? U _ZN5boost6python6detail11init_moduleEPKcPFvvE > ? ? ? ? U _ZN5boost6python6detail12gcc_demangleEPKc > ? ? ? ? U > _ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_ > ? ? ? ? U _ZN5boost6python7objects15function_objectERKNS1_11py_functionE > ? ? ? ? U _ZN5boost6python7objects21py_function_impl_baseD2Ev > ? ? ? ? U _ZN5boost6python9converter19do_return_to_pythonEPKc > ? ? ? ? U _ZN5boost6python9converter8registry5queryENS0_9type_infoE > ? ? ? ? U _ZNK5boost6python7objects21py_function_impl_base9max_arityEv > ? ? ? ? U > _ZNK5boost6python9converter12registration25expected_from_python_typeEv > ? ? ? ? U _ZTIN5boost6python7objects21py_function_impl_baseE > ? ? ? ? U _ZTIPKc@@CXXABI_1.3 > ? ? ? ? U _ZTIc@@CXXABI_1.3 > ? ? ? ? U _ZTVN10__cxxabiv120__si_class_type_infoE@@CXXABI_1.3 > ? ? ? ? U _ZTVN5boost6python7objects21py_function_impl_baseE > ? ? ? ? U _ZdlPv@@GLIBCXX_3.4 > ? ? ? ? U _Znwj@@GLIBCXX_3.4 > ? ? ? ? U __cxa_atexit@@GLIBC_2.1.3 > ? ? ? ? w __cxa_finalize@@GLIBC_2.1.3 > ? ? ? ? U __cxa_guard_abort@@CXXABI_1.3 > ? ? ? ? U __cxa_guard_acquire@@CXXABI_1.3 > ? ? ? ? U __cxa_guard_release@@CXXABI_1.3 > ? ? ? ? w __gmon_start__ > ? ? ? ? U __gxx_personality_v0@@CXXABI_1.3 > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From mail at philippmuenzel.de Wed Oct 6 16:07:05 2010 From: mail at philippmuenzel.de (=?ISO-8859-1?Q?Philipp_M=FCnzel?=) Date: Wed, 06 Oct 2010 16:07:05 +0200 Subject: [C++-sig] Using boost.python with Makefile (no bjam) In-Reply-To: References: <4CAC52BD.8090304@philippmuenzel.de> Message-ID: <4CAC8289.2040205@philippmuenzel.de> I added -lpython2.6 to the linker command, but I didn't change anything. Obviously, the missing symbols are boost symbols and not python symbols, since their names _ZN5boost6python6detail11init_moduleEPKcPFvvE clearly refer boost. I built boost_python with the following command: sudo ./bjam install -q --layout=system --with-python toolset=gcc variant=release link=static threading=multi runtime-link=static What is missing here? Philipp On 10/06/2010 03:30 PM, Charles Solar wrote: > You need to link with libpython as well. libpython should resolve these. > > On Wed, Oct 6, 2010 at 5:43 AM, Philipp M?nzel wrote: >> Oh crap, the command that links is of course: >> >> $ g++ -shared -Wl,-soname,"libhello.so" -L/usr/local/lib -lboost_python >> -o libhello.so hello.o >> >> But I get the undefined symbols nevertheless: >> U PyString_Type >> w _Jv_RegisterClasses >> U _Py_NoneStruct >> U _Unwind_Resume@@GCC_3.0 >> U _ZN5boost6python6detail11init_moduleEPKcPFvvE >> U _ZN5boost6python6detail12gcc_demangleEPKc >> U >> _ZN5boost6python6detail17scope_setattr_docEPKcRKNS0_3api6objectES3_ >> U _ZN5boost6python7objects15function_objectERKNS1_11py_functionE >> U _ZN5boost6python7objects21py_function_impl_baseD2Ev >> U _ZN5boost6python9converter19do_return_to_pythonEPKc >> U _ZN5boost6python9converter8registry5queryENS0_9type_infoE >> U _ZNK5boost6python7objects21py_function_impl_base9max_arityEv >> U >> _ZNK5boost6python9converter12registration25expected_from_python_typeEv >> U _ZTIN5boost6python7objects21py_function_impl_baseE >> U _ZTIPKc@@CXXABI_1.3 >> U _ZTIc@@CXXABI_1.3 >> U _ZTVN10__cxxabiv120__si_class_type_infoE@@CXXABI_1.3 >> U _ZTVN5boost6python7objects21py_function_impl_baseE >> U _ZdlPv@@GLIBCXX_3.4 >> U _Znwj@@GLIBCXX_3.4 >> U __cxa_atexit@@GLIBC_2.1.3 >> w __cxa_finalize@@GLIBC_2.1.3 >> U __cxa_guard_abort@@CXXABI_1.3 >> U __cxa_guard_acquire@@CXXABI_1.3 >> U __cxa_guard_release@@CXXABI_1.3 >> w __gmon_start__ >> U __gxx_personality_v0@@CXXABI_1.3 >> _______________________________________________ >> 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 thefireflyproject.us Thu Oct 7 07:55:47 2010 From: admin at thefireflyproject.us (Bryce Lelbach) Date: Thu, 7 Oct 2010 01:55:47 -0400 Subject: [C++-sig] Fw: [cfe-dev] Is Boost-Python tested? Message-ID: <20101007015547.18219a23@Pegasus> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello list, I'm a Boost regular - happened to come across this on the clang developer's list. I responded briefly to it, but I don't really have any knowledge of Boost.Python's internals. Therefore, forwarding it to you guys :P. - - Bryce Lelbach Begin forwarded message: Date: Wed, 06 Oct 2010 19:32:40 +0200 From: Riccardo Rossi To: cfe-dev at cs.uiuc.edu Subject: [cfe-dev] Is Boost-Python tested? Dear list, during the last two days i have been compiling my research code (around 500k lines of c++) using clang (clang 2.9 as downloaded from the svn 2 days ago). My code relies hevily on boost python.In doing my compilation i first compiled boost1.44 with clang (which went fine) and i later used it in compiling my code. Apart for minor issues the compilation went fine and the code runs correctly through the benchamrk example, HOWEVER on exit i get a segmentation fault. The segmentation fault is also confirmed by valgrind. Our code has been tested (and works correctly) using gcc, intel, sun and msvc (this last one in windows), and provides a pretty clean valgrind output (at least as clean as the boost python hello world example). I am honestly a bit surprised of having such a segfault on our test examples, and i was wandering if the boost_python stuff has been tested, in particular with reference to the allocation of "internal_references". please find attached the output of valgrind for the case of interest, where i just load our library in python and i close the program. for reference the gcc output (intel's is very similar) finishes with HEAP SUMMARY: ==6879== in use at exit: 1,866,386 bytes in 3,436 blocks ==6879== total heap usage: 9,373 allocs, 5,937 frees, 4,125,837 bytes allocated ==6879== ==6879== LEAK SUMMARY: ==6879== definitely lost: 0 bytes in 0 blocks ==6879== indirectly lost: 0 bytes in 0 blocks ==6879== possibly lost: 368,951 bytes in 361 blocks ==6879== still reachable: 1,497,435 bytes in 3,075 blocks ==6879== suppressed: 0 bytes in 0 blocks As a secondary thing, i wanted to comment that the compilation time is not better than gcc. I compiled the clang myself, so i probably did somethign wrong. In particular i attempted habilitating optimization, but i probably skipped something to have optimal performance. Any suggestion on how to make it faster? thank you in advance for any suggestion you can provide Riccardo - -- ________________________________________________________________ Riccardo Rossi, Ph.D, Civil Engineer member of the Kratos Group: kratos.cimne.upc.es Centro Internacional de M?todos Num?ricos en Ingenier?a (CIMNE) Universidad Polit?cnica de Catalu?a (UPC) Edificio C-1, campus Norte UPC Gran Capitan, s/n 08034 Barcelona, Espa?a Tel. (+34) 93 401 73 99 ________________________________________________________________ AVISO IMPORTANTE Los datos de car?cter personal contenidos en el mensaje, se registrar?n en un fichero para facilitar la gesti?n de las comunicaciones de CIMNE. Se pueden ejercitar los derechos de acceso, rectificaci?n, cancelaci?n y oposici?n por escrito, dirigi?ndose a nuestras oficinas de CIMNE, Gran Capit?n s/n, Edificio C1 - Campus Norte UPC, 08034 Barcelona, Espa?a. AV?S IMPORTANT Les dades de car?cter personal contingudes en aquest missatge es registraran en un fitxer per facilitar la gesti? de les comunicacions del CIMNE. Es poden exercir els drets d'acc?s, rectificaci?, cancel?laci? i oposici?, per escrit a les nostres oficines del CIMNE, Gran Capit? s/n, Edifici C1, Campus Nord UPC, 08034 Barcelona, Espanya. IMPORTANT NOTICE All personal data contained in this mail will be processed confidentially and stored in a file property of CIMNE in order to manage corporate communications. You may exercise the right of access, rectification, deletion and objection by letter sent to CIMNE, Gran Capit?n, Edificio C1 - Campus Norte UPC, 08034 Barcelona, Spain. - -- Bryce Lelbach aka wash http://groups.google.com/group/ariel_devel -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkytYOMACgkQO/fqqIuE2t6XMACfQRIia28fmKvxWTAqkvz+dWJ0 HwAAoNrwy2DaOCVsb40u7K0lm9UPSIEe =512P -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: clang_valgrind.log.tar.gz Type: application/x-compressed-tar Size: 10129 bytes Desc: not available URL: -------------- next part -------------- _______________________________________________ cfe-dev mailing list cfe-dev at cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev From marek at octogan.net Sat Oct 9 12:54:26 2010 From: marek at octogan.net (Marek Denis) Date: Sat, 09 Oct 2010 12:54:26 +0200 Subject: [C++-sig] shared_ptr and register_ptr_to_python Message-ID: <4CB049E2.7010602@octogan.net> Hello list, What I am trying to achieve is a part of C++ code operating on some data nad 'putting' some C++ defined (as well as Python exposed) objects into the Python blocking queues. Is there any possibility for Python to work directly on the C++ objects? Right now, when I launch the Python function from withing the C++ code, passing the POINTER (just normal pointer) od my objects what I can observer is a process of creating and copying the new object in Python. I can then operate on this object and so on, however I truly believe that working on the same object would be faster. Another problem is that I need to use some polymorphism functionality, so I would like to be able to put a object of type Derived from withing C++ code, get it from the Python perspective as Base object and launch virtual function (which would be Derived::f in this case). I am still not sure whether passing shared_ptr and using register_ptr_to_python is what I really need, wherether there is ANY possibility to do what I actually need. In other words I am creating objects with C++ but want to operate on them with Python, preferably with all the polimorphism and that fancy stuff. Any code snippets, suggestions? BTW. What options shall I pass to g++ in order to use shared_ptr? Thank you in advance, -- best regards Marek Denis [marek at octogan.net] From talljimbo at gmail.com Sun Oct 10 03:47:20 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sat, 09 Oct 2010 18:47:20 -0700 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB049E2.7010602@octogan.net> References: <4CB049E2.7010602@octogan.net> Message-ID: <4CB11B28.6000707@gmail.com> On 10/09/2010 03:54 AM, Marek Denis wrote: > Hello list, > > What I am trying to achieve is a part of C++ code operating on some data > nad 'putting' some C++ defined (as well as Python exposed) objects into > the Python blocking queues. > Is there any possibility for Python to work directly on the C++ objects? > Right now, when I launch the Python function from withing the C++ code, > passing the POINTER (just normal pointer) od my objects what I can > observer is a process of creating and copying the new object in Python. > I can then operate on this object and so on, however I truly believe > that working on the same object would be faster. > Another problem is that I need to use some polymorphism functionality, > so I would like to be able to put a object of type Derived from withing > C++ code, get it from the Python perspective as Base object and launch > virtual function (which would be Derived::f in this case). > I am still not sure whether passing shared_ptr and using > register_ptr_to_python is what I really need, wherether there is ANY > possibility to do what I actually need. In other words I am creating > objects with C++ but want to operate on them with Python, preferably > with all the polimorphism and that fancy stuff. Any code snippets, > suggestions? > BTW. What options shall I pass to g++ in order to use shared_ptr? > Thank you in advance, > Pretty much everything you need should automatically work, whether you use shared_ptr or raw pointers with call policies. If you've invoked register_ptr_to_python on all the classes you're using, you'll find that in Python you'll always get the most-derived class, even if it's returned as a base class pointer or smart pointer on the C++ side. You shouldn't need any extra compiler flags. Just use Boost.Python the way described in the tutorial, and throw in some register_ptr_to_python invocations - that should be all you need. HTH! Jim Bosch From marek at octogan.net Sun Oct 10 14:26:24 2010 From: marek at octogan.net (Marek Denis) Date: Sun, 10 Oct 2010 14:26:24 +0200 Subject: [C++-sig] Fwd: Re: shared_ptr and register_ptr_to_python Message-ID: <4CB1B0F0.7040509@octogan.net> On 10.10.2010 03:47, Jim Bosch wrote: > > Pretty much everything you need should automatically work, whether you > use shared_ptr or raw pointers with call policies. If you've invoked > register_ptr_to_python on all the classes you're using, That's what I couldn't get while reading Boost tutorial (the example code didn't work either :( ). Let's say I have three classes: class A {}; class B : public A {}; class C : public B {}; should I later just put: register_ptr_to_python< A >(); register_ptr_to_python< B >(); register_ptr_to_python< C >(); ? > you'll find that > in Python you'll always get the most-derived class, even if it's > returned as a base class pointer or smart pointer on the C++ side. Here is the small code snippet: +v boost::python::call_method(callback,"addToQueue",c); -v where callback is a PyObject* pointer,and 'c' is a pointer to the object. Whenever I call this instruction, I can see that the 'c' object is being copied (I just put some cout << "debug" << endl in the definition of the Copy Constructor), so I assumed that Python code doesn't operate on the object that was created in C++ module. Instead, it just operates on the copy. > You shouldn't need any extra compiler flags. Just use Boost.Python the > way described in the tutorial, and throw in some register_ptr_to_python > invocations - that should be all you need. -- best wishes Marek Denis From talljimbo at gmail.com Sun Oct 10 20:15:15 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sun, 10 Oct 2010 11:15:15 -0700 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB19C3E.1060801@octogan.net> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> Message-ID: <4CB202B3.2030701@gmail.com> On 10/10/2010 03:58 AM, Marek Denis wrote: > On 10.10.2010 03:47, Jim Bosch wrote: >> >> Pretty much everything you need should automatically work, whether you >> use shared_ptr or raw pointers with call policies. If you've invoked >> register_ptr_to_python on all the classes you're using, > > That's what I couldn't get while reading Boost tutorial (the example > code didn't work either :( ). > Let's say I have three classes: > > class A {}; > class B : public A {}; > class C : public B {}; > > should I later just put: > register_ptr_to_python< A >(); > register_ptr_to_python< B >(); > register_ptr_to_python< C >(); > ? Actually, you want something like this: register_ptr_to_python< boost::shared_ptr >(); If you want to use raw pointers, I don't think you need register_ptr_to_python (see below). > Here is the small code snippet: > > +v > boost::python::call_method(callback,"addToQueue",c); > -v > > where callback is a PyObject* pointer,and 'c' is a pointer to the object. > Whenever I call this instruction, I can see that the 'c' object is being > copied (I just put some cout << "debug" << endl in the definition of the > Copy Constructor), so I assumed that Python code doesn't operate on the > object that was created in C++ module. Instead, it just operates on the > copy. > I'm actually kind of surprised about this - in other circumstances (particularly when returning values in wrapped functions by pointer), Boost.Python doesn't copy pointers or references unless you explicitly ask it to. One thing that may be worth trying: when you wrap C Python, mark it as noncopyable: class_,boost::noncopyable>("C") I'd be curious to see what happens with your call_method code snippet with that in place. In any case, if you're willing to use shared_ptr everywhere instead of raw pointers, and switch your register_ptr_to_python calls as I've shown above, I think that will also stop any copying that's going on here. There should be a way to do it with raw pointers too, but I don't see it yet (and it may not exist). Jim From marek at octogan.net Sun Oct 10 23:16:59 2010 From: marek at octogan.net (Marek Denis) Date: Sun, 10 Oct 2010 23:16:59 +0200 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB202B3.2030701@gmail.com> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> <4CB202B3.2030701@gmail.com> Message-ID: <4CB22D4B.9050609@octogan.net> On 10.10.2010 20:15, Jim Bosch wrote: > Actually, you want something like this: > > register_ptr_to_python< boost::shared_ptr >(); > > If you want to use raw pointers, I don't think you need > register_ptr_to_python (see below). You are right. > I'm actually kind of surprised about this - in other circumstances > (particularly when returning values in wrapped functions by pointer), > Boost.Python doesn't copy pointers or references unless you explicitly > ask it to. I did some tests to check it out (you can check the code at [1] ) and noticed, that when I launch the +v boost::python::call_method(callback,"addToQueue",c); -v piece of code, the object is copied after using self.queue.get() in the python script. This may be the magic (and/or implementation of the Queue.Queue) of Python layer, not Boost.Python itself. So I believe I will have to live with the pointless (in this case) memory copying in my program :) > One thing that may be worth trying: when you wrap C Python, > mark it as noncopyable: > > class_,boost::noncopyable>("C") > > I'd be curious to see what happens with your call_method code snippet > with that in place. I will let you know when I find somthing out. [1] http://marek.octogan.net/python/ Using raw pointers is enough in my case, shared_ptrs would be safer, as different threads may delete object. -- Marek Denis From talljimbo at gmail.com Mon Oct 11 00:42:59 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sun, 10 Oct 2010 15:42:59 -0700 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB22D4B.9050609@octogan.net> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> <4CB202B3.2030701@gmail.com> <4CB22D4B.9050609@octogan.net> Message-ID: <4CB24173.7010007@gmail.com> On 10/10/2010 02:16 PM, Marek Denis wrote: > I did some tests to check it out (you can check the code at [1] ) > and noticed, that when I launch the > +v > boost::python::call_method(callback,"addToQueue",c); > -v > > piece of code, the object is copied after using self.queue.get() in the > python script. This may be the magic (and/or implementation of the > Queue.Queue) of Python layer, not Boost.Python itself. > So I believe I will have to live with the pointless (in this case) > memory copying in my program :) > >> One thing that may be worth trying: when you wrap C Python, >> mark it as noncopyable: >> >> class_,boost::noncopyable>("C") >> >> I'd be curious to see what happens with your call_method code snippet >> with that in place. > > I will let you know when I find somthing out. > > [1] http://marek.octogan.net/python/ > > Using raw pointers is enough in my case, shared_ptrs would be safer, as > different threads may delete object. > It is indeed call_method that's generating the copy; because there's no place for a call policy there, it tries to use a by-value converter. If you try it with boost::noncopyable, it refuses to compile for exactly that reason. I'm surprised that's it's behavior (I don't think it's really consistent with the rest of Boost.Python, but it is what it is). Essentially, what you need to do is pass a Python object to call_method (boost::python::object or PyObject *) that already contains your C++ object. In order to get one, you need need to tell Boost.Python to construct A and B with what it calls a "back reference". Your C++ constructors will be given a PyObject* by boost.python, pointing to the Python objects the C++ object will be wrapped in, and you can then store those as data members and pass the PyObject * to call_method. You can find more information in the Boost.Python reference docs on class_, especially the "HeldType Semantics" section. By the way, the call policies on your "gen" function should be return_value_policy, not return_internal_reference<>; the latter is for returning data members of wrapped classes and other things that are owned by another existing wrapped object. Jim From marek at octogan.net Mon Oct 11 19:49:37 2010 From: marek at octogan.net (Marek Denis) Date: Mon, 11 Oct 2010 19:49:37 +0200 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB24173.7010007@gmail.com> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> <4CB202B3.2030701@gmail.com> <4CB22D4B.9050609@octogan.net> <4CB24173.7010007@gmail.com> Message-ID: <4CB34E31.1020605@octogan.net> On 11.10.2010 00:42, Jim Bosch wrote: > Essentially, what you need to do is pass a Python object to call_method > (boost::python::object or PyObject *) that already contains your C++ > object. In order to get one, you need need to tell Boost.Python to > construct A and B with what it calls a "back reference". Your C++ > constructors will be given a PyObject* by boost.python, pointing to the > Python objects the C++ object will be wrapped in, and you can then store > those as data members and pass the PyObject * to call_method. You can > find more information in the Boost.Python reference docs on class_, > especially the "HeldType Semantics" section. I did checked the docs, but I think I don't get how should it be done in my case. What they talk about (as well as in the provided example) They let the user to create Python classes derived from C++ classes and launchind virtual Python function. Would ou mind providing a sample piece of code how should it be done to wrap my C++ object into PyObject* ? Thanks in advance. > By the way, the call policies on your "gen" function should be > return_value_policy, not return_internal_reference<>; > the latter is for returning data members of wrapped classes and other > things that are owned by another existing wrapped object. Good point, thanks! -- regards Marek Denis From talljimbo at gmail.com Mon Oct 11 22:01:04 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Mon, 11 Oct 2010 13:01:04 -0700 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB34E31.1020605@octogan.net> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> <4CB202B3.2030701@gmail.com> <4CB22D4B.9050609@octogan.net> <4CB24173.7010007@gmail.com> <4CB34E31.1020605@octogan.net> Message-ID: <4CB36D00.4000607@gmail.com> On 10/11/2010 10:49 AM, Marek Denis wrote: > On 11.10.2010 00:42, Jim Bosch wrote: > >> Essentially, what you need to do is pass a Python object to call_method >> (boost::python::object or PyObject *) that already contains your C++ >> object. In order to get one, you need need to tell Boost.Python to >> construct A and B with what it calls a "back reference". Your C++ >> constructors will be given a PyObject* by boost.python, pointing to the >> Python objects the C++ object will be wrapped in, and you can then store >> those as data members and pass the PyObject * to call_method. You can >> find more information in the Boost.Python reference docs on class_, >> especially the "HeldType Semantics" section. > > I did checked the docs, but I think I don't get how should it be done in > my case. What they talk about (as well as in the provided example) > They let the user to create Python classes derived from C++ classes and > launchind virtual Python function. Would ou mind providing a sample > piece of code how should it be done to wrap my C++ object into PyObject* > ? Thanks in advance. > I think this is something like what you want to do: ----------------------------------------- namespace bp = boost::python class A { public: std::string getData() { return _data; } void setCallback(bp::object const & callback) { _callback = callback; } bp::object invokeCallback() { return _callback(getSelf()); } virtual PyObject * getSelf() const = 0; virtual ~A() {} explicit A(std::string const & data) : _data(data) {} private: std::string _data; bp::object _callback; }; class B : public A { public: explicit B(std::string const & data) : A(data) {} }; class PyA : public A { public: PyA(PyObject * self, std::string const & data) : A(data), _self(self) {} virtual PyObject * getSelf() const { return _self; } private: PyObject * _self; }; class PyB : public B { public: PyB(PyObject * self, std::string const & data) : B(data), _self(self) {} virtual PyObject * getSelf() const { return _self; } private: PyObject * _self; }; BOOST_PYTHON_MODULE(example) { bp::class_("A", bp::init(bp::arg("data"))) .add_property("data", &A::getData) .def("setCallback", &A::setCallback) .def("invokeCallback", &A::invokeCallback) bp::class_,PyB>( "B", bp::init(bp::arg("data")) ); } ----------------------------------------- A couple of notes: - I have not tested this. Likely there are some typos, and possibly even a bit of forgotten syntax - hopefully it's easy to correct. - Note that there's no need to re-wrap the methods that B inherits from A, but you do have create both PyA and PyB if you want both A and B to be instantiable from Python (after all, getSelf() is pure virtual). - If you have a C++ function that returns an A or B instance by reference or pointer, this code will still work. Of course, such an object will have to find some other way to implement getSelf() - only objects instantiated in Python will actually be PyA or PyB instances. - I didn't actually use call_method anywhere, because bp::object has an overloaded operator() that does what you need (and using object here is better than PyObject because it handles the reference counting; you don't use it for _self because we don't want reference counting there). - This is a little non-standard because the base classes A and B are Python-aware and are pure virtual - but that makes sense, because your pattern requires that all C++ objects have a back-reference to their Python selves. - I think there's a way to do this that merges each class with it's Python counterpart (i.e., it tells Boost.Python that A has a constructor that takes the special "self" argument), and it has something to do with specializing a template traits class. But I haven't ever done it, and I don't want to lead you astray. HTH! Jim From gipson_b at yahoo.com Thu Oct 14 19:17:13 2010 From: gipson_b at yahoo.com (Bryant Gipson) Date: Thu, 14 Oct 2010 10:17:13 -0700 (PDT) Subject: [C++-sig] Using C++ classes exposed by other modules Message-ID: <349895.47297.qm@web82605.mail.mud.yahoo.com> Hi All, Maybe a simple question, maybe not: I have a binary-only module which was automatically generated by Py++ and its associated pre-compiled C++ libraries.? There's a basic C++ type "A" which was exposed along with plenty of support functions in the associated C++ library which operate on it in both C++ and Python.? i.e. python: a = mod.A(); mod.helpfulFunction(a);?>>Some helpful output.? My problem is now I want to write a module which operates on the C++ class A. C++: void mySlightlyHelpfulFunction(cppmodule::A &a) { ? ... } BOOST_PYTHON_MODULE(myModule) { ? def("mySlightlyHelpfulFunction",mySlightlyHelpfulFunction); } Python: a = mod.A() myModule.mySlightlyHelpfulFunction(a) ??? myModule.mySlightlyHelpfulFunction(A) did not match C++ signature: ??? mySlightlyHelpfulFunction(mod::A {lvalue}) I've also tried this with Py++ with the same results. Thus far it appears that no converter has been globally registered by the module mod. Any help would be hugely appreciated. I apologise if this is a trivial question, I'm still new to hybrid C++/python. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Thu Oct 14 21:01:15 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Thu, 14 Oct 2010 12:01:15 -0700 Subject: [C++-sig] Using C++ classes exposed by other modules In-Reply-To: <349895.47297.qm@web82605.mail.mud.yahoo.com> References: <349895.47297.qm@web82605.mail.mud.yahoo.com> Message-ID: <4CB7537B.6080101@gmail.com> On 10/14/2010 10:17 AM, Bryant Gipson wrote: > Hi All, > > Maybe a simple question, maybe not: > > I have a binary-only module which was automatically generated by Py++ > and its associated pre-compiled C++ libraries. > > There's a basic C++ type "A" which was exposed along with plenty of > support functions in the associated C++ library which operate on it in > both C++ and Python. > > i.e. > > python: > a = mod.A(); > mod.helpfulFunction(a); > >>Some helpful output. > > My problem is now I want to write a module which operates on the C++ > class A. > > C++: > > void mySlightlyHelpfulFunction(cppmodule::A &a) > { > ... > } > > BOOST_PYTHON_MODULE(myModule) > { > def("mySlightlyHelpfulFunction",mySlightlyHelpfulFunction); > } > > Python: > a = mod.A() > myModule.mySlightlyHelpfulFunction(a) > myModule.mySlightlyHelpfulFunction(A) > did not match C++ signature: > mySlightlyHelpfulFunction(mod::A {lvalue}) > > I've also tried this with Py++ with the same results. > Thus far it appears that no converter has been globally registered by > the module mod. > > Any help would be hugely appreciated. > > I apologise if this is a trivial question, I'm still new to hybrid > C++/python. > This *should* work without anything extra, and generally does in a lot of my own code. All I can think of is that your two modules somehow are getting different copies of the Boost.Python registry (maybe that happens with static linking to the Boost Python library - if that's even possible?) What platform/compiler are you using? Jim Bosch From themiwi at users.sourceforge.net Fri Oct 15 09:13:41 2010 From: themiwi at users.sourceforge.net (Michael Wild) Date: Fri, 15 Oct 2010 09:13:41 +0200 Subject: [C++-sig] Docstrings question Message-ID: Hi all I'm fairly new to Boost.Python and currently I'm looking for a convenient way of adding docstrings to overloaded operators, e.g: class A; class B A operator+(A const&, A const&); B operator+(B const&, B const&); BOOST_PYTHON_MODULE(foo) { bp::class_("A") .def(self + self) //< How to add docstring here? } I know I could also use: A (*A_add_op)(A const&, A const&) = operator+; bp::class_("A") .def("__add__", A_add_op, "Add two A objects") or a direct cast, but honestly, I don't look forward to all that typing, and it is so much harder to read than the first option. Thanks for the help Michael -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 487 bytes Desc: This is a digitally signed message part URL: From avibahra at googlemail.com Fri Oct 15 15:39:53 2010 From: avibahra at googlemail.com (Avi Bahra) Date: Fri, 15 Oct 2010 14:39:53 +0100 Subject: [C++-sig] building boost python --threading mystery ? Message-ID: Trying to understand --threading option when applied to building boost python On Linux with gcc it appears to have no effect. bjam toolset=gcc --with-python link=shared variant=debug --threading=single Building the Boost C++ Libraries. ...patience... ...patience... ...found 1489 targets... ...updating 40 targets... common.mkdir bin.v2 common.mkdir bin.v2/libs common.mkdir bin.v2/libs/python common.mkdir bin.v2/libs/python/build common.mkdir bin.v2/libs/python/build/gcc-4.2.1 common.mkdir bin.v2/libs/python/build/gcc-4.2.1/debug common.mkdir bin.v2/libs/python/build/gcc-4.2.1/debug/threading-multi gcc.compile.c++ bin.v2/libs/python/build/gcc-4.2.1/debug/threading-multi/numeric.o When I specify "--threading=single" it appears to be ignored: Even putting a rubbish value has no effect ? --threading=gooblygook bjam toolset=gcc --with-python link=shared variant=debug --threading=gooblygook nBuilding the Boost C++ Libraries.nn ...patience... ...patience... ...found 1489 targets... ...updating 19 targets... gcc.compile.c++ bin.v2/libs/python/build/gcc-4.2.1/debug/threading-multi/object/function.o However if you have Jamfile that has "using python" like boost python examples then it gets built as : bjam ...patience... ...patience... ...patience... ...found 12311 targets... ...updating 42 targets... common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2 common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python/build common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python/build/gcc-4.2.1 common.mkdir /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python/build/gcc-4.2.1/debug gcc.compile.c++ /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python/build/gcc-4.2.1/debug/numeric.o gcc.compile.c++ /var/tmp/ma0/boost/boost_1_43_0/bin.v2/libs/python/build/gcc-4.2.1/debug/list.o This time there is no mention of threading ? So it appears that when building boost python at $BOOST_ROOT level it is fixed as multi threaded but then gets ignored when building python extensions. The net result being two builds of boost python. Best regards, Avi From nat at lindenlab.com Tue Oct 19 14:10:28 2010 From: nat at lindenlab.com (Nat Linden) Date: Tue, 19 Oct 2010 08:10:28 -0400 Subject: [C++-sig] Using C++ classes exposed by other modules In-Reply-To: <349895.47297.qm@web82605.mail.mud.yahoo.com> References: <349895.47297.qm@web82605.mail.mud.yahoo.com> Message-ID: On Thu, Oct 14, 2010 at 1:17 PM, Bryant Gipson wrote: C++: > > void mySlightlyHelpfulFunction(cppmodule::A &a) > { > ... > } > > Python: > a = mod.A() > myModule.mySlightlyHelpfulFunction(a) > myModule.mySlightlyHelpfulFunction(A) > did not match C++ signature: > mySlightlyHelpfulFunction(mod::A {lvalue}) > Just a guess, but would declaring it as: void mySlightlyHelpfulFunction(const cppmodule::A &a) work better? (Note insertion of "const") The {lvalue} in the signature output suggests that the problem could be that Boost.Python is internally constructing a C++ temporary cppmodule::A value and trying to pass it into mySlightlyHelpfulFunction(). -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Tue Oct 19 20:04:03 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 19 Oct 2010 11:04:03 -0700 Subject: [C++-sig] Using C++ classes exposed by other modules In-Reply-To: References: <349895.47297.qm@web82605.mail.mud.yahoo.com> Message-ID: <4CBDDD93.20500@gmail.com> On 10/19/2010 05:10 AM, Nat Linden wrote: > On Thu, Oct 14, 2010 at 1:17 PM, Bryant Gipson > wrote: > > C++: > > void mySlightlyHelpfulFunction(cppmodule::A &a) > { > ... > } > > Python: > a = mod.A() > myModule.mySlightlyHelpfulFunction(a) > myModule.mySlightlyHelpfulFunction(A) > did not match C++ signature: > mySlightlyHelpfulFunction(mod::A {lvalue}) > > > Just a guess, but would declaring it as: > > void mySlightlyHelpfulFunction(const cppmodule::A &a) > > work better? (Note insertion of "const") > > The {lvalue} in the signature output suggests that the problem could be > that Boost.Python is internally constructing a C++ temporary > cppmodule::A value and trying to pass it into mySlightlyHelpfulFunction(). > That would help in other, similar, similar cases, but wasn't the problem here. The OP replied off-line; he was simply linking to the wrong Boost.Python library. Sorry I neglected to pass it on to the list! Jim From ndbecker2 at gmail.com Wed Oct 20 02:14:35 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 19 Oct 2010 20:14:35 -0400 Subject: [C++-sig] boost::python + python3.1.2 throw Message-ID: Has behavior of c++ exception changed with boost::python + python3? I used to simply use throw from c++. Now I get: SystemError: initialization of ldpc_45 raised unreported exception I believe this exception was really: if (!fp) throw std::runtime_error ((boost::format ("fopen %1% failed") % name).str()); which would have produced a good error message under python2.6. From ndbecker2 at gmail.com Wed Oct 20 03:32:15 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 19 Oct 2010 21:32:15 -0400 Subject: [C++-sig] boost::python + python3.1.2 throw References: Message-ID: Neal Becker wrote: > Has behavior of c++ exception changed with boost::python + python3? > > I used to simply use throw from c++. Now I get: > SystemError: initialization of ldpc_45 raised unreported exception > > I believe this exception was really: > if (!fp) > throw std::runtime_error ((boost::format ("fopen %1% failed") % > name).str()); > > which would have produced a good error message under python2.6. I think this difference in behavior is for an exception thrown during module initialization? A c++ exception thrown after initialization seems to behave as before. From ndbecker2 at gmail.com Wed Oct 20 23:17:46 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 20 Oct 2010 17:17:46 -0400 Subject: [C++-sig] boost::python + python3.1.2 throw References: Message-ID: Neal Becker wrote: > Neal Becker wrote: > >> Has behavior of c++ exception changed with boost::python + python3? >> >> I used to simply use throw from c++. Now I get: >> SystemError: initialization of ldpc_45 raised unreported exception >> >> I believe this exception was really: >> if (!fp) >> throw std::runtime_error ((boost::format ("fopen %1% failed") % >> name).str()); >> >> which would have produced a good error message under python2.6. > > I think this difference in behavior is for an exception thrown > during module initialization? > > A c++ exception thrown after initialization seems to behave as before. Just confirmed, under python2.6 I get my nice error message: Traceback (most recent call last): File "test_btr_equal_coded.py", line 570, in run (sys.argv[1:]) File "test_btr_equal_coded.py", line 148, in run from ldpc_45 import encoder, decoder, N, K RuntimeError: fopen H23_64800_7-50_3-50_3.dat failed But on python3.1.2 I just get SystemError: initialization of ldpc_45 raised unreported exception From rwgk at yahoo.com Wed Oct 20 23:51:58 2010 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 20 Oct 2010 14:51:58 -0700 (PDT) Subject: [C++-sig] boost::python + python3.1.2 throw In-Reply-To: References: Message-ID: <66682.62612.qm@web111410.mail.gq1.yahoo.com> I'm not sure how much Boost.Python is used with Python 3. Haoyu and Troy have done all the fundamental work in the 2009 GSOC project, but the Python 3 support isn't routinely exercised as far as I know. We need a volunteer to establish and maintain routine Python 3 testing, and possibly fix bugs like you are observing. (I still don't have any interest in Python 3 myself since my primary project depends on a myriad of tools that don't support Python 3.) Ralf ----- Original Message ---- > From: Neal Becker > To: cplusplus-sig at python.org > Sent: Wed, October 20, 2010 2:17:46 PM > Subject: Re: [C++-sig] boost::python + python3.1.2 throw > > Neal Becker wrote: > > > Neal Becker wrote: > > > >> Has behavior of c++ exception changed with boost::python + python3? > >> > >> I used to simply use throw from c++. Now I get: > >> SystemError: initialization of ldpc_45 raised unreported exception > >> > >> I believe this exception was really: > >> if (!fp) > >> throw std::runtime_error ((boost::format ("fopen %1% failed") % > >> name).str()); > >> > >> which would have produced a good error message under python2.6. > > > > I think this difference in behavior is for an exception thrown > > during module initialization? > > > > A c++ exception thrown after initialization seems to behave as before. > > Just confirmed, under python2.6 I get my nice error message: > Traceback (most recent call last): > File "test_btr_equal_coded.py", line 570, in > run (sys.argv[1:]) > File "test_btr_equal_coded.py", line 148, in run > from ldpc_45 import encoder, decoder, N, K > RuntimeError: fopen H23_64800_7-50_3-50_3.dat failed > > But on python3.1.2 I just get > SystemError: initialization of ldpc_45 raised unreported exception > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From mckenzig at optonline.net Fri Oct 22 06:07:03 2010 From: mckenzig at optonline.net (Grant Mckenzie) Date: Fri, 22 Oct 2010 00:07:03 -0400 Subject: [C++-sig] Creating non-naive datetime objects in C++ Message-ID: Hi, I am writing some C++ code and importing into python via swig. I'd like to pass datetime objects to pass back to python. The following code will create a naive datetime after including datetime.h. PyObject* ret = PyDateTimeAPI->DateTime_FromDateAndTime( y, m, d, h, m, s, u, Py_None, PyDateTimeAPI->DateTimeType); I'd like to create a datetime object with UTC timezone info set. Much to my chagrin, I am having lots of trouble finding an example of how to do this. Any help would be appreciated. Regards, Grant. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simwarg at gmail.com Sun Oct 24 22:53:30 2010 From: simwarg at gmail.com (Simon W) Date: Sun, 24 Oct 2010 22:53:30 +0200 Subject: [C++-sig] Delete objects, remove from dict Message-ID: Hey, I have a dict of the main namespace in boost::python. Now I want to delete an object from the dict to unload/delete that object dict namespace = .. extract dict from __main__ module ...; namespace["test"] = object(555); namespace.remove("test"); // <- how can I do something like this with boost python? // Simon -------------- next part -------------- An HTML attachment was scrubbed... URL: From tuerke at cbs.mpg.de Sun Oct 24 23:10:44 2010 From: tuerke at cbs.mpg.de (=?ISO-8859-1?Q?Erik_T=FCrke?=) Date: Sun, 24 Oct 2010 23:10:44 +0200 Subject: [C++-sig] Inheritance problem Message-ID: <4CC4A0D4.3070307@cbs.mpg.de> Hi! I am trying to expose some c++ classes with boost.python. Unfortunately, i have some trouble with the inheritance of classes which need a wrapper. It is something like that: class Base { public: void someFunction() { doSomething; } }; class BaseWrapper : public Base, boost::python::wrapper { public: //constructor here void someFunctionWrapped() { doSomeThing and call Base::someFunction(); } private: PyObject *self; }; class Derived : public Base {}; class DerivedWrapper : public Derived, boost::python::wrapper { public: //constructor here private: PyObject *self; }; BOOST_PYTHON_MODULE( myModule ) { class_() ) .def( "someFunction", &BaseWrapper::someFunctionWrapped); class_ > ("Derived", init<>()); } In Python: import myModule derived = myModule.Derived() derived.someFunction() This crashes with a signature error: Boost.Python.ArgumentError: Python argument types in Base.someFunction(Derived) did not match C++ signature: someFunction(isis::python::BaseWrapped {lvalue}) If the function (here someFunction(Wrapped) ) was not declared in the wrapper class, it works. But unfortunately i need it there. Is someone aware of this problem and can give me a hint? Thanks for your help! Best regards! Erik T?rke Department of Neurophysics Max-Planck-Institute for Human Cognitive and Brain Sciences Stephanstrasse 1A 04103 Leipzig Germany Tel: +49 341 99 40-2440 Email: tuerke at cbs.mpg.de www.cbs.mpg.de From rwgk at yahoo.com Mon Oct 25 01:26:47 2010 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 24 Oct 2010 16:26:47 -0700 (PDT) Subject: [C++-sig] Delete objects, remove from dict In-Reply-To: References: Message-ID: <460331.27504.qm@web111403.mail.gq1.yahoo.com> > namespace.remove("test"); // <- how can I do something like this with boost >python? namespace["test"].del(); See also: http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html Ralf From marek at octogan.net Mon Oct 25 11:53:24 2010 From: marek at octogan.net (Marek Denis) Date: Mon, 25 Oct 2010 11:53:24 +0200 Subject: [C++-sig] shared_ptr and register_ptr_to_python In-Reply-To: <4CB36D00.4000607@gmail.com> References: <4CB049E2.7010602@octogan.net> <4CB11B28.6000707@gmail.com> <4CB19C3E.1060801@octogan.net> <4CB202B3.2030701@gmail.com> <4CB22D4B.9050609@octogan.net> <4CB24173.7010007@gmail.com> <4CB34E31.1020605@octogan.net> <4CB36D00.4000607@gmail.com> Message-ID: <4CC55394.3030004@octogan.net> On 11.10.2010 22:01, Jim Bosch wrote: > A couple of notes: > > - I have not tested this. Likely there are some typos, and possibly even > a bit of forgotten syntax - hopefully it's easy to correct. > > - Note that there's no need to re-wrap the methods that B inherits from > A, but you do have create both PyA and PyB if you want both A and B to > be instantiable from Python (after all, getSelf() is pure virtual). > > - If you have a C++ function that returns an A or B instance by > reference or pointer, this code will still work. Of course, such an > object will have to find some other way to implement getSelf() - only > objects instantiated in Python will actually be PyA or PyB instances. I still don't think it solves my problem as in original case the objects A and B are created only under C++. I would like to pass the pointer of such object, insted of copying them into Queue.Queue in Python and you wrote that the objects (A,B) need to be instantiated under Python...This time it's more like bad Queue.Queue implementation, not boost.python (as CallPolicies don't work). Anyway, thank you for you help, I appreciate... -- pozdrawiam Marek Denis [marek at octogan.net] From godlike at ancient-ritual.com Mon Oct 25 15:34:15 2010 From: godlike at ancient-ritual.com (Panos) Date: Mon, 25 Oct 2010 16:34:15 +0300 Subject: [C++-sig] Wrapping method that returns const int& (boost::python) Message-ID: I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and I get a compiler error. How is it possible to wrap getX WITHOUT changing anything in Foo? Thanks in advance! Panos Christopoulos Charitos www.ancient-ritual.com www.anki3d.org From tuerke at cbs.mpg.de Mon Oct 25 16:17:34 2010 From: tuerke at cbs.mpg.de (Erik Tuerke) Date: Mon, 25 Oct 2010 16:17:34 +0200 Subject: [C++-sig] Wrapping method that returns const int& (boost::python) In-Reply-To: References: Message-ID: <4CC5917E.6010003@cbs.mpg.de> Panos wrote: > I have a simple test case: > > > class Foo > { > public: > const int& getX() const {return x;} > void setX(const int& x_) {x = x_;} > > private: > int x; > }; > > > BOOST_PYTHON_MODULE(module) > { > class_("Foo") > .def("getX", &Foo::getX) > ; > } > > > The problem is that I cannot wrap getX and I get a compiler error. How > is it possible to wrap getX WITHOUT changing anything in Foo? > > Thanks in advance! > > > Panos Christopoulos Charitos > www.ancient-ritual.com > www.anki3d.org > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > Hi! I totally affiliate myself to this problem. The only difference is that i do not return a const reference but rather a reference. So maybe we can find a solution for this together :-) Greetings! -- Erik Tuerke Department of Neurophysics Max-Planck-Institute for Human Cognitive and Brain Sciences Stephanstrasse 1A 04103 Leipzig Germany Tel: +49 341 99 40-2440 Email: tuerke at cbs.mpg.de www.cbs.mpg.de From simwarg at gmail.com Mon Oct 25 17:48:27 2010 From: simwarg at gmail.com (Simon W) Date: Mon, 25 Oct 2010 17:48:27 +0200 Subject: [C++-sig] Delete objects, remove from dict In-Reply-To: <460331.27504.qm@web111403.mail.gq1.yahoo.com> References: <460331.27504.qm@web111403.mail.gq1.yahoo.com> Message-ID: Hey and thanks for the answer! Unfortunately that doesn't seem to work. I'm using boost.python for Python 3 ( boost python 1.44? ) error C2039: 'del' : is not a member of 'boost::python::api::object' I've had a look on the reference manual but I don't understand if it's a free function or an method of object() ? Neither work .. The code i'm using: * object obj = mMainNamespace[ name.c_str() ]; obj.del();* // Simon On Mon, Oct 25, 2010 at 1:26 AM, Ralf W. Grosse-Kunstleve wrote: > > namespace.remove("test"); // <- how can I do something like this with > boost > >python? > > namespace["test"].del(); > > See also: > > http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html > > Ralf > _______________________________________________ > 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 rwgk at yahoo.com Mon Oct 25 18:46:53 2010 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 25 Oct 2010 09:46:53 -0700 (PDT) Subject: [C++-sig] Delete objects, remove from dict In-Reply-To: References: <460331.27504.qm@web111403.mail.gq1.yahoo.com> Message-ID: <915591.95918.qm@web111409.mail.gq1.yahoo.com> I've only tried it with Python 2; I'm not setup for working with Python 3. Try boost::python::api::delitem(target, key); and if that fails too PyObject_DelItem(target.ptr(), key.ptr()); Ralf > >From: Simon W >To: Development of Python/C++ integration >Sent: Mon, October 25, 2010 8:48:27 AM >Subject: Re: [C++-sig] Delete objects, remove from dict > >Hey and thanks for the answer! Unfortunately that doesn't seem to work. I'm >using boost.python for Python 3 ( boost python 1.44? ) > >error C2039: 'del' : is not a member of 'boost::python::api::object' > >I've had a look on the reference manual but I don't understand if it's a free >function or an method of object() ? Neither work .. > >The code i'm using: > object obj = mMainNamespace[ name.c_str() ]; > obj.del(); > >// Simon > > >On Mon, Oct 25, 2010 at 1:26 AM, Ralf W. Grosse-Kunstleve >wrote: > >> namespace.remove("test"); // <- how can I do something like this with boost >>>python? >> >>namespace["test"].del(); >> >>See also: >> >>http://www.boost.org/doc/libs/1_44_0/libs/python/doc/v2/object.html >> >>Ralf From rwgk at yahoo.com Mon Oct 25 19:07:18 2010 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 25 Oct 2010 10:07:18 -0700 (PDT) Subject: [C++-sig] Delete objects, remove from dict In-Reply-To: <915591.95918.qm@web111409.mail.gq1.yahoo.com> References: <460331.27504.qm@web111403.mail.gq1.yahoo.com> <915591.95918.qm@web111409.mail.gq1.yahoo.com> Message-ID: <217582.58915.qm@web111415.mail.gq1.yahoo.com> Oh, at second glance... > > object obj = mMainNamespace[ name.c_str() ]; > > obj.del(); This cannot work! You need to do it the way I showed before. mMainNamespace[ name.c_str() ].del(); The [] operator returns a proxy object which supports the del since it still knows what the target object is. Once you've assigned the proxy object to boost::python::object the target information is lost. Ralf From simwarg at gmail.com Mon Oct 25 19:21:17 2010 From: simwarg at gmail.com (Simon W) Date: Mon, 25 Oct 2010 19:21:17 +0200 Subject: [C++-sig] Delete objects, remove from dict In-Reply-To: <217582.58915.qm@web111415.mail.gq1.yahoo.com> References: <460331.27504.qm@web111403.mail.gq1.yahoo.com> <915591.95918.qm@web111409.mail.gq1.yahoo.com> <217582.58915.qm@web111415.mail.gq1.yahoo.com> Message-ID: Thanks that did the trick! On Mon, Oct 25, 2010 at 7:07 PM, Ralf W. Grosse-Kunstleve wrote: > Oh, at second glance... > > > > > > object obj = mMainNamespace[ name.c_str() ]; > > > obj.del(); > > This cannot work! > You need to do it the way I showed before. > > mMainNamespace[ name.c_str() ].del(); > > The [] operator returns a proxy object which supports the del since > it still knows what the target object is. Once you've assigned the > proxy object to boost::python::object the target information is lost. > > Ralf > _______________________________________________ > 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 simwarg at gmail.com Mon Oct 25 19:35:24 2010 From: simwarg at gmail.com (Simon W) Date: Mon, 25 Oct 2010 19:35:24 +0200 Subject: [C++-sig] Reference count on class object and import() Message-ID: Hey again, I'm trying to implement a load / unload module functionallity. When I delete the module in the __main__ dict the module's reference count is still > 1. I've been trying to find if I reference it anywhere else in my code but I can't find anything! When I did a check in vc++ debugger found something. When I run this code: object obj = import(name.c_str()); *obj*'s *ob_refcnt* member is 2 when I check in the vc++ debugger. Shouldn't it be 1? After that line, I put it in the __main__ dict like: mMainNamespace[ name.c_str() ] = obj; The reference count shows 4, as expected. When I'm entering my unload() function when I want to remove the module I do like: void unload() { object t = mMainNamespace[ name.c_str() ]; // reference count in t is now 4 ? mMainNamespace[ name.c_str() ].del(); // I delete but it's not unloaded properly because it's still referenced somewhere .. } What does import() do? It must save some reference somewhere? -------------- next part -------------- An HTML attachment was scrubbed... URL: From marek at octogan.net Mon Oct 25 19:51:16 2010 From: marek at octogan.net (Marek Denis) Date: Mon, 25 Oct 2010 19:51:16 +0200 Subject: [C++-sig] Mapping RAW memory data into Python Message-ID: <4CC5C394.8030402@octogan.net> Hi, While I had some questions concerning accessing objects in Python, that were previously created in C++ now I'd like to know whether it's possible to get access to the raw memory from Python layer. Let's suppose I have the char* ptr pointer that points to the memory chunk with IPv4 packet. I would like to be able to read (and preferably write) data from Python layer (not via wrapped object that contains char* ptr and has some methods to write/read data), but without making any memory copies. I can use struct (even define format dynamically) in Python, but I don't know how do I pass the proper pointer from C++. If I use boost::python::object I had problems that script didn't know char type. I can use boost::python::str, return it and use in Python but I suppose it does copy data into str object, right? If not Boost, maybe basic Python C API would work? BTW. Suppose I had char* txt = "some string"; How do i create boost::python::object() that would containt the whole string? Passing *txt or txt into boost::python::object(*txt) didn't work. -- regards Marek Denis From abhishek.srivastava at nechclst.in Mon Oct 25 20:11:15 2010 From: abhishek.srivastava at nechclst.in (Abhishek Srivastava) Date: Mon, 25 Oct 2010 23:41:15 +0530 Subject: [C++-sig] Wrapping method that returns const int& (boost::python) References: Message-ID: <0A8CFEC45B7F4C419F7543867C47442302893B74@mailserver.nechclst.in> Does this works for you?? class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX, return_value_policy()) ; } With Regards, Abhishek Srivastava -----Original Message----- From: cplusplus-sig-bounces+abhishek.srivastava=nechclst.in at python.org on behalf of Panos Sent: Mon 10/25/2010 7:04 PM To: cplusplus-sig at python.org Subject: [C++-sig] Wrapping method that returns const int& (boost::python) I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and I get a compiler error. How is it possible to wrap getX WITHOUT changing anything in Foo? Thanks in advance! Panos Christopoulos Charitos www.ancient-ritual.com www.anki3d.org _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . ----------------------------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Mon Oct 25 21:16:57 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Mon, 25 Oct 2010 12:16:57 -0700 Subject: [C++-sig] Mapping RAW memory data into Python In-Reply-To: <4CC5C394.8030402@octogan.net> References: <4CC5C394.8030402@octogan.net> Message-ID: <4CC5D7A9.5040908@gmail.com> On 10/25/2010 10:51 AM, Marek Denis wrote: > Hi, > While I had some questions concerning accessing objects in Python, that > were previously created in C++ now I'd like to know whether it's > possible to get access to the raw memory from Python layer. > Let's suppose I have the char* ptr pointer that points to the memory > chunk with IPv4 packet. I would like to be able to read (and preferably > write) data from Python layer (not via wrapped object that contains > char* ptr and has some methods to write/read data), but without making > any memory copies. > I can use struct (even define format dynamically) in Python, but I don't > know how do I pass the proper pointer from C++. If I use > boost::python::object I had problems that script didn't know char type. > I can use boost::python::str, return it and use in Python but I suppose > it does copy data into str object, right? > > If not Boost, maybe basic Python C API would work? > > BTW. Suppose I had char* txt = "some string"; > How do i create boost::python::object() that would containt the whole > string? Passing *txt or txt into boost::python::object(*txt) didn't work. > If it's okay for that data to be totally opaque in Python, then you probably want to look into PyCObject in the Python C API. The Python str type does not support pointing at memory it doesn't own, so it sounds like that isn't an option for you. If you want to interpret it in some way so that native Python code can understand it, you'll need to use Numpy. I've written a low-level Boost.Python interface to Numpy that you might find useful in that case here: http://svn.boost.org/svn/boost/sandbox/numpy/ ...but it will still be pretty complicated. Passing raw memory into Python is hard precisely because it's very hard to do the memory management in a safe way. Jim Bosch From seefeld at sympatico.ca Tue Oct 26 01:51:49 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 25 Oct 2010 19:51:49 -0400 Subject: [C++-sig] Wrapping method that returns const int& (boost::python) In-Reply-To: <4CC5917E.6010003@cbs.mpg.de> References: <4CC5917E.6010003@cbs.mpg.de> Message-ID: <4CC61815.8040406@sympatico.ca> Panos, Erik, the issue here is likely that Python's "int" objects are immutable. Therefore, you can't pass around ints by reference, only by-value. If the compiler is confused, perhaps you need to explicitly set a return-value policy that makes this clear ? Stefan -- ...ich hab' noch einen Koffer in Berlin... From j.reid at mail.cryst.bbk.ac.uk Tue Oct 26 13:22:53 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 26 Oct 2010 12:22:53 +0100 Subject: [C++-sig] boost.python and distutils Message-ID: Hi, I need to distribute a python package that includes a boost.python extension. I've been working on Linux but I'd like the distribution to install easily on any platform with boost and python. I'm guessing distutils is the way to go. I'm not sure if the easiest way is to try to get distutils to call bjam or somehow to code all the compile and link options into the setup.py script (this seems like a headache). If I get distutils to call bjam how can the setup.py script know what the files are to install given different OSes and versions of boost? Perhaps just using a boost.build script would be easier than distutils. This is what the boost.graph python bindings do. Has anyone got any experience doing this? Thanks, John. From lists at informa.tiker.net Tue Oct 26 16:12:03 2010 From: lists at informa.tiker.net (Andreas Kloeckner) Date: Tue, 26 Oct 2010 10:12:03 -0400 Subject: [C++-sig] boost.python and distutils In-Reply-To: References: Message-ID: <87y69lgi18.fsf@grizzly.selfip.net> Hi John, On Tue, 26 Oct 2010 12:22:53 +0100, John Reid wrote: > I need to distribute a python package that includes a boost.python > extension. I've been working on Linux but I'd like the distribution to > install easily on any platform with boost and python. > > I'm guessing distutils is the way to go. I'm not sure if the easiest way > is to try to get distutils to call bjam or somehow to code all the > compile and link options into the setup.py script (this seems like a > headache). If I get distutils to call bjam how can the setup.py script > know what the files are to install given different OSes and versions of > boost? > > Perhaps just using a boost.build script would be easier than distutils. > This is what the boost.graph python bindings do. > > Has anyone got any experience doing this? I've done distutils+Boost.Python for years now, without any issue. See here for code examples: - http://git.tiker.net/pyopencl.git - http://git.tiker.net/pyublas.git - http://git.tiker.net/pycuda.git No bjam whatsoever. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: From simwarg at gmail.com Tue Oct 26 23:29:03 2010 From: simwarg at gmail.com (Simon W) Date: Tue, 26 Oct 2010 23:29:03 +0200 Subject: [C++-sig] Reference count on class object and import() In-Reply-To: References: Message-ID: Of course, I did find another reference that I didn't notice. Python reference works as expected .. hehe! On Mon, Oct 25, 2010 at 7:35 PM, Simon W wrote: > Hey again, > > I'm trying to implement a load / unload module functionallity. When I > delete the module in the __main__ dict the module's reference count is still > > 1. I've been trying to find if I reference it anywhere else in my code but > I can't find anything! When I did a check in vc++ debugger found something. > When I run this code: > > object obj = import(name.c_str()); > > *obj*'s *ob_refcnt* member is 2 when I check in the vc++ debugger. > Shouldn't it be 1? > > After that line, I put it in the __main__ dict like: > > mMainNamespace[ name.c_str() ] = obj; > > The reference count shows 4, as expected. > > When I'm entering my unload() function when I want to remove the module I > do like: > void unload() > { > object t = mMainNamespace[ name.c_str() ]; > // reference count in t is now 4 ? > > mMainNamespace[ name.c_str() ].del(); // I delete but it's not > unloaded properly because it's still referenced somewhere .. > } > > What does import() do? It must save some reference somewhere? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Wed Oct 27 12:43:44 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 27 Oct 2010 11:43:44 +0100 Subject: [C++-sig] boost.python and distutils In-Reply-To: <87y69lgi18.fsf@grizzly.selfip.net> References: <87y69lgi18.fsf@grizzly.selfip.net> Message-ID: Hi Andreas, On 26/10/10 15:12, Andreas Kloeckner wrote: > Hi John, > > I've done distutils+Boost.Python for years now, without any issue. See > here for code examples: > > - http://git.tiker.net/pyopencl.git > - http://git.tiker.net/pyublas.git > - http://git.tiker.net/pycuda.git > After following the getting started instructions http://www.boost.org/doc/libs/1_44_0/more/getting_started/unix-variants.html#easy-build-and-install I found I had to change the aksetup_helper.py module slightly as there was no 'gcc43-mt' in the boost library filenames: class BoostLibraries(Libraries): def __init__(self, lib_base_name): Libraries.__init__(self, "BOOST_%s" % lib_base_name.upper(), #["boost_%s-${BOOST_COMPILER}-mt" % lib_base_name], ["boost_%s" % lib_base_name], help="Library names for Boost C++ %s library (without lib or .so)" % humanize(lib_base_name)) Did you write aksetup or is it a third party thing? Do you know why the library names are different? Thanks for your help it is extremely useful, John. From j.reid at mail.cryst.bbk.ac.uk Wed Oct 27 13:04:30 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 27 Oct 2010 12:04:30 +0100 Subject: [C++-sig] boost.python and distutils In-Reply-To: <87y69lgi18.fsf@grizzly.selfip.net> References: <87y69lgi18.fsf@grizzly.selfip.net> Message-ID: On 26/10/10 15:12, Andreas Kloeckner wrote: > Hi John, > I've done distutils+Boost.Python for years now, without any issue. See > here for code examples: > > - http://git.tiker.net/pyopencl.git > - http://git.tiker.net/pyublas.git > - http://git.tiker.net/pycuda.git Also the instructions in README_SETUP.txt didn't seem to work for me. """ If you don't want to continue reading, just try the regular ./configure.py --help ./configure.py --some-options make sudo make install """ This didn't generate a makefile but the distutils method did work. Are these instructions out-of-date or did I miss something? Thanks, John. From nat at lindenlab.com Wed Oct 27 15:02:51 2010 From: nat at lindenlab.com (Nat Linden) Date: Wed, 27 Oct 2010 09:02:51 -0400 Subject: [C++-sig] Mapping RAW memory data into Python In-Reply-To: <4CC5C394.8030402@octogan.net> References: <4CC5C394.8030402@octogan.net> Message-ID: On Mon, Oct 25, 2010 at 1:51 PM, Marek Denis wrote: now I'd like to know whether it's possible to get access to the raw memory > from Python layer. > Let's suppose I have the char* ptr pointer that points to the memory chunk > with IPv4 packet. I would like to be able to read (and preferably write) > data from Python layer (not via wrapped object that contains char* ptr and > has some methods to write/read data), but without making any memory copies. > Would it work for you to create a 'buffer' object in your C++ code? I haven't used that myself, but my impression is that the Python 'buffer' datatype exists specifically to address such issues. http://docs.python.org/release/2.5.4/lib/typesseq.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From marek at octogan.net Wed Oct 27 17:30:04 2010 From: marek at octogan.net (Marek Denis) Date: Wed, 27 Oct 2010 17:30:04 +0200 Subject: [C++-sig] Mapping RAW memory data into Python In-Reply-To: References: <4CC5C394.8030402@octogan.net> Message-ID: <4CC8457C.9060301@octogan.net> On 27.10.2010 15:02, Nat Linden wrote: > Would it work for you to create a 'buffer' object in your C++ code? I > haven't used that myself, but my impression is that the Python 'buffer' > datatype exists specifically to address such issues. > > http://docs.python.org/release/2.5.4/lib/typesseq.html This sounds very interesting, especially it has correspondencing functions in C API. I'll investigate it a bit deeper, for sure. Thank you very much! -- pozdrawiam Marek Denis From marek at octogan.net Thu Oct 28 14:55:43 2010 From: marek at octogan.net (Marek Denis) Date: Thu, 28 Oct 2010 14:55:43 +0200 Subject: [C++-sig] Mapping RAW memory data into Python In-Reply-To: <4CC8457C.9060301@octogan.net> References: <4CC5C394.8030402@octogan.net> <4CC8457C.9060301@octogan.net> Message-ID: <4CC972CF.20904@octogan.net> W dniu 27.10.2010 17:30, Marek pisze: >> http://docs.python.org/release/2.5.4/lib/typesseq.html Yeah, Buffers (and especially API/C Buffer and MemoryView functions) vere what i was looking for. Thanks again! http://docs.python.org/c-api/buffer.html?highlight=buffer#PyBuffer_FromMemory/ -- Marek