From RaoulGough at yahoo.co.uk Mon Mar 3 22:44:03 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Mon, 03 Mar 2008 21:44:03 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> <47B71ADC.1030401@yahoo.co.uk> <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> Message-ID: <47CC7123.70902@yahoo.co.uk> Roman Yakovenko wrote: > P.S 2. Can you upload somewhere the images from the documentation. The > images in the label could not be opened > for some reason. > > FYI, I've been granted sandbox access to the SVN repository, and I think I've managed to resurrect the old indexing_v2 branch under http://svn.boost.org/svn/boost/sandbox/python_indexing_v2. If you check this out with svn, you should be able to see the old indexing_v2 documentation, complete with the original images in your working copy in python_indexing_v2/libs/python/doc/v2/containers.html. For example: $ svn co http://svn.boost.org/svn/boost/sandbox/python_indexing_v2 .... A python_indexing_v2/libs/python/doc/v2/proxy_detached.png .... A python_indexing_v2/libs/python/doc/v2/proxy.png .... A python_indexing_v2/libs/python/doc/v2/overview.png .... A python_indexing_v2/libs/python/doc/v2/containers.html .... -- Cheers, Raoul. From zzhao at laika.com Fri Mar 7 08:30:23 2008 From: zzhao at laika.com (ZiZi Zhao) Date: Thu, 6 Mar 2008 23:30:23 -0800 (PST) Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: <200802281326.24585.walter@mathematik.hu-berlin.de> Message-ID: <2467298.1412041204875023861.JavaMail.root@zimbra01.laika.com> Hello, I have compiled boost python with python 2.5.1 and had a script written in the same packages, i.e., python 2.5.1 and extended c++ class/functions of boost.python. As long as I import some python module that contains 'import uuid', I got "Fatal Python error: version mis-match". Is there anyway to fix this? Thanks, ZIZI LAIKA _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. From zzhao at laika.com Fri Mar 7 14:57:03 2008 From: zzhao at laika.com (ZiZi Zhao) Date: Fri, 7 Mar 2008 05:57:03 -0800 (PST) Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: <2467298.1412041204875023861.JavaMail.root@zimbra01.laika.com> Message-ID: <6433583.1412891204898223558.JavaMail.root@zimbra01.laika.com> I forgot to tell: my boost-python version is 1.34.1 built on Python 2.5.1, using gcc 4.0.2. thanks!! ----- Original Message ----- From: "ZiZi Zhao" To: "Development of Python/C++ integration" Cc: c++-sig at python.org Sent: 2008?3?6? ??? ??11?30?23? (GMT-0800) America/Los_Angeles Subject: [C++-sig] boost python - python uuid mismatch Hello, I have compiled boost python with python 2.5.1 and had a script written in the same packages, i.e., python 2.5.1 and extended c++ class/functions of boost.python. As long as I import some python module that contains 'import uuid', I got "Fatal Python error: version mis-match". Is there anyway to fix this? Thanks, ZIZI LAIKA _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. From michael.wieher at gmail.com Fri Mar 7 15:19:41 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Fri, 7 Mar 2008 08:19:41 -0600 Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: <2467298.1412041204875023861.JavaMail.root@zimbra01.laika.com> References: <200802281326.24585.walter@mathematik.hu-berlin.de> <2467298.1412041204875023861.JavaMail.root@zimbra01.laika.com> Message-ID: (this might be incorrect, please correct me if I'm wrong, but my understanding is...) Basically the compiled library, boost.python, in this instance, must be compiled by the same/similar-enough compiler. That is, you need to use the same compiler to compile the python installation you're using and the library you're importing. My experience has been that this is not an absolute requirement, (two similar-enough compilers work) but if they're different enough, there will be a problem. The version of boost itself is, I believe, irrelevant. 2008/3/7, ZiZi Zhao : > > > Hello, > I have compiled boost python with python 2.5.1 and had a script written in > the same packages, i.e., python 2.5.1 and extended c++ class/functions of > boost.python. > > As long as I import some python module that contains 'import uuid', I got > "Fatal Python error: version mis-match". > > Is there anyway to fix this? > > Thanks, > > ZIZI > LAIKA > > > > > _____________________________________________________________________ > The information contained in this message and its attachments is > confidential and proprietary to LAIKA, Inc. By opening this email > or any of its attachments, you agree to keep all such information > confidential and not to use, distribute, disclose or copy any part > of such information without the prior written consent of LAIKA, > Inc. If you are not the intended recipient of this message, any use, > distribution, disclosure or copying of such information is prohibited. > If received in error, please contact the sender. > > _______________________________________________ > 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 zzhao at laika.com Fri Mar 7 16:21:36 2008 From: zzhao at laika.com (ZiZi Zhao) Date: Fri, 7 Mar 2008 07:21:36 -0800 (PST) Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: Message-ID: <11832710.1413291204903296786.JavaMail.root@zimbra01.laika.com> the Python 2.5.1 was compiled using gcc 3.4.6; and boost.python 1.34.1 gcc 4.0.2, which may be 'different enough'. should I try to recompile python 2.5.1 and boost.python 1.34.1 both with gcc 4.0.2? f.y.i. gcc 4.0.2 is the required compiler for my application. THANKS, ZIZI LAIKA ----- Original Message ----- From: "Michael Wieher" To: "Development of Python/C++ integration" Sent: 2008?3?7? ??? ??06?19?41? (GMT-0800) America/Los_Angeles Subject: Re: [C++-sig] boost python - python uuid mismatch (this might be incorrect, please correct me if I'm wrong, but my understanding is...) Basically the compiled library, boost.python, in this instance, must be compiled by the same/similar-enough compiler. That is, you need to use the same compiler to compile the python installation you're using and the library you're importing. My experience has been that this is not an absolute requirement, (two similar-enough compilers work) but if they're different enough, there will be a problem. The version of boost itself is, I believe, irrelevant. 2008/3/7, ZiZi Zhao < zzhao at laika.com >: Hello, I have compiled boost python with python 2.5.1 and had a script written in the same packages, i.e., python 2.5.1 and extended c++ class/functions of boost.python. As long as I import some python module that contains 'import uuid', I got "Fatal Python error: version mis-match". Is there anyway to fix this? Thanks, ZIZI LAIKA _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Mar 7 16:26:40 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 07 Mar 2008 10:26:40 -0500 Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: <11832710.1413291204903296786.JavaMail.root@zimbra01.laika.com> References: <11832710.1413291204903296786.JavaMail.root@zimbra01.laika.com> Message-ID: <47D15EB0.40705@sympatico.ca> ZiZi Zhao wrote: > the Python 2.5.1 was compiled using gcc 3.4.6; and boost.python 1.34.1 > gcc 4.0.2, which may be 'different enough'. > > should I try to recompile python 2.5.1 and boost.python 1.34.1 both with > gcc 4.0.2? > > f.y.i. gcc 4.0.2 is the required compiler for my application. There is no need to recompile Python itself, which only exposes a C interface. It's the C++ ABI that may change between compiler versions, so make sure all your C++ components are compiled with the same compiler. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From michael.wieher at gmail.com Fri Mar 7 16:28:40 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Fri, 7 Mar 2008 09:28:40 -0600 Subject: [C++-sig] boost python - python uuid mismatch In-Reply-To: <11832710.1413291204903296786.JavaMail.root@zimbra01.laika.com> References: <11832710.1413291204903296786.JavaMail.root@zimbra01.laika.com> Message-ID: It is something I would try. If 4.0.2 is required for your app, why not make the compiled bytecode uniform, at least in that respect. I'm not saying it'll work =) But I'd give it a shot. 2008/3/7, ZiZi Zhao : > > the Python 2.5.1 was compiled using gcc 3.4.6; and boost.python 1.34.1 gcc > 4.0.2, which may be 'different enough'. > > should I try to recompile python 2.5.1 and boost.python 1.34.1 both with > gcc 4.0.2? > > f.y.i. gcc 4.0.2 is the required compiler for my application. > > THANKS, > ZIZI > LAIKA > > > ----- Original Message ----- > From: "Michael Wieher" > To: "Development of Python/C++ integration" > Sent: 2008?3?7? ??? ??06?19?41? (GMT-0800) America/Los_Angeles > Subject: Re: [C++-sig] boost python - python uuid mismatch > > (this might be incorrect, please correct me if I'm wrong, but my > understanding is...) > Basically the compiled library, boost.python, in this instance, must be > compiled by the same/similar-enough compiler. That is, you need to use the > same compiler to compile the python installation you're using and the > library you're importing. My experience has been that this is not an > absolute requirement, (two similar-enough compilers work) but if they're > different enough, there will be a problem. The version of boost itself is, > I believe, irrelevant. > > 2008/3/7, ZiZi Zhao : > > > > > > Hello, > > I have compiled boost python with python 2.5.1 and had a script written > > in the same packages, i.e., python 2.5.1 and extended c++ > > class/functions of boost.python. > > > > As long as I import some python module that contains 'import uuid', I > > got > > "Fatal Python error: version mis-match". > > > > Is there anyway to fix this? > > > > Thanks, > > > > ZIZI > > LAIKA > > > > > > > > > > _____________________________________________________________________ > > The information contained in this message and its attachments is > > confidential and proprietary to LAIKA, Inc. By opening this email > > or any of its attachments, you agree to keep all such information > > confidential and not to use, distribute, disclose or copy any part > > of such information without the prior written consent of LAIKA, > > Inc. If you are not the intended recipient of this message, any use, > > distribution, disclosure or copying of such information is prohibited. > > If received in error, please contact the sender. > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > _____________________________________________________________________ > The information contained in this message and its attachments is > confidential and proprietary to LAIKA, Inc. By opening this email > or any of its attachments, you agree to keep all such information > confidential and not to use, distribute, disclose or copy any part > of such information without the prior written consent of LAIKA, > Inc. If you are not the intended recipient of this message, any use, > distribution, disclosure or copying of such information is prohibited. > If received in error, please contact the sender. > > > _______________________________________________ > 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 michael.wieher at gmail.com Fri Mar 7 16:43:51 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Fri, 7 Mar 2008 09:43:51 -0600 Subject: [C++-sig] Strange Behavior w/File Pointers Message-ID: mYmodule.cpp --------------------------- istream globalFile; struct dataStruct { int a; int b; short c; } __attribute__(align(2)); PyObject * mYmodule_setFile() { --parseTuple-- globalFile.open(pathToFile,ios::in|ios::binary); } PyObject * mYmodule_getNBytesAtATime() { --parseTuple-- int N; //the size of a dataStruct globalFile.read((char*)&dataStruct,N); Py_BuildValue('ii',dataStruct->a, dataStruct->b); } ============== Given the above rough pseudocode, I find that each time my Python module calls myModule.getNBytesAtATime() the file-pointer shifts strangely. Most of the time it shifts N bytes. But, sometimes, on the same points but with no definable reason that I can see, it shifts N*x bytes, where x is some integer. I've fixed the problem by manually resetting the file-pointer on re-entry to getNBytesAtATime, so the code works, but if anyone can shed some light on this little quirk, I'd be interested. -Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From RaoulGough at yahoo.co.uk Fri Mar 7 19:11:07 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 07 Mar 2008 18:11:07 +0000 Subject: [C++-sig] Strange Behavior w/File Pointers In-Reply-To: References: Message-ID: <47D1853B.8060209@yahoo.co.uk> Michael Wieher wrote: > mYmodule.cpp > --------------------------- > > istream globalFile; > struct dataStruct { > int a; > int b; > short c; > } __attribute__(align(2)); > > PyObject * > mYmodule_setFile() { > --parseTuple-- > globalFile.open(pathToFile,ios::in|ios::binary); > } > > PyObject * > mYmodule_getNBytesAtATime() { > --parseTuple-- > int N; //the size of a dataStruct > globalFile.read((char*)&dataStruct,N); > Py_BuildValue('ii',dataStruct->a, dataStruct->b); > } > > ============== > Given the above rough pseudocode, I find that each time my Python > module calls myModule.getNBytesAtATime() the file-pointer shifts > strangely. Most of the time it shifts N bytes. But, sometimes, on > the same points but with no definable reason that I can see, it shifts > N*x bytes, where x is some integer. Are you sure this happens in a single call to the C++ function? If I suspected something like what you describe I would probably "instrument" the C++ function by having it log something to stdout or stderr, e.g. std::cout << "Getting " << N << " bytes starting at " << globalFile.tellg() << std::endl; .... std::cout << "Got " << N << " bytes, now at " << globalFile.tellg() << std::endl; (not compiled or tested!). This should show you if the function itself is moving the pointer unexpectedly, or if it's happening somewhere else... -- Cheers, Raoul. From michael.wieher at gmail.com Fri Mar 7 19:32:42 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Fri, 7 Mar 2008 12:32:42 -0600 Subject: [C++-sig] Strange Behavior w/File Pointers In-Reply-To: <47D1853B.8060209@yahoo.co.uk> References: <47D1853B.8060209@yahoo.co.uk> Message-ID: Yes I'm sure. I've written functions to write out from inside the C++ file to a text file to check this, as well as getPtr functions that will export the pointer's location to the python, and the results are the same. It doesn't happen EVERY call, but seemingly randomly. (1 in 15, 3 in 10, etc.) Could there be strange binary characters that are read in that could cause it to shift like that? 2008/3/7, Raoul Gough : > > Michael Wieher wrote: > > mYmodule.cpp > > --------------------------- > > > > istream globalFile; > > struct dataStruct { > > int a; > > int b; > > short c; > > } __attribute__(align(2)); > > > > PyObject * > > mYmodule_setFile() { > > --parseTuple-- > > globalFile.open(pathToFile,ios::in|ios::binary); > > } > > > > PyObject * > > mYmodule_getNBytesAtATime() { > > --parseTuple-- > > int N; //the size of a dataStruct > > globalFile.read((char*)&dataStruct,N); > > Py_BuildValue('ii',dataStruct->a, dataStruct->b); > > } > > > > ============== > > Given the above rough pseudocode, I find that each time my Python > > module calls myModule.getNBytesAtATime() the file-pointer shifts > > strangely. Most of the time it shifts N bytes. But, sometimes, on > > the same points but with no definable reason that I can see, it shifts > > N*x bytes, where x is some integer. > > > Are you sure this happens in a single call to the C++ function? If I > suspected something like what you describe I would probably "instrument" > the C++ function by having it log something to stdout or stderr, e.g. > > std::cout << "Getting " << N << " bytes starting at " << > globalFile.tellg() << std::endl; > .... > std::cout << "Got " << N << " bytes, now at " << globalFile.tellg() << > std::endl; > > (not compiled or tested!). This should show you if the function itself > is moving the pointer unexpectedly, or if it's happening somewhere else... > > > -- > Cheers, > Raoul. > > _______________________________________________ > 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 RaoulGough at yahoo.co.uk Fri Mar 7 22:17:39 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 07 Mar 2008 21:17:39 +0000 Subject: [C++-sig] Strange Behavior w/File Pointers In-Reply-To: References: <47D1853B.8060209@yahoo.co.uk> Message-ID: <47D1B0F3.20505@yahoo.co.uk> Michael Wieher wrote: > Yes I'm sure. > > I've written functions to write out from inside the C++ file to a text > file to check this, as well as getPtr functions that will export the > pointer's location to the python, and the results are the same. > > It doesn't happen EVERY call, but seemingly randomly. (1 in 15, 3 in > 10, etc.) > > Could there be strange binary characters that are read in that could > cause it to shift like that? Don't know - it sounds weird to me. I see you're opening the file with the ios::binary flag, so there shouldn't be anything reformatting like that happening. Anyway, didn't you say it always reads an integer multiple of the number of bytes you asked for? That wouldn't be explained by multibyte character conversions. It sounds more like the function being called unexpectedly, or something else manipulating the file - I guess you could rule that out by making the file a private member variable or something along those lines. All I can suggest is the usual stuff which you probably already know - check all return codes, error status values, and reduce the test case further and further until the problem goes away or it proves there's a problem in the library - e.g. split the actual file reading into a separate function with its own logging, and test that from plain C++ code to rule out any weird Python/C++ interactions. Then maybe switch to std::streambuf interface or even stdio's FILE*, but it's hard to imagine there'd be a bug like that in the standard library that you're using. -- Cheers, Raoul. From michael.wieher at gmail.com Fri Mar 7 22:24:07 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Fri, 7 Mar 2008 15:24:07 -0600 Subject: [C++-sig] Strange Behavior w/File Pointers In-Reply-To: <47D1B0F3.20505@yahoo.co.uk> References: <47D1853B.8060209@yahoo.co.uk> <47D1B0F3.20505@yahoo.co.uk> Message-ID: Well, lucky for me each read is uniform length and they're sequential, so I was able to handle the problem by seekg() to the index*len each time I call f() I'm pretty sure the weirdest part was that, if I read in data to a structure and then didn't do anything else, it behaved fine. but if I read in data to a structure and then accessed members of that structure, it got screwy. Maybe it has to do with gnu's __attribute__ flag or some strange combination of weirdness. but thanks for the tips =) 2008/3/7, Raoul Gough : > > Michael Wieher wrote: > > Yes I'm sure. > > > > I've written functions to write out from inside the C++ file to a text > > file to check this, as well as getPtr functions that will export the > > pointer's location to the python, and the results are the same. > > > > It doesn't happen EVERY call, but seemingly randomly. (1 in 15, 3 in > > 10, etc.) > > > > Could there be strange binary characters that are read in that could > > cause it to shift like that? > > > Don't know - it sounds weird to me. I see you're opening the file with > the ios::binary flag, so there shouldn't be anything reformatting like > that happening. Anyway, didn't you say it always reads an integer > multiple of the number of bytes you asked for? That wouldn't be > explained by multibyte character conversions. It sounds more like the > function being called unexpectedly, or something else manipulating the > file - I guess you could rule that out by making the file a private > member variable or something along those lines. > > All I can suggest is the usual stuff which you probably already know - > check all return codes, error status values, and reduce the test case > further and further until the problem goes away or it proves there's a > problem in the library - e.g. split the actual file reading into a > separate function with its own logging, and test that from plain C++ > code to rule out any weird Python/C++ interactions. Then maybe switch to > std::streambuf interface or even stdio's FILE*, but it's hard to imagine > there'd be a bug like that in the standard library that you're using. > > > -- > > Cheers, > Raoul. > > _______________________________________________ > 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 pablo_best at o2.pl Tue Mar 11 00:26:47 2008 From: pablo_best at o2.pl (pawell) Date: Mon, 10 Mar 2008 16:26:47 -0700 (PDT) Subject: [C++-sig] Global variables (standard C/C++ types) Message-ID: <15968033.post@talk.nabble.com> I would like to use Python in my game engine as a script language but first I want to test Python as console (something like interactive mode). I tested boost.python and encountered problem. I want to expose global variables so I can use them in some module (__main__ for example). I found I can use something like "scope().attr("var_name") = object(ptr(var_ptr))" but it works only with classes (like std::string or my own). Is there simple way to expose such variables? I've searched a lot but found nothing :/ -- View this message in context: http://www.nabble.com/Global-variables-%28standard-C-C%2B%2B-types%29-tp15968033p15968033.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From seefeld at sympatico.ca Tue Mar 11 00:34:32 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 10 Mar 2008 19:34:32 -0400 Subject: [C++-sig] Global variables (standard C/C++ types) In-Reply-To: <15968033.post@talk.nabble.com> References: <15968033.post@talk.nabble.com> Message-ID: <47D5C588.1050702@sympatico.ca> pawell wrote: > I would like to use Python in my game engine as a script language but first I > want to test Python as console (something like interactive mode). I tested > boost.python and encountered problem. I want to expose global variables so I > can use them in some module (__main__ for example). I found I can use > something like "scope().attr("var_name") = object(ptr(var_ptr))" but it > works only with classes (like std::string or my own). Is there simple way to > expose such variables? I've searched a lot but found nothing :/ I'm not sure what exactly you are referring to as "it works...". What variables (or better, what types) do you want to expose that don't "work" ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From pablo_best at o2.pl Tue Mar 11 01:34:09 2008 From: pablo_best at o2.pl (pawell) Date: Mon, 10 Mar 2008 17:34:09 -0700 (PDT) Subject: [C++-sig] Global variables (standard C/C++ types) In-Reply-To: <47D5C588.1050702@sympatico.ca> References: <15968033.post@talk.nabble.com> <47D5C588.1050702@sympatico.ca> Message-ID: <15971785.post@talk.nabble.com> Standard c/c++ types like int, double, bool, etc. When I try something like: "scope().attr("a") = object(ptr(&some_bool_var));" I get from gcc: "/usr/include/boost/python/object/make_instance.hpp:24: error: invalid application of ?sizeof? to incomplete type" I would like to use "a" variable like a standard Python's boolean type ( "a = True" ). Stefan Seefeld wrote: > > pawell wrote: >> I would like to use Python in my game engine as a script language but >> first I >> want to test Python as console (something like interactive mode). I >> tested >> boost.python and encountered problem. I want to expose global variables >> so I >> can use them in some module (__main__ for example). I found I can use >> something like "scope().attr("var_name") = object(ptr(var_ptr))" but it >> works only with classes (like std::string or my own). Is there simple way >> to >> expose such variables? I've searched a lot but found nothing :/ > > I'm not sure what exactly you are referring to as "it works...". What > variables (or better, what types) do you want to expose that don't "work" > ? > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/Global-variables-%28standard-C-C%2B%2B-types%29-tp15968033p15971785.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From seefeld at sympatico.ca Tue Mar 11 01:41:40 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 10 Mar 2008 20:41:40 -0400 Subject: [C++-sig] Global variables (standard C/C++ types) In-Reply-To: <15971785.post@talk.nabble.com> References: <15968033.post@talk.nabble.com> <47D5C588.1050702@sympatico.ca> <15971785.post@talk.nabble.com> Message-ID: <47D5D544.2060700@sympatico.ca> pawell wrote: > Standard c/c++ types like int, double, bool, etc. When I try something like: > "scope().attr("a") = object(ptr(&some_bool_var));" I get from gcc: > "/usr/include/boost/python/object/make_instance.hpp:24: error: invalid > application of ?sizeof? to incomplete type" > I would like to use "a" variable like a standard Python's boolean type ( "a > = True" ). int, float, bool and similar types are immutable in python. You can set scope().attr("a") = some_bool_var; (copying the value of some_bool_var into a global python variable 'a'). But there is no way to store a reference to a boolean variable living in C++. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From pablo_best at o2.pl Tue Mar 11 01:53:27 2008 From: pablo_best at o2.pl (pawell) Date: Mon, 10 Mar 2008 17:53:27 -0700 (PDT) Subject: [C++-sig] Global variables (standard C/C++ types) In-Reply-To: <47D5D544.2060700@sympatico.ca> References: <15968033.post@talk.nabble.com> <47D5C588.1050702@sympatico.ca> <15971785.post@talk.nabble.com> <47D5D544.2060700@sympatico.ca> Message-ID: <15972138.post@talk.nabble.com> Stefan Seefeld wrote: > > pawell wrote: >> Standard c/c++ types like int, double, bool, etc. When I try something >> like: >> "scope().attr("a") = object(ptr(&some_bool_var));" I get from gcc: >> "/usr/include/boost/python/object/make_instance.hpp:24: error: invalid >> application of ?sizeof? to incomplete type" >> I would like to use "a" variable like a standard Python's boolean type ( >> "a >> = True" ). > > int, float, bool and similar types are immutable in python. You can set > > scope().attr("a") = some_bool_var; > > (copying the value of some_bool_var into a global python variable 'a'). > But there is no way to store a reference to a boolean variable living in > C++. > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > I will probably write some class - with set/get methodes - that holds reference to those variables or try to get values from Python. thanks for help :) -- View this message in context: http://www.nabble.com/Global-variables-%28standard-C-C%2B%2B-types%29-tp15968033p15972138.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From zzhao at laika.com Tue Mar 11 19:16:13 2008 From: zzhao at laika.com (ZiZi Zhao) Date: Tue, 11 Mar 2008 11:16:13 -0700 (PDT) Subject: [C++-sig] boost 1.34.1 & python 2.5.2 on centos 5 In-Reply-To: <15968033.post@talk.nabble.com> Message-ID: <31665157.1705291205259373210.JavaMail.root@zimbra01.laika.com> Hi All, I just built python 2.5.2 on my centos 5 system, and now building boost 1.34.1 on python 2.5.2, both are compiled with gcc 4.0.2. But, I got tons of messages such as: ./boost/python/converter/arg_from_python.hpp:239: error: ?PyObject? was not declared in this scope ./boost/python/converter/arg_from_python.hpp:239: error: ?p? was not declared in this scope ./boost/python/converter/arg_from_python.hpp:240: error: expected `;' before ?{? token ./boost/python/converter/arg_from_python.hpp: In member function ?T boost::python::converter::pointer_cref_arg_from_python::operator()() const?: ./boost/python/converter/arg_from_python.hpp:258: error: ?Py_None? was not declared in this scope ./boost/python/converter/arg_from_python.hpp: At global scope: ./boost/python/converter/arg_from_python.hpp:267: error: ISO C++ forbids declaration of ?pointer_arg_from_python? with no type ./boost/python/converter/arg_from_python.hpp:267: error: ?boost::python::converter::pointer_arg_from_python::pointer_arg_from_python? declared as an ?inline? variable ./boost/python/converter/arg_from_python.hpp:267: error: ?int boost::python::converter::pointer_arg_from_python::pointer_arg_from_python? is not a static member of ?struct boost::python::converter::pointer_arg_from_python? ... ./boost/python/call.hpp:53: error: template declaration of ?typename boost::python::detail::returnable::type boost::python::call? ./boost/python/call.hpp:53: error: ?PyObject? was not declared in this scope ./boost/python/call.hpp:53: error: ?callable? was not declared in this scope ./boost/python/call.hpp:54: error: expected primary-expression before ?const? ./boost/python/call.hpp:54: error: expected primary-expression before ?const? ./boost/python/call.hpp:54: error: expected primary-expression before ?const? ./boost/python/call.hpp:54: error: expected primary-expression before ?const? ... The error messages go on forever. I stopped the compiling and saw: "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -pthread -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -I"." -I"/local/prod/python/python_2.5/include/python2.4" -c -o "bin.v2/libs/python/build/gcc-4.0.2/debug/threading-multi/class.o" "libs/python/src/object/class.cpp" I have no clue about where the "/local/prod/python/python_2.5/include/python2.4" is from. My PYTHON_ROOT in bjam configure is completely different, /swdevl/local/python_2.5.2. and there is simply no 'python2.4' in /local/prod/python/python_2.5/include/. Any one knows whats happening? I built boost 1.34.1 on python 2.5.1 on centos 4, which was just done fine, and using the same gcc 4.0.2. Thanks, ZIZI LAIKA _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. From michael.wieher at gmail.com Tue Mar 11 20:02:58 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Tue, 11 Mar 2008 14:02:58 -0500 Subject: [C++-sig] boost 1.34.1 & python 2.5.2 on centos 5 In-Reply-To: <31665157.1705291205259373210.JavaMail.root@zimbra01.laika.com> References: <15968033.post@talk.nabble.com> <31665157.1705291205259373210.JavaMail.root@zimbra01.laika.com> Message-ID: #include That defines PyObject... after that, see what errors go away =) 2008/3/11, ZiZi Zhao : > > Hi All, > > I just built python 2.5.2 on my centos 5 system, and now building boost > 1.34.1 on python 2.5.2, both are compiled with gcc 4.0.2. > > But, I got tons of messages such as: > > ./boost/python/converter/arg_from_python.hpp:239: error: 'PyObject' was > not declared in this scope > ./boost/python/converter/arg_from_python.hpp:239: error: 'p' was not > declared in this scope > ./boost/python/converter/arg_from_python.hpp:240: error: expected `;' > before '{' token > ./boost/python/converter/arg_from_python.hpp: In member function 'T > boost::python::converter::pointer_cref_arg_from_python::operator()() > const': > ./boost/python/converter/arg_from_python.hpp:258: error: 'Py_None' was not > declared in this scope > ./boost/python/converter/arg_from_python.hpp: At global scope: > ./boost/python/converter/arg_from_python.hpp:267: error: ISO C++ forbids > declaration of 'pointer_arg_from_python' with no type > ./boost/python/converter/arg_from_python.hpp:267: error: > 'boost::python::converter::pointer_arg_from_python::pointer_arg_from_python' > declared as an 'inline' variable > ./boost/python/converter/arg_from_python.hpp:267: error: 'int > boost::python::converter::pointer_arg_from_python::pointer_arg_from_python' > is not a static member of 'struct > boost::python::converter::pointer_arg_from_python' > ... > > ./boost/python/call.hpp:53: error: template declaration of 'typename > boost::python::detail::returnable::type boost::python::call' > ./boost/python/call.hpp:53: error: 'PyObject' was not declared in this > scope > ./boost/python/call.hpp:53: error: 'callable' was not declared in this > scope > ./boost/python/call.hpp:54: error: expected primary-expression before > 'const' > ./boost/python/call.hpp:54: error: expected primary-expression before > 'const' > ./boost/python/call.hpp:54: error: expected primary-expression before > 'const' > ./boost/python/call.hpp:54: error: expected primary-expression before > 'const' > ... > > The error messages go on forever. I stopped the compiling and saw: > > "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC > -pthread -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -I"." > -I"/local/prod/python/python_2.5/include/python2.4" -c -o "bin.v2 > /libs/python/build/gcc-4.0.2/debug/threading-multi/class.o" > "libs/python/src/object/class.cpp" > > I have no clue about where the > "/local/prod/python/python_2.5/include/python2.4" is from. My PYTHON_ROOT in > bjam configure is completely different, /swdevl/local/python_2.5.2. and > there is simply no 'python2.4' in > /local/prod/python/python_2.5/include/. > > Any one knows whats happening? > > I built boost 1.34.1 on python 2.5.1 on centos 4, which was just done > fine, and using the same gcc 4.0.2. > > Thanks, > > ZIZI > LAIKA > > > _____________________________________________________________________ > The information contained in this message and its attachments is > confidential and proprietary to LAIKA, Inc. By opening this email > or any of its attachments, you agree to keep all such information > confidential and not to use, distribute, disclose or copy any part > of such information without the prior written consent of LAIKA, > Inc. If you are not the intended recipient of this message, any use, > distribution, disclosure or copying of such information is prohibited. > If received in error, please contact the sender. > > _______________________________________________ > 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 zzhao at laika.com Tue Mar 11 23:30:18 2008 From: zzhao at laika.com (ZiZi Zhao) Date: Tue, 11 Mar 2008 15:30:18 -0700 (PDT) Subject: [C++-sig] boost 1.34.1 & python 2.5.2 on centos 5 In-Reply-To: Message-ID: <12680608.1755621205274618084.JavaMail.root@zimbra01.laika.com> I have to use 'configure' to set all options about python first, -- with-python ='/somewhere/ python2 .5.2/bin/ python' -- with-python -root='/somewhere/ python2 .5. 2' -- with-python -version= '2 . 5' -- with-libraries = '-L /somewhere/ python2 .5.2/lib/ python2 .5/ config -L / usr /lib -lpython2 . 5' -- with-toolset = 'gcc' then, run bjam . The errors seems gone. But, there is a PYthon-2 .5.1 in the file system, how could I know which python 2.5.* the 'bjam' picked up, since it even could make up something like -I "/local/prod/python/ python_2 .5/include/ python2 .4" I have no clue about where the "/local/prod/python/ python_2 .5/include/ python2 .4" is from. I edit the bjam option with -sPYTHON_ROOT =/ swdevl /local/ python_2 .5.2. bjam builds everything implicitly. I really don't like this way. Why is there no bjam _build.log for us to check what was going on in the building? ZIZI LAIKA ----- Original Message ----- From: "Michael Wieher " < michael . wieher @ gmail .com> To: "Development of Python/C++ integration" Sent: Tuesday, March 11, 2008 12:02:58 PM ( GMT-0800 ) America/ Los_Angeles Subject: Re: [C++ -sig ] boost 1.34.1 & python 2.5.2 on centos 5 #include That defines PyObject ... after that, see what errors go away =) 2008/3/11, ZiZi Zhao < zzhao @ laika .com >: Hi All, I just built python 2.5.2 on my centos 5 system, and now building boost 1.34.1 on python 2.5.2, both are compiled with gcc 4.0.2. But, I got tons of messages such as: ./boost/python/converter/ arg_from_python . hpp :239: error: 'PyObject' was not declared in this scope ./boost/python/converter/ arg_from_python . hpp :239: error: 'p' was not declared in this scope ./boost/python/converter/ arg_from_python . hpp :240: error: expected `;' before '{' token ./boost/python/converter/ arg_from_python . hpp : In member function 'T boost::python::converter:: pointer_cref_arg_from_python ::operator()() const' : ./boost/python/converter/ arg_from_python . hpp :258: error: 'Py_None' was not declared in this scope ./boost/python/converter/ arg_from_python . hpp : At global scope: ./boost/python/converter/ arg_from_python . hpp :267: error: ISO C++ forbids declaration of 'pointer_arg_from_python' with no type ./boost/python/converter/ arg_from_python . hpp :267: error: 'boost ::python::converter:: pointer_arg_from_python :: pointer_arg_from_python' declared as an 'inline' variable ./boost/python/converter/ arg_from_python . hpp :267: error: 'int boost::python::converter:: pointer_arg_from_python :: pointer_arg_from_python' is not a static member of 'struct boost::python::converter:: pointer_arg_from_python ' ... ./boost/python/call. hpp :53: error: template declaration of 'typename boost::python::detail::returnable::type boost::python:: call' ./boost/python/call. hpp :53: error: 'PyObject' was not declared in this scope ./boost/python/call. hpp :53: error: 'callable' was not declared in this scope ./boost/python/call. hpp :54: error: expected primary-expression before 'const' ./boost/python/call. hpp :54: error: expected primary-expression before 'const' ./boost/python/call. hpp :54: error: expected primary-expression before 'const' ./boost/python/call. hpp :54: error: expected primary-expression before 'const' ... The error messages go on forever. I stopped the compiling and saw: "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -pthread -DBOOST_ALL_NO_LIB =1 -DBOOST_PYTHON_SOURCE -I "." -I "/local/prod/python/ python_2 .5/include/ python2 .4" -c -o "bin. v2 /libs/python/build/ gcc -4.0.2/debug/ threading-multi /class.o" "libs/python/ src /object/class. cpp " I have no clue about where the "/local/prod/python/ python_2 .5/include/ python2 .4" is from. My PYTHON_ROOT in bjam configure is completely different, / swdevl /local/ python_2 .5.2. and there is simply no 'python2 . 4' in /local/prod/python/ python_2 .5/include/. Any one knows whats happening? I built boost 1.34.1 on python 2.5.1 on centos 4, which was just done fine, and using the same gcc 4.0.2. Thanks, ZIZI LAIKA _ _______________________________________________ _____________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA , Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA , Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. _______________________________________________ C++ -sig mailing list C++ -sig @python.org http ://mail.python.org/mailman/ listinfo /c++ -sig _____________________________________________________________________ The information contained in this message and its attachments is confidential and proprietary to LAIKA, Inc. By opening this email or any of its attachments, you agree to keep all such information confidential and not to use, distribute, disclose or copy any part of such information without the prior written consent of LAIKA, Inc. If you are not the intended recipient of this message, any use, distribution, disclosure or copying of such information is prohibited. If received in error, please contact the sender. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pablo_best at o2.pl Wed Mar 12 01:14:37 2008 From: pablo_best at o2.pl (pawell) Date: Tue, 11 Mar 2008 17:14:37 -0700 (PDT) Subject: [C++-sig] Global variables (standard C/C++ types) In-Reply-To: <47D5C588.1050702@sympatico.ca> References: <15968033.post@talk.nabble.com> <47D5C588.1050702@sympatico.ca> Message-ID: <15995328.post@talk.nabble.com> I found (I think) some other solution. This code works as I expected: int global_int = 666; bool global_bool = 666; struct PCFG { }; PCFG tmp_pcfg; BOOST_PYTHON_MODULE(my_app) { class_("PCFG") .def_readwrite("global_int",&global_int) .def_readwrite("global_bool",&global_bool) ; scope().attr("pcfg") = object(ptr(&tmp_pcfg)); } int main(int argc, char** argv) { Py_Initialize(); init__main__(); initmy_app(); Py_Main(argc,argv); Py_Finalize(); std::cout << "global_int: " << global_int << std::endl; std::cout << "global_bool: " << global_bool << std::endl; return 0; } Now I can modify my_app.pcfg.global_bool or my_app.pcfg.global_int and see result in C++ :) Is it ok to reference C++ global objects as Python class members? -- View this message in context: http://www.nabble.com/Global-variables-%28standard-C-C%2B%2B-types%29-tp15968033p15995328.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From aklaing at gmail.com Thu Mar 13 11:01:30 2008 From: aklaing at gmail.com (Ambrose Kofi Laing) Date: Thu, 13 Mar 2008 06:01:30 -0400 Subject: [C++-sig] returning PyObject * (unmodified) from embedded python back to c++ Message-ID: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> Hi all, I'm new to boost::python, and I need to write a program that defines an abstract base class in C++, and a derived class in Python. Then I want to instantiate the derived class in python and store its address in a C++ variable of type pointer to the base type and call python methods in the derived type polymorphically from C++. All of that works. The remaining problem is how to let the python function return arbitrary python objects to C++, and have C++ hold a pointer to the arbitrary returned result. Below is my code so far, it isn't working as written (but when I change all the 'PyObject *' to C++ type string and make other appropriate changes in the python file, it works for returning string types. Can anyone give me an idea what changes are required in the code to do what I need ? Thanks, Ambrose The two files are included below: mymodule.cpp---------------------------------------------------------------------------------------- #include #include #include using namespace std; #include using namespace boost::python; struct Base { Base() { s = Py_None; } Base(PyObject *input){ s = input; } virtual ~Base() {} virtual PyObject *run() { return s; } private: PyObject *s; }; struct BaseWrap : Base, wrapper { BaseWrap() : Base() {} BaseWrap(PyObject *input) : Base(input) {} PyObject *run() { if (override run = this->get_override("run")) return run(); return Base::run(); } PyObject *default_run() { return this->Base::run(); } }; typedef boost::shared_ptr BasePtr; BasePtr g(new Base); BasePtr get_g() { return g; } BasePtr set_g(BasePtr input_g) { BasePtr tmp; tmp = g; g = input_g; return tmp; } PyObject *run_g() { PyObject *tmp; tmp = g->run(); return tmp; } BOOST_PYTHON_MODULE(mymodule) { def("set_g", set_g); def("get_g", get_g); def("run_g", run_g); class_("Base", init<>()) .def(init()) .def("run", &Base::run, &BaseWrap::default_run) ; register_ptr_to_python< BasePtr >(); } ----- test.py---------------------------------------------------------------------------------------------------- #!/usr/bin/env python from mymodule import * class DerivedS( Base ): def run( self ): x = Base.run( self ) return x+x class DerivedM( Base ): def __init__( self ): import random x = random.randint(0,4) if x == 0: self.x = 1 # int elif x == 1: self.x = 1.0 elif x == 2: self.x = 'string' elif x == 3: self.x = ['array'] elif x == 4: self.x = ('tuple') def run( self ): return self.x + self.x # defined for all 5 types above # minimal set of tests: b1 = Base() set_g(b1) x = b1.run() # test from python should print nothing y = run_g() # test call from C++ should print nothing if x is None: print 'x is None' if y is None: print 'y is None' b2 = Base('init_str') ib1 = set_g(b2) # want something identical to b1 b2.run() # want 'init_str' run_g() # want 'init_str' ds = DerivedS('derived') ib2 = set_g(ds) # want something identical to b2 ds.run() # want 'derivedderived' run_g() # want 'derivedderived' dm = DerivedM() ids = set_g(dm) # want something identical to ds dm.run() # want one of the values # 2, 2.0, 'stringstring', ['array','array'], ('tuple','tuple') run_g() # same output as previous -------------- next part -------------- An HTML attachment was scrubbed... URL: From claudius.mueller at gmail.com Thu Mar 13 22:57:44 2008 From: claudius.mueller at gmail.com (Claudius Mueller) Date: Thu, 13 Mar 2008 14:57:44 -0700 Subject: [C++-sig] boost-python tutorial - semi success... Message-ID: <6ea182d0803131457w3d814ff1k6234539f1b63446e@mail.gmail.com> Hi, First time posting here - so please let me know if the information I've provided is good enough or if you'd like to see further posts in a different format. I have a problem importing the module generated during the boost/python tutorial - or much more precise: the module is not there. I have followed the steps of the tutorial (http://svn.boost.org/svn/boost/trunk/libs/python/doc/tutorial/doc/html/python/hello.html). The output files that test the module during the bjam run all say that it worked (hello.output, hello.test). But there is no hello_ext.pyd present anywhere. Bjam output says that it is generated (see below) and the test python script may have found it during the test - but if I look in all the folders (even searched the whole harddrive for it) the file is not there. Even if I run bjam -n and simply copy the python invocation + environment variable settings (PATH, PYTHONPATH) that worked during the bjam run into the command line - it no longer works (hello.ouptut gives me an error that hello_ext module can't be loaded). As if hello_ext.pyd was only generated temporarily... Does anybody have an idea what I'm doing wrong? Probably something really stupid... System details: =========== - Vista Home Premium - Boost 1.35 - Python 2.5 - Visual C++ 2008 Express Edition Bjam -n output: =========== ...patience... ...found 1103 targets... ...updating 3 targets... file bin\msvc-9.0\debug\threading-multi\hello_ext.pyd.rsp "bin\msvc-9.0\debug\threading-multi\hello.obj" "..\..\..\..\bin.v2\libs\python\build\msvc-9.0\debug\threading-multi\boost_python-vc90-mt-gd-1_35.lib" "python25.lib" msvc.link.dll bin\msvc-9.0\debug\threading-multi\hello_ext.pyd call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul link /NOLOGO /INCREMENTAL:NO /DLL /DEBUG /subsystem:console /out:"bin\msvc-9.0\debug\threading-multi\hello_ext.pyd" /IMPLIB:"bin\msvc-9.0\debug\threading-multi\hello_ext.lib" /LIBPATH:"C:\python25\libs" @"bin\msvc-9.0\debug\threading-multi\hello_ext.pyd.rsp" if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% if exist "bin\msvc-9.0\debug\threading-multi\hello_ext.pyd.manifest" ( mt -nologo -manifest "bin\msvc-9.0\debug\threading-multi\hello_ext.pyd.manifest" "-outputresource:bin\msvc-9.0\debug\threading-multi\hello_ext.pyd;2" ) capture-output bin\hello.test\msvc-9.0\debug\threading-multi\hello set Path=C:\C++\Boost\bin.v2\libs\python\build\msvc-9.0\debug\threading-multi;C:\C++\Boost\libs\python\example\tutorial\bin\msvc-9.0\debug\threading-multi;C:\python25;C:\python25\libs;%Path% set PYTHONPATH=bin\msvc-9.0\debug\threading-multi C:/python25\python "hello.py" > "bin\hello.test\msvc-9.0\debug\threading-multi\hello.output" 2>&1 set status=%ERRORLEVEL% echo. >> "bin\hello.test\msvc-9.0\debug\threading-multi\hello.output" echo EXIT STATUS: %status% >> "bin\hello.test\msvc-9.0\debug\threading-multi\hello.output" if %status% EQU 0 ( copy "bin\hello.test\msvc-9.0\debug\threading-multi\hello.output" "bin\hello.test\msvc-9.0\debug\threading-multi\hello" ) set verbose=0 if %status% NEQ 0 ( set verbose=1 ) if %verbose% EQU 1 ( echo ====== BEGIN OUTPUT ====== type "bin\hello.test\msvc-9.0\debug\threading-multi\hello.output" echo ====== END OUTPUT ====== ) exit %status% RmTemps bin\hello.test\msvc-9.0\debug\threading-multi\hello del /f /q "bin\msvc-9.0\debug\threading-multi\hello_ext.pyd" **passed** bin\hello.test\msvc-9.0\debug\threading-multi\hello.test echo passed > bin\hello.test\msvc-9.0\debug\threading-multi\hello.test ...updated 3 targets... ================= Any help would be greatly appreciated! Thank you, Claudius From aklaing at gmail.com Fri Mar 14 01:54:52 2008 From: aklaing at gmail.com (Ambrose Kofi Laing) Date: Thu, 13 Mar 2008 20:54:52 -0400 Subject: [C++-sig] returning PyObject * (unmodified) from embedded python back to c++ In-Reply-To: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> References: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> Message-ID: <193c66940803131754r5d69b3b8k49b501a7d2814619@mail.gmail.com> Hi, I sent this email earlier and I'm not sure if it came through (I was just getting subscribed). I'm new to boost::python, and I need to write a program that defines an abstract base class in C++, and a derived class in Python. Then I want to instantiate the derived class in python and store its address in a C++ variable of type pointer to the base type and call python methods in the derived type polymorphically from C++. All of that works. The remaining problem is how to let the python function return arbitrary python objects to C++, and have C++ hold a pointer to the arbitrary returned result. Below is my code so far, it isn't working as written (but when I change all the 'PyObject *' to C++ type string and make other appropriate changes in the python file, it works for returning string types. Can anyone give me an idea what changes are required in the code to do what I need? Any pointers would be very much appreciated. Thanks, Ambrose The two files are included below: ------ mymodule.cpp ------------------------------------------------ #include #include #include using namespace std; #include using namespace boost::python; struct Base { Base() { s = Py_None; } Base(PyObject *input){ s = input; } virtual ~Base() {} virtual PyObject *run() { return s; } private: PyObject *s; }; struct BaseWrap : Base, wrapper { BaseWrap() : Base() {} BaseWrap(PyObject *input) : Base(input) {} PyObject *run() { if (override run = this->get_override("run")) return run(); return Base::run(); } PyObject *default_run() { return this->Base::run(); } }; typedef boost::shared_ptr BasePtr; BasePtr g(new Base); BasePtr get_g() { return g; } BasePtr set_g(BasePtr input_g) { BasePtr tmp; tmp = g; g = input_g; return tmp; } PyObject *run_g() { PyObject *tmp; tmp = g->run(); return tmp; } BOOST_PYTHON_MODULE(mymodule) { def("set_g", set_g); def("get_g", get_g); def("run_g", run_g); class_("Base", init<>()) .def(init()) .def("run", &Base::run, &BaseWrap::default_run) ; register_ptr_to_python< BasePtr >(); } ----- test.py---------------------------------------------------------------------------------------------------- #!/usr/bin/env python from mymodule import * class DerivedS( Base ): def run( self ): x = Base.run( self ) return x+x class DerivedM( Base ): def __init__( self ): import random x = random.randint(0,4) if x == 0: self.x = 1 # int elif x == 1: self.x = 1.0 elif x == 2: self.x = 'string' elif x == 3: self.x = ['array'] elif x == 4: self.x = ('tuple') def run( self ): return self.x + self.x # defined for all 5 types above # minimal set of tests: b1 = Base() set_g(b1) x = b1.run() # test from python should print nothing y = run_g() # test call from C++ should print nothing if x is None: print 'x is None' if y is None: print 'y is None' b2 = Base('init_str') ib1 = set_g(b2) # want something identical to b1 b2.run() # want 'init_str' run_g() # want 'init_str' ds = DerivedS('derived') ib2 = set_g(ds) # want something identical to b2 ds.run() # want 'derivedderived' run_g() # want 'derivedderived' dm = DerivedM() ids = set_g(dm) # want something identical to ds dm.run() # want one of the values # 2, 2.0, 'stringstring', ['array','array'], ('tuple','tuple') run_g() # same output as previous -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Fri Mar 14 20:11:08 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Fri, 14 Mar 2008 14:11:08 -0500 Subject: [C++-sig] Debug build Message-ID: <3dc9bcf00803141211w59560bbah97be4a7be07e6127@mail.gmail.com> I have had some need for end to end debugging. (step through python, boost.python the wrapper layer, and the wrapped library to find my error). To that end I have compiled python in debug mode, and compiled my library in debug mode. I have an odd error: Press any key to continue . . . C:\tools-current>python Python 2.5.1 (r251:54863, Feb 1 2008, 11:38:01) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import cppclient >>> ^Z C:\tools-current>python_d Python 2.5.1 (r251:54863, Feb 1 2008, 11:28:42) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import cppclient Fatal Python error: Interpreter not initialized (version mismatch?) C:\tools-current> -------------- next part -------------- An HTML attachment was scrubbed... URL: From aklaing at gmail.com Mon Mar 17 01:10:08 2008 From: aklaing at gmail.com (Ambrose Kofi Laing) Date: Sun, 16 Mar 2008 20:10:08 -0400 Subject: [C++-sig] returning PyObject * (unmodified) from embedded python back to c++ In-Reply-To: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> References: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> Message-ID: <193c66940803161710u7d53f34cif1b54490b9ca1a4d@mail.gmail.com> There's been some progress, using the boost object implementation. However it appears that the "chg" method of the DerivedO object is not overridden properly. So when it is changed in python, I get what I expect, but when it is changed in C++, it appears to run the Base::chg method instead of the DerivedO::chg method. I'm sure I'm only missing some tiny detail now. ---- mymodule.cpp ------------------------------------------------ #define MYTYPE object #define MYDEFAULT object(0) /* #define MYTYPE string #define MYDEFAULT "" */ #include #include #include using namespace std; #include using namespace boost::python; struct Base { Base() { s = MYDEFAULT ; } Base(MYTYPE input){ s = input; } virtual ~Base() {} virtual MYTYPE run() { return s; } virtual void chg(MYTYPE input) { s = input; } private: MYTYPE s; }; struct BaseWrap : Base, wrapper { BaseWrap() : Base() {} BaseWrap(MYTYPE input) : Base(input) {} MYTYPE run() { if (override run = this->get_override("run")) return run(); return Base::run(); } MYTYPE default_run() { return this->Base::run(); } void chg(MYTYPE input) { if (override chg = this->get_override("chg")) chg(input); Base::chg(input); } void default_chg(MYTYPE input) { this->Base::chg(input); } }; typedef boost::shared_ptr BasePtr; BasePtr g(new Base); BasePtr get_g() { return g; } BasePtr set_g(BasePtr input_g) { BasePtr tmp; tmp = g; g = input_g; return tmp; } MYTYPE run_g() { MYTYPE tmp; tmp = g->run(); return tmp; } void chg_g(MYTYPE input) { g->chg(input); } BOOST_PYTHON_MODULE(mymodule) { def("set_g", set_g); def("get_g", get_g); def("run_g", run_g); def("chg_g", chg_g); class_("Base", init<>()) .def(init()) .def("run", &Base::run, &BaseWrap::default_run) .def("chg", &Base::chg, &BaseWrap::default_chg) ; register_ptr_to_python< BasePtr >(); } ---- test.py ------------------------------------------------ #!/usr/bin/env python from mymodule import * class DerivedS( Base ): def run( self ): x = Base.run( self ) return x+x class DerivedO( Base ): def chg( self, val ): y = [1, 1.0, 'string', ['array'], ('tuple',) ][val] Base.chg( self, y ) def run( self ): x = Base.run( self ) return x+x # defined for all 5 types above. ---- test run ------------------------------------------------ >>> from mymodule import * >>> b1 = Base() >>> b1.run() 0 >>> x = b1.run() >>> set_g(b1) >>> run_g() 0 >>> b2 = Base('init_str') >>> ib1 = set_g(b2) >>> ib1.run() 0 >>> b2.run() 'init_str' >>> run_g() 'init_str' >>> chg_g(40) >>> b2.run() 40 >>> run_g() 40 >>> ds = DerivedS('derived') >>> ib2=set_g(ds) >>> ib2.run() 40 >>> ds.run() 'derivedderived' >>> run_g() 'derivedderived' >>> ds.chg('changed in python ') >>> ds.run() 'changed in python changed in python ' >>> chg_g('changed in C++ ') >>> run_g() 'changed in C++ changed in C++ ' >>> ds.run() 'changed in C++ changed in C++ ' >>> class DerivedO( Base ): ... def chg( self, val ): ... y = [1, ... 1.0, ... 'string', ... ['array'], ... ('tuple',) ... ][val] ... Base.chg( self, y ) ... def run( self ): ... x = Base.run( self ) ... return x+x # defined for all 5 types above. ... >>> do = DerivedO() >>> do.run() 0 >>> ids = set_g(do) >>> ids.run() 'changed in C++ changed in C++ ' >>> do.chg(1) >>> do.run() 2.0 >>> do.chg(2) >>> do.run() 'stringstring' >>> do.chg(3) >>> do.run() ['array', 'array'] >>> run_g() ['array', 'array'] >>> do.chg(4) >>> run_g() ('tuple', 'tuple') >>> chg_g(2) >>> do.run() 4 >>> chg_g(1) >>> do.run() 2 >>> chg_g('this is ') Traceback (most recent call last): File "", line 1, in File "", line 8, in chg TypeError: list indices must be integers >>> chg_g(3) >>> run_g() 6 >>> do.chg(1) >>> do.run() 2.0 >>> do.chg(2) >>> do.run() 'stringstring' >>> do.chg(3) >>> do.run() ['array', 'array'] >>> do.chg(4) >>> do.run() ('tuple', 'tuple') >>> do.chg(0) >>> do.run() 2 >>> run_g() 2 >>> chg_g(0) >>> run_g() 0 >>> chg_g(1) >>> run_g() 2 >>> chg_g(2) >>> run_g() 4 >>> do.run() 4 >>> do.chg(2) >>> do.run() 'stringstring' >>> run_g() 'stringstring' >>> chg_g(2) >>> do.run() 4 >>> run_g() 4 >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.buza at gmail.com Mon Mar 17 22:58:37 2008 From: apt.buza at gmail.com (Andrew Buza) Date: Mon, 17 Mar 2008 14:58:37 -0700 Subject: [C++-sig] Unable to compile modules using vector_indexing_suite Message-ID: <686dcf140803171458j2d52c872ldcacf18b86ad2f61@mail.gmail.com> Hi Everyone. I hope this is the right place for boost_python usage questions. I'm having trouble getting anything using vector_indexing_suite to compile. I don't think it is a problem with configuration since all the other parts of boost_python I've used are working fine, and the sample given below (almost identical to one of the example usages in the documentation) fails to compile as well, so it isn't an error in usage on my part (I hope!). The sample I'm using is: #include #include #include using namespace boost::python; BOOST_PYTHON_MODULE(test) { class_ >("IntVec") .def(vector_indexing_suite >()) ; } which is compiled with: C:\>cl Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86 Copyright (C) Microsoft Corporation 1984-2002. All rights reserved. C:\>cl /nologo /TP /EHsc /IC:\cxx\boost_1_33_1 /IC:\Python24\include /c src/test.cpp and gives the following error: C:\cxx\boost_1_33_1\boost\detail\compressed_pair.hpp(347) : error C2247: 'boost::python::objects::iterator_range::next' not accessible because 'boost::details::compressed_pair_imp' uses 'private' to inherit from 'boost::python::objects::iterator_range::next' Does anyone have any insight into this problem? From aklaing at gmail.com Tue Mar 18 01:26:47 2008 From: aklaing at gmail.com (Ambrose Kofi Laing) Date: Mon, 17 Mar 2008 20:26:47 -0400 Subject: [C++-sig] returning PyObject * (unmodified) from embedded python back to c++ In-Reply-To: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> References: <193c66940803130301i39a34453i84687d8bac71f8cf@mail.gmail.com> Message-ID: <193c66940803171726n243e7772te6474ab874f0b93e@mail.gmail.com> All good now, thought I'd just post the final version. ---- mymodule.cpp -------------------------------------------------------- #define MYTYPE object #define MYDEFAULT object(0) /* #define MYTYPE string #define MYDEFAULT "" */ #include #include #include using namespace std; #include using namespace boost::python; struct Base { Base() { s = MYDEFAULT ; } Base(MYTYPE input){ s = input; } virtual ~Base() {} virtual MYTYPE run() { return s; } virtual void chg(MYTYPE input) { s = input; } private: MYTYPE s; }; struct BaseWrap : Base, wrapper { BaseWrap() : Base() {} BaseWrap(MYTYPE input) : Base(input) {} MYTYPE run() { if (override run = this->get_override("run")) return run(); return Base::run(); } MYTYPE default_run() { return this->Base::run(); } void chg(MYTYPE input) { if (override chg = this->get_override("chg")) chg(input); else Base::chg(input); } void default_chg(MYTYPE input) { this->Base::chg(input); } }; typedef boost::shared_ptr BasePtr; BasePtr g(new Base); BasePtr get_g() { return g; } BasePtr set_g(BasePtr input_g) { BasePtr tmp; tmp = g; g = input_g; return tmp; } MYTYPE run_g() { MYTYPE tmp; tmp = g->run(); return tmp; } void chg_g(MYTYPE input) { g->chg(input); } BOOST_PYTHON_MODULE(mymodule) { def("set_g", set_g); def("get_g", get_g); def("run_g", run_g); def("chg_g", chg_g); class_("Base", init<>()) .def(init()) .def("run", &Base::run, &BaseWrap::default_run) .def("chg", &Base::chg, &BaseWrap::default_chg) ; register_ptr_to_python< BasePtr >(); } ---- test.py -------------------------------------------------------- #!/usr/bin/env python from mymodule import * class DerivedS( Base ): def run( self ): x = Base.run( self ) return x+x class DerivedO( Base ): def chg( self, val ): y = [1, 1.0, 'string', ['array'], ('tuple',) ][val] Base.chg( self, y ) def run( self ): x = Base.run( self ) return x+x # defined for all 5 types above. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Thu Mar 20 20:26:47 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 20 Mar 2008 14:26:47 -0500 Subject: [C++-sig] Fatal Python error: Interpreter not initialized (version mismatch?) Message-ID: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> No one can help me? This is an odd error. It only comes up when I am running debug python.should I be asking a more general python group? On Fri, Mar 14, 2008 at 2:11 PM, Matthew Scouten wrote: > I have had some need for end to end debugging. (step through python, > boost.python the wrapper layer, and the wrapped library to find my error). > > To that end I have compiled python in debug mode, and compiled my library > in debug mode. I have an odd error: > > Press any key to continue . . . > C:\tools-current>python > Python 2.5.1 (r251:54863, Feb 1 2008, 11:38:01) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import cppclient > >>> ^Z > > > C:\tools-current>python_d > Python 2.5.1 (r251:54863, Feb 1 2008, 11:28:42) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import cppclient > Fatal Python error: Interpreter not initialized (version mismatch?) > > C:\tools-current> > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.wieher at gmail.com Thu Mar 20 20:33:19 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Thu, 20 Mar 2008 14:33:19 -0500 Subject: [C++-sig] Fatal Python error: Interpreter not initialized (version mismatch?) In-Reply-To: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> References: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> Message-ID: I'm not really familiar with boost, but I do know that when you use python to build the C pyd you'll want to be sure that the version of python that built the pyd is the same as the interpreter. Also be sure that the C compiler used to build the library is the same as the one you used to compile python with. you could post to the main group, but I think this is the right spot. 2008/3/20, Matthew Scouten : > > No one can help me? This is an odd error. It only comes up when I am > running debug python.should I be asking a more general python group? > > On Fri, Mar 14, 2008 at 2:11 PM, Matthew Scouten < > matthew.scouten at gmail.com> wrote: > > > I have had some need for end to end debugging. (step through python, > > boost.python the wrapper layer, and the wrapped library to find my > > error). > > > > To that end I have compiled python in debug mode, and compiled my > > library in debug mode. I have an odd error: > > > > Press any key to continue . . . > > C:\tools-current>python > > Python 2.5.1 (r251:54863, Feb 1 2008, 11:38:01) [MSC v.1310 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import cppclient > > >>> ^Z > > > > > > C:\tools-current>python_d > > Python 2.5.1 (r251:54863, Feb 1 2008, 11:28:42) [MSC v.1310 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import cppclient > > Fatal Python error: Interpreter not initialized (version mismatch?) > > > > C:\tools-current> > > > > > > > > > > _______________________________________________ > 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 seefeld at sympatico.ca Thu Mar 20 20:34:06 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 20 Mar 2008 15:34:06 -0400 Subject: [C++-sig] Fatal Python error: Interpreter not initialized (version mismatch?) In-Reply-To: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> References: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> Message-ID: <47E2BC2E.1020200@sympatico.ca> Matthew Scouten wrote: > No one can help me? This is an odd error. It only comes up when I am > running debug python.should I be asking a more general python group? Didn't David answer this question already ? You need to make sure boost.python as well as your application / modules are compiled against the same python library, as debug and release versions aren't binary-compatible. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From seefeld at sympatico.ca Thu Mar 20 20:38:06 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 20 Mar 2008 15:38:06 -0400 Subject: [C++-sig] Fatal Python error: Interpreter not initialized (version mismatch?) In-Reply-To: References: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> Message-ID: <47E2BD1E.7010809@sympatico.ca> Michael Wieher wrote: > Also be sure that the C compiler used to build the library is the same > as the one you used to compile python with. That's not necessary. C code doesn't have the same ABI compatibility issues as C++ code has. It's only true for C++ code, as different compilers (typically) don't adhere to the same C++ ABI (Application Binary Interface). Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From matthew.scouten at gmail.com Thu Mar 20 20:49:25 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 20 Mar 2008 14:49:25 -0500 Subject: [C++-sig] Fatal Python error: Interpreter not initialized (version mismatch?) In-Reply-To: <47E2BC2E.1020200@sympatico.ca> References: <3dc9bcf00803201226x378ed209r34f150d28331a073@mail.gmail.com> <47E2BC2E.1020200@sympatico.ca> Message-ID: <3dc9bcf00803201249y2c4e5713y6150128aebd8e6d5@mail.gmail.com> Boost::python, and my extension are both compiled against python 2.5.1 My extension's debug version and release configurations were both compiled against the appropriate configuration of the same python lib. If Someone answered my question earlier. It must not have reached me. sorry. On Thu, Mar 20, 2008 at 2:34 PM, Stefan Seefeld wrote: > Matthew Scouten wrote: > > No one can help me? This is an odd error. It only comes up when I am > > running debug python.should I be asking a more general python group? > > Didn't David answer this question already ? > > You need to make sure boost.python as well as your application / modules > are compiled against the same python library, as debug and release > versions aren't binary-compatible. > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > 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 arunvn_ind at yahoo.co.uk Fri Mar 21 13:55:24 2008 From: arunvn_ind at yahoo.co.uk (Arun v n) Date: Fri, 21 Mar 2008 05:55:24 -0700 (PDT) Subject: [C++-sig] How to open .CHM help files. Message-ID: <640773.8170.qm@web27401.mail.ukl.yahoo.com> Can anyone give some inputs on how to open a .CHM help file in a WIN32 application. Does HTMLHelp() method work in Win32 appln. What should be the headers and libs included. Is there any other way to access these help files. Experts kindly give me some input on this. Regards, Arun VN --------------------------------- Never miss a thing. Make Yahoo your homepage. -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Mar 21 14:15:35 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 21 Mar 2008 09:15:35 -0400 Subject: [C++-sig] How to open .CHM help files. In-Reply-To: <640773.8170.qm@web27401.mail.ukl.yahoo.com> References: <640773.8170.qm@web27401.mail.ukl.yahoo.com> Message-ID: <47E3B4F7.4070707@sympatico.ca> Arun v n wrote: > Can anyone give some inputs on how to open a .CHM help file in a WIN32 > application. > Does HTMLHelp() method work in Win32 appln. What should be the headers > and libs included. > Is there any other way to access these help files. I have no idea what a '.CHM' file is, and it doesn't sound as if it was related to Python or Python/C++ integration, so I'd suggest you choose a more appropriate forum to ask. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jameswhetstone at comcast.net Sat Mar 22 21:57:31 2008 From: jameswhetstone at comcast.net (James Whetstone) Date: Sat, 22 Mar 2008 13:57:31 -0700 Subject: [C++-sig] How to use boost.python to wrap a class with a pure virtual function that has a 'void *' argument Message-ID: <004e01c88c5f$58faeac0$6601a8c0@structure> I'm new to Python and Boost.python and as the subject implies, I'm having trouble wrapping a C++ class that looks like this: struct A { virtual void handleMessage(void *message)=0; }; To wrap this class, I've written the following code: struct AWrapper : A, wrapper { void handleMessage(void *message) { this->get_override("handleMessage")(message); } }; class_("A") .def("handleMessage", pure_virtual(&A::handleMessage)) ; My python test code looks like this: import APackage class aclass(APackage.A): def handleMessage(msg) : print msg But this code crashes when the handleMessage function is called in python (I think) because 'void *' cannot be marshalled. Is there some way around this? Also, since the void* object is intended to be "zero copy", I should probably convert the void * to a PyObject first and re-write my handleMessage to look like this: void handleMessage(void *message) { int size = getMessageSize(message); PyObject *obj = PyBuffer_FromReadWriteMemory(message, size); this->get_override("handleMessage")(obj); } Has anyone done this type of thing? I'm writing this code using MS Visual Studio 8 and if anyone can help, it would *very* appreciated. Thanks! James -------------- next part -------------- An HTML attachment was scrubbed... URL: From per at gorep.se Tue Mar 25 12:45:03 2008 From: per at gorep.se (Per Ghosh) Date: Tue, 25 Mar 2008 12:45:03 +0100 Subject: [C++-sig] How to open .CHM help files. In-Reply-To: <640773.8170.qm@web27401.mail.ukl.yahoo.com> References: <640773.8170.qm@web27401.mail.ukl.yahoo.com> Message-ID: <47E8E5BF.9090705@gorep.se> An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Wed Mar 26 19:35:30 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Wed, 26 Mar 2008 13:35:30 -0500 Subject: [C++-sig] A vector of objects with private == operators Message-ID: <3dc9bcf00803261135h5f4feb80jb980e1497be20f81@mail.gmail.com> I have noticed that the vector indexing suite only compiles for a vector if foo has an == operator. Some of the objects that I need to wrap in a library have to wrap have no == operator. That's fine, I just create a dummy operator as a global function. The dummy operator just tests &a==&b. Now I come to a problem. the 'bar' class has a == operator, but it is declared private. I tried to create a global == operator but the compiler complained that it was ambiguous (the compiler is such a whiny little brat.) So my questions are 3 fold, Why the heck does vector_indexing_suite need an == operator? Assuming I can't change the problem class, what are possible workarounds? Does vector_indexing_suite2 still need an == operator? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at informa.tiker.net Wed Mar 26 19:42:55 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Wed, 26 Mar 2008 14:42:55 -0400 Subject: [C++-sig] A vector of objects with private == operators In-Reply-To: <3dc9bcf00803261135h5f4feb80jb980e1497be20f81@mail.gmail.com> References: <3dc9bcf00803261135h5f4feb80jb980e1497be20f81@mail.gmail.com> Message-ID: <200803261442.56918.lists@informa.tiker.net> On Mittwoch 26 M?rz 2008, Matthew Scouten wrote: > I have noticed that the vector indexing suite only compiles for a > vector if foo has an == operator. Some of the objects that I need to > wrap in a library have to wrap have no == operator. That's fine, I just > create a dummy operator as a global function. The dummy operator just tests > &a==&b. > > Now I come to a problem. the 'bar' class has a == operator, but it is > declared private. I tried to create a global == operator but the compiler > complained that it was ambiguous (the compiler is such a whiny little > brat.) > > So my questions are 3 fold, > Why the heck does vector_indexing_suite need an == operator? > Assuming I can't change the problem class, what are possible workarounds? > Does vector_indexing_suite2 still need an == operator? This is a hack I've been using: 8< -------------------------------------------------------------- template class no_compare_indexing_suite : public boost::python::vector_indexing_suite > { public: static bool contains(T &container, typename T::value_type const &key) { PYTHON_ERROR(NotImplementedError, "containment checking not supported on this container"); } }; 8< -------------------------------------------------------------- Use like so: cl.def(no_compare_indexing_suite()) Andreas -------------- 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 apt.buza at gmail.com Wed Mar 26 23:03:01 2008 From: apt.buza at gmail.com (Andrew Buza) Date: Wed, 26 Mar 2008 15:03:01 -0700 Subject: [C++-sig] Unable to compile modules using vector_indexing_suite In-Reply-To: <686dcf140803171458j2d52c872ldcacf18b86ad2f61@mail.gmail.com> References: <686dcf140803171458j2d52c872ldcacf18b86ad2f61@mail.gmail.com> Message-ID: <686dcf140803261503r28f88cbbs2e9f5ab70316b44c@mail.gmail.com> On Mon, Mar 17, 2008 at 2:58 PM, Andrew Buza wrote: > Hi Everyone. I hope this is the right place for boost_python usage questions. > > I'm having trouble getting anything using vector_indexing_suite to > compile. I don't think it is a problem with configuration since all > the other parts of boost_python I've used are working fine, and the > sample given below (almost identical to one of the example usages in > the documentation) fails to compile as well, so it isn't an error in > usage on my part (I hope!). > > The sample I'm using is: > > #include > #include > #include > > using namespace boost::python; > > BOOST_PYTHON_MODULE(test) > { > class_ >("IntVec") > .def(vector_indexing_suite >()) > ; > } > > which is compiled with: > > C:\>cl > Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86 > Copyright (C) Microsoft Corporation 1984-2002. All rights reserved. In case anyone else has this problem and stumbles across this message, this is the same issue described in "compile error in iterator" posted in November 2006 to this group (http://mail.python.org/pipermail/c++-sig/2006-November/011684.html). From venkat83 at gmail.com Thu Mar 27 14:10:07 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Thu, 27 Mar 2008 13:10:07 +0000 Subject: [C++-sig] boost::python PyUnicodeUCS4_FromEncodedObject In-Reply-To: References: Message-ID: Hi, Am stumbling on a very rudimentary problem and am totally not able to proceed. Googling did not help me much and hence am trying to state the problem in its entirety. Any quick comments/hints would be highly helpful. Am getting the following error when i try to import the module (class) into python : $python >>> import myClass *Traceback (most recent call last): File "", line 1, in ? ImportError: ./myClass.so: undefined symbol: PyUnicodeUCS4_FromEncodedObject * *Environment:* g++ (GCC) 4.0.0 20050519 (Red Hat 4.0.0-8) Python 2.4.3 *Other Information:* $ldd myClass.so libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00db8000) libm.so.6 => /lib/tls/libm.so.6 (0x002b3000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00eb7000) libpthread.so.0 => /lib/tls/libpthread.so.0 (0x0057a000) libc.so.6 => /lib/tls/libc.so.6 (0x00b6f000) /lib/ld-linux.so.2 (0x00712000) * Files Used :* *myClass.cpp* ------------- #include #include #include #include #include #include #include class Var { public: int value; std::string name; Var(std::string n) { name=n; value=10; } }; std::string processObj(boost::python::object x) { Var obj=boost::python::extract(x); return obj.name; } using namespace boost::python; BOOST_PYTHON_MODULE(myClass) { class_("Var", init()) .def_readonly("name", &Var::name) .def_readwrite("value", &Var::value); def("processObj", processObj); } *setup.py* --------------- from distutils.core import setup from distutils.extension import Extension setup(name="myvaarg",ext_modules=[Extension("myvaarg",["sample.cpp "],libraries=["boost_python"])]) $python setup.py build -- Venkat -------------- next part -------------- An HTML attachment was scrubbed... URL: From venkat83 at gmail.com Thu Mar 27 14:12:53 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Thu, 27 Mar 2008 13:12:53 +0000 Subject: [C++-sig] boost::python PyUnicodeUCS4_FromEncodedObject In-Reply-To: References: Message-ID: On Thu, Mar 27, 2008 at 1:10 PM, Venkatraman S wrote: > > *setup.py* > --------------- > from distutils.core import setup > from distutils.extension import Extension > setup(name="myvaarg",ext_modules=[Extension("myvaarg",["*sample.cpp"* > ],libraries=["boost_python"])]) > > This is "myClass.cpp". -- Venkat Mobile : (91)-99529 43249 Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Thu Mar 27 15:58:02 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 27 Mar 2008 10:58:02 -0400 Subject: [C++-sig] boost::python PyUnicodeUCS4_FromEncodedObject In-Reply-To: References: Message-ID: <47EBB5FA.2040209@sympatico.ca> Venkatraman S wrote: > $ldd myClass.so > libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00db8000) > libm.so.6 => /lib/tls/libm.so.6 (0x002b3000) > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00eb7000) > libpthread.so.0 => /lib/tls/libpthread.so.0 (0x0057a000) > libc.so.6 => /lib/tls/libc.so.6 (0x00b6f000) > /lib/ld-linux.so.2 (0x00712000) Why is boost_python not part of the dependencies ? Are you linking to the static version ? > _*setup.py*_ > --------------- > from distutils.core import setup > from distutils.extension import Extension > setup(name="myvaarg",ext_modules=[Extension("myvaarg",["sample.cpp"],libraries=["boost_python"])]) > > $python setup.py build Can you print out the compile and link commands this generates ? I'm using distutils myself, but found its extension handling limited and broken, and so have reimplemented the 'build_ext' command. I wouldn't be surprized if distutils was causing the error you are experiencing. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From matthew.scouten at gmail.com Thu Mar 27 17:12:23 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 27 Mar 2008 11:12:23 -0500 Subject: [C++-sig] A vector of objects with private == operators In-Reply-To: <200803261442.56918.lists@informa.tiker.net> References: <3dc9bcf00803261135h5f4feb80jb980e1497be20f81@mail.gmail.com> <200803261442.56918.lists@informa.tiker.net> Message-ID: <3dc9bcf00803270912w3772b29dq778c92cac4eab1ec@mail.gmail.com> Thank you, This looks like it will fix my problems. However, the PYTHON_ERROR line will not compile because there is apparently no such function. Is this a macro specific to your project? if so, what is behind it? 2008/3/26 Andreas Kl?ckner : > On Mittwoch 26 M?rz 2008, Matthew Scouten wrote: > > I have noticed that the vector indexing suite only compiles for a > > vector if foo has an == operator. Some of the objects that I need > to > > wrap in a library have to wrap have no == operator. That's fine, I just > > create a dummy operator as a global function. The dummy operator just > tests > > &a==&b. > > > > Now I come to a problem. the 'bar' class has a == operator, but it is > > declared private. I tried to create a global == operator but the > compiler > > complained that it was ambiguous (the compiler is such a whiny little > > brat.) > > > > So my questions are 3 fold, > > Why the heck does vector_indexing_suite need an == operator? > > Assuming I can't change the problem class, what are possible > workarounds? > > Does vector_indexing_suite2 still need an == operator? > > This is a hack I've been using: > > 8< -------------------------------------------------------------- > template > class no_compare_indexing_suite : > public boost::python::vector_indexing_suite no_compare_indexing_suite > > { > public: > static bool contains(T &container, typename T::value_type const &key) > { PYTHON_ERROR(NotImplementedError, "containment checking not supported > on > this container"); } > }; > 8< -------------------------------------------------------------- > > Use like so: > > cl.def(no_compare_indexing_suite()) > > Andreas > > _______________________________________________ > 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 Stefan.Borovac at t-online.de Fri Mar 28 10:34:03 2008 From: Stefan.Borovac at t-online.de (Stefan.Borovac at t-online.de) Date: Fri, 28 Mar 2008 10:34:03 +0100 Subject: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem Message-ID: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> An HTML attachment was scrubbed... URL: From Mark.English at rbccm.com Fri Mar 28 11:39:52 2008 From: Mark.English at rbccm.com (English, Mark) Date: Fri, 28 Mar 2008 10:39:52 -0000 Subject: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem In-Reply-To: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> Message-ID: <0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan.Borovac at t-online.de > Sent: 28 March 2008 09:34 > To: c++-sig at python.org > Subject: [C++-sig] ActiveState Python 2.5.1.1,Boost 1.34.1 and MSVC 8 SP1 problem > Everything worked fine using ActiveState Python 2.3.2-232 and ActiveState Python 2.4.3.12. > But after switching to ActiveState Python 2.5.1.1, I can not import the DLL anymore (without > any detailed error message). It simply doesn't work. Have you tried examining the DLL with DependencyWalker ? http://www.dependencywalker.com/ Also sometimes details about failed DLL imports can appear in the EventLog. Were you building previously against Python 2.3 and 2.4 using MSVC 8 ? If not you may now be encountering a a c-runtime conflict although that's just a guess. If that is the problem, try building a Python 2.5 from source with VC 8. This will make your build non-standard though, so then you face issues distributing your DLL. Good luck, Mark _______________________________________________________________________ This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential. Unauthorised use or disclosure is prohibited. If you receive this e-mail in error, please advise immediately and delete the original message without copying, using, or telling anyone about its contents. This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message. This message does not create or change any contract. Royal Bank of Canada and its subsidiaries accept no responsibility for damage caused by any viruses contained in this email or its attachments. Emails may be monitored. RBC Capital Markets is a business name used by branches and subsidiaries of Royal Bank of Canada, including Royal Bank of Canada, London branch and Royal Bank of Canada Europe Limited. In accordance with English law requirements, details regarding Royal Bank of Canada Europe Limited are set out below: ROYAL BANK OF CANADA EUROPE LIMITED Registered in England and Wales 995939 Registered Address: 71 Queen Victoria Street, London, EC4V 4DE. Authorised and regulated by the Financial Service Authority. Member of the London Stock Exchange -------------- next part -------------- An HTML attachment was scrubbed... URL: From Stefan.Borovac at t-online.de Fri Mar 28 12:21:58 2008 From: Stefan.Borovac at t-online.de (Stefan.Borovac at t-online.de) Date: Fri, 28 Mar 2008 12:21:58 +0100 Subject: [C++-sig] =?iso-8859-15?q?ActiveState_Python_2=2E5=2E1=2E1=2C_Boo?= =?iso-8859-15?q?st_1=2E34=2E1_and_MSVC_8_SP1_problem?= In-Reply-To: <0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> <0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> Message-ID: <1JfCek-14PaL20@fwd27.aul.t-online.de> An HTML attachment was scrubbed... URL: From Mark.English at rbccm.com Fri Mar 28 12:27:26 2008 From: Mark.English at rbccm.com (English, Mark) Date: Fri, 28 Mar 2008 11:27:26 -0000 Subject: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem In-Reply-To: <1JfCek-14PaL20@fwd27.aul.t-online.de> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de><0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> <1JfCek-14PaL20@fwd27.aul.t-online.de> Message-ID: <0130AB6AEBCC2045B3F203151123DA651CBB7E@SXLM-101.fg.rbc.com> From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan.Borovac at t-online.de Sent: 28 March 2008 11:22 To: Development of Python/C++ integration Subject: Re: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem >>> import TTBridge Traceback (most recent call last): File "", line 1, in ? ImportError: No module named TTBridge Are you sure your module is on the Python25 PYTHONPATH ? _______________________________________________________________________ This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential. Unauthorised use or disclosure is prohibited. If you receive this e-mail in error, please advise immediately and delete the original message without copying, using, or telling anyone about its contents. This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message. This message does not create or change any contract. Royal Bank of Canada and its subsidiaries accept no responsibility for damage caused by any viruses contained in this email or its attachments. Emails may be monitored. RBC Capital Markets is a business name used by branches and subsidiaries of Royal Bank of Canada, including Royal Bank of Canada, London branch and Royal Bank of Canada Europe Limited. In accordance with English law requirements, details regarding Royal Bank of Canada Europe Limited are set out below: ROYAL BANK OF CANADA EUROPE LIMITED Registered in England and Wales 995939 Registered Address: 71 Queen Victoria Street, London, EC4V 4DE. Authorised and regulated by the Financial Service Authority. Member of the London Stock Exchange -------------- next part -------------- An HTML attachment was scrubbed... URL: From meine at informatik.uni-hamburg.de Fri Mar 28 12:35:23 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 28 Mar 2008 12:35:23 +0100 Subject: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem In-Reply-To: <1JfCek-14PaL20@fwd27.aul.t-online.de> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> <0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> <1JfCek-14PaL20@fwd27.aul.t-online.de> Message-ID: <200803281235.23641.meine@informatik.uni-hamburg.de> Am Freitag, 28. M?rz 2008 12:21:58 schrieb Stefan.Borovac at t-online.de: >
align="left" dir="ltr">
/>
class="539543310-28032008"> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de><0130AB6AEBCC2045B3F203151123DA651CBB7B@SXLM-101.fg.rbc.com> <1JfCek-14PaL20@fwd27.aul.t-online.de> <0130AB6AEBCC2045B3F203151123DA651CBB7E@SXLM-101.fg.rbc.com> Message-ID: <1JfDuc-1z7EcS0@fwd26.aul.t-online.de> > >>> import TTBridge > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named TTBridge > Are you sure your module is on the Python25 PYTHONPATH ? Yes, I tested it also. However, we start considering another approach to this problem. We can use Python 2.4 until we found a workaraound. That is a pity but unavoidable in these conditions (I don't have the time). Cheers Stefan P.S.: Sorry about the HTML junk, hope this message is plain text only! From nat at lindenlab.com Fri Mar 28 16:03:52 2008 From: nat at lindenlab.com (Nat Goodspeed) Date: Fri, 28 Mar 2008 11:03:52 -0400 Subject: [C++-sig] ActiveState Python 2.5.1.1, Boost 1.34.1 and MSVC 8 SP1 problem In-Reply-To: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> References: <1JfAyJ-0taLxI0@fwd35.aul.t-online.de> Message-ID: <47ED08D8.1030007@lindenlab.com> Stefan.Borovac at t-online.de wrote: > I'am currently working on small project which involves > a python programm which calls a C++ DLL using Boost Python. > > Everything worked fine using ActiveState Python 2.3.2-232 and ActiveState Python > 2.4.3.12. > But after switching to ActiveState Python 2.5.1.1, I can not import the DLL > anymore (without > any detailed error message). It simply doesn't work. Try renaming your .dll to .pyd? See this section in the "What's New in Python 2.5" documentation: http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000 "Windows: .dll is no longer supported as a filename extension for extension modules. .pyd is now the only filename extension that will be searched for." From venkat83 at gmail.com Fri Mar 28 17:58:40 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Fri, 28 Mar 2008 22:28:40 +0530 Subject: [C++-sig] boost::python PyUnicodeUCS4_FromEncodedObject In-Reply-To: <47EBB5FA.2040209@sympatico.ca> References: <47EBB5FA.2040209@sympatico.ca> Message-ID: On Thu, Mar 27, 2008 at 2:58 PM, Stefan Seefeld wrote: > Can you print out the compile and link commands this generates ? I'm > using distutils myself, but found its extension handling limited and > broken, and so have reimplemented the 'build_ext' command. I wouldn't be > surprized if distutils was causing the error you are experiencing. > > Well, i compiled Python again with unicode support(UCS4) and it worked. But still, would like to know as to how you reimplemented build_ext - can you share some information. -- Venkat Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Mar 28 18:08:19 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 28 Mar 2008 13:08:19 -0400 Subject: [C++-sig] boost::python PyUnicodeUCS4_FromEncodedObject In-Reply-To: References: <47EBB5FA.2040209@sympatico.ca> Message-ID: <47ED2603.3000600@sympatico.ca> Venkatraman S wrote: > > On Thu, Mar 27, 2008 at 2:58 PM, Stefan Seefeld > wrote: > > Can you print out the compile and link commands this generates ? I'm > using distutils myself, but found its extension handling limited and > broken, and so have reimplemented the 'build_ext' command. I wouldn't be > surprized if distutils was causing the error you are experiencing. > > > Well, i compiled Python again with unicode support(UCS4) and it worked. > But still, would like to know as to how you reimplemented build_ext - > can you share some information. It's brute-force, really: I made it a wrapper around other build systems (GNU make / autotools based, in my case). The result is that I'm dealing with a hybrid system: make/autotools for individual extension modules, and distutils for the overall project (especially the packaging). This seems to be a good compromize between effort and features. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From rschlup at highspeedcrow.ca Fri Mar 28 20:20:57 2008 From: rschlup at highspeedcrow.ca (Rolf Schlup) Date: Fri, 28 Mar 2008 14:20:57 -0500 Subject: [C++-sig] Py++ filter based on return type Message-ID: Hi Roman, I'm trying to bind a relatively complex interface class of an IG control system and it has a lot of methods that return references to member which are classes in themselves. I'm also working on a script that will automatically create a Py++ script from Rational Rose model. I have become a little stuck in creating a Py++ that will create a module class that will build. Hopefully, you'll be able to answer the following questions so that I can get back to it 1) Since there are a whole lot of methods, what is the best way to work with the call policies - especially with the member functions that return references to other classes using & and not pointers 2) Minimize the need for 20 or more include declarations. Including only those files that are absolutely necessary for the class being bound 3) I've been looking for examples for what I'm trying to do, but they are very scarce. I think I'm past the whole hello_world thing. Is there a place on the web that has what I'm looking for? Thank you in advance, Rolf Schlup -------------- next part -------------- An HTML attachment was scrubbed... URL: From srossross at gmail.com Fri Mar 28 22:59:56 2008 From: srossross at gmail.com (Sean Ross-Ross) Date: Fri, 28 Mar 2008 14:59:56 -0700 Subject: [C++-sig] c++ exception handleing Message-ID: <69018DC9-9930-435E-A80D-11D777A6F189@gmail.com> Hi, had coded a c++ algorithm that I have just wrapped with boost, inside the algorithm I have some python callback functions when an error is raised in one of the python callbacks, the c++ code (file and line number) is obviously not included in the stack trace. Is there an elegant way to provide the user with more information of the exception? perhaps insert the c++ file and line number that the python function was called from? ~Sean From seefeld at sympatico.ca Fri Mar 28 23:26:07 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 28 Mar 2008 18:26:07 -0400 Subject: [C++-sig] c++ exception handleing In-Reply-To: <69018DC9-9930-435E-A80D-11D777A6F189@gmail.com> References: <69018DC9-9930-435E-A80D-11D777A6F189@gmail.com> Message-ID: <47ED707F.8060604@sympatico.ca> Sean Ross-Ross wrote: > Hi, had coded a c++ algorithm that I have just wrapped with boost, > inside the algorithm I have some python callback functions > when an error is raised in one of the python callbacks, the c++ code > (file and line number) is obviously not included in the stack trace. > Is there an elegant way to provide the user with more information of > the exception? perhaps insert the c++ file and line number that the > python function was called from? Certainly. However, the respective Python API isn't (yet) nicely wrapped into boost.python, so you'll have to do that manually, i.e. by calling PyErr_SetObject() yourself. The type and value you set there can be anything you like, and so you are free to inject useful information about the location the exception happened in. (Of course, you can't synthesize a call stack reaching into C++ code, though...) HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From venkat83 at gmail.com Sat Mar 29 02:36:10 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Sat, 29 Mar 2008 07:06:10 +0530 Subject: [C++-sig] Python/C PyRun_String Message-ID: Hi All, Am using Pythong/C API for embedding. I have written a small-simple wrapper that does the low level functions and exposes the functionalities in a c++ style(i.,e the application layer doensnt use 'PyObject'). I am reading the contents of a file(Python script) and am running the same using PyRun_String; the script setups some variables in the Main Dict which i access it using the PyArg_Parse...etc etc(the standard way). This keeps running in a loop - i.,e it needs to be processed for every transaction - hence the Python wrapper is a singleton which preserves the main dict. Am stumbling on a problem wherein when i try to access a variable in Python from C as a string - this variable in python was constructed by concatenating a float with a string(using 'str'), and hence the resulting python variable is also a string. If i comment out the variable , then the program runs fine; else it(C program) throws out a segmentation fault. A clueless as to how to debug this and suitable hints would be immense help. (If required , i can share the code for this - i just didnt want to send it here) Secondly, can anyone point me to the Boost::python way of embedding - basically, i would like to know how to build/compile the program without using bjam. Regards, -- Venkat Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Mar 29 07:46:59 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 29 Mar 2008 09:46:59 +0300 Subject: [C++-sig] Py++ filter based on return type In-Reply-To: References: Message-ID: <7465b6170803282346p207dd07dvdf52f1f356c694ea@mail.gmail.com> 2008/3/28 Rolf Schlup : > Hi Roman, Good morning > I'm trying to bind a relatively complex interface class of an IG control > system and it has a lot of methods that return references to member which > are classes in themselves. I'm also working on a script that will > automatically create a Py++ script from Rational Rose model. Coool :-) > I have become > a little stuck in creating a Py++ that will create a module class that will > build. > > Hopefully, you'll be able to answer the following questions so that I can > get back to it > > 1) Since there are a whole lot of methods, what is the best way to > work with the call policies ? especially with the member functions that > return references to other classes using & and not pointers Py++ & call policies documentation: http://language-binding.net/pyplusplus/documentation/functions/call_policies.html type_traits ( similar to Boost.TypeTraits ) functionality: http://www.language-binding.net/pygccxml/apidocs/pygccxml.declarations.type_traits-module.html The usage example for your use case from pygccxml import declarations from pyplusplus.module_builder import call_policies mb = module_builder_t(...) def has_return_internal_reference_policy( f ): if not f.return_type: #constructor or destructor return False r_type = f.return_type if declarations.is_reference(r_type) and declarations.is_class( declarations.remove_reference( r_type ): return True if declarations.is_pointer(r_type) and declarations.is_class( declarations.remove_pointer( r_type ): return True #TODO: add const treatment return False scope = mb.[namespace|class_](....) #select the appropriate scope scope.calldefs( has_return_internal_reference_policy ).call_policies = call_policies.return_internal_reference() > 2) Minimize the need for 20 or more include declarations. Including > only those files that are absolutely necessary for the class being bound What version do you use? I worked hard to minimize the number of included files. Can you create small example? > 3) I've been looking for examples for what I'm trying to do, but they > are very scarce. I think I'm past the whole hello_world thing. Is there a > place on the web that has what I'm looking for? I don't exactly understand what you are trying to do, but here few links that I hope will help you: * few boost libraries wrapped by me: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/examples/pyboost_dev/dev/ * python-ogre - huge repository of modules wrapped with Py++ - http://python-ogre.svn.sourceforge.net/viewvc/python-ogre/trunk/python-ogre/code_generators/ take a look on "common_utils" directory HTH, if not come back and ask more specific question :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rwgk at yahoo.com Sun Mar 30 07:39:53 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 29 Mar 2008 22:39:53 -0700 (PDT) Subject: [C++-sig] c++ exception handleing Message-ID: <850525.65895.qm@web31107.mail.mud.yahoo.com> > (Of course, you can't > synthesize a call stack reaching into C++ code, though...) Actually, under Linux and Mac OS X you can: http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/meta_ext.cpp?view=markup Ralf From rschlup at highspeedcrow.ca Sun Mar 30 16:36:30 2008 From: rschlup at highspeedcrow.ca (Rolf Schlup) Date: Sun, 30 Mar 2008 09:36:30 -0500 Subject: [C++-sig] New to Py++ Message-ID: Hi all, I'm new to Py++ and I need to create bindings for a Visual Simulation control library for the company I work for. The library consists of over 200 classes of which 50 or need to be "exposed" to be usable. I've tried the Py++ GUI, but the C++ code I get from it doesn't compile. There is one main interface class - VSControl - that has methods for returning references to members ( mostly of other classes ). Some of the classes have forward referencing of their dependencies which causes the C++ to completely haywire and I'm thinking it has something to do with how Py++ generates the wrapper code. I'm also having a lot of issues with Call Policies. Mainly, the ones that have with return of reference types are giving me warnings when I generate the C++ code. I've been using the followingcode, but the resulting C++ code only compiles when I manually add the necessary header files to the generated code. But, then when I try to import it, I get unresolved reference errors. If I try to add all necessary files to the builder lines, the warnings and compiler errors increase exponentially. Again, any help or examples that can yield usable binding code will be appreciated. I've included the VSControl header file at the end of this message. Thank you in advance Rolf Schlup **************************************************************************** **************************************************************************** ******************* #!/usr/bin/python import os import sys sys.path.append( '../../../..' ) from pyplusplus import module_builder from pyplusplus.module_builder import call_policies from pygccxml import declarations from pygccxml.declarations import custom_matcher_t as c_matcher from pygccxml.declarations import regex_matcher_t as re_matcher #Creating an instance of class that will help you to expose your declarations mb = module_builder.module_builder_t( files=[ 'VSControl.hpp'] , gccxml_path=r"/usr/local/bin/gccxml" , working_directory=r"/home/rolf/source/ws_stes/BER/cobusiness/test/VisualSyst emTest/VSPython/" , include_paths=['/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCore ' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCommBase' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSException' ,'/home/rolf/source/ws_stes/UNT/real/Types' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCoordConverter' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSEnumAndTypes' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSDefFileReader' ,'/usr/include/python/' ,'/home/rolf/source/ws_stes/BER/real/' ,'/home/rolf/source/ws_stes/BER/real/Global' ,'/home/rolf/source/ws_stes/BER/reglobal' ,'/home/rolf/source/ws_stes/BER/cobusiness/' ,'/home/rolf/source/ws_stes/UNT/real/' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSCommManager' ,'/home/rolf/source/ws_stes/BER/cobusiness/VisualSystem/VSComm' ] , define_symbols=[] ) # The following 2 lines do not have any effect mb.build_code_creator('VSControl') mb.code_creator.add_include( "path.hpp" ) mem_funs = mb.calldefs() mem_funs.create_with_signature = True for mem_fun in mem_funs: if mem_fun.call_policies: continue if not mem_fun.call_policies and (declarations.is_reference(mem_fun.return_type) or declarations.is_pointer (mem_fun.return_type) ): mem_fun.call_policies = call_policies.return_value_policy(call_policies.reference_existing_object ) #Well, don't you want to see what's going on? mb.print_declarations() #Give a name to the module. After this step you should not modify/customize declarations. mb.build_code_creator( module_name='vscontrol' ) #I don't want absolute includes within code mb.code_creator.user_defined_directories.append( os.path.abspath('.') ) #Write code to file. mb.write_module( os.path.join( os.path.abspath('.'),'VSControl_Bindings.cpp' ) ) **************************************************************************** *********************************************************************** #ifndef VSControl_h #define VSControl_h 1 #include "Global/REALGlobal.hpp" #include "VisualSystem/VSCommBase/VSAllPacketDefinitions.hpp" namespace N_VisualSystem { class VSBasePacket; class VSCommManager; class VSConverterBase; class VSMunitionMan; class VSIsectorMan; class VSCreatureMan; class VSSensorMan; class VSCelestial; class VSEntityMan; class VSObjectAllocater; class VSSystem; class VSEffectMan; class VSTerrainMan; class VSHudMan; class VSTextMan; class VSWeatherMan; class VSSightMan; } // namespace N_VisualSystem namespace N_VisualSystem { class VSControl { public: VSControl (); virtual ~VSControl(); virtual bool init (const std::string& a_configFileName, const std::string& a_interfaceName); VSWeatherMan& getWeatherMan (); VSCelestial& getCelestial () const; VSCreatureMan& getCreatureMan () const; VSEffectMan& getEffectMan (); VSEntityMan& getEntityMan () const; VSHudMan& getHudMan (); VSIsectorMan& getIsectorMan () const; VSMunitionMan& getMunitionMan (); VSSensorMan& getSensorMan (); VSSightMan& getSightMan () const; VSSystem& getSystem (); VSTerrainMan& getTerrainMan (); VSTextMan& getTextMan (); virtual bool isUpdateRequested (); void startUpdate (); void endUpdate (); bool getConnectionState () const; void preUpdate (); protected: void createPacketRefList (); void evalIncommingPackets (const std::vector& a_packetList); void handleSystemResponse (const VSSystemPacket& a_systemPacket); void handleCollisionResponse (); void handleTerrainResponse (const VSTerrainResponsePacket& a_terrainPacket); void handleEffectResponse (const VSEffectResponsePacket& a_effectResponsePacket); VSCommManager& getCommManager (); void handleIsectorResponse (const VSBasePacket& a_isectorPacket); bool m_Initialized; std::vector m_PacketRefList; ShVal m_CommManager; private: VSControl(const VSControl &right); VSControl & operator=(const VSControl &right); bool operator==(const VSControl &right) const; bool operator!=(const VSControl &right) const; void installDefaultCoordConverter (); ShVal m_EntityManager; ShVal m_TerrainManager; ShVal m_System; ShVal m_SightManager; ShVal m_WeatherManager; ShVal m_TextManager; ShVal m_HudManager; ShVal m_EffectManager; ShVal m_Celestial; ShVal m_SensorManager; ShVal m_CreatureManager; ShVal m_IsectorManager; ShVal m_MunitionManager; VSConverterBase* m_DefaultConverter; }; } // namespace N_VisualSystem #endif -------------- next part -------------- An HTML attachment was scrubbed... URL: From srossross at gmail.com Sun Mar 30 17:23:21 2008 From: srossross at gmail.com (Sean Ross-Ross) Date: Sun, 30 Mar 2008 08:23:21 -0700 Subject: [C++-sig] c++ exception handleing In-Reply-To: <850525.65895.qm@web31107.mail.mud.yahoo.com> References: <850525.65895.qm@web31107.mail.mud.yahoo.com> Message-ID: <6AC2E71C-E739-4125-AAD7-B965D5374324@gmail.com> This meta_ext.cpp sounds cool. Are there any demos or tutorials on how to use the stack synth? On a second note, when my python callback from c++ raises an exception I get an "Abort trap" after the function exits. This just started recently and I don't know what I changed to make it do that. Does anyone have any idea where to start looking for the problem? Thanks for the help On 29-Mar-08, at 10:39 PM, Ralf W. Grosse-Kunstleve wrote: >> (Of course, you can't >> synthesize a call stack reaching into C++ code, though...) > > Actually, under Linux and Mac OS X you can: > > http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ > meta_ext.cpp?view=markup > > Ralf > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mathem at tician.de Sun Mar 30 19:03:00 2008 From: mathem at tician.de (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Sun, 30 Mar 2008 13:03:00 -0400 Subject: [C++-sig] A vector of objects with private == operators In-Reply-To: <3dc9bcf00803270912w3772b29dq778c92cac4eab1ec@mail.gmail.com> References: <3dc9bcf00803261135h5f4feb80jb980e1497be20f81@mail.gmail.com> <200803261442.56918.lists@informa.tiker.net> <3dc9bcf00803270912w3772b29dq778c92cac4eab1ec@mail.gmail.com> Message-ID: <200803301303.02279.mathem@tician.de> Argh, sorry. My bad. #define PYTHON_ERROR(TYPE, REASON) \ { \ PyErr_SetString(PyExc_##TYPE, REASON); \ throw boost::python::error_already_set(); \ } Andreas On Donnerstag 27 M?rz 2008, Matthew Scouten wrote: > Thank you, > This looks like it will fix my problems. > However, the PYTHON_ERROR line will not compile because there is apparently > no such function. Is this a macro specific to your project? if so, what is > behind it? > > 2008/3/26 Andreas Kl?ckner : > > On Mittwoch 26 M?rz 2008, Matthew Scouten wrote: > > > I have noticed that the vector indexing suite only compiles for a > > > vector if foo has an == operator. Some of the objects that I need > > > > to > > > > > wrap in a library have to wrap have no == operator. That's fine, I just > > > create a dummy operator as a global function. The dummy operator just > > > > tests > > > > > &a==&b. > > > > > > Now I come to a problem. the 'bar' class has a == operator, but it is > > > declared private. I tried to create a global == operator but the > > > > compiler > > > > > complained that it was ambiguous (the compiler is such a whiny little > > > brat.) > > > > > > So my questions are 3 fold, > > > Why the heck does vector_indexing_suite need an == operator? > > > Assuming I can't change the problem class, what are possible > > > > workarounds? > > > > > Does vector_indexing_suite2 still need an == operator? > > > > This is a hack I've been using: > > > > 8< -------------------------------------------------------------- > > template > > class no_compare_indexing_suite : > > public boost::python::vector_indexing_suite > no_compare_indexing_suite > > > { > > public: > > static bool contains(T &container, typename T::value_type const &key) > > { PYTHON_ERROR(NotImplementedError, "containment checking not > > supported on > > this container"); } > > }; > > 8< -------------------------------------------------------------- > > > > Use like so: > > > > cl.def(no_compare_indexing_suite()) > > > > Andreas > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig -- Andreas Kloeckner ^ mathem at tician.de 114 Camp Street Apt 2 | http://mathema.tician.de Providence, RI 02906 | cell: (401) 497-9385 Applied Mathematics, Brown | home: (401) 648-0599 ---------------------------+------------------------------------> AIM/ICQ: inducer77 | XMPP/GoogleTalk: inducer at amessage.de -------------- 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 roman.yakovenko at gmail.com Sun Mar 30 19:13:47 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 30 Mar 2008 20:13:47 +0300 Subject: [C++-sig] New to Py++ In-Reply-To: References: Message-ID: <7465b6170803301013q6d3f3a99v5cb57e55f0a7924c@mail.gmail.com> 2008/3/30 Rolf Schlup : > Hi all, Good evening > I'm new to Py++ and I need to create bindings for a Visual Simulation > control library for the company I work for. The library consists of over > 200 classes of which 50 or need to be "exposed" to be usable. I've tried > the Py++ GUI, but the C++ code I get from it doesn't compile. Py++ GUI was created to suite single goal: to show what code generates Py++, without customization. You can use it almost as-is in small projects or when you just start with Boost.Python. > There is one > main interface class ? VSControl - that has methods for returning > references to members ( mostly of other classes ). Some of the classes have > forward referencing of their dependencies which causes the C++ to completely > haywire and I'm thinking it has something to do with how Py++ generates the > wrapper code. Well, you can expose forward declarated classes as opaque type. I think that Py++ doesn't support thi use case. Normally what you want is to expose that classes too. In order to do this, you need to create header file, that will include all relevant files and than to path is to Py++ > I'm also having a lot of issues with Call Policies. Mainly, > the ones that have with return of reference types are giving me warnings > when I generate the C++ code. I've been using the followingcode, but the > resulting C++ code only compiles when I manually add the necessary header > files to the generated code. I guess this errors relaed to forward declarations. Try to pass single header file, built as described above. > But, then when I try to import it, I get > unresolved reference errors. I think this error is related to your environment. Use "dependency viewer" to verify that your dll can load others. >If I try to add all necessary files to the > builder lines, the warnings and compiler errors increase exponentially. > Again, any help or examples that can yield usable binding code will be > appreciated. I need more specific error description. From my experience it is better to start from something small, just few classes. To get to the point you can import and use few simple exported classes and than start to add other classes and functions. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/