From greg.landrum at gmail.com Fri Dec 1 05:31:34 2006 From: greg.landrum at gmail.com (Greg Landrum) Date: Fri, 1 Dec 2006 05:31:34 +0100 Subject: [C++-sig] compile error in iterator In-Reply-To: References: Message-ID: <60825b0f0611302031n39f6f401tf57b3ea2ced898b5@mail.gmail.com> On 11/30/06, Kelly Burkhart wrote: > The problem was private derivation in > boost/detail/compressed_pair.hpp. The CVS HEAD version of this file > replaced private derivation with protected. Replacing this one file > in my 1.33.1 tree solved my problem. This cleared up the problem for me as well. Thanks Kelly. -greg From eXt at sidvind.com Sat Dec 2 12:49:29 2006 From: eXt at sidvind.com (David Sveningsson) Date: Sat, 02 Dec 2006 12:49:29 +0100 Subject: [C++-sig] Extending Python with not-basic-c++ In-Reply-To: <456F3C5A.8060408@sympatico.ca> References: <456EEC74.5090006@sidvind.com> <456EF4C9.2000802@sympatico.ca> <456EFCEA.4050702@sidvind.com> <456F3C5A.8060408@sympatico.ca> Message-ID: <45716849.2060409@sidvind.com> Stefan Seefeld skrev: >> As I said, it works but for each module I have to link against many of >> my c++ object files. So the same files is linked into many modules. What >> I mant to know if this is the way it has to be done or if there is a >> better way. Won't it be problematic if each module has it's own version >> of everything? > > Don't you use shared libraries ? Sharing doesn't imply duplication. Yes, I compile the libraries like this (straight from the Makefile): GCC=g++ OPTIONS=-c -g -Wall -march=pentium-m -msse3 -pipe FLAGS=-I../../Source/Include -DLINUX CFLAGS=$(OPTIONS) $(FLAGS) LDFLAGS=-g -lX11 -lGL -lGLU OUTPUT=../../Game/Core.so #Skipped the objects here... PyModules: CFLAGS+=-I/usr/include/python2.4 PyModules: LDFLAGS+=-shared -lboost_python -lpython2.4 all: $(OBJS) PyModules %.o : %.cpp Makefile $(GCC) $(CFLAGS) $< -o PyModules: $(PY_OBJS) $(GCC) $(OBJS) $(LDFLAGS) -o $(OUTPUT) So each source file is compiled like this: g++ -c -g -Wall -march=pentium-m -msse3 -pipe -I../../Source/Include -DLINUX -I/usr/include/python2.4 ../../Source/Implementation/PythonModules/CoreModule.cpp -o CoreModule.o And then linked like this: g++ CoreModule.o -g -lX11 -lGL -lGLU -shared -lboost_python -lpython2.4 -shared -lboost_python -lpython2.4 -o ../../Game/Core.so But when I try to import the module into Python (import Core) i get the following error: Traceback (most recent call last): File "./foo.py", line 3, in ? import Core ImportError: /home/ext/workspace/06proj/Game/Core.so: undefined symbol: _ZN15AutoreleasePool9constructEv So I have to link with AutoreleasePool.o After I have linked with all objects that is required and creates another module and imports it AFTER the core module I still get the same error for the new module. The only way to get it working is to link with those modules again but that creates to separate modules. For instance, I have an event dispatcher in the core module. Another module I try to create also needs the event dispatcher but since the is linked separately into both modules they cannot communicate. I don't want to have everything in a big module, I want to split things up. I can live with a core module that have all code with circular dependencies etc but I don't want everything in it. Doesn't it compile the shared libraries as it should? Since they don't seem to behave like one. I only have experience with creating shared libraries in c/c++ for use with c/c++ but as I understood it was basically the same? -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From seefeld at sympatico.ca Sat Dec 2 16:06:23 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sat, 02 Dec 2006 10:06:23 -0500 Subject: [C++-sig] Extending Python with not-basic-c++ In-Reply-To: <45716849.2060409@sidvind.com> References: <456EEC74.5090006@sidvind.com> <456EF4C9.2000802@sympatico.ca> <456EFCEA.4050702@sidvind.com> <456F3C5A.8060408@sympatico.ca> <45716849.2060409@sidvind.com> Message-ID: <4571966F.4070401@sympatico.ca> David Sveningsson wrote: > Stefan Seefeld skrev: >>> As I said, it works but for each module I have to link against many of >>> my c++ object files. So the same files is linked into many modules. What >>> I mant to know if this is the way it has to be done or if there is a >>> better way. Won't it be problematic if each module has it's own version >>> of everything? >> Don't you use shared libraries ? Sharing doesn't imply duplication. > Yes, I compile the libraries like this (straight from the Makefile): [...] > And then linked like this: > g++ CoreModule.o -g -lX11 -lGL -lGLU -shared -lboost_python -lpython2.4 > -shared -lboost_python -lpython2.4 -o ../../Game/Core.so > > > But when I try to import the module into Python (import Core) i get the > following error: > > Traceback (most recent call last): > File "./foo.py", line 3, in ? > import Core > ImportError: /home/ext/workspace/06proj/Game/Core.so: undefined symbol: > _ZN15AutoreleasePool9constructEv > > So I have to link with AutoreleasePool.o No, you have to link with the (hopefully shared) library that contains AutoreleasePool.o. That will only make your 'Core.so' python module aware of the library, so the dynamic loader (presumably ld.so) can load it when you import the 'Core' module. But this has nothing to do with boost.python, really. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From eXt at sidvind.com Sat Dec 2 17:18:02 2006 From: eXt at sidvind.com (David Sveningsson) Date: Sat, 02 Dec 2006 17:18:02 +0100 Subject: [C++-sig] Extending Python with not-basic-c++ In-Reply-To: <4571966F.4070401@sympatico.ca> References: <456EEC74.5090006@sidvind.com> <456EF4C9.2000802@sympatico.ca> <456EFCEA.4050702@sidvind.com> <456F3C5A.8060408@sympatico.ca> <45716849.2060409@sidvind.com> <4571966F.4070401@sympatico.ca> Message-ID: <4571A73A.606@sidvind.com> Stefan Seefeld skrev: > > No, you have to link with the (hopefully shared) library that contains AutoreleasePool.o. > That will only make your 'Core.so' python module aware of the library, so the dynamic > loader (presumably ld.so) can load it when you import the 'Core' module. Ohh, I understand. That would explain it all. I didn't link the python module against a shared library, only as shared. Doing that instead helped. > > But this has nothing to do with boost.python, really. I think it does since I use boost.python to create the modules. Well, it would be the same even if I used the python C API directly but the problem is the same with boost.python. Maybe this should be mentioned in the boost documentation? Anyway, thanks for the help! I really appreciate it! -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From eXt at sidvind.com Sun Dec 3 13:49:47 2006 From: eXt at sidvind.com (David Sveningsson) Date: Sun, 03 Dec 2006 13:49:47 +0100 Subject: [C++-sig] Extending Python with not-basic-c++ In-Reply-To: <4571A73A.606@sidvind.com> References: <456EEC74.5090006@sidvind.com> <456EF4C9.2000802@sympatico.ca> <456EFCEA.4050702@sidvind.com> <456F3C5A.8060408@sympatico.ca> <45716849.2060409@sidvind.com> <4571966F.4070401@sympatico.ca> <4571A73A.606@sidvind.com> Message-ID: <4572C7EB.70001@sidvind.com> David Sveningsson skrev: > Stefan Seefeld skrev: >> No, you have to link with the (hopefully shared) library that contains AutoreleasePool.o. >> That will only make your 'Core.so' python module aware of the library, so the dynamic >> loader (presumably ld.so) can load it when you import the 'Core' module. > > Ohh, I understand. That would explain it all. I didn't link the python > module against a shared library, only as shared. Doing that instead helped. > >> But this has nothing to do with boost.python, really. > > I think it does since I use boost.python to create the modules. Well, it > would be the same even if I used the python C API directly but the > problem is the same with boost.python. Maybe this should be mentioned in > the boost documentation? > > Anyway, thanks for the help! I really appreciate it! > I had another problem which isn't really related to python or boost but I think you might be able to answer it anyway. My python module tries to load my shared library but it can't find it unless it is in a directory like /usr/lib. I don't want to put my libraries there but rather in the same directory as the module and the python code. I think LD_LIBRARY_PATH could be set but I don't want to set that each time (or use a script either). Is there some way to fix this? -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From ngoodspeed at solidworks.com Sun Dec 3 14:03:57 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Sun, 3 Dec 2006 08:03:57 -0500 Subject: [C++-sig] Extending Python with not-basic-c++ Message-ID: <94F7A8DD4408D8499C6812FE42E2D4B7349FE2@corp-mail4.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of David Sveningsson > Sent: Sunday, December 03, 2006 7:50 AM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] Extending Python with not-basic-c++ > > My python module tries to > load my shared library but it can't find it unless it is in a directory > like /usr/lib. I think > LD_LIBRARY_PATH could be set but I don't want to set that each time (or > use a script either). Is there some way to fix this? [Nat] Your Python module is trying to load your extension using Python's import statement? For that, you need to set Python's sys.path rather than LD_LIBRARY_PATH. But if your shared library depends on additional new shared libraries, you may need to set LD_LIBRARY_PATH as well so the OS loader can find them. ---------------------- class Madness(object): def method(self): pass From seefeld at sympatico.ca Sun Dec 3 14:16:04 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 03 Dec 2006 08:16:04 -0500 Subject: [C++-sig] Extending Python with not-basic-c++ In-Reply-To: <4572C7EB.70001@sidvind.com> References: <456EEC74.5090006@sidvind.com> <456EF4C9.2000802@sympatico.ca> <456EFCEA.4050702@sidvind.com> <456F3C5A.8060408@sympatico.ca> <45716849.2060409@sidvind.com> <4571966F.4070401@sympatico.ca> <4571A73A.606@sidvind.com> <4572C7EB.70001@sidvind.com> Message-ID: <4572CE14.5020103@sympatico.ca> David Sveningsson wrote: > I had another problem which isn't really related to python or boost but > I think you might be able to answer it anyway. My python module tries to > load my shared library but it can't find it unless it is in a directory > like /usr/lib. I don't want to put my libraries there but rather in the > same directory as the module and the python code. I think > LD_LIBRARY_PATH could be set but I don't want to set that each time (or > use a script either). Is there some way to fix this? You might configure the dynamic loader ('ld.so' ?) to look there by default. For example, I have an /etc/ld.so.conf config file that I add default search paths such as /usr/local/lib. That said, I don't think it's such a great idea to store ordinary DSOs together in the same directory as python extension modules. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Lutz.Lauterbach at qimonda.com Wed Dec 6 10:40:22 2006 From: Lutz.Lauterbach at qimonda.com (Lutz.Lauterbach at qimonda.com) Date: Wed, 6 Dec 2006 10:40:22 +0100 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) Message-ID: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> I have been successfully installing and using Boost.Python on Win2k for a short while, providing C-functions to Python which uses call-by-value and even a variable number of parameters. But since some days I get stuck at the problem of passing parameters from Python to C using call-by-reference. Here two little (simplified!) examples: void jz_void_float1(float a, float &b) { b=a; } void jz_void_float2(float a, float *b) { *b=a; } #include using namespace boost::python; BOOST_PYTHON_MODULE(hello) { def("jz_void_float1", jz_void_float1); def("jz_void_float2", jz_void_float2); } It compiles without errors and I can call the function in Python, but then it complains about the types: >>> var=3.3 >>> jz_void_float1(4.4,var) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in hello.jz_void_float(float, float) did not match C++ signature: jz_void_float(f, f {lvalue}) I would like to know how to "convert" the types or whether this idea of implementation is doable at all (or whether another thin-wrapper "layer" is necessary or whatever). I have seen the pointer-stuff working with char types, but all the others were failing. The intention of the call-by-reference is obviously to change the Python-value directly via the pointer, since there is only one return value, but we want to modify/return several data from the C-function. Please do not say "Boost.Python was designed for C++ and not for C, so better use SWIG or whatever", because I am sold on the "minimal-invasive" methodology of Boost.Python which makes us able to use/develop our C-code even further (in C). Best regards, Lutz. From roman.yakovenko at gmail.com Wed Dec 6 11:25:54 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 6 Dec 2006 12:25:54 +0200 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) In-Reply-To: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> Message-ID: <7465b6170612060225s12f53b0dv6ffef4d5242f8f7e@mail.gmail.com> On 12/6/06, Lutz.Lauterbach at qimonda.com wrote: > I have been successfully installing and using Boost.Python on Win2k for > a > short while, providing C-functions to Python which uses call-by-value > and even a variable number of parameters. But since some days I get > stuck at the problem of passing parameters from Python to C using > call-by-reference. Here two little (simplified!) examples: > > void jz_void_float1(float a, float &b) { b=a; } > void jz_void_float2(float a, float *b) { *b=a; } > > #include > using namespace boost::python; > BOOST_PYTHON_MODULE(hello) { > def("jz_void_float1", jz_void_float1); > def("jz_void_float2", jz_void_float2); > } > > It compiles without errors and I can call the function in Python, but > then it complains about the types: > > >>> var=3.3 > >>> jz_void_float1(4.4,var) > Traceback (most recent call last): File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > hello.jz_void_float(float, float) did not match C++ signature: > jz_void_float(f, f {lvalue}) > > I would like to know how to "convert" the types or whether this idea of > implementation is doable at all (or whether another thin-wrapper "layer" > is > necessary or whatever). I have seen the pointer-stuff working with char > types, but all the others were failing. > > The intention of the call-by-reference is obviously to change the > Python-value directly via the pointer, since there is only one return > value, but we want to modify/return several data from the C-function. > > Please do not say "Boost.Python was designed for C++ and not for C, so > better use SWIG or whatever", I will not say this :-) Boost.Python is still perfectly good for the task. In general you will have to write small wrapper around every function that takes/returns Python immutable( C++ fundamentals, strings and enums ) by reference/pointer. Also it is possible to automate the process of wrapper creation. Take a look on Py++ function transformation feature: C++ source code: http://tinyurl.com/yhsef5 Py++ script( unit test), that exposes the declarations: http://tinyurl.com/yjs2uw I attached the generated code. The documentation to the feature is under development right now, nevertheless it should be pretty useful. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: function_transformations.cpp Type: text/x-c++src Size: 18334 bytes Desc: not available URL: From dave at boost-consulting.com Thu Dec 7 16:43:01 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 07 Dec 2006 10:43:01 -0500 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> Message-ID: <87bqmfogoq.fsf@pereiro.luannocracy.com> writes: > Please do not say "Boost.Python was designed for C++ and not for C, so > better use SWIG or whatever", because I am sold on the > "minimal-invasive" methodology of Boost.Python which makes us able to > use/develop our C-code even further (in C). One thing to watch out for: Boost.Python works by operating on function pointers, and these two types are different in principle: typedef void (*t1)(int); typedef extern "C" void (*t2)(int); Many compilers will treat them interchangeably, but I think Boost.Python doesn't contain the overloads required to handle extern "C" functions when they're not interchangeable with C++ functions. So to export these functions portably you may need to wrap them in C++ functions. Py++ could of course automate that, but Roman would have to program it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Dec 7 16:38:05 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 07 Dec 2006 10:38:05 -0500 Subject: [C++-sig] Extending Python with not-basic-c++ References: <94F7A8DD4408D8499C6812FE42E2D4B7349FE2@corp-mail4.solidworks.swk> Message-ID: <87hcw7ogwy.fsf@pereiro.luannocracy.com> "Nat Goodspeed" writes: >> -----Original Message----- >> From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] > On >> Behalf Of David Sveningsson >> Sent: Sunday, December 03, 2006 7:50 AM >> To: Development of Python/C++ integration >> Subject: Re: [C++-sig] Extending Python with not-basic-c++ >> >> My python module tries to >> load my shared library but it can't find it unless it is in a > directory >> like /usr/lib. I think >> LD_LIBRARY_PATH could be set but I don't want to set that each time > (or >> use a script either). Is there some way to fix this? > > [Nat] Your Python module is trying to load your extension using Python's > import statement? > > For that, you need to set Python's sys.path rather than LD_LIBRARY_PATH. You can do that with PYTHONPATH in the environment. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Dec 7 19:03:56 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 07 Dec 2006 13:03:56 -0500 Subject: [C++-sig] boost::langbinding? References: <57ffdb9c0611301042j653b17cey81d3d71cc47a2994@mail.gmail.com> Message-ID: <874ps7mvlf.fsf@pereiro.luannocracy.com> "anders langlands" writes: > Whatever happened to boost::langbinding? Is the project completely > dead in the water? It seemed like a pretty good idea to have one > library to handle binding to all your favourite 'scripting > languages' Daniel and I got busy and we haven't had the time to get back to it since then. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Dec 7 19:07:54 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 07 Dec 2006 13:07:54 -0500 Subject: [C++-sig] Boost.Python windows auto-linking Message-ID: <87y7pjlgud.fsf@pereiro.luannocracy.com> Boost's CVS HEAD now contains support for the auto-linking feature provided by most windows compilers (e.g. Visual C++). I'm very eager to hear whether it works for people, especially since we're getting very close to releasing Boost 1.34 Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Thu Dec 7 19:18:23 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 7 Dec 2006 20:18:23 +0200 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) In-Reply-To: <87bqmfogoq.fsf@pereiro.luannocracy.com> References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> <87bqmfogoq.fsf@pereiro.luannocracy.com> Message-ID: <7465b6170612071018sa0bb125i5d98c239f2cf24a@mail.gmail.com> On 12/7/06, David Abrahams wrote: >Py++ could of course automate that, but Roman would have > to program it. The functionality already presents in Py++ :-). I am writing the documentation right now. The first draft of the documentation could be found here: http://tinyurl.com/ymu5n7 -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Ryan.VanNote at itt.com Thu Dec 7 20:51:39 2006 From: Ryan.VanNote at itt.com (Van Note, Ryan - SSD) Date: Thu, 7 Dec 2006 14:51:39 -0500 Subject: [C++-sig] Boost, Boost.Python and G++ 2.96 on VxWorks Message-ID: <77E700AE7021314DB6CDF6D6E8F6613203EA7C40@ACDFWMAIL1.acd.de.ittind.com> I am currently attempting to build the Boost date and time library using G++ 2.96 on VxWorks. Were you ever successful with the build using 2.96? Thanks, Ryan Van Note Software Engineer ITT Space Systems Division ryan.vannote at itt.com (260)-451-6547 ************************************ This e-mail and any files transmitted with it are proprietary and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT, Inc. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail. ************************************ -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Dec 7 21:08:22 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 7 Dec 2006 22:08:22 +0200 Subject: [C++-sig] Boost, Boost.Python and G++ 2.96 on VxWorks In-Reply-To: <77E700AE7021314DB6CDF6D6E8F6613203EA7C40@ACDFWMAIL1.acd.de.ittind.com> References: <77E700AE7021314DB6CDF6D6E8F6613203EA7C40@ACDFWMAIL1.acd.de.ittind.com> Message-ID: <7465b6170612071208m67c20efbm68c08234beb360fe@mail.gmail.com> On 12/7/06, Van Note, Ryan - SSD wrote: > I am currently attempting to build the Boost date and time library using G++ > 2.96 on VxWorks. Were you ever successful with the build using 2.96? Hi. This is a wrong group to ask the question. Nevertheless you can find out the answer here: http://engineering.meta-comm.com/boost-regression/CVS-RC_1_34_0/developer/date_time.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mw8329 at yahoo.com.au Thu Dec 7 21:58:18 2006 From: mw8329 at yahoo.com.au (Martin Wille) Date: Thu, 07 Dec 2006 21:58:18 +0100 Subject: [C++-sig] Boost, Boost.Python and G++ 2.96 on VxWorks In-Reply-To: <77E700AE7021314DB6CDF6D6E8F6613203EA7C40@ACDFWMAIL1.acd.de.ittind.com> References: <77E700AE7021314DB6CDF6D6E8F6613203EA7C40@ACDFWMAIL1.acd.de.ittind.com> Message-ID: <4578806A.4000107@yahoo.com.au> Van Note, Ryan - SSD wrote: > I am currently attempting to build the Boost date and time library using > G++ 2.96 on VxWorks. Were you ever successful with the build using > 2.96? Oh dear. So called "gcc 2.96" is not even an official gcc release. The version number was created by a Linux distributor who attempted to improve gcc 2.95 by applying a number of patches. The result was a compiler that was significantly more broken than gcc 2.95.3 was. Note that gcc 2 is horribly outdated. It's built on a pre-standard C++ base. You'll probably be better off with a more recent compiler. You can try looking at gcc 2.95 regression test results (if you happen to find any), but odds are that the results for 2.96 would look a lot worse if there were any (I don't think anyone ever published test results for gcc "2.96"). HTH, m Send instant messages to your online friends http://au.messenger.yahoo.com From j.reid at mail.cryst.bbk.ac.uk Fri Dec 8 16:41:26 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 08 Dec 2006 15:41:26 +0000 Subject: [C++-sig] Numpy array boost ublas conversion Message-ID: Hi, I recently had some problems using the boost python numeric class to convert between numpy arrays and boost ublas matrices. I ended solving this in the ad-hoc method below. Perhaps someone else will find this useful or someone will point out how I could/should be doing this... John. #include #include using namespace boost::python; /** Converts between numpy arrays and boost ublas matrices. */ struct numpy_converter { typedef object object; typedef tuple tuple; object numpy; object array_type; object array_function; object dtype; /** Constructor. dtype_name determines type of matrices created. */ numpy_converter( const char * dtype_name = "float64" ) { PyObject* module = ::PyImport_Import( object( "numpy" ).ptr() ); if( ! module ) { throw std::logic_error( "Could not import numpy" ); } numpy = object( handle<>( module ) ); array_type = numpy.attr( "ndarray" ); array_function = numpy.attr( "array" ); set_dtype( dtype_name ); } /** Set which dtype the created numpy matrices have. */ void set_dtype( const char * dtype_name = "float64" ) { dtype = numpy.attr( dtype_name ); } /** Convert a numpy matrix to a ublas one. */ template< typename T > matrix & numpy_to_ublas( object a, boost::numeric::ublas::matrix< T > & m ) { tuple shape( a.attr("shape") ); if( boost::python::len( shape ) != 2 ) { throw std::logic_error( "numeric::array must have 2 dimensions" ); } m.resize( extract< unsigned >( shape[0] ), extract< unsigned >( shape[1] ) ); for( unsigned i = 0; i < m.size1(); ++i ) { for( unsigned j = 0; j < m.size2(); ++j ) { m( i, j ) = boost::python::extract< T >( a[ boost::python::make_tuple( i, j ) ] ); } } return m; } /** Convert a ublas matrix to a numpy matrix. */ template< typename T > object ublas_to_numpy( const boost::numeric::ublas::matrix< T > & m ) { //create a numpy array to put it in object result( array_type( boost::python::make_tuple( m.size1(), m.size2() ), dtype ) ); //copy the elements for( unsigned i = 0; m.size1() != i; ++i ) { for( unsigned j = 0; m.size2() != j; ++j ) { result[ make_tuple( i, j ) ] = m( i, j ); } } return result; } }; From Lutz.Lauterbach at qimonda.com Fri Dec 8 18:04:03 2006 From: Lutz.Lauterbach at qimonda.com (Lutz Lauterbach) Date: Fri, 8 Dec 2006 17:04:03 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?call_C-functions_=28by_reference=29_from_Pyth?= =?utf-8?q?on_=28using=09Boost=2EPython=29?= References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> <7465b6170612060225s12f53b0dv6ffef4d5242f8f7e@mail.gmail.com> Message-ID: Roman Yakovenko gmail.com> writes: > In general you will have to write small wrapper around every function > that takes/returns Python immutable( C++ fundamentals, strings and enums) > by reference/pointer. Thanks Roman, taking your advice (and another example from somewhere in this forum and your attached Boost-code example) I created little wrapper functions which make the thing work: void jz_void_float1(float a, float &b) { b=a; } void jz_void_float2(float a, float *b) { *b=a; } //////////////////////////// #include namespace bp = boost::python; bp::tuple py_jz_void_float1(float v1, float v2 ){ jz_void_float1(v1,v2); return bp::make_tuple( v1,v2); } bp::tuple py_jz_void_float2(float v1, float v2 ){ jz_void_float2(v1,&v2); return bp::make_tuple( v1,v2); } using namespace bp; BOOST_PYTHON_MODULE(hello) { def("jz_void_float1", py_jz_void_float1); def("jz_void_float2", py_jz_void_float2); } > Also it is possible to automate the process of wrapper creation. Take > a look on Py++ function transformation feature: > C++ source code: http://tinyurl.com/yhsef5 > Py++ script( unit test), that exposes the declarations: > http://tinyurl.com/yjs2uw > I attached the generated code. Unfortunately I cannot take your Py++ suggestion, cause I use Win2k and gcc (which GCCXML is not able to work with (neither cygwin nor mingw)) and my Py++ program would look more complicated than the whole Boost code, so I rather code the Boost stuff directly in C++ instead of exerting another tool ... even though the automation sounds very attractive. But now I face another hurdle: I also want to return arrays from C. Using the above scheme: void jz_array(float a[], float b[]){ a[0]=0;a[1]=1;a[2]=2; b[0]=0;b[1]=-1;b[2]=-2; return; } ////////////////////////////////// #include namespace bp = boost::python; bp::tuple py_jz_array(){ float v1[3];float v2[3]; jz_array(v1, v2); return bp::make_tuple(v1,v2); } using namespace bp; BOOST_PYTHON_MODULE(test) { def("jz_array",py_jz_array);} does not work. It comiples, but when calling the function "jz_array" from Python it says >>> jz_array() Traceback (most recent call last): File "", line 1, in ? TypeError: No to_python (by-value) converter found for C++ type: float [3] Do you know any solution? From roman.yakovenko at gmail.com Fri Dec 8 18:51:37 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 8 Dec 2006 19:51:37 +0200 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) In-Reply-To: References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> <7465b6170612060225s12f53b0dv6ffef4d5242f8f7e@mail.gmail.com> Message-ID: <7465b6170612080951i1e4c2530s4c000f5f2d0e0581@mail.gmail.com> On 12/8/06, Lutz Lauterbach wrote: > But now I face another hurdle: I also want to return arrays from C. Using the > above scheme: > > void jz_array(float a[], float b[]){ > a[0]=0;a[1]=1;a[2]=2; > b[0]=0;b[1]=-1;b[2]=-2; > return; > } > ////////////////////////////////// > #include > namespace bp = boost::python; > bp::tuple py_jz_array(){ > float v1[3];float v2[3]; > jz_array(v1, v2); > return bp::make_tuple(v1,v2); > } > using namespace bp; > BOOST_PYTHON_MODULE(test) > { def("jz_array",py_jz_array);} > > does not work. It comiples, but when calling the function "jz_array" from > Python it says > > >>> jz_array() > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No to_python (by-value) converter found for C++ type: float [3] > > Do you know any solution? Take a look on fixed_input_array or fixed_output_array function within a file I attached previously in this thread. You can find implementation of helper functions here: http://tinyurl.com/ydpjak -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun Dec 10 08:11:32 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 10 Dec 2006 09:11:32 +0200 Subject: [C++-sig] Boost.Python windows auto-linking In-Reply-To: <87y7pjlgud.fsf@pereiro.luannocracy.com> References: <87y7pjlgud.fsf@pereiro.luannocracy.com> Message-ID: <7465b6170612092311x179cdc81waf56d4e876e3f49@mail.gmail.com> On 12/7/06, David Abrahams wrote: > > Boost's CVS HEAD now contains support for the auto-linking feature provided > by most windows compilers (e.g. Visual C++). I'm very eager to hear > whether it works for people ... I tried but it did not work for me :-(. It could be my fault, I don't use bjam. For some reason the lib file libboost_python-vc71-mt-1_35.lib was not created ( Well may be it do was created I just did not find it ) and linker failed. When I renamed libboost_python.lib file, from the bin-stage directory, than my tests started to work. Ideas? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lutz.Lauterbach at qimonda.com Tue Dec 12 10:15:43 2006 From: Lutz.Lauterbach at qimonda.com (Lutz Lauterbach) Date: Tue, 12 Dec 2006 09:15:43 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?call_C-functions_=28by_reference=29_from_Pyth?= =?utf-8?q?on_=28using=09Boost=2EPython=29?= References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> <7465b6170612060225s12f53b0dv6ffef4d5242f8f7e@mail.gmail.com> <7465b6170612080951i1e4c2530s4c000f5f2d0e0581@mail.gmail.com> Message-ID: Roman Yakovenko gmail.com> writes: > Take a look on fixed_input_array or fixed_output_array function within > a file I attached previously in this thread. You can find implementation of > helper functions here: http://tinyurl.com/ydpjak > ... I took your suggestion and inserted the file "convenience.pypp.hpp" in my program and also copied some Boost-code from your other example (concerning fixed_input_array/fixed_output_array). During compilation it brings (only) two error messages: convenience.pypp.hpp: In function `void pyplusplus::convenience::ensure_uniform_sequence(boost::python::api::object, pyp lusplus::convenience::index_type)': convenience.pypp.hpp:43: error: `len' is not a member of `boost::python' convenience.pypp.hpp: In function `void pyplusplus::convenience::copy_sequence (const boost::python::api::object&, Inserter)': convenience.pypp.hpp:73: error: `len' is not a member of `boost::python' This seems to be a rather basic problem, I do not see any missing include file since I "#include ", but I have no clue. Do you know the reason? From roman.yakovenko at gmail.com Tue Dec 12 12:36:08 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 12 Dec 2006 13:36:08 +0200 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) In-Reply-To: References: <00314E7F9E92594E84D353E2F112FE4F028889D0@mucse306.eu.infineon.com> <7465b6170612060225s12f53b0dv6ffef4d5242f8f7e@mail.gmail.com> <7465b6170612080951i1e4c2530s4c000f5f2d0e0581@mail.gmail.com> Message-ID: <7465b6170612120336h3d659e70nedac4c949453a383@mail.gmail.com> On 12/12/06, Lutz Lauterbach wrote: > This seems to be a rather basic problem, I do not see any missing include file > since I "#include ", but I have no clue. Do you know the > reason? Yes, it is not defined in your version :-) Take a look on len implementation: http://boost.cvs.sourceforge.net/boost/boost/boost/python/object.hpp?view=markup -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From j.reid at mail.cryst.bbk.ac.uk Tue Dec 12 21:21:39 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 12 Dec 2006 20:21:39 +0000 Subject: [C++-sig] boost.python multiply defined symbols Message-ID: <457F0F53.90908@mail.cryst.bbk.ac.uk> Hi, When I create a static library that uses boost.python and subsequently link this into an extension some boost.python functions are multiply defined. I've attached a minimal test case that shows this problem. The output from bjam --v2 -q is in the file bjam.out. Is there some way to tell msvc 8 not to include the inlined boost.python functions in the static library? Or should this be fixed in the boost.python code? I could turn my static lib into a dll but I'd rather not. I could also move the offending code into the extension but again I'd rather not. I'm on windows XP, using boost build v2 with the latest CVS version of RC_1_34_0. My compiler is the latest patched version of VC++ express. Also I'd like to say thanks for a great library, John. Apologies if this is a duplicate posting, my mail client is playing up bjam.out: Building Boost.Regex with the optional Unicode/ICU support disabled. Please refer to the Boost.Regex documentation for more information (and if you don't know what ICU is then you probably don't need it). ...patience... ...found 1139 targets... ...updating 2 targets... msvc.link.dll bin\msvc-8.0\debug\threading-multi\test_ext.pyd bin\msvc-8.0\debug\threading-multi\test_ext.lib boost_python-vc80-mt-gd-1_34.lib(boost_python-vc80-mt-gd-1_34.dll) : error LNK2005: "public: __thiscall boost::python::handle::~handle(void)" (??1?$handle at U_object@@@python at boost@@QAE at XZ) already defined in libtest_lib.lib(lib_src.obj) boost_python-vc80-mt-gd-1_34.lib(boost_python-vc80-mt-gd-1_34.dll) : error LNK2005: "public: __thiscall boost::python::handle::handle(void)" (??0?$handle at U_object@@@python at boost@@QAE at XZ) already defined in libtest_lib.lib(lib_src.obj) Creating library bin\msvc-8.0\debug\threading-multi\test_ext.lib and object bin\msvc-8.0\debug\threading-multi\test_ext.exp bin\msvc-8.0\debug\threading-multi\test_ext.pyd : fatal error LNK1169: one or more multiply defined symbols found call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 >nul link /NOLOGO /INCREMENTAL:NO /DLL /DEBUG /subsystem:console /out:"bin\msvc-8.0\debug\threading-multi\test_ext.pyd" /IMPLIB:"bin\msvc-8.0\debug\threading-multi\test_ext.lib" /LIBPATH:"C:\apps\Python24\libs" @"bin\msvc-8.0\debug\threading-multi\test_ext.pyd.rsp" if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% if exist "bin\msvc-8.0\debug\threading-multi\test_ext.pyd.manifest" ( mt -nologo -manifest "bin\msvc-8.0\debug\threading-multi\test_ext.pyd.manifest" "-outputresource:bin\msvc-8.0\debug\threading-multi\test_ext.pyd;2" ) ...failed msvc.link.dll bin\msvc-8.0\debug\threading-multi\test_ext.pyd bin\msvc-8.0\debug\threading-multi\test_ext.lib... ...removing bin\msvc-8.0\debug\threading-multi\test_ext.lib ...failed updating 1 target... ext_src.cpp: #include using namespace boost::python; void lib_fn(); void dummy_fn() { handle< > test; } BOOST_PYTHON_MODULE( _pyker ) { def( "fn", lib_fn ); } lib_src.cpp: #include using namespace boost::python; void lib_fn() { handle< > test; } Jamfile.v2: import python ; project test : requirements /boost/python//boost_python # gets python include path BOOST_ALL_NO_LIB # disable boost auto-linking : usage-requirements ; lib test_lib : lib_src.cpp : static ; python-extension test_ext : ext_src.cpp test_lib /boost/python//boost_python ; project-root.jam: path-constant TOP : . ; use-project /boost : $(BOOST_ROOT) ; From j.reid at mail.cryst.bbk.ac.uk Wed Dec 13 12:52:08 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 13 Dec 2006 11:52:08 +0000 Subject: [C++-sig] Warnings when compiling python extension Message-ID: Hi, With msvc 8 I see the following warnings when compiling my own code against boost.python. I'm using the latest CVS of RC_1_34_0. C:\Dev\ThirdParty\boost\RC_1_34_0\boost\boost/python/docstring_options.hpp(65) : warning C4099: 'boost::python::objects::function' : type name first seen using 'struct' now seen using 'class' C:\Dev\ThirdParty\boost\RC_1_34_0\boost\boost/python/object/function.hpp(17) : see declaration of 'boost::python::objects::function' C:\Dev\ThirdParty\boost\RC_1_34_0\boost\boost/python/numeric.hpp(98) : warning C4099: 'boost::python::numeric::array' : type name first seen using 'struct' now seen using 'class' C:\Dev\ThirdParty\boost\RC_1_34_0\boost\boost/python/numeric.hpp(20) : see declaration of 'boost::python::numeric::array' Cheers, John. From dave at boost-consulting.com Wed Dec 13 16:47:07 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 13 Dec 2006 10:47:07 -0500 Subject: [C++-sig] boost.python multiply defined symbols References: <457F0F53.90908@mail.cryst.bbk.ac.uk> Message-ID: <87fybjkdc4.fsf@pereiro.luannocracy.com> John Reid writes: > Hi, > > When I create a static library that uses boost.python > and subsequently link this into an extension some boost.python > functions are multiply defined. > > I've attached a minimal test case that shows this problem. The output > from bjam --v2 -q is in the file bjam.out. > > Is there some way to tell msvc 8 not to include the inlined boost.python > functions in the static library? I don't know. Near as I can tell, what you're seeing is a compiler bug. An inline function should never cause this sort of link error. A member function of a class template should also never cause it. So an inline member function of a class template *really* shouldn't cause it :) > Or should this be fixed in the boost.python code? To the best of my knowledge, there isn't a flaw in the Boost.Python code that could explain this, so I don't think so. > I could turn my static lib into a dll but I'd rather not. I could > also move the offending code into the extension but again I'd rather > not. > > I'm on windows XP, using boost build v2 with the latest CVS version of > RC_1_34_0. My compiler is the latest patched version of VC++ express. If you're using BBv2 it should be easy for you to produce a reduced test case (e.g. 2 source files, one for your extension and one for the static library) that reproduces the issue... oh, whoops, I see it there at the bottom! Thanks. Unfortunately I can't imagine what would cause this problem. > Also I'd like to say thanks for a great library, You're welcome. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ext at sidvind.com Thu Dec 14 13:45:51 2006 From: ext at sidvind.com (David Sveningsson) Date: Thu, 14 Dec 2006 13:45:51 +0100 Subject: [C++-sig] Typecasting Message-ID: <4581477F.1000200@sidvind.com> Hi, I'm back again with another question. I am exposing some C++ classes to python using boost. A have a class that is exposed to python. The class has a virtual function that takes a pointer to a baseclass. This baseclass has a function that returns the type of the class. By looking at the type one can typecast into the corresponding class. Now, I want to expose this behavior to python. I have a wrapper class to expose the first class. It uses the get_override function to call the function in python. So far it works. I can instantiate the class in python and the method is called. The problem is what to do next. I can look at the type function and determine what type of class it is but whatever is passed into the function is always a baseclass in python. I need to convert the class into the right class. All classes are exposed to python. Some code: Python wrapper object: class PyObj: public Object, public wrapper { public: PyObj(){ } PyObj(const Object&){ } void notify(Event* evt){ this->get_override("notify")(evt); } }; Event class: class Event: public Object { public: Event(); Event(Event_t type){ _type = type; } Event_t type(){ return _type; } protected: Event_t _type; }; Derived event: class EventKeyboard: public Event { public: EventKeyboard() : Event( EVT_KEYBOARD ){} int keycode(){ return _keycode; } private: int _keycode; }; Python code (only relevant part) class Foo (Core.Object): def notify(self,a): if a.type() == Core.Event_t.EVT_KEYBOARD: print a.keycode() # Does not work, method not defined a.__class__ = Core.EventKeyboard print a.keycode() # This gives this error: # Boost.Python.ArgumentError: Python argument types in # EventKeyboard.keycode(EventKeyboard) # did not match C++ signature: # keycode(EventKeyboard {lvalue}) -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From ext at sidvind.com Thu Dec 14 17:32:50 2006 From: ext at sidvind.com (David Sveningsson) Date: Thu, 14 Dec 2006 17:32:50 +0100 Subject: [C++-sig] Typecasting In-Reply-To: <4581477F.1000200@sidvind.com> References: <4581477F.1000200@sidvind.com> Message-ID: <45817CB2.9090106@sidvind.com> David Sveningsson skrev: > Hi, I'm back again with another question. I am exposing some C++ classes > to python using boost. > > A have a class that is exposed to python. The class has a virtual > function that takes a pointer to a baseclass. This baseclass has a > function that returns the type of the class. By looking at the type one > can typecast into the corresponding class. > > Now, I want to expose this behavior to python. I have a wrapper class to > expose the first class. It uses the get_override function to call the > function in python. So far it works. I can instantiate the class in > python and the method is called. > > The problem is what to do next. I can look at the type function and > determine what type of class it is but whatever is passed into the > function is always a baseclass in python. I need to convert the class > into the right class. > The biggest problem right now seems to be that when I call "this->get_override("notify")(evt);" the instance is copied. Since it refers to a Object baseclass thats what you get in python. But the object class does not contain anything. Is there some way to call python with a reference to the real instance? -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From seefeld at sympatico.ca Thu Dec 14 17:34:43 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 14 Dec 2006 11:34:43 -0500 Subject: [C++-sig] Typecasting In-Reply-To: <45817CB2.9090106@sidvind.com> References: <4581477F.1000200@sidvind.com> <45817CB2.9090106@sidvind.com> Message-ID: <45817D23.8060102@sympatico.ca> David Sveningsson wrote: > The biggest problem right now seems to be that when I call > "this->get_override("notify")(evt);" the instance is copied. Since it > refers to a Object baseclass thats what you get in python. But the > object class does not contain anything. Is there some way to call python > with a reference to the real instance? > I believe this->get_override("notify")(boost::python::ptr(evt)); should do the trick. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From ext at sidvind.com Thu Dec 14 17:51:55 2006 From: ext at sidvind.com (David Sveningsson) Date: Thu, 14 Dec 2006 17:51:55 +0100 Subject: [C++-sig] Typecasting In-Reply-To: <45817D23.8060102@sympatico.ca> References: <4581477F.1000200@sidvind.com> <45817CB2.9090106@sidvind.com> <45817D23.8060102@sympatico.ca> Message-ID: <4581812B.9020706@sidvind.com> Stefan Seefeld skrev: > > I believe > > this->get_override("notify")(boost::python::ptr(evt)); > > should do the trick. > > HTH, > Stefan > Yes it did, now python even recieves the right class. No need for typecasting or anything. Thanks! -- //*David Sveningsson [eXt]* Freelance coder | Game Development Student http://sidvind.com Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding. From Lutz.Lauterbach at qimonda.com Fri Dec 15 10:39:39 2006 From: Lutz.Lauterbach at qimonda.com (Lutz.Lauterbach at qimonda.com) Date: Fri, 15 Dec 2006 10:39:39 +0100 Subject: [C++-sig] call C-functions (by reference) from Python (using Boost.Python) Message-ID: <00314E7F9E92594E84D353E2F112FE4F029C2F69@mucse306.eu.infineon.com> I want to thank the guys in the forum for all the hints and as a result I would like to share my outcomes/conclusions with you to avoid the pain for you that I have already gone through. Please check out the attached file. There you find C-functions wrapped with Boost.Python including *call-by-reference *creating arrays in C and passing them to Python I work with Win2k. After installing Boost.Python (better to say uncompressing/unzipping) version V1.33.1 and MinGW version 5.0.2. (with gcc version 3.4.2 (mingw-special)) I adapted the hello.cpp file in directory \libs\python\example\tutorial\hello.cpp. To make the thing work you need to put the include file "convenience.pypp.hpp" in the same directory (or in the include path). This one I also slightly adapted, because otherwise it did not compile with these Boost.Python/MinGW versions installed. To finally compile the code on my computer with Python version 2.2 I had to call in the above mentioned directory the command: bjam "-sTOOLS=mingw" "-sMINGW_ROOT_DIRECTORY=C:\Programs\MinGW" "-sPYTHON_VERSION=2.2" "-sPYTHON_ROOT=C:\Progra~1\Python22" This creates a "bin" directory and the two important module files (hello.pyd & boost_python.dll) in some subdirectories inside "bin", which I had to copy to the Python installation directory. Then I could call a C-function (from my created module "hello") like this e.g.: >>> from hello import * >>> jz_array(3) ([0.0, 1.0, 2.0], [0.0, -1.0, -2.0]) Good luck & best regards, Lutz Lauterbach. -------------- next part -------------- A non-text attachment was scrubbed... Name: c_functions.zip Type: application/x-zip-compressed Size: 3178 bytes Desc: c_functions.zip URL: From j.reid at mail.cryst.bbk.ac.uk Fri Dec 15 10:50:56 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 15 Dec 2006 09:50:56 +0000 Subject: [C++-sig] boost.python multiply defined symbols In-Reply-To: <87fybjkdc4.fsf@pereiro.luannocracy.com> References: <457F0F53.90908@mail.cryst.bbk.ac.uk> <87fybjkdc4.fsf@pereiro.luannocracy.com> Message-ID: Thanks for looking at it. I've raised a bug with Microsoft support: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=245796 I guess either it is a fundamental flaw in their compiler or something weird in my configuration. Hopefully we'll find out soon. John. David Abrahams wrote: > > To the best of my knowledge, there isn't a flaw in the Boost.Python > code that could explain this, so I don't think so. > From kanand at qualcomm.com Fri Dec 15 23:45:42 2006 From: kanand at qualcomm.com (Anand, Kumar) Date: Fri, 15 Dec 2006 14:45:42 -0800 Subject: [C++-sig] Py++: Excluding Header files Message-ID: I am trying to generate boost python bindings for a class in a header file. This header file includes other headers (some in the same dir and some in different dir). It seems gcc-xml is trying to parse a class (see below) defined in one of the external header files and complains: Class A { ......... Union { ...... }messages; }; pygccxml.parser.source_reader.gccxml_runtime_error_t: Error occured while running GCC-XML error: semicolon missing after struct declaration error: namespace-scope anonymous aggregates must be static internal compiler error: Segmentation fault When I create the module builder, is there a way I can specify it not to parse any of the included headers as I don't need boost python bindings for them? Also any idea why above error is happening? Thanks Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From kanand at qualcomm.com Sat Dec 16 01:04:12 2006 From: kanand at qualcomm.com (Anand, Kumar) Date: Fri, 15 Dec 2006 16:04:12 -0800 Subject: [C++-sig] Py++ : passing defines to gccxml In-Reply-To: Message-ID: I am trying to use Py++ to generate boost python bindings for a C++ header file. However gcc-xml parsing fails because of absence of certain define used inside an inline function in the header file. Is there a way to pass a define through Py++ module builder which will be eventually passed to gccxml as -D? Thanks Kumar ________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Dec 16 20:00:42 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 16 Dec 2006 21:00:42 +0200 Subject: [C++-sig] Py++ : passing defines to gccxml In-Reply-To: References: Message-ID: <7465b6170612161100t6a295322mc9912b4595be4b2b@mail.gmail.com> On 12/16/06, Anand, Kumar wrote: > I am trying to use Py++ to generate boost python bindings for a C++ header > file. However gcc-xml parsing fails because of absence of certain define > used inside an inline function in the header file. Is there a way to pass a > define through Py++ module builder which will be eventually passed to gccxml > as ?D? API documentation: http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.module_builder.builder.module_builder_t-class.html#__init__ Usage example: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/examples/pyboost_dev/dev/date_time/generate_code.py?view=markup http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/examples/pyboost_dev/dev/date_time/date_time_settings.py?view=markup HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Dec 16 20:07:10 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 16 Dec 2006 21:07:10 +0200 Subject: [C++-sig] Py++: Excluding Header files In-Reply-To: References: Message-ID: <7465b6170612161107q1f6b78dke1c8b97cb821b31d@mail.gmail.com> On 12/16/06, Anand, Kumar wrote: > When I create the module builder, is there a way I can specify it not to > parse any of the included headers as I don't need boost python bindings for > them? Not really, read introduction to GCC-XML: http://gccxml.org/HTML/Index.html > Also any idea why above error is happening? You did not give enough information. Sometimes GCC-XML is not able to parse some files, but it is possible to find work around to the problems. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jontwang at gmail.com Mon Dec 18 17:56:52 2006 From: jontwang at gmail.com (Jonathan Wang) Date: Mon, 18 Dec 2006 10:56:52 -0600 Subject: [C++-sig] strange registry behavior Message-ID: <4f7636bf0612180856mf0ad0eah4072597666542557@mail.gmail.com> I'm using code from scitbx/include/scitbx/boost_python/container_conversions.h to register automatic conversions to/from C++ container types to Python lists. However, I'm seeing some extremely strange behavior - my conversion doesn't seem to actually be found at call time. The C++ code that registers the conversion: from_python_sequence, variable_capacity_policy>(); to_tuple_mapping >(); tuple_mapping, variable_capacity_policy>(); I intentionally registered the conversion twice to get an error message that the conversion was in fact registered: >>> import vector as v /home/jwang1/eqvol/Analytic2/python/vector.py:1: RuntimeWarning: to-Python converter for std::vector > already registered; second conversion method ignored. But when I make a call that returns a vector, I get: >>> baz = foo + bar Traceback (most recent call last): File "", line 1, in ? File "/home/jwang1/eqvol/Analytic2/python/vector.py", line 75, in __add__ return Vector(extract.getResult(calc)) TypeError: No Python class registered for C++ class std::vector > Does this make any sense? How can Python complain that the to-Python converter was registered twice if it can't find the converter at runtime? I get the same error if I don't cause the error on registration (i.e. only having the tuple_mapping... line). Thanks, Jonathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Mon Dec 18 19:54:54 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 18 Dec 2006 10:54:54 -0800 (PST) Subject: [C++-sig] strange registry behavior Message-ID: <20061218185455.34097.qmail@web31109.mail.mud.yahoo.com> Hi Jonathan, > >>> baz = foo + bar > Traceback (most recent call last): > File "", line 1, in ? > File "/home/jwang1/eqvol/Analytic2/python/vector.py", line 75, in __add__ > return Vector(extract.getResult(calc)) > TypeError: No Python class registered for C++ class std::vector > It is difficult to help. What is Vector? A Python class? What is extract? What is calc? Does this fail? r = extract.getResult(calc) Or this? Vector(r) BTW: The facilities in container_conversions.h were designed for small arrays (say sizes < 10). The conversions from/to Python objects will be rate-limiting for bigger arrays. Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From jontwang at gmail.com Mon Dec 18 20:17:16 2006 From: jontwang at gmail.com (Jonathan Wang) Date: Mon, 18 Dec 2006 13:17:16 -0600 Subject: [C++-sig] strange registry behavior In-Reply-To: <20061218185455.34097.qmail@web31109.mail.mud.yahoo.com> References: <20061218185455.34097.qmail@web31109.mail.mud.yahoo.com> Message-ID: <4f7636bf0612181117n2a35cb95udb2d4c996b8992bd@mail.gmail.com> On 12/18/06, Ralf W. Grosse-Kunstleve wrote: > > > Hi Jonathan, > > > >>> baz = foo + bar > > Traceback (most recent call last): > > File "", line 1, in ? > > File "/home/jwang1/eqvol/Analytic2/python/vector.py", line 75, in > __add__ > > return Vector(extract.getResult(calc)) > > TypeError: No Python class registered for C++ class std::vector std::allocator > > > It is difficult to help. > What is Vector? A Python class? > What is extract? > What is calc? > Does this fail? > r = extract.getResult(calc) > Or this? > Vector(r) Nevermind... I figured this out. The vector was getting returned with return_internal_reference call policy, which requires a class to be registered, not just a result converter. Switching the call policy fixed things. Thanks, Jonathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Dec 21 13:57:15 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 21 Dec 2006 14:57:15 +0200 Subject: [C++-sig] [ANN] Py++ - 0.8.5 In-Reply-To: <7465b6170612210455i71e690c6r3a47f9d337a100dc@mail.gmail.com> References: <7465b6170612210455i71e690c6r3a47f9d337a100dc@mail.gmail.com> Message-ID: <7465b6170612210457i516bad7dqdecb71b9050b3cb9@mail.gmail.com> Hello! I'm pleased to announce the 0.8.5 release of Py++. What is Py++? ============= Py++ is an object-oriented framework for creating a code generator for Boost.Python library. Where is Py++? ============== Site: http://language-binding.net/pyplusplus/pyplusplus.html Download: http://language-binding.net/pyplusplus/download.html What's new? =========== Features -------- * Added "Function Transformation" feature. This feature allows you to describe function wrapper and Py++ will do the rest. Example could be found here: http://tinyurl.com/y3ec24 * Added new functionality, which allows you to control messages and warnings. * Adding new algorithm, which controls the registration order of the functions. * Added new "Py++" defined "return_pointee_value" call policy * Opaque types are fully supported * Py++ will check the "completeness" of the bindings. It will check for you that the exposed declarations don't have references to unexposed ones. Small features -------------- * It is possible to configure "Py++" to generate faster ( compilation time ) code for indexing suite version 2. * The algorithm, which finds all class properties was improved. Now it provides a better way to control properties creation. A property that would hide another exposed declaration will not be registered\\created. * Work around for "custom smart pointer as member variable" Boost.Python bug was introduced. For a more complete list, please see the news: http://language-binding.net/pyplusplus/history/history.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From birgir.sigurjonsson at roxar.com Thu Dec 21 16:30:27 2006 From: birgir.sigurjonsson at roxar.com (Birgir Sigurjonsson) Date: Thu, 21 Dec 2006 16:30:27 +0100 Subject: [C++-sig] Wrap a virtual function which returns a raw pointer Message-ID: <458AA893.9060706@roxar.com> Hi all. How can I wrap a virtual function which returns a raw pointer which will be managed from C++. I am embedding Python in my C++ application and I have the follwoing classes that I want to wrap in boost.python: In the code below the virtual function ALFactory::make() returns a pointer to an abstract class AL which is also wrapped with boost.python. I want to be able to override make() in python and in the implementation of this function create and return a new python subclass of my C++ AL. The lifetime of the created object is managed by the ALFactory. class ALFactory : private boost::noncopyable { public: ALFactory(const std::string& key); virtual ~ALFactory(); virtual AL* make() = 0; }; class AL : private boost::noncopyable { public: virtual ~AL(); protected: AL(); }; ################ Wrap classes class ALWrap : public AL, public boost::python::wrapper { public: ALWrap() : AL() {} }; class ALFactoryWrap : public ALFactory, public boost::python::wrapper { public: ALFactoryWrap(const std::string& key) : ALFactory(key) {} AL* make() { return this->get_override("make")(); } }; ############ BOOST_PYTHON_MODULE(import_framework) { class_("AL") ; class_("ALFactory", init()) .def("make", pure_virtual(&ALFactory::make), return_value_policy()) ; } ############### #### Python module code from import_framework import AbstractLoader, AbstractLoaderFactory class Ascii135Loader(AbstractLoader): def __init__(self): print self.__init__ class Ascii135LoaderFactory(AbstractLoaderFactory): def __init__(self, key): super(Ascii135LoaderFactory, self).__init__(key) print self.__init__ def make(self): return Ascii135Loader() register_this = Ascii135LoaderFactory("Ascii135") ####################### I get the following error. pure virtual method called ######################### I have browsed the documentation and not found a clear answer. I found the following quote on http://wiki.python.org/moin/boost.python/class decribes my problem. "There are several problems with the above arrangement, but the most important one is that if you keep the shared_ptr alive longer than its corresponding Python object, calls to the Python-overridable virtual functions will crash, because they'll try to call through an invalid pointer." How can I solve this problem? Best regards, Birgir Sigurjonsson. DISCLAIMER: This message contains information that may be privileged or confidential and is the property of the Roxar Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorised to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From mikeowen at llnl.gov Thu Dec 21 20:02:41 2006 From: mikeowen at llnl.gov (J. Michael Owen) Date: Thu, 21 Dec 2006 11:02:41 -0800 Subject: [C++-sig] Boost.Python exception problems on AIX 5.3 (compiled with gcc 3.4.3, 64 bit) Message-ID: I'm having some problems with Boost.Python (1.33.1) exceptions not being caught properly when I compile with gcc 3.4.3 on AIX 5.3 (I'm using 64 bit mode). Boost.Python exceptions don't seem to be handled correctly, resulting in Python exiting with an error like terminate called after throwing an instance of 'boost::python::error_already_set' Abort This problem shows up in the Boost.Python self tests: for instance the "libs/python/test/vector_indexing_suite.py" test exits in the method "print_xvec" because of an uncaught end of iteration exception -- here's the final error message I see: Trying: print_xvec(v) Expecting: [ a b c d e ] EXIT STATUS: 134 I'll append the complete log from "vector_indexing_suite.py" to the end of this message for completeness. Of the Boost.Python self tests, the following set currently fail for me: crossmod_exception shared_ptr polymorphism polymorphism2 auto_ptr args enum exception_translator try builtin_converters callbacks object list slice virtual_functions implicit iterator extract opaque pickle2 vector_indexing_suite map_indexing_suite I'm building the python used (2.4.3) myself, and I've confirmed that it is being built with the C++ compiler set (g++-3.4.3) which is being used for linking. Does anyone have any suggestions I could use to track down this problem? Thanks! Mike. In case it's of interest, here's the complete log from vector_indexing_suite: execute-test ../../../bin/boost/libs/python/test/vector_indexing_suite.test/gcc/ release/vector_indexing_suite.run /bin/sh[8]: 197050 Abort ====== BEGIN OUTPUT ====== # installing zipimport hook import zipimport # builtin # installed zipimport hook # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/site.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/site.py import site # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/site.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/os.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/os.py import os # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/os.pyc import posix # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/posixpath.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/posixpath.py import posixpath # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/posixpath.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/stat.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/stat.py import stat # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/stat.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/UserDict.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/UserDict.py import UserDict # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/UserDict.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/copy_reg.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/copy_reg.py import copy_reg # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/copy_reg.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/types.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/types.py import types # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/types.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/warnings.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/warnings.py import warnings # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/warnings.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/linecache.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/linecache.py import linecache # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/linecache.pyc import encodings # directory /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ __init__.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ __init__.py import encodings # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ __init__.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/codecs.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/codecs.py import codecs # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/codecs.pyc import _codecs # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ aliases.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ aliases.py import encodings.aliases # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ aliases.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ iso8859_1.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ iso8859_1.py import encodings.iso8859_1 # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/encodings/ iso8859_1.pyc Python 2.4.3 (#2, Dec 20 2006, 15:59:22) [GCC 3.4.3] on aix5 Type "help", "copyright", "credits" or "license" for more information. # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/doctest.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/doctest.py import doctest # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/doctest.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/__future__.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/__future__.py import __future__ # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/__future__.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/traceback.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/traceback.py import traceback # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/traceback.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/inspect.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/inspect.py import inspect # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/inspect.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/string.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/string.py import string # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/string.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/re.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/re.py import re # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/re.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre.py import sre # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_compile.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_compile.py import sre_compile # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_compile.pyc import _sre # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/ sre_constants.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_constants.py import sre_constants # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/ sre_constants.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_parse.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_parse.py import sre_parse # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/sre_parse.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/strop.so", 2); import strop # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ strop.so # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/dis.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/dis.py import dis # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/dis.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/opcode.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/opcode.py import opcode # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/opcode.pyc import imp # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tokenize.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tokenize.py import tokenize # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tokenize.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/token.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/token.py import token # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/token.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/unittest.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/unittest.py import unittest # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/unittest.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/time.so", 2); import time # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ time.so # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/difflib.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/difflib.py import difflib # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/difflib.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/heapq.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/heapq.py import heapq # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/heapq.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/itertools.so", 2); import itertools # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ itertools.so # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bisect.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bisect.py import bisect # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bisect.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/_bisect.so", 2); import _bisect # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ _bisect.so dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/_heapq.so", 2); import _heapq # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ _heapq.so # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pdb.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pdb.py import pdb # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pdb.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/cmd.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/cmd.py import cmd # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/cmd.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bdb.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bdb.py import bdb # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/bdb.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/repr.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/repr.py import repr # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/repr.pyc # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pprint.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pprint.py import pprint # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/pprint.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/cStringIO.so", 2); import cStringIO # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ cStringIO.so # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tempfile.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tempfile.py import tempfile # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/tempfile.pyc import errno # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/random.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/random.py import random # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/random.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/math.so", 2); import math # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ math.so dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/binascii.so", 2); import binascii # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ binascii.so dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/_random.so", 2); import _random # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ _random.so dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/fcntl.so", 2); import fcntl # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ fcntl.so import thread # builtin # /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/StringIO.pyc matches /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/StringIO.py import StringIO # precompiled from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/StringIO.pyc dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib- dynload/readline.so", 2); import readline # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/lib/python2.4/lib-dynload/ readline.so dlopen("/g/g12/owen/Spheral++/aix/trunk/optimize/spheral/src/ thirdPartyLibs/boost_1_33_1/bin/boost/libs/python/test/ vector_indexing_suite_ext.so/gcc/release/shared-linkable-true/ vector_indexing_suite_ext.so", 2); dlopen("../../../bin/boost/libs/python/build/libboost_python.so/gcc/ release/shared-linkable-true/libboost_python.so", 2); import libboost_python # dynamically loaded from ../../../bin/boost/libs/python/build/libboost_python.so/gcc/release/ shared-linkable-true/libboost_python.so import vector_indexing_suite_ext # dynamically loaded from /g/g12/owen/Spheral++/aix/trunk/optimize/spheral/src/thirdPartyLibs/ boost_1_33_1/bin/boost/libs/python/test/vector_indexing_suite_ext.so/ gcc/release/shared-linkable-true/vector_indexing_suite_ext.so terminate called after throwing an instance of 'boost::python::error_already_set' running... Trying: from vector_indexing_suite_ext import * Expecting nothing ok Trying: x = X('hi') Expecting nothing ok Trying: x Expecting: hi ok Trying: x.reset() # a member function that modifies X Expecting nothing ok Trying: x Expecting: reset ok Trying: x.foo() # another member function that modifies X Expecting nothing ok Trying: x Expecting: foo ok Trying: x_value('bochi bochi') Expecting: 'gotya bochi bochi' ok Trying: def print_xvec(xvec): s = '[ ' for x in xvec: s += repr(x) s += ' ' s += ']' print s Expecting nothing ok Trying: v = XVec() Expecting nothing ok Trying: v[:] = [X('a'),X('b'),X('c'),X('d'),X('e')] Expecting nothing ok Trying: print_xvec(v) Expecting: [ a b c d e ] EXIT STATUS: 134 ====== END OUTPUT ====== From gabriel.becedillas at corest.com Thu Dec 21 19:58:10 2006 From: gabriel.becedillas at corest.com (Gabriel Becedillas) Date: Thu, 21 Dec 2006 15:58:10 -0300 Subject: [C++-sig] Automatic conversions for const std::string& Message-ID: <458AD942.4010201@corest.com> I have a lot of functions returning "const std::string&". Every time I wrap one of those I have to do it like this: class_.def("name", &someclass::bla, boost::python::return_value_policy() ); Is there a way to register a return value conversion for "const std::string&" so I can omit the "boost::python::return_value_policy()" every time I have to wrap this functions ? I wan't those strings to be copied to python as new strings (I don't want to hold a pointer to them). Thanks From roman.yakovenko at gmail.com Thu Dec 21 20:25:51 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 21 Dec 2006 21:25:51 +0200 Subject: [C++-sig] Wrap a virtual function which returns a raw pointer In-Reply-To: <458AA893.9060706@roxar.com> References: <458AA893.9060706@roxar.com> Message-ID: <7465b6170612211125t66790c4ex4c913ff394f28481@mail.gmail.com> On 12/21/06, Birgir Sigurjonsson wrote: > > Hi all. > How can I wrap a virtual function which returns a raw pointer > which will be managed from C++. > > I am embedding Python in my C++ application and > I have the follwoing classes that I want to wrap in boost.python: > > > In the code below the virtual function ALFactory::make() returns a pointer > to an abstract class AL which is also wrapped with boost.python. > I want to be able to override make() in python and in the > implementation of this function create and return a new python > subclass of my C++ AL. The lifetime of the created object is managed > by the ALFactory. > > > class ALFactory : private boost::noncopyable { > public: > > ALFactory(const std::string& key); > virtual ~ALFactory(); > > virtual AL* make() = 0; > > }; > > class AL : private boost::noncopyable { > public: > virtual ~AL(); > protected: > AL(); > > }; > > ################ Wrap classes > class ALWrap : public AL, public boost::python::wrapper { > public: > ALWrap() : AL() {} > }; > > class ALFactoryWrap : public ALFactory, public boost::python::wrapper { > public: > ALFactoryWrap(const std::string& key) : ALFactory(key) {} > AL* make() { > return this->get_override("make")(); > } > }; > > > ############ > BOOST_PYTHON_MODULE(import_framework) { > class_("AL") > ; > > class_("ALFactory", init()) > .def("make", pure_virtual(&ALFactory::make), return_value_policy()) > ; > } > ############### > > #### Python module code > > from import_framework import AbstractLoader, AbstractLoaderFactory What are AbstractLoader, AbstractLoaderFactory? The class names you exposed are AL and ALFactory > class Ascii135Loader(AbstractLoader): > def __init__(self): > print self.__init__ Here you have to call to AbstractLoader __init__ method. This is a must. ( I assume AbstractLoader is actually AL ) > > > class Ascii135LoaderFactory(AbstractLoaderFactory): > def __init__(self, key): > super(Ascii135LoaderFactory, self).__init__(key) Why do you use super here? AbstractLoaderFactory.__init__(self, key) should work. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rwgk at yahoo.com Thu Dec 21 21:32:03 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 21 Dec 2006 12:32:03 -0800 (PST) Subject: [C++-sig] Boost.Python exception problems on AIX 5.3 (compiled with gcc 3.4.3, 64 bit) Message-ID: <20061221203203.87974.qmail@web31113.mail.mud.yahoo.com> Under Linux I'm importing all extension modules with RTLD_GLOBAL. This is a very old workaround for exception handling problems similar to what you describe, but I'm not sure about the details anymore (e.g. which gcc was the trouble maker). This is roughly how I import our extensions: previous_dlopenflags = sys.getdlopenflags() sys.setdlopenflags(0x100|0x2) import myext sys.setdlopenflags(previous_dlopenflags) The bit masks are platform specific, RTLD_GLOBAL | RTLD_NOW. If any of this applies to AIX (?) you have to find out somehow what the correct bit masks are. HTH, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From Robert.Smallshire at roxar.com Thu Dec 21 22:10:04 2006 From: Robert.Smallshire at roxar.com (Robert Smallshire) Date: Thu, 21 Dec 2006 22:10:04 +0100 Subject: [C++-sig] Wrap a virtual function which returns a raw pointer References: <458AA893.9060706@roxar.com> <7465b6170612211125t66790c4ex4c913ff394f28481@mail.gmail.com> Message-ID: <446E8416AAF61D47B271B4E2FAE19BE61E2F84@svgw2k15.roxardomain.roxar.com> >> What are AbstractLoader, AbstractLoaderFactory? >> The class names you exposed are AL and ALFactoy? >> The class names you exposed are AL and ALFactory Yes, sorry. The effort to extract a readable, fairly minimal example, gone wrong. AL == AbstractLoader ALFactory == AbstractLoaderFactory >> class Ascii135Loader(AbstractLoader): >> def __init__(self): >> print self.__init__ > Here you have to call to AbstractLoader __init__ method. This is a must. Of course. Silly omission. >> >> >> class Ascii135LoaderFactory(AbstractLoaderFactory): >> def __init__(self, key): >> super(Ascii135LoaderFactory, self).__init__(key) > Why do you use super here? > AbstractLoaderFactory.__init__(self, key) should work. True enough, and either is fine. Use of super() is habit, encouraged by following some guidelines >, with future subclassing in mind. Rob DISCLAIMER: This message contains information that may be privileged or confidential and is the property of the Roxar Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorised to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikeowen at llnl.gov Thu Dec 21 22:49:00 2006 From: mikeowen at llnl.gov (J. Michael Owen) Date: Thu, 21 Dec 2006 13:49:00 -0800 Subject: [C++-sig] Boost.Python exception problems on AIX 5.3 (compiled with gcc 3.4.3, 64 bit) Message-ID: <0b4c3439b4ca91b3a9c5aac1551757e7@llnl.gov> Hi Ralf, Yeah, I use that dlopen hack myself on all the platforms where I'm using gcc. I've already tried this to handle this exception problem -- at least I think I've done it correctly. On AIX you can find the definitions for these things in /usr/include/dlfcn.h, where I see #define RTLD_NOW 0x00000002 /* Load object and dependents now. */ #define RTLD_GLOBAL 0x00010000 /* Make symbols in this module visible to other dlopens. */ So I've tried setting the following before importing my own test modules: import sys sys.setdlopenflags(0x00000002|0x00010000) Unfortunately this has no effect on the problem. Am I missing something in how I'm setting this? Mike. > Under Linux I'm importing all extension modules with RTLD_GLOBAL. This > is a very old workaround for exception handling problems similar to > what you describe, but I'm not sure about the details anymore (e.g. > which gcc was the trouble maker). > > This is roughly how I import our extensions: > > previous_dlopenflags = sys.getdlopenflags() > sys.setdlopenflags(0x100|0x2) > import myext > sys.setdlopenflags(previous_dlopenflags) > > The bit masks are platform specific, RTLD_GLOBAL | RTLD_NOW. If any of > this applies to AIX (?) you have to find out somehow what the correct > bit masks are. > > HTH, > Ralf -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 1538 bytes Desc: not available URL: From rwgk at yahoo.com Thu Dec 21 23:25:30 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 21 Dec 2006 14:25:30 -0800 (PST) Subject: [C++-sig] Boost.Python exception problems on AIX 5.3 (compiled with gcc 3.4.3, 64 bit) Message-ID: <20061221222531.29639.qmail@web31102.mail.mud.yahoo.com> > import sys > sys.setdlopenflags(0x00000002|0x00010000) > > Unfortunately this has no effect on the problem. Am I missing > something in how I'm setting this? Looks OK to me. No more ideas. A few years ago we had fatal EH problems using a certain Tru64 cxx release. The only way to resolve this was upgrading the compiler... __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From meine at informatik.uni-hamburg.de Fri Dec 22 16:20:02 2006 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 22 Dec 2006 16:20:02 +0100 Subject: [C++-sig] Automatic conversions for const std::string& In-Reply-To: <458AD942.4010201@corest.com> References: <458AD942.4010201@corest.com> Message-ID: <200612221620.04390.meine@informatik.uni-hamburg.de> On Thursday, 21. December 2006 19:58, Gabriel Becedillas wrote: > I have a lot of functions returning "const std::string&". Every time I > wrap one of those I have to do it like this: > > class_.def("name", &someclass::bla, > boost::python::return_value_policy() > ); > > Is there a way to register a return value conversion for "const > std::string&" so I can omit the > "boost::python::return_value_policy()" > every time I have to wrap this functions ? I wan't those strings to be > copied to python as new strings (I don't want to hold a pointer to them). I think I would rather use boost::python::return_value_policy ccr; class_.def("name", &someclass::bla, ccr); class_.def("name2", &someclass::bla2, ccr); ... (You could also derive your own class_-like wrapper from class_ and add def() overloads accordingly, or "defs" for "define string-returning function", but the latter would not improve much then, and the former is more work.) -- Ciao, / / /--/ / / ANS From bharadwaj_9023 at yahoo.co.in Sat Dec 23 13:10:51 2006 From: bharadwaj_9023 at yahoo.co.in (sai bharadwaj) Date: Sat, 23 Dec 2006 12:10:51 +0000 (GMT) Subject: [C++-sig] Your confirmation is required to join the C++-sig mailing list In-Reply-To: Message-ID: <20061223121051.31747.qmail@web7806.mail.in.yahoo.com> -- Bharadwaj Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php -------------- next part -------------- An HTML attachment was scrubbed... URL: From serguei.son at citigroup.com Thu Dec 28 22:44:54 2006 From: serguei.son at citigroup.com (Son, Serguei) Date: Thu, 28 Dec 2006 16:44:54 -0500 Subject: [C++-sig] Extending Python with not-basic-c++ Message-ID: David For a great example of embedding Python in a game, check out Civilization IV.