From adruab at hotmail.com Mon Mar 1 02:02:53 2004 From: adruab at hotmail.com (Adrian Bentley) Date: Sun, 29 Feb 2004 17:02:53 -0800 Subject: [C++-sig] Boost... Exception safe (can I turn it off?), and controlled object construction? Message-ID: Hi, I'd like to turn off the exception forwarding feature of boost python (trying to adapt for use in high performance where exceptions are not desired). What I'd really like to do is be able to handle the exception classically, by giving it a function to call or the like. I've read through some of the documentation and haven't found anything like this. Any pointers would be welcome. Also, I'm trying to use the language in kind of a weird way. It's probably a bad idea but I'm running with it anyway :)... I'm trying to embed python as a scripting language for my object system thing (game engine framework), and I'd like to be able to extend objects using python (extend embed at the same time! :P). Example of something like what I'm trying to do: //In pyobject file class BaseObject { void *data; //where the variables will all go //All it's stuff in here, some which requires manual construction and such }; Pythonclass : BaseObject { //add stuff here } //in actual program class Py_wrapper : public BaseObject { PyObject *pyo; //gotten from embedded python //forward variable requests to python object etc.... }; // End example Ok, now that you all know I'm crazy the reason why I want to do this is that the base object is designed to communicate a certain way with things it's attached to, which probably wouldn't cooperate with the way python works, so I need to manually construct the base object (also not sure how to do this in boost python). Basically what I'd like is to have python override things like a class normally would, and track it in my object system. I'm kind of doubting there's a way to do that, hence then extra layer of indirection py_wrapper (which should work). So yeah, if anyone has any ideas I'd really appreciate it. Feel free to enlighten me to a better method of interoperation (I'm kinda new to multi language stuff). Any help is appreciated, thanks, Adruab > Adrian Bentley -------------- next part -------------- An HTML attachment was scrubbed... URL: From ingo at fargonauten.de Mon Mar 1 10:08:19 2004 From: ingo at fargonauten.de (Ingo Luetkebohle) Date: Mon, 01 Mar 2004 10:08:19 +0100 Subject: [C++-sig] embedding examples Message-ID: <1078132099.32100.6.camel@localhost> Hi, I have trouble compiling the 'Using the interpreter' examples from the tutorial. Code like this: handle<> main_module(borrowed( PyImport_AddModule("__main__") )); dict main_namespace(handle<>(borrowed( PyModule_GetDict(main_module.get()) ))); results in error: variable declaration is not allowed here using gcc 3.2 and gcc 3.3 on Linux. When I use handle<> main_module(borrowed( PyImport_AddModule("__main__") )); handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) )); dict main_namespace(main_nsh); it compiles and the resulting dict is usable. So, this is not a showstopper but it doesn't work as documented and results in longer code. Is there anything I can do to get the intended behaviour? regards -- Ingo Soll doch jeder bleiben, wie er gerne w?re. From darylew at hotmail.com Mon Mar 1 10:26:43 2004 From: darylew at hotmail.com (Daryle Walker) Date: Mon, 01 Mar 2004 04:26:43 -0500 Subject: [C++-sig] Software development levels In-Reply-To: Message-ID: On 2/29/04 1:01 PM, "David Abrahams" wrote: > Daryle Walker writes: [SNIP] >> If it's missing features, I would consider it alpha-level software. Recall >> that the alpha/beta/final scale relates to feature completeness, NOT code >> quality! > > I don't "recall that", and it seems to contradict what you say > below... I'm sorry, I forgot that the alpha/beta/final scale isn't formally taught in general. >> The two usually go hand in hand, but not always. (There are >> programs that are awesome even in the alpha stage, and craptacular final >> stage programs. The latter leads to accusations of "rushing the SW out the >> door and forcing the beta-testing on [paying] users".) > > If it's all about features and not quality, what do the terms "alpha > testing" and "beta testing" mean? Alpha stage--not feature complete Beta stage--feature complete, but may have some bugs Alpha testing--checking if the features that are there work Beta testing--shaking out all the bugs -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com From pierre.barbier at cirad.fr Mon Mar 1 10:56:48 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 10:56:48 +0100 Subject: [C++-sig] Pickling problem Message-ID: <1078135007.742.6.camel@pbarbier> Hi ! I have a problem with pickling a proxy class. I join the C++ code as an attached file. I have three classes : - Base : an abstract class - Derived : a subclass of Base - Proxy : the proxy class that contains an instance of Base Derived objects can be pickled and the pickling of Proxy just return a tuple with a Base object in it. Here is a python sample : >>> import test_abstract >>> p = test_abstract.Proxy(test_abstract.Derived(10)) >>> import cPickle >>> cPickle.dumps(p.getBase()) 'ctest_abstract\nDerived\np1\n(I10\ntRp2\n.' >>> cPickle.dumps(p) Traceback (most recent call last): File "", line 1, in ? cPickle.PicklingError: Can't pickle : import of module Boost.Python failed I really don't know what to do ! Thanks, Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 -------------- next part -------------- A non-text attachment was scrubbed... Name: test_abstract.cc Type: text/x-c++ Size: 3972 bytes Desc: not available URL: From pierre.barbier at cirad.fr Mon Mar 1 11:42:59 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 11:42:59 +0100 Subject: [C++-sig] Pickling problem In-Reply-To: <1078135007.742.6.camel@pbarbier> References: <1078135007.742.6.camel@pbarbier> Message-ID: <1078137779.693.13.camel@pbarbier> I think I've found the problem (or at least part of it). The method getBase() of the class Proxy returns a Base pointer. When called from python, boost detect the dynamic type of the object (here Derived) and returns the real object. But, when I create a boost::python::object from C++ this resolution is not done and the object is known as a Base one. So, when pickling, it tries to pickle a Base object (which cannot be pickled). Is there a way to force the detection of the dynamic type when creating a boost::python::object ? I would like to have this behaviour : C++ code: boost::python::object get_base(Proxy& p) { return boost::python::object(p.getBase()); } BOOST_PYTHON_MODULE(test_abstract) { ... def("get_base", get_base); ... } Python: >>> from test_abstract import * >>> p = Proxy(Derived(10)) >>> get_base(p) Derived(10) But for now I have : >>> from test_abstract import * >>> p = Proxy(Derived(10)) >>> get_base(p) How can I have the first behaviour ? Pierre On Mon, 2004-03-01 at 10:56, Pierre Barbier de Reuille wrote: > Hi ! > > I have a problem with pickling a proxy class. I join the C++ code as an > attached file. > > I have three classes : > - Base : an abstract class > - Derived : a subclass of Base > - Proxy : the proxy class that contains an instance of Base > > Derived objects can be pickled and the pickling of Proxy just return a > tuple with a Base object in it. Here is a python sample : > > > >>> import test_abstract > >>> p = test_abstract.Proxy(test_abstract.Derived(10)) > >>> import cPickle > >>> cPickle.dumps(p.getBase()) > 'ctest_abstract\nDerived\np1\n(I10\ntRp2\n.' > >>> cPickle.dumps(p) > Traceback (most recent call last): > File "", line 1, in ? > cPickle.PicklingError: Can't pickle : > import of module Boost.Python failed > > I really don't know what to do ! > > Thanks, > > Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From steam at nurfuerspam.de Mon Mar 1 12:30:34 2004 From: steam at nurfuerspam.de (Hanz Meizer) Date: Mon, 01 Mar 2004 12:30:34 +0100 Subject: [C++-sig] Defining and adding functions in pyste. Message-ID: Hi, I've got a working boost file and want to integrate my changes into the pyste file that created it. The problem: I've defined functions inside of the boost file and added those functions as member functions of a class like that: namespace { std::string foobar() { } } // Module ====================================================================== void Export_Test() { class_< Test >("Test") .def("foobar", &foobar) ... I added the declaration of foobar to the pyste file using declaration_code(""" namespace { std::string foobar() { } } """) This is working and showing in the output as expected. Unfortunately, using add_method gives me bad results because pyste doesn't know about the foobar function. ow do I have to setup my pyste file that it generates the same layout as my boost file? H. From dave at boost-consulting.com Mon Mar 1 14:09:32 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 08:09:32 -0500 Subject: [C++-sig] Re: Boost... Exception safe (can I turn it off?), and controlled object construction? References: Message-ID: "Adrian Bentley" writes: > Hi, > > I'd like to turn off the exception forwarding feature Not sure which one you're referring to here, but... > of boost python (trying to adapt for use in high performance where > exceptions are not desired). Even if you could turn off the feature, I doubt you'd notice any measurable difference in performance because the Python interpreter is so much slower than C++. Any performance loss due to the try/catch block at the boundary between the two languages will almost surely be swamped by the cost of executing code in the Python interpreter. > What I'd really like to do is be able to handle the exception > classically, by giving it a function to call or the like. I've read > through some of the documentation and haven't found anything like > this. Any pointers would be welcome. There's nothing of that kind. Boost.Python uses the C++ standard library, and the C++ standard library throws exceptions, so trying to avoid them would be fruitless. > Also, I'm trying to use the language in kind of a weird way. It's > probably a bad idea but I'm running with it anyway :)... I'm trying > to embed python as a scripting language for my object system thing > (game engine framework), and I'd like to be able to extend objects > using python (extend embed at the same time! :P). That's pretty typical, actually. > Example of something like what I'm trying to do: > > //In pyobject file class BaseObject { void *data; //where the > variables will all go //All it's stuff in here, some which requires > manual construction and such > }; > > Pythonclass : BaseObject { //add stuff here > } > > //in actual program class Py_wrapper : public BaseObject { PyObject > *pyo; //gotten from embedded python > > //forward variable requests to python object etc.... > }; > > // End example That doesn't illustrate very much, but I don't know why anyone would use PyObject* when they could use boost::python::object. > Ok, now that you all know I'm crazy the reason why I want to do this > is that the base object is designed to communicate a certain way with > things it's attached to, which probably wouldn't cooperate with the > way python works Maybe you should find out for sure before deciding. > , so I need to manually construct the base object (also not sure how > to do this in boost python). I've no clue what you're asking about, sorry. > Basically what I'd like is to have python override things like a class > normally would, and track it in my object system. I'm kind of > doubting there's a way to do that, hence then extra layer of > indirection py_wrapper (which should work). http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html http://www.boost.org/libs/python/doc/tutorial/doc/deriving_a_python_class.html -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Mar 1 14:15:00 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 08:15:00 -0500 Subject: [C++-sig] Re: embedding examples References: <1078132099.32100.6.camel@localhost> Message-ID: Ingo Luetkebohle writes: > Hi, > > I have trouble compiling the 'Using the interpreter' examples from the > tutorial. > > Code like this: > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); > dict main_namespace(handle<>(borrowed( > PyModule_GetDict(main_module.get()) ))); > results in > error: variable declaration is not allowed here > > using gcc 3.2 and gcc 3.3 on Linux. > > When I use > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); > handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) )); > dict main_namespace(main_nsh); > > it compiles and the resulting dict is usable. > > So, this is not a showstopper but it doesn't work as documented and > results in longer code. Is there anything I can do to get the intended > behaviour? [joel, can you fix this?] I think this will work. Please let us know if it doesn't: // Retrieve the main module object main_module = python::extract( PyImport_AddModule("__main__") ); // Retrieve the main module's namespace dict main_namespace( extract(main_module.attr("__dict__")) ); -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Mar 1 14:16:21 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 08:16:21 -0500 Subject: [C++-sig] Re: Software development levels References: Message-ID: Daryle Walker writes: > On 2/29/04 1:01 PM, "David Abrahams" wrote: > >> Daryle Walker writes: > [SNIP] >>> If it's missing features, I would consider it alpha-level software. Recall >>> that the alpha/beta/final scale relates to feature completeness, NOT code >>> quality! >> >> I don't "recall that", and it seems to contradict what you say >> below... > > I'm sorry, I forgot that the alpha/beta/final scale isn't formally taught in > general. > >>> The two usually go hand in hand, but not always. (There are >>> programs that are awesome even in the alpha stage, and craptacular final >>> stage programs. The latter leads to accusations of "rushing the SW out the >>> door and forcing the beta-testing on [paying] users".) >> >> If it's all about features and not quality, what do the terms "alpha >> testing" and "beta testing" mean? > > Alpha stage--not feature complete > Beta stage--feature complete, but may have some bugs > > Alpha testing--checking if the features that are there work > Beta testing--shaking out all the bugs Just to clarify, the module is "missing a few features" *that people might want*, but it's not missing any features that it was originally designed to provide. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Mar 1 14:28:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 08:28:26 -0500 Subject: [C++-sig] Re: Pickling problem References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > I think I've found the problem (or at least part of it). > > The method getBase() of the class Proxy returns a Base pointer. When > called from python, boost detect the dynamic type of the object (here > Derived) and returns the real object. But, when I create a > boost::python::object from C++ this resolution is not done and the > object is known as a Base one. So, when pickling, it tries to pickle a > Base object (which cannot be pickled). Is there a way to force the > detection of the dynamic type when creating a boost::python::object ? > > I would like to have this behaviour : > > C++ code: > > boost::python::object get_base(Proxy& p) > { > return boost::python::object(p.getBase()); > } > > BOOST_PYTHON_MODULE(test_abstract) > { > ... > def("get_base", get_base); > ... > } Perhaps: BOOST_PYTHON_MODULE(test_abstract) { ... def("get_base", &Proxy::getBase, return_internal_reference<>()); ... } ?? -- Dave Abrahams Boost Consulting www.boost-consulting.com From joel at boost-consulting.com Mon Mar 1 14:34:47 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Mon, 01 Mar 2004 21:34:47 +0800 Subject: [C++-sig] Re: embedding examples In-Reply-To: References: <1078132099.32100.6.camel@localhost> Message-ID: <40433BF7.5030806@boost-consulting.com> David Abrahams wrote: > Ingo Luetkebohle writes: > > >>Hi, >> >>I have trouble compiling the 'Using the interpreter' examples from the >>tutorial. >> >>Code like this: >> handle<> main_module(borrowed( PyImport_AddModule("__main__") )); >> dict main_namespace(handle<>(borrowed( >>PyModule_GetDict(main_module.get()) ))); >>results in >> error: variable declaration is not allowed here >> >>using gcc 3.2 and gcc 3.3 on Linux. >> >>When I use >> handle<> main_module(borrowed( PyImport_AddModule("__main__") )); >> handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) )); >> dict main_namespace(main_nsh); >> >>it compiles and the resulting dict is usable. >> >>So, this is not a showstopper but it doesn't work as documented and >>results in longer code. Is there anything I can do to get the intended >>behaviour? > > > [joel, can you fix this?] > > I think this will work. Please let us know if it doesn't: > > // Retrieve the main module > object main_module = python::extract( > PyImport_AddModule("__main__") > ); > > // Retrieve the main module's namespace > dict main_namespace( > extract(main_module.attr("__dict__")) > ); I think Dirk Gerrits is the authority here. He's the author of that part of the tutorial. Dirk? -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From pierre.barbier at cirad.fr Mon Mar 1 15:04:31 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 15:04:31 +0100 Subject: [C++-sig] Pickling problem In-Reply-To: <1078137779.693.13.camel@pbarbier> References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> Message-ID: <1078149112.693.18.camel@pbarbier> Ok, I've found the solution of my problem. If I create a function with this implementation : PyObject* test_base( Proxy& p ) { return reference_existing_object::apply::type()( p.getBase() ); } The PyObject* will have the correct type (ie. not Base* but the dynamic type of the result). Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Mon Mar 1 15:28:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 09:28:42 -0500 Subject: [C++-sig] Re: Pickling problem References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > Ok, I've found the solution of my problem. > If I create a function with this implementation : > > PyObject* test_base( Proxy& p ) > { > return reference_existing_object::apply::type()( p.getBase() ); > } > > The PyObject* will have the correct type (ie. not Base* but the dynamic > type of the result). The solution I posted is cleaner and won't leave you with dangling references. -- Dave Abrahams Boost Consulting www.boost-consulting.com From pierre.barbier at cirad.fr Mon Mar 1 15:37:28 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 15:37:28 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> Message-ID: <1078151848.742.24.camel@pbarbier> I didn't receive any other answer ! Did you post it for another question ? If not, can you repost it ? By the way, I have another problem : In my class Base I define a virtual method 'operator=='. In the wrapper, if I follow the tutorial I write : class BaseWrap : public Base { ... virtual bool operator==(const Base& other) const { return call_method(self, "__eq__", other); } ... } But doing that, "other" is view as an 'other' class when it will surely be a Python class. I tried to write the method like this : class BaseWrap : public Base { ... virtual bool operator==(const Base& other) const { const BaseWrap* bw = dynamic_cast( &other ); PyObject* real_other = converter( &other ); object obj; if( bw != NULL ) { real_other = bw->self; obj = object(handle<>(borrowed(real_other))); } else { real_other = converter( &other ); obj = object(handle<>(real_other)); } return call_method(self, "__eq__", obj); } ... } But it crashes in python when I try to access the argument. I'm sure I'm missing something, but I can't see what ! Thanks, Pierre On Mon, 2004-03-01 at 15:28, David Abrahams wrote: > Pierre Barbier de Reuille writes: > > > Ok, I've found the solution of my problem. > > If I create a function with this implementation : > > > > PyObject* test_base( Proxy& p ) > > { > > return reference_existing_object::apply::type()( p.getBase() ); > > } > > > > The PyObject* will have the correct type (ie. not Base* but the dynamic > > type of the result). > > The solution I posted is cleaner and won't leave you with dangling > references. -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From ingo at fargonauten.de Mon Mar 1 16:11:38 2004 From: ingo at fargonauten.de (Ingo Luetkebohle) Date: Mon, 01 Mar 2004 16:11:38 +0100 Subject: [C++-sig] Re: embedding examples In-Reply-To: References: <1078132099.32100.6.camel@localhost> Message-ID: <1078153896.13885.15.camel@localhost> Hello David, thanks for the hints. There was a slight run-time problem with the code, which I solved as explained below. I hope my "fix" doesn't have any side-effects. Am Mo, den 01.03.2004 schrieb David Abrahams um 14:15: > // Retrieve the main module's namespace > dict main_namespace( > extract(main_module.attr("__dict__")) > ); If I use that verbatim, an exception is thrown and PyErr_Print() prints TypeError: No to_python (by-value) converter found for C++ type: N5boost6python7extractINS0_4dictEEE I'm assuming that is because 'attr' returns an object_attribute, not a PyObject* and for extract to work, some behind-the-scenes conversion creates the above error. Correct? Luckily dict main_namespace(main_module.attr("__dict__")); works fine and seems simpler, too. regards, -- Ingo Soll doch jeder bleiben, wie er gerne w?re. From pierre.barbier at cirad.fr Mon Mar 1 16:09:06 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 16:09:06 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: <1078151848.742.24.camel@pbarbier> References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> Message-ID: <1078153746.693.28.camel@pbarbier> Just the python part to reproduce my problem : from test_abstract import * class TestDerived(Base): def __init__(self, a): Base.__init__(self) self.a = a def __eq__(self, other): print "TestDerived.__eq__" print "with %s and %s" % (self, other) if isinstance(other, TestDerived): return self.a == other.a return False def __neq__(self, other): print "TestDerived.__neq__" print "with %s and %s" % (self, other) if isinstance(other, TestDerived): return self.a != other.a return True def getCopy(self): return TestDerived(self.a) def __hash__(self): return hash(self.a) t1 = TestDerived(10) p1 = Proxy(t1) p2 = Proxy(TestDerived(10)) p3 = Proxy(TestDerived(11)) print p1 == p1 # This is ok print p1 == p2 # Crash here print p1 == p3 # And there Thanks, Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Mon Mar 1 16:38:46 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 10:38:46 -0500 Subject: [C++-sig] Re: Pickling problem References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > I didn't receive any other answer ! Did you post it for another question > ? If not, can you repost it ? http://article.gmane.org/gmane.comp.python.c%2B%2B/5973 It's untested, but if it works, it's much better. -- Dave Abrahams Boost Consulting www.boost-consulting.com From pierre.barbier at cirad.fr Mon Mar 1 16:38:43 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 16:38:43 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> Message-ID: <1078155522.693.30.camel@pbarbier> This does not work because return_internal_reference<> requires a pointer or reference. However, I think that : PyObject* test_base( Proxy& p ) { return return_internal_reference<1>::result_converter::apply::type()( p.getBase() ); } gives the same result that you suggested. On Mon, 2004-03-01 at 16:38, David Abrahams wrote: > Pierre Barbier de Reuille writes: > > > I didn't receive any other answer ! Did you post it for another question > > ? If not, can you repost it ? > > http://article.gmane.org/gmane.comp.python.c%2B%2B/5973 > > It's untested, but if it works, it's much better. -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Mon Mar 1 16:40:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 10:40:42 -0500 Subject: [C++-sig] Re: Pickling problem References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > By the way, I have another problem : > > In my class Base I define a virtual method 'operator=='. In the wrapper, > if I follow the tutorial I write : > You didn't post a definition for "converter". Please post a complete reproducible test case. -- Dave Abrahams Boost Consulting www.boost-consulting.com From pierre.barbier at cirad.fr Mon Mar 1 16:45:44 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 16:45:44 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> Message-ID: <1078155944.742.35.camel@pbarbier> oops ... sorry ... I send as attachement the complete file. For the Python test case, here it is : from test_abstract import * class TestDerived(Base): def __init__(self, a): Base.__init__(self) self.a = a def __eq__(self, other): print "TestDerived.__eq__" print "with %s and %s" % (self, other) if isinstance(other, TestDerived): return self.a == other.a return False def __neq__(self, other): print "TestDerived.__neq__" print "with %s and %s" % (self, other) if isinstance(other, TestDerived): return self.a != other.a return True def getCopy(self): return TestDerived(self.a) def __hash__(self): return hash(self.a) t1 = TestDerived(10) p1 = Proxy(t1) p2 = Proxy(TestDerived(10)) p3 = Proxy(TestDerived(11)) print p1 == p1 # works print p1 == p2 # crash print p1 == p3 # crash On Mon, 2004-03-01 at 16:40, David Abrahams wrote: > Pierre Barbier de Reuille writes: > > > By the way, I have another problem : > > > > In my class Base I define a virtual method 'operator=='. In the wrapper, > > if I follow the tutorial I write : > > > > > You didn't post a definition for "converter". Please post a complete > reproducible test case. -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 -------------- next part -------------- A non-text attachment was scrubbed... Name: test_abstract.cc Type: text/x-c++ Size: 5666 bytes Desc: not available URL: From pierre.barbier at cirad.fr Mon Mar 1 16:59:49 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 16:59:49 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: <1078155944.742.35.camel@pbarbier> References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> <1078155944.742.35.camel@pbarbier> Message-ID: <1078156789.693.40.camel@pbarbier> Ok, the problem seems to be with the ownership of the class derived from Base. It seems I did not understand well how to transfer the ownership from Python to C++. The use of auto_ptr does not seems to be enough as soon as I derive the class in Python. Is there a way to completly transfer the ownership of the object (even the python part of it) to the C++ program ? -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Mon Mar 1 17:02:48 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Mar 2004 11:02:48 -0500 Subject: [C++-sig] Re: Pickling problem References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> <1078155522.693.30.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > This does not work because return_internal_reference<> requires a > pointer or reference. Yeah... but if getBase doesn't return a pointer or reference, then it returns by value. And if it returns by value, the static type of the returned object is the same as its dynamic type, so I don't see how you expect to end up with a Derived object. > However, I think that : > > PyObject* test_base( Proxy& p ) > { > return > return_internal_reference<1>::result_converter::apply::type()( > p.getBase() ); > } > > gives the same result that you suggested. Not really. That gives the same result you were getting before with reference_existing_object. -- Dave Abrahams Boost Consulting www.boost-consulting.com From pierre.barbier at cirad.fr Mon Mar 1 17:17:02 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 17:17:02 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: <1078156789.693.40.camel@pbarbier> References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> <1078155944.742.35.camel@pbarbier> <1078156789.693.40.camel@pbarbier> Message-ID: <1078157821.693.48.camel@pbarbier> I tried to modify my class constructors / destructor like that : struct BaseWrap : public Base { ... BaseWrap( PyObject* self_ ) : self( self_ ) { Py_INCREF( self ); } BaseWrap( PyObject* self_, const Base& copy ) : Base( copy ), self( self_ ) { Py_INCREF( self ); } virtual ~BaseWrap() { Py_DECREF( self ); } ... } And now it seems to work. Is there a problem with that ? Pierre On Mon, 2004-03-01 at 16:59, Pierre Barbier de Reuille wrote: > Ok, the problem seems to be with the ownership of the class derived from > Base. It seems I did not understand well how to transfer the ownership > from Python to C++. > > The use of auto_ptr does not seems to be enough as soon as I derive the > class in Python. Is there a way to completly transfer the ownership of > the object (even the python part of it) to the C++ program ? -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From pierre.barbier at cirad.fr Mon Mar 1 17:07:04 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 01 Mar 2004 17:07:04 +0100 Subject: [C++-sig] Re: Pickling problem In-Reply-To: References: <1078135007.742.6.camel@pbarbier> <1078137779.693.13.camel@pbarbier> <1078149112.693.18.camel@pbarbier> <1078151848.742.24.camel@pbarbier> <1078155522.693.30.camel@pbarbier> Message-ID: <1078157224.693.43.camel@pbarbier> On Mon, 2004-03-01 at 17:02, David Abrahams wrote: > Pierre Barbier de Reuille writes: > > > This does not work because return_internal_reference<> requires a > > pointer or reference. > > Yeah... but if getBase doesn't return a pointer or reference, then it > returns by value. And if it returns by value, the static type of the > returned object is the same as its dynamic type, so I don't see how > you expect to end up with a Derived object. No, what I meant is that I cannot use return_internal_reference with a boost::python::object as a result. Nor can I use it with a PyObject* ! I know I can directly send a Base* object, but the goal of this function is to test the creation of a boost::python::object from C++. > > > However, I think that : > > > > PyObject* test_base( Proxy& p ) > > { > > return > > return_internal_reference<1>::result_converter::apply::type()( > > p.getBase() ); > > } > > > > gives the same result that you suggested. > > Not really. That gives the same result you were getting before with > reference_existing_object. Arg ... so I don't know what to do :( -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dirk at gerrits.homeip.net Mon Mar 1 23:32:15 2004 From: dirk at gerrits.homeip.net (Dirk Gerrits) Date: Mon, 01 Mar 2004 23:32:15 +0100 Subject: [C++-sig] Re: embedding examples In-Reply-To: <40433BF7.5030806@boost-consulting.com> References: <1078132099.32100.6.camel@localhost> <40433BF7.5030806@boost-consulting.com> Message-ID: Joel de Guzman wrote: >> Ingo Luetkebohle writes: >> >> >>> Hi, >>> >>> I have trouble compiling the 'Using the interpreter' examples from the >>> tutorial. [snip] > I think Dirk Gerrits is the authority here. He's the author of that > part of the tutorial. Dirk? Well the (sad?) truth is that I haven't used Python or Boost.Python for quite a while (several months). Also, my views on embedding versus extending have changed. Issues with the embedding tutorial code have come up before, and IIRC Dave was able to provide fixes. Dave, Joel, other BPL contributors, you have my permission to change the embedding tutorial. If you can't manage it, just let me know and I'll see what I can do, but I think it would be best for Boost.Python if some one else took care of the embedding tutorial from now on. Kind regards, Dirk Gerrits From joel at boost-consulting.com Tue Mar 2 14:06:53 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Tue, 02 Mar 2004 21:06:53 +0800 Subject: [C++-sig] Re: embedding examples In-Reply-To: References: <1078132099.32100.6.camel@localhost> <40433BF7.5030806@boost-consulting.com> Message-ID: <404486ED.3050205@boost-consulting.com> Dirk Gerrits wrote: > Joel de Guzman wrote: > >> I think Dirk Gerrits is the authority here. He's the author of that >> part of the tutorial. Dirk? > > > Well the (sad?) truth is that I haven't used Python or Boost.Python for > quite a while (several months). Also, my views on embedding versus > extending have changed. > > Issues with the embedding tutorial code have come up before, and IIRC > Dave was able to provide fixes. Dave, Joel, other BPL contributors, you > have my permission to change the embedding tutorial. If you can't manage > it, just let me know and I'll see what I can do, but I think it would be > best for Boost.Python if some one else took care of the embedding > tutorial from now on. Ok, I'll take care of it then. -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From dave at boost-consulting.com Tue Mar 2 15:50:09 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 02 Mar 2004 09:50:09 -0500 Subject: [C++-sig] Re: embedding examples References: <1078132099.32100.6.camel@localhost> <40433BF7.5030806@boost-consulting.com> <404486ED.3050205@boost-consulting.com> Message-ID: Joel de Guzman writes: > Dirk Gerrits wrote: > >> Joel de Guzman wrote: >> >>> I think Dirk Gerrits is the authority here. He's the author of that >>> part of the tutorial. Dirk? >> Well the (sad?) truth is that I haven't used Python or Boost.Python >> for >> quite a while (several months). Also, my views on embedding versus >> extending have changed. >> Issues with the embedding tutorial code have come up before, and >> IIRC >> Dave was able to provide fixes. Dave, Joel, other BPL contributors, you >> have my permission to change the embedding tutorial. If you can't manage >> it, just let me know and I'll see what I can do, but I think it would be >> best for Boost.Python if some one else took care of the embedding >> tutorial from now on. > > Ok, I'll take care of it then. Thanks, Joel! -- Dave Abrahams Boost Consulting www.boost-consulting.com From ingo at fargonauten.de Tue Mar 2 17:03:00 2004 From: ingo at fargonauten.de (Ingo Luetkebohle) Date: Tue, 02 Mar 2004 17:03:00 +0100 Subject: [C++-sig] Re: embedding examples In-Reply-To: References: <1078132099.32100.6.camel@localhost> Message-ID: <1078243379.816.5.camel@localhost> Am Mo, den 01.03.2004 schrieb David Abrahams um 14:15: > // Retrieve the main module > object main_module = python::extract( > PyImport_AddModule("__main__") > ); One word of caution: extract does not seem to check for NULL pointers. PyImport_AddModule never returns NULL, but other functions do. E.g., I was using PyImport_ImportModule and when it can't find the module, it returns NULL. To work around that, I use handle<> on the very first call like that, then initialize an object and stick with Boost.Python calls afterwards. Thanks again for the help :) -- Ingo Soll doch jeder bleiben, wie er gerne w?re. From sirbender at freenet.de Tue Mar 2 19:30:06 2004 From: sirbender at freenet.de (Billy Gnosis) Date: Tue, 02 Mar 2004 19:30:06 +0100 Subject: [C++-sig] Could anyone send me an example code for C++/Python Interfacing ??? Message-ID: <4044D2AE.5090500@freenet.de> Hi... I am writing plugins for an already existing application. An API is supplied in C++ to "interact" with the necessary parts of the application. I have written a Pthon programm that does some text parsing tasks and returns a some lists and an Nnumeric array as the desired result. Now I would like to _call _this Python program from within my C++ plugin _with a single argument:_ _a filename_. The Python program now should do the Text processing trick and_ return the lists (could convert to Numeric arrays before, if it helps) and arrays to the C++ programm_. (optimally this should happen without the user knowing that python is working partially in the background - no Dos Box opening etc.). I have underlined the parts of the process in the text above I don't know how to do...I hope there is a simpler solution than using a neat interfacing support like SWIG etc... Now, I want to ask somebody if he perhaps has a little SIMPLE example code in C++ and Python where something similar is done. I would appreciate some example files very much, as I could then directly test out what's going on. Surely I am also very happy with any other counsel... Thanks, billy From sirbender at freenet.de Tue Mar 2 21:17:24 2004 From: sirbender at freenet.de (Billy Gnosis) Date: Tue, 02 Mar 2004 21:17:24 +0100 Subject: [C++-sig] Could anyone send me an example code for C++/Python Interfacing ??? In-Reply-To: <4044D2AE.5090500@freenet.de> References: <4044D2AE.5090500@freenet.de> Message-ID: <4044EBD4.4060003@freenet.de> Billy Gnosis wrote: > Hi... > > > I am writing plugins for an already existing application. An API is > supplied in C++ to "interact" with the necessary parts of the > application. > > I have written a Pthon programm that does some text parsing tasks and > returns a some lists and an Nnumeric array as the desired result. > > Now I would like to /*_call _this Python program from within my C++ > plugin _with a single argument:_ _a filename_*/. The Python program > now should do the Text processing trick and*/_ return the lists (could > convert to Numeric arrays_ _before that, if it helps) and arrays to > the C++ programm_/*. (optimally this should happen without the user > knowing that python is working partially in the background - no Dos > Box opening etc.). > > I have underlined the parts of the process in the text above I don't > know how to do...I hope there is a simpler solution than using a neat > interfacing support like SWIG etc... > > Now, I want to ask somebody if he perhaps has a little SIMPLE example > code in C++ and Python where something similar is done. I would > appreciate some example files very much, as I could then directly > test out what's going on. > Surely I am also very happy with any other counsel... > > Thanks, > > billy > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > From nicodemus at esss.com.br Tue Mar 2 23:11:59 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Tue, 02 Mar 2004 19:11:59 -0300 Subject: [C++-sig] Defining and adding functions in pyste. In-Reply-To: References: Message-ID: <404506AF.3050700@esss.com.br> Hanz Meizer wrote: > > This is working and showing in the output as expected. Unfortunately, > using add_method gives me bad results because pyste doesn't know about > the foobar function. ow do I have to setup my pyste file that it > generates the same layout as my boost file? You have to include foobar in another header file, and use that to include your classe: Test = Class("Test", "foobar.h") add_method(Test, "foobar") HTH, Nicodemus. From adruab at hotmail.com Wed Mar 3 03:55:08 2004 From: adruab at hotmail.com (Adrian Bentley) Date: Tue, 2 Mar 2004 18:55:08 -0800 Subject: [C++-sig] Re: Boost... Exception safe (can I turn it off?), and controlled object construction? References: Message-ID: Sorry about being somewhat unclear. In terms of what I wanted to do with exceptions, I was under the impression that the boost python code boiled down to using the C Python API (which allows you to set a python global exception handler... I think). There are alternative ways I can wrap the interpreting calls to prevent exceptions from being thrown. However, I want to compile the code without exceptions turned on, which would prevent me from being able to use try catch blocks. In terms of my object madness: > > //In pyobject file class BaseObject { void *data; //where the > > variables will all go //All it's stuff in here, some which requires > > manual construction and such > > }; > > > > Pythonclass : BaseObject { //add stuff here > > } > > > > //in actual program class Py_wrapper : public BaseObject { PyObject > > *pyo; //gotten from embedded python > > > > //forward variable requests to python object etc.... > > }; > > > > // End example > > That doesn't illustrate very much, but I don't know why anyone would > use PyObject* when they could use boost::python::object. Heh, yeah, I'm not sure why I spontaneously forgot to write boost::python::object instead. > > Ok, now that you all know I'm crazy the reason why I want to do this > > is that the base object is designed to communicate a certain way with > > things it's attached to, which probably wouldn't cooperate with the > > way python works > > Maybe you should find out for sure before deciding. > > > , so I need to manually construct the base object (also not sure how > > to do this in boost python). > > I've no clue what you're asking about, sorry. To elaborate, and clarify (since I don't seem to be very good at that): > > Basically what I'd like is to have python override things like a class > > normally would, and track it in my object system. I'm kind of > > doubting there's a way to do that, hence then extra layer of > > indirection py_wrapper (which should work). Clarification: I don't imagine there is any way to "cast" the python object to a BaseObject * or the like, is there? I'd imagine there wouldn't be, given that python must use a method of inheritance incompatible with C++. In the case that I would NOT be able to cast as such, if I wanted to register any python derived BaseObjects with my system, I'd have to use the wrapping class with the object inside. Thanks for the pointers (and being patient with me :P), Adruab > Adrian Bentley From gilles.orazi at varianinc.com Wed Mar 3 14:35:17 2004 From: gilles.orazi at varianinc.com (Gilles Orazi) Date: Wed, 03 Mar 2004 14:35:17 +0100 Subject: [C++-sig] Virtual base class and concrete class Message-ID: <5.2.0.9.2.20040303135525.00b5ebd0@begonia.varianinc.com> An HTML attachment was scrubbed... URL: From pierre.barbier at cirad.fr Wed Mar 3 14:50:16 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Wed, 03 Mar 2004 14:50:16 +0100 Subject: [C++-sig] Automation of Python object retrieval Message-ID: <1078321816.742.164.camel@pbarbier> I have a problem with the boost::python::object contruction. I'd want to know if there is a way to automate the retrieval of the existing Python object when I hold a Pointer on the C++ base class and that the class is extended in Python. Here's an example of what I do now : ================ In C++ ================ #include #include #include #include using namespace boost::python; struct Base { virtual ~Base() {} virtual std::string toStr() const { return "base"; } virtual bool operator==( Base& b ) { return toStr() == b.toStr(); } }; struct BaseWrap : public Base { BaseWrap( PyObject* self_ ) : self(self_) { Py_INCREF(self); /* Ensure the Python object exists as least as long as the C++ object does */ } BaseWrap( PyObject* self_, const Base& copy) : Base(copy), self(self_) { Py_INCREF(self); } virtual ~BaseWrap() { Py_DECREF(self); } virtual std::string toStr() const { return call_method(self, "toStr"); } std::string default_toStr() const { return Base::toStr(); } virtual bool operator==( Base& b ) { return call_method(self, "__eq__", b); // Naive approach } bool default_eq( Base& b) { return Base::operator==( b ); } PyObject *self; }; struct Holder { Holder( Base* b = NULL ) : hold( b ) {} bool operator==( Holder& other ) { return *hold == *other.hold; } std::string toStr() { return hold->toStr(); } Base& getHold() { return *hold; } Base* hold; }; Holder* makeHolder( std::auto_ptr b ) { Holder* obj = new Holder( b.get() ); b.release(); return obj; }; BOOST_PYTHON_MODULE(mymod) { class_ >("Base", init<>()) .def("__eq__", &Base::operator==, &BaseWrap::default_eq) .def("toStr", &Base::toStr, &BaseWrap::default_toStr) ; implicitly_convertible, std::auto_ptr >(); class_( "Holder" ) .def( "__init__", make_constructor( makeHolder ) ) .def( "__eq__", &Holder::operator== ) .def( "toStr", &Holder::toStr ) .def( "getHold", &Holder::getHold, return_internal_reference<1>() ) ; } ================ In Python: ================ from mymod import * class Derived(Base): def __init__(self, value): Base.__init__(self) self._value = value def toStr(self): return "Derived with value %s" % self._value def __eq__(self,other): if isinstance(other, Derived): return self._value == other._value return False h = Holder(Derived(10)) h1 = Holder(Derived(10)) h2 = Holder(Derived("10")) h3 = Holder(Derived(11)) print h == h1 # => 0 print h == h2 # => 0 print h == h # => 0 ====================== All the equality tests fails because the other in detected as a Base object and not a Derived object !!! But, if I replace the BaseWrap::operator== by : virtual bool operator==( Base& b ) { static reference_existing_object::apply::type convert; BaseWrap* bw = dynamic_cast( &b ); object other; if( bw != NULL ) { other = object( handle<>( borrowed( bw->self ) ) ); } else { other = object( handle<>( convert( b ) ) ); } return call_method(self, "__eq__", other); } I get the wanted behaviour. But I wonder if there is a cleaner method to do that ? Or at least a method to automate that. It's always the same : take the self PyObject* from the wrapper and use it to build the the boost::python::object. Thanks, Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From steam at nurfuerspam.de Wed Mar 3 16:46:51 2004 From: steam at nurfuerspam.de (Hanz Meizer) Date: Wed, 03 Mar 2004 16:46:51 +0100 Subject: [C++-sig] Re: Conversion of C++ return type. In-Reply-To: References: Message-ID: > Good guess. > > Unfortunately I can't track down the details for you, but here's the > gist: you need to register a custom to_python_converter for Any. > Then, inside its conversion function, you need to get the typeid of > the type stored by the Any (if you can't get that you're out of luck), > and invoke the registry's lookup function to get the to-python > conversion chain for the stored type. Then you need to "manually" > invoke that converter. Expect the resulting code to be fairly ugly > and low-level. Sorry :( > > The Any objects usually contain very basic types, or vectors of very basic types. So I think what would be really nice is to have two functions, one converting an Any object to a PyObject that contains a pythonification of the Any member objects, and another one that gets called with a python object and returns the corresponding Any object. The latter would be used implicitly when a C++ Method is called from python (for example std::string printAny(const Any& car) ). For example: I have a function Any* getProperty() that returns an Any that either conains a vector or a single double. The conversion function then would take the Any, and return a PyObject to python that either contins a list of doubles or a simple double. Unfortunately, diggig through the examples and mailing list archives didn't enlighten me enough, my last test was something like: namespace { struct any_to_python { static PyObject* convert(Any const& x) { std:cerr << "convert called, rejoice!" << endl; exit(1); } }; ... class_< Any, boost::noncopyable >("Any", no_init) ; to_python_converter< Any, any_to_python >(); The intention is to have any_to_python::convert check what is inside of the Any and return the approprioate, constructed python object. Unfortunately, convert is never called. If I uncomment the class_<> ...; thing, python says: No Python class registered for C++ class Any If I sue the class_<>...; thing, I get some error because python tries to call __str__ on the Any object and fails. Help! :) Regards, H. From halbert at bbn.com Wed Mar 3 17:32:59 2004 From: halbert at bbn.com (Dan Halbert) Date: Wed, 3 Mar 2004 11:32:59 -0500 Subject: [C++-sig] register_exception_translator problem in 1.31.0 Message-ID: <200403031632.i23GWxs00444@rolex.bbn.com> I am trying to use the exception translator feature stock BPL version from Boost 1.31.0. My code is like this: void translate(My::Own::Exception const &e) { PyErr_SetString( ... ); } BOOST_PYTHON_MODULE(mod) { // ... register_exception_translator(translate); } However, I get a compile error with gcc 3.2.2 on Linux: ../py_my_own.cpp: In function `void init_module_mod()': ../py_my_own.cpp:68: no matching function for call to ` register_exception_translator(void (&)(My::Own::Exception&))' Studying the BPL include files has gotten me nowhere. Can you tell me what I'm doing wrong? Thanks, Dan From dave at boost-consulting.com Wed Mar 3 20:34:44 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 03 Mar 2004 14:34:44 -0500 Subject: [C++-sig] Re: register_exception_translator problem in 1.31.0 References: <200403031632.i23GWxs00444@rolex.bbn.com> Message-ID: Dan Halbert writes: > I am trying to use the exception translator feature stock BPL version > from Boost 1.31.0. My code is like this: > > void > translate(My::Own::Exception const &e) > { > PyErr_SetString( ... ); > } > > > BOOST_PYTHON_MODULE(mod) > { > // ... > register_exception_translator(translate); Add an ampersand ('&') here-------------------------------^ > } > > However, I get a compile error with gcc 3.2.2 on Linux: > > ../py_my_own.cpp: In function `void init_module_mod()': > ../py_my_own.cpp:68: no matching function for call to ` > register_exception_translator(void (&)(My::Own::Exception&))' > > Studying the BPL include files has gotten me nowhere. Can you tell me > what I'm doing wrong? HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From jeff.holle at verizon.net Wed Mar 3 20:55:41 2004 From: jeff.holle at verizon.net (Jeff Holle) Date: Wed, 03 Mar 2004 11:55:41 -0800 Subject: [C++-sig] A problem with pyste. Message-ID: <4046383D.8000304@verizon.net> I'm using Pyste version 0.9.28 and gcc v3.3 on a linux system. I've a problem doing the most complex thing I've done with pyste so far. It involves exposing a couple of templated functions, which can each be instantiated with 3 types of classes. I've attached both the pyste configuration file and the referenced *.h file. The errors produced are the following: /tmp/tmp9zPX8o.h:135: error: syntax error before `;' token /tmp/tmp9zPX8o.h: In function `void __instantiate_putNamespace_Parameter()': /tmp/tmp9zPX8o.h:137: error: `putNamespace_Parameter' undeclared (first use this function) Note that putNamespace_Parameter is explicitly specified within NamespaceDef.pyste. I tried to use the default name instead of renaming it and the error message changed to can't find "UMLModel_putNamespace_Parameter". Could somebody with more experience with pyste please inform me what I'm doing wrong. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: NamespaceDef.pyste URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: NamespaceDef.h URL: From halbert at bbn.com Wed Mar 3 21:18:34 2004 From: halbert at bbn.com (Dan Halbert) Date: Wed, 3 Mar 2004 15:18:34 -0500 Subject: [C++-sig] Re: register_exception_translator problem in 1.31.0 In-Reply-To: (message from David Abrahams on Wed, 03 Mar 2004 14:34:44 -0500) References: <200403031632.i23GWxs00444@rolex.bbn.com> Message-ID: <200403032018.i23KIY400820@rolex.bbn.com> >> register_exception_translator(translate); >Add an ampersand ('&') here-------------------------------^ Ah, so the tutorial example is wrong. Thank you! (Bad example is at http://www.boost.org/libs/python/doc/tutorial/doc/exception_translation.html) From dave at boost-consulting.com Wed Mar 3 22:49:37 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 03 Mar 2004 16:49:37 -0500 Subject: [C++-sig] Re: register_exception_translator problem in 1.31.0 References: <200403031632.i23GWxs00444@rolex.bbn.com> <200403032018.i23KIY400820@rolex.bbn.com> Message-ID: Dan Halbert writes: > >> register_exception_translator(translate); > >Add an ampersand ('&') here-------------------------------^ > > Ah, so the tutorial example is wrong. Thank you! > (Bad example is at http://www.boost.org/libs/python/doc/tutorial/doc/exception_translation.html) http://www.boost.org/libs/python/doc/v2/exception_translator.html gets it right. Hmm. Do me a favor, please. In exception_translator.hpp, change: template void register_exception_translator(Translate const& translate, boost::type* = 0) ^^^^^^ to: template void register_exception_translator(Translate translate, boost::type* = 0) and try your example again. I expect it works, and if so I'm inclined to change the signature of register_exception_translator. -- Dave Abrahams Boost Consulting www.boost-consulting.com From halbert at bbn.com Thu Mar 4 00:32:06 2004 From: halbert at bbn.com (Dan Halbert) Date: Wed, 3 Mar 2004 18:32:06 -0500 Subject: [C++-sig] Re: register_exception_translator problem in 1.31.0 In-Reply-To: (message from David Abrahams on Wed, 03 Mar 2004 16:49:37 -0500) References: <200403031632.i23GWxs00444@rolex.bbn.com> <200403032018.i23KIY400820@rolex.bbn.com> Message-ID: <200403032332.i23NW6q01280@rolex.bbn.com> David Abrahams wrote: >> >> register_exception_translator(translate); >> >Add an ampersand ('&') here-------------------------------^ >> >Hmm. Do me a favor, please. In exception_translator.hpp, change: > > template > void register_exception_translator(Translate const& translate, boost::type* = 0) > ^^^^^^ >to: > > template > void register_exception_translator(Translate translate, boost::type* = 0) > >and try your example again. I expect it works, and if so I'm inclined >to change the signature of register_exception_translator. OK, I did try this, and now it works either with "&translate" or plain "translate" above. So that does seem better. Dan From halbert at bbn.com Thu Mar 4 00:45:49 2004 From: halbert at bbn.com (Dan Halbert) Date: Wed, 3 Mar 2004 18:45:49 -0500 Subject: [C++-sig] pyste: excluding a constructor Message-ID: <200403032345.i23Njnl01298@rolex.bbn.com> OK, now a pyste question, with the 1.31.0 pyste: I have code like this: ======================================== class Opaque; // Forward declaration, not otherwise declared in this .h class Foo { public: Foo(int); Foo(Opaque*); // ... } ======================================== I get "use of undefined type" and "forward declaration" g++ errors about Opaque. I see two possibilities: 1. Can I use a policy, maybe, to avoid this error? 2. I don't necessarily care about pythonizing the second constructor. I could exclude Opaque, but how do I exclude the second constructor? Nicodemus mentioned some meta-programming constructs he was adding sometime last summer which looked like they could be used to iterate through the constructors and exclude the second one. But I tried something like his example and couldn't get it to work. I studied infos.py but didn't glean a solution. Thanks very much, Dan From s_sourceforge at nedprod.com Thu Mar 4 02:51:34 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 04 Mar 2004 01:51:34 -0000 Subject: [C++-sig] pyste: excluding a constructor In-Reply-To: <200403032345.i23Njnl01298@rolex.bbn.com> Message-ID: <40468BA6.19225.1BAAA3D2@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 3 Mar 2004 at 18:45, Dan Halbert wrote: > I get "use of undefined type" and "forward declaration" g++ errors > about Opaque. I see two possibilities: > > 1. Can I use a policy, maybe, to avoid this error? Just specify the return_opaque_pointer() policy. I may have the name slightly wrong - look it up in pyste.py. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQEaLpsEcvDLFGKbPEQKGpwCeI/aFyteBoeV50cNi779pbWwu/ecAoKZ4 FXeRUAKtnrpspmKMxIcy9nYn =6doy -----END PGP SIGNATURE----- From pierre.barbier at cirad.fr Thu Mar 4 09:19:04 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Thu, 04 Mar 2004 09:19:04 +0100 Subject: [C++-sig] embedding examples In-Reply-To: <1078132099.32100.6.camel@localhost> References: <1078132099.32100.6.camel@localhost> Message-ID: <1078388344.742.175.camel@pbarbier> Hi ! I use the interpreter with the CVS version of Boost. In my code I use these lines to get the __main__ dict (and it works ...): object main_module = object(handle<>(borrowed(PyImport_AddModule("__main__")))); object main_namespace = extract( object(handle<>(borrowed(PyModule_GetDict(main_module.ptr())))) ); Pierre On Mon, 2004-03-01 at 10:08, Ingo Luetkebohle wrote: > Hi, > > I have trouble compiling the 'Using the interpreter' examples from the > tutorial. > > Code like this: > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); > dict main_namespace(handle<>(borrowed( > PyModule_GetDict(main_module.get()) ))); > results in > error: variable declaration is not allowed here > > using gcc 3.2 and gcc 3.3 on Linux. > > When I use > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); > handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) )); > dict main_namespace(main_nsh); > > it compiles and the resulting dict is usable. > > So, this is not a showstopper but it doesn't work as documented and > results in longer code. Is there anything I can do to get the intended > behaviour? > > regards -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From Holger.Joukl at LBBW.de Thu Mar 4 17:28:25 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Thu, 4 Mar 2004 17:28:25 +0100 Subject: [C++-sig] building boost.python problems Message-ID: Dear boost.pythoneers, first of all, sorry for the lengthish post (and more so, for the confidential blabla my employer attaches to all my outgoing mails). I?m having a little trouble building even the simplest tutorial example, running python 2.3.3 on a solaris 2.6 system and boost.python 1.31.0: This is what I get when following the tutorial build instructions: hjoukl at dev-b .../boost_1_31_0 $ cd libs/python/example/tutorial/ 0 hjoukl at dev-b .../tutorial $ export PYTHON_ROOT=/opt/tools 0 hjoukl at dev-b .../tutorial $ export PYTHON_VERSION=2.3 0 hjoukl at dev-b .../tutorial $ which gcc /opt/tools/bin/gcc 0 hjoukl at dev-b .../tutorial $ ./bjam ...found 1972 targets... ...updating 24 targets... gcc-C++-action ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/numeric.o In file included from /opt/tools/include/python2.3/Python.h:8, from /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/detail/wrap_python.hpp:121, from /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/detail/prefix..hpp:13, from /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/numeric.hpp:9, from /data/projects/hjoukl/new_boost/boost_1_31_0/libs/python/build/../src/numeric.cpp:7: /opt/tools/include/python2.3/pyconfig.h:825: warning: `_FILE_OFFSET_BITS' redefined /usr/include/sys/feature_tests.h:80: warning: this is the location of the previous definition /opt/tools/bin/objcopy: unrecognized section flag `debug' /opt/tools/bin/objcopy: supported flags: alloc, load, readonly, code, data, rom, contents ... set -e g++ -c -Wall -ftemplate-depth-100 -DBOOST_PYTHON_DYNAMIC_LIB -DBOOST_PYTHON_SOURCE -g -O0 -fno-inline -fPIC -I"../../../../bin/boost/libs/python/build" -I "/opt/tools/include/python2.3" -I "/data/projects/hjoukl/new_boost/boost_1_31_0" -o "../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/object_operators.o" "/data/projects/hjoukl/new_boost/boost_1_31_0/libs/python/build/../src/object_operators.cpp" /opt/tools/bin/objcopy --set-section-flags .debug_str=contents,debug "../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/object_operators.o" ...failed gcc-C++-action ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/object_operators.o... ...removing ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/object_operators.o ...skipped <@boost!libs!python!build/libboost_python.so/gcc/debug/shared-linkable-true>libboost_python.so for lack of <@boost!libs!python!build/libboost_python.so/gcc/debug/shared-linkable-true>numeric.o... ...skipped <@boost!libs!python!example!tutorial/hello.so/gcc/debug/shared-linkable-true>hello.so for lack of <@boost!libs!python!build/libboost_python.so/gcc/debug/shared-linkable-true>libboost_python.so... ...failed updating 22 targets... ...skipped 2 targets... As I understand this, boost_python shared library is looked for in a debug version, which is not found as for some other reason, building the debug objects failed. There is indeed a "normal" boost_python lib: 1 hjoukl at dev-b .../tutorial $ ls -l ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/release/shared-linkable-true/libboost_python-gcc-1_31.so -rwxr-xr-x 1 hjoukl intern 448536 Mar 2 13:00 ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/release/shared-linkable-true/libboost_python-gcc-1_31.so* Also the objcopy step seems not to work, probably for the same reason? No hello.so is created and the jam build system remains a mystery to me at the moment. Any hints are appreciated, G Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From rwgk at yahoo.com Thu Mar 4 20:55:25 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 4 Mar 2004 11:55:25 -0800 (PST) Subject: [C++-sig] building boost.python problems In-Reply-To: Message-ID: <20040304195525.51371.qmail@web20202.mail.yahoo.com> FWIW: When I tried the last time a few months ago Boost.Python built OK under Solaris 5.9 with gcc 3.3.1, using Python 2.3. I also know about a successful build with gcc 3.2.2 and Python 2.3.2 (don't know the Solaris version). A SCons-based build system was used in both cases, but your error message doesn't seem to be related to the build system. What is the output of g++ --version on your machine? Ralf __________________________________ Do you Yahoo!? Yahoo! Search - Find what you?re looking for faster http://search.yahoo.com From grafik.list at redshift-software.com Thu Mar 4 21:33:24 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 04 Mar 2004 14:33:24 -0600 Subject: [C++-sig] RE: building boost.python problems Message-ID: <40479294.8020801@redshift-software.com> Sorry for the top post, deleted the original email too fast :-( ... > Dear boost.pythoneers, > first of all, sorry for the lengthish post (and more so, for the > confidential blabla my employer attaches to all my outgoing mails). > > I?m having a little trouble building even the simplest tutorial example, > running python 2.3.3 on a solaris 2.6 system and boost.python 1.31.0: > This is what I get when following the tutorial build instructions: > > hjoukl at dev-b .../boost_1_31_0 $ cd libs/python/example/tutorial/ > 0 hjoukl at dev-b .../tutorial $ export PYTHON_ROOT=/opt/tools > 0 hjoukl at dev-b .../tutorial $ export PYTHON_VERSION=2.3 > 0 hjoukl at dev-b .../tutorial $ which gcc > /opt/tools/bin/gcc > 0 hjoukl at dev-b .../tutorial $ ./bjam > ...found 1972 targets... > ...updating 24 targets... > gcc-C++-action > ../../../../bin/boost/libs/python/build/libboost_python.so/gcc/debug/shared-linkable-true/numeric.o > In file included from /opt/tools/include/python2.3/Python.h:8, > from > /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/detail/wrap_python.hpp:121, > from > /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/detail/prefix..hpp:13, > from > /data/projects/hjoukl/new_boost/boost_1_31_0/boost/python/numeric.hpp:9, > from > /data/projects/hjoukl/new_boost/boost_1_31_0/libs/python/build/../src/numeric.cpp:7: > /opt/tools/include/python2.3/pyconfig.h:825: warning: `_FILE_OFFSET_BITS' > redefined > /usr/include/sys/feature_tests.h:80: warning: this is the location of the > previous definition > /opt/tools/bin/objcopy: unrecognized section flag `debug' > /opt/tools/bin/objcopy: supported flags: alloc, load, readonly, code, data, > rom, contents I think all your problems stems from the objcopy not working. This prevents the linking from continuing and basically nothing getting produced. Two options to fix this are to: disable objcopy on Solaris, or figure out which section flag to use instead of "debug". But some explanation first... The objcopy is a workaround for the n^2 linking problems of GCC, it has the effect of disabling the problematic symbol reduction algorithm in the linker. For BPL this is important because of the large number of _debug_ symbols generated by the templates. OK, so to the first option disabling the objcopy. Try this change... Index: gcc-tools.jam =================================================================== RCS file: /cvsroot/boost/boost/tools/build/v1/gcc-tools.jam,v retrieving revision 1.86 diff -u -2 -r1.86 gcc-tools.jam --- gcc-tools.jam 26 Jan 2004 20:21:22 -0000 1.86 +++ gcc-tools.jam 4 Mar 2004 20:12:57 -0000 @@ -160,4 +160,5 @@ { NO_GNU_LN = true ; # sun seems not to use the GNU linker with gcc + NO_OBJCOPY = true ; } case Linux : @@ -350,6 +351,10 @@ # used to manipulate the object files produced by GCC to # prevent the merging of debug symbols (which happens to be n^2 slow) -flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; -flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; +if ! $(NO_OBJCOPY) +{ + flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; +} + if ! $(on-windows) { For the second option, you could try using "--set-section-flags .debug_str=contents" (that is removing the ",debug"). Which this patch does... Index: gcc-tools.jam =================================================================== RCS file: /cvsroot/boost/boost/tools/build/v1/gcc-tools.jam,v retrieving revision 1.86 diff -u -1 -r1.86 gcc-tools.jam --- gcc-tools.jam 26 Jan 2004 20:21:22 -0000 1.86 +++ gcc-tools.jam 4 Mar 2004 20:23:30 -0000 @@ -161,2 +161,3 @@ NO_GNU_LN = true ; # sun seems not to use the GNU linker with gcc + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents" ; } @@ -166,2 +167,3 @@ SONAME = -Wl,-soname, ; + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; } @@ -352,3 +354,3 @@ flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; -flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; + if ! $(on-windows) And of course I'd like to know which one works so I can apply the change to future releases. ...HTH :-) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From pearu at cens.ioc.ee Thu Mar 4 22:16:58 2004 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Thu, 4 Mar 2004 23:16:58 +0200 (EET) Subject: [C++-sig] wrapping class X with private constructor X::X(const X&) Message-ID: Hi, I am trying to wrap a library class that is special in the sense that its constructor is specified as private and this causes compilation to fail. Is it true that boost.python tries to use X::X(const X&) internally? Is is possible to avoid it? (I tried to use no_init and init<>() with no success.) Thanks, Pearu Details ------- GCC: 3.3.3 Here is a fragment of my boost.python wrapper: class_ >("matrix"); //where `int8u` is typedef `unsigned char` Here's the definition of agg::matrix: template class matrix { public: matrix(); matrix(T* buf, unsigned width, unsigned height, int stride); private: matrix(const matrix&); } and here follows the error message: bpl_src/rendering_buffer.cpp: In function `void export_rendering_buffer()': bpl_src/rendering_buffer.cpp:8: warning: unused variable `char rendering_buffer_doc[26]' agg2/include/agg_matrix.h: In constructor ` boost::python::objects::value_holder::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper >, Value = agg::matrix]': boost_1_31_0/boost/python/object/make_instance.hpp:69: instantiated from `static Holder* boost::python::objects::make_instance::construct(void*, PyObject*, boost::reference_wrapper) [with T = agg::matrix, Holder = boost::python::objects::value_holder >]' boost_1_31_0/boost/python/object/make_instance.hpp:43: instantiated from `static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = const boost::reference_wrapper >, T = agg::matrix, Holder = boost::python::objects::value_holder >, Derived = boost::python::objects::make_instance, boost::python::objects::value_holder > >]' boost_1_31_0/boost/python/object/class_wrapper.hpp:27: instantiated from `static PyObject* boost::python::objects::class_cref_wrapper::convert(const Src&) [with Src = agg::matrix, MakeInstance = boost::python::objects::make_instance, boost::python::objects::value_holder > >]' boost_1_31_0/boost/python/converter/as_to_python_function.hpp:28: instantiated from `static PyObject* boost::python::converter::as_to_python_function::convert(const void*) [with T = agg::matrix, ToPython = boost::python::objects::class_cref_wrapper, boost::python::objects::make_instance, boost::python::objects::value_holder > > >]' boost_1_31_0/boost/python/to_python_converter.hpp:34: instantiated from `boost::python::to_python_converter::to_python_converter() [with T = agg::matrix, Conversion = boost::python::objects::class_cref_wrapper, boost::python::objects::make_instance, boost::python::objects::value_holder > > >]' boost_1_31_0/boost/python/class.hpp:105: instantiated from `void boost::python::detail::register_class_to_python(boost::mpl::bool_, SelectHolder, T*) [with T = agg::matrix, SelectHolder = boost::python::objects::select_holder, boost::python::detail::not_specified>]' boost_1_31_0/boost/python/class.hpp:631: instantiated from `void boost::python::class_::register_() const [with T = agg::matrix, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' boost_1_31_0/boost/python/class.hpp:660: instantiated from `boost::python::class_::class_(const char*, boost::python::no_init_t) [with T = agg::matrix, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' bpl_src/rendering_buffer.cpp:11: instantiated from here agg2/include/agg_matrix.h:124: error: `agg::matrix::matrix(const agg::matrix&) [with T = int8u]' is private boost_1_31_0/boost/python/object/value_holder.hpp:117: error: within this context From dave at boost-consulting.com Thu Mar 4 22:33:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 04 Mar 2004 16:33:50 -0500 Subject: [C++-sig] Re: wrapping class X with private constructor X::X(const X&) References: Message-ID: Pearu Peterson writes: > I am trying to wrap a library class that is special in the sense > that its constructor is specified as private and this causes > compilation to fail. Is it true that boost.python tries > to use X::X(const X&) internally? Yes; it has to figure out how to return Xs from functions, should you wrap such a function. > Is is possible to avoid it? yes (see below). > (I tried to use no_init and init<>() with no success.) > > Thanks, > Pearu > > Details > ------- > > GCC: 3.3.3 > Here is a fragment of my boost.python wrapper: > > class_ >("matrix"); add ", boost::noncopyable" -------^ -- Dave Abrahams Boost Consulting www.boost-consulting.com From mike at nospam.com Thu Mar 4 22:36:36 2004 From: mike at nospam.com (Mike Rovner) Date: Thu, 4 Mar 2004 13:36:36 -0800 Subject: [C++-sig] Re: wrapping class X with private constructor X::X(const X&) References: Message-ID: Pearu Peterson wrote: > Is it true that boost.python tries > to use X::X(const X&) internally? Is is possible to avoid it? Yes. Yes, use boost::noncopyable as in class_("Klass", no_init) ... HTH, Mike From Holger.Joukl at LBBW.de Fri Mar 5 09:39:20 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 5 Mar 2004 09:39:20 +0100 Subject: [C++-sig] building boost.python problems Message-ID: What is the output of g++ --version on your machine? g++ -v Reading specs from /opt/tools/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs gcc version 2.95.2 19991024 (release) Oops, forgot that in my original email. I will try out Rene?s proposed solutions and post the results. Holger _________________________________ Holger Joukl Landesbank Baden-W?rttemberg 1651 Financial Markets Technologies fon +49 (711) 124 - 7078 fax +49 (711) 124 - 3759 _________________________________ Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From Holger.Joukl at LBBW.de Fri Mar 5 11:07:56 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 5 Mar 2004 11:07:56 +0100 Subject: [C++-sig] RE: building boost.python problems Message-ID: Hmm, I can?t seem to apply Rene Rivera?s patches; I always get this: 2 hjoukl at dev-b .../v1 $ patch -i gcc-tools.patch Looks like a unified context diff. I can't seem to find a patch in there anywhere. Will try inserting the changes manually now. Regards, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From Holger.Joukl at LBBW.de Fri Mar 5 12:34:37 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 5 Mar 2004 12:34:37 +0100 Subject: [C++-sig] building boost.python problems Message-ID: My problems to apply Rene?s patches resulted from some mail-related issues I think. Some lines were wrapped where they are not in the sources and also a problem with tabs. Don?t know why, maybe our unspeakable Lotus Notes. Or lines already wrapped by the sending mail client. Anyway, I applied the changes manually. BOTH solutions worked fine for me. I repost the diffs here, just for completeness. Rene?s originals are the authoritative ones (the line numbers are a little different, too), of course. P1: 1 hjoukl at dev-b .../v1 $ diff -u -1 gcc-tools.jam.ORIGINAL gcc-tools.jam.rivera1_patched --- gcc-tools.jam.ORIGINAL Fri Mar 5 09:53:35 2004 +++ gcc-tools.jam.rivera1_patched Fri Mar 5 11:26:02 2004 @@ -162,2 +162,3 @@ NO_GNU_LN = true ; # sun seems not to use the GNU linker with gcc + NO_OBJCOPY = true ; } @@ -352,4 +353,8 @@ # prevent the merging of debug symbols (which happens to be n^2 slow) -flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; -flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; +if ! $(NO_OBJCOPY) +{ + flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; +} + if ! $(on-windows) P2: 1 hjoukl at dev-b .../v1 $ diff -u -1 gcc-tools.jam.ORIGINAL gcc-tools.jam.rivera2_patched --- gcc-tools.jam.ORIGINAL Fri Mar 5 09:53:35 2004 +++ gcc-tools.jam.rivera2_patched Fri Mar 5 12:16:32 2004 @@ -162,2 +162,3 @@ NO_GNU_LN = true ; # sun seems not to use the GNU linker with gcc + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents" ; } @@ -167,2 +168,3 @@ SONAME = -Wl,-soname, ; + flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; } @@ -353,3 +355,3 @@ flags gcc .OBJCOPY : [ GLOB $(GCC_BIN_DIRECTORY) $(PATH) : objcopy ] ; -flags gcc OBJCOPY_FLAGS on : "--set-section-flags .debug_str=contents,debug" ; + if ! $(on-windows) 1 hjoukl at dev-b .../v1 $ So, a big thank you, Rene! Now I am gonna try to wrap the TIB/Rv API. Follow-up questions are sure to come, soon :-) Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From grafik.list at redshift-software.com Fri Mar 5 16:22:27 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Fri, 05 Mar 2004 09:22:27 -0600 Subject: [C++-sig] building boost.python problems In-Reply-To: References: Message-ID: <40489B33.4010000@redshift-software.com> Holger Joukl wrote: > My problems to apply Rene?s patches resulted from some mail-related issues > I think. > Some lines were wrapped where they are not in the sources and also a > problem with tabs. > Don?t know why, maybe our unspeakable Lotus Notes. Or lines already wrapped > by the > sending mail client. Yes likely some word wraps on both my end and your end :-) > Anyway, I applied the changes manually. BOTH solutions worked fine for me. Good. > So, a big thank you, Rene! You're welcome. Question for you... Was either solution faster doing the link? As I'd rather go with the faster one. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From Holger.Joukl at LBBW.de Fri Mar 5 16:41:51 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 5 Mar 2004 16:41:51 +0100 Subject: [c++-sig] private copy constructor with callback from c++ Message-ID: Yet another long post... I am trying to wrap Tibco?s TIB/Rv API, using BPL 1.31.0 and pyste, gcc 2.95.2, solaris 2.6. There happens to be a call from the C++ side to TibrvMsgCallback::onEvent (with BPL it is actually TibrvMsgCallback_Wrapper::onEvent?), giving a TibrvListener* as an argument. Now the problem seems to me that the TibrvListener class (inheriting from TibrvEvent), has a private copy constructor. This results in a core dump when performing the call. Do I have chance of avoiding this problem? Funny thing is, I first tried to build all the stuff by hand, not using bjam -- there I managed to not run into core, but got an error message that no to_python converter was registered for TibrvListener/TibrvEvent; so maybe I could write a custom converter? Thank you very much for any help Holger Btw I do not have access to my box until tuesday, so no hurry/do not wonder if I will not respond quickly. Here is the wrapper code: // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ struct void_; BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_); void_ *TibrvEvent_getClosure_wrapper(TibrvEvent* event) { return (void_ *) event->getClosure(); } // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ struct void_; BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_); void_ *TibrvEvent_getClosure_wrapper(TibrvEvent* event) { return (void_ *) event->getClosure(); } //BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void) namespace { struct TibrvEvent_Wrapper: TibrvEvent { TibrvStatus destroy(TibrvEventOnComplete* p0) { return call_method< TibrvStatus >(self, "destroy", p0); } TibrvStatus default_destroy_0() { return TibrvEvent::destroy(); } TibrvStatus default_destroy_1(TibrvEventOnComplete* p0) { return TibrvEvent::destroy(p0); } PyObject* self; }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(TibrvListener_create_overloads_4_5, create, 4, 5) }// namespace // Module ====================================================================== void Export_TibrvEvent() { class_< TibrvEvent, boost::noncopyable, TibrvEvent_Wrapper >("TibrvEvent", no_init) .def("destroy", &TibrvEvent::destroy, &TibrvEvent_Wrapper::default_destroy_1) .def("destroy", &TibrvEvent_Wrapper::default_destroy_0) .def("isValid", &TibrvEvent::isValid) .def("getQueue", &TibrvEvent::getQueue, return_value_policy< reference_existing_object >()) .def("getClosure", &TibrvEvent_getClosure_wrapper, return_value_policy< return_opaque_pointer >()) .def("isListener", &TibrvEvent::isListener) .def("isTimer", &TibrvEvent::isTimer) .def("isIOEvent", &TibrvEvent::isIOEvent) .def("getType", &TibrvEvent::getType) .def("getHandle", &TibrvEvent::getHandle) ; class_< TibrvListener, bases< TibrvEvent >, boost::noncopyable >("TibrvListener", init< >()) .def("create", &TibrvListener::create, TibrvListener_create_overloads_4_5()) .def("getTransport", &TibrvListener::getTransport, return_value_policy< reference_existing_object >()) .def("getSubject", &TibrvListener::getSubject) ; } #include // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace { struct TibrvCallback_Wrapper: TibrvCallback { TibrvCallback_Wrapper(PyObject* self_, const TibrvCallback& p0): TibrvCallback(p0), self(self_) {} TibrvCallback_Wrapper(PyObject* self_): TibrvCallback(), self(self_) {} void onEvent(TibrvEvent* p0, TibrvMsg& p1) { call_method< void >(self, "onEvent", p0, p1); } PyObject* self; }; struct TibrvMsgCallback_Wrapper: TibrvMsgCallback { TibrvMsgCallback_Wrapper(PyObject* self_, const TibrvMsgCallback& p0): TibrvMsgCallback(p0), self(self_) {} TibrvMsgCallback_Wrapper(PyObject* self_): TibrvMsgCallback(), self(self_) {} void onMsg(TibrvListener* p0, TibrvMsg& p1) { cout << "-->TibrvMsgCallback_Wrapper::onMsg\n"; call_method< void >(self, "onMsg", p0, p1); cout << "<--TibrvMsgCallback_Wrapper::onMsg\n"; } void onEvent(TibrvEvent* p0, TibrvMsg& p1) { cout << "-->TibrvMsgCallback_Wrapper::onEvent\n"; call_method< void >(self, "onEvent", p0, p1); cout << "<--TibrvMsgCallback_Wrapper::onEvent\n"; } PyObject* self; }; Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From dave at boost-consulting.com Fri Mar 5 17:13:39 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Mar 2004 11:13:39 -0500 Subject: [C++-sig] Re: private copy constructor with callback from c++ References: Message-ID: "Holger Joukl" writes: > Now the problem seems to me that the TibrvListener class (inheriting > from TibrvEvent), has a private copy constructor. This results in a > core dump when performing the call. I think you've mis-diagnosed the problem. There's basically no way the accessibility of the copy ctor can have an effect on runtime behavior. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ron.clarke at hp.com Fri Mar 5 02:43:54 2004 From: ron.clarke at hp.com (Ron Clarke) Date: Thu, 4 Mar 2004 17:43:54 -0800 Subject: [C++-sig] Accessing string vector in Python Message-ID: I am trying to wrap a class method (using Boost.Python 1.31, MS VS.NET2003, Python 2.3) that returns a vector of std::string objects. Here is the C++ definition: typedef std :: vector StringVector; ... StringVector* myClass::getOwners() {... } When wrapping this method for Python use, I thought I could use the vector_indexing_suite like so: BOOST_PYTHON_MODULE(MyModule) { ... class_("StringVector") .def(vector_indexing_suite() ) ; ... } This builds OK, and the StringVector is accessible in Python. However, Python does not understand the individual elements within the vector. When I try to access StringVector elements, Python complains: sv = img.pubDict.getOwners() for i in range(len(sv)): print sv[i] TypeError: No Python class registered for C++ class class std::basic_string,class std::allocator > How do I get Python to understand/convert to string objects it can handle? I tried registering a converter, but that wasn't the answer (implicitly_convertible(); ). I cannot make the StringVector contents boost::python::str objects, since the code being wrapped must also be callable by C++ users. Any suggestions are greatly appreciated. Thanks in advance. -- Ron Clarke ron.clarke at hp.com From johng at quakes.uq.edu.au Mon Mar 8 03:00:46 2004 From: johng at quakes.uq.edu.au (John Gerschwitz) Date: Mon, 08 Mar 2004 12:00:46 +1000 Subject: [C++-sig] problem with embedded python Message-ID: <404BD3CE.3060409@quakes.uq.edu.au> Thanks for your reply Pierre, > The error is when linking ... to be able to help you, I would need the > linking command. > Yes I was wonderng whether I am missing a library or whether it is a library ordering problem. Here is the link step. icc -o SerialAccessorTest.exe ./obj/SerialAccessorTest.o ./obj/AbstractAccessor.o ./obj/PointData.o ./obj/ParallelAccessor.o ./obj/SerialAccessorTestCase.o ./obj/SerialAccessor.o ./obj/Data.o -L/raid2/john/newEsys/esys/tools/CppUnitTest/lib -L/raid2/john/newEsys/esys/utils/lib -L/raid2/john/newEsys/esys/escript/lib -L/raid2/john/newEsys/esys/tools/boost/bin/boost/libs/python/build/libboost_python.so/intel-ia64/debug/shared-linkable-true -L/usr/local/lib/python2.2/config -L/opt/intel/cmplrs/80.058/intel_cc_80/lib -lCppUnitTest -lUtils -lescript -lboost_python-intel-d-1_31 -lpython2.2 -ldl -lutil -lguide > On Thu, 2004-02-26 at 07:41, John Gerschwitz wrote: >> Can anybody tell me why I am getting the following error. The problem >> C++ code >> looks like this . The problem occurs trying to import numarray. >> >> Py_Initialize(); >> handle<> numarrayModule(PyImport_ImportModule("numarray")); >> numeric::array pointData(make_tuple(1,2,3,4)); >> >> Thanks John >> >> Traceback (most recent call last): >> File "/usr/local/lib/python2.2/site-packages/numarray/__init__.py", >> line 1, in ? >> from numarrayall import * >> File "/usr/local/lib/python2.2/site-packages/numarray/numarrayall.py", >> line 1, in ? >> from numerictypes import * >> File >> "/usr/local/lib/python2.2/site-packages/numarray/numerictypes.py", line >> 33, in ? >> from typeconv import typeConverters as _typeConverters >> File "/usr/local/lib/python2.2/site-packages/numarray/typeconv.py", >> line 6, in ? >> import _conv >> ImportError: /usr/local/lib/python2.2/site-packages/numarray/_conv.so: >> undefined symbol: PyCObject_Type >> >> >> >> _______________________________________________ >> C++-sig mailing list >> C++-sig at python.org >> http://mail.python.org/mailman/listinfo/c++-sig > -- > Pierre Barbier de Reuille > > INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP > Botanique et Bio-informatique de l'Architecture des Plantes > TA40/PSII, Boulevard de la Lironde > 34398 MONTPELLIER CEDEX 5, France > > tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From halbert at bbn.com Mon Mar 8 18:12:34 2004 From: halbert at bbn.com (Dan Halbert) Date: Mon, 8 Mar 2004 12:12:34 -0500 Subject: [C++-sig] Pyste 1.31.0 and exceptions Message-ID: <200403081712.i28HCYP27270@rolex.bbn.com> Hi, I am trying to use the Pyste from Boost 1.31.0 with code that uses exceptions. My impression was that this version of Pyste does support automatic exception handling, but maybe I am wrong. I was using gccxml-0.4.2, which does not output any info about exceptions. I switched to gccxml-0.6.0, which does. I have this test case: ============================================== foo.pyste: foo = AllFromHeader("foo.h") ============================================== foo.h: void g() throw (int); // line #1 class C { public: void f() throw (int); }; // line #2 ============================================== If I comment out line #2, then I get no errors, but the generated C++ code does not mention the exception for g(). If I comment out line #1 and leave #2 (or uncomment both), then Pyste gets an error, with the Python stack trace shown below. I am using "int" exceptions for simplicity in this test case, but I also get a similar failure with class exceptions. Thanks, Dan ============================================== Traceback (most recent call last): File "/d4m/tools/i686ling/Python-2.3.3/bin/pyste.py", line 4, in ? pyste.main() File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/pyste.py", line 405, in main status = Begin() File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/pyste.py", line 244, in Begin return GenerateCode(parser, module, out, interfaces, multiple) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/pyste.py", line 372, in GenerateCode export.GenerateCode(codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/Exporter.py", line 50, in GenerateCode self.Export(codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/HeaderExporter.py", line 44, in Export self.HandleDeclaration(decl, codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/HeaderExporter.py", line 61, in HandleDeclaration self.HandleExporter(decl, exporter_class, codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/HeaderExporter.py", line 77, in HandleExporter exporter.GenerateCode(codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/Exporter.py", line 50, in GenerateCode self.Export(codeunit, exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/ClassExporter.py", line 92, in Export self.InheritMethods(exported_names) File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/ClassExporter.py", line 119, in InheritMethods pointers = [x.PointerDeclaration(True) for x in self.class_ if isinstance(x, Method)] File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/declarations.py", line 320, in PointerDeclaration return '(%s (%s::*)(%s) %s%s)&%s' %\ File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/declarations.py", line 226, in Exceptions return " throw(%s)" % ', '.join (self.throws) TypeError: sequence item 0: expected string, FundamentalType found From rclemley at booksys.com Mon Mar 8 19:06:48 2004 From: rclemley at booksys.com (Rob Lemley) Date: Mon, 8 Mar 2004 12:06:48 -0600 Subject: [C++-sig] problem with embedded python In-Reply-To: <404BD3CE.3060409@quakes.uq.edu.au> References: <404BD3CE.3060409@quakes.uq.edu.au> Message-ID: <200403081206.48915.rclemley@booksys.com> On Sunday 07 March 2004 20:00, John Gerschwitz wrote: > > The error is when linking ... to be able to help you, I would need the > > linking command. > > Yes I was wonderng whether I am missing a library or whether it is a > library ordering problem. It looks like the error occurs at runtime linking because of missing options when building the python-embedding executable. Python knows how to do it and the distutils module will tell you how to do it. See section '5.6 Linking Requirements' in the 'Extending and Embedding' document from the main documentation webpage for your version of python. (http://python.org/doc/2.2.3/ext/link-reqs.html) -RCL From s_sourceforge at nedprod.com Mon Mar 8 20:20:05 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 08 Mar 2004 19:20:05 -0000 Subject: [C++-sig] Pyste 1.31.0 and exceptions In-Reply-To: <200403081712.i28HCYP27270@rolex.bbn.com> Message-ID: <404CC765.22345.340405DB@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8 Mar 2004 at 12:12, Dan Halbert wrote: > foo = AllFromHeader("foo.h") Last time I heard AllFromHeader() was still not working. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQEzHZ8EcvDLFGKbPEQIDSgCfe/v6wRYl5hevexc2gzOk9Ksk+6oAoIHT 21VDl94Kvf00oJCziXIHcicJ =kJSd -----END PGP SIGNATURE----- From halbert at bbn.com Mon Mar 8 21:01:58 2004 From: halbert at bbn.com (Dan Halbert) Date: Mon, 8 Mar 2004 15:01:58 -0500 Subject: [C++-sig] Pyste 1.31.0 and exceptions In-Reply-To: <404CC765.22345.340405DB@localhost> (s_sourceforge@nedprod.com) References: <404CC765.22345.340405DB@localhost> Message-ID: <200403082001.i28K1wj27655@rolex.bbn.com> >From: "Niall Douglas" >On 8 Mar 2004 at 12:12, Dan Halbert wrote: > >> foo = AllFromHeader("foo.h") > >Last time I heard AllFromHeader() was still not working. Actually, it seems to work pretty well for me, though I promise to be careful. But even if I change my example to what is below, and don't use AllFromHeader(), I get the same error as I listed previously. --Dan ============================================== foo.pyste: ##foo = AllFromHeader("foo.h") Function("g", "foo.h") Class("C", "foo.h") ============================================== foo.h: void g() throw (int); // line #1 class C { public: void f() throw (int); }; // line #2 ============================================== ... File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/declarations.py", line 226, in Exceptions return " throw(%s)" % ', '.join (self.throws) TypeError: sequence item 0: expected string, FundamentalType found From ostiguy at fnal.gov Mon Mar 8 21:40:27 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Mon, 8 Mar 2004 14:40:27 -0600 (CST) Subject: [C++-sig] c++ to python automatic conversion Message-ID: Hi - I am having difficulty with c++ to python conversion. Consider the following snippet: ================================================================================ #include using namespace boost::python; struct B { int n; int m; B(): n(0), m(0) { } }; struct A { A() {} B* makeB() { return new B; } }; BOOST_PYTHON_MODULE(demo) { class_("A") .def("makeB", &A::makeB, return_value_policy() ); class_("B"); } ===================================================================================== Then, the following works fine (no error) Python 2.3.3 (#3, Mar 8 2004, 11:58:32) [GCC 3.3.3] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> from demo import * >>> a = A() >>> b = a.makeB() >>> type(b) However, if I put class A and class B in two different files (modules) say demo1 and demo2 repectively, I get Python 2.3.3 (#3, Mar 8 2004, 11:58:32) [GCC 3.3.3] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> from demo1 import A >>> from demo2 import B >>> a = A() >>> b = a.makeB() Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class B Do I have to provide an explicit converter ? Can you explain how this can be done ? As usual, any help is greatly appreciated. -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Beam Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From dave at boost-consulting.com Mon Mar 8 22:24:27 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 08 Mar 2004 16:24:27 -0500 Subject: [C++-sig] Re: c++ to python automatic conversion References: Message-ID: Francois Ostiguy writes: > Then, the following works fine (no error) > > Python 2.3.3 (#3, Mar 8 2004, 11:58:32) > [GCC 3.3.3] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. >>>> from demo import * >>>> a = A() >>>> b = a.makeB() >>>> type(b) > > > However, if I put class A and class B in two different files (modules) say > demo1 and demo2 repectively, I get > > Python 2.3.3 (#3, Mar 8 2004, 11:58:32) > [GCC 3.3.3] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. >>>> from demo1 import A >>>> from demo2 import B >>>> a = A() >>>> b = a.makeB() > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No Python class registered for C++ class B > > Do I have to provide an explicit converter ? > Can you explain how this can be done ? > > As usual, any help is greatly appreciated. What compiler did you use to build Boost.Python and your modules? How did you build your modules? Are they both linked to the same libboost_python.so? -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Mon Mar 8 23:03:46 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 8 Mar 2004 14:03:46 -0800 (PST) Subject: [C++-sig] Re: c++ to python automatic conversion In-Reply-To: Message-ID: <20040308220346.93101.qmail@web20212.mail.yahoo.com> This reminds me of the serious trouble I had with FSF gcc (i.e. *not* Apple's port) under Mac OS X. See here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14232 To check if you have a similar same problem edit the file boost/libs/python/src/converter/registry.cpp Somewhere near the top insert: #define BOOST_PYTHON_TRACE_REGISTRY Recompile and relink libboost_python.so. Run your simple test and post the output. I hope this is not it but trying this out will only take a few minutes. Ralf --- David Abrahams wrote: > Francois Ostiguy writes: > > > Then, the following works fine (no error) > > > > Python 2.3.3 (#3, Mar 8 2004, 11:58:32) > > [GCC 3.3.3] on sunos5 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> from demo import * > >>>> a = A() > >>>> b = a.makeB() > >>>> type(b) > > > > > > However, if I put class A and class B in two different files (modules) say > > demo1 and demo2 repectively, I get > > > > Python 2.3.3 (#3, Mar 8 2004, 11:58:32) > > [GCC 3.3.3] on sunos5 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> from demo1 import A > >>>> from demo2 import B > >>>> a = A() > >>>> b = a.makeB() > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: No Python class registered for C++ class B > > > > Do I have to provide an explicit converter ? > > Can you explain how this can be done ? > > > > As usual, any help is greatly appreciated. > > What compiler did you use to build Boost.Python and your modules? > > How did you build your modules? Are they both linked to the same > libboost_python.so? __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree From ostiguy at fnal.gov Tue Mar 9 00:16:16 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Mon, 8 Mar 2004 17:16:16 -0600 (CST) Subject: [C++-sig] Re: c++ to python automatic conversion In-Reply-To: <20040308220346.93101.qmail@web20212.mail.yahoo.com> References: <20040308220346.93101.qmail@web20212.mail.yahoo.com> Message-ID: >What compiler did you use to build Boost.Python and your modules? >How did you build your modules? Are they both linked to the same >libboost_python.so? The modules were built using gcc 3.3. They were also both linked to the same libboost_python ... but inadvertently to the static version (.a) of that library. When I link to libboost_python.so, everything works fine. I suppose the library contains a list of registered classes. Linking with the static version of the lib resulted produced two instances of that list instead of the desired single shared instance. Many Thanks ! -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Beam Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From dave at boost-consulting.com Tue Mar 9 01:02:21 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 08 Mar 2004 19:02:21 -0500 Subject: [C++-sig] Re: c++ to python automatic conversion References: <20040308220346.93101.qmail@web20212.mail.yahoo.com> Message-ID: Francois Ostiguy writes: >>What compiler did you use to build Boost.Python and your modules? > >>How did you build your modules? Are they both linked to the same >>libboost_python.so? > > > > The modules were built using gcc 3.3. They were also both linked to the > same libboost_python ... but inadvertently to the static version (.a) of > that library. When I link to libboost_python.so, everything works fine. > I suppose the library contains a list of registered classes. Linking with > the static version of the lib resulted produced two instances of that list > instead of the desired single shared instance. > > Many Thanks ! Hint: follow the formula that the examples in libs/python/example use. Run bjam with the -n or -d+2 option to see the build/run commands. If you want to use your own build system, just make sure it replicates the same actions. -- Dave Abrahams Boost Consulting www.boost-consulting.com From nicodemus at esss.com.br Tue Mar 9 02:08:23 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 08 Mar 2004 22:08:23 -0300 Subject: [C++-sig] Pyste 1.31.0 and exceptions In-Reply-To: <200403082001.i28K1wj27655@rolex.bbn.com> References: <404CC765.22345.340405DB@localhost> <200403082001.i28K1wj27655@rolex.bbn.com> Message-ID: <404D1907.7060906@esss.com.br> Dan Halbert wrote: > >From: "Niall Douglas" > >On 8 Mar 2004 at 12:12, Dan Halbert wrote: > > > >> foo = AllFromHeader("foo.h") > > > >Last time I heard AllFromHeader() was still not working. > >Actually, it seems to work pretty well for me, though I promise to be >careful. But even if I change my example to what is below, and don't >use AllFromHeader(), I get the same error as I listed previously. --Dan > >============================================== >foo.pyste: > >##foo = AllFromHeader("foo.h") >Function("g", "foo.h") >Class("C", "foo.h") >============================================== >foo.h: > >void g() throw (int); // line #1 >class C { public: void f() throw (int); }; // line #2 >============================================== > > ... > File "/d4m/tools/i686ling/Python-2.3.3/lib/python2.3/site-packages/Pyste/declarations.py", line 226, in Exceptions > return " throw(%s)" % ', '.join (self.throws) >TypeError: sequence item 0: expected string, FundamentalType found > > Thanks for reporting this. A patch that fixes this is applied to CVS. AllFromHeader doesn't work for some classes hierarquies, for simple uses it works fine. I still can't find time to make it work... way too busy. 8( Regards, Nicodemus. Index: declarations.py =================================================================== RCS file: /cvsroot/boost/boost/libs/python/pyste/src/Pyste/declarations.py,v retrieving revision 1.6 diff -r1.6 declarations.py 226c226 < return " throw(%s)" % ', '.join (self.throws) --- > return " throw(%s)" % ', '.join ([x.FullName() for x in self.throws]) 239c239 < return '(%s (*)(%s))&%s' % (result, params, self.FullName()) --- > return '(%s (*)(%s)%s)&%s' % (result, params, self.Exceptions(), self.FullName()) 349c349 < is_public = self.visibility = Scope.public --- > is_public = self.visibility == Scope.public From paul at paulgrenyer.co.uk Tue Mar 9 12:57:52 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Tue, 9 Mar 2004 11:57:52 GMT Subject: [C++-sig] invalid literal for int() Message-ID: <200403091157.i29Bvqh27322@ns.cricketthosting.co.uk> Hi All I've got a bit of a weird one. I'm passing a string value my embedded python environment like this: m_main_namespace[fieldDetails.name.c_str()] = str(); Where fieldDetails.name == "TITLE". I am trying to convert the value of title to an integer inside the python code that is run in the embedded environment: intValue = int( TITLE[0:2] ) but the error I get is: "invalid literal for int()". Anyone know how I can solve this? Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From paul at paulgrenyer.co.uk Tue Mar 9 13:24:42 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Tue, 9 Mar 2004 12:24:42 GMT Subject: [C++-sig] invalid literal for int() Message-ID: <200403091224.i29COgf28918@ns.cricketthosting.co.uk> Hi The plot has just thickened. The following doesn't produce any errors: import string houseno = ADD1[0:2] if TITLE == "MR": if int(houseno) > 0 and int(houseno) < 16: outputFile = "Mr.out" else: outputFile = "rest.out" However, if I remove the first if statement: import string houseno = ADD1[0:2] if int(houseno) > 0 and int(houseno) < 16: outputFile = "Mr.out" else: outputFile = "rest.out" I am back to the "invalid literal for int()" error. I must be doing something very wrong somewhere. Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From dave at boost-consulting.com Tue Mar 9 14:10:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 09 Mar 2004 08:10:26 -0500 Subject: [C++-sig] Re: invalid literal for int() References: <200403091224.i29COgf28918@ns.cricketthosting.co.uk> Message-ID: "Paul Grenyer" writes: > Hi > > The plot has just thickened. The following doesn't produce any errors: > > import string > > houseno = ADD1[0:2] > > if TITLE == "MR": > if int(houseno) > 0 and int(houseno) < 16: > outputFile = "Mr.out" > else: > outputFile = "rest.out" > > However, if I remove the first if statement: > > import string > > houseno = ADD1[0:2] > > if int(houseno) > 0 and int(houseno) < 16: > outputFile = "Mr.out" > else: > outputFile = "rest.out" > > I am back to the "invalid literal for int()" error. > > I must be doing something very wrong somewhere. These are pure Python errors, having nothing to do with C++: >>> int('foo') Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): foo -- Dave Abrahams Boost Consulting www.boost-consulting.com From paul at paulgrenyer.co.uk Tue Mar 9 14:24:26 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Tue, 9 Mar 2004 13:24:26 GMT Subject: [C++-sig] Re: invalid literal for int() Message-ID: <200403091324.i29DOQE32523@ns.cricketthosting.co.uk> Hi Dave > These are pure Python errors, having nothing to do with C++: > > >>> int('foo') > Traceback (most recent call last): > File "", line 1, in ? > ValueError: invalid literal for int(): foo Right. I've rechecked our code. I thought we were just checking syntax; we're not. That explains everything. Thanks! Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From ostiguy at fnal.gov Tue Mar 9 22:17:08 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Tue, 9 Mar 2004 15:17:08 -0600 (CST) Subject: [C++-sig] iterators and abstact base class Message-ID: Hi - This has to be an FAQ. I searched the list archives and I was not able locate a satisfactory solution to the following problem: Assume an abstract base class A and a derived class B. I have an iterator I for a container C holding B-type objects. The iterator returns a pointer to the base class A. At runtime, I.next() returns a type A which cannot be instantiated. I would like to iterate through my container and call a (virtual) function on each element. Can you point me to an idiom/technique that would allow me to accomplish this ? As always, any help is greatly appreciated. -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Beam Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From RaoulGough at yahoo.co.uk Tue Mar 9 23:05:05 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Tue, 09 Mar 2004 22:05:05 +0000 Subject: [C++-sig] Re: Accessing string vector in Python References: Message-ID: "Ron Clarke" writes: > I am trying to wrap a class method (using Boost.Python 1.31, MS VS.NET2003, > Python 2.3) that returns a vector of std::string objects. Here is the C++ > definition: > > typedef std :: vector StringVector; > ... > StringVector* myClass::getOwners() > {... > } Returning the vector via a plain pointer? I guess you've omitted the return policy that this would require. > > When wrapping this method for Python use, I thought I could use the > vector_indexing_suite like so: > BOOST_PYTHON_MODULE(MyModule) > { > ... > class_("StringVector") > .def(vector_indexing_suite() ) > ; > ... > } > > This builds OK, and the StringVector is accessible in Python. However, > Python does not understand the individual elements within the vector. When I > try to access StringVector elements, Python complains: > sv = img.pubDict.getOwners() > for i in range(len(sv)): > print sv[i] > TypeError: No Python class registered for C++ class class > std::basic_string,class > std::allocator > > > How do I get Python to understand/convert to string objects it can handle? I > tried registering a converter, but that wasn't the answer > (implicitly_convertible(); ). > > I cannot make the StringVector contents boost::python::str objects, since > the code being wrapped must also be callable by C++ users. Any suggestions > are greatly appreciated. > > Thanks in advance. Sounds weird to me. Have you tried a very simple function that returns a std::string? The vector indexing suite provides a __getitem__ method that (in this case) will return a string, and that should all just work automatically. Actually, maybe it returns a proxy object for the string - can't exactly remember how the original indexing suite does this... Does something like the following work? std::string get_string () { return std::string ("hello world"); } //... boost::python::def ("get_string", get_string); # in python s = get_string print s This should work, of course. -- Raoul Gough. export LESS='-X' From dave at boost-consulting.com Tue Mar 9 23:34:53 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 09 Mar 2004 17:34:53 -0500 Subject: [C++-sig] Re: iterators and abstact base class References: Message-ID: Francois Ostiguy writes: > Hi - > > This has to be an FAQ. I searched the list archives and I was not able > locate a satisfactory solution to the following problem: > > Assume an abstract base class A and a derived class B. I have an iterator > I for a container C holding B-type objects. The iterator returns a > pointer to the base class A. > At runtime, I.next() ?? This is a standard C++ iterator, or something else?? > returns a type A which cannot be instantiated. Clearly it can't return A; it can return a reference to A, though. > I would like to iterate through my container and call a (virtual) function > on each element. Can you point me to an idiom/technique that would > allow me to accomplish this ? Is this a Python/C++ question, a straight C++ question, or something else? Too many details are missing. -- Dave Abrahams Boost Consulting www.boost-consulting.com From halbert at bbn.com Wed Mar 10 00:43:38 2004 From: halbert at bbn.com (Dan Halbert) Date: Tue, 9 Mar 2004 18:43:38 -0500 Subject: [C++-sig] passing buffer of bytes from Python to C++ Message-ID: <200403092343.i29NhcE30830@rolex.bbn.com> One of the C++ methods I've wrapped with BPL has a signature something like process_data(unsigned char const* buffer, unsigned long buffer_length) In other words, it's just taking a buffer of bytes (it's 8-bit audio data), which I'll be reading from a file or a network connection in Python. I can make the Python data object whatever I want (string, list, tuple), but I see that BPL doesn't convert any of these to a char pointer automatically. Is there a way to generate a simple char* buffer with Python and BPL? Later I'll also want to do the same thing for buffers of 16-bit values, so is that also possible? Thanks, and continuing thanks for putting up with all my questions, Dan From s_sourceforge at nedprod.com Wed Mar 10 01:47:12 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 10 Mar 2004 00:47:12 -0000 Subject: [C++-sig] passing buffer of bytes from Python to C++ In-Reply-To: <200403092343.i29NhcE30830@rolex.bbn.com> Message-ID: <404E6590.3623.5EA7163@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9 Mar 2004 at 18:43, Dan Halbert wrote: > I can make the Python data object whatever I want (string, list, > tuple), but I see that BPL doesn't convert any of these to a char > pointer automatically. Is there a way to generate a simple char* > buffer with Python and BPL? Isn't there a FAQ entry about this? Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQE5lkcEcvDLFGKbPEQJ+UQCfWU+CAKeRGOOjm9xjB3lrCnX9+hYAnR2c IZEhvwK+1aF4cyvnD7UdCp7g =v1ex -----END PGP SIGNATURE----- From dave at boost-consulting.com Wed Mar 10 13:45:34 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 10 Mar 2004 07:45:34 -0500 Subject: [C++-sig] Re: passing buffer of bytes from Python to C++ References: <200403092343.i29NhcE30830@rolex.bbn.com> Message-ID: Dan Halbert writes: > One of the C++ methods I've wrapped with BPL has a signature something like > > process_data(unsigned char const* buffer, unsigned long buffer_length) > > In other words, it's just taking a buffer of bytes (it's 8-bit audio > data), which I'll be reading from a file or a network connection in > Python. > > I can make the Python data object whatever I want (string, list, > tuple), but I see that BPL doesn't convert any of these to a char > pointer automatically. Is there a way to generate a simple char* > buffer with Python and BPL? Python strings will be automatically converted to char const* ^^^^^ > Later I'll also want to do the same thing for buffers of 16-bit > values, so is that also possible? I'm afraid there's only a conversion from Python unicode strings to std::wstring, but not to wchar_t const*. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ak at ixion.net Wed Mar 10 13:52:53 2004 From: ak at ixion.net (Andreas Kloeckner) Date: Wed, 10 Mar 2004 13:52:53 +0100 Subject: [C++-sig] Tutorial example for derivation in python doesn't work Message-ID: <20040310125253.GA2548@aramis.ath.cx> Hi all, I've tried to use python-implemented C++ interfaces as described in the tutorial, with no luck. More specifically, I tried to just redo the example described in the tutorial pages "Class Virtual Functions" and "Deriving a Python Class". I copied-and-pasted the examples there into two files (which you can find attached to this email, along with my build script), built them, and voila, I get the following error message: Traceback (most recent call last): File "virtual_functions.py", line 7, in ? print call_f(Derived()) RuntimeError: This class cannot be instantiated from Python Upon giving the derived class an __init__ function as commented out below, the error changes to: Traceback (most recent call last): File "virtual_functions.py", line 9, in ? print call_f(Derived()) Boost.Python.ArgumentError: Python argument types in virtual_functions_ext.call_f(Derived) did not match C++ signature: call_f(Base {lvalue}) My configuration is Boost 1.31.0 Python 2.3.3 gcc 3.3.3 Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: virtual_functions.cpp Type: text/x-c++src Size: 458 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: virtual_functions.py Type: application/x-python Size: 145 bytes Desc: not available URL: -------------- next part -------------- #!/bin/bash g++-3.3 -shared -I$HOME/pool/include/python2.3 -I$HOME/work/boost $1.cpp -o $1_ext.so -lboost_python From ostiguy at fnal.gov Wed Mar 10 17:10:08 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Wed, 10 Mar 2004 10:10:08 -0600 (CST) Subject: [C++-sig] Re: iterators and abstact base class In-Reply-To: References: Message-ID: On Tue, 9 Mar 2004, David Abrahams wrote: > > Hi - > > > > This has to be an FAQ. I searched the list archives and I was not able > > locate a satisfactory solution to the following problem: > > > > Assume an abstract base class A and a derived class B. I have an iterator > > I for a container C holding B-type objects. The iterator returns a > > pointer to the base class A. > > At runtime, I.next() > > ?? This is a standard C++ iterator, or something else?? > > > returns a type A which cannot be instantiated. > > Clearly it can't return A; it can return a reference to A, though. > > > I would like to iterate through my container and call a (virtual) function > > on each element. Can you point me to an idiom/technique that would > > allow me to accomplish this ? > > Is this a Python/C++ question, a straight C++ question, or something > else? Too many details are missing. > Sorry for not being specific enough. This is really a boost.python question. The iterator is a custom iterator (the code was written in the early 1990s) which returns a pointer to the base class. Of course, the object returned is always an instance of a derived class. So if class C is my container class and next is the "iterator" class A; // abstract class class B: public A { ... }; C c; // container class, contains objects instances of // classes derived from A ... Iterator i(c); A* a = i. next(); // generic way to retrieve the next element in the container a.function(); // calls a virtual function on the element I want to achieve in python b1 = B(..) # appropriate contructor b2 = B(..) # c = C(b1, b2) # constructs a C which contains b1 and b2 i = I(c) # i is an iterator for c a = i.next() <<<<==== this is the problem. i.next() must return something that can be held into python object a. In C++ i.next() returns a type A*. a.function() ... How do I define a python type that can be used to hold what i.next() returns ? As always, your help is greatly appreciated. -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Beam Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From dave at boost-consulting.com Wed Mar 10 20:29:17 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 10 Mar 2004 14:29:17 -0500 Subject: [C++-sig] Re: iterators and abstact base class References: Message-ID: Francois Ostiguy writes: > Sorry for not being specific enough. This is really a boost.python > question. The iterator is a custom iterator (the code was written > in the early 1990s) which returns a pointer to the base class. > Of course, the object returned is always an instance of a derived class. > So if class C is my container class and next is the "iterator" > > class A; // abstract class > class B: public A { > ... > }; > > C c; // container class, contains objects instances of > // classes derived from A > ... > > Iterator i(c); > > A* a = i. next(); // generic way to retrieve the next element in the > container > a.function(); // calls a virtual function on the element Surely it's a->function(); ?? > I want to achieve in python > > b1 = B(..) # appropriate contructor > b2 = B(..) # > c = C(b1, b2) # constructs a C which contains b1 and b2 > i = I(c) # i is an iterator for c > > a = i.next() <<<<==== this is the problem. i.next() must return something > that can be held into python object a. In C++ > i.next() returns a type A*. > > a.function() > > ... > > How do I define a python type that can be used to hold what i.next() returns ? I don't understand the problem. Why not wrap "A" using class_; then wrap next() with reference_existing_object or another appropriate call policy? -- Dave Abrahams Boost Consulting www.boost-consulting.com From mikeowen at llnl.gov Thu Mar 11 02:47:13 2004 From: mikeowen at llnl.gov (J. Michael Owen) Date: Wed, 10 Mar 2004 17:47:13 -0800 Subject: [C++-sig] Cross module inheritance failing with the Intel compiler on Linux Message-ID: I'm trying to use the Intel C++ complier (7.0) on Linux with Boost.Python (latest release, 1.31.0), but running into problems with cross module inheritance. At the end of this message I've appended a stripped down example of the problem in 4 files: A.hh, B.hh, A.cc, and B.cc. A.hh defines a base class "Base", while B.hh defines a class "Derived" which inherits publicly from "Base". I compile these into two separate modules (A.cc -> A.so, B.cc -> B.so), and then fire up python and execute the following: >>> import A >>> import B If I build everything with g++ all is fine and I can use the "Derived" class in python. However, if I build with Intel's icc (both Boost.Python and this example code of course) everything compiles, but I get the following run time error: >>> import A >>> import B Traceback (most recent call last): File "", line 1, in ? RuntimeError: extension class wrapper for base class 4Base has not been created yet >>> Are other folks successfully using Intel icc with Boost.Python? Does anyone have any suggestions how I could correct this problem? Thanks! Mike. ************************************ A.hh ************************************** #include class Base { public: Base() { std::cerr << "Base()" << std::endl; } virtual ~Base() { std::cerr << "~Base()" << std::endl;} virtual void printMessage() const { std::cerr << "Base instance @ " << this << std::endl; } }; ************************************ B.hh ************************************** #include #include "A.hh" class Derived: public Base { public: Derived(): Base() { std::cerr << "Derived()" << std::endl; } virtual ~Derived() { std::cerr << "~Derived()" << std::endl;} virtual void printMessage() const { std::cerr << "Derived instance @ " << this << std::endl; } }; ************************************ A.cc ************************************** #include "A.hh" #include using namespace boost::python; BOOST_PYTHON_MODULE(A) { class_("Base", init<>()) .def("printMessage", &Base::printMessage) ; } ************************************ B.cc ************************************** #include "B.hh" #include using namespace boost::python; BOOST_PYTHON_MODULE(B) { class_ >("Derived", init<>()); } ******************************************************************************** -- "Hey...where are the sunflower seeds?" | J. Michael Owen o_o / | (") | Email: mikeowen at llnl.gov \/'\/ | ____(__(,_,)_______________________________________________________________ From rwgk at yahoo.com Thu Mar 11 05:40:17 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 10 Mar 2004 20:40:17 -0800 (PST) Subject: [C++-sig] Cross module inheritance failing with the Intel compiler on Linux In-Reply-To: Message-ID: <20040311044017.91244.qmail@web20203.mail.yahoo.com> --- "J. Michael Owen" wrote: > >>> import A > >>> import B > Traceback (most recent call last): > File "", line 1, in ? > RuntimeError: extension class wrapper for base class 4Base has not been > created yet > >>> I can reproduce the error with this compiler: Intel(R) C++ Compiler for 32-bit applications, Version 7.1 Build 20031225Z But it works with this compiler: Intel(R) C++ Compiler for 32-bit applications, Version 8.0 Build 20040122Z Package ID: l_cc_pc_8.0.058_pe059 >>> import A >>> import B >>> B.Derived() Base() Derived() >>> ~Derived() ~Base() I know cross-module inheritance works with Intel 7.1 for non-virtual classes. I don't have any idea what to do about the failure for virtual classes. Can you switch to the 8.0 compiler? Ralf __________________________________ Do you Yahoo!? Yahoo! Search - Find what you?re looking for faster http://search.yahoo.com From rwgk at yahoo.com Thu Mar 11 09:03:51 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 11 Mar 2004 00:03:51 -0800 (PST) Subject: [C++-sig] Cross module inheritance failing with the Intel compiler on Linux In-Reply-To: <20040311044017.91244.qmail@web20203.mail.yahoo.com> Message-ID: <20040311080351.18704.qmail@web20203.mail.yahoo.com> --- "Ralf W. Grosse-Kunstleve" wrote: > I know cross-module inheritance works with Intel 7.1 for non-virtual classes. I guess it doesn't make a difference to the OP, but to set the record straight I have to correct myself. All my non-virtual inheritance relationships don't cross module boundaries. The original problem persists even for non-virtual classes. Anyway, I think I have the solution: compile everything with -DBOOST_PYTHON_TYPE_ID_NAME Alternatively, change boost/boost/python/type_id.hpp so the code starting at line 32 looks like this: # if (defined(__GNUC__) && __GNUC__ >= 3) \ || defined(_AIX) \ || ( defined(__sgi) && defined(__host_mips)) \ || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC)) # define BOOST_PYTHON_TYPE_ID_NAME # endif David, what do you think about the defines that I chose? Ralf __________________________________ Do you Yahoo!? Yahoo! Search - Find what you?re looking for faster http://search.yahoo.com From Holger.Joukl at LBBW.de Thu Mar 11 10:28:15 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Thu, 11 Mar 2004 10:28:15 +0100 Subject: [C++-sig] boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) Message-ID: Hi, Jamfile seems to work like this: Jamfile entry ---translates to---> build/link command line /include/path ---> -I/include/path /path/name---> -L/path/name mylib ---> -lmylib How can I set a runtime library dir? I did not find the information in the docs, nor did the boost *.jam files help me much. Any hint on how to do that (or where to find the proper documentation) is appreciated! Thanks, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From dave at boost-consulting.com Thu Mar 11 12:45:37 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 06:45:37 -0500 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) References: Message-ID: "Holger Joukl" writes: > Hi, > Jamfile seems to work like this: > Jamfile entry ---translates to---> build/link command line > > /include/path ---> -I/include/path > /path/name---> -L/path/name > mylib ---> -lmylib > > How can I set a runtime library dir? I did not find the information > in the docs, nor did the boost *.jam files help me much. Any hint > on how to do that (or where to find the proper documentation) is > appreciated! Thanks, Holger What do you mean by "a runtime library dir"? Please illustrate with specific command-line elements. Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com From Holger.Joukl at LBBW.de Thu Mar 11 13:36:34 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Thu, 11 Mar 2004 13:36:34 +0100 Subject: [C++-sig] Re: Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) Message-ID: Hi, sorry if the terminology is wrong/unclear. What I meant is the library search path for the runtime linker, given to gcc with the -R flag: E.g. g++ -o myProg -L /my/strange/dir -R /my/strange/dir -lmyStrangeLib main.o funcs.o Just to get rid of LD_LIBRARY_PATH, I am looking for the Jamfile equivalent of "-R /my/strange/dir" on the commandline. I guess it is possible to make such a search path known in a Jamfile, but I didn?t see the solution. Thanks, Holger _________________________________ Holger Joukl Landesbank Baden-W?rttemberg 1651 Financial Markets Technologies fon +49 (711) 124 - 7078 fax +49 (711) 124 - 3759 _________________________________ Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From dave at boost-consulting.com Thu Mar 11 15:09:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 09:09:50 -0500 Subject: [C++-sig] Re: Cross module inheritance failing with the Intel compiler on Linux References: Message-ID: "J. Michael Owen" writes: > I'm trying to use the Intel C++ complier (7.0) on Linux with Boost.Python > (latest release, 1.31.0), but running into problems with cross module > inheritance. At the end of this message I've appended a stripped down example > of the problem in 4 files: A.hh, B.hh, A.cc, and B.cc. A.hh defines a base > class "Base", while B.hh defines a class "Derived" which inherits publicly from > "Base". I compile these into two separate modules (A.cc -> A.so, B.cc -> B.so), > and then fire up python and execute the following: > >>>> import A >>>> import B > > If I build everything with g++ all is fine and I can use the "Derived" class in > python. However, if I build with Intel's icc (both Boost.Python and this > example code of course) everything compiles, but I get the following run time > error: > >>>> import A >>>> import B > Traceback (most recent call last): > File "", line 1, in ? > RuntimeError: extension class wrapper for base class 4Base has not been created yet >>>> > > Are other folks successfully using Intel icc with Boost.Python? Does anyone > have any suggestions how I could correct this problem? Here's the story: I don't know about Intel 7.0. In the latest release, we added the feature to Boost.Build in order to allow us to use Intel 8.x with the GCC standard library (-cxxlib-gcc ICC command-line option). This was unfortunately needed in order to get extensions built with Intel 8.x to work with a stock (GCC-built) Python on Linux. Unfortunately, the -cxxlib-gcc feature is broken in Intel 7.1, so the strategem fails. If you want to use a Python built with the Intel compiler, you should use a Boost.Python library built with default instead of gcc in your bjam BUILD variable. I *think* that'll work with Intel 7.x, but I can't promise. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Mar 11 15:11:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 09:11:26 -0500 Subject: [C++-sig] Re: Cross module inheritance failing with the Intel compiler on Linux References: <20040311044017.91244.qmail@web20203.mail.yahoo.com> <20040311080351.18704.qmail@web20203.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > Anyway, I think I have the solution: compile everything with > > -DBOOST_PYTHON_TYPE_ID_NAME > > Alternatively, change > > boost/boost/python/type_id.hpp > > so the code starting at line 32 looks like this: > > # if (defined(__GNUC__) && __GNUC__ >= 3) \ > || defined(_AIX) \ > || ( defined(__sgi) && defined(__host_mips)) \ > || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC)) > # define BOOST_PYTHON_TYPE_ID_NAME > # endif > > David, what do you think about the defines that I chose? Did you test this with Intel 7.1 by running the Boost.Python regressions? I'd be surprised if it worked; I could've sworn it was the first thing I checked when trying to solve this problem. IIRC we still have problems with exception handling. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Mar 11 15:23:05 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 09:23:05 -0500 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) References: Message-ID: "Holger Joukl" writes: > Hi, > sorry if the terminology is wrong/unclear. > What I meant is the library search path for the runtime linker, > given to gcc with the -R flag: > E.g. > g++ -o myProg -L /my/strange/dir -R /my/strange/dir -lmyStrangeLib main.o > funcs.o > > Just to get rid of LD_LIBRARY_PATH, I am looking for the Jamfile equivalent > of > "-R /my/strange/dir" on the commandline. > I guess it is possible to make such a search path known in a Jamfile, but I > didn?t see > the solution. I'm afraid I don't know. I've never heard of the "-R" option before; Boost.Build uses LD_LIBRARY_PATH to prepare the search path for the runtime linker. -- Dave Abrahams Boost Consulting www.boost-consulting.com From halbert at bbn.com Thu Mar 11 15:58:29 2004 From: halbert at bbn.com (Dan Halbert) Date: Thu, 11 Mar 2004 09:58:29 -0500 Subject: [C++-sig] Re: passing buffer of bytes from Python to C++ In-Reply-To: (message from David Abrahams on Wed, 10 Mar 2004 07:45:34 -0500) References: <200403092343.i29NhcE30830@rolex.bbn.com> Message-ID: <200403111458.i2BEwTO02178@rolex.bbn.com> >From: David Abrahams >Dan Halbert writes: > >> One of the C++ methods I've wrapped with BPL has a signature something like >> >> process_data(unsigned char const* buffer, unsigned long buffer_length) > >Python strings will be automatically converted to char const* Thanks, David. Just to provide closure here, the problem I had was the "unsigned char", which is not converted automatically, though "char" is. I have wrapped the method to avoid this. Dan From Holger.Joukl at LBBW.de Thu Mar 11 16:09:05 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Thu, 11 Mar 2004 16:09:05 +0100 Subject: [C++-sig] Re: Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) Message-ID: >Dave wrote: >I'm afraid I don't know. I've never heard of the "-R" option before; >Boost.Build uses LD_LIBRARY_PATH to prepare the search path for the >runtime linker. Wouldn?t that mean you always have to set the LD_LIBRARY_PATH when importing an extension module that e.g. wraps a 3rd party library that is not installed in /usr/lib? Same thing for libboost_python.so, must be in a standard place or it?s LD_LIBRARY_PATH again. I created such an extension module with bjam: When I elfdump or ldd the resulting shared object, there is no information about where to find the libraries it depends on (including libboost_python.so). Can I maybe pass the "-R ..." information as ? Thanks, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From grafik.list at redshift-software.com Thu Mar 11 16:32:23 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 11 Mar 2004 09:32:23 -0600 Subject: [C++-sig] Re: Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) In-Reply-To: References: Message-ID: <40508687.8040401@redshift-software.com> Holger Joukl wrote: >>Dave wrote: >>I'm afraid I don't know. I've never heard of the "-R" option before; >>Boost.Build uses LD_LIBRARY_PATH to prepare the search path for the >>runtime linker. > > > Wouldn?t that mean you always have to set the LD_LIBRARY_PATH when > importing > an extension module that e.g. wraps a 3rd party library that is not > installed > in /usr/lib? Don't think so, as Python uses different search path for dynamically loading modules. > Same thing for libboost_python.so, must be in a standard place or it?s > LD_LIBRARY_PATH again. Yes to that. But this is something that installers (like RPM) do for you by running ldconfig, or equivalent. > I created such an extension module with bjam: > When I elfdump or ldd the resulting shared object, there is no information > about > where to find the libraries it depends on (including libboost_python.so). Correct, and that's likely the optimal design as it makes the modules transportable. Which means you can install them to your preferred location instead of whatever the location you decided upon when they got built. > Can I maybe pass the "-R ..." information as ? You can use "", but be warned this is platform and linker specific. For example you call the -R flag but for the GNU linker it really should be the -rpath flag, and you must pass it to the linker with "-Wl,-rpath,". -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From dave at boost-consulting.com Thu Mar 11 16:41:09 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 10:41:09 -0500 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) References: <40508687.8040401@redshift-software.com> Message-ID: Rene Rivera writes: > Holger Joukl wrote: >>>Dave wrote: >>>I'm afraid I don't know. I've never heard of the "-R" option before; >>>Boost.Build uses LD_LIBRARY_PATH to prepare the search path for the >>>runtime linker. >> Wouldn?t that mean you always have to set the LD_LIBRARY_PATH when >> importing >> an extension module that e.g. wraps a 3rd party library that is not >> installed >> in /usr/lib? > > Don't think so, as Python uses different search path for dynamically > loading modules. I don't think you understood. If the module wraps a 3rd party .so, that must be in LD_LIBRARY_PATH. >> Same thing for libboost_python.so, must be in a standard place or it?s >> LD_LIBRARY_PATH again. > > Yes to that. But this is something that installers (like RPM) do for > you by running ldconfig, or equivalent. > >> I created such an extension module with bjam: When I elfdump or ldd >> the resulting shared object, there is no information about where to >> find the libraries it depends on (including libboost_python.so). > > Correct, and that's likely the optimal design as it makes the modules > transportable. Which means you can install them to your preferred > location instead of whatever the location you decided upon when they > got built. Right. Most people don't want absolute paths to libraries encoded in their objects. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ingo at fargonauten.de Thu Mar 11 16:55:08 2004 From: ingo at fargonauten.de (Ingo Luetkebohle) Date: Thu, 11 Mar 2004 16:55:08 +0100 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) In-Reply-To: References: <40508687.8040401@redshift-software.com> Message-ID: <1079020508.9245.11.camel@localhost> Am Do, den 11.03.2004 schrieb David Abrahams um 16:41: > Right. Most people don't want absolute paths to libraries encoded in > their objects. While that might be so, it says nothing about ld's '-R' (or '-rpath' on Linux) option. That option prepends a directory to the run-time linker search path. There is no absolute path to a library, the library is searched as usual, but in additional locations. Most people I know prefer that to LD_LIBRARY_PATH very much ;-) One reason is that it can be applied to a single shared object or executable, instead of applying unconditionally to everything. Like, "for *this* library, look in '/usr/local/boost/lib' for additional dependencies". Another pro is that it works with setuid binaries while LD_LIBRARY_PATH usually does not, for obvious reasons. While moving libraries is an issue, one can always re-link with a different RPATH. libtool does that, for example. regards -- Ingo Soll doch jeder bleiben, wie er gerne w?re. From grafik.list at redshift-software.com Thu Mar 11 17:25:46 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 11 Mar 2004 10:25:46 -0600 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) In-Reply-To: <1079020508.9245.11.camel@localhost> References: <40508687.8040401@redshift-software.com> <1079020508.9245.11.camel@localhost> Message-ID: <4050930A.3010903@redshift-software.com> Ingo Luetkebohle wrote: > Am Do, den 11.03.2004 schrieb David Abrahams um 16:41: > >>Right. Most people don't want absolute paths to libraries encoded in >>their objects. > > > While that might be so, it says nothing about ld's '-R' (or '-rpath' on > Linux) option. That option prepends a directory to the run-time linker > search path. There is no absolute path to a library, the library is > searched as usual, but in additional locations. I'm sorry but that makes no sense to me :-( Yes you can add search locations, but you can't predict all the search locations that a user might want to move a library to. For example I prefer to install all libraries of a program with the program, and there is no way to predict where that is. > Most people I know prefer that to LD_LIBRARY_PATH very much ;-) Most people don't know about the alternatives available with ELF linker-loaders ;-) > One reason is that it can be applied to a single shared object or > executable, instead of applying unconditionally to everything. Like, > "for *this* library, look in '/usr/local/boost/lib' for additional > dependencies". But it would not know to search.. "/home/user/boost_1_31_0/lib" > Another pro is that it works with setuid binaries while LD_LIBRARY_PATH > usually does not, for obvious reasons. And for good reason... ldconfig, and other system level configuration of the load search path and library cache is the preferred way to manage that. > While moving libraries is an issue, one can always re-link with a > different RPATH. libtool does that, for example. You can only relink if you have a linker. So if you only distribute binaries you are out of luck. I went over all these issues and more a long time ago in trying to figure out how to manage distribution for my current project and there are many things I can say about the Unix/Linux link loading model, but the nicest I can say is that it's broken. In the end I resorted to using the highly under documented feature of ELF for adding searchs paths relative to the loading module. So now I can get the effect I have on Windows of adding the location of my executable (or any other relative subdir) to the library search path... <*>-Wl,-rpath,'${ORIGIN}' -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From rwgk at yahoo.com Thu Mar 11 18:19:10 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 11 Mar 2004 09:19:10 -0800 (PST) Subject: [C++-sig] Re: Cross module inheritance failing with the Intel compiler on Linux In-Reply-To: Message-ID: <20040311171910.46706.qmail@web20207.mail.yahoo.com> --- David Abrahams wrote: > Did you test this with Intel 7.1 by running the Boost.Python > regressions? I'd be surprised if it worked; I could've sworn it was > the first thing I checked when trying to solve this problem. IIRC we > still have problems with exception handling. I just re-did the tests with Intel 7.1 (using my type_id.hpp patch) and they all work except for crossmod_exception.py, as you expect. At the moment I am thinking: - Mike's example tells us that we should be using BOOST_PYTHON_TYPE_ID_NAME - BOOST_PYTHON_TYPE_ID_NAME does not affect EH Correct? As an aside, I am also thinking that Intel 8.0 works for Mike's example because it defines __GNUC__ which leads to BOOST_PYTHON_TYPE_ID_NAME being defined. Does this make sense? Ralf __________________________________ Do you Yahoo!? Yahoo! Search - Find what you?re looking for faster http://search.yahoo.com From ostiguy at fnal.gov Thu Mar 11 18:43:16 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Thu, 11 Mar 2004 11:43:16 -0600 (CST) Subject: [C++-sig] Re: iterators and abstact base class In-Reply-To: References: Message-ID: On Wed, 10 Mar 2004, David Abrahams wrote: > > I want to achieve in python > > > > b1 = B(..) # appropriate contructor > > b2 = B(..) # > > c = C(b1, b2) # constructs a C which contains b1 and b2 > > i = I(c) # i is an iterator for c > > > > a = i.next() <<<<==== this is the problem. i.next() must return something > > that can be held into python object a. In C++ > > i.next() returns a type A*. > > > > a.function() > > > > ... > > > > How do I define a python type that can be used to hold what i.next() returns ? > > I don't understand the problem. Why not wrap "A" using class_; then > wrap next() with reference_existing_object or another appropriate call > policy? > I am affraid the problem is sitting in front of my keyboard. I guess I did not fully appreciate the fact that introspection allows one to determine the dynamic type of an object and to return a reference to the full type intead of a reference to a base class object. Thanks again! -Francois ---------------------------------------------------------------------------- Dr. Jean-Francois OSTIGUY voice: (630) 840-2231 Beam Physics Dept MS220 FAX: (630) 840-6039 Fermi National Accelerator Laboratory email: ostiguy at fnal.gov Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy From dholth at fastmail.fm Thu Mar 11 19:40:24 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Thu, 11 Mar 2004 13:40:24 -0500 Subject: [C++-sig] Pyste add_method() Message-ID: <1079030423.10839.10.camel@bluefish> I think I've found the solution to my old problem: sync = Class("ogg::sync", "oggcc.h") # part 1 syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h") # part 2 add_method(sync, "ogg::sync_write") rename(sync.sync_write, "write") exclude(syncwrite) Doesn't work for me: it will say something like: RuntimeError: no ogg::sync_write declaration found! Instead, if I say the class is in the file that declares the wrapper, (oggpy_wrappers.h also includes oggcc.h): sync = Class("ogg::sync", "oggpy_wrappers.h") (insert part 2 here) it works nicely. - Daniel Holth From dave at boost-consulting.com Thu Mar 11 21:09:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 11 Mar 2004 15:09:26 -0500 Subject: [C++-sig] Re: Cross module inheritance failing with the Intel compiler on Linux References: <20040311171910.46706.qmail@web20207.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- David Abrahams wrote: >> Did you test this with Intel 7.1 by running the Boost.Python >> regressions? I'd be surprised if it worked; I could've sworn it was >> the first thing I checked when trying to solve this problem. IIRC we >> still have problems with exception handling. > > I just re-did the tests with Intel 7.1 (using my type_id.hpp patch) and they > all work except for crossmod_exception.py, as you expect. > At the moment I am thinking: > > - Mike's example tells us that we should be using BOOST_PYTHON_TYPE_ID_NAME > > - BOOST_PYTHON_TYPE_ID_NAME does not affect EH > > Correct? > > As an aside, I am also thinking that Intel 8.0 works for Mike's example because > it defines __GNUC__ which leads to BOOST_PYTHON_TYPE_ID_NAME being defined. > Does this make sense? Yep, I buy your theories. Please feel free to make patches at will. -- Dave Abrahams Boost Consulting www.boost-consulting.com From nicodemus at esss.com.br Fri Mar 12 01:53:37 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Thu, 11 Mar 2004 21:53:37 -0300 Subject: [C++-sig] Pyste add_method() In-Reply-To: <1079030423.10839.10.camel@bluefish> References: <1079030423.10839.10.camel@bluefish> Message-ID: <40510A11.2060803@esss.com.br> Daniel Holth wrote: >I think I've found the solution to my old problem: > >sync = Class("ogg::sync", "oggcc.h") # part 1 > >syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h") # part 2 >add_method(sync, "ogg::sync_write") >rename(sync.sync_write, "write") >exclude(syncwrite) > >Doesn't work for me: it will say something like: >RuntimeError: no ogg::sync_write declaration found! > >Instead, if I say the class is in the file that declares the wrapper, >(oggpy_wrappers.h also includes oggcc.h): > >sync = Class("ogg::sync", "oggpy_wrappers.h") > >(insert part 2 here) > >it works nicely. > > That's correct. I posted the same solution in response to a post from Hanz Meizer a few weeks ago. 8) Regards, Nicodemus. From colin_irwin at hotmail.com Fri Mar 12 05:44:22 2004 From: colin_irwin at hotmail.com (Colin Irwin) Date: Fri, 12 Mar 2004 15:44:22 +1100 Subject: [C++-sig] boost.python problem: 'virtual functions and default implementations' tutorial doesn't work Message-ID: I'm having a problem following the tutorial that comes with the Boost::Python library, in particular defining virtual functions with default implementations. I've been using this as a test, as I have a set of C++ classes that I want to be available in Python. These classes use a top-level interface that has callback functions in the style of inheritable functions. I would like to be able to define a Python class, deriving this off the C++ top-level interface class and in particular inheriting these callback functions to deal with certain events. I have a test setup as follows (which pretty much follows the tutorial example) and I've tried to compile it using MSVC .NET 2003 (v7.1) with Boost 1.31.0: class Base { public: virtual void function(); }; class BaseWrapper : public Base { public: BaseWrapper(PyObject* self_) : self(self_) { } virtual void function() { call_method(this->self, "function"); }; void default_function() { Base::function(); }; private: PyObject* self; }; BOOST_PYTHON_MODULE(test_module) { class_("Base") .def("function", &Base::function, &BaseWrapper::default_function) ; } When I compile it, I get the following error: ..\..\42_External_Units\421_Boost\boost\python\object\value_holder.hpp(137) : error C2661: 'BaseWrapper::BaseWrapper' : no overloaded function takes 2 arguments ... (a whole set of 'while compiling...') ... test.cpp(35) : see reference to class template instantiation 'boost::python::class_' being compiled with [ T=Base, X1=BaseWrapper ] I've been able to resolve the error by using the following python module definition instead: BOOST_PYTHON_MODULE(test_module) { class_("Base") .def("function", &Base::function, &BaseWrapper::default_function) ; } Now this noncopyable is not mentioned in the tutorial file and indeed, I don't think it does exactly what I want in this case. By this I mean it prevents copying any of the derived objects in Python doesn't it? Where have I gone wrong? The tutorial file doesn't seem to work as expected. My fix doesn't do what I want it do (I think this is right, if I've inadvertently prevented copying). How should I structure my module definition/code? TIA Colin From colin_irwin at hotmail.com Tue Mar 9 06:58:38 2004 From: colin_irwin at hotmail.com (Colin Irwin) Date: Tue, 9 Mar 2004 16:58:38 +1100 Subject: [C++-sig] Virtual functions and default implementations (Boost::Python tutorial example doesn't work) Message-ID: I'm having a problem following the tutorial that comes with the Boost::Python library, in particular defining virtual functions with default implementations. I've been using this as a test, as I have a set of C++ classes that I want to be available in Python. These classes use a top-level interface that has callback functions in the style of inheritable functions. I would like to be able to define a Python class, deriving this off the C++ top-level interface class and in particular inheriting these callback functions to deal with certain events. I have a test setup as follows (which pretty much follows the tutorial example) and I've tried to compile it using MSVC .NET 2003 (v7.1) with Boost 1.31.0: class Base { public: virtual void function(); }; class BaseWrapper : public Base { public: BaseWrapper(PyObject* self_) : self(self_) { } virtual void function() { call_method(this->self, "function"); }; void default_function() { Base::function(); }; private: PyObject* self; }; BOOST_PYTHON_MODULE(test_module) { class_("Base") .def("function", &Base::function, &BaseWrapper::default_function) ; } When I compile it, I get the following error: ..\..\42_External_Units\421_Boost\boost\python\object\value_holder.hpp(137) : error C2661: 'BaseWrapper::BaseWrapper' : no overloaded function takes 2 arguments ... (a whole set of 'while compiling...') ... test.cpp(35) : see reference to class template instantiation 'boost::python::class_' being compiled with [ T=Base, X1=BaseWrapper ] I've been able to resolve the error by using the following python module definition instead: BOOST_PYTHON_MODULE(test_module) { class_("Base") .def("function", &Base::function, &BaseWrapper::default_function) ; } Now this noncopyable is not mentioned in the tutorial file and indeed, I don't think it does exactly what I want in this case. By this I mean it prevents copying any of the derived objects in Python doesn't it? Where have I gone wrong? The tutorial file doesn't seem to work as expected. My fix doesn't do what I want it do (I think this is right, if I've inadvertently prevented copying). How should I structure my module definition/code? TIA Colin From Holger.Joukl at LBBW.de Fri Mar 12 09:18:27 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Fri, 12 Mar 2004 09:18:27 +0100 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) Message-ID: Rene wrote: >feature of ELF for adding searchs paths relative to the loading module.. So now >I can get the effect I have on Windows of adding the location of my executable >(or any other relative subdir) to the library search path... > <*>-Wl,-rpath,'${ORIGIN}' If I understand correctly, this translate to an equivalent to "gcc -R<$ORIGIN>" with $ORIGIN being a relative path -- that is, simply using -R option with relative paths. While being fine for executables, I suspect that this is not really appropriate for boost.python wrapped libraries, where - libboost_python.so would probably reside in $PYTHON_ROOT/lib/python2.x/site-packages - the wrapper library shared object would probably reside in $PYTHON_ROOT/lib/python2.x/site-packages - the wrapped library resides anywhere on your system Running python and using this extension is now dependant from where you invoke the interpreter; it will only work if the wrapped lib can be found in the relative path $ORIGIN. So it is either LD_LIBRARY_PATH again (not good) or adding some search paths with -R in the link step, the search paths being s.th. like site-dependant standard library installation directories. E.g. a shared filesystem named /apps/prod where I would install central components (like python :-) Anyway, thanks a lot for all the hints! Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From pierre.barbier at cirad.fr Fri Mar 12 09:37:18 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Fri, 12 Mar 2004 09:37:18 +0100 Subject: [C++-sig] boost.python problem: 'virtual functions and default implementations' tutorial doesn't work In-Reply-To: References: Message-ID: <1079080638.1024.1.camel@pbarbier> The problem comes from a change in the handling of the copy constructor in Boost.Python. Now, if you want to have a copy contructor for your class, you have to write a contructor in your wrapper as : BaseWrapper( PyObject* self_, const Base& copy); In fact, for every constructor you have, you need to add a first argument being the PyObject* of the current object. Pierre Le ven 12/03/2004 ? 05:44, Colin Irwin a ?crit : > I'm having a problem following the tutorial that comes with the > Boost::Python library, in particular defining virtual functions with default > implementations. I've been using this as a test, as I have a set of C++ > classes that I want to be available in Python. These classes use a > top-level interface that has callback functions in the style of inheritable > functions. I would like to be able to define a Python class, deriving this > off the C++ top-level interface class and in particular inheriting these > callback functions to deal with certain events. I have a test setup as > follows (which pretty much follows the tutorial example) and I've tried to > compile it using MSVC .NET 2003 (v7.1) with Boost 1.31.0: > > class Base > { > public: > virtual void function(); > }; > > class BaseWrapper : public Base > { > public: > BaseWrapper(PyObject* self_) : > self(self_) { } > virtual void function() { call_method(this->self, > "function"); }; > void default_function() { Base::function(); }; > > private: > PyObject* self; > }; > > BOOST_PYTHON_MODULE(test_module) > { > > class_("Base") > .def("function", &Base::function, &BaseWrapper::default_function) > ; > } > > When I compile it, I get the following error: > ..\..\42_External_Units\421_Boost\boost\python\object\value_holder.hpp(137) > : error C2661: 'BaseWrapper::BaseWrapper' : no overloaded function takes 2 > arguments > > ... (a whole set of 'while compiling...') ... > > test.cpp(35) : see reference to class template instantiation > 'boost::python::class_' being compiled > > with > > [ > > T=Base, > > X1=BaseWrapper > > ] > > > > I've been able to resolve the error by using the following python module > definition instead: > > BOOST_PYTHON_MODULE(test_module) > { > > class_("Base") > .def("function", &Base::function, &BaseWrapper::default_function) > ; > } > > Now this noncopyable is not mentioned in the tutorial file and indeed, I > don't think it does exactly what I want in this case. By this I mean it > prevents copying any of the derived objects in Python doesn't it? > Where have I gone wrong? The tutorial file doesn't seem to work as > expected. My fix doesn't do what I want it do (I think this is right, if > I've inadvertently prevented copying). How should I structure my module > definition/code? > > TIA > > Colin > > > > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From grafik.list at redshift-software.com Fri Mar 12 10:01:20 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Fri, 12 Mar 2004 03:01:20 -0600 Subject: [C++-sig] Re: boost.build: How to set runtime library paths in a Jamfile (wrapping 3rd party libs) In-Reply-To: References: Message-ID: <40517C60.7010606@redshift-software.com> Holger Joukl wrote: > Rene wrote: > >>feature of ELF for adding searchs paths relative to the loading module.. So > > now > >>I can get the effect I have on Windows of adding the location of my > > executable > >>(or any other relative subdir) to the library search path... > > >><*>-Wl,-rpath,'${ORIGIN}' > > > If I understand correctly, this translate to an equivalent to "gcc > -R<$ORIGIN>" with $ORIGIN being a > relative path -- that is, simply using -R option with relative paths. You understand incorrectly... There is no equivalent using regular searh paths and relative directories. The ELF linker-loader (ld.so in Linux) replaces the ORIGIN link variable with the path of the object doing the loading, and adds it to the list of search paths. And by the way GCC will translate your -R to -rpath when it feeds it to the linker. > While being fine for executables, I suspect that this is not really > appropriate for boost.python wrapped > libraries, where > - libboost_python.so would probably reside in > $PYTHON_ROOT/lib/python2.x/site-packages You are making an assumption about locality. Why would you place it there? > - the wrapper library shared object would probably reside in > $PYTHON_ROOT/lib/python2.x/site-packages Again why? > - the wrapped library resides anywhere on your system Like my home directory for example ;-) > Running python and using this extension is now dependant from where you > invoke the interpreter; Not from where you invoke, but from where the *.so (or exec) doing the loading resides. > it will only work if the wrapped lib can be found in the relative path > $ORIGIN. Or if it can find it in the regular search path of the system. > So it is either LD_LIBRARY_PATH again (not good) or adding some search > paths with -R in > the link step, the search paths being s.th. like site-dependant standard > library installation directories. > E.g. a shared filesystem named /apps/prod where I would install central > components (like python :-) But if you use the ORIGIN link-var you can install to /apps/prod/something/myapp and put plugins and libboost_python*.so in a plugins subdir. All you need is to add the '${ORIGIN}/plugins' -rpath. > Anyway, thanks a lot for all the hints! You're Welcome :-) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From stefan.seefeld at orthosoft.ca Fri Mar 12 15:38:35 2004 From: stefan.seefeld at orthosoft.ca (Stefan Seefeld) Date: Fri, 12 Mar 2004 09:38:35 -0500 Subject: [C++-sig] instantiating python::object wrapping C++ objects Message-ID: <252bdc2ce7eb198071924fe7ceadc30d4051cc2c@Orthosoft.ca> hi there, I want to write a function that wraps C++ object references into python::object instances. The corresponding python::class_ is defined in a different module, but I don't know what the inverse of python::extract<> is, i.e. how I can write a function python::object do_wrap(MyType *v); All the needed functionality seems to be there, so it appears I'm missing something obvious here, but what ? Thanks for your help, Stefan From pierre.barbier at cirad.fr Fri Mar 12 15:51:08 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Fri, 12 Mar 2004 15:51:08 +0100 Subject: [C++-sig] instantiating python::object wrapping C++ objects In-Reply-To: <252bdc2ce7eb198071924fe7ceadc30d4051cc2c@Orthosoft.ca> References: <252bdc2ce7eb198071924fe7ceadc30d4051cc2c@Orthosoft.ca> Message-ID: <1079103058.1062.8.camel@pbarbier> If you take extra care about the life of the C++ object, you can use this: object do_wrap(MyType *v) { static reference_existing_object::apply::type converter; PyObject* obj = converter(v); return object(handle<>(obj)); } I suppose the "converter" return a new reference so you don't need to use the "borrowed" object. Also, there are converters in other return policies, but I don't know if they are different ! Pierre Le ven 12/03/2004 ? 15:38, Stefan Seefeld a ?crit : > hi there, > > I want to write a function that wraps C++ object references > into python::object instances. The corresponding python::class_ > is defined in a different module, but I don't know what the inverse > of python::extract<> is, i.e. how I can write a function > > python::object do_wrap(MyType *v); > > All the needed functionality seems to be there, so it appears > I'm missing something obvious here, but what ? > > Thanks for your help, > > Stefan > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Fri Mar 12 16:38:59 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 12 Mar 2004 10:38:59 -0500 Subject: [C++-sig] Re: boost.python problem: 'virtual functions and default implementations' tutorial doesn't work References: Message-ID: "Colin Irwin" writes: > I've been able to resolve the error by using the following python module > definition instead: > > BOOST_PYTHON_MODULE(test_module) > { > > class_("Base") > .def("function", &Base::function, &BaseWrapper::default_function) > ; > } > > Now this noncopyable is not mentioned in the tutorial file and indeed, I > don't think it does exactly what I want in this case. By this I mean it > prevents copying any of the derived objects in Python doesn't it? No, it simply tells Boost.Python not to try create a by-value converter from C++ Base objects to Python, such as would be used to wrap a C++ function returing a Base object by value. > Where have I gone wrong? The tutorial file doesn't seem to work as > expected. Then the tutorial is broken and needs to be fixed. > My fix doesn't do what I want it do (I think this is right, if > I've inadvertently prevented copying). How should I structure my module > definition/code? As suggested by Pierre, the additional constructor in BaseWrapper should work: BaseWrapper( PyObject* self_, const Base& copy); -- Dave Abrahams Boost Consulting www.boost-consulting.com From halbert at jubilee.bbn.com Sun Mar 14 18:03:34 2004 From: halbert at jubilee.bbn.com (Dan Halbert) Date: Sun, 14 Mar 2004 12:03:34 -0500 Subject: [C++-sig] Pyste: set_wrapper on overloaded function or method Message-ID: <200403141703.i2EH3YA29952@hbo.bbn.com> I was trying to create a wrapper for an overloaded method using the Pyste "set_wrapper" capability (pyste from Boost 1.31.0). However, I ran into a problem which can be illustrated by the following example: ======================================== testing.pyste: -------------- testing = AllFromHeader("testing.h") set_wrapper(testing.f, "f_wrapper") set_wrapper(testing.C.g, "g_wrapper") ======================================== testing.h: ---------- int f(int i=1) { return i;} struct C { int g(int i=2) { return i;} }; int f_wrapper(float fl=3.0) { return (int) fl; } int g_wrapper(C* c, float fl=4.0) { return (int) fl; } ======================================== Pyste produces a .cpp which includes this code: //... BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(C_g_overloads_0_1, g, 0, 1) BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads_0_1, f, 0, 1) BOOST_PYTHON_FUNCTION_OVERLOADS(f_wrapper_overloads_0_1, f_wrapper, 0, 1) BOOST_PYTHON_FUNCTION_OVERLOADS(g_wrapper_overloads_1_2, g_wrapper, 1, 2) // ... BOOST_PYTHON_MODULE(testing) { class_< C >("C", init< >()) .def(init< const C& >()) .def("g", &g_wrapper, C_g_overloads_0_1()) // ** Line g ** ; def("f", &f_wrapper, f_overloads_0_1()); // ** Line f ** // ... } ======================================== The problem is that in Lines g and f above, the third args to ".def" are the wrong overloads to use. They are the overloads for the original method or function, not the wrapper overloads. The code should be: .def("g", &g_wrapper, g_wrapper_overloads_1_2()) // corrected Line g def("f", &f_wrapper, f_wrapper_overloads_0_1()); // corrected Line f If f_wrapper and g_wrapper had no overloads, there should be no third arg at all. I tried to fix this by patching ClassExporter.py around line 376, where the third arg to ".def" is constructed. I checked for a wrapper and tried to generate the overloads arg for the wrapper, not the method. But I was stymied because the wrapper object is not a full-fledged declaration object, and I can't get its min and max args. I'm still looking at the code, but perhaps someone more familar with it could suggest a fix. The same kind of fix would need to go into FunctionExporter.py. (In the example above, I would normally have done an Include("testing_wrapper.h"). I left it out for simplicity and also to force the BOOST_PYTHON_FUNCTION_OVERLOADS to occur.) Regards, Dan From steam at nurfuerspam.de Mon Mar 15 11:34:07 2004 From: steam at nurfuerspam.de (Hanz Meizer) Date: Mon, 15 Mar 2004 11:34:07 +0100 Subject: [C++-sig] Re: Conversion of C++ return type. In-Reply-To: References: Message-ID: Hi, Just wanted to notify the list that I found the solution. Besides some other errors I made one of the wrapped functions return_internal_reference. This didn't invoke the to_python_converter I registered, but tried to create a wrapped Any object, where no wrapper was existant of course. I made all functions copy_(non)const_reference and it seems that in this case the to_python_converter get's called all the time. That is reasonable, but I think it should be mentioned in the documentation so that people can check if all their functions use copy_const_reference, bacause if you're new to boost.python there are so many things that can be the cause that you just don't kow where to search H. From halbert at bbn.com Mon Mar 15 16:35:00 2004 From: halbert at bbn.com (Dan Halbert) Date: Mon, 15 Mar 2004 10:35:00 -0500 Subject: [C++-sig] Pyste add_method() In-Reply-To: <40510A11.2060803@esss.com.br> (message from Nicodemus on Thu, 11 Mar 2004 21:53:37 -0300) References: <1079030423.10839.10.camel@bluefish> <40510A11.2060803@esss.com.br> Message-ID: <200403151535.i2FFZ0X19529@rolex.bbn.com> >From: Nicodemus >Daniel Holth wrote: >>I think I've found the solution to my old problem: >> >>sync = Class("ogg::sync", "oggcc.h") # part 1 >> >>syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h") # part 2 >>add_method(sync, "ogg::sync_write") >>rename(sync.sync_write, "write") >>exclude(syncwrite) >> >>Doesn't work for me: it will say something like: >>RuntimeError: no ogg::sync_write declaration found! >> >>Instead, if I say the class is in the file that declares the wrapper, >>(oggpy_wrappers.h also includes oggcc.h): >> >>sync = Class("ogg::sync", "oggpy_wrappers.h") >> >>(insert part 2 here) >> >>it works nicely. This reminds me of the issue I reported about set_wrapper yesterday, and how it wasn't clear to me how to fix the problem. Right now, both set_wrapper() and add_method() take a string as a second argument to name the function, instead of a full-fledged "declaration info" object, or whatever it's called. We say: Include("wrappers.h") set_wrapper(my_function, "my_function_wrapper") Similarly we say: add_method(MyClass, "my_new_method") But suppose the second argument was not a string, but a definition object. Maybe I'm wrong, but it seems to me clearer to say something like: my_function_wrapper = Function("my_function_wrapper", "wrappers.h") set_wrapper(my_function, my_function_wrapper) and my_new_method = Function("my_new_method", "new_methods.h") add_method(MyClass, my_new_method) Internally to Pyste, this would give set_wrapper() and add_method() more information to work with. Dan From ndbecker2 at verizon.net Mon Mar 15 21:24:29 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 15 Mar 2004 15:24:29 -0500 Subject: [C++-sig] std::vector Message-ID: I'm back to looking at integration of python with C++ code, which uses std::vector, particulary vector and vector>. What would be the best/easiest/recommended way to get python to pickle an std::vector? From tether at mitlns.mit.edu Mon Mar 15 22:23:30 2004 From: tether at mitlns.mit.edu (Stephen Tether) Date: Mon, 15 Mar 2004 15:23:30 -0600 Subject: [C++-sig] Pyste in boost 1.31.0 has trouble with exception specs Message-ID: <40561ED2.10703@mitlns.mit.edu> I tried running Pyste on the following files test.hh and test.pyste and it threw an TypeError exception. // Begin test.hh #include class Foo { public: virtual void bar() throw(std::exception); }; // End test.hh # Begin test.pyste Class("Foo", "test.hh") # End test.pyste The exception traceback: Traceback (most recent call last): File "/evbsoft/python/v2_3_3c1/bin/pyste.py", line 8, in ? pyste.main() File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", line 405, in main status = Begin() File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", line 244, in Begin return GenerateCode(parser, module, out, interfaces, multiple) File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/pyste.py", line 372, in GenerateCode export.GenerateCode(codeunit, exported_names) File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/Exporter.py", line 50, in GenerateCode self.Export(codeunit, exported_names) File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/ClassExporter.py", line 92, in Export self.InheritMethods(exported_names) File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/ClassExporter.py", line 119, in InheritMethods pointers = [x.PointerDeclaration(True) for x in self.class_ if isinstance(x, Method)] File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/declarations.py", line 320, in PointerDeclaration return '(%s (%s::*)(%s) %s%s)&%s' %\ File "/evbsoft/python/v2_3_3c1/lib/python2.3/site-packages/Pyste/declarations.py", line 226, in Exceptions return " throw(%s)" % ', '.join (self.throws) TypeError: sequence item 0: expected string, Type found It looks like a list comprehension or map() call at line 226 of declarations.py: return " throw(%s)" % ', '.join ([x.name for x in self.throws]) If I make that change I get the following output: // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace { struct Foo_Wrapper: Foo { Foo_Wrapper(PyObject* self_, const Foo& p0): Foo(p0), self(self_) {} Foo_Wrapper(PyObject* self_): Foo(), self(self_) {} void bar() throw(std::exception) { call_method< void >(self, "bar"); } void default_bar() { Foo::bar(); } PyObject* self; }; }// namespace // Module ====================================================================== BOOST_PYTHON_MODULE(test) { class_< Foo, Foo_Wrapper >("Foo", init< >()) .def(init< const Foo& >()) .def("bar", &Foo::bar, &Foo_Wrapper::default_bar) ; } // End of test.cpp - Steve Tether From rwgk at yahoo.com Mon Mar 15 23:54:23 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 15 Mar 2004 14:54:23 -0800 (PST) Subject: [C++-sig] std::vector In-Reply-To: Message-ID: <20040315225423.44660.qmail@web20208.mail.yahoo.com> --- "Neal D. Becker" wrote: > I'm back to looking at integration of python with C++ code, which uses > std::vector, particulary vector and vector>. > > What would be the best/easiest/recommended way to get python to pickle an > std::vector? Easiest (this requires boost from CVS, will not work with 1.31.0): class_ >("std_vector_double") .def(vector_indexing_suite >()) .enable_pickling() ; In Python: # import the wrapped world class from your_ext import std_vector_double # definition of __getinitargs__ def std_vector_double_getinitargs(self): return tuple(self) # now inject __getinitargs__ (Python is a dynamic language!) std_vector_double.__getinitargs__ = std_vector_double_getinitargs This requires a std_vector_double constructor that takes a tuple as the argument. I am not sure if the indexing suite provides this; probably not. Make one yourself or define __getstate__ and __setstate__. See: http://cci.lbl.gov/~rwgk/shortcuts/boost/libs/python/doc/v2/pickle.html I highly recommend implementing the constructor and leaving __getstate__ and __setstate__ alone. This easy solution is very inefficient because each element is converted to a Python object. The scitbx solves this problem with a small, custom serialization library. The entire array is converted to one Python object, a Python string. It is fast and the pickled arrays are quite compact and portable. I am afraid I never found the time do write the documentation; hope one day someone will take the scitbx code and join it with the indexing suite. Here it is the relevant code if someone wants to have a look: http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/include/scitbx/serialization/base_256.h?view=markup http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/include/scitbx/boost_python/pickle_single_buffered.h?view=markup http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/include/scitbx/boost_python/pickle_double_buffered.h?view=markup Ralf __________________________________ Do you Yahoo!? Yahoo! Mail - More reliable, more storage, less spam http://mail.yahoo.com From greglandrum at mindspring.com Tue Mar 16 17:25:12 2004 From: greglandrum at mindspring.com (greg Landrum) Date: Tue, 16 Mar 2004 08:25:12 -0800 Subject: [C++-sig] vector_indexing_suite and std::string Message-ID: <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> The attached files create and test an extension module that uses the indexing_suite to return std::vectors containing ints and std::strings to Python. The int vectors work just fine, but the std::string vectors generate: TypeError: No Python class registered for C++ class std::string errors when the individual elements are accessed. It's clearly not a problem with returning std::strings, because the bareString() function does that without any difficulties. Ron Clarke posted about this a couple of weeks ago: http://mail.python.org/pipermail/c++-sig/2004-March/006966.html but no solution or work-around was provided, so I figured I'd try again. System details: Boost: 1.31 Python: 2.2.3 OS: both Redhat8.0 (g++ v3.2)and Win2K (VC++ 7.1) Thanks, -greg -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: indexing_with_strings.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: indexing_with_strings.py Type: application/octet-stream Size: 564 bytes Desc: not available URL: From jbrandmeyer at earthlink.net Tue Mar 16 21:19:50 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 16 Mar 2004 15:19:50 -0500 Subject: [C++-sig] vector_indexing_suite and slicing Message-ID: <1079468390.2134.55.camel@illuvatar> A few months ago there was a discussion on this list related to the semantics of setting a (possibly extended) slice when the setting range is empty[1]. As part of that discussion I submitted a patch to change the behavior of a Python list [2]. The resolution on that was to clarify that list.__setitem__(slice, obj) has the following behavior (no changes): When called with a simple slice that defines an empty range, perform an insertion at the first index. When called with an extended slice regardless of the length of the range, perform a replacement of the objects indexed by the slice with objects from obj. obj must have exactly the same number of elements as indexed by the slice. To close the loop, the attached patch will fix the bugs I noted in [3] while following the guidance provided by the Python folks. Unless there are any objections, I'll commit this to HEAD and the RC_1_31_0 branch tonight. -Jonathan Brandmeyer [1]: summary http://mail.python.org/pipermail/c++-sig/2004-January/006589.html [2]: bug tracker for python https://sourceforge.net/tracker/?func=detail&atid=305470&aid=873305&group_id=5470 [3]: http://mail.python.org/pipermail/c++-sig/2004-January/006552.html -------------- next part -------------- A non-text attachment was scrubbed... Name: indexing_suite.patch Type: text/x-patch Size: 4288 bytes Desc: not available URL: From nicodemus at esss.com.br Tue Mar 16 23:14:31 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Tue, 16 Mar 2004 19:14:31 -0300 Subject: [C++-sig] Pyste: set_wrapper on overloaded function or method In-Reply-To: <200403141703.i2EH3YA29952@hbo.bbn.com> References: <200403141703.i2EH3YA29952@hbo.bbn.com> Message-ID: <40577C47.9010703@esss.com.br> Dan Halbert wrote: >I was trying to create a wrapper for an overloaded method using the >Pyste "set_wrapper" capability (pyste from Boost 1.31.0). However, I ran >into a problem which can be illustrated by the following example: > > >The problem is that in Lines g and f above, the third args to ".def" >are the wrong overloads to use. They are the overloads for the >original method or function, not the wrapper overloads. The code >should be: > > .def("g", &g_wrapper, g_wrapper_overloads_1_2()) // corrected Line g > > def("f", &f_wrapper, f_wrapper_overloads_0_1()); // corrected Line f > >If f_wrapper and g_wrapper had no overloads, there should be no third >arg at all. > >I tried to fix this by patching ClassExporter.py around line 376, >where the third arg to ".def" is constructed. I checked for a wrapper >and tried to generate the overloads arg for the wrapper, not the >method. But I was stymied because the wrapper object is not a >full-fledged declaration object, and I can't get its min and max args. >I'm still looking at the code, but perhaps someone more familar with >it could suggest a fix. > >The same kind of fix would need to go into FunctionExporter.py. > >(In the example above, I would normally have done an >Include("testing_wrapper.h"). I left it out for simplicity and also to >force the BOOST_PYTHON_FUNCTION_OVERLOADS to occur.) > > > Hi Dan, I'm not ignoring this message, it's just that I haven't got time to look it through... I've been pretty busy. But expect a reply in the next few days. Regards, Nicodemus. From jbrandmeyer at earthlink.net Wed Mar 17 00:16:13 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 16 Mar 2004 18:16:13 -0500 Subject: [C++-sig] vector_indexing_suite and std::string In-Reply-To: <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> References: <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> Message-ID: <1079478972.2134.60.camel@illuvatar> On Tue, 2004-03-16 at 11:25, greg Landrum wrote: > The attached files create and test an extension module that uses the indexing_suite to return std::vectors containing ints and std::strings to Python. The int vectors work just fine, but the std::string vectors generate: > TypeError: No Python class registered for C++ class std::string > errors when the individual elements are accessed. > > It's clearly not a problem with returning std::strings, because the bareString() function does that without any difficulties. > > Ron Clarke posted about this a couple of weeks ago: > http://mail.python.org/pipermail/c++-sig/2004-March/006966.html > but no solution or work-around was provided, so I figured I'd try again. > > System details: > Boost: 1.31 > Python: 2.2.3 > OS: both Redhat8.0 (g++ v3.2)and Win2K (VC++ 7.1) > > Thanks, > -greg Its not in the indexing suite, per se, its a problem with the implementation of register_ptr_to_python(). Here is a test that demonstrates the problem. Kindly ignore the memory leak, its just for demonstration purposes. HTH, Jonathan Brandmeyer -------------- next part -------------- A non-text attachment was scrubbed... Name: wrap_test.cpp Type: text/x-c++ Size: 869 bytes Desc: not available URL: From jbrandmeyer at earthlink.net Wed Mar 17 02:48:52 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 16 Mar 2004 20:48:52 -0500 Subject: [C++-sig] vector_indexing_suite and std::string In-Reply-To: <1079478972.2134.60.camel@illuvatar> References: <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> <1079478972.2134.60.camel@illuvatar> Message-ID: <1079488132.2134.71.camel@illuvatar> On Tue, 2004-03-16 at 18:16, Jonathan Brandmeyer wrote: > Its not in the indexing suite, per se, its a problem with the > implementation of register_ptr_to_python(). Here is a test that > demonstrates the problem. Kindly ignore the memory leak, its just for > demonstration purposes. > > HTH, > Jonathan Brandmeyer > > ______________________________________________________________________ Never mind, that isn't a bug with register_ptr_to_python(), it's a feature, as Dave tried to explain to me before ;). For vectors of std::string and std::complex, use the following workaround to make the indexing suite work: .def( vector_indexing_suite< std::vector, true>()) ^^^^ A permanent fix would involve making sure that this type expression evaluates true when Data is either std::string or std::complex (from indexing_suite.hpp line 121): typedef mpl::or_< mpl::bool_ , mpl::not_ > > no_proxy; -Jonathan Brandmeyer From greglandrum at mindspring.com Wed Mar 17 06:15:05 2004 From: greglandrum at mindspring.com (greg Landrum) Date: Tue, 16 Mar 2004 21:15:05 -0800 Subject: [C++-sig] vector_indexing_suite and std::string In-Reply-To: <1079488132.2134.71.camel@illuvatar> References: <1079478972.2134.60.camel@illuvatar> <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> <1079478972.2134.60.camel@illuvatar> Message-ID: <5.1.0.14.2.20040316211423.03fc70a8@mail.mindspring.com> At 05:48 PM 3/16/2004, Jonathan Brandmeyer wrote: >Never mind, that isn't a bug with register_ptr_to_python(), it's a >feature, as Dave tried to explain to me before ;). For vectors of >std::string and std::complex, use the following workaround to make the >indexing suite work: > >.def( vector_indexing_suite< std::vector, true>()) > ^^^^ That cleared up the problem. Thanks Jonathan! -greg From A.Srivastav at zensar.com Wed Mar 17 09:16:42 2004 From: A.Srivastav at zensar.com (Ajitkumar Srivastav) Date: Wed, 17 Mar 2004 13:46:42 +0530 Subject: [C++-sig] crash problem Message-ID: <4171EC88BB77E34EAE1012DBEB6C7EC70A2512@ZENMAILHQ1.ind.zensar.com> Hello, I have used python 2.3 in my C++ application. I generally make calls to python library to perform my intended task. It happens properly. But after that immediatly the memory gets corrupted and application crashes. Pls help. thnx in advance Ajit Shrivastav Zensar Technologies Ltd. Mile Post no. 4 Pune- 411014 Tel no. - 9520-26633711 x121 Mobile no. - 98900 37203 www.zensar.com Your Transformation Partner It's amazing that the amount of news that happens in the world everyday always just exactly fits the newspaper. From joel at boost-consulting.com Thu Mar 18 14:06:32 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Thu, 18 Mar 2004 21:06:32 +0800 Subject: [C++-sig] vector_indexing_suite and std::string In-Reply-To: <5.1.0.14.2.20040316211423.03fc70a8@mail.mindspring.com> References: <1079478972.2134.60.camel@illuvatar> <5.1.0.14.2.20040316080922.040df988@mail.earthlink.net> <1079478972.2134.60.camel@illuvatar> <5.1.0.14.2.20040316211423.03fc70a8@mail.mindspring.com> Message-ID: <40599ED8.6030503@boost-consulting.com> greg Landrum wrote: > At 05:48 PM 3/16/2004, Jonathan Brandmeyer wrote: > > >>Never mind, that isn't a bug with register_ptr_to_python(), it's a >>feature, as Dave tried to explain to me before ;). For vectors of >>std::string and std::complex, use the following workaround to make the >>indexing suite work: >> >>.def( vector_indexing_suite< std::vector, true>()) >> ^^^^ > > > That cleared up the problem. Thanks Jonathan! Thanks for answering Greg, Jonathan. Hopefully, with the new indexing suite (by Raoul) all these will be non issues. -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From joel at boost-consulting.com Thu Mar 18 14:09:42 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Thu, 18 Mar 2004 21:09:42 +0800 Subject: [C++-sig] vector_indexing_suite and slicing In-Reply-To: <1079468390.2134.55.camel@illuvatar> References: <1079468390.2134.55.camel@illuvatar> Message-ID: <40599F96.6020602@boost-consulting.com> Jonathan Brandmeyer wrote: > A few months ago there was a discussion on this list related to the > semantics of setting a (possibly extended) slice when the setting range > is empty[1]. As part of that discussion I submitted a patch to change > the behavior of a Python list [2]. The resolution on that was to > clarify that list.__setitem__(slice, obj) has the following behavior > (no changes): > > When called with a simple slice that defines an empty range, perform an > insertion at the first index. > > When called with an extended slice regardless of the length of the > range, perform a replacement of the objects indexed by the slice with > objects from obj. obj must have exactly the same number of elements as > indexed by the slice. > > To close the loop, the attached patch will fix the bugs I noted in [3] > while following the guidance provided by the Python folks. Unless there > are any objections, I'll commit this to HEAD and the RC_1_31_0 branch > tonight. > > -Jonathan Brandmeyer > > > [1]: summary > http://mail.python.org/pipermail/c++-sig/2004-January/006589.html > [2]: bug tracker for python > https://sourceforge.net/tracker/?func=detail&atid=305470&aid=873305&group_id=5470 > [3]: http://mail.python.org/pipermail/c++-sig/2004-January/006552.html No objections here. I wonder though about the status of Raoul's new indexing suite. I was under the impression that his work will supersede the current indexing suite. Raoul? Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From gwl at u.washington.edu Fri Mar 19 00:48:33 2004 From: gwl at u.washington.edu (Graeme Lufkin) Date: Thu, 18 Mar 2004 15:48:33 -0800 Subject: [C++-sig] Re: embedding examples References: <1078132099.32100.6.camel@localhost> Message-ID: On Mon, 01 Mar 2004 10:08:19 +0100, Ingo Luetkebohle wrote: > I have trouble compiling the 'Using the interpreter' examples from the > tutorial. > > Code like this: > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); dict > main_namespace(handle<>(borrowed( > PyModule_GetDict(main_module.get()) ))); results in > error: variable declaration is not allowed here > > using gcc 3.2 and gcc 3.3 on Linux. > > When I use > handle<> main_module(borrowed( PyImport_AddModule("__main__") )); > handle<> main_nsh(borrowed( PyModule_GetDict(main_module.get()) )); > dict main_namespace(main_nsh); > > it compiles and the resulting dict is usable. > > So, this is not a showstopper but it doesn't work as documented and > results in longer code. Is there anything I can do to get the intended > behaviour? > > regards I've got this problem as well, and have investigated its roots. The problem is that the programmer thinks he's creating an anonymous temporary handle<> object, while the compiler thinks you're declaring a variable. For example: PyObject* pobj = 0; handle<>(pobj); I think I'm creating an anonymous temporary of type handle<>, constructing it with pobj (yes, this would fail, because handle<> throws on null, but that's not the point). The compiler discards the parentheses and thus tries to redeclare pobj as a variable of type handle<>, which is an error. Let's use a more familiar class template for some more examples. //declare n as int int n = 3; //declare v to be a vector, construct it with n elements vector v(3); //construct an anonymous temporary of n elements, setting them to 2 vector(n, 2); //construct an anonymous temporary of 3 elements vector(3); //attempt to redeclare n as a vector vector(n); Before I tried it, I would have guessed the last item would do the same thing as the second-to-last item. gcc and Intel know better than I, apparently. Enough of this fun, what do I do about handles? The reason I need the handle<> in the first place is so that the PyObject pointer gets Py_DECREF'd when I'm done with it. So all calls to the Python API that return a PyObject* should get wrapped in a handle<>, possibly borrowed. But, as the examples in the tutorial show, you often don't need the PyObject*, you just want to make sure it gets reference counted correctly. For example, in the code from the tutorial listed below, instead of creating and immediately destroying an anonymous temporary handle<>, the compiler tries to declare a variable called PyRun_String as a handle<> and construct it with a constructor that doesn't exist. If I give the handle<> a name, it works as I expected. handle<>( PyRun_String("hello = file('hello.txt','w')\n" "hello.write('Hello world!')\n" "hello.close()", Py_file_input, main_namespace.get(), main_namespace.get()) ); So finally to my question: Since these anonymous temporaries are useful, what should I do? Is there a fundamental C++ rule that I'm missing or fighting against? Also could the embedding part of the tutorial be updated to no longer contain code that doesn't compile? - Graeme Lufkin gwl at u.washington.edu "This sentence contains exactly threee erors." From JCrystal at lucascareers.com Fri Mar 19 20:04:00 2004 From: JCrystal at lucascareers.com (Crystal, Jennifer) Date: Fri, 19 Mar 2004 14:04:00 -0500 Subject: [C++-sig] Sr. Software Developer - New York, NY Message-ID: <5E78C9CE14A9C94899DEC75CF243B89904F354AA@ex01.lucas.internal> Hi, my name is Jennifer Crystal and I am an Executive Recruiter with the LucasGroup. The Lucas Group has been in business for 33 years and is ranked in the top 20 search firms nationwide. Headquartered in Atlanta, we have 12 locations across the US with 20+ recruiting niches. While national in scope, we do not franchise offices, and thereby maintain core values and rigorous professional standards throughout our organization. Our 250+ recruiters are experts in their specialties, with extensive industry contacts and average 10-year tenure with our company. The LucasGroup was also chosen by the Wall Street Journal as the Executive Search Firm of choice and has established a beneficial partnership. I am searching for Sr. Software Engineer in New York, NY: SR. SOFTWARE DEVELOPER JOB PURPOSE/OBJECTIVE Sr. Software development / programming for ecommerce portal and customer applications. ESSENTIAL DUTIES AND RESPONSIBILITIES: Will work in small to mid-size teams to develop Web-based mission-critical applications using Predominately Python, Zope, Linux, Oracle. QUALIFICATION REQUIREMENTS: To perform this job successfully, and individual must be able to perform each essential duty satisfactorily. The requirements listed below are representative of the knowledge, skill, and abilities required: * Superior knowledge of Python (3+ years) * Oracle 8i or other DBMS specifically integration (3+ years) * Formal project life cycle training * Linux knowledge (3+ years) * Objective Oriented Design (5+ years) and analysis * Client Server background (5+ years in VB 6, Java or similar) * Experience with large and small development teams EDUCATION AND ECPERIENCE: * Preferable Education Requirement: Bachelor's degree or higher in computer science or engineering field. * Minimum Experience Requirement: 5+ years previous successful development/programming experience on the web.. * Preferable Experience Requirement: Prefer experience in ecommerce portal environment. Exposure to relational databases, data warehousing, internet-based application development or distributed object architectures. At least 2 years experience with internet technologies and significant additional application development experience in client-sever environments. * Other: Experience with SQL, VB, java, Linux/Unix, Oracle and integration of databases with Cold Fusion onto an ecommerce web platform, Apache. If you or someone you know might be interested in any of the positions, please send me a MS Word resume to jcrystal at lucascareers.com or contact me at 800-466-4489 x171. Thanks! Jennifer Crystal Senior Recruiter, Technology LucasGroup Recruiting Excellence Since 1970 3384 Peachtree Road, Suite 700 Atlanta, GA 30326 404-239-5630 x171 800-466-4489 x171 jcrystal at lucascareers.com www.lucascareers.com LucasGroup, In Partnership with THE WALL STREET JOURNAL. & CareerJournal Online. ***The information contained in this email is proprietary and confidential and is intended solely for the use of the named addressee. Do not disclose, copy, distribute, or disseminate it to any other party without the expressed consent of the sending party. If you have received this message in error please return the message to the sender by replying to it and then delete the message from your computer. Jennifer Crystal Senior Recruiter, Technology LucasGroup Recruiting Excellence Since 1970 3384 Peachtree Road, Suite 700 Atlanta, GA 30326 404-239-5630 x171 800-466-4489 x171 jcrystal at lucascareers.com www.lucascareers.com LucasGroup, In Partnership with THE WALL STREET JOURNAL. & CareerJournal Online. ***The information contained in this email is proprietary and confidential and is intended solely for the use of the named addressee. Do not disclose, copy, distribute, or disseminate it to any other party without the expressed consent of the sending party. If you have received this message in error please return the message to the sender by replying to it and then delete the message from your computer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From RaoulGough at yahoo.co.uk Sun Mar 21 20:52:54 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 21 Mar 2004 19:52:54 +0000 Subject: [C++-sig] Re: vector_indexing_suite and slicing References: <1079468390.2134.55.camel@illuvatar> <40599F96.6020602@boost-consulting.com> Message-ID: Joel de Guzman writes: > Jonathan Brandmeyer wrote: > >> A few months ago there was a discussion on this list related to the >> semantics of setting a (possibly extended) slice when the setting range >> is empty[1]. As part of that discussion I submitted a patch to change >> the behavior of a Python list [2]. The resolution on that was to >> clarify that list.__setitem__(slice, obj) has the following behavior >> (no changes): >> When called with a simple slice that defines an empty range, perform >> an >> insertion at the first index. >> When called with an extended slice regardless of the length of the >> range, perform a replacement of the objects indexed by the slice with >> objects from obj. obj must have exactly the same number of elements as >> indexed by the slice. >> To close the loop, the attached patch will fix the bugs I noted in >> [3] >> while following the guidance provided by the Python folks. Unless there >> are any objections, I'll commit this to HEAD and the RC_1_31_0 branch >> tonight. >> -Jonathan Brandmeyer >> [1]: summary >> http://mail.python.org/pipermail/c++-sig/2004-January/006589.html >> [2]: bug tracker for python >> https://sourceforge.net/tracker/?func=detail&atid=305470&aid=873305&group_id=5470 >> [3]: http://mail.python.org/pipermail/c++-sig/2004-January/006552.html > > No objections here. I wonder though about the status of Raoul's > new indexing suite. I was under the impression that his work will > supersede the current indexing suite. Raoul? I'm pretty sure I mentioned my work in the same thread back in January, and that the slice behaviour of the new indexing suite was already Python compliant. I haven't had time recently to get the documentation in order, but I intend to get that done before the ACCU conference in mid-April. Once the docco is ready, we could probably consider merging indexing_v2 onto the mainline, but I guess there's no harm in patching the original indexing suite in the meantime. -- Raoul Gough. export LESS='-X' From joel at boost-consulting.com Mon Mar 22 01:01:21 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Mon, 22 Mar 2004 08:01:21 +0800 Subject: [C++-sig] Re: vector_indexing_suite and slicing In-Reply-To: References: <1079468390.2134.55.camel@illuvatar> <40599F96.6020602@boost-consulting.com> Message-ID: <405E2CD1.2040703@boost-consulting.com> Raoul Gough wrote: > Joel de Guzman writes: > >>>To close the loop, the attached patch will fix the bugs I noted in >>>[3] >>>while following the guidance provided by the Python folks. Unless there >>>are any objections, I'll commit this to HEAD and the RC_1_31_0 branch >>>tonight. [snip] >>No objections here. I wonder though about the status of Raoul's >>new indexing suite. I was under the impression that his work will >>supersede the current indexing suite. Raoul? > > > I'm pretty sure I mentioned my work in the same thread back in > January, and that the slice behaviour of the new indexing suite was > already Python compliant. > > I haven't had time recently to get the documentation in order, but I > intend to get that done before the ACCU conference in mid-April. Once > the docco is ready, we could probably consider merging indexing_v2 > onto the mainline, but I guess there's no harm in patching the > original indexing suite in the meantime. I agree. I look forward to the new indexing suite. I still owe you a thorough review ;-) Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From dave at boost-consulting.com Mon Mar 22 01:17:49 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Mar 2004 19:17:49 -0500 Subject: [C++-sig] Re: crash problem References: <4171EC88BB77E34EAE1012DBEB6C7EC70A2512@ZENMAILHQ1.ind.zensar.com> Message-ID: "Ajitkumar Srivastav" writes: > Hello, > > I have used python 2.3 in my C++ application. > > I generally make calls to python library to perform my intended > task. It happens properly. But after that immediatly the memory > gets corrupted and application crashes. Usually you need to describe what you're doing a bit before anyone can help you. Most often, it requires reducing your problem to a small, reproducible case. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Mar 22 04:09:47 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Mar 2004 22:09:47 -0500 Subject: [C++-sig] Re: Conversion of C++ return type. References: Message-ID: Hanz Meizer writes: > Hi, > > Just wanted to notify the list that I found the solution. Besides some > other errors I made one of the wrapped functions > return_internal_reference. This didn't invoke the to_python_converter > I registered, but tried to create a wrapped Any object, where no > wrapper was existant of course. I made all functions > copy_(non)const_reference and it seems that in this case the > to_python_converter get's called all the time. That is reasonable, but > I think it should be mentioned in the documentation What, specifically? > so that people can > check if all their functions use copy_const_reference, bacause if > you're new to boost.python there are so many things that can be the > cause that you just don't kow where to search Please propose a patch to the documentation, so I know exactly what you'd like to see explained, and what language you think would've prevented your confusion. -- Dave Abrahams Boost Consulting www.boost-consulting.com From bhartsho at yahoo.com Mon Mar 22 08:48:45 2004 From: bhartsho at yahoo.com (brett hartshorn) Date: Sun, 21 Mar 2004 23:48:45 -0800 (PST) Subject: [C++-sig] Boost newbie help Message-ID: <20040322074845.47550.qmail@web13421.mail.yahoo.com> I'm having a problem wrapping a class that looks like this: class A { A _myVar; A (const A &); //don't ask why this is not defined public: A() { _myVar = myFunction(); } } It will generate errors when building that say: error: `A::A(const A&)' is private /usr/include/boost/python/object/value_holder.hpp:111: error: within this context If i remove the strange constructor that does nothing, then it builds without any problems. Anybody have any ideas how to fix this, other than removing that constructor? thanks for the help, -brett __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From bhartsho at yahoo.com Mon Mar 22 09:00:53 2004 From: bhartsho at yahoo.com (brett hartshorn) Date: Mon, 22 Mar 2004 00:00:53 -0800 (PST) Subject: [C++-sig] How to specify a double return type? Message-ID: <20040322080053.31492.qmail@web13426.mail.yahoo.com> I have a type called dReal, that can either be a float or double number type, depending on the build options. A member function in my class returns a dReal type, this is giving me problems in Boost. I am still new to boost, so i am not sure what to do. Here is the error i get: /usr/include/boost/python/detail/invoke.hpp:93: error: no match for call to `( boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (const dReal*)' I've tried to use: return_internal_reference<>() return_value_policy()) return_value_policy() but to no avail. Also i have member functions that take in a dReal number. What is the best way to pass that function a dReal type? Or can i just pass floats and doubles in python and boost will treat those as a dReal? thanks, -brett __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From rwgk at yahoo.com Mon Mar 22 15:48:05 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 22 Mar 2004 06:48:05 -0800 (PST) Subject: [C++-sig] Boost newbie help In-Reply-To: <20040322074845.47550.qmail@web13421.mail.yahoo.com> Message-ID: <20040322144805.85314.qmail@web20205.mail.yahoo.com> I believe you just have to use boost::noncopyable. http://www.boost.org/libs/python/doc/v2/class.html To see many examples: cd boost/libs/python/test grep noncopyable * Ralf --- brett hartshorn wrote: > I'm having a problem wrapping a class that looks like this: > > class A { > A _myVar; > A (const A &); //don't ask why this is not defined > > public: > A() { _myVar = myFunction(); } > > } > > It will generate errors when building that say: > error: `A::A(const A&)' is private > /usr/include/boost/python/object/value_holder.hpp:111: error: within this > context > > If i remove the strange constructor that does nothing, then it builds without > any problems. > Anybody have any ideas how to fix this, other than removing that constructor? __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From rwgk at yahoo.com Mon Mar 22 15:54:09 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 22 Mar 2004 06:54:09 -0800 (PST) Subject: [C++-sig] How to specify a double return type? In-Reply-To: <20040322080053.31492.qmail@web13426.mail.yahoo.com> Message-ID: <20040322145409.13312.qmail@web20211.mail.yahoo.com> Is dReal a typedef for double or float? If so: Python float are immutable. You cannot return pointers to immutable types. Somehow you have to change your interface, e.g. through the use of "thin wrappers." Please explain in more detail what exactly you want to do; hopefully this will lead us to the best solution. Ralf --- brett hartshorn wrote: > I have a type called dReal, that can either be a float or double number type, > depending on the > build options. A member function in my class returns a dReal type, this is > giving me problems in > Boost. I am still new to boost, so i am not sure what to do. > > Here is the error i get: > /usr/include/boost/python/detail/invoke.hpp:93: error: no match for call to > `( > > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning dReal*>) (const dReal*)' > > I've tried to use: > return_internal_reference<>() > return_value_policy()) > return_value_policy() > but to no avail. > > Also i have member functions that take in a dReal number. What is the best > way to pass that > function a dReal type? Or can i just pass floats and doubles in python and > boost will treat those > as a dReal? __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree From nico_ml at mgdesign.org Mon Mar 22 16:02:45 2004 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Mon, 22 Mar 2004 16:02:45 +0100 Subject: [C++-sig] Boost newbie help References: <20040322074845.47550.qmail@web13421.mail.yahoo.com> Message-ID: <00ca01c4101e$bc92ff30$de00a8c0@nico> > If i remove the strange constructor that does nothing, then it builds without any problems. > Anybody have any ideas how to fix this, other than removing that constructor? use a declaration like this one : class_("A"); HTH, Nicolas. From dave at boost-consulting.com Tue Mar 23 05:17:46 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 22 Mar 2004 23:17:46 -0500 Subject: [C++-sig] Re: vector_indexing_suite and slicing References: <1079468390.2134.55.camel@illuvatar> <40599F96.6020602@boost-consulting.com> <405E2CD1.2040703@boost-consulting.com> Message-ID: Joel de Guzman writes: > Raoul Gough wrote: > >> Joel de Guzman writes: >> >>>>To close the loop, the attached patch will fix the bugs I noted in >>>>[3] >>>>while following the guidance provided by the Python folks. Unless there >>>>are any objections, I'll commit this to HEAD and the RC_1_31_0 branch >>>>tonight. > > [snip] > >>>No objections here. I wonder though about the status of Raoul's >>>new indexing suite. I was under the impression that his work will >>>supersede the current indexing suite. Raoul? >> I'm pretty sure I mentioned my work in the same thread back in >> January, and that the slice behaviour of the new indexing suite was >> already Python compliant. >> I haven't had time recently to get the documentation in order, but I >> intend to get that done before the ACCU conference in mid-April. Once >> the docco is ready, we could probably consider merging indexing_v2 >> onto the mainline, but I guess there's no harm in patching the >> original indexing suite in the meantime. > > I agree. I look forward to the new indexing suite. I still owe > you a thorough review ;-) Since we're not near a release at this point, I'm happy to have it checked into the main trunk once you have docs. -- Dave Abrahams Boost Consulting www.boost-consulting.com From bhartsho at yahoo.com Tue Mar 23 06:58:09 2004 From: bhartsho at yahoo.com (brett hartshorn) Date: Mon, 22 Mar 2004 21:58:09 -0800 (PST) Subject: [C++-sig] Re: How to specify a double return type? Message-ID: <20040323055809.17691.qmail@web13425.mail.yahoo.com> Thanks Ralf and Nicolas for answering my first question. boost::noncopyable fixed my problem! Sadly, dReal is a typedef. I have tried to make 'thin wrappers' but i am not sure if i'm doing it right. Here's an example, Foo is the class i am wrapping, Bar is my thin wrapper. typedef double dReal; class Foo { public: const dReal * getSomething() const { return otherFunction(); } }; class Bar : public Foo { public: const double * getSomething() const { return Foo::getSomething(); } }; // the wrapper class_ bar("Bar"); bar .def("getSomething", &Bar::getSomething, return_internal_reference<>()) ; The tail end of my errors when compiling: instantiated from here /usr/include/boost/python/object/make_instance.hpp:25: error: invalid application of `sizeof' to an incomplete type -brett >Is dReal a typedef for double or float? If so: Python float are immutable. You >cannot return pointers to immutable types. Somehow you have to change your >interface, e.g. through the use of "thin wrappers." >Please explain in more detail what exactly you want to do; hopefully this will >lead us to the best solution. >Ralf __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From rwgk at yahoo.com Tue Mar 23 16:10:09 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 23 Mar 2004 07:10:09 -0800 (PST) Subject: [C++-sig] Re: How to specify a double return type? In-Reply-To: <20040323055809.17691.qmail@web13425.mail.yahoo.com> Message-ID: <20040323151009.93603.qmail@web20203.mail.yahoo.com> --- brett hartshorn wrote: > Thanks Ralf and Nicolas for answering my first question. boost::noncopyable > fixed my problem! > > Sadly, dReal is a typedef. I have tried to make 'thin wrappers' but i am not > sure if i'm doing it > right. Here's an example, Foo is the class i am wrapping, Bar is my thin > wrapper. > > typedef double dReal; > > class Foo { > public: > const dReal * getSomething() const { > return otherFunction(); > } > > }; > class Bar : public Foo { > public: > const double * getSomething() const { > return Foo::getSomething(); > } > }; You are making a "thick wrapper". And as far as Boost.Python is concerned there is no difference between wrapping Foo::getSomething and Bar::getsomething. I believe you have to do something like this (untested): // a thin wrapper double Foo_getSomething(Foo const& foo_instance) { return *foo_instance.getSomething(); // dereference the pointer } class_("Foo") .def("getSomething", Foo_getSomething) ; You can .def an unbound C++ function as a Python method. Cool? In Python foo_instance.getSomething() returns the *current* value of your dReal. If the value inside your Foo class changes you have to call foo_instance.getSomething() again to see the change in Python. E.g. instead of holding on to the const double* (as you might in C++) you have to hold on to the foo_instance instead. HTH, Ralf __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From pierre.barbier at cirad.fr Tue Mar 23 16:11:25 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Tue, 23 Mar 2004 16:11:25 +0100 Subject: [C++-sig] Exception not caught Message-ID: <1080054685.917.52.camel@pbarbier> Hello, I've registred an exception : struct ObjectCreationException { }; with the following function : void obj_create_trans( const ObjectCreationException& err ) { PyErr_SetString( PyExc_UserWarning, "Error when creating object, see standard error for more information" ); } and in the module definition : boost::python::register_exception_translator(&obj_create_trans); But, when my C++ program throw this exception, the program just abort. What can be the problem ? Thanks, Pierre -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Wed Mar 24 01:56:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 23 Mar 2004 19:56:42 -0500 Subject: [C++-sig] Re: Exception not caught References: <1080054685.917.52.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > But, when my C++ program throw this exception, the program just abort. > What can be the problem ? I suggest using a debugger to find out. -- Dave Abrahams Boost Consulting www.boost-consulting.com From tlovexyj at 21cn.com Wed Mar 24 10:03:28 2004 From: tlovexyj at 21cn.com (=?gb2312?B?x6fA78LtuM4=?=) Date: Wed, 24 Mar 2004 17:03:28 +0800 Subject: [C++-sig] Fw: PyErr_Print error track in c++ Message-ID: python-chinese at lists.python.cn, ??? ?????C++???????py????PyErr_Print??????? ???python???????PyObject_CallObject????module????????? ???????module????????????????????????????? ???py??? import sys, time from cd2 import * # ?????? class errCatcher: def __init__(self, filename): self.info = '' self.name = filename tmp = open(filename, 'w') tmp.close() def write(self, stuff): self.info += stuff def showmsg(self): f = open(self.name, 'a') f.write(time.ctime()) f.write('\n--------------------------------------------------\n') f.write(self.info) f.write('\n\n') f.close() MsgBox(self.info) self.info = '' # ?????? class outCatcher: def __init__(self, filename): self.name = filename tmp = open(filename, 'w') tmp.close() def write(self, stuff): f = open(self.name, 'a') f.write(stuff) f.close() sys.stderr = errCatcher('python_err.log') sys.stdout = outCatcher('python_out.log') ???C++??python?????? void RunFuncInModule(const Char *szFuncName, const Char *szModuleName) { try { python::handle<> main_module( python::borrowed( PyImport_AddModule( "__main__" ) ) ); python::handle<> main_namespace( python::borrowed( PyModule_GetDict( main_module.get() ) ) ); python::handle<> local_module( python::borrowed( PyImport_ImportModule( const_cast( szModuleName ) ) ) ); #ifdef _DEBUG python::handle<> ( python::borrowed( PyImport_ReloadModule( local_module.get() ) ) ); #endif python::handle<> local_namespace( python::borrowed( PyModule_GetDict( local_module.get() ) ) ); PyObject *func = python::expect_non_null( PyDict_GetItemString( local_namespace.get(), const_cast( szFuncName ) ) ); if ( PyCallable_Check( func ) != 0 ) { python::handle<>( PyObject_CallObject( func, NULL ) ); } } catch (python::error_already_set) { python::handle_exception(); PyErr_Print(); PyRun_SimpleString("sys.stderr.showmsg()"); } } ????????? ?? ???????????? ????????tlovexyj at 21cn.com ??????????2004-03-24 From pierre.barbier at cirad.fr Wed Mar 24 10:10:07 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Wed, 24 Mar 2004 10:10:07 +0100 Subject: [C++-sig] Re: Exception not caught In-Reply-To: References: <1080054685.917.52.camel@pbarbier> Message-ID: <1080119393.727.23.camel@pbarbier> I found the problem : it's a threading pb :( I raise the exception in a thread not being the python one. I'll try to find a way to raise the python exception event if launched from the other thread (during the execution of the code raising the exception, the python thread is blocked on a lock waiting the the end of the processing). Thanks, Pierre Le mer 24/03/2004 ? 01:56, David Abrahams a ?crit : > Pierre Barbier de Reuille writes: > > > But, when my C++ program throw this exception, the program just abort. > > What can be the problem ? > > I suggest using a debugger to find out. -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From ndbecker2 at verizon.net Thu Mar 25 01:19:38 2004 From: ndbecker2 at verizon.net (Neal Becker) Date: Wed, 24 Mar 2004 19:19:38 -0500 Subject: [C++-sig] simple numarray question Message-ID: I'm trying out numarray with boost::python. numarray-0.9, python-2.3.3. Any clues what's wrong with this simple test (I'm trying to print out #elements in the array) #include #include #include #include using namespace boost; using namespace boost::python; // sets the first element in a 1d numeric array void set_first_element(numeric::array& y, double value) { // y[python::make_tuple(0,0)] = value; y[0] = value; std::clog << y.nelements() << std::endl; } BOOST_PYTHON_MODULE(Test3) { def("f", set_first_element); } from numarray import * >>> from Test3 import * >>> x=array([1.2, 3.4]) >>> f(x, 2.8) Traceback (most recent call last): File "", line 1, in ? TypeError: No registered converter was able to produce a C++ rvalue of type long from this Python object of type builtin_function_or_method From tlovexyj at 21cn.com Thu Mar 25 02:30:58 2004 From: tlovexyj at 21cn.com (=?utf-8?B?5Y2D6YeM6ams6IKd?=) Date: Thu, 25 Mar 2004 09:30:58 +0800 Subject: [C++-sig] PyErr_Print error track in c++ Message-ID: hello, c++-sig at python.org I write own class to track PyErr_Print message for my c++ application. And I use PyObject_CallObject to call some function in some module. But, when some error in the module or the function of the module, who i use PyImport_ImportModule to import or call, it cannot report error message for me. :( What can be the problem ? below is track code: import sys, time from cd2 import * # ?????? class errCatcher: def __init__(self, filename): self.info = '' self.name = filename tmp = open(filename, 'w') tmp.close() def write(self, stuff): self.info += stuff def showmsg(self): f = open(self.name, 'a') f.write(time.ctime()) f.write('\n--------------------------------------------------\n') f.write(self.info) f.write('\n\n') f.close() MsgBox(self.info) self.info = '' # ?????? class outCatcher: def __init__(self, filename): self.name = filename tmp = open(filename, 'w') tmp.close() def write(self, stuff): f = open(self.name, 'a') f.write(stuff) f.close() sys.stderr = errCatcher('python_err.log') sys.stdout = outCatcher('python_out.log') c++ code embed python: void RunFuncInModule(const Char *szFuncName, const Char *szModuleName) { try { python::handle<> main_module( python::borrowed( PyImport_AddModule( "__main__" ) ) ); python::handle<> main_namespace( python::borrowed( PyModule_GetDict( main_module.get() ) ) ); python::handle<> local_module( python::borrowed( PyImport_ImportModule( const_cast( szModuleName ) ) ) ); #ifdef _DEBUG python::handle<> ( python::borrowed( PyImport_ReloadModule( local_module.get() ) ) ); #endif python::handle<> local_namespace( python::borrowed( PyModule_GetDict( local_module.get() ) ) ); PyObject *func = python::expect_non_null( PyDict_GetItemString( local_namespace.get(), const_cast( szFuncName ) ) ); if ( PyCallable_Check( func ) != 0 ) { python::handle<>( PyObject_CallObject( func, NULL ) ); } } catch (python::error_already_set) { python::handle_exception(); PyErr_Print(); PyRun_SimpleString("sys.stderr.showmsg()"); } } ??????????2004-03-24 From paul at paulgrenyer.co.uk Thu Mar 25 14:53:05 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Thu, 25 Mar 2004 13:53:05 GMT Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak Message-ID: <200403251353.i2PDr5d31317@ns.cricketthosting.co.uk> Hi All I've had a look at the FAQ and used google to look through the archives but I can't find anything about this problem or anything similar to it. My basic problem is that when I use the Multithreaded Dll (both Debug and Release) runtime with boost python I get a memory leak. Even with the simplest of code. For example: #include #include #include #include int main() { Py_Initialize(); { using namespace boost::python; handle<> main_module(borrowed( PyImport_AddModule ("__main__") )); } Py_Finalize(); return EXIT_SUCCESS; } If I use the single threaded runtime or the multithreaded static runtime there is no memory leak. I've checked and rebuilt boost python to ensure that it is built with the multithreaded dll runtime, but that didn't solve the problem. Therefore I suspect that the problem is with the python23.dll and the corresponding library? Has anyone else come across this? Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From e at cyan.com Thu Mar 25 18:35:25 2004 From: e at cyan.com (Eric Anderson) Date: Thu, 25 Mar 2004 09:35:25 -0800 Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak References: <200403251353.i2PDr5d31317@ns.cricketthosting.co.uk> Message-ID: <0ddf01c4128f$90116960$bf01a8c0@ea1xp> > My basic problem is that when I use the Multithreaded Dll (both Debug > and Release) runtime with boost python I get a memory leak. Even with > the simplest of code. I also use MSVC 7.1 w/ Multithreaded DLL. I seem to have the same problem. The leak I'm seeing is at: boost_1_30_0\boost\function\function_base.hpp(262) I have not taken the time to track down the cause yet. Eric From gbiddison at velocity11.com Thu Mar 25 19:33:30 2004 From: gbiddison at velocity11.com (Giles Biddison) Date: Thu, 25 Mar 2004 10:33:30 -0800 Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak Message-ID: (apologies -- I'm not sure if top or bottom post is the norm for this list) I can verify this problem. I've been reluctant to call it a memory leak, because it only seems to occur after calling Py_Finalize(). I did not go so far as to attempt to use anything other than the multithreaded runtime dll. Giles Biddison gbiddison at velocity11.com -----Original Message----- Date: Thu, 25 Mar 2004 13:53:05 GMT From: "Paul Grenyer" Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak To: c++-sig at python.org Message-ID: <200403251353.i2PDr5d31317 at ns.cricketthosting.co.uk> Content-Type: text/plain; charset=iso-8859-1 Hi All I've had a look at the FAQ and used google to look through the archives but I can't find anything about this problem or anything similar to it. My basic problem is that when I use the Multithreaded Dll (both Debug and Release) runtime with boost python I get a memory leak. Even with the simplest of code. For example: #include #include #include #include int main() { Py_Initialize(); { using namespace boost::python; handle<> main_module(borrowed( PyImport_AddModule ("__main__") )); } Py_Finalize(); return EXIT_SUCCESS; } If I use the single threaded runtime or the multithreaded static runtime there is no memory leak. I've checked and rebuilt boost python to ensure that it is built with the multithreaded dll runtime, but that didn't solve the problem. Therefore I suspect that the problem is with the python23.dll and the corresponding library? Has anyone else come across this? Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. ------------------------------ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig End of C++-sig Digest, Vol 8, Issue 26 ************************************** From paul at paulgrenyer.co.uk Thu Mar 25 19:37:23 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Thu, 25 Mar 2004 18:37:23 -0000 Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak References: <200403251353.i2PDr5d31317@ns.cricketthosting.co.uk> <0ddf01c4128f$90116960$bf01a8c0@ea1xp> Message-ID: <003101c41298$36f79260$0302a8c0@paul> Hi > > My basic problem is that when I use the Multithreaded Dll (both Debug > > and Release) runtime with boost python I get a memory leak. Even with > > the simplest of code. > > I also use MSVC 7.1 w/ Multithreaded DLL. I seem to have the same problem. > The leak I'm seeing is at: > > boost_1_30_0\boost\function\function_base.hpp(262) Interesting. I'll take a look at that once I get back in the office tomorrow. Thanks! Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now ready for download From paul at paulgrenyer.co.uk Thu Mar 25 19:42:23 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Thu, 25 Mar 2004 18:42:23 -0000 Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak References: Message-ID: <003a01c41298$e9b74e90$0302a8c0@paul> Hi > I can verify this problem. I've been reluctant to call it a memory > leak, because it only seems to occur after calling Py_Finalize(). I did > not go so far as to attempt to use anything other than the multithreaded > runtime dll. That's interesting as well. I don't think it does only occur after Py_Finalize. I first notice the problem during a test application that executes over 1.6 million python scripts one after the other. Py_Initialize and Py_Finalize are only called once, at the beginning and end of the application, respectively. The memory allocation is clearly rising all the time. As soon as I switch to another runtime the leak goes away. I am currently running all our unit tests with the static multithreaded runtime. If they pass then we may well switch to that for the time being, but I would prefer to fix the problem and keep using the dll multithreaded runtime. Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now ready for download From dave at boost-consulting.com Thu Mar 25 23:08:41 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 25 Mar 2004 17:08:41 -0500 Subject: [C++-sig] Re: Fw: PyErr_Print error track in c++ References: Message-ID: "????" writes: > python-chinese at lists.python.cn, ??? > > ?????C++???????py????PyErr_Print??????? I can't read the message; most of the characters show up for me as empty rectangles. I suspect that applies to most other participants on the list. Please re-post in plain-ASCII encoded English if you want us to help. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Mar 25 23:13:05 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 25 Mar 2004 17:13:05 -0500 Subject: [C++-sig] Re: simple numarray question References: Message-ID: Neal Becker writes: > I'm trying out numarray with boost::python. numarray-0.9, > python-2.3.3. Which compiler? > Any clues what's wrong with this simple test (I'm trying to print out > #elements in the array) > > #include > #include > #include > #include > > using namespace boost; > using namespace boost::python; > > // sets the first element in a 1d numeric array > void set_first_element(numeric::array& y, double value) > { > // y[python::make_tuple(0,0)] = value; > y[0] = value; > std::clog << y.nelements() << std::endl; I suggest pruning out parts of this function until you are able to pinpoint the error. For example: y.nelements(); then: y[0] = value; then: y[0]; > } > > BOOST_PYTHON_MODULE(Test3) > { > def("f", set_first_element); > } > > from numarray import * >>>> from Test3 import * >>>> x=array([1.2, 3.4]) >>>> f(x, 2.8) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No registered converter was able to produce a C++ rvalue of type > long from this Python object of type builtin_function_or_method -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Mar 25 23:21:01 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 25 Mar 2004 17:21:01 -0500 Subject: [C++-sig] Re: PyErr_Print error track in c++ References: Message-ID: ".??.?.??.?.?.??" writes: > hello, c++-sig at python.org > > I write own class to track PyErr_Print message for my c++ application. > And I use PyObject_CallObject to call some function in some > module. Usually it's better to use the function call operator of python::object. > But, when some error in the module or the function of the module, > who i use PyImport_ImportModule to import or call, it cannot > report error message for me. :( What specific symptom are you seeing, and which specific line of your sample code causes that symptom. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ndbecker2 at verizon.net Fri Mar 26 04:07:09 2004 From: ndbecker2 at verizon.net (Neal Becker) Date: Thu, 25 Mar 2004 22:07:09 -0500 Subject: [C++-sig] Re: simple numarray question References: Message-ID: David Abrahams wrote: > Neal Becker writes: > >> I'm trying out numarray with boost::python. numarray-0.9, >> python-2.3.3. > > Which compiler? > gcc version 3.3.3 20040311 (Red Hat Linux 3.3.3-3) boost_1_31_0 >> Any clues what's wrong with this simple test (I'm trying to print out >> #elements in the array) >> >> #include >> #include >> #include >> #include >> >> using namespace boost; >> using namespace boost::python; >> >> // sets the first element in a 1d numeric array >> void set_first_element(numeric::array& y, double value) >> { >> // y[python::make_tuple(0,0)] = value; >> y[0] = value; >> std::clog << y.nelements() << std::endl; > > I suggest pruning out parts of this function until you are able to > pinpoint the error. For example: > > y.nelements(); > then: > y[0] = value; > > then: > y[0]; > >> } >> >> BOOST_PYTHON_MODULE(Test3) >> { >> def("f", set_first_element); >> } >> >> from numarray import * >>>>> from Test3 import * >>>>> x=array([1.2, 3.4]) >>>>> f(x, 2.8) >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: No registered converter was able to produce a C++ rvalue of >> type long from this Python object of type builtin_function_or_method > So I guess you're implying that as far as you can see, this is OK? I have approximately zero experience with boost-python so far, so I need to know if it's my code or my environment that is the problem. From bhartsho at yahoo.com Fri Mar 26 07:24:34 2004 From: bhartsho at yahoo.com (brett hartshorn) Date: Thu, 25 Mar 2004 22:24:34 -0800 (PST) Subject: [C++-sig] boost python wrapper parser bug? Message-ID: <20040326062434.63236.qmail@web13425.mail.yahoo.com> I think i found a bug in boost python. My bug sounds very much like this one: http://mail.python.org/pipermail/c++-sig/2002-December/003125.html I am wrapping a series of classes, they are all very much the same, they all inherit from the same base class, they all have protected deconstrutors. I am wrapping like: class_foo("myclass", no_init) and all is working great, except for this one class called Extensions. It appears there is nothing very different about this class, but for some reason boost does not like - hates in fact - its protected deconstructor. I've even talked to the author of the class and here is what he had to say: """What I find strange is that only osgGL2::Extensions::~Extensions() experiences this problem. I wonder what makes it unique? Can you confirm that e.g. osg::BlendColor::Extensions::~Extensions() (or any of the others mentioned below) does wrap successfully (since it is also a protected dtor)? Perhaps it has something to do with the levels of nesting of namespaces? However, the code is valid c++ and successfully compiles and runs on multiple platforms. So I still believe it's a bug in the boost wrapper parser, tho I'm not in a position to create a definitive testcase. You might want to mention to the boost folks. Hmm, looking closer at the original error message, something else strange: >>>osgGL2/Extensions.cpp:37: instantiated from here >>>/usr/local/include/osgGL2/Extensions:178: error: `virtual >>> osgGL2::Extensions::~Extensions()' is protected That dtor is not virtual, I don't know why the error message claims it is? Cheers -- mew""" if anyone wants to see the code in question you have to download it the PyOSG wrappers from here: http://opart.org/pyosg/ the wrapper file you want to look at is in pyosg_devel/osgGL2/Extensions.cpp the class header it wraps is in the OSG package under include/osgGL2/Extensions I don't think the error is on my side in the wrapper code, but if it is found to be, i applogize in advance for this post. -brett __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html From paul at paulgrenyer.co.uk Fri Mar 26 09:55:15 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Fri, 26 Mar 2004 08:55:15 GMT Subject: [C++-sig] MSVC 7.1 Multithreaded Dll Memory Leak [long post] Message-ID: <200403260855.i2Q8tFJ20451@ns.cricketthosting.co.uk> Hi > I am currently running all our unit tests with the static > multithreaded runtime. If they pass then we may well switch to that > for the time being, but I would prefer to fix the problem and keep > using the dll multithreaded runtime. I'm not sure how relevant to most people this post will be, but for those of you that are interested.... All of our C++ unit tests, including those that use the embedded Python interpretter ran successfully when linked against the static runtime, with one exception (pun intended) where an exception was thrown due to an invalid string position. That should be an easy fix and this exercise has hopefully thrown up a bug I can fix. However, all of our boost python extensions (I didn't write the stuff and I'm not sure of the right terminology. I mean C++ code wrapped in boost python to expose it to python) failed with unknown C++ errors or something similar. I suspect this is due to the fact that they are Dlls and therefore presumably need the Dll runtime. Ah! I thought, build everything with the static runtime except the boost python extensions. No! The boost pythong extensions use other libraries in our system that have already been built with the static runtime, so they fail to link. So, I'm stuck with either having to do two different builds to build our whole system (not nice. espcially when you have one large project capable of building and running all tests) or try to get the memory leak fixed. Dave, is this memory leak a recognised problem? Is anything being done to fix it? As the problem is in function.hpp is it worth posting about it to the main boost list? Thanks! Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From benny at kramekweb.com Fri Mar 26 13:26:33 2004 From: benny at kramekweb.com (Benny Kramek) Date: Fri, 26 Mar 2004 12:26:33 +0000 Subject: [C++-sig] Boost::Signals - Python functions as slots Message-ID: <20040326122633.19442.qmail@hosting335.com> I'm using Boost::Signals in C++. I want to be able to attach python functions as slots to the C++ signals. Here is a very simple test that doesn't work. Everything compiles OK, but I get a Python error. ### C++ class class Button { public: void doOnClick(const boost::signal::slot_type& slot); private: boost::signal onClick; }; void Button::doOnClick(const boost::signal::slot_type& slot) { onClick.connect(slot); } ### Boost::Python Module class_