From wilson.max at gmail.com Thu Nov 1 00:02:16 2007 From: wilson.max at gmail.com (Maximilian Wilson) Date: Wed, 31 Oct 2007 16:02:16 -0700 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com> <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> Message-ID: <2ddbda5f0710311602w4bc6da57gc6967a9ed4ccd89f@mail.gmail.com> On Oct 31, 2007 1:11 PM, Matthew Scouten wrote: > Ok, I just found this: > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > > I seems to be saying that I can not do what I want with out patching > Boost::Python (or does this only apply to multiple interpretors? ) > Is this still true (please tell me it's been fixed)? > if so, where can I get this patch and how do I apply it? > I think this is simply saying that you need to treat the Python interpreter as a protected resource/critical section. As I understand your problem, you have only one C++ thread using the interpreter so the fact that BP isn't thread-aware shouldn't matter to you. My thought on reading your original post was it's possible that your "minor worker threads" are interacting with variables used by your Python-using thead, and thus that your assumption #1 doesn't hold. However, presumably you've already checked out this possibility or you wouldn't be triple-checking your assumptions. -Max -------------- next part -------------- An HTML attachment was scrubbed... URL: From Nicolas.Rougier at loria.fr Thu Nov 1 11:38:11 2007 From: Nicolas.Rougier at loria.fr (Nicolas P. Rougier) Date: Thu, 1 Nov 2007 11:38:11 +0100 Subject: [C++-sig] Fix for TypeError: __init__() should return None, not 'NoneType' Message-ID: <3389B802-7B64-4F21-8155-12AEA8EEC083@loria.fr> Hi all, Just for the record: While browsing sig-c++ archive I found the question about getting the message: Error: TypeError: __init__() should return None, not 'NoneType' I got the same error message on MacOS. The reason was that I installed framework python 2.5, build boost for this version but linked my program against python2.3 (got no warning from the compiler) because the version I installed did not provide the libpython2.5.dylib link to the library. A simple fix is to actually make the link: cd ~/lib ln -s /Library/Frameworks/Python.framework/Versions/2.5/Python libpython2.5.dylib and link against python2.5, not python (which is indeed python2.3). Hope this helps. Nicolas From matthew.scouten at gmail.com Thu Nov 1 17:31:20 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 1 Nov 2007 11:31:20 -0500 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <642889.6428.qm@web31107.mail.mud.yahoo.com> References: <642889.6428.qm@web31107.mail.mud.yahoo.com> Message-ID: <3dc9bcf00711010931n74abce26w5522eaf5b2c208ab@mail.gmail.com> The you seem to be saying that the problem is the GIL rather than the problem is with the GIL rather than Boost::Python itself. Does the I am already making sure to acquire the GIL before I call into python. Here is an example of a callback wrapper: void DataConsumer_wrapper::OnSampleCallback( int a1, int a2) { {callback call; if (override func = this->get_override("OnSampleCallback")) { func(a1,a2 ); return; } }// end callback call; return DataConsumer::OnSampleCallback(a1,a2); } As I mentioned before: 'callback call' calls PyGILState_Ensure in its ctor and PyGILState_Release in its dtor. So I believe I have acquired the GIL correctly. My thought was that it was some internal data structure in boost python that needed locking as well. But I have the GIL before I touch any thing in boost::python, so nothing is getting called from python and the callback thread should be the only one in B::P code. Do Niall Douglas' patches do anything except manage the GIL? If not than maybe my problem is not thread related after all, or maybe the GIL issue is subtler than I thought. Is there any one on this list who knows about the guts of Boost Python? I would appreciate their comments. On 10/31/07, Ralf W. Grosse-Kunstleve wrote: > > I don't know too much about threading, but I think > > - you still need Niall Douglas' patches > if your threads want > to call back into Python > - it is fair to say that the real problem is "Python & threading", > > mainly because of the dreaded global interpreter lock (GIL) > > Recently there has been some discussion on python-dev about getting > > rid of the GIL, but I'm not holding my breath... > > > IIUC, if your threads never call back into Python you don't have to > > deal with the GIL. > If you have to deal with the GIL I'm not surprised to see you > frustrated. This is something that was largely ignored in the > Boost.Python development (there is only so much you can hope to > achieve in a given amount of time...). > > > > In my work I've consciously avoided threading. Under this simplification > I find Boost.Python well documented and intuitive :-) > > Ralf > > > > ----- Original Message ---- > > From: Matthew Scouten > > To: Development of Python/C++ integration > > Sent: Wednesday, October 31, 2007 1:11:27 PM > > Subject: Re: [C++-sig] Am I crazy or is it my computer? > > > > Ok, I just found this: > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > > > > I seems to be saying that I can not do what I want with out patching > Boost::Python (or does this only apply to multiple interpretors? ) > > Is this still true (please tell me it's been fixed)? > > if so, where can I get this patch and how do I apply it? > > > > I asked about multi-threading and boost python in on this list a while > ago, and got no answer. I took this a a "go ahead, no problems". If I am > being an idiot, could you tell me so? Just flame away at me so I know I've > been stupid. A lot of people here actually know what they are doing. I do > not have that luxury. I am finding boost python extremely complex and > non-intuitive. There is also a lack of good documentation (example code is > nice to have, but does not constitute proper documentation all by itself). > > > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Thu Nov 1 17:34:23 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 1 Nov 2007 11:34:23 -0500 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <3dc9bcf00711010931n74abce26w5522eaf5b2c208ab@mail.gmail.com> References: <642889.6428.qm@web31107.mail.mud.yahoo.com> <3dc9bcf00711010931n74abce26w5522eaf5b2c208ab@mail.gmail.com> Message-ID: <3dc9bcf00711010934x5cd8844fmf303ad439efe6777@mail.gmail.com> Sorry apparently I can not write right today make that first paragraph: The you seem to be saying that the problem is the GIL rather than Boost::Python itself. I am already making sure to acquire the GIL before I call into python. Here is an example of a callback wrapper: On 11/1/07, Matthew Scouten wrote: > > The you seem to be saying that the problem is the GIL rather than the > problem is with the GIL rather than Boost::Python itself. Does the I am > already making sure to acquire the GIL before I call into python. Here is an > example of a callback wrapper: > > void DataConsumer_wrapper::OnSampleCallback( int a1, int a2) > { > {callback call; > if (override func = this->get_override("OnSampleCallback")) > { > func(a1,a2 ); > return; > } > }// end callback call; > return DataConsumer::OnSampleCallback(a1,a2); > } > > As I mentioned before: 'callback call' calls PyGILState_Ensure in its ctor > and PyGILState_Release in its dtor. So I believe I have acquired the GIL > correctly. > > My thought was that it was some internal data structure in boost python > that needed locking as well. But I have the GIL before I touch any thing in > boost::python, so nothing is getting called from python and the callback > thread should be the only one in B::P code. > > Do Niall Douglas' patches do anything except manage the GIL? If not than > maybe my problem is not thread related after all, or maybe the GIL issue is > subtler than I thought. > > Is there any one on this list who knows about the guts of Boost Python? I > would appreciate their comments. > > > > > > > On 10/31/07, Ralf W. Grosse-Kunstleve wrote: > > > > I don't know too much about threading, but I think > > > > - you still need Niall Douglas' patches > > if your threads want > > to call back into Python > > - it is fair to say that the real problem is "Python & threading", > > > > mainly because of the dreaded global interpreter lock (GIL) > > > > Recently there has been some discussion on python-dev about getting > > > > rid of the GIL, but I'm not holding my breath... > > > > > > IIUC, if your threads never call back into Python you don't have to > > > > deal with the GIL. > > If you have to deal with the GIL I'm not surprised to see you > > frustrated. This is something that was largely ignored in the > > Boost.Python development (there is only so much you can hope to > > achieve in a given amount of time...). > > > > > > > > In my work I've consciously avoided threading. Under this simplification > > I find Boost.Python well documented and intuitive :-) > > > > Ralf > > > > > > > > ----- Original Message ---- > > > > From: Matthew Scouten > > > > To: Development of Python/C++ integration > > > > Sent: Wednesday, October 31, 2007 1:11:27 PM > > > > Subject: Re: [C++-sig] Am I crazy or is it my computer? > > > > > > > > Ok, I just found this: > > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > > > > > > > > I seems to be saying that I can not do what I want with out patching > > Boost::Python (or does this only apply to multiple interpretors? ) > > > > Is this still true (please tell me it's been fixed)? > > > > if so, where can I get this patch and how do I apply it? > > > > > > > > I asked about multi-threading and boost python in on this list a while > > ago, and got no answer. I took this a a "go ahead, no problems". If I am > > being an idiot, could you tell me so? Just flame away at me so I know I've > > been stupid. A lot of people here actually know what they are doing. I do > > not have that luxury. I am finding boost python extremely complex and > > non-intuitive. There is also a lack of good documentation (example code is > > nice to have, but does not constitute proper documentation all by itself). > > > > > > > > > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jin at sohovfx.com Thu Nov 1 19:26:49 2007 From: jin at sohovfx.com (jjiinnnn) Date: Thu, 1 Nov 2007 11:26:49 -0700 (PDT) Subject: [C++-sig] failed in PyImport_Import() In-Reply-To: References: <87de5f460710242352w5b57dc4djbcfba96ccf0f3578@mail.gmail.com> Message-ID: <13534565.post@talk.nabble.com> Oh My goodness, I've been having the same problem and I have been trying to figure this out the entire day! and This solved it for me.. What a weird weird problem... Thank you so much Steaven Wyckoff! You are the life saver!! Steven Wyckoff wrote: > > > PyRun_SimpleString("import sys"); > PyRun_SimpleString("sys.path.append(\"your/path/here\")"); > > > -- View this message in context: http://www.nabble.com/failed-in-PyImport_Import%28%29-tf4688986.html#a13534565 Sent from the Python - c++-sig mailing list archive at Nabble.com. From jin at sohovfx.com Thu Nov 1 19:28:42 2007 From: jin at sohovfx.com (jjiinnnn) Date: Thu, 1 Nov 2007 11:28:42 -0700 (PDT) Subject: [C++-sig] failed in PyImport_Import() In-Reply-To: References: <87de5f460710242352w5b57dc4djbcfba96ccf0f3578@mail.gmail.com> Message-ID: <13534565.post@talk.nabble.com> Oh My goodness, I've been having the same problem and I have been trying to figure this out the entire day! and This solved it for me.. What a weird weird problem... Thank you so much Steven Wyckoff! You are the life saver!! Steven Wyckoff wrote: > > > PyRun_SimpleString("import sys"); > PyRun_SimpleString("sys.path.append(\"your/path/here\")"); > > > -- View this message in context: http://www.nabble.com/failed-in-PyImport_Import%28%29-tf4688986.html#a13534565 Sent from the Python - c++-sig mailing list archive at Nabble.com. From s_sourceforge at nedprod.com Thu Nov 1 21:58:00 2007 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 01 Nov 2007 20:58:00 -0000 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com>, <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> Message-ID: <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> On 31 Oct 2007 at 15:11, Matthew Scouten wrote: > Ok, I just found this: > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > > I seems to be saying that I can not do what I want with out patching > Boost::Python (or does this only apply to multiple interpretors? ) > Is this still true (please tell me it's been fixed)? > if so, where can I get this patch and how do I apply it? Follow the link to TnFOX given in the FAQ. Then study FXPython - heavily - and with a very fine toothed comb. > I asked about multi-threading and boost python in on this list a while ago, > and got no answer. I took this a a "go ahead, no problems". If I am being an > idiot, could you tell me so? Just flame away at me so I know I've been > stupid. I remember your question, and I didn't answer because the FAQ answers and I don't have the time to answer FAQ answered questions. I think the Boost.Python homepage could do with a large flashing neon sign saying "CHECK THE FAQ BEFORE ASKING A QUESTION" right before "SEARCH THE C++ SIG MAILING LIST ARCHIVES BEFORE ASKING A QUESTION". Had you done either, you would have known the answer. Now with the berating being done, I must express my sympathies for your task. I wrapped TnFOX for Python using Boost.Python and it was extremely painful indeed. It can be done, but expect at least 200 hours of programmer time to wrap your head around it. Once you know what you're doing, it becomes quite easy. > A lot of people here actually know what they are doing. I do not > have that luxury. I am finding boost python extremely complex and > non-intuitive. There is also a lack of good documentation (example code is > nice to have, but does not constitute proper documentation all by itself). Actually, the docs are pretty good. I would have cut out my own tongue to admit that a few years ago, but the problem is not the documentation - it's the programmer thinking in old style C++ ways. Once you wrap your head around Boost.Python, it becomes quite intuitive. I can now happilly plug around its internals and do anything I like fairly confidently. It's actually quite a simple & intuitive design though I do wish there were more usage examples out there - and also I wish more interfaces were publicly defined & solid. Now I have designed the machinery needed to get threaded C++ and Python working. It took me months, and it's not pretty at all and rather easy to break if you modify it. But copying me would be the easiest by far. BTW I reckon your problems stem from the GIL not only being a lock but also being a state variable for Python. This state varies, unpredictably, during and between locks whenever you touch Python at all (including via any other thread). Touching BPL in any way usually means touching Python, so basically dragons abound here. This will explain the often erratic & weird ordering of actions in FXPython in TnFOX - I worked it out after many hours in the debugger watching Python, C++, and Boost.Python interact. I suggest you copy my form closely in your endeavours. Good luck! Cheers, Niall From wilson.max at gmail.com Fri Nov 2 00:50:02 2007 From: wilson.max at gmail.com (Maximilian Wilson) Date: Thu, 1 Nov 2007 16:50:02 -0700 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com> <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> Message-ID: <2ddbda5f0711011650s7f5d26c0h5073e6b94873e1d@mail.gmail.com> On Nov 1, 2007 1:58 PM, Niall Douglas wrote: > I remember your question, and I didn't answer because the FAQ answers > and I don't have the time to answer FAQ answered questions. I think > the Boost.Python homepage could do with a large flashing neon sign > saying "CHECK THE FAQ BEFORE ASKING A QUESTION" right before "SEARCH > THE C++ SIG MAILING LIST ARCHIVES BEFORE ASKING A QUESTION". > Matthew actually did mention the FAQ in his second post. Since I'm not clear on the issue yet either, is the FAQ saying that it's not safe to use Boost::Python in multi-threaded C++ code even if only one C++ thread uses the interpreter? Because that seems very odd to me. -Max -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Fri Nov 2 22:58:55 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Fri, 2 Nov 2007 16:58:55 -0500 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com> <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> Message-ID: <3dc9bcf00711021458i29465549h53718d9c1365549c@mail.gmail.com> On 11/1/07, Niall Douglas wrote: > > On 31 Oct 2007 at 15:11, Matthew Scouten wrote: > > > Ok, I just found this: > > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > > > > I seems to be saying that I can not do what I want with out patching > > Boost::Python (or does this only apply to multiple interpretors? ) > > Is this still true (please tell me it's been fixed)? > > if so, where can I get this patch and how do I apply it? > > Follow the link to TnFOX given in the FAQ. Then study FXPython - > heavily - and with a very fine toothed comb. > > > I asked about multi-threading and boost python in on this list a while > ago, > > and got no answer. I took this a a "go ahead, no problems". If I am > being an > > idiot, could you tell me so? Just flame away at me so I know I've been > > stupid. > > I remember your question, and I didn't answer because the FAQ answers > and I don't have the time to answer FAQ answered questions. I think > the Boost.Python homepage could do with a large flashing neon sign > saying "CHECK THE FAQ BEFORE ASKING A QUESTION" right before "SEARCH > THE C++ SIG MAILING LIST ARCHIVES BEFORE ASKING A QUESTION". > > Had you done either, you would have known the answer. > > Now with the berating being done, I must express my sympathies for > your task. I wrapped TnFOX for Python using Boost.Python and it was > extremely painful indeed. It can be done, but expect at least 200 > hours of programmer time to wrap your head around it. Once you know > what you're doing, it becomes quite easy. > > > A lot of people here actually know what they are doing. I do not > > have that luxury. I am finding boost python extremely complex and > > non-intuitive. There is also a lack of good documentation (example code > is > > nice to have, but does not constitute proper documentation all by > itself). > > Actually, the docs are pretty good. I would have cut out my own > tongue to admit that a few years ago, but the problem is not the > documentation - it's the programmer thinking in old style C++ ways. > > Once you wrap your head around Boost.Python, it becomes quite > intuitive. I can now happilly plug around its internals and do > anything I like fairly confidently. It's actually quite a simple & > intuitive design though I do wish there were more usage examples out > there - and also I wish more interfaces were publicly defined & > solid. > > Now I have designed the machinery needed to get threaded C++ and > Python working. It took me months, and it's not pretty at all and > rather easy to break if you modify it. But copying me would be the > easiest by far. > > BTW I reckon your problems stem from the GIL not only being a lock > but also being a state variable for Python. This state varies, > unpredictably, during and between locks whenever you touch Python at > all (including via any other thread). Touching BPL in any way usually > means touching Python, so basically dragons abound here. > > This will explain the often erratic & weird ordering of actions in > FXPython in TnFOX - I worked it out after many hours in the debugger > watching Python, C++, and Boost.Python interact. I suggest you copy > my form closely in your endeavours. > > Good luck! > > Cheers, > Niall I have downloaded your code and had a look at it. I have a few questions. First of all I do not have and do not need multiple interpretors(thank goodness). I am not sure what parts of what you did are for multi interpretors and what parts are for simple multi threading with one interpretor. I noticed that you did not use the PyGILState_Ensure & PyGILState_Release pair. This makes sense, because they is meant for a single interpretor environment. What I do not understand is: why they would not be sufficient in my environment. from the information at: http://svn.python.org/projects/peps/trunk/pep-0311.txt and http://docs.python.org/api/threads.html I can safely say that I am certain that they would be sufficient in a pure C/Python environment. I am calling _Ensure before touching any boost python, and not calling _Release until I am done with all boost python calls in a given callback. I have posted my example before: void DataConsumer_wrapper::OnSampleCallback( int a1, int a2) { {callback call; if (override func = this->get_override("OnSampleCallback")) { logfunc log("DataConsumer_wrapper::OnSampleCallback", true); func(a1,a2 ); return; } }// end callback call; return DataConsumer::OnSampleCallback(a1,a2); } This is a virtual function callback. The "callback call" line is calling PyGILState_Ensure: class callback { public: inline callback() { state = PyGILState_Ensure(); } inline ~callback() { PyGILState_Release(state); } private: PyGILState_STATE state; }; So If this was pure C/Python, I have obeyed the rules. My question is: Is there something in boost::python itself (as opposed to C/Python) that may be having a problem with this model? -------------- next part -------------- An HTML attachment was scrubbed... URL: From fullung at gmail.com Sat Nov 3 13:06:27 2007 From: fullung at gmail.com (Albert Strasheim) Date: Sat, 3 Nov 2007 14:06:27 +0200 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <3dc9bcf00711021458i29465549h53718d9c1365549c@mail.gmail.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com> <3dc9bcf00710311311sb096aa1oc4b926b92f3aaaa8@mail.gmail.com> <472A3DD8.447.137AE831@s_sourceforge.nedprod.com> <3dc9bcf00711021458i29465549h53718d9c1365549c@mail.gmail.com> Message-ID: <20071103120627.GA12758@dogbert.sdsl.sun.ac.za> Hello, On Fri, 02 Nov 2007, Matthew Scouten wrote: > What I do not understand is: why they would not be sufficient in my > environment. from the information at: > http://svn.python.org/projects/peps/trunk/pep-0311.txt > and > http://docs.python.org/api/threads.html I just skimmed through this thread, but I think you might be missing a call to PyEval_InitThreads() inside your BOOST_PYTHON_MODULE definition. I found that without this call, the calls to PyGILState_Ensure and PyGILState_Release are essentially no-ops. I don't know too much about threading, so I could be wrong, but my module seems to work, so maybe not. The code for my module is here: http://pyactivemq.googlecode.com/svn/trunk/ Mainly you want to look at: http://pyactivemq.googlecode.com/svn/trunk/src/main/pyactivemq.cpp http://pyactivemq.googlecode.com/svn/trunk/src/main/MessageListener.cpp Cheers, Albert From s_sourceforge at nedprod.com Sun Nov 4 02:37:42 2007 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 04 Nov 2007 01:37:42 -0000 Subject: [C++-sig] Am I crazy or is it my computer? In-Reply-To: <2ddbda5f0711011650s7f5d26c0h5073e6b94873e1d@mail.gmail.com> References: <3dc9bcf00710300858j1de24addyfc9970340a76879d@mail.gmail.com>, <472A3DD8.447.137AE831@s_sourceforge.nedprod.com>, <2ddbda5f0711011650s7f5d26c0h5073e6b94873e1d@mail.gmail.com> Message-ID: <472D2266.22865.3EFE57@s_sourceforge.nedprod.com> On 1 Nov 2007 at 16:50, Maximilian Wilson wrote: > > I remember your question, and I didn't answer because the FAQ answers > > and I don't have the time to answer FAQ answered questions. I think > > the Boost.Python homepage could do with a large flashing neon sign > > saying "CHECK THE FAQ BEFORE ASKING A QUESTION" right before "SEARCH > > THE C++ SIG MAILING LIST ARCHIVES BEFORE ASKING A QUESTION". > > > Matthew actually did mention the FAQ in his second post. Since I'm not clear > on the issue yet either, is the FAQ saying that it's not safe to use > Boost::Python in multi-threaded C++ code even if only one C++ thread uses > the interpreter? Because that seems very odd to me. You're 100% safe if: 1. Both BPL and python uses and is used in one and only one thread. 2. No other thread should touch anything related to BPL/python or anything associated with BPL/python. Now all that said, you can get away with a lot more than that. But python really wasn't designed to handle threads at all, you can't even have more than one interpreter in a single process yet :( I personally find this latter restriction to be incredibly daft and the clear result of vast overuse of static global variables :( Cheers, Niall From theboyhaddon at hotmail.com Sun Nov 4 04:11:34 2007 From: theboyhaddon at hotmail.com (john haddon) Date: Sun, 4 Nov 2007 03:11:34 +0000 Subject: [C++-sig] Boost.Python and garbage collection Message-ID: Hi, I've run into a problem with cyclic references between instances of objects bounds with boost::python - the garbage collector doesn't seem to be able to collect them. This is illustrated by the python code below : import weakref import gc # make a cyclic reference between instances of a bound class o1 = BoostPythonClass() o2 = BoostPythonClass() o1.r = o2 o2.r = o1 # make weak references to track their lifetime w1 = weakref.ref( o1 ) w2 = weakref.ref( o2 ) # delete the instances and run the garbage collector del o1 del o2 gc.collect() # check that the objects have been collected assert( w1() is None ) assert( w2() is None ) I dug a bit deeper into this and had a go at fixing things by implementing garbage collection support for instances in src/object/class.cpp. By implementing a traversal to instance::dict the problem seems to be fixed and the asserts in the test above pass. I've also run the unit tests for a largish project using boost python with this modified code and they pass ok. The changes are pretty slight - here's the output from diff : 354a355,373 > > static int instance_traverse( PyObject* op, visitproc visit, void* arg ) > { > instance<>* inst = downcast>(op); > if( inst->dict ) > { > return visit( inst->dict, arg ); > } > return 0; > } > > static int instance_clear( PyObject* op ) > { > instance<>* inst = downcast>(op); > PyObject* tmp = inst->dict; > inst->dict = 0; > python::xdecref( tmp ); > return 0; > } 391c410 < Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC --- > Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC 394,395c413,414 < 0, /* tp_traverse */ < 0, /* tp_clear */ --- > instance_traverse, /* tp_traverse */ > instance_clear, /* tp_clear */ The internals of boost::python are a bit of a mystery to me, so I don't know if I've missed something or if there's a good reason this isn't implemented already. I'm posting to the list in the hope that it might be useful and if I haven't messed up could get merged into the source. Cheers... John _________________________________________________________________ Express yourself with free Messenger emoticons. Get them today! http://www.freemessengeremoticons.ca/?icid=EMENCA122 From gjcarneiro at gmail.com Sun Nov 4 17:39:48 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Sun, 4 Nov 2007 16:39:48 +0000 Subject: [C++-sig] Boost.Python and garbage collection In-Reply-To: References: Message-ID: On 04/11/2007, john haddon wrote: > > > Hi, > > I've run into a problem with cyclic references between instances of > objects bounds with boost::python - the garbage collector doesn't seem to be > able to collect them. This is illustrated by the python code below : > > > > import weakref > import gc > > # make a cyclic reference between instances of a bound class > o1 = BoostPythonClass() > o2 = BoostPythonClass() > o1.r = o2 > o2.r = o1 > > # make weak references to track their lifetime > w1 = weakref.ref( o1 ) > w2 = weakref.ref( o2 ) > > # delete the instances and run the garbage collector > del o1 > del o2 > gc.collect() Maybe this doesn't invalidate your conclusions, but just a heads up: don't simply call "gc.collect()", instead do "while gc.collect(): pass". That is because sometimes multiple GC iterations are required to collect all objects. # check that the objects have been collected > assert( w1() is None ) > assert( w2() is None ) > > > > I dug a bit deeper into this and had a go at fixing things by implementing > garbage collection support for instances in src/object/class.cpp. By > implementing a traversal to instance::dict the problem seems to be fixed and > the asserts in the test above pass. I've also run the unit tests for a > largish project using boost python with this modified code and they pass ok. > The changes are pretty slight - here's the output from diff : > > > > 354a355,373 > > > > static int instance_traverse( PyObject* op, visitproc visit, void* > arg ) > > { > > instance<>* inst = downcast>(op); > > if( inst->dict ) > > { > > return visit( inst->dict, arg ); > > } > > return 0; > > } > > > > static int instance_clear( PyObject* op ) > > { > > instance<>* inst = downcast>(op); > > PyObject* tmp = inst->dict; > > inst->dict = 0; > > python::xdecref( tmp ); > > return 0; > > } > 391c410 > < Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC > --- > > Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC > 394,395c413,414 > < 0, /* tp_traverse */ > < 0, /* tp_clear */ > --- > > instance_traverse, /* tp_traverse */ > > instance_clear, /* tp_clear */ > > > The internals of boost::python are a bit of a mystery to me, so I don't > know if I've missed something or if there's a good reason this isn't > implemented already. I'm posting to the list in the hope that it might be > useful and if I haven't messed up could get merged into the source. > > Cheers... > John > _________________________________________________________________ > Express yourself with free Messenger emoticons. Get them today! > http://www.freemessengeremoticons.ca/?icid=EMENCA122 > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From theboyhaddon at hotmail.com Sun Nov 4 22:33:11 2007 From: theboyhaddon at hotmail.com (john haddon) Date: Sun, 4 Nov 2007 21:33:11 +0000 Subject: [C++-sig] Boost.Python and garbage collection In-Reply-To: References: Message-ID: >># delete the instances and run the garbage collector >>del o1 >>del o2 >>gc.collect() > >Maybe this doesn't invalidate your conclusions, but just a heads up: don't simply call " gc.collect()", instead do>"while gc.collect(): pass". That is because sometimes multiple GC iterations are required to collect all objects. Thanks for the tip. I've rerun the tests with your adjusted code and fortunately my mistake doesn't invalidate the original conclusion - which makes sense as without the additional code there's no way for the garbage collector to see the contents of the dict for the instance... _________________________________________________________________ Send a smile, make someone laugh, have some fun! Start now! http://www.freemessengeremoticons.ca/?icid=EMENCA122 From maikbeckmann at gmx.de Tue Nov 6 18:22:10 2007 From: maikbeckmann at gmx.de (MaikBeckmann) Date: Tue, 6 Nov 2007 17:22:10 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?numeric=3A=3Aarray_get=5Fpytype?= Message-ID: > Hello I'm playing around with num_util: http://www.eos.ubc.ca/research/clouds/software/ pythonlibs/num_util/num_util_release2/ While the compiler is happy with boost-1.34.1, it states when using trunk: get_pytype is not a member of boost::python::converter::object_manager_traits< boost::python::numeric::array > A comparison between 1.34.1 and the trunk shows that get_pytype was newly introduced, but numeric.hpp was not updated to use it. Has it just been forgotten?? Regards, - Maik Beckmann From j.reid at mail.cryst.bbk.ac.uk Tue Nov 6 19:02:17 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 06 Nov 2007 18:02:17 +0000 Subject: [C++-sig] numeric::array get_pytype In-Reply-To: References: Message-ID: MaikBeckmann wrote: > While the compiler is happy with boost-1.34.1, it states > when using trunk: > get_pytype is not a member of > boost::python::converter::object_manager_traits< > boost::python::numeric::array > I had a similar compile error when using the trunk with Raoul Gough's indexing suite. I have not got to the bottom of it yet. John. From rwgk at yahoo.com Tue Nov 6 20:22:12 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 6 Nov 2007 11:22:12 -0800 (PST) Subject: [C++-sig] numeric::array get_pytype Message-ID: <509837.76169.qm@web31106.mail.mud.yahoo.com> > A comparison between 1.34.1 and the trunk shows that > get_pytype was newly introduced, but numeric.hpp was not updated > to use it. > > Has it just been forgotten?? Probably. I hope Nick will take a look. In the meantime, does it work if you compile with -DBOOST_PYTHON_NO_PY_SIGNATURES ? Ralf From maikbeckmann at gmx.de Wed Nov 7 08:31:05 2007 From: maikbeckmann at gmx.de (Maik Beckmann) Date: Wed, 7 Nov 2007 07:31:05 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?numeric=3A=3Aarray_get=5Fpytype?= References: <509837.76169.qm@web31106.mail.mud.yahoo.com> Message-ID: Ralf W. Grosse-Kunstleve yahoo.com> writes: > In the meantime, does it work if you compile with -DBOOST_PYTHON_NO_PY_SIGNATURES ? > > Ralf It does, thx. - Maik From nickm at sitius.com Wed Nov 7 15:54:54 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 07 Nov 2007 09:54:54 -0500 Subject: [C++-sig] numeric::array get_pytype References: Message-ID: <4731D1BE.E8A9624C@sitius.com> Hi John, I responded to your problem. Did you apply the change? Nikolay John Reid wrote: > > MaikBeckmann wrote: > > While the compiler is happy with boost-1.34.1, it states > > when using trunk: > > get_pytype is not a member of > > boost::python::converter::object_manager_traits< > > boost::python::numeric::array > > > I had a similar compile error when using the trunk with Raoul Gough's > indexing suite. I have not got to the bottom of it yet. > > John. From nickm at sitius.com Wed Nov 7 16:20:40 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 07 Nov 2007 10:20:40 -0500 Subject: [C++-sig] numeric::array get pytype References: Message-ID: <4731D7C8.46843020@sitius.com> Hi Maik, I have missed that file, sorry. Could you send me a snippet that duplicates this? I will also put it into the tests. Regards, Nikolay MaikBeckmann wrote: > > > > Hello > > I'm playing around with num_util: > http://www.eos.ubc.ca/research/clouds/software/ > pythonlibs/num_util/num_util_release2/ > > While the compiler is happy with boost-1.34.1, it states > when using trunk: > get_pytype is not a member of > boost::python::converter::object_manager_traits< > boost::python::numeric::array > > > > A comparison between 1.34.1 and the trunk shows that > get_pytype was newly introduced, but numeric.hpp was not updated > to use it. > > Has it just been forgotten?? > > Regards, > - Maik Beckmann From Sylvain.Pion at sophia.inria.fr Wed Nov 7 16:26:27 2007 From: Sylvain.Pion at sophia.inria.fr (Sylvain Pion) Date: Wed, 07 Nov 2007 16:26:27 +0100 Subject: [C++-sig] Mapping C++ typedefs to Python Message-ID: <4731D923.4020000@sophia.inria.fr> Hi, I use typedefs in C++, that is, several names for the same type (enums in my case). Is it possible to export this in Python? Is there the equivalent of typedefs in Python, and how can I specify this using Boost.Python? Thanks for any advice. -- Sylvain Pion INRIA Sophia-Antipolis Geometrica Project-Team CGAL, http://cgal.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4309 bytes Desc: S/MIME Cryptographic Signature URL: From nickm at sitius.com Wed Nov 7 16:40:54 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 07 Nov 2007 10:40:54 -0500 Subject: [C++-sig] numeric::array get pytype References: <4731D7C8.46843020@sitius.com> Message-ID: <4731DC86.839A5A04@sitius.com> Hi Maik, Ignore my prev post, I duplicated it, fix is comming shortly. Nick Nikolay Mladenov wrote: > > Hi Maik, > > I have missed that file, sorry. > > Could you send me a snippet that duplicates this? > I will also put it into the tests. > > Regards, > > Nikolay > > MaikBeckmann wrote: > > > > > > > Hello > > > > I'm playing around with num_util: > > http://www.eos.ubc.ca/research/clouds/software/ > > pythonlibs/num_util/num_util_release2/ > > > > While the compiler is happy with boost-1.34.1, it states > > when using trunk: > > get_pytype is not a member of > > boost::python::converter::object_manager_traits< > > boost::python::numeric::array > > > > > > > A comparison between 1.34.1 and the trunk shows that > > get_pytype was newly introduced, but numeric.hpp was not updated > > to use it. > > > > Has it just been forgotten?? > > > > Regards, > > - Maik Beckmann From j.reid at mail.cryst.bbk.ac.uk Wed Nov 7 16:57:27 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 07 Nov 2007 15:57:27 +0000 Subject: [C++-sig] numeric::array get_pytype In-Reply-To: <4731D1BE.E8A9624C@sitius.com> References: <4731D1BE.E8A9624C@sitius.com> Message-ID: Nikolay Mladenov wrote: > I responded to your problem. Did you apply the change? No I missed the post - thx for pointing it out, I shall try it when I get a chance to try to move to boost svn trunk again. Thanks, John. From nickm at sitius.com Wed Nov 7 17:08:50 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 07 Nov 2007 11:08:50 -0500 Subject: [C++-sig] numeric::array get pytype References: Message-ID: <4731E312.34170589@sitius.com> Fixed in the trunk. Nikolay MaikBeckmann wrote: > > > > Hello > > I'm playing around with num_util: > http://www.eos.ubc.ca/research/clouds/software/ > pythonlibs/num_util/num_util_release2/ > > While the compiler is happy with boost-1.34.1, it states > when using trunk: > get_pytype is not a member of > boost::python::converter::object_manager_traits< > boost::python::numeric::array > > > > A comparison between 1.34.1 and the trunk shows that > get_pytype was newly introduced, but numeric.hpp was not updated > to use it. > > Has it just been forgotten?? > > Regards, > - Maik Beckmann From nat at lindenlab.com Wed Nov 7 17:20:44 2007 From: nat at lindenlab.com (Nat Goodspeed) Date: Wed, 07 Nov 2007 11:20:44 -0500 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <4731D923.4020000@sophia.inria.fr> References: <4731D923.4020000@sophia.inria.fr> Message-ID: <4731E5DC.4040507@lindenlab.com> Sylvain Pion wrote: > I use typedefs in C++, that is, several names for the same type > (enums in my case). > Is it possible to export this in Python? > Is there the equivalent of typedefs in Python, and how > can I specify this using Boost.Python? enums: http://boost.org/libs/python/doc/tutorial/doc/html/python/object.html#python.enums If you have several C++ names for the same type, wouldn't it work to export each of them as though they were distinct? Unless I'm missing something, neither Python nor Boost.Python needs to know their sameness. From maikbeckmann at gmx.de Wed Nov 7 18:14:00 2007 From: maikbeckmann at gmx.de (Maik Beckmann) Date: Wed, 7 Nov 2007 17:14:00 +0000 (UTC) Subject: [C++-sig] numeric::array get pytype References: <4731E312.34170589@sitius.com> Message-ID: Nikolay Mladenov sitius.com> writes: > > Fixed in the trunk. > > Nikolay Everything works smooth. Thank you for your fast engagement! - Maik From roman.yakovenko at gmail.com Wed Nov 7 19:00:53 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 7 Nov 2007 20:00:53 +0200 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <4731E5DC.4040507@lindenlab.com> References: <4731D923.4020000@sophia.inria.fr> <4731E5DC.4040507@lindenlab.com> Message-ID: <7465b6170711071000o2d114d99hc5f1d8a467f7156d@mail.gmail.com> On 11/7/07, Nat Goodspeed wrote: > > Sylvain Pion wrote: > > > I use typedefs in C++, that is, several names for the same type > > (enums in my case). > > Is it possible to export this in Python? > > Is there the equivalent of typedefs in Python, and how > > can I specify this using Boost.Python? > > enums: > > > http://boost.org/libs/python/doc/tutorial/doc/html/python/object.html#python.enums > > If you have several C++ names for the same type, wouldn't it work to > export each of them as though they were distinct? Unless I'm missing > something, neither Python nor Boost.Python needs to know their sameness. This approach introduces compile & size overhead, plus you will get few warnings during module loading. The better one is to wrap exposed module with Python package and to add all aliases within it. For example: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/examples/pyboost_dev/pyboost/date_time/__init__.py?revision=642&view=markup -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Nov 7 19:10:10 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 07 Nov 2007 13:10:10 -0500 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <4731E5DC.4040507@lindenlab.com> References: <4731D923.4020000@sophia.inria.fr> <4731E5DC.4040507@lindenlab.com> Message-ID: <4731FF82.3060206@sympatico.ca> Nat Goodspeed wrote: > Sylvain Pion wrote: > >> I use typedefs in C++, that is, several names for the same type >> (enums in my case). >> Is it possible to export this in Python? >> Is there the equivalent of typedefs in Python, and how >> can I specify this using Boost.Python? > > enums: > > http://boost.org/libs/python/doc/tutorial/doc/html/python/object.html#python.enums > > If you have several C++ names for the same type, wouldn't it work to > export each of them as though they were distinct? Unless I'm missing > something, neither Python nor Boost.Python needs to know their sameness. That's technically correct, though I'm not sure what the purpose of this would be. Why duplicate code like this ? In Python type aliases are even easier than in C++, as types are assignable objects. So, why do it from within boost.python, and not inside python ? class Foo: pass Bar = Foo # 'Bar' is now the equivalent of C++'s typedef, aliasing 'Foo' Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Sylvain.Pion at sophia.inria.fr Wed Nov 7 20:12:36 2007 From: Sylvain.Pion at sophia.inria.fr (Sylvain Pion) Date: Wed, 07 Nov 2007 20:12:36 +0100 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <4731FF82.3060206@sympatico.ca> References: <4731D923.4020000@sophia.inria.fr> <4731E5DC.4040507@lindenlab.com> <4731FF82.3060206@sympatico.ca> Message-ID: <47320E24.7030501@sophia.inria.fr> Stefan Seefeld a ?crit : > Nat Goodspeed wrote: >> Sylvain Pion wrote: >> >>> I use typedefs in C++, that is, several names for the same type >>> (enums in my case). >>> Is it possible to export this in Python? >>> Is there the equivalent of typedefs in Python, and how >>> can I specify this using Boost.Python? >> enums: >> >> http://boost.org/libs/python/doc/tutorial/doc/html/python/object.html#python.enums >> >> If you have several C++ names for the same type, wouldn't it work to >> export each of them as though they were distinct? Unless I'm missing >> something, neither Python nor Boost.Python needs to know their sameness. > > That's technically correct, though I'm not sure what the purpose of this > would be. Why duplicate code like this ? In Python type aliases are even > easier than in C++, as types are assignable objects. So, why do it from > within boost.python, and not inside python ? > > class Foo: pass > > Bar = Foo # 'Bar' is now the equivalent of C++'s typedef, aliasing 'Foo' Thanks everybody for the suggestions and explanations. I finally solved the problem within Python. The reason I asked to do this within C++ using Boost.Python is that this would have regrouped my code in the same place (after all, this is a property of the C++ code which I want to describe). BTW, this comes from me porting CGAL-Python to CGAL 3.3. -- Sylvain Pion INRIA Sophia-Antipolis Geometrica Project-Team CGAL, http://cgal.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4309 bytes Desc: S/MIME Cryptographic Signature URL: From hans_meine at gmx.net Wed Nov 7 21:55:11 2007 From: hans_meine at gmx.net (Hans Meine) Date: Wed, 7 Nov 2007 21:55:11 +0100 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <47320E24.7030501@sophia.inria.fr> References: <4731D923.4020000@sophia.inria.fr> <4731FF82.3060206@sympatico.ca> <47320E24.7030501@sophia.inria.fr> Message-ID: <200711072155.11469.hans_meine@gmx.net> On Mittwoch 07 November 2007, Sylvain Pion wrote: > > Bar = Foo # 'Bar' is now the equivalent of C++'s typedef, aliasing 'Foo' > > Thanks everybody for the suggestions and explanations. > I finally solved the problem within Python. > > The reason I asked to do this within C++ using Boost.Python is that > this would have regrouped my code in the same place (after all, this > is a property of the C++ code which I want to describe). I am using scope().attr("Bar") = scope().attr("Foo"); to achieve the same using the BPL. -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From Sylvain.Pion at sophia.inria.fr Thu Nov 8 10:48:01 2007 From: Sylvain.Pion at sophia.inria.fr (Sylvain Pion) Date: Thu, 08 Nov 2007 10:48:01 +0100 Subject: [C++-sig] Mapping C++ typedefs to Python In-Reply-To: <200711072155.11469.hans_meine@gmx.net> References: <4731D923.4020000@sophia.inria.fr> <4731FF82.3060206@sympatico.ca> <47320E24.7030501@sophia.inria.fr> <200711072155.11469.hans_meine@gmx.net> Message-ID: <4732DB51.60701@sophia.inria.fr> Hans Meine a ?crit : > On Mittwoch 07 November 2007, Sylvain Pion wrote: >>> Bar = Foo # 'Bar' is now the equivalent of C++'s typedef, aliasing 'Foo' >> Thanks everybody for the suggestions and explanations. >> I finally solved the problem within Python. >> >> The reason I asked to do this within C++ using Boost.Python is that >> this would have regrouped my code in the same place (after all, this >> is a property of the C++ code which I want to describe). > > I am using > scope().attr("Bar") = scope().attr("Foo"); > to achieve the same using the BPL. Thanks Hans! This is exactly what I was looking for. -- Sylvain Pion INRIA Sophia-Antipolis Geometrica Project-Team CGAL, http://cgal.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 4309 bytes Desc: S/MIME Cryptographic Signature URL: From nomicon at pacbell.net Fri Nov 9 11:11:31 2007 From: nomicon at pacbell.net (nomicon) Date: Fri, 09 Nov 2007 02:11:31 -0800 Subject: [C++-sig] Problems sending and receiving a map container Message-ID: <47343253.8040607@pacbell.net> Hi I am having problems sending and receiving a C++ map container to and from python. I have successfully embedded the python interpreter into my C++ code. I defined an abstract base class in C++ and exported it to python using Boost. In python I can inherit from this class. In C++ I can read in the python module, create an instance of a python object then send and receive integers values as you would a C++ method. So for example, I have exported a method called "SetData". SetData currently takes an integer value. After I create a python object in C++ I can call SetData from C++ as such: pyObject->SetData( 520 ) and python will get the value (520 in this case). My "GetData method is able to return an integer value from python. All is good so far. What I would like to do is pass in a C++ map container (e.g. map) to python instead of passing an integer. I would also like to get a map container back from python. I have read the map_indexing_suite tutorial, Boost FAQs, Python C++ forums and looked at the test programs provided with Boost. Many indicate that this is possible but still I am completly baffled on how to actually implement this. Does anyone have an example that they could share showing how they implemented sending and receiving a C++ map container to and from python using Boost? Any advice on this subject would be greatly appreciated. many thanks, Mark From simon at dackbrann.net Sun Nov 11 17:11:42 2007 From: simon at dackbrann.net (Simon Norberg) Date: Sun, 11 Nov 2007 17:11:42 +0100 Subject: [C++-sig] Problem Crosscompiling boost python modules Message-ID: <473729BE.7080106@dackbrann.net> Hello, I am trying to crosscompile my boost-python module with mingw creating a windows module. After alot of problems trying to cross compile boost python i got it pre compiled from http://gforge.inria.fr/frs/?group_id=79. I can crosscompile this small test code : http://pastebin.com/f569662b8 with i586-mingw32msvc-g++ hello.cpp -shared -o hello.pyd -I/usr/local/i586-mingw32/include/soci/ -I/usr/local/i586-mingw32/include/soci/sqlite3/ -I/usr/local/i586-mingw32/include -I /usr/local/i586-mingw32/include/ -I /usr/local/i586-mingw32/include/python/ -I /usr/i586-mingw32msvc/include/ -L/usr/local/i586-mingw32//lib /usr/local/i586-mingw32/lib/libsoci_core-gcc-2_2.a /usr/local/i586-mingw32/lib/libsoci_sqlite3-gcc-2_2.a /usr/local/i586-mingw32/lib/libsqlite3.a /usr/local/i586-mingw32/lib/libpython25.a /usr/local/i586-mingw32/lib/boost_python-mgw.a but this test code: http://pastebin.com/f32c03a4e compiled with: i586-mingw32msvc-g++ test_db.cpp -shared -o test_db.pyd -I/usr/local/i586-mingw32/include/soci/ -I/usr/local/i586-mingw32/include/soci/sqlite3/ -I/usr/local/i586-mingw32/include -I /usr/local/i586-mingw32/include/ -I /usr/local/i586-mingw32/include/python/ -I /usr/i586-mingw32msvc/include/ -L/usr/local/i586-mingw32//lib /usr/local/i586-mingw32/lib/libsoci_core-gcc-2_2.a /usr/local/i586-mingw32/lib/libsoci_sqlite3-gcc-2_2.a /usr/local/i586-mingw32/lib/libsqlite3.a /usr/local/i586-mingw32/lib/libpython25.a /usr/local/i586-mingw32/lib/boost_python-mgw.a results in this error: In file included from /usr/local/i586-mingw32/include/python/Python.h:92, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/stringobject.h:63: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/stringobject.h:64: error: ISO C++ forbids declaration of `parameter' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:114, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/pyerrors.h:328: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/pyerrors.h:329: error: ISO C++ forbids declaration of `va' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:119, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/modsupport.h:23: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:23: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:35: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:35: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:37: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:37: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:38: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:38: error: ISO C++ forbids declaration of `parameter' with no type simon at debian:~/yapa/branches/test$ i586-mingw32msvc-g++ hello.cpp -shared -o hello.pyd -I/usr/local/i586-mingw32/include/soci/ -I/usr/local/i586-mingw32/include/soci/sqlite3/ -I/usr/local/i586-mingw32/include -I /usr/local/i586-mingw32/include/ -I /usr/local/i586-mingw32/include/python/ -I /usr/i586-mingw32msvc/include/ -L/usr/local/i586-mingw32//lib /usr/local/i586-mingw32/lib/libsoci_core-gcc-2_2.a /usr/local/i586-mingw32/lib/libsoci_sqlite3-gcc-2_2.a /usr/local/i586-mingw32/lib/libsqlite3.a /usr/local/i586-mingw32/lib/libpython25.a /usr/local/i586-mingw32/lib/boost_python-mgw.a simon at debian:~/yapa/branches/test$ gedit hello.cpp simon at debian:~/yapa/branches/test$ gedit test_db.cpp simon at debian:~/yapa/branches/test$ i586-mingw32msvc-g++ test_db.cpp -shared -o test_db.pyd -I/usr/local/i586-mingw32/include/soci/ -I/usr/local/i586-mingw32/include/soci/sqlite3/ -I/usr/local/i586-mingw32/include -I /usr/local/i586-mingw32/include/ -I /usr/local/i586-mingw32/include/python/ -I /usr/i586-mingw32msvc/include/ -L/usr/local/i586-mingw32//lib /usr/local/i586-mingw32/lib/libsoci_core-gcc-2_2.a /usr/local/i586-mingw32/lib/libsoci_sqlite3-gcc-2_2.a /usr/local/i586-mingw32/lib/libsqlite3.a /usr/local/i586-mingw32/lib/libpython25.a /usr/local/i586-mingw32/lib/boost_python-mgw.a In file included from /usr/local/i586-mingw32/include/python/Python.h:92, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/stringobject.h:63: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/stringobject.h:64: error: ISO C++ forbids declaration of `parameter' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:114, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/pyerrors.h:328: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/pyerrors.h:329: error: ISO C++ forbids declaration of `va' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:119, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from test_db.cpp:45: /usr/local/i586-mingw32/include/python/modsupport.h:23: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:23: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:35: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:35: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:37: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:37: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:38: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:38: error: ISO C++ forbids declaration of `parameter' with no type Any hints on whats wrong i highly appreciated, I have worked with getting boost python to cross compile all day :( The version of mingw-g++ is i586-mingw32msvc-g++ (GCC) 3.4.5 (mingw special) got it with apt-get in Debian Etch Regards, Simon Norberg From p.jaroszynski at gmail.com Thu Nov 15 18:17:28 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Thu, 15 Nov 2007 18:17:28 +0100 Subject: [C++-sig] Wrapper for exception translation - resurrection? :) Message-ID: <200711151817.30128.p.jaroszynski@gmail.com> Hello, I am in need of a better exceptions support in boost.python and I found a very interesting discussion [1], which is pretty close to what I was thinking about. The question is whether there was any actual progress with it? I want to try and implement it if it's still something that would be accepted. [1] - http://osdir.com/ml/python.c++/2003-07/msg00202.html -- Best Regards, Piotr Jaroszy?ski From dave at boost-consulting.com Thu Nov 15 18:57:51 2007 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 15 Nov 2007 12:57:51 -0500 Subject: [C++-sig] Wrapper for exception translation - resurrection? :) In-Reply-To: <200711151817.30128.p.jaroszynski@gmail.com> ("Piotr =?utf-8?Q?Jaroszy=C5=84ski=22's?= message of "Thu\, 15 Nov 2007 18\:17\:28 +0100") References: <200711151817.30128.p.jaroszynski@gmail.com> Message-ID: <87bq9vjsrk.fsf@grogan.peloton> on Thu Nov 15 2007, Piotr Jaroszy?ski wrote: > Hello, > > I am in need of a better exceptions support in boost.python and I found a very > interesting discussion [1], which is pretty close to what I was thinking > about. The question is whether there was any actual progress with it? > > I want to try and implement it if it's still something that would be accepted. > > [1] - http://osdir.com/ml/python.c++/2003-07/msg00202.html I think it could be. It's a long thread and I don't have time to completely refresh my memory, but if I was favorable to it once, I probably would be again. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From Matt.Knox at tdam.com Fri Nov 16 20:43:22 2007 From: Matt.Knox at tdam.com (mattknox_ca) Date: Fri, 16 Nov 2007 11:43:22 -0800 (PST) Subject: [C++-sig] python-extension depending on other project Message-ID: <13800157.post@talk.nabble.com> Hi there, I have 2 projects I am trying to build, one is a C++ shared library, the other is a C++ python extension. My python extension needs to link to the shared library, and hence the shared library needs to be built first. However, bjam won't let me specify the library (test.a) as a requirement for the python extension because it doesn't exist when it is invoked. It won't exist until the shared library poject is built. So I am not sure how to build these two things using a common Jamroot. My Jamroot looks like this: ###### Jamroot ####### import os ; BOOST_ROOT = [ os.environ BOOST_ROOT ] ; use-project /boost : $(BOOST_ROOT) ; project test : requirements /boost/python//boost_python some_folder ; # pure C++ shared library build-project c_lib ; # python extension build-project py_ext ; ############################## Then I have 2 subfolders (c_lib and py_ext) with the following Jamfile's: ###### Jamfile for c_lib project ####### import os ; # Declare a library called test lib test : test.cpp ; C_LIBS = [ os.environ C_LIBS ] ; # copies built library to current directory install . : test : $(C_LIBS)lib ; ###### Jamfile for py_ext project ####### import os ; C_LIBS = [ os.environ C_LIBS ] ; project quant : requirements $(C_LIBS)lib/test.a ; # Declare a Python extension called _holiday. python-extension py_ext : py_ext.cpp ; # copies built library to current directory install . : py_ext ; ############################## This results in the error "error: Unable to find file or target named..." because test.a does not exist yet. So basically my question is, how do I properly specify these dependencies here? I realize I am probably doing something rather stupid, but if someone could point out the error in my ways I would be extremely grateful. Thanks! - Matt -- View this message in context: http://www.nabble.com/python-extension-depending-on-other-project-tf4823455.html#a13800157 Sent from the Python - c++-sig mailing list archive at Nabble.com. From matthew.scouten at gmail.com Fri Nov 16 21:31:24 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Fri, 16 Nov 2007 14:31:24 -0600 Subject: [C++-sig] A wrapped class contains another wrapped class. Hilarity ensues. Message-ID: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> I have 2 c++ classes called foo and bar. I wrapped both. bar contains a foo as a public data member. foo contains a function called get_buffer that is exported as "__str__" and as the getter of the property 'buffer' if I construct a foo, I can call that function with no problem. if I create a bar and try to call the function on its foo I get an error. My C++ and B::P code: class foo { public: foo() {std::strcpy(buffer, "good bye cruel world!\0\0");} char buffer[24]; }; struct foo_wrapper : foo , wrapper { foo_wrapper(const foo& f); foo_wrapper(); //property getters std::string get_buffer() const; }; foo_wrapper::foo_wrapper(const foo& exch): foo(exch), wrapper(){} foo_wrapper::foo_wrapper(): foo(), wrapper(){} std::string foo_wrapper::get_buffer() const { return std::string(foo::buffer); } class bar { public: foo f; }; class bar_wrapper: public bar, public wrapper { public: bar_wrapper(); bar_wrapper(const bar &); }; bar_wrapper::bar_wrapper() : bar(), wrapper(){} bar_wrapper::bar_wrapper(const bar &bb ) : bar(bb), wrapper(){} BOOST_PYTHON_MODULE(BusyBox) { class_("foo") .def(init<>()) .add_property("buffer", &foo_wrapper::get_buffer) .def("__str__", &foo_wrapper::get_buffer) ; class_("bar") .def_readwrite("f", &bar::f) ; } A REPL session that demos the errors:>>> from BusyBox import * >>> f1 = foo() >>> >>> f1.buffer 'good bye cruel world!' >>> str(f1) 'good bye cruel world!' >>> >>> b1 = bar() >>> >>> b1.f.buffer #Generates error Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in None.None(foo) did not match C++ signature: None(struct foo_wrapper {lvalue}) >>> str(b1.f) #Generates error Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in foo.__str__(foo) did not match C++ signature: __str__(struct foo_wrapper {lvalue}) >>> >>> f2 = b1.f >>> >>> b2.buffer #Generates error Traceback (most recent call last): File "", line 1, in NameError: name 'b2' is not defined >>> str(f2) #Generates error Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in foo.__str__(foo) did not match C++ signature: __str__(struct foo_wrapper {lvalue}) >>> I feel like I must be doing something stupid. What is wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Sun Nov 18 00:17:13 2007 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 17 Nov 2007 18:17:13 -0500 Subject: [C++-sig] pep362 Message-ID: I know there was some interest in this, so: http://pypi.python.org/pypi/pep362/ From simon at dackbrann.net Sun Nov 18 17:58:39 2007 From: simon at dackbrann.net (Simon Norberg) Date: Sun, 18 Nov 2007 17:58:39 +0100 Subject: [C++-sig] Problem Crosscompiling boost python modules In-Reply-To: <473729BE.7080106@dackbrann.net> References: <473729BE.7080106@dackbrann.net> Message-ID: <47406F3F.8010502@dackbrann.net> I have continued trying to crosscompile boost python modules, and i found something that i cant understand why it results in errors. lets begin with: http://pastebin.com/f569662b8 it corsscompiles perfectly with: i586-mingw32msvc-g++ hello.cpp -shared -o hello.pyd -I/usr/local/i586-mingw32/include/soci/ -I/usr/local/i586-mingw32/include/soci/sqlite3/ -I/usr/local/i586-mingw32/include -I /usr/local/i586-mingw32/include/ -I /usr/local/i586-mingw32/include/python/ -I /usr/i586-mingw32msvc/include/ -L/usr/local/i586-mingw32//lib /usr/local/i586-mingw32/lib/libsoci_core-gcc-2_2.a /usr/local/i586-mingw32/lib/libsoci_sqlite3-gcc-2_2.a /usr/local/i586-mingw32/lib/libsqlite3.a /usr/local/i586-mingw32/lib/libpython25.a /usr/local/i586-mingw32/lib/boost_python-mgw.a butt if i add this 2 lines to the beginning of the file: #include "soci.h" #include "soci-sqlite3.h" and compile with exactly the same options i get: In file included from /usr/local/i586-mingw32/include/python/Python.h:92, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from hello.cpp:28: /usr/local/i586-mingw32/include/python/stringobject.h:63: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/stringobject.h:64: error: ISO C++ forbids declaration of `parameter' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:114, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from hello.cpp:28: /usr/local/i586-mingw32/include/python/pyerrors.h:328: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/pyerrors.h:329: error: ISO C++ forbids declaration of `va' with no type In file included from /usr/local/i586-mingw32/include/python/Python.h:119, from /usr/local/i586-mingw32/include/boost/python/detail/wrap_python.hpp:142, from /usr/local/i586-mingw32/include/boost/python/detail/prefix.hpp:13, from /usr/local/i586-mingw32/include/boost/python/module.hpp:8, from hello.cpp:28: /usr/local/i586-mingw32/include/python/modsupport.h:23: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:23: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:35: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:35: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:37: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:37: error: ISO C++ forbids declaration of `parameter' with no type /usr/local/i586-mingw32/include/python/modsupport.h:38: error: `va_list' has not been declared /usr/local/i586-mingw32/include/python/modsupport.h:38: error: ISO C++ forbids declaration of `parameter' with no type And then i don't even use anything at all from those libraries, and the error are not related to those libraries either as far as i can tell. Regards Simon Norberg From rwgk at yahoo.com Mon Nov 19 01:17:23 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 18 Nov 2007 16:17:23 -0800 (PST) Subject: [C++-sig] Problem Crosscompiling boost python modules Message-ID: <522858.36890.qm@web31101.mail.mud.yahoo.com> See: http://docs.python.org/api/includes.html Boost.Python takes care of this as much as possible if you include a header first. Ralf From simon at dackbrann.net Mon Nov 19 21:08:16 2007 From: simon at dackbrann.net (Simon Norberg) Date: Mon, 19 Nov 2007 21:08:16 +0100 Subject: [C++-sig] Problem Crosscompiling boost python modules In-Reply-To: <522858.36890.qm@web31101.mail.mud.yahoo.com> References: <522858.36890.qm@web31101.mail.mud.yahoo.com> Message-ID: <4741ED30.9090104@dackbrann.net> > See: http://docs.python.org/api/includes.html > Boost.Python takes care of this as much as possible if you include > a header first. > Ralf > Thank you, works perfect now :) From nguyenxuanson at gmail.com Tue Nov 20 12:06:12 2007 From: nguyenxuanson at gmail.com (Nguyen Xuan Son) Date: Tue, 20 Nov 2007 11:06:12 +0000 Subject: [C++-sig] boost/python tutorial Message-ID: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> Hi I run the command line to build the \boost\libs\python\example\tutorial >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 I see that everything run correctly and I check the folder \boost\libs\python\example\tutorial\bin\hello.test\msvc- 8.0\debug\threading-multi and the output told me everything is OK. But I find no where the DLL, and I could not load the extension from the python command line: >>> import hello_ext Traceback (most recent call last): File "", line 1, in -toplevel- import hello_ext ImportError: No module named hello_ext Can someone help me out of this? I really confused. Son -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.VanSickle at CanfieldSci.com Tue Nov 20 15:55:35 2007 From: Scott.VanSickle at CanfieldSci.com (Scott VanSickle) Date: Tue, 20 Nov 2007 09:55:35 -0500 Subject: [C++-sig] boost/python tutorial In-Reply-To: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> Message-ID: <997199507FD49A4EA997EE1E7626474638E48E44B6@Pan.domain-01> You need to copy the generated pyd and lib files into a folder that corresponds to the name of your Python module under your Python root folder. Note that the pyd is the DLL, the lib is the DLL's import library. If you don't use namespaces, I think that the pyd and lib should be copied directly into your Python root folder. Create an __init__.py file in the module folder that looks something like this #============ import sys sys.path.append('..\..') # this brings in the DLL (pyd) from _hello_ext import * #============ You should then be able to import your hello_ext module in any of your Python code. Scott V From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nguyen Xuan Son Sent: Tuesday, November 20, 2007 6:06 AM To: c++-sig at python.org Subject: [C++-sig] boost/python tutorial Hi I run the command line to build the \boost\libs\python\example\tutorial >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 I see that everything run correctly and I check the folder \boost\libs\python\example\tutorial\bin\hello.test\msvc-8.0\debug\threading-multi and the output told me everything is OK. But I find no where the DLL, and I could not load the extension from the python command line: >>> import hello_ext Traceback (most recent call last): File "", line 1, in -toplevel- import hello_ext ImportError: No module named hello_ext Can someone help me out of this? I really confused. Son From nguyenxuanson at gmail.com Tue Nov 20 18:13:37 2007 From: nguyenxuanson at gmail.com (Nguyen Xuan Son) Date: Tue, 20 Nov 2007 17:13:37 +0000 Subject: [C++-sig] boost/python tutorial In-Reply-To: <997199507FD49A4EA997EE1E7626474638E48E44B6@Pan.domain-01> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> <997199507FD49A4EA997EE1E7626474638E48E44B6@Pan.domain-01> Message-ID: <884aa930711200913m5465c3c8w4690f4353e4fd855@mail.gmail.com> Hi, after the run there are two folders created A/ \boost\libs\python\example\tutorial\bin\msvc- 8.0\debug\threading-multi I find: 20/11/2007 16:59 . 20/11/2007 16:59 .. 20/11/2007 13:26 406,907 hello.obj 20/11/2007 13:26 178 hello.obj.rsp 20/11/2007 13:28 535 hello_ext.exp 20/11/2007 13:28 1,752 hello_ext.lib 20/11/2007 13:28 543,744 hello_ext.pdb 20/11/2007 13:28 385 hello_ext.pyd.manifest 20/11/2007 13:28 173 hello_ext.pyd.rsp 20/11/2007 16:59 0 list.txt 8 File(s) 953,674 bytes 2 Dir(s) 2,935,967,744 bytes free B/ \boost\libs\python\example\tutorial\bin\hello.test\msvc- 8.0\debug\threading-multi I find: 20/11/2007 17:00 . 20/11/2007 17:00 .. 20/11/2007 13:28 34 hello 20/11/2007 13:28 34 hello.output 20/11/2007 13:28 9 hello.test 20/11/2007 17:00 0 list.txt 4 File(s) 77 bytes 2 Dir(s) 2,935,959,552 bytes free There is no lib file there. I copy files in A/ to C:\Python24\Lib\site-packages\hello_ext and try to launch the file hello.py localy (which i had copied to this folder as well). So I am still stuck here. Please help me out:( SOn On Nov 20, 2007 2:55 PM, Scott VanSickle wrote: > You need to copy the generated pyd and lib files into a folder that > corresponds to the name of your Python module under your Python root folder. > Note that the pyd is the DLL, the lib is the DLL's import library. If you > don't use namespaces, I think that the pyd and lib should be copied directly > into your Python root folder. > > Create an __init__.py file in the module folder that looks something like > this > > #============ > import sys > > sys.path.append('..\..') > > # this brings in the DLL (pyd) > from _hello_ext import * > > #============ > > You should then be able to import your hello_ext module in any of your > Python code. > > Scott V > > > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of Nguyen Xuan Son > Sent: Tuesday, November 20, 2007 6:06 AM > To: c++-sig at python.org > Subject: [C++-sig] boost/python tutorial > > Hi > I run the command line to build the \boost\libs\python\example\tutorial > > >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 > > I see that everything run correctly and I check the folder > \boost\libs\python\example\tutorial\bin\hello.test\msvc- > 8.0\debug\threading-multi > > and the output told me everything is OK. But I find no where the DLL, and > I could not load the extension from the python command line: > >>> import hello_ext > > Traceback (most recent call last): > File "", line 1, in -toplevel- > import hello_ext > ImportError: No module named hello_ext > > Can someone help me out of this? I really confused. > > Son > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.VanSickle at CanfieldSci.com Tue Nov 20 19:13:10 2007 From: Scott.VanSickle at CanfieldSci.com (Scott VanSickle) Date: Tue, 20 Nov 2007 13:13:10 -0500 Subject: [C++-sig] boost/python tutorial In-Reply-To: <884aa930711200913m5465c3c8w4690f4353e4fd855@mail.gmail.com> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> <997199507FD49A4EA997EE1E7626474638E48E44B6@Pan.domain-01> <884aa930711200913m5465c3c8w4690f4353e4fd855@mail.gmail.com> Message-ID: <997199507FD49A4EA997EE1E7626474638E48E44D8@Pan.domain-01> Son, We don't use the bjam command line method that you are using to build the module; we build a different way as follows. We have a boostbuild.cmd that looks like this: ======================= set BOOST_BUILD_PATH=%BOOST_ROOT%\tools\build\v2 set PATH=%PATH%;%BOOST_ROOT%;%PYTHON_ROOT%;**your optional additional paths go here** set LIB=%LIB%;**additional optional LIB paths go here**;%BOOST_ROOT%\stage\lib set BUILD="%1" bjam toolset=msvc %BUILD% ======================= We launch boostbuild.cmd with a command line parm of either debug or release We also have a boost-build.jam file in the folder with boostbuild.cmd that looks like this (I don't think that this is being used): ======================= # Copyright David Abrahams 2006. Distributed under the Boost # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # Edit this path to point at the tools/build/v2 subdirectory of your # Boost installation. Absolute paths work, too. boost-build $BOOST_ROOT/tools/build/v2 ; ======================= Note that we use a BOOST_ROOT environment variable on all of our systems to point to where boost is. In the folder with the CPP is a jamroot file that looks like this: ======================= # Copyright David Abrahams 2006. Distributed under the Boost # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # Specify the path to the Boost project. If you move this project, # adjust the path to refer to the Boost root directory. use-project boost : $(BOOST_ROOT) ; # Set up the project-wide requirements that everything uses the # boost_python library defined in the project whose global ID is # /boost/python. project : requirements /boost/python//boost_python ; # Declare a Python extension python-extension _**name of ext goes here** # Declare a Python extension : **name of CPP with wrapper class(es) goes here** # Source : **your includes go here** **your defines go here** : **your lib path goes here**$(BOOST_ROOT)/stage/lib ; ======================= Assuming that the wrapper CPP compiles (you'll get done quicker if you make sure that the CPP compiles in your C++ dev environment first), running "boostbuild debug" generates a bunch of files with a base name that matches the Python module name in jamroot, including the _name.lib and _name.pyd files. We copy the lib and pyd to the folder where the CPP is, then everything works as long as you have the __init__.py that I previously described in that folder. If you copy the pdb file also (or if it can be found in your path), you will be able to debug the pyd module in Visual Studio once Python loads it. FYI - we use a Python wrapped class that dumps messages by calling the Windows OutputDebugString function and make use of the sysinternals DebugView tool to see the messages. This can help you to easily see what's going on in your Python code. There are probably other tools out there to do something like this that you could find; if you are using something like Komodo to debug your code you might not need anything else. I hope that this helps. Scott VanSickle From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Nguyen Xuan Son Sent: Tuesday, November 20, 2007 12:14 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] boost/python tutorial Hi, after the run there are two folders created A/ \boost\libs\python\example\tutorial\bin\msvc-8.0\debug\threading-multi I find: 20/11/2007 16:59 ????????? . 20/11/2007 16:59 ????????? .. 20/11/2007 13:26 406,907 hello.obj 20/11/2007 13:26 178 hello.obj.rsp 20/11/2007 13:28 535 hello_ext.exp 20/11/2007 13:28 1,752 hello_ext.lib 20/11/2007 13:28 543,744 hello_ext.pdb 20/11/2007 13:28 385 hello_ext.pyd.manifest 20/11/2007 13:28 173 hello_ext.pyd.rsp 20/11/2007 16:59 0 list.txt 8 File(s) 953,674 bytes 2 Dir(s) 2,935,967,744 bytes free B/ \boost\libs\python\example\tutorial\bin\hello.test\msvc-8.0\debug\threading-multi I find: 20/11/2007 17:00 ????????? . 20/11/2007 17:00 ????????? .. 20/11/2007 13:28 34 hello 20/11/2007 13:28 34 hello.output 20/11/2007 13:28 9 hello.test 20/11/2007 17:00 0 list.txt 4 File(s) 77 bytes 2 Dir(s) 2,935,959,552 bytes free There is no lib file there. I copy files in A/ to C:\Python24\Lib\site-packages\hello_ext and try to launch the file hello.py localy (which i had copied to this folder as well). So I am still stuck here. Please help me out:( SOn On Nov 20, 2007 2:55 PM, Scott VanSickle wrote: You need to copy the generated pyd and lib files into a folder that corresponds to the name of your Python module under your Python root folder. Note that the pyd is the DLL, the lib is the DLL's import library. If you don't use namespaces, I think that the pyd and lib should be copied directly into your Python root folder. Create an __init__.py file in the module folder that looks something like this #============ import sys sys.path.append('..\..') # this brings in the DLL (pyd) from _hello_ext import * #============ You should then be able to import your hello_ext module in any of your Python code. Scott V From: c++-sig-bounces at python.org [mailto: c++-sig-bounces at python.org] On Behalf Of Nguyen Xuan Son Sent: Tuesday, November 20, 2007 6:06 AM To: c++-sig at python.org Subject: [C++-sig] boost/python tutorial Hi I run the command line to build the \boost\libs\python\example\tutorial >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 I see that everything run correctly and I check the folder \boost\libs\python\example\tutorial\bin\hello.test\msvc-8.0\debug\threading-multi and the output told me everything is OK. But I find no where the DLL, and I could not load the extension from the python command line: >>> import hello_ext Traceback (most recent call last): File "", line 1, in -toplevel- import hello_ext ImportError: No module named hello_ext Can someone help me out of this? I really confused. Son _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From joel at boost-consulting.com Wed Nov 21 01:44:38 2007 From: joel at boost-consulting.com (Joel de Guzman) Date: Wed, 21 Nov 2007 08:44:38 +0800 Subject: [C++-sig] boost/python tutorial In-Reply-To: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> Message-ID: <47437F76.8060303@boost-consulting.com> Nguyen Xuan Son wrote: > Hi > I run the command line to build the \boost\libs\python\example\tutorial > > >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 > > I see that everything run correctly and I check the folder > \boost\libs\python\example\tutorial\bin\hello.test\msvc-8.0\debug\threading-multi > > and the output told me everything is OK. But I find no where the DLL, > and I could not load the extension from the python command line: > >>> import hello_ext > > Traceback (most recent call last): > File "", line 1, in -toplevel- > import hello_ext > ImportError: No module named hello_ext > > Can someone help me out of this? I really confused. If you are using Boost 1.34 and above, please use the new instructions here: http://svn.boost.org/svn/boost/trunk/libs/python/doc/tutorial/doc/html/python/hello.html Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From nguyenxuanson at gmail.com Wed Nov 21 09:08:47 2007 From: nguyenxuanson at gmail.com (Nguyen Xuan Son) Date: Wed, 21 Nov 2007 08:08:47 +0000 Subject: [C++-sig] boost/python tutorial In-Reply-To: <47437F76.8060303@boost-consulting.com> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> <47437F76.8060303@boost-consulting.com> Message-ID: <884aa930711210008j79be9906r4ac2bb506da14a20@mail.gmail.com> hi Joel 1/ I have the lasted version of boost/trunk, have it build with "install" parameter correctly. 2/ I did follow the instruction and check the content of all file in \bin\hello.test which show that test are all passed. 3/ but I can not load the extension from Python command line. I am stuck at point 3. Maybe I am low these days:) Son On Nov 21, 2007 12:44 AM, Joel de Guzman wrote: > Nguyen Xuan Son wrote: > > Hi > > I run the command line to build the \boost\libs\python\example\tutorial > > > > >bjam -sPYTHON_ROOT=C:/Python24 -sPYTHON_VERSION=2.4 -sTOOLS=vc8 > > > > I see that everything run correctly and I check the folder > > \boost\libs\python\example\tutorial\bin\hello.test\msvc- > 8.0\debug\threading-multi > > > > and the output told me everything is OK. But I find no where the DLL, > > and I could not load the extension from the python command line: > > >>> import hello_ext > > > > Traceback (most recent call last): > > File "", line 1, in -toplevel- > > import hello_ext > > ImportError: No module named hello_ext > > > > Can someone help me out of this? I really confused. > > If you are using Boost 1.34 and above, please use the > new instructions here: > > > http://svn.boost.org/svn/boost/trunk/libs/python/doc/tutorial/doc/html/python/hello.html > > Regards, > -- > Joel de Guzman > http://www.boost-consulting.com > http://spirit.sf.net > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlisee at gmail.com Wed Nov 21 19:19:27 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Wed, 21 Nov 2007 18:19:27 +0000 (UTC) Subject: [C++-sig] =?utf-8?q?Py++_and_a_std=3A=3Avector_of_shared=5Fptrs?= Message-ID: Hello, I am trying to wrap a std::vector >, and Py++ will have none of it. I am using indexing suite version 2, and telling Py++ to right the module as multiple files. I exclude everything at the global namespace level then I find the namespace_t that corresponds to the "sample" namespace and include all of it. When I attempt to compile the resulting files I get the following error: Here is the compile error (with lots of "instantiated here", before this): /opt/ram/local/include/boost-1_34_1/boost/python/suite/indexing/value_traits.hpp :56: error: no match for ?operator*)p1)->boost::shared_ptr::operator* [with T = samples::A]() < ((const boost::shared_ptr*)p2)->boost::shared_ptr::operator* [with T = samples::A]()? scons: *** [build/wrappers/samples/generated/vector_less_boost_scope_shared_ptr_less_sample s_scope_A_grate__comma_std_scope_allocator_less_boost_scope_shared_ptr_less_sam ples_scope_A_grate___grate___grate_.pypp.os] Error 1 That error appears only why I try to wrap the "funcVectorShared" function, without that function the code compile and works fine. Here is the code the generates it: SharedPtrVector.h: #ifndef RAM_TEST_SHAREDPTRVECTOR_H #define RAM_TEST_SHAREDPTRVECTOR_H // STD Includes #include // Library Includes #include namespace samples { class A { }; boost::shared_ptr func(); std::vector funcVector(); std::vector > funcVectorShared(); } #endif // RAM_TEST_SHAREDPTRVECTOR_H SharedPtrVector.cpp: #include "include/SharedPtrVector.h" namespace samples { boost::shared_ptr func() { return boost::shared_ptr(new A()); } std::vector funcVector() { std::vector items; items.push_back(A()); items.push_back(A()); return items; } std::vector > funcVectorShared() { std::vector > items; items.push_back(boost::shared_ptr(new A())); items.push_back(boost::shared_ptr(new A())); return items; } } From p.jaroszynski at gmail.com Wed Nov 21 20:48:43 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Wed, 21 Nov 2007 20:48:43 +0100 Subject: [C++-sig] Wrapper for exception translation - resurrection? :) In-Reply-To: <87bq9vjsrk.fsf@grogan.peloton> References: <200711151817.30128.p.jaroszynski@gmail.com> <87bq9vjsrk.fsf@grogan.peloton> Message-ID: <200711212048.45329.p.jaroszynski@gmail.com> Hello again, For those, who don't read #boost all the time, the idea is to allow exposing C++ exceptions like that: class_ > (...) and probably: exception > (...) which would do the same thing as class_ and also register some default exception translator. First thing I did was injecting a Python exception as a base in new_class (object/class.cpp). That was rather easy and the type I get back from the object result = object(class_metatype())(name, bases, d); seems fine, afair it is exactly the same as the one I get from PyErr_NewException function. But new_class isn't the whole story. There are a few things done after it, which also modify the type (including the change of tp_init, which seems to be important). To test this new stuff I have created a simple module exposing a basic class and an exception translator: // Our C++ exception (PyExc_BaseException base is forced in the new_class) bp::class_ ("Foo", bp::no_init).def_readonly("msg", &Foo::msg); // function that raises Foo bp::def("cpp_raise", &cpp_raise); // translator bp::register_exception_translator(&translator); void translator(const Foo & f) { // Make a new "good" exception type using the PyErr_NewException PyTypeObject * good_et((PyTypeObject*)PyErr_NewException("exception.exc", PyExc_BaseException, 0)); // Fetch our type registered in boost.python PyTypeObject * bad_et( bp::converter::registered::converters.get_class_object()); // Approach 1 // Get the tp_init from good_et - otherwise PyEval_CallObject fails bad_et->tp_init = good_et->tp_init; // Create the exception instance PyObject * bad_e(PyEval_CallObject((PyObject*)bad_et, PyTuple_New(0))); // End of approach 1 // Approach 2 // Use the bp::object to create a new instance - segfaults PyObject * bad_e(bp::incref(bp::object(f).ptr())); // End of approach 2 // Raise the exception PyErr_SetObject((PyObject*)bad_et, bad_e); } Approach 1: try: cpp_raise() - raises Foo except Foo, e: - works print dir(e) - works print e.message - works, this data member is from the BaseException print e.msg - fails (see below), this is the msg data member we exposed Boost.Python.ArgumentError: Python argument types in None.None(Foo) did not match C++ signature: None(Foo {lvalue}) ^^ Seems boost.python doesn't like Foo instances created this way Approach 2: try: cpp_raise() - raises Foo except Foo, e: - works print e.msg - works, this is the msg data member we exposed print dir(e) - segfault print e.message - segfault GC SEGFAULT All the segfaults are caused by the fact that make_instance_impl (object/make_instance.hpp) is not making a "real" instance of the type, it is only calling type->tp_alloc, which doesn't run all the functions (BaseException_* in Objects/exception.c in Python source) necessary to make a proper Python exception object and leaves it with uninitialized data. I suppose make_instance is working like that b/c it wasn't designed to create instances of types derived from native Python classes, but I can only guess here. To sum up, it seems that if we manage to take the working parts from both approaches we get what we want, but it may not be as simple as it sounds and that's why I am asking for hints/comments/suggestions/solutions... -- Best Regards, Piotr Jaroszy?ski From roman.yakovenko at gmail.com Wed Nov 21 22:11:18 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 21 Nov 2007 23:11:18 +0200 Subject: [C++-sig] Py++ and a std::vector of shared_ptrs In-Reply-To: References: Message-ID: <7465b6170711211311s4a6cefdeq840c25d5f4212f67@mail.gmail.com> On Nov 21, 2007 8:19 PM, Joseph Lisee wrote: > Hello, > > I am trying to wrap a std::vector >, and Py++ > will > have none of it. I am using indexing suite version 2, and telling Py++ to > right > the module as multiple files. I exclude everything at the global > namespace > level then I find the namespace_t that corresponds to the "sample" > namespace and > include all of it. When I attempt to compile the resulting files I get > the > following error: > > Here is the compile error (with lots of "instantiated here", before this): > > /opt/ram/local/include/boost-1_34_1/boost/python/suite/indexing/value_traits.hpp > :56: > error: no match for 'operator<' in '((const > boost::shared_ptr*)p1)->boost::shared_ptr::operator* [with > T = > samples::A]() < ((const > boost::shared_ptr*)p2)->boost::shared_ptr::operator* [with > T = > samples::A]()' > scons: *** > > [build/wrappers/samples/generated/vector_less_boost_scope_shared_ptr_less_sample > > s_scope_A_grate__comma_std_scope_allocator_less_boost_scope_shared_ptr_less_sam > ples_scope_A_grate___grate___grate_.pypp.os] > Error 1 > Py++ is not as smart as it could be :-). The root of the problem is class A, it doesn't defines operator== and operator<. On the other side indexing suite v2 is smart enough to understand, that container contains pointers, so it will not compare pointers but pointee. I was not aware to this functionality so didn't implemented it. Solution: 0. to create patch to Py++ to support this functionality :-))) or 1. add comparison operators to the class ( you can use free operators too ) or 2. disable methods, which require compare operators: f = mb.free_fun( 'funcVectorShared' ) v = declarations.remove_declarated( f.return_type ) v.indexing_suite.disable_method( 'sort' ) v.indexing_suite.disable_method( 'count' ) v.indexing_suite.disable_method( 'index' ) v.indexing_suite.disable_method( 'contains' ) HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogeeff at gmail.com Thu Nov 22 20:12:29 2007 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Thu, 22 Nov 2007 14:12:29 -0500 Subject: [C++-sig] std::list export Message-ID: How do I export std::list, so I can iterate over it in for statement? I really only need read-only iteration support. Gennadiy From roman.yakovenko at gmail.com Thu Nov 22 20:23:57 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 22 Nov 2007 21:23:57 +0200 Subject: [C++-sig] std::list export In-Reply-To: References: Message-ID: <7465b6170711221123s15d9e8d2q4432dac90ab746d5@mail.gmail.com> On Nov 22, 2007 9:12 PM, Gennadiy Rozental wrote: > How do I export std::list, so I can iterate over it in for statement? > > I really only need read-only iteration support. > > If you really new read-only iteration than you can use "iterator" or "range" functionality http://boost.org/libs/python/doc/v2/iterator.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogeeff at gmail.com Fri Nov 23 04:58:07 2007 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Thu, 22 Nov 2007 22:58:07 -0500 Subject: [C++-sig] exporting function objects Message-ID: What is a correct way to export class A with operator() implemented as callable object? Genandiy From rwgk at yahoo.com Fri Nov 23 05:48:31 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 22 Nov 2007 20:48:31 -0800 (PST) Subject: [C++-sig] exporting function objects Message-ID: <467192.53158.qm@web31115.mail.mud.yahoo.com> I think this should work: class_("A") .def("__call__", &A::operator()) ; Ralf ----- Original Message ---- From: Gennadiy Rozental To: c++-sig at python.org Sent: Thursday, November 22, 2007 7:58:07 PM Subject: [C++-sig] exporting function objects What is a correct way to export class A with operator() implemented as callable object? Genandiy _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From rogeeff at gmail.com Fri Nov 23 06:19:36 2007 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Fri, 23 Nov 2007 00:19:36 -0500 Subject: [C++-sig] exporting function objects References: <467192.53158.qm@web31115.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" wrote in message news:467192.53158.qm at web31115.mail.mud.yahoo.com... >I think this should work: > > class_("A") > .def("__call__", &A::operator()) > ; This one I figured out. But it seems clumsy. I would much prefer class_("A") .def( self() ) Gennadiy From j.reid at mail.cryst.bbk.ac.uk Fri Nov 23 09:50:31 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 23 Nov 2007 08:50:31 +0000 Subject: [C++-sig] exporting function objects In-Reply-To: References: <467192.53158.qm@web31115.mail.mud.yahoo.com> Message-ID: Gennadiy Rozental wrote: > This one I figured out. But it seems clumsy. I would much prefer > class_("A") > .def( self() ) How do you think it is clumsy? To someone who knows about how __call__ works in python its intent is more obvious. From joel at boost-consulting.com Mon Nov 26 07:19:07 2007 From: joel at boost-consulting.com (Joel de Guzman) Date: Mon, 26 Nov 2007 14:19:07 +0800 Subject: [C++-sig] boost/python tutorial In-Reply-To: <884aa930711210008j79be9906r4ac2bb506da14a20@mail.gmail.com> References: <884aa930711200306l50b6fceena4d830c2919b34d3@mail.gmail.com> <47437F76.8060303@boost-consulting.com> <884aa930711210008j79be9906r4ac2bb506da14a20@mail.gmail.com> Message-ID: Nguyen Xuan Son wrote: > hi Joel > 1/ I have the lasted version of boost/trunk, have it build with > "install" parameter correctly. > 2/ I did follow the instruction and check the content of all file in > \bin\hello.test which show that test are all passed. > 3/ but I can not load the extension from Python command line. > > I am stuck at point 3. Maybe I am low these days:) > Son You can find the paths to the DLL and the module from the bjam command line output. In the tutorial: And so on... Finally: Creating library path-to-boost_python.dll Creating library path-to-'''hello_ext'''.exp **passed** ... hello.test ...updated 35 targets... You can simply grab those and place them in your Python command line path. Or.. you can also do: bjam -n (or -d+2) and copy the python invocation, with the part that sets env vars before it. and directly run the same command. HTH. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From matthew.scouten at gmail.com Mon Nov 26 22:05:30 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Mon, 26 Nov 2007 15:05:30 -0600 Subject: [C++-sig] A wrapped class contains another wrapped class. Hilarity ensues. In-Reply-To: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> References: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> Message-ID: <3dc9bcf00711261305m232ee380t3fd163295cfd0d32@mail.gmail.com> After one week with no reply I think I must have asked a stupid question (or one that is so crazy difficult that no one knows the answer). Still search as I might, I can not understand what is wrong here, or why it does not work. Maybe I do not understand some important concept that world make the answer obvious (I am rather new to python after all). Much googleing found this link: http://mail.python.org/pipermail/c++-sig/2005-August/009339.html I do not think that his problem is quite the same as mine, but there were just enough hits to be more frustrating than helpful. Why is the error message telling me about l-values when I am not trying to assign to anything, just call a function on it? What are to/from python converters exactly? Are they related to, or the same as l-value,r-value converters? Why would I define them manually? I thought that was what I was doing when I wrapped the class in the first place. Is that really my problem, or is it more (or less) subtle than that? If I really am being a dumb ass, please feel free to flame me (as long as you include a link to the answers I apparently should have found on my own, to prove I am a dumb ass). On Nov 16, 2007 2:31 PM, Matthew Scouten wrote: > I have 2 c++ classes called foo and bar. I wrapped both. bar contains a > foo as a public data member. foo contains a function called get_buffer that > is exported as "__str__" and as the getter of the property 'buffer' > > if I construct a foo, I can call that function with no problem. > if I create a bar and try to call the function on its foo I get an error. > > My C++ and B::P code: > > class foo > { > public: > > foo() {std::strcpy(buffer, "good bye cruel world!\0\0");} > char buffer[24]; > }; > > struct foo_wrapper : foo , wrapper > { > foo_wrapper(const foo& f); > foo_wrapper(); > > //property getters > std::string get_buffer() const; > }; > > foo_wrapper::foo_wrapper(const foo& exch): foo(exch), wrapper(){} > > foo_wrapper::foo_wrapper(): foo(), wrapper(){} > > std::string foo_wrapper::get_buffer() const > { > return std::string(foo::buffer); > } > > > class bar > { > public: > foo f; > }; > > class bar_wrapper: public bar, public wrapper > { > public: > bar_wrapper(); > bar_wrapper(const bar &); > }; > > bar_wrapper::bar_wrapper() : bar(), wrapper(){} > > bar_wrapper::bar_wrapper(const bar &bb ) : bar(bb), wrapper(){} > > BOOST_PYTHON_MODULE(BusyBox) > { > > class_("foo") > .def(init<>()) > .add_property("buffer", &foo_wrapper::get_buffer) > .def("__str__", &foo_wrapper::get_buffer) > ; > > class_("bar") > .def_readwrite("f", &bar::f) > ; > } > > A REPL session that demos the errors:>>> from BusyBox import * > >>> f1 = foo() > >>> > >>> f1.buffer > 'good bye cruel world!' > >>> str(f1) > 'good bye cruel world!' > >>> > >>> b1 = bar() > >>> > >>> b1.f.buffer #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > None.None(foo) > did not match C++ signature: > None(struct foo_wrapper {lvalue}) > >>> str(b1.f) #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > foo.__str__(foo) > did not match C++ signature: > __str__(struct foo_wrapper {lvalue}) > >>> > >>> f2 = b1.f > >>> > >>> b2.buffer #Generates error > Traceback (most recent call last): > File "", line 1, in > NameError: name 'b2' is not defined > >>> str(f2) #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > foo.__str__(foo) > did not match C++ signature: > __str__(struct foo_wrapper {lvalue}) > >>> > > I feel like I must be doing something stupid. What is wrong? > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Nov 27 08:50:26 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 27 Nov 2007 09:50:26 +0200 Subject: [C++-sig] A wrapped class contains another wrapped class. Hilarity ensues. In-Reply-To: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> References: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> Message-ID: <7465b6170711262350k2b4d84d1q93cf2171012be8bc@mail.gmail.com> On Nov 16, 2007 10:31 PM, Matthew Scouten wrote: > I have 2 c++ classes called foo and bar. I wrapped both. bar contains a foo as a public data member. foo contains a function called get_buffer that is exported as "__str__" and as the getter of the property 'buffer' > > if I construct a foo, I can call that function with no problem. > if I create a bar and try to call the function on its foo I get an error. > > My C++ and B::P code: > > class foo > { > public: > > foo() {std::strcpy(buffer, "good bye cruel world!\0\0");} > char buffer[24]; > }; > > struct foo_wrapper : foo , wrapper > { > foo_wrapper(const foo& f); > foo_wrapper(); > > //property getters > std::string get_buffer() const; > }; > > foo_wrapper::foo_wrapper(const foo& exch): foo(exch), wrapper(){} > > foo_wrapper::foo_wrapper(): foo(), wrapper(){} > > std::string foo_wrapper::get_buffer() const > { > return std::string(foo::buffer); > } > > > class bar > { > public: > foo f; > }; > > class bar_wrapper: public bar, public wrapper > { > public: > bar_wrapper(); > bar_wrapper(const bar &); > }; > > bar_wrapper::bar_wrapper() : bar(), wrapper(){} > > bar_wrapper::bar_wrapper(const bar &bb ) : bar(bb), wrapper(){} > > BOOST_PYTHON_MODULE(BusyBox) > { > > class_("foo") > .def(init<>()) > .add_property("buffer", &foo_wrapper::get_buffer) > .def("__str__", &foo_wrapper::get_buffer) > ; > > class_("bar") > .def_readwrite("f", &bar::f) > ; > } > > A REPL session that demos the errors:>>> from BusyBox import * > >>> f1 = foo() > >>> > >>> f1.buffer > 'good bye cruel world!' > >>> str(f1) > 'good bye cruel world!' > >>> > >>> b1 = bar() > >>> > >>> b1.f.buffer #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > None.None(foo) > did not match C++ signature: > None(struct foo_wrapper {lvalue}) > >>> str(b1.f) #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > foo.__str__(foo) > did not match C++ signature: > __str__(struct foo_wrapper {lvalue}) > >>> > >>> f2 = b1.f > >>> > >>> b2.buffer #Generates error > Traceback (most recent call last): > File "", line 1, in > NameError: name 'b2' is not defined > >>> str(f2) #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > foo.__str__(foo) > did not match C++ signature: > __str__(struct foo_wrapper {lvalue}) > >>> > > I feel like I must be doing something stupid. What is wrong? You don't have, while the error messages contains enough information it is really difficult to new user to understand what is going wrong. > >>> str(f2) #Generates error > Traceback (most recent call last): > File "", line 1, in > Boost.Python.ArgumentError: Python argument types in > foo.__str__(foo) > did not match C++ signature: > __str__(struct foo_wrapper {lvalue}) > >>> The error message says that you cannot call foo.__str__ method with "foo" as "this" pointer, but you should provide "foo_wrapper" for this purpose. The library is right: >struct foo_wrapper : foo , wrapper > { > ... > std::string get_buffer() const; > }; In order to call get_buffer, the object type should be "foo_wrapper", not "foo". You didn't exposed "foo_wrapper" class, but "foo". If you define get_buffer as struct foo_wrapper : foo , wrapper { ... static std::string get_buffer(const foo& x ){ return std::string(x.buffer); } }; Everything will work as expected. The really confusing thing is that the library allowed you to call __str__ method on object constructed from Python. This is because internally it keeps foo_wrapper instance instead of "foo" one. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From matthew.scouten at gmail.com Tue Nov 27 18:59:48 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Tue, 27 Nov 2007 11:59:48 -0600 Subject: [C++-sig] A wrapped class contains another wrapped class. Hilarity ensues. In-Reply-To: <7465b6170711262350k2b4d84d1q93cf2171012be8bc@mail.gmail.com> References: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> <7465b6170711262350k2b4d84d1q93cf2171012be8bc@mail.gmail.com> Message-ID: <3dc9bcf00711270959l4feba16ld6218cb73b17e4c8@mail.gmail.com> AH! yes that worked. Thank you so much. It seems the real WTF here was that it seemed to work fine when the foo was instantiated directly from python. Because that seemed to work, I thought I was doing everything right until I get further into wrapping my library. Please ignore my earlier begging email. I was way the heck down the wrong path, looking for the wrong solutions, and getting very frustrated. Thank you all. On Nov 27, 2007 1:50 AM, Roman Yakovenko wrote: > On Nov 16, 2007 10:31 PM, Matthew Scouten > wrote: > > I have 2 c++ classes called foo and bar. I wrapped both. bar contains a > foo as a public data member. foo contains a function called get_buffer that > is exported as "__str__" and as the getter of the property 'buffer' > > > > if I construct a foo, I can call that function with no problem. > > if I create a bar and try to call the function on its foo I get an > error. > > > > My C++ and B::P code: > > > > class foo > > { > > public: > > > > foo() {std::strcpy(buffer, "good bye cruel world!\0\0");} > > char buffer[24]; > > }; > > > > struct foo_wrapper : foo , wrapper > > { > > foo_wrapper(const foo& f); > > foo_wrapper(); > > > > //property getters > > std::string get_buffer() const; > > }; > > > > foo_wrapper::foo_wrapper(const foo& exch): foo(exch), wrapper(){} > > > > foo_wrapper::foo_wrapper(): foo(), wrapper(){} > > > > std::string foo_wrapper::get_buffer() const > > { > > return std::string(foo::buffer); > > } > > > > > > class bar > > { > > public: > > foo f; > > }; > > > > class bar_wrapper: public bar, public wrapper > > { > > public: > > bar_wrapper(); > > bar_wrapper(const bar &); > > }; > > > > bar_wrapper::bar_wrapper() : bar(), wrapper(){} > > > > bar_wrapper::bar_wrapper(const bar &bb ) : bar(bb), wrapper(){} > > > > BOOST_PYTHON_MODULE(BusyBox) > > { > > > > class_("foo") > > .def(init<>()) > > .add_property("buffer", &foo_wrapper::get_buffer) > > .def("__str__", &foo_wrapper::get_buffer) > > ; > > > > class_("bar") > > .def_readwrite("f", &bar::f) > > ; > > } > > > > A REPL session that demos the errors:>>> from BusyBox import * > > >>> f1 = foo() > > >>> > > >>> f1.buffer > > 'good bye cruel world!' > > >>> str(f1) > > 'good bye cruel world!' > > >>> > > >>> b1 = bar() > > >>> > > >>> b1.f.buffer #Generates error > > Traceback (most recent call last): > > File "", line 1, in > > Boost.Python.ArgumentError: Python argument types in > > None.None(foo) > > did not match C++ signature: > > None(struct foo_wrapper {lvalue}) > > >>> str(b1.f) #Generates error > > Traceback (most recent call last): > > File "", line 1, in > > Boost.Python.ArgumentError: Python argument types in > > foo.__str__(foo) > > did not match C++ signature: > > __str__(struct foo_wrapper {lvalue}) > > >>> > > >>> f2 = b1.f > > >>> > > >>> b2.buffer #Generates error > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'b2' is not defined > > >>> str(f2) #Generates error > > Traceback (most recent call last): > > File "", line 1, in > > Boost.Python.ArgumentError: Python argument types in > > foo.__str__(foo) > > did not match C++ signature: > > __str__(struct foo_wrapper {lvalue}) > > >>> > > > > I feel like I must be doing something stupid. What is wrong? > > You don't have, while the error messages contains enough information > it is really difficult to new user to understand what is going wrong. > > > > >>> str(f2) #Generates error > > Traceback (most recent call last): > > File "", line 1, in > > Boost.Python.ArgumentError: Python argument types in > > foo.__str__(foo) > > did not match C++ signature: > > __str__(struct foo_wrapper {lvalue}) > > >>> > > The error message says that you cannot call foo.__str__ method with > "foo" as "this" pointer, but you should provide "foo_wrapper" for this > purpose. The library is right: > > >struct foo_wrapper : foo , wrapper > > { > > ... > > std::string get_buffer() const; > > }; > > In order to call get_buffer, the object type should be "foo_wrapper", > not "foo". You didn't exposed "foo_wrapper" class, but "foo". > If you define get_buffer as > > > struct foo_wrapper : foo , wrapper > { > ... > static std::string get_buffer(const foo& x ){ return > std::string(x.buffer); } > }; > > Everything will work as expected. > > The really confusing thing is that the library allowed you to call > __str__ method on object constructed from Python. This is because > internally it keeps foo_wrapper instance instead of "foo" one. > > HTH > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Nov 27 19:07:51 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 27 Nov 2007 20:07:51 +0200 Subject: [C++-sig] A wrapped class contains another wrapped class. Hilarity ensues. In-Reply-To: <3dc9bcf00711270959l4feba16ld6218cb73b17e4c8@mail.gmail.com> References: <3dc9bcf00711161231q2897816fs4c11bf5049f5d074@mail.gmail.com> <7465b6170711262350k2b4d84d1q93cf2171012be8bc@mail.gmail.com> <3dc9bcf00711270959l4feba16ld6218cb73b17e4c8@mail.gmail.com> Message-ID: <7465b6170711271007v1805833dw31b4d67eaa4500b5@mail.gmail.com> On Nov 27, 2007 7:59 PM, Matthew Scouten wrote: > AH! yes that worked. Thank you so much. It seems the real WTF here was that > it seemed to work fine when the foo was instantiated directly from python. > Because that seemed to work, I thought I was doing everything right until I > get further into wrapping my library. > > Please ignore my earlier begging email. I was way the heck down the wrong > path, looking for the wrong solutions, and getting very frustrated. I suggest you to try Py++ ( http://www.language-binding.net/ ). It could help you to avoid such things. It has simple, but still useful GUI: http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From matthew.scouten at gmail.com Tue Nov 27 20:59:31 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Tue, 27 Nov 2007 13:59:31 -0600 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] Message-ID: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> On Nov 27, 2007 12:07 PM, Roman Yakovenko wrote: > On Nov 27, 2007 7:59 PM, Matthew Scouten > wrote: > > AH! yes that worked. Thank you so much. It seems the real WTF here was > that > > it seemed to work fine when the foo was instantiated directly from > python. > > Because that seemed to work, I thought I was doing everything right > until I > > get further into wrapping my library. > > > > Please ignore my earlier begging email. I was way the heck down the > wrong > > path, looking for the wrong solutions, and getting very frustrated. > > I suggest you to try Py++ ( http://www.language-binding.net/ ). It > could help you to avoid such things. > > It has simple, but still useful GUI: > > http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html We did try that. GCC-XML chokes on our library code. It was originally written for C, and later ported to C++. Along the way it picked up some crazy preprocessor and template hacks and even some meta-template programming. Granted most of this stuff is not the part we need to wrap, but it is not easily separable. On top of all that, it was written with msvc8 in mind, not GCC. Even with with options set to emulate msvc8, GCC-XML generates hundreds of error messages the last of which is "internal compiler error". It works fine on other code, and our library compiles just fine on msvc8. We thought it would be faster to just soldier on in raw Boost.Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Nov 27 21:06:03 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 27 Nov 2007 22:06:03 +0200 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> Message-ID: <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> On Nov 27, 2007 9:59 PM, Matthew Scouten wrote: > We did try that. GCC-XML chokes on our library code. It was originally > written for C, and later ported to C++. Along the way it picked up some > crazy preprocessor and template hacks and even some meta-template > programming. Granted most of this stuff is not the part we need to wrap, but > it is not easily separable. On top of all that, it was written with msvc8 in > mind, not GCC. > > Even with with options set to emulate msvc8, GCC-XML generates hundreds of > error messages the last of which is "internal compiler error". It works fine > on other code, and our library compiles just fine on msvc8. :-(. Did you try new latest cvs version of gccxml? It is built on top of GCC 4.2. SVN version of Py++ and pygccxml should work fine with it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From matthew.scouten at gmail.com Tue Nov 27 23:27:58 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Tue, 27 Nov 2007 16:27:58 -0600 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> Message-ID: <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> On Nov 27, 2007 2:06 PM, Roman Yakovenko wrote: > On Nov 27, 2007 9:59 PM, Matthew Scouten > wrote: > > We did try that. GCC-XML chokes on our library code. It was originally > > written for C, and later ported to C++. Along the way it picked up > some > > crazy preprocessor and template hacks and even some meta-template > > programming. Granted most of this stuff is not the part we need to wrap, > but > > it is not easily separable. On top of all that, it was written with > msvc8 in > > mind, not GCC. > > > > Even with with options set to emulate msvc8, GCC-XML generates hundreds > of > > error messages the last of which is "internal compiler error". It works > fine > > on other code, and our library compiles just fine on msvc8. > > :-(. Did you try new latest cvs version of gccxml? It is built on top > of GCC 4.2. > SVN version of Py++ and pygccxml should work fine with it. Yes, when we started a couple of months ago we got it fresh from cvs. I had to get it at home and carry it in on a flashdrive because some fire wall between here and there prevented me from pulling down at work. Then I had to get Cmake and get the Dad-Blasted thing to compile. Then I had to find the right options to beat it with to get it to work on simple example code. Finally, I point it at our library and what does it do? It blows up in my face. If there has been a major update in the past 2 or 3 months, it might be worth checking out again. otherwise I am not throwing any more time down that rabbit hole. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.VanSickle at CanfieldSci.com Tue Nov 27 23:40:29 2007 From: Scott.VanSickle at CanfieldSci.com (Scott VanSickle) Date: Tue, 27 Nov 2007 17:40:29 -0500 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> Message-ID: <997199507FD49A4EA997EE1E7626474638E48E456B@Pan.domain-01> If you can get Py++ to work with the VS2005 headers please email the group. I spent well over a solid week to try to generate my wrapper classes with that method and gave up (it sounds like you had the same pleasant experience). I made dummy versions of any VC2005 headers that had errors, set every #define I could find to try to make GCC-XML happy and basically got nowhere. I was not trying to wrap any of my own template code (except STL and some boost stuff) and still failed with trying to wrap even a pretty minimal class. It is obvious to me that the VC2005 headers are just not intended by the authors to be used from anything but VC2005. I also had many issues with the boost libraries; I probably could have worked around those in my case. Scott V From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Matthew Scouten Sent: Tuesday, November 27, 2007 5:28 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] On Nov 27, 2007 2:06 PM, Roman Yakovenko wrote: On Nov 27, 2007 9:59 PM, Matthew Scouten wrote: > We did try that. GCC-XML chokes on our library code. It was originally > written for C, and later ported to C++. Along the way it picked up some > crazy preprocessor and template hacks and even some meta-template > programming. Granted most of this stuff is not the part we need to wrap, but > it is not easily separable. On top of all that, it was written with msvc8 in > mind, not GCC. > > Even with with options set to emulate msvc8, GCC-XML generates hundreds of > error messages the last of which is "internal compiler error". It works fine > on other code, and our library compiles just fine on msvc8. :-(. Did you try new latest cvs version of gccxml? It is built on top of GCC 4.2. SVN version of Py++ and pygccxml should work fine with it. Yes, when we started a couple of months ago we got it fresh from cvs. I had to get it at home and carry it in on a flashdrive because some fire wall between here and there prevented me from pulling down at work. Then I had to get Cmake and get the Dad-Blasted thing to compile. Then I had to find the right options to beat it with to get it to work on simple example code. Finally, I point it at our library and what does it do? It blows up in my face. If there has been a major update in the past 2 or 3 months, it might be worth checking out again. otherwise I am not throwing any more time down that rabbit hole. From Jason.Kankiewicz at dreamworks.com Wed Nov 28 18:39:16 2007 From: Jason.Kankiewicz at dreamworks.com (Jason Kankiewicz) Date: Wed, 28 Nov 2007 09:39:16 -0800 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <997199507FD49A4EA997EE1E7626474638E48E456B@Pan.domain-01> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> <997199507FD49A4EA997EE1E7626474638E48E456B@Pan.domain-01> Message-ID: <474DA7C4.6040807@dreamworks.com> Scott, I, too, had difficulty getting GCC_XML to grok MSVC8 code early this year. Fortunately, the CVS version soon contained new headers and my problems disappeared. The problems existed because I had installed Service Pack 1 for VS2005 and GCC_XML's VC8 headers hadn't yet been modified to match. Have you installed Service Pack 1 for VS2005? If not, I suggest that you do. Regards, Jason Scott VanSickle wrote: > If you can get Py++ to work with the VS2005 headers please email the group. I spent well over a solid week to try to generate my wrapper classes with that method and gave up (it sounds like you had the same pleasant experience). I made dummy versions of any VC2005 headers that had errors, set every #define I could find to try to make GCC-XML happy and basically got nowhere. I was not trying to wrap any of my own template code (except STL and some boost stuff) and still failed with trying to wrap even a pretty minimal class. It is obvious to me that the VC2005 headers are just not intended by the authors to be used from anything but VC2005. I also had many issues with the boost libraries; I probably could have worked around those in my case. > > Scott V > > > > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Matthew Scouten > Sent: Tuesday, November 27, 2007 5:28 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] > > > On Nov 27, 2007 2:06 PM, Roman Yakovenko wrote: > On Nov 27, 2007 9:59 PM, Matthew Scouten wrote: > >> We did try that. GCC-XML chokes on our library code. It was originally >> written for C, and later ported to C++. Along the way it picked up some >> crazy preprocessor and template hacks and even some meta-template >> programming. Granted most of this stuff is not the part we need to wrap, but >> it is not easily separable. On top of all that, it was written with msvc8 in >> mind, not GCC. >> >> Even with with options set to emulate msvc8, GCC-XML generates hundreds of >> error messages the last of which is "internal compiler error". It works fine >> on other code, and our library compiles just fine on msvc8. >> > :-(. Did you try new latest cvs version of gccxml? It is built on top > of GCC 4.2. > SVN version of Py++ and pygccxml should work fine with it. > > Yes, when we started a couple of months ago we got it fresh from cvs. I had to get it at home and carry it in on a flashdrive because some fire wall between here and there prevented me from pulling down at work. Then I had to get Cmake and get the Dad-Blasted thing to compile. Then I had to find the right options to beat it with to get it to work on simple example code. Finally, I point it at our library and what does it do? It blows up in my face. > > If there has been a major update in the past 2 or 3 months, it might be worth checking out again. otherwise I am not throwing any more time down that rabbit hole. > From ssarangi123 at gmail.com Fri Nov 30 00:26:56 2007 From: ssarangi123 at gmail.com (Satyajit Sarangi) Date: Thu, 29 Nov 2007 17:26:56 -0600 Subject: [C++-sig] Embedding and calling extended python commands Message-ID: Hi All, I am new to the boost python api and had a few basic questions where I got stuck. I am writing an application in C++ which has modules written so that they can be invoked in a command type format. For example commands like, draw_line(), draw_circle() etc are implemented. I compiled these with boost python to the corresponding .lib and .pyd After that I write a simple script which imports the module and then calls these commands. for example.. import mymodule draw_line() draw_circle() ----------------------------------------------------------------------------------------------------------- Now can the embedded python interpreter to call this file as a regular script or do I need any changes. I tried doing it this way and it gives me a lot of errors though I can import the module with regular python interpreter. Am sorry for such a stupid question but I am stuck at it. I will really appreciate any help. thanks Satyajit -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Nov 30 13:43:08 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 30 Nov 2007 07:43:08 -0500 Subject: [C++-sig] Embedding and calling extended python commands In-Reply-To: References: Message-ID: <4750055C.7050808@sympatico.ca> Satyajit Sarangi wrote: > Now can the embedded python interpreter to call this file as a regular > script or do I need any changes. > > I tried doing it this way and it gives me a lot of errors though I can > import the module with regular python interpreter. What errors do you get ? Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Scott.VanSickle at CanfieldSci.com Fri Nov 30 15:49:00 2007 From: Scott.VanSickle at CanfieldSci.com (Scott VanSickle) Date: Fri, 30 Nov 2007 09:49:00 -0500 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <474DA7C4.6040807@dreamworks.com> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> <997199507FD49A4EA997EE1E7626474638E48E456B@Pan.domain-01> <474DA7C4.6040807@dreamworks.com> Message-ID: <997199507FD49A4EA997EE1E7626474638E4BDA862@Pan.domain-01> Jason, Yes, I installed SP1 a while back. It definitely helped with a few annoying VC2005 problems. There is a different SP that you have to install for Vista, in case you're developing with VS2005 on any Vista machines. We have do test on Vista, so we have all set up secondary dev machines that run Vista so we can debug on that OS. It's telling that the SP for VS2005 that would allow it to run on Vista came out a while after Vista; that probably means to me that Microsoft never did any debugging of any of their Vista "non-OS" code on Vista! Where exactly did you get the new headers? Are you saying that you have headers with which you can generate Python wrapper classes now? I got nowhere with the headers that I currently have from GCC_XML or VS2005. I would be very interested in being able to use Py++ to generate my headers; I am currently doing it all by hand. Scott V -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Jason Kankiewicz Sent: Wednesday, November 28, 2007 12:39 PM To: c++-sig at python.org Subject: Re: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] Scott, I, too, had difficulty getting GCC_XML to grok MSVC8 code early this year. Fortunately, the CVS version soon contained new headers and my problems disappeared. The problems existed because I had installed Service Pack 1 for VS2005 and GCC_XML's VC8 headers hadn't yet been modified to match. Have you installed Service Pack 1 for VS2005? If not, I suggest that you do. Regards, Jason Scott VanSickle wrote: > If you can get Py++ to work with the VS2005 headers please email the group. I spent well over a solid week to try to generate my wrapper classes with that method and gave up (it sounds like you had the same pleasant experience). I made dummy versions of any VC2005 headers that had errors, set every #define I could find to try to make GCC-XML happy and basically got nowhere. I was not trying to wrap any of my own template code (except STL and some boost stuff) and still failed with trying to wrap even a pretty minimal class. It is obvious to me that the VC2005 headers are just not intended by the authors to be used from anything but VC2005. I also had many issues with the boost libraries; I probably could have worked around those in my case. > > Scott V > > > > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Matthew Scouten > Sent: Tuesday, November 27, 2007 5:28 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] > > > On Nov 27, 2007 2:06 PM, Roman Yakovenko wrote: > On Nov 27, 2007 9:59 PM, Matthew Scouten wrote: > >> We did try that. GCC-XML chokes on our library code. It was originally >> written for C, and later ported to C++. Along the way it picked up some >> crazy preprocessor and template hacks and even some meta-template >> programming. Granted most of this stuff is not the part we need to wrap, but >> it is not easily separable. On top of all that, it was written with msvc8 in >> mind, not GCC. >> >> Even with with options set to emulate msvc8, GCC-XML generates hundreds of >> error messages the last of which is "internal compiler error". It works fine >> on other code, and our library compiles just fine on msvc8. >> > :-(. Did you try new latest cvs version of gccxml? It is built on top > of GCC 4.2. > SVN version of Py++ and pygccxml should work fine with it. > > Yes, when we started a couple of months ago we got it fresh from cvs. I had to get it at home and carry it in on a flashdrive because some fire wall between here and there prevented me from pulling down at work. Then I had to get Cmake and get the Dad-Blasted thing to compile. Then I had to find the right options to beat it with to get it to work on simple example code. Finally, I point it at our library and what does it do? It blows up in my face. > > If there has been a major update in the past 2 or 3 months, it might be worth checking out again. otherwise I am not throwing any more time down that rabbit hole. > _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From ssarangi123 at gmail.com Fri Nov 30 16:32:05 2007 From: ssarangi123 at gmail.com (Satyajit Sarangi) Date: Fri, 30 Nov 2007 09:32:05 -0600 Subject: [C++-sig] Embedding and calling extended python commands Message-ID: Hi Stefan, The errors which I get are as follows: Python File 1: import smallPython a = smallPython a.greet() a.square(100) Error: C:\Python25>testpy test.py running file test.py... y:\private\my documents\ssarangi\my documents\visual studio 2005\projects\smallpython\smallpython\main.cpp(166): Python Error detected in function 'int __cdecl main(int,char **)' Traceback (most recent call last): File "test.py", line 1, in import smallPython ImportError: __import__ not found 1 error detected. However, I can import the smallPython module directly into the python interpreter... Seems like I am missing something and also it shows me an error for the cpp file when I have the smallPython.pyd and smallPython.lib in the python root directory. The cpp file is the same as the example getting_started_1.cpp Cpp File: #include #include #include namespace { // Avoid cluttering the global namespace. // A couple of simple C++ functions that we want to expose to Python. std::string greet() { return "hello, world"; } int square(int number) { return number * number; } } namespace python = boost::python; // Python requires an exported function called init in every // extension module. This is where we build the module contents. BOOST_PYTHON_MODULE(smallPython) { // Add regular functions to the module. python::def("greet", greet); python::def("square", square); } Thanks a lot for the help Satyajit -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Nov 30 16:44:31 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 30 Nov 2007 10:44:31 -0500 Subject: [C++-sig] Embedding and calling extended python commands In-Reply-To: References: Message-ID: <47502FDF.30808@sympatico.ca> Satyajit Sarangi wrote: > C:\Python25>testpy test.py > running file test.py... > y:\private\my documents\ssarangi\my documents\visual studio > 2005\projects\smallpython\smallpython\main.cpp(166): Python Error > detected in function 'int __cdecl main(int,char **)' > Traceback (most recent call last): > File "test.py", line 1, in > import smallPython > ImportError: __import__ not found > 1 error detected. This means you didn't initialize the embedded python interpreter correctly. (You didn't include the code for that.) The boost.python tutorial should tell you all you need. It has a special section on Embedding. Also, you may want to look at the boost.python tests exec.cpp and import_.cpp for inspiration. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From matthew.scouten at gmail.com Fri Nov 30 22:25:41 2007 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Fri, 30 Nov 2007 15:25:41 -0600 Subject: [C++-sig] Wrapping an enum like class that is not an enum Message-ID: <3dc9bcf00711301325g334a9c44n7c1bfbd7a0dd14a7@mail.gmail.com> I (a BP newbie) could use some advice on how th wrap something odd. The library I am using has something called an AEnum. It is a type of enum like class. It is guaranteed to behave exactly like an enum, except that it has some extra properties. There is an int, a string and a symbol associated with each value. In spite of that, the sizeof(AEnum_blah) == sizeof(int) , Guaranteed an AEnum is castable to and from an int and the bits of the AEnum are identical to the bits of the int it casts to. I can't wrap it as a class because it is generated by crazy macros and meta-template programming (And besides, I don't understand it...) So, I thought, If this thing is Guaranteed to be just like an enum in everyway that matters, why not pretend that it IS an enum and wrap it like one? So I used the "enum_<>()" Well that works just great when passing to or returning from functions. Except, if it is the member of a class... >>> from MantiCore import * >>> o = Order() >>> o.order_status Traceback (most recent call last): File "", line 1, in TypeError: cannot create weak reference to 'MantiCore.AEnum_OrderStatusCodes' object I can get around this by exporting it as a property of the class rather than a data member, but there are a lot of them. So, Anyone have a better way to do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: