From ndbecker2 at verizon.net Tue Aug 3 16:33:09 2004 From: ndbecker2 at verizon.net (Neal Becker) Date: Tue, 3 Aug 2004 10:33:09 -0400 Subject: [C++-sig] pycxx, sequences, stl Message-ID: <200408031033.09259.ndbecker2@verizon.net> I am experimenting with pycxx. I want to expose STL vector for high-performance c++ algorithms. The idea is to 1) create vectors in python, 2) call C++ algorithms using them. One problem so far, it looks like we have SeqBase, but T has to be a python object. It looks like we can't have SeqBase for example. So we could make SeqBase. This is no good for my purpose. I want my sequences to be compact and fast - just wrap std::vector, for example. Any ideas? From ndbecker2 at verizon.net Wed Aug 4 16:33:19 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Wed, 04 Aug 2004 10:33:19 -0400 Subject: [C++-sig] Optimize vector_indexing_suite set_slice Message-ID: vector_indexing_suite set_slice does: 1) erase 2) insert Shouldn't this be optimized to simply do copy? From MKhesin at liquidnet.com Wed Aug 4 17:16:08 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Wed, 4 Aug 2004 11:16:08 -0400 Subject: [C++-sig] add_property and boost::bind? Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050A77@exchange.lnholdings.com> Is it possible to define a property using boost::python and pass it a boost::bind object instead of a function pointer? e.g something like struct Foo { int lookup(const char*); }; class_("Foo") .add_property("aaa", boost::bind(&Foo::lookup, "aaa")) ; This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldfwyn at 163.com Wed Aug 4 19:23:33 2004 From: ldfwyn at 163.com (Li Dongfeng) Date: Wed, 4 Aug 2004 12:23:33 -0500 Subject: [C++-sig] Numeric--factory function Message-ID: <20040804162324.643CB1E415E@bag.python.org> Hi, I'm trying boost python with the python numarray module. The objective is to do something in C++ arrays and be able to transmit input and output with python using numarray.array. I tried to compile the test files numpy.cpp in the python test directory, mostly it goes well, but I found that the ``factory'' function call cause errors when testing from python. Here are the error messages: >>> exercise_numarray(x, p) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'NumArray' object has no attribute 'array' where x is an numarray.array, browsing the definition from boost python source file ``numeric.cpp'', I found that the ``factory'' function is a method of class ``array_base'', and it just calls the attr("array") to get the ``array'' method from the underlying python numarray.array object. But I found that the python array has no method named ``array''(it is the ``array'' class name, not a *method* of the numarray.array class). In fact, I found that the python numarray.array class has a ``factory'' method. Am I on some error or is the implementation of boost::python::numeric::array_base::factory not compatible with recent python numarray module(I'm using version 1.0)? Another question: how to convert data in a python numarray.array in C++ to/from raw C++ arrays? Using the xnumarray[make_tuple(2,1)]=ycarray[2*ydim2 + 1] like method should be very in-efficient. Hope someone could enlighten me. Please reply to my email in addition to the sig. ????????Li Dongfeng ????????ldfwyn at 163.com ??????????2004-08-04 From jan.heiser at raubtierbaendiger.de Wed Aug 4 18:11:10 2004 From: jan.heiser at raubtierbaendiger.de (Jan Heiser) Date: Wed, 04 Aug 2004 18:11:10 +0200 Subject: [C++-sig] Boost::Python 1.13.1 on SuSE 9.1 x86_64 Message-ID: Hi there, I have successfully compiled Boost 1.31.1 on SuSE 9.1 x86_64 (with the regex patch and the SuSE 9.x patch published in this list/newsgroup). It worked. However, when I tried to compile some code written for Boost::python, I ran into the following problem (compiling with -Wall -Werror) : /usr/local/include/boost-1_31/boost/python/with_custodian_and_ward.hpp: In static member function `static PyObject* boost::python::with_custodian_and_ward_postcall::postcall(const ArgumentPackage&, PyObject*) [with ArgumentPackage = PyObject*, long unsigned int custodian = 0, long unsigned int ward = 1, BasePolicy_ = boost::python::default_call_policies]': /usr/local/include/boost-1_31/boost/python/detail/caller.hpp:201: instantiated from `PyObject* boost::python::detail::caller_arity<1>::impl: :operator()(PyObject*, PyObject*) [with F = XXX, Policies = boost::python::return_internal_reference<1, boost: :python::default_call_policies>, Sig = boost::mpl::vector2]' /usr/local/include/boost-1_31/boost/python/object/py_function.hpp:39: instanti ated from `PyObject* boost::python::objects::caller_py_function_impl::op erator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller, boost::mpl::vector2 >]' /usr/local/include/boost-1_31/boost/mpl/if.hpp:75: instantiated from here /usr/local/include/boost-1_31/boost/python/with_custodian_and_ward.hpp:89: warning: comparison is always false due to limited range of data type It boils down to the fact that on x86_64 unsigned and std::size_t do not have the same width, unsigned still has 32 bits, std::size_t has 64 bits. Now, my idea was to directly change the template function: boost/python/with_custodian_and_ward.hpp:79 - template + template Now my questions: Has anybody else in the world dared to compile and use Boost::python on Linux x86_64 or another 64bit OS? Is the proposed change sensible or does it more damage than it heals? (probably there are more places to change accordingly, though) How to get that into CVS? Jan From rwgk at yahoo.com Wed Aug 4 19:16:27 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 4 Aug 2004 10:16:27 -0700 (PDT) Subject: [C++-sig] Boost::Python 1.13.1 on SuSE 9.1 x86_64 In-Reply-To: Message-ID: <20040804171627.67903.qmail@web20222.mail.yahoo.com> Some additional info. I hope David will respond to this. --- Jan Heiser wrote: > It boils down to the fact that on x86_64 unsigned and std::size_t do not > have the same width, unsigned still has 32 bits, std::size_t has 64 bits. This is the same under SuSE SLES-8 (AMD64), VERSION = 8.1 and Tru64 Unix (Alpha CPU). Boost.Python is known to work on both platforms. > Has anybody else in the world dared to compile and use Boost::python on > Linux x86_64 or another 64bit OS? Yes. We have been doing this for years. Ralf __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From paustin at eos.ubc.ca Wed Aug 4 19:40:14 2004 From: paustin at eos.ubc.ca (Philip Austin) Date: Wed, 4 Aug 2004 10:40:14 -0700 Subject: [C++-sig] Numeric--factory function In-Reply-To: <20040804162324.643CB1E415E@bag.python.org> References: <20040804162324.643CB1E415E@bag.python.org> Message-ID: <16657.8062.551261.320906@gull.eos.ubc.ca> Li Dongfeng writes: > Hi, > > I'm trying boost python with the python numarray module. > The objective is to do something in C++ arrays and be able to > transmit input and output with python using numarray.array. > I tried to compile the test files numpy.cpp in the python > test directory, mostly it goes well, but I > found that the ``factory'' function call > cause errors when testing from python. > > Here are the error messages: > > >>> exercise_numarray(x, p) > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'NumArray' object has no attribute 'array' The signatures for the numarray array constructor, diagonal, trace and a few other functions have changed in recent numarray versions -- I'm working on a patch for this, hopefully by the end of the week -- Phil From dave at boost-consulting.com Wed Aug 4 23:44:44 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 04 Aug 2004 15:44:44 -0600 Subject: [C++-sig] Re: add_property and boost::bind? References: <4B6FB7F60D37D41188C300B0D022E0C003050A77@exchange.lnholdings.com> Message-ID: Max Khesin writes: > Is it possible to define a property using boost::python and pass it a > boost::bind object instead of a function pointer? e.g something like > > > struct Foo > { > int lookup(const char*); > }; > > > class_("Foo") > .add_property("aaa", boost::bind(&Foo::lookup, "aaa")) > ; You can use make_function with a Signature parameter and pass that to add_property. But your bind expression above won't work. Maybe something like: .add_property("aaa", make_function( boost::bind(&Foo::lookup, _1, "aaa") , default_call_policies() , mpl::vector1() ) ) ?? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Wed Aug 4 23:48:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 04 Aug 2004 15:48:42 -0600 Subject: [C++-sig] Re: Boost::Python 1.13.1 on SuSE 9.1 x86_64 References: Message-ID: Jan Heiser writes: > It boils down to the fact that on x86_64 unsigned and std::size_t do not > have the same width, unsigned still has 32 bits, std::size_t has 64 bits. > > > Now, my idea was to directly change the template function: > > boost/python/with_custodian_and_ward.hpp:79 > - template default_call_policies> > + template default_call_policies> I wouldn't want to make that change. I'd much rather use a std::size_t for the arity variable at the line of the warning. But either way, this warning is obviously completely bogus. A size_t can never be greater than an unsigned int??! My advice: turn off -Wall and/or -Werror. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From MKhesin at liquidnet.com Thu Aug 5 07:46:07 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Thu, 5 Aug 2004 01:46:07 -0400 Subject: [C++-sig] Re: add_property and boost::bind? Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050A7B@exchange.lnholdings.com> > You can use make_function with a Signature parameter and pass that to > add_property. But your bind expression above won't work. > > Maybe something like: > > .add_property("aaa", > make_function( > boost::bind(&Foo::lookup, _1, "aaa") > , default_call_policies() > , mpl::vector1() > ) > ) > This is what I was looking for. I knew my example was not complete - it was just wishful thinking code. But this fails to compile on vc6 & vc8, both pretty much indicate the same error: c:\home\mkhesin\libs\boost_1_31_0\boost\bind.hpp(246) : error C2784: 'result_traits::type boost::_bi::list0::operator [](const boost::_bi::bind_t &) const' : could not deduce template argument for 'const boost::_bi::bind_t &' from 'boost::arg' with [ I=1 ] any idea? This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. From dalwan01 at student.umu.se Thu Aug 5 10:51:56 2004 From: dalwan01 at student.umu.se (Daniel Wallin) Date: Thu, 05 Aug 2004 10:51:56 +0200 Subject: [C++-sig] Re: add_property and boost::bind? In-Reply-To: <4B6FB7F60D37D41188C300B0D022E0C003050A7B@exchange.lnholdings.com> References: <4B6FB7F60D37D41188C300B0D022E0C003050A7B@exchange.lnholdings.com> Message-ID: Max Khesin wrote: >>You can use make_function with a Signature parameter and pass that to >>add_property. But your bind expression above won't work. >> >>Maybe something like: >> >> .add_property("aaa", >> make_function( >> boost::bind(&Foo::lookup, _1, "aaa") >> , default_call_policies() >> , mpl::vector1() >> ) >> ) >> > > > This is what I was looking for. I knew my example was not complete - it was > just wishful thinking code. But this fails to compile on vc6 & vc8, both > pretty much indicate the same error: > c:\home\mkhesin\libs\boost_1_31_0\boost\bind.hpp(246) : error C2784: > 'result_traits::type boost::_bi::list0::operator [](const > boost::_bi::bind_t &) const' : could not deduce template argument for > 'const boost::_bi::bind_t &' from 'boost::arg' > with > [ > I=1 > ] > > any idea? I think the signature is supposed to be: mpl::vector2 The make_function() call above will create a nullary function, where _1 doesn't make any sense. HTH, -- Daniel Wallin From MKhesin at liquidnet.com Thu Aug 5 16:31:47 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Thu, 5 Aug 2004 10:31:47 -0400 Subject: [C++-sig] Re: add_property and boost::bind? Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050A82@exchange.lnholdings.com> awsome, it woiks! Thanks, Dave, Daniel. m > -----Original Message----- > From: Daniel Wallin [mailto:dalwan01 at student.umu.se] > Sent: Thursday, August 05, 2004 4:52 AM > To: c++-sig at python.org > Subject: [C++-sig] Re: add_property and boost::bind? > > > Max Khesin wrote: > >>You can use make_function with a Signature parameter and > pass that to > >>add_property. But your bind expression above won't work. > >> > >>Maybe something like: > >> > >> .add_property("aaa", > >> make_function( > >> boost::bind(&Foo::lookup, _1, "aaa") > >> , default_call_policies() > >> , mpl::vector1() > >> ) > >> ) > >> > > > > > > This is what I was looking for. I knew my example was not > complete - it was > > just wishful thinking code. But this fails to compile on > vc6 & vc8, both > > pretty much indicate the same error: > > c:\home\mkhesin\libs\boost_1_31_0\boost\bind.hpp(246) : error C2784: > > 'result_traits::type boost::_bi::list0::operator [](const > > boost::_bi::bind_t &) const' : could not deduce > template argument for > > 'const boost::_bi::bind_t &' from 'boost::arg' > > with > > [ > > I=1 > > ] > > > > any idea? > > I think the signature is supposed to be: > > mpl::vector2 > > The make_function() call above will create a nullary > function, where _1 > doesn't make any sense. > > HTH, > -- > Daniel Wallin > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan.heiser at raubtierbaendiger.de Thu Aug 5 18:14:02 2004 From: jan.heiser at raubtierbaendiger.de (Jan Heiser) Date: Thu, 05 Aug 2004 18:14:02 +0200 Subject: [C++-sig] Re: Boost::Python 1.13.1 on SuSE 9.1 x86_64 References: Message-ID: David Abrahams wrote: > Jan Heiser writes: > >> It boils down to the fact that on x86_64 unsigned and std::size_t do not >> have the same width, unsigned still has 32 bits, std::size_t has 64 bits. >> >> >> Now, my idea was to directly change the template function: >> >> boost/python/with_custodian_and_ward.hpp:79 >> - template > default_call_policies> >> + template > default_call_policies> > > I wouldn't want to make that change. I'd much rather use a > std::size_t for the arity variable at the line of the warning. But > either way, this warning is obviously completely bogus. A size_t can > never be greater than an unsigned int??! Changing the type of arity works. You're right, this is probably better. Any chance this will be put into CVS so it'll be part of the next release? > My advice: turn off -Wall and/or -Werror. For the project Boost::python is used in, it is important that -Wall -Werror is turned on. After it was introduced, quite a number of bugs directly showed up. Jan From dave at boost-consulting.com Thu Aug 5 18:55:31 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 05 Aug 2004 10:55:31 -0600 Subject: [C++-sig] Re: Boost::Python 1.13.1 on SuSE 9.1 x86_64 References: Message-ID: Jan Heiser writes: > David Abrahams wrote: > >> Jan Heiser writes: >> >>> It boils down to the fact that on x86_64 unsigned and std::size_t do not >>> have the same width, unsigned still has 32 bits, std::size_t has 64 bits. >>> >>> >>> Now, my idea was to directly change the template function: >>> >>> boost/python/with_custodian_and_ward.hpp:79 >>> - template >> default_call_policies> >>> + template >> default_call_policies> >> >> I wouldn't want to make that change. I'd much rather use a >> std::size_t for the arity variable at the line of the warning. But >> either way, this warning is obviously completely bogus. A size_t can >> never be greater than an unsigned int??! > > Changing the type of arity works. You're right, this is probably better. Any > chance this will be put into CVS so it'll be part of the next release? > >> My advice: turn off -Wall and/or -Werror. > > For the project Boost::python is used in, it is important that -Wall -Werror > is turned on. After it was introduced, quite a number of bugs directly > showed up. If you agree to report the bug to the GCC maintainers, I'll happily apply the patch. Caveat: I can by no means guarantee that GCC won't emit other silly warnings for Boost.Python code. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From xin at xlevus.net Sat Aug 7 07:02:17 2004 From: xin at xlevus.net (xin) Date: Fri, 06 Aug 2004 22:02:17 -0700 Subject: [C++-sig] Exposing C++ Class instances to Python Message-ID: So I have the following code. /***** START Point.cpp *****/ struct Point { Point() { count = 0; size = 1; script="testScript"} int count; int size; char *script; }; BOOST_PYTHON_MODULE(HgSharedLib) { class_("Point") .def_readonly("count", &Point::count) .def_readwrite("size", &Point::size); } /***** END Point.cpp *****/ /***** START PyController.cpp ******/ PyObject *pyController::getPyFunc(char *moduleName, char *functionName) { /* Courtsey of Jeffrey Holle */ PyObject *pModule = PyImport_ImportModule(moduleName); if(pModule == NULL) std::cout << "The Python Module \"" << moduleName << "\" is not available" << std::endl; PyObject *pDict = PyModule_GetDict(pModule); if(pDict == NULL) std::cout << "Failed to Aqquire dictionary of \"" << moduleName << "\"" << std::endl; PyObject *pFunc = PyDict_GetItemString(pDict,functionName); if(pFunc == NULL) std::cout << "Failed to find requested python function \"" << functionName << "\"" << std::endl; Py_DECREF(pModule); return pFunc; } bool pyController::runScript(Point &dest) { Py_Initialize(); PyRun_SimpleString("import sys\nsys.path.append(\"/home/xin/code/Hg/src\")"); PyObject *pFunc = getPyFunc(dest.script, "TestFunc"); std::cout << "Start Size: " << dest.size << std::endl; // Run TestFunc Here std::cout << "End Size: " << dest.size << std::endl; Py_Finalize(); } /***** END PyController.cpp *****/ /**** START main.cpp *****/ int main() { Point foo; pyController PyCon; PyCon.runScript(foo); return 0 } /**** END main.cpp *****/ /***** START testScript.py *****/ def TestFunc (pt): pt.size = 5 return pt.size /***** END testScript.py *****/ My overall goal is to run TestFunc on foo. And the output to end up like. Start Size: 1 End Size: 5 What Im unsure of, is how to turn foo into a PyObject to then run the python FUnction TestFunc with the new PyObject (foo) as an arguement. ( Python Equiv: TestFunc(foo) ) I hope Im making sense.. Thanks for you help From ndbecker2 at verizon.net Fri Aug 6 16:35:24 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Fri, 06 Aug 2004 10:35:24 -0400 Subject: [C++-sig] numarray, lvalue_from_pytype Message-ID: I'm trying to write some c++ functions to be interfaced with numarray. I ran into this: TypeError: No registered converter was able to extract a C++ reference to type s_PyArrayObject from this Python object of type NumArray I thought I'd use lvalue_from_pytype like this: lvalue_from_pytype, &_numarray_type>(); Problem is, _numarray_type is declared static, so the symbol is not visible. In fact, this is right out of the model python type extension code, so it would typically be the case that the PyTypeObject is static in the defining module. Any suggestions? From jmastro at rochester.rr.com Mon Aug 9 01:25:15 2004 From: jmastro at rochester.rr.com (James Mastro) Date: Sun, 8 Aug 2004 19:25:15 -0400 Subject: [C++-sig] Wrapped shared_ptr's Message-ID: <200408081925.15748.jmastro@rochester.rr.com> Well, I have C++ and Python working together happily for my basic types. How do I go about wrapping shared_ptr's, though? My C++ code doesn't pass around any raw ptr's, just shared_ptr's. So I have a class called ObjectPtr: class Object { public: Object() {} void setData( int data ) { mData = data; } private: int mData; }; typedef boost::shared_ptr ObjectPtr; Right now this works fine with Python if I'm just passing the object back and forth. But I want to call Object's functions from Python. What I have now is just this: BOOST_PYTHON_MODULE( MyModule ) { class_< ObjectPtr>( "Object", init<>() ) .def( "setData", &Object::setData ) ; } which is of course incorrect. Is register_ptr_to_python required here? -jim From joel at boost-consulting.com Mon Aug 9 06:10:46 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Mon, 09 Aug 2004 12:10:46 +0800 Subject: [C++-sig] Optimize vector_indexing_suite set_slice In-Reply-To: References: Message-ID: <4116F946.8060006@boost-consulting.com> Neal D. Becker wrote: > vector_indexing_suite set_slice does: 1) erase 2) insert > > Shouldn't this be optimized to simply do copy? You mean this: container.erase(container.begin()+from, container.begin()+to); container.insert(container.begin()+from, v); Pardon me for being slow, but how? Could you spell it out for me? Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From roman.yakovenko at actimize.com Mon Aug 9 07:19:44 2004 From: roman.yakovenko at actimize.com (Roman Yakovenko) Date: Mon, 9 Aug 2004 08:19:44 +0300 Subject: [C++-sig] new idea for pyste Message-ID: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB2@exchange.adrembi.com> Hi. I am working with pyste for an year. It is very good tool for small projects. One thing that confuse me is passing arguments to pyste. I need to write an other script, that will run\configure pyste. ( I working on windows so an other script is batch file ). I prefer an other way. To export object called environment, that will have all necessary pyste configuration stuffs. For example: class environment(object): def __init__(self): self.__gccxml_path = 'gccxml.exe' #gccxml.exe should be in PATH self.__include_pathes = [] self.__module_name = None ... def __get_gccxml_path( self ): return self.__gccxml_path def __set_gccxml_path( self, gccxml_path ): self.__gccxml_path = gccxml_path gccxml_path = property( __get_gccxml_path, __set_gccxml_path ) ... I think that moving this direction is good for a few reasons. One of them is - it will cancel pyste files as special purpose files. Those files will be regular python scripts. Also I think that this will simplifier pyste. Example: ( pseudo code ) env = environment() env.gccxml_path = r'c:\gccxml\gccxml.exe' env.include_path = [ r'c:\boost_cvs', r'c:\whatever' ] env.use_namespace = 'py' env.debug = False env.working_directory = r'r'c:\development\repository_api\py_api' SetModuleName( 'PyRepository' ) for header_file in directory( r'c:\development\repository_api' ): AllFromHeader( header_file ) GenerateMain( 'PyRepository.cpp' ) What do you think about this? I would like to contribute pathces. Roman From dave at boost-consulting.com Mon Aug 9 14:16:33 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 06:16:33 -0600 Subject: [C++-sig] Re: Wrapped shared_ptr's References: <200408081925.15748.jmastro@rochester.rr.com> Message-ID: James Mastro writes: > Well, I have C++ and Python working together happily for my basic types. How > do I go about wrapping shared_ptr's, though? My C++ code doesn't pass around > any raw ptr's, just shared_ptr's. So I have a class called ObjectPtr: > > class Object { > public: > Object() {} > void setData( int data ) { mData = data; } > private: > int mData; > }; > typedef boost::shared_ptr ObjectPtr; > > Right now this works fine with Python if I'm just passing the object back and > forth. But I want to call Object's functions from Python. What I have now is > just this: > > BOOST_PYTHON_MODULE( MyModule ) > { > class_< ObjectPtr>( "Object", init<>() ) > .def( "setData", &Object::setData ) > ; > } > which is of course incorrect. Is register_ptr_to_python required here? No; just use class_. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Mon Aug 9 15:15:06 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 07:15:06 -0600 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> Message-ID: Joel de Guzman writes: > Neal D. Becker wrote: > >> vector_indexing_suite set_slice does: 1) erase 2) insert >> Shouldn't this be optimized to simply do copy? > > You mean this: > > container.erase(container.begin()+from, container.begin()+to); > container.insert(container.begin()+from, v); > > Pardon me for being slow, but how? Could you spell it out for me? It's not as simple as "copy", but if you think hard about it you can see how to avoid any redundant moves or copies. The pseudocode is complicated so I'm not writing it out in full here, but: if new_size <= old_size: erase(old_finish + (new_size - old_size), old_finish) if new_size < old_size: copy(new_start, new_finish, old_start) else: # fill in the details here -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Mon Aug 9 15:16:21 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 07:16:21 -0600 Subject: [C++-sig] Re: new idea for pyste References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB2@exchange.adrembi.com> Message-ID: "Roman Yakovenko" writes: > I think that moving this direction is good for a few reasons. One of them is > - it will cancel pyste files as special purpose files. Those files will be > regular python scripts. Also I think that this will simplifier pyste. I thought Pyste files *were* regular Python (?) That was one of the things I tried to convince Bruno to do in his design. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From rwgk at yahoo.com Mon Aug 9 16:13:09 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 9 Aug 2004 07:13:09 -0700 (PDT) Subject: [C++-sig] make_constructor & keyword arguments? Message-ID: <20040809141309.18824.qmail@web20227.mail.yahoo.com> Is it possible to add keyword argument support to a constructor injected with boost::python::make_constructor? I tried this .def("__init__", boost::python::make_constructor(from_iselection_unsigned), (arg_("size"), arg_("iselection"))) but it doesn't compile ("incomplete type"). I also tried using operator() and operator[] of the make_constructor instance; it compiles but doesn't work at runtime. What is the correct syntax? Thanks! Ralf __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Mon Aug 9 16:28:46 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 08:28:46 -0600 Subject: [C++-sig] Re: make_constructor & keyword arguments? References: <20040809141309.18824.qmail@web20227.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > Is it possible to add keyword argument support to a constructor injected with > boost::python::make_constructor? I tried this > > .def("__init__", > boost::python::make_constructor(from_iselection_unsigned), > (arg_("size"), arg_("iselection"))) > > but it doesn't compile ("incomplete type"). Full error message please? > I also tried using operator() and > operator[] of the make_constructor instance; it compiles but doesn't work at > runtime. Not surprising. make_constructor just returns a callable python::object, so operator() and operator[] just do the ordinary things you might expect to that object. > What is the correct syntax? I think you need a "self" argument, though I might be wrong. .def("__init__", boost::python::make_constructor( from_iselection_unsigned , (arg_("self"), arg_("size"), arg_("iselection")) )) The reference docs for make_function/make_constructor need to be fixed, as I posted last week. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From rwgk at yahoo.com Mon Aug 9 17:28:31 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 9 Aug 2004 08:28:31 -0700 (PDT) Subject: [C++-sig] Re: make_constructor & keyword arguments? In-Reply-To: Message-ID: <20040809152831.35504.qmail@web20227.mail.yahoo.com> --- David Abrahams wrote: > I think you need a "self" argument, though I might be wrong. > > .def("__init__", > boost::python::make_constructor( > from_iselection_unsigned > , (arg_("self"), arg_("size"), arg_("iselection")) > )) Using this code exactly (copy-and-paste) I am getting the following error messages: Linux RH8, gcc 3.4.0: http://cci.lbl.gov/~rwgk/tmp/make_constructor_keyword_problem_gcc340 Tru64 5, cxx 6.5 (EDG 245): http://cci.lbl.gov/~rwgk/tmp/make_constructor_keyword_problem_cxx65 I also tried without the arg_("self") but the errors are pretty much the same. BTW: typedef boost::python::arg arg_; // gcc 2.96 workaround Ralf _______________________________ Do you Yahoo!? Express yourself with Y! Messenger! Free. Download now. http://messenger.yahoo.com From dave at boost-consulting.com Mon Aug 9 18:13:46 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 10:13:46 -0600 Subject: [C++-sig] Re: make_constructor & keyword arguments? References: <20040809152831.35504.qmail@web20227.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > Using this code exactly (copy-and-paste) I am getting the following error > messages: > > Linux RH8, gcc 3.4.0: > http://cci.lbl.gov/~rwgk/tmp/make_constructor_keyword_problem_gcc340 > > Tru64 5, cxx 6.5 (EDG 245): > http://cci.lbl.gov/~rwgk/tmp/make_constructor_keyword_problem_cxx65 > > I also tried without the arg_("self") but the errors are pretty much the same. Oh, whoops, you need call policies if you want to supply keywords: .def("__init__", boost::python::make_constructor( from_iselection_unsigned , boost::python::default_call_policies() , (arg_("self"), arg_("size"), arg_("iselection")) )) It should be fairly obvious from looking at make_constructor.hpp (I know that's a lame excuse for inadequate documentation). > BTW: typedef boost::python::arg arg_; // gcc 2.96 workaround You can add that typedef to args.hpp if you like. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From rwgk at yahoo.com Mon Aug 9 20:31:13 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 9 Aug 2004 11:31:13 -0700 (PDT) Subject: [C++-sig] Re: make_constructor & keyword arguments? In-Reply-To: Message-ID: <20040809183113.77363.qmail@web20227.mail.yahoo.com> --- David Abrahams wrote: > Oh, whoops, you need call policies if you want to supply keywords: > > .def("__init__", > boost::python::make_constructor( > from_iselection_unsigned > , boost::python::default_call_policies() > , (arg_("self"), arg_("size"), arg_("iselection")) > )) This compiles after I deleted arg_("self"). However, the keywords don't seem to do anything. I went back to the basics and modified boost/libs/python/test/injected.cpp based on the boost CVS head from a few minutes ago: Index: injected.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/python/test/injected.cpp,v retrieving revision 1.2 diff -r1.2 injected.cpp 12a13 > #include 32c33,37 < .def("__init__", make_constructor(product), "this is product's docstring") --- > .def("__init__", make_constructor(product > , default_call_policies() > , (arg("a"), arg("b"), arg("c")) > ), > "this is product's docstring") This compiles without a problem and the following Python code still works as expected (i.e. prints the value 105): from injected_ext import * print X(3,5,7).value() However, this line results in an error: print X(3,5,c=7).value() Traceback (most recent call last): File "/net/cci/rwgk/zi", line 3, in ? print X(3,5,c=7).value() Boost.Python.ArgumentError: Python argument types in X.__init__(X, int, int) did not match C++ signature: __init__(boost::python::api::object, int, int, int) __init__(boost::python::api::object, int, int) __init__(boost::python::api::object) __init__(_object*, int) I'd expect to see the the keywords in the traceback, e.g.: __init__(boost::python::api::object, int a, int b, int c) Could it be that my list of arg's is not actually used in make_constructor.hpp? Thanks! Ralf __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Mon Aug 9 21:26:20 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 13:26:20 -0600 Subject: [C++-sig] Re: make_constructor & keyword arguments? References: <20040809183113.77363.qmail@web20227.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > This compiles without a problem and the following Python code still works as > expected (i.e. prints the value 105): > > from injected_ext import * > print X(3,5,7).value() > > However, this line results in an error: > > print X(3,5,c=7).value() > > Traceback (most recent call last): > File "/net/cci/rwgk/zi", line 3, in ? > print X(3,5,c=7).value() > Boost.Python.ArgumentError: Python argument types in > X.__init__(X, int, int) > did not match C++ signature: > __init__(boost::python::api::object, int, int, int) > __init__(boost::python::api::object, int, int) > __init__(boost::python::api::object) > __init__(_object*, int) > > I'd expect to see the the keywords in the traceback, e.g.: > > __init__(boost::python::api::object, int a, int b, int c) > > Could it be that my list of arg's is not actually used in make_constructor.hpp? I don't think that's the problem. Try changing (in make_constructor.hpp): enum { arity = mpl::size::value - 1 }; to: enum { arity = mpl::size::value }; Then add back the "self" keyword and let me know if it works. If it all works, please check in your modifications to the test and the file. Thanks (sorry) Dave -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From paul.bridger at paradise.net.nz Mon Aug 9 23:01:20 2004 From: paul.bridger at paradise.net.nz (paul.bridger) Date: Tue, 10 Aug 2004 09:01:20 +1200 Subject: [C++-sig] Re: new idea for pyste In-Reply-To: References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB2@exchange.adrembi.com> Message-ID: <4117E620.2070601@paradise.net.nz> Pyste files are regular python, but they are not executable by themselves. I think RY wants to be able to do something like: # foo.pyste import Pyste yoink = Class('Yoink', 'yoink.h') and then be able to: $ python foo.pyste David Abrahams wrote: > "Roman Yakovenko" writes: > > >>I think that moving this direction is good for a few reasons. One of them is >>- it will cancel pyste files as special purpose files. Those files will be >>regular python scripts. Also I think that this will simplifier pyste. > > > I thought Pyste files *were* regular Python (?) That was one of the > things I tried to convince Bruno to do in his design. > From rwgk at yahoo.com Mon Aug 9 23:31:32 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 9 Aug 2004 14:31:32 -0700 (PDT) Subject: [C++-sig] Re: make_constructor & keyword arguments? In-Reply-To: Message-ID: <20040809213132.49525.qmail@web20223.mail.yahoo.com> --- David Abrahams wrote: > > Could it be that my list of arg's is not actually used in > make_constructor.hpp? > > I don't think that's the problem. I am afraid you have to change your mind. :-) Here is the critical patch: Index: make_constructor.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/python/make_constructor.hpp,v retrieving revision 1.3 diff -u -r1.3 make_constructor.hpp --- make_constructor.hpp 5 Jan 2004 11:46:29 -0000 1.3 +++ make_constructor.hpp 9 Aug 2004 21:19:02 -0000 @@ -184,6 +184,7 @@ detail::caller(f, inner_policy(p)) , outer_signature() ) + , kw ); } // } > Try changing (in make_constructor.hpp): > > enum { arity = mpl::size::value - 1 }; > > to: > > enum { arity = mpl::size::value }; > > Then add back the "self" keyword and let me know if it works. With my "critical" patch it works both ways. With "- 1" and without arg("self") the traceback shows: __init__(boost::python::api::object, int a, int b, int c) Without the "- 1" and with arg("self"): __init__(boost::python::api::object self, int a, int b, int c) The latter is inconsistent with the traceback resulting from wrapping constructors the regular way (e.g. .def(init((arg("x"))) ). I also find it inconvenient having to provide arg("self") all the time. Therefore I am leaning towards keeping the "- 1" in make_constructor.hpp. What do you think? While poking around I discovered that the keywords are also not used correctly in this situation: class_("X", init((arg("x")))) Where would I be looking for missing ", kw" to fix this? Ralf __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail From rwgk at yahoo.com Tue Aug 10 00:22:46 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 9 Aug 2004 15:22:46 -0700 (PDT) Subject: [C++-sig] Re: make_constructor & keyword arguments? In-Reply-To: <20040809213132.49525.qmail@web20223.mail.yahoo.com> Message-ID: <20040809222246.33523.qmail@web20225.mail.yahoo.com> --- "Ralf W. Grosse-Kunstleve" wrote: > While poking around I discovered that the keywords are also not used > correctly > in this situation: > > class_("X", init((arg("x")))) Sorry, I have to take this back; I must have done something silly. At second look this turns out to work correctly. Ralf __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail From psbolanos at hotmail.com Tue Aug 10 01:08:07 2004 From: psbolanos at hotmail.com (Pedro Bolaņos) Date: Mon, 09 Aug 2004 23:08:07 +0000 Subject: [C++-sig] Boost-Python Message-ID: Hi, I've been trying to build boost-python both through the visual studio project file, and by using bjam. Either way I get the following output (errors): ------ Build started: Project: boost_python, Configuration: Debug Win32 ------ Compiling... type_id.cpp tuple.cpp str.cpp registry.cpp pickle_support.cpp ../../../../boost\python\args_fwd.hpp(46) : error C2118: negative subscript or subscript is too large ../../../../boost\python\args_fwd.hpp(47) : see reference to class template instantiation 'boost::python::detail::error::more_keywords_than_function_arguments<,>' being compiled object_protocol.cpp object_operators.cpp numeric.cpp module.cpp long.cpp list.cpp life_support.cpp iterator.cpp ../../../../boost\python\args_fwd.hpp(46) : error C2118: negative subscript or subscript is too large ../../../../boost\python\args_fwd.hpp(47) : see reference to class template instantiation 'boost::python::detail::error::more_keywords_than_function_arguments<,>' being compiled inheritance.cpp ../../../../boost\pending\detail\property.hpp(75) : error C2039: 'result<`template-parameter258'>' : is not a member of 'boost::detail::property_value_end' ../../../../boost\pending\detail\property.hpp(75) : fatal error C1507: previous user errors and subsequent error recovery halt further compilation function.cpp ../../../../boost\python\args_fwd.hpp(46) : error C2118: negative subscript or subscript is too large ../../../../boost\python\args_fwd.hpp(47) : see reference to class template instantiation 'boost::python::detail::error::more_keywords_than_function_arguments<,>' being compiled from_python.cpp errors.cpp enum.cpp dict.cpp class.cpp Generating Code... Compiling... builtin_converters.cpp \Desarrollo\boost_1_31_0\libs\python\src\converter\builtin_converters.cpp(78) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data \Desarrollo\boost_1_31_0\libs\python\src\converter\builtin_converters.cpp(71) : while compiling class-template member function 'void boost::python::converter::`anonymous-namespace'::slot_rvalue_from_python::construct(PyObject *,boost::python::converter::rvalue_from_python_stage1_data *)' with [ T=float, SlotPolicy=boost::python::converter::`anonymous-namespace'::float_rvalue_from_python ] \Desarrollo\boost_1_31_0\libs\python\src\converter\builtin_converters.cpp(397) : see reference to class template instantiation 'boost::python::converter::`anonymous-namespace'::slot_rvalue_from_python' being compiled with [ T=float, SlotPolicy=boost::python::converter::`anonymous-namespace'::float_rvalue_from_python ] arg_to_python_base.cpp aix_init_module.cpp Generating Code... Build log was saved at "file://c:\Desarrollo\boost_1_31_0\libs\python\build\VisualStudio\debug-obj\BuildLog.htm" boost_python - 5 error(s), 1 warning(s) ---------------------- Done ---------------------- Build: 0 succeeded, 1 failed, 0 skipped What can I do about it? Am I doing something wrong? - I'm working on Windows XP - I'm using Microsoft Visual Studio .NET 2003 - I'm using Boost 1.31 and boost-jam 3.1.10 Thanks, Pedro Bola?os. _________________________________________________________________ STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail From dave at boost-consulting.com Tue Aug 10 03:43:16 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 19:43:16 -0600 Subject: [C++-sig] Re: make_constructor & keyword arguments? References: <20040809213132.49525.qmail@web20223.mail.yahoo.com> <20040809222246.33523.qmail@web20225.mail.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- "Ralf W. Grosse-Kunstleve" wrote: >> While poking around I discovered that the keywords are also not used >> correctly >> in this situation: >> >> class_("X", init((arg("x")))) > > Sorry, I have to take this back; I must have done something silly. At second > look this turns out to work correctly. OK, please feel free to apply any patch you believe is correct, as long as there's a regression test to go with it. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Aug 10 03:49:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Aug 2004 19:49:50 -0600 Subject: [C++-sig] Re: Boost-Python References: Message-ID: "Pedro Bola?os" writes: > Hi, > > I've been trying to build boost-python both through the visual studio > project file, and by using bjam. Either way I get the following output > (errors): > What can I do about it? Am I doing something wrong? > - I'm working on Windows XP > - I'm using Microsoft Visual Studio .NET 2003 > - I'm using Boost 1.31 and boost-jam 3.1.10 I can't vouch for the VS project file (that's maintained by Brett Calcott as described here: http://www.boost.org/libs/python/doc/building.html#VisualStudio), but I promise you that combination worked with bjam when we shipped Boost 1.31.0 Are you sure you get the same errors in either case? Are you certain that it's actually using vc7.1 and not some earlier version of vc++ (you can check by adding -d+2 to the start of the bjam command-line to see the build commands). What bjam command-line/environment settings are you using? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From nicodemus at esss.com.br Tue Aug 10 04:53:34 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 09 Aug 2004 23:53:34 -0300 Subject: [C++-sig] Re: new idea for pyste In-Reply-To: <4117E620.2070601@paradise.net.nz> References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB2@exchange.adrembi.com> <4117E620.2070601@paradise.net.nz> Message-ID: <411838AE.4070900@esss.com.br> Hi everybody, As some of you may have noticed, I have been a little off the list lately. Right now I have a full day job, I'm finishing my college, and lately I've been working on a side project for another company on my spare time. As one can see, little to no time is left to work on my personal projects (Pyste here included). That's the reason why I sometimes take days to respond a message or apply patches (which are very appreciatted. Thanks to all the contributors!). That does not mean that I plan to abandon Pyste, on the contrary: I plan to give it a good re-write next year (when I'm finally a graduate 8)), or at least dedicate a good time to bring it up to good shape (yes Niall, including fixing AllFromHeader ;)). But enough rambling. I think the idea is nice, but I would like to see what's the improvement over something like this: import os import sys from Pyste import pyste # manipulate argv as needed sys.argv.append(...) # add/find include directories at your leisure sys.argv.append('-I') sys.argv.append('my dir') pyste.main() main() could be made to take an argv instead of always using sys.argv, but that change is trivial (I was surprised that it was not already that way: I always write main()'s like that...). Anyway, I think both ways to work with Pyste are valid: they can coexist peacefully if Roman's idea is proved to be useful. Regards, Nicodemus. paul.bridger wrote: > Pyste files are regular python, but they are not executable by > themselves. I think RY wants to be able to do something like: > > # foo.pyste > import Pyste > yoink = Class('Yoink', 'yoink.h') > > and then be able to: > $ python foo.pyste > > David Abrahams wrote: > >> "Roman Yakovenko" writes: >> >> >>> I think that moving this direction is good for a few reasons. One of >>> them is >>> - it will cancel pyste files as special purpose files. Those files >>> will be regular python scripts. Also I think that this will >>> simplifier pyste. >> >> >> >> I thought Pyste files *were* regular Python (?) That was one of the >> things I tried to convince Bruno to do in his design. >> > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From joel at boost-consulting.com Tue Aug 10 05:13:04 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Tue, 10 Aug 2004 11:13:04 +0800 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice In-Reply-To: References: <4116F946.8060006@boost-consulting.com> Message-ID: <41183D40.9070301@boost-consulting.com> David Abrahams wrote: > Joel de Guzman writes: > > >>Neal D. Becker wrote: >> >> >>>vector_indexing_suite set_slice does: 1) erase 2) insert >>>Shouldn't this be optimized to simply do copy? >> >>You mean this: >> >> container.erase(container.begin()+from, container.begin()+to); >> container.insert(container.begin()+from, v); >> >>Pardon me for being slow, but how? Could you spell it out for me? > > > It's not as simple as "copy", but if you think hard about it you can > see how to avoid any redundant moves or copies. The pseudocode is > complicated so I'm not writing it out in full here, but: > > if new_size <= old_size: > erase(old_finish + (new_size - old_size), old_finish) > if new_size < old_size: > copy(new_start, new_finish, old_start) > else: > # fill in the details here I see. Yeah, same ol' buffer management. Ok, I'll optimize it. But it'll have to be after 1.32. Ok? Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From roman.yakovenko at actimize.com Tue Aug 10 06:47:46 2004 From: roman.yakovenko at actimize.com (Roman Yakovenko) Date: Tue, 10 Aug 2004 07:47:46 +0300 Subject: [C++-sig] Re: new idea for pyste Message-ID: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB6@exchange.adrembi.com> From: Nicodemus > I think the idea is nice, but I would like to see what's the > improvement > over something like this: > ... > Regards, > Nicodemus. The main differences are: Pyste is library that helps user to export his classes Pyste files is regular python files, and not "... simple interface file ..." It is much easier to manage big projects: 1. No need in "file-list" file 2. better control over generation: ( example: I want to generate all classes from specific namespace, to an other file, right now Pyste support only generation from header file and then excluding all classes that I don't want to be exported. I think it could be much easier to write AllFromNamespace( 'repository', [ 'a.h', 'b.h', 'c.h' ] ) ( new functionality -> new Pyste options -> complicated command line -> additional script to run Pyste ) > import os > import sys > from Pyste import pyste > > # manipulate argv as needed > sys.argv.append(...) > > # add/find include directories at your leisure > sys.argv.append('-I') > sys.argv.append('my dir') > > pyste.main() > You are right: right now the difference between what I propose and what we have is small, but it completely change the future: instead of "code generator" + "interface files" + "options" we will have "code generation framework" + "scripts written in python" only. Roman From dave at boost-consulting.com Tue Aug 10 15:13:49 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 Aug 2004 07:13:49 -0600 Subject: [C++-sig] Re: new idea for pyste References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB2@exchange.adrembi.com> <4117E620.2070601@paradise.net.nz> <411838AE.4070900@esss.com.br> Message-ID: Nicodemus writes: > Hi everybody, > > As some of you may have noticed, I have been a little off the list > lately. Right now I have a full day job, I'm finishing my college, and > lately I've been working on a side project for another company on my > spare time. As one can see, little to no time is left to work on my > personal projects (Pyste here included). That's the reason why I > sometimes take days to respond a message or apply patches (which are > very appreciatted. Thanks to all the contributors!). That does not > mean that I plan to abandon Pyste, on the contrary: I plan to give it > a good re-write next year (when I'm finally a graduate 8)), or at > least dedicate a good time to bring it up to good shape (yes Niall, > including fixing AllFromHeader ;)). But enough rambling. Maybe we can coordinate that with the langbinding project, Daniel Wallin's and my big rewrite thing. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Aug 10 15:14:58 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 Aug 2004 07:14:58 -0600 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> <41183D40.9070301@boost-consulting.com> Message-ID: Joel de Guzman writes: > David Abrahams wrote: > >> Joel de Guzman writes: >> >>>Neal D. Becker wrote: >>> >>> >>>>vector_indexing_suite set_slice does: 1) erase 2) insert >>>>Shouldn't this be optimized to simply do copy? >>> >>>You mean this: >>> >>> container.erase(container.begin()+from, container.begin()+to); >>> container.insert(container.begin()+from, v); >>> >>>Pardon me for being slow, but how? Could you spell it out for me? >> It's not as simple as "copy", but if you think hard about it you can >> see how to avoid any redundant moves or copies. The pseudocode is >> complicated so I'm not writing it out in full here, but: >> if new_size <= old_size: >> erase(old_finish + (new_size - old_size), old_finish) >> if new_size < old_size: >> copy(new_start, new_finish, old_start) >> else: >> # fill in the details here > > I see. Yeah, same ol' buffer management. Ok, I'll optimize it. > But it'll have to be after 1.32. Ok? Sure thing. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Aug 10 15:14:34 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 Aug 2004 07:14:34 -0600 Subject: [C++-sig] Re: new idea for pyste References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CB6@exchange.adrembi.com> Message-ID: "Roman Yakovenko" writes: > You are right: right now the difference between what I propose and > what we have is small, but it completely change the future: instead > of "code generator" + "interface files" + "options" we will have > "code generation framework" + "scripts written in python" only. I support the proposed approach. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From itamar at itamarst.org Tue Aug 10 16:06:06 2004 From: itamar at itamarst.org (Itamar Shtull-Trauring) Date: Tue, 10 Aug 2004 10:06:06 -0400 Subject: [C++-sig] C++ classes intended for use with Python Message-ID: <1092146766.8259.6.camel@sheriffpony> Currently, if I want to have virtual methods overridable in Python I need to go through the whole wrapper class song and dance. Thing is, I am creating classes whose only goal is to integrate with Python. I'm not wrapping a C++ library, I'm writing a Python/C++ library. Is there any way I can have classes automatically get an appropriate PyObject* self argument when instantiated? Obviously they'd be only used by subclassing them in Python. -- Itamar Shtull-Trauring http://itamarst.org From dave at boost-consulting.com Tue Aug 10 17:35:52 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 Aug 2004 11:35:52 -0400 Subject: [C++-sig] Re: C++ classes intended for use with Python References: <1092146766.8259.6.camel@sheriffpony> Message-ID: Itamar Shtull-Trauring writes: > Currently, if I want to have virtual methods overridable in Python I > need to go through the whole wrapper class song and dance. Thing is, I > am creating classes whose only goal is to integrate with Python. I'm not > wrapping a C++ library, I'm writing a Python/C++ library. Is there any > way I can have classes automatically get an appropriate PyObject* self > argument when instantiated? Obviously they'd be only used by subclassing > them in Python. Use the new idiom of deriving X from wrapper (use MI if neccessary). See this thread for details: http://news.gmane.org/find-root.php?message_id=%3cusmbedb9y.fsf%40boost%2dconsulting.com%3e HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ndbecker2 at verizon.net Tue Aug 10 17:37:38 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Tue, 10 Aug 2004 11:37:38 -0400 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> <41183D40.9070301@boost-consulting.com> Message-ID: David Abrahams wrote: > Joel de Guzman writes: > >> David Abrahams wrote: >> >>> Joel de Guzman writes: >>> >>>>Neal D. Becker wrote: >>>> >>>> >>>>>vector_indexing_suite set_slice does: 1) erase 2) insert >>>>>Shouldn't this be optimized to simply do copy? >>>> >>>>You mean this: >>>> >>>> container.erase(container.begin()+from, container.begin()+to); >>>> container.insert(container.begin()+from, v); >>>> >>>>Pardon me for being slow, but how? Could you spell it out for me? >>> It's not as simple as "copy", but if you think hard about it you can >>> see how to avoid any redundant moves or copies. The pseudocode is >>> complicated so I'm not writing it out in full here, but: >>> if new_size <= old_size: >>> erase(old_finish + (new_size - old_size), old_finish) >>> if new_size < old_size: >>> copy(new_start, new_finish, old_start) >>> else: >>> # fill in the details here >> >> I see. Yeah, same ol' buffer management. Ok, I'll optimize it. >> But it'll have to be after 1.32. Ok? > > Sure thing. > Just to clarify a little: 1. wrapping std::vector is useful for c++ algorithms intended for efficient processing of relatively large data vectors. 2. This doesn't inherently give any way to directly reference a slice of data. More code has to be written if you want to say from python "compute function F on a slice of vector V". 3. This limitation (lack of optimization to operate directly on slices) may not be very important in many cases, you could just do: Suppose we have a a vector v, and want to modify a slice of v using alg F: w = F (v[2:4]) # compute result from slice v[2:4] = w #splice in result 4. But it's even worse than it looks, because the "splice in result" will actually call erase and insert, instead of just copy. From itamar at itamarst.org Tue Aug 10 19:12:29 2004 From: itamar at itamarst.org (Itamar Shtull-Trauring) Date: Tue, 10 Aug 2004 13:12:29 -0400 Subject: [C++-sig] Re: C++ classes intended for use with Python In-Reply-To: References: <1092146766.8259.6.camel@sheriffpony> Message-ID: <1092157949.8261.8.camel@sheriffpony> On Tue, 2004-08-10 at 11:35, David Abrahams wrote: > Use the new idiom of deriving X from wrapper (use MI if > neccessary). See this thread for details: This requires 1.32 when released or HEAD for now, I assume? -- Itamar Shtull-Trauring http://itamarst.org From rwgk at yahoo.com Tue Aug 10 19:46:24 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 10 Aug 2004 10:46:24 -0700 (PDT) Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice In-Reply-To: Message-ID: <20040810174624.2593.qmail@web20223.mail.yahoo.com> --- "Neal D. Becker" wrote: > 3. This limitation (lack of optimization to operate directly on slices) may > not be very important in many cases, you could just do: > Suppose we have a a vector v, and want to modify a slice of v using alg F: > > w = F (v[2:4]) # compute result from slice > v[2:4] = w #splice in result > > 4. But it's even worse than it looks, because the "splice in result" will > actually call erase and insert, instead of just copy. FWIW: I've solved this problem in a different way. I am using two types of "selections" which may be understood as generalization of slices: - type 1: selection array of bools, same size as data array - type 2: selection array of std::size_t Generalized slicing works like this: v.select(selection_array) And now the other way (without using erase and insert): v.set_selected(selection_array, data_array_of_suitable_size) I find that I don't use regular slicing very much, but the generalized slicing is used all over the place in our apps. I am carefully avoiding "slice references" because it is a Pandora's box and can easily backfire performance-wise. If I had an exceptional case where copying a slice is prohibitive I'd code up a specialized C++ function and wrap it with Boost.Python. Ralf __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Tue Aug 10 20:06:53 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 Aug 2004 14:06:53 -0400 Subject: [C++-sig] Re: C++ classes intended for use with Python References: <1092146766.8259.6.camel@sheriffpony> <1092157949.8261.8.camel@sheriffpony> Message-ID: Itamar Shtull-Trauring writes: > On Tue, 2004-08-10 at 11:35, David Abrahams wrote: > >> Use the new idiom of deriving X from wrapper (use MI if >> neccessary). See this thread for details: > > This requires 1.32 when released or HEAD for now, I assume? Yes. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From s_sourceforge at nedprod.com Tue Aug 10 22:26:40 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 10 Aug 2004 21:26:40 +0100 Subject: [C++-sig] Re: new idea for pyste In-Reply-To: <411838AE.4070900@esss.com.br> References: <4117E620.2070601@paradise.net.nz> Message-ID: <41193D90.25152.6B32A37D@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9 Aug 2004 at 23:53, Nicodemus wrote: > a good re-write next year (when I'm finally a graduate 8)), or at > least dedicate a good time to bring it up to good shape (yes Niall, > including fixing AllFromHeader ;)). But enough rambling. As it happens, I've had to substantially reorder the plan of writing Tn because I realised I needed i/o points working (and hence data streams) before I could do the UI. After all, a UI is rendered data just like a rendered bitmap. Anyway, I'd imagine I'll get the above and possibly data linking done before the end of summer and the start of my new degree. Therefore my need for a full pyste drops substantially off till at least after Christmas, probably Spring 2005. In other words, no rush! > I think the idea is nice, but I would like to see what's the > improvement over something like this: > [snip] > Anyway, I think both ways to work with Pyste are valid: they can > coexist peacefully if Roman's idea is proved to be useful. Perhaps a good third way is to make pyste an optional extension to scons whereby scons will auto convert pyste files into C++ files. You needn't use scons to use pyste in this fashion, but it's easier. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQRkvgMEcvDLFGKbPEQLTnwCdEGwB0F4YxZQyIajyWwHE68TOcPAAnR27 x6VRZYPiqdCSlhcEGdpUq/Bg =pG8X -----END PGP SIGNATURE----- From jan.heiser at raubtierbaendiger.de Wed Aug 11 15:07:02 2004 From: jan.heiser at raubtierbaendiger.de (Jan Heiser) Date: Wed, 11 Aug 2004 15:07:02 +0200 Subject: [C++-sig] Re: Boost::Python 1.13.1 on SuSE 9.1 x86_64 References: Message-ID: David Abrahams wrote: > If you agree to report the bug to the GCC maintainers, I'll happily > apply the patch. I try to. The problem is reproducing the bug in a simple example - so far I had no luck... But then, it is probably the heavy netsing of templates that confuses GCC. Or, maybe again it's only SuSE9.1 GCC that causes trouble... > Caveat: I can by no means guarantee that GCC won't emit other silly > warnings for Boost.Python code. Sure. Thanks so far. From dave at boost-consulting.com Wed Aug 11 15:30:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 11 Aug 2004 09:30:11 -0400 Subject: [C++-sig] Re: Boost::Python 1.13.1 on SuSE 9.1 x86_64 References: Message-ID: Jan Heiser writes: > David Abrahams wrote: > >> If you agree to report the bug to the GCC maintainers, I'll happily >> apply the patch. > > I try to. The problem is reproducing the bug in a simple example - so far I > had no luck... But then, it is probably the heavy netsing of templates that > confuses GCC. If you can only reduce it a little, that's all you can do and they'll have to deal with your large testcase. > Or, maybe again it's only SuSE9.1 GCC that causes trouble... That should be easy enough to determine, shouldn't it? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From seefeld at sympatico.ca Thu Aug 12 03:20:12 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 11 Aug 2004 21:20:12 -0400 Subject: [C++-sig] test/embedding.cpp in bpl 1.31 Message-ID: <411AC5CC.9010104@sympatico.ca> hi there, debugging my applications, I'v had a closer look into the test/embedding.cpp file, and I'd like to suggest two changes, one cosmetic, and one fix. The fix concerns line line 108/109, which read: python::object py_base = PythonDerived(); Base& py = python::extract(py_base)(); PythonDerived is a type object extracted from a python script, so the first line calls the constructor. The second takes the instance and extracts a 'Base' reference for later use. But what's the '()' operator supposed to do in that line ? If I remove it, the test still performs correctly, so it seems it doesn't have any effect (at least in this context). Can anybody explain this behavior ? The other change concerns the way the 'PythonDerived' type object is obtained. Instead of running 'PyRun_String' I'd just extract it from the 'main_namespace' dictionary after the first script has been evaluated: python::object PythonDerived = main_namespace["PythonDerived"]; Both changes are contained in the attached patch... --- My original goal looking into this file was to understand a crash I get when running 'PyRun_File', so I tried to do what the comment in embedding.cpp suggests, i.e. I put the script defining the 'PythonDerived' class into a separate file and then use 'PyRun_File' to evaluate that script instead of 'PyRun_String'. While this works fine on linux, the application crashes on windows (msvc) somewhere inside the PyRun_File call. I did the appropriate (I think) changes to 'test/embedding.cpp' for comparison, and I observed the same crash (i.e. just recompiling the modified 'embedding' test inside the boost build system). I'd very much appreciate if anybody could either confirm this behavior on windows (msvc) or show what changes need to be done to the code to make it work. (I believe this use case is sufficiently important to warrant a demo /test in its own right.) Thanks a lot ! Stefan -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch URL: From chezdique at yahoo.com Thu Aug 12 11:02:51 2004 From: chezdique at yahoo.com (dique) Date: Thu, 12 Aug 2004 02:02:51 -0700 (PDT) Subject: [C++-sig] test/embedding.cpp in bpl 1.31 In-Reply-To: <411AC5CC.9010104@sympatico.ca> Message-ID: <20040812090251.38989.qmail@web41502.mail.yahoo.com> This is because your program linked with a different runtime library (msvcr70.dll or msvcr71.dll I guess) from the one used by Python (msvcrt.dll). The crash, I supposed, was caused by passing around the FILE* pointer to different version of runtime library. What I did was to use the Python built-in function execfile instead: using namespace boost::python void runFile(const char* fileName) { object mainModule(handle<>(borrowed(PyImport_AddModule("__main__") ))); object mainNamespace = mainModule.attr("__dict__"); mainNamespace["_pythonscript_file_name"] = fileName; const char execString[] = "execfile(_pythonscript_file_name)\n" "del _pythonscript_file_name\n"; try { object result(handle<>(PyRun_String(execString, Py_file_input, mainNamespace.ptr(), mainNamespace.ptr()))); } catch(error_already_set) { PyErr_Print(); } } --- Stefan Seefeld wrote: > hi there, > > debugging my applications, I'v had a closer > look into the test/embedding.cpp file, and I'd > like to suggest two changes, one cosmetic, and one > fix. > > The fix concerns line line 108/109, which read: > > python::object py_base = PythonDerived(); > Base& py = python::extract(py_base)(); > > PythonDerived is a type object extracted from > a python script, so the first line calls the > constructor. The second takes the instance and > extracts a 'Base' reference for later use. > But what's the '()' operator supposed to do in > that line ? If I remove it, the test still > performs correctly, so it seems it doesn't > have any effect (at least in this context). > Can anybody explain this behavior ? > > The other change concerns the way the > 'PythonDerived' > type object is obtained. Instead of running > 'PyRun_String' > I'd just extract it from the 'main_namespace' > dictionary > after the first script has been evaluated: > > python::object PythonDerived = > main_namespace["PythonDerived"]; > > Both changes are contained in the attached patch... > > --- > > My original goal looking into this file was to > understand a crash I get when running 'PyRun_File', > so I tried to do what the comment in embedding.cpp > suggests, > i.e. I put the script defining the 'PythonDerived' > class into a > separate file and then use 'PyRun_File' to evaluate > that script > instead of 'PyRun_String'. While this works fine on > linux, the > application crashes on windows (msvc) somewhere > inside the PyRun_File > call. > > I did the appropriate (I think) changes to > 'test/embedding.cpp' for > comparison, and I observed the same crash (i.e. just > recompiling > the modified 'embedding' test inside the boost build > system). > > I'd very much appreciate if anybody could either > confirm this > behavior on windows (msvc) or show what changes need > to be done > to the code to make it work. (I believe this use > case is sufficiently > important to warrant a demo /test in its own right.) > > Thanks a lot ! > > Stefan > > 93,98c93 > < python::handle<> class_ptr( > < PyRun_String("PythonDerived\n", > Py_eval_input, > < main_namespace.ptr(), > main_namespace.ptr()) ); > < > < // Wrap the raw Python object in a > Boost.Python object > < python::object PythonDerived(class_ptr); > --- > > python::object PythonDerived = > main_namespace["PythonDerived"]; > 109c104 > < Base& py = python::extract(py_base)(); > --- > > Base& py = python::extract(py_base); > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Thu Aug 12 14:09:18 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 12 Aug 2004 08:09:18 -0400 Subject: [C++-sig] Re: test/embedding.cpp in bpl 1.31 References: <411AC5CC.9010104@sympatico.ca> Message-ID: Stefan Seefeld writes: > hi there, > > debugging my applications, I'v had a closer > look into the test/embedding.cpp file, and I'd > like to suggest two changes, one cosmetic, and one fix. > > The fix concerns line line 108/109, which read: > > python::object py_base = PythonDerived(); > Base& py = python::extract(py_base)(); > > PythonDerived is a type object extracted from > a python script, so the first line calls the > constructor. The second takes the instance and > extracts a 'Base' reference for later use. > But what's the '()' operator supposed to do in > that line ? It's a workaround for broken compilers. > If I remove it, the test still > performs correctly, so it seems it doesn't > have any effect (at least in this context). > Can anybody explain this behavior ? You don't need it unless you want your code to work on vc6/7. > The other change concerns the way the 'PythonDerived' > type object is obtained. Instead of running 'PyRun_String' > I'd just extract it from the 'main_namespace' dictionary > after the first script has been evaluated: > > python::object PythonDerived = main_namespace["PythonDerived"]; > > Both changes are contained in the attached patch... That seems like a good change. > My original goal looking into this file was to > understand a crash I get when running 'PyRun_File', > so I tried to do what the comment in embedding.cpp suggests, > i.e. I put the script defining the 'PythonDerived' class into a > separate file and then use 'PyRun_File' to evaluate that script > instead of 'PyRun_String'. While this works fine on linux, the > application crashes on windows (msvc) somewhere inside the PyRun_File > call. > > I did the appropriate (I think) changes to 'test/embedding.cpp' for > comparison, and I observed the same crash (i.e. just recompiling > the modified 'embedding' test inside the boost build system). > > I'd very much appreciate if anybody could either confirm this > behavior on windows (msvc) or show what changes need to be done > to the code to make it work. (I believe this use case is sufficiently > important to warrant a demo /test in its own right.) > > Thanks a lot ! I don't have a comment about that part yet, and no time to make the evaluation. That said, if you could package up a bjam-able example I might find time to try it. All I'd do is look at it with the debugger, though, and I guess you can do that just as well as I can. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From sseefeld at art.ca Thu Aug 12 15:36:52 2004 From: sseefeld at art.ca (Stefan Seefeld) Date: Thu, 12 Aug 2004 09:36:52 -0400 Subject: [C++-sig] Re: test/embedding.cpp in bpl 1.31 Message-ID: <20DCDD8F0FCED411AC4D001083CF504501AA9714@MTL-EXCHANGE> > -----Original Message----- > From: David Abrahams [mailto:dave at boost-consulting.com] > Sent: August 12, 2004 08:09 > > PythonDerived is a type object extracted from > > a python script, so the first line calls the > > constructor. The second takes the instance and > > extracts a 'Base' reference for later use. > > But what's the '()' operator supposed to do in > > that line ? > > It's a workaround for broken compilers. ok. May I suggest to add a little comment to avoid confusing the reader (and to remember developers to remove the workaround once support for those broken compilers has ended). [problems with PyRun_File...] > I don't have a comment about that part yet, and no time to make the > evaluation. That said, if you could package up a bjam-able example I > might find time to try it. All I'd do is look at it with the > debugger, though, and I guess you can do that just as well as I can. yep, and I did. As someone else confirmed, the problem was that the python runtime library had been compiled with vc 7.0, while I'm working with 7.1. It appears the FILE structure layout changed, so those two versions aren't binary compatible. I'm now recompiling python with vc 7.1... Thanks again, Stefan From dave at boost-consulting.com Thu Aug 12 16:07:22 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 12 Aug 2004 10:07:22 -0400 Subject: [C++-sig] Re: test/embedding.cpp in bpl 1.31 References: <20DCDD8F0FCED411AC4D001083CF504501AA9714@MTL-EXCHANGE> Message-ID: Stefan Seefeld writes: >> -----Original Message----- >> From: David Abrahams [mailto:dave at boost-consulting.com] >> Sent: August 12, 2004 08:09 > >> > PythonDerived is a type object extracted from >> > a python script, so the first line calls the >> > constructor. The second takes the instance and >> > extracts a 'Base' reference for later use. >> > But what's the '()' operator supposed to do in >> > that line ? >> >> It's a workaround for broken compilers. > > ok. May I suggest to add a little comment to avoid > confusing the reader OK. > (and to remember developers to remove the workaround once support > for those broken compilers has ended). When BPL ends support for vc6/7 we will have a complete rewrite with many new interfaces. Or did you mean "...and to remind users..." > > [problems with PyRun_File...] > >> I don't have a comment about that part yet, and no time to make the >> evaluation. That said, if you could package up a bjam-able example I >> might find time to try it. All I'd do is look at it with the >> debugger, though, and I guess you can do that just as well as I can. > > yep, and I did. As someone else confirmed, the problem was that the > python runtime library had been compiled with vc 7.0, while I'm > working with 7.1. It appears the FILE structure layout changed, so > those two versions aren't binary compatible. I'm now recompiling > python with vc 7.1... That's right. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From sseefeld at art.ca Thu Aug 12 16:22:37 2004 From: sseefeld at art.ca (Stefan Seefeld) Date: Thu, 12 Aug 2004 10:22:37 -0400 Subject: [C++-sig] Re: test/embedding.cpp in bpl 1.31 Message-ID: <20DCDD8F0FCED411AC4D001083CF504501AA9715@MTL-EXCHANGE> > -----Original Message----- > From: David Abrahams [mailto:dave at boost-consulting.com] > Sent: August 12, 2004 10:07 > > (and to remember developers to remove the workaround once support > > for those broken compilers has ended). > > When BPL ends support for vc6/7 we will have a complete rewrite with > many new interfaces. Or did you mean "...and to remind users..." yeah, everybody looking at the code (for inspiration, if nothing else) who is not familiar with all those compiler-specific workarounds. Regards, Stefan From dave at boost-consulting.com Thu Aug 12 16:28:39 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 12 Aug 2004 10:28:39 -0400 Subject: [C++-sig] Re: test/embedding.cpp in bpl 1.31 References: <20DCDD8F0FCED411AC4D001083CF504501AA9714@MTL-EXCHANGE> Message-ID: David Abrahams writes: >> ok. May I suggest to add a little comment to avoid >> confusing the reader > > OK. Actually, I did the following. The first use of extract<> was an abuse. Unfortunately, there are other extra pairs of parens required to workaround gcc-2.95.3 parser bugs object main_module(( ... )) ^ But that is already repeated elsewhere in the file and didn't seem to raise any alarms. --- embedding.cpp.~1.10.~ 2004-07-23 11:41:44.974043200 -0400 +++ embedding.cpp 2004-08-12 10:22:20.944963200 -0400 @@ -69,9 +69,8 @@ Py_Initialize(); // Retrieve the main module - python::object main_module = python::extract( - PyImport_AddModule("__main__") - )(); + python::object main_module(( + python::handle<>(python::borrowed(PyImport_AddModule("__main__"))))); // Retrieve the main module's namespace python::object main_namespace((main_module.attr("__dict__"))); @@ -106,7 +105,11 @@ // But now creating and using instances of the Python class is almost // as easy! python::object py_base = PythonDerived(); - Base& py = python::extract(py_base)(); + Base& py = python::extract(py_base) +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) + () +#endif + ; std::cout << py.hello() << std::endl; } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From my.mailing.lists at noos.fr Fri Aug 13 09:22:45 2004 From: my.mailing.lists at noos.fr (nik) Date: Fri, 13 Aug 2004 09:22:45 +0200 Subject: [C++-sig] creating a python object containing lists of lists In-Reply-To: References: <20DCDD8F0FCED411AC4D001083CF504501AA9714@MTL-EXCHANGE> Message-ID: <411C6C45.6090309@noos.fr> hi, I'm new to python, but the project I'm on means I've got to jump into it feet first. Going through the python.org tutorial has got me so far, but I'm stuck now. I'm trying to pass a complicated structure from my C++ app to a python script, so that my users have a chance to alter it if they want. I'd like to provide example scripts that can serialise the data into files, or create entries into a database etc. I've embedded the python interpreter, and I'm using PyRun_SimpleFile to load a python script. I'd like to make a Python object representing my structure available to that script. The structure is a mix of strings, lists, and lists of lists - I suppose in a simplified way it looks like (in C++); using namespace std; typedef list listOfStrings; typedef struct { listOfStrings subData; string subTitle; string subHeading; } subComponent; typedef list listOfSubcomponenets; typedef { listOfSubcomponents theData; string Title; string otherStuff; } myStructure; With a filled myStructure instance being the object I want to pass to the python script. I've only just started looking at python, but it's looking like it's possible. From the example of embedding python in the tutorial, it shows me how to create an object with a couple of strings as attributes. I can see that I could make these objects lists, but I'm wondering what to do about the inner list (listOfStrings in my example above). I'm wondering if I'm on the right track with these views of the problem; * I could generate the whole thing adding lists to lists, but I'm not sure if the user would find that easy to navigate through the PyObject (ie the object would have an attribute called 'theData', but then what? Do I tell them go to the first item of theData and that's a list? To them it wouldn't be called subData, it'd just be an item). * I could create a PyObject that's the subComponent, and put that in the myStructure PyObject. I tried this and got a segmentation fault so I've done something wrong (not suprisingly, since I haven't got a clue what I'm doing yet). * The boost::python library seems to be suggesting that it can create the PyObject automatically (abracadabra!), although I've not gone into this in depth. Is that true? Is this the right list for this kind of question, or is there a more suitable one? thanks, nik From kollmann at telbiomed.at Fri Aug 13 08:59:08 2004 From: kollmann at telbiomed.at (Alexander Kollmann) Date: Fri, 13 Aug 2004 08:59:08 +0200 Subject: [C++-sig] recompiling cpp-file Message-ID: hi, i'm have no idea how to recompile a *.cpp for a certain python version. how can i do that ? regards alex From ndbecker2 at verizon.net Fri Aug 13 16:43:18 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Fri, 13 Aug 2004 10:43:18 -0400 Subject: [C++-sig] My latest project Message-ID: I'm working on mixing python with c++ algorithms for signal processing applications. I've come to the conclusion that wrapping std::vector is a good choice for containers. I'm pretty happy now with the basic design, and I'd like to share it. This boost-python module wraps (currently) std::vector and std::vector>. It implements (currently) basic arithmetic: vector op vector vector op T vector op complex vector> op vector> vector> op complex vector> op vector vector> op T "in-place" ops not yet implemented. -------------- next part -------------- A non-text attachment was scrubbed... Name: mismatch.H Type: text/x-csrc Size: 169 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Scalar.H Type: text/x-csrc Size: 198 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: vector.cc Type: text/x-c++src Size: 6105 bytes Desc: not available URL: From dave at boost-consulting.com Fri Aug 13 19:14:46 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 Aug 2004 13:14:46 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: "Neal D. Becker" writes: > I'm working on mixing python with c++ algorithms for signal processing > applications. > > I've come to the conclusion that wrapping std::vector is a good choice for > containers. > > I'm pretty happy now with the basic design, and I'd like to share it. This > boost-python module wraps (currently) std::vector and > std::vector>. It implements (currently) basic arithmetic: > > vector op vector > vector op T > vector op complex > > vector> op vector> > vector> op complex > vector> op vector > vector> op T > > "in-place" ops not yet implemented. 1. Why not use the vector_indexing_suite? 2. Why all the ugly macros when you could use function templates? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ndbecker2 at verizon.net Fri Aug 13 20:32:26 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Fri, 13 Aug 2004 14:32:26 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: David Abrahams wrote: > "Neal D. Becker" writes: > >> I'm working on mixing python with c++ algorithms for signal processing >> applications. >> >> I've come to the conclusion that wrapping std::vector is a good choice >> for containers. >> >> I'm pretty happy now with the basic design, and I'd like to share it. >> This boost-python module wraps (currently) std::vector and >> std::vector>. It implements (currently) basic >> arithmetic: >> >> vector op vector >> vector op T >> vector op complex >> >> vector> op vector> >> vector> op complex >> vector> op vector >> vector> op T >> >> "in-place" ops not yet implemented. > > 1. Why not use the vector_indexing_suite? It is used. What did you mean? > 2. Why all the ugly macros when you could use function templates? How can I use function template to define a function "operator op" where "op" is a variable? For example, VVOP(double,double,double,+,plus()) macro defines operator+(const std::vector&, const std::vector&) From dave at boost-consulting.com Fri Aug 13 21:01:18 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 Aug 2004 15:01:18 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: "Neal D. Becker" writes: > David Abrahams wrote: > >> "Neal D. Becker" writes: >> >>> I'm working on mixing python with c++ algorithms for signal processing >>> applications. >>> >>> I've come to the conclusion that wrapping std::vector is a good choice >>> for containers. >>> >>> I'm pretty happy now with the basic design, and I'd like to share it. >>> This boost-python module wraps (currently) std::vector and >>> std::vector>. It implements (currently) basic >>> arithmetic: >>> >>> vector op vector >>> vector op T >>> vector op complex >>> >>> vector> op vector> >>> vector> op complex >>> vector> op vector >>> vector> op T >>> >>> "in-place" ops not yet implemented. >> >> 1. Why not use the vector_indexing_suite? > > It is used. What did you mean? Sorry, I missed it. >> 2. Why all the ugly macros when you could use function templates? > > How can I use function template to define a function "operator op" where > "op" is a variable? > > For example, VVOP(double,double,double,+,plus()) macro defines > operator+(const std::vector&, const std::vector&) That's not what I meant. Why: #define VECIMP(TYPE, PROXY) \ class_ >("vector_"#TYPE) \ .def(init()) \ .def(init()) \ .def(init&>()) \ .def("size", &std::vector::size) \ .def("resize", (void (std::vector::*)(size_t, const TYPE&) )&std::vector::resize) \ .def("resize", (void (std::vector::*)(size_t) )&std::vector::resize) \ .def(self + self) \ .def(self - self) \ .def(self * self) \ .def(self / self) \ .def(self + TYPE()) \ .def(self - TYPE()) \ .def(self * TYPE()) \ .def(self / TYPE()) \ .def(self + std::complex()) \ .def(self - std::complex()) \ .def(self * std::complex()) \ .def(self / std::complex()) \ .def(vector_indexing_suite, PROXY >()) \ ; ? I realize you're generating the vector name, but it'd be more principled to do the rest with a template. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ostiguy at fnal.gov Fri Aug 13 21:22:58 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Fri, 13 Aug 2004 14:22:58 -0500 (CDT) Subject: [C++-sig] creating an instance of a class_<> object in c++ and exporting it to python Message-ID: Hi - I am try in to do the following: Consider a C++ class A wrapped using boost.python: class_("A", noinit) .def("f1", &A::f1) .... ; >From C++, I would like to (1) create an instance of a wrapped object "A", initializing it using a pointer to an existing instance of a C++ A object. (2) export the python object into the namespace of an (embedded) interpreter. AFAIK boost.python does not provide a mechanism to accomplish (2), but that seems straightforward using the Python C-API. I am really at a loss on how to achieve (1) using boost.python. It would seem like a useful thing to create instances of wrapped objects in C++. The most relevant bit of information I found is in the tutorial: > Due to the dynamic nature of Boost.Python objects, any class_ may > also be one of these types! The following code snippet wraps the class > (type) > object. > We can use this to create wrapped instances. Example > object vec345 = ( > class_("Vec2", init()) > .def_readonly("length", &Point::length) > .def_readonly("angle", &Point::angle) > )(3.0, 4.0); > > assert(vec345.attr("length") == 5.0); This code does create an instance of vec345; however, unless I misunderstand something I am under the impression that every invocation of class_ will re-register the class A. Perhaps this is not a problem; nevertheless it appears unnecessarily redundant and potentially error-prone (multiple class_ declarations appearing in different source files). Is it possible to somehow retrieve the class type of an extended C++ class directly from the interpreter and then create a new instance ? Any comments or insight would be most welcome. -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 MKhesin at liquidnet.com Fri Aug 13 21:47:16 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Fri, 13 Aug 2004 15:47:16 -0400 Subject: [C++-sig] creating an instance of a class_<> object in c++ an d exporting it to python Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050AE3@exchange.lnholdings.com> Maybe I missed something, but I think this should work for you: class_ classA("A", noinit);// this is the class object - only one registration! classA.def("f1", &A::f1) .... ; CPPObj cppObj; object instanceOfA1 = classA(&cppObj);// multiple instances object instanceOfA2 = classA(&cppObj); regards, max > -----Original Message----- > From: Francois Ostiguy [mailto:ostiguy at fnal.gov] > Sent: Friday, August 13, 2004 3:23 PM > To: c++-sig at python.org > Subject: [C++-sig] creating an instance of a class_<> object > in c++ and > exporting it to python > > > > > Hi - > > I am try in to do the following: > > Consider a C++ class A wrapped using boost.python: > > class_("A", noinit) > .def("f1", &A::f1) > .... > ; > > >From C++, I would like to > > (1) create an instance of a wrapped object "A", initializing it using > a pointer to an existing instance of a C++ A object. > > (2) export the python object into the namespace of an (embedded) > interpreter. > > AFAIK boost.python does not provide a mechanism to accomplish (2), > but that seems straightforward using the Python C-API. > > I am really at a loss on how to achieve (1) using > boost.python. It would > seem like a useful thing to create instances of wrapped objects in > C++. > The most relevant bit of information I found is in the tutorial: > > > > Due to the dynamic nature of Boost.Python objects, any class_ may > > also be one of these types! The following code snippet > wraps the class > > (type) > > object. > > > We can use this to create wrapped instances. Example > > object vec345 = ( > > class_("Vec2", init()) > > .def_readonly("length", &Point::length) > > .def_readonly("angle", &Point::angle) > > )(3.0, 4.0); > > > > assert(vec345.attr("length") == 5.0); > > > This code does create an instance of vec345; > however, unless I misunderstand something I am under > the impression that every invocation of > class_ will re-register the class A. > Perhaps this is not a problem; nevertheless it > appears unnecessarily redundant and potentially error-prone > (multiple class_ declarations appearing in different source > files). > > Is it possible to somehow retrieve the class type of an extended > C++ class directly from the interpreter and then > create a new instance ? > > Any comments or insight would be most welcome. > > > -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 > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 13 21:59:18 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 Aug 2004 15:59:18 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ an d exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE3@exchange.lnholdings.com> Message-ID: Max Khesin writes: > Maybe I missed something, but I think this should work for you: > > class_ classA("A", noinit);// this is the class > object - only one registration! > classA.def("f1", &A::f1) > .... > ; > CPPObj cppObj; > object instanceOfA1 = classA(&cppObj);// multiple instances > object instanceOfA2 = classA(&cppObj); Or: object classA = class("A", noinit) .def("f1", &A::f1) ... ; etc. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From MKhesin at liquidnet.com Fri Aug 13 22:03:33 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Fri, 13 Aug 2004 16:03:33 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> > Max Khesin writes: > > > Maybe I missed something, but I think this should work for you: > > > > class_ classA("A", noinit);// > this is the class > > object - only one registration! > > classA.def("f1", &A::f1) > > .... > > ; > > CPPObj cppObj; > > object instanceOfA1 = classA(&cppObj);// multiple instances > > object instanceOfA2 = classA(&cppObj); > > > Or: > > object classA > = class("A", noinit) > .def("f1", &A::f1) > ... > ; In style! Nice. Also the OP wants to "create an instance of a wrapped object "A", initializing it using a pointer to an existing instance of a C++ A object." so I assume something like this is needed: object classA = class("A", CPPObj*) .def("f1", &A::f1) ... ; > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 13 22:38:25 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 Aug 2004 16:38:25 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Max Khesin writes: >> Max Khesin writes: >> >> > Maybe I missed something, but I think this should work for you: >> > >> > class_ classA("A", noinit);// >> this is the class >> > object - only one registration! >> > classA.def("f1", &A::f1) >> > .... >> > ; >> > CPPObj cppObj; >> > object instanceOfA1 = classA(&cppObj);// multiple instances >> > object instanceOfA2 = classA(&cppObj); >> >> >> Or: >> >> object classA >> = class("A", noinit) >> .def("f1", &A::f1) >> ... >> ; Note: that's just the class. You need to call it to create the A object: object a = classA(); > In style! Nice. Also the OP wants to > "create an instance of a wrapped object "A", initializing it using > a pointer to an existing instance of a C++ A object." so I assume > something like this is needed: > > object classA > = class("A", CPPObj*) ^^^^^^^ > .def("f1", &A::f1) > ... > ; No, won't work. You can't pass a type as a function argument. First the OP needs to decide whether the resulting Python object owns or just refers to the existing instance. I'm going to assume the latter. What you do is wrap a C++ function that returns the A* using make_function and an appropriate policy, and then call it. // untested A* get_existing() { return &some_existing_a; } object py_get_existing = make_function( &get_existing , return_value_policy() ) object a = py_get_existing() HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ostiguy at fnal.gov Sat Aug 14 00:51:04 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Fri, 13 Aug 2004 17:51:04 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Dave and Max - Many thanks. With your suggestions, I am getting much closer ... but it is not quite working yet. Here is what I tried (in slightly simplified form): ... class A; class_ PythonTypeA; A* aptr = new A(); A* get_existing() { return aptr; } object py_get_existing = make_function( &get_existing, return_value_policy() ); object PythonInstanceOfA = PythonTypeA( py_get_existing() ); ... The code compiles cleanly. Unfortunately, I get a core dump when the last line is executed. The debugger tells me that the problem originates from line 154 in return_from_python.hpp 151 inline T return_object_manager_from_python::operator()(PyObject* obj) const 152 { 153 return T( 154 object_manager_traits::adopt(expect_non_null(obj)) 155 ); 156 } 157 } 158 159 }}} // namespace boost::python::converter 160 obj is null and expect_non_null(obj) throws an exception. This function is called from line 20 in object_call.cpp 13 14 template 15 typename detail::dependent::type 16 operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) const 17 { 18 typedef typename detail::dependent::type obj; 19 U const& self = *static_cast(this); 20 return call(get_managed_object(self, tag), BOOST_PP_ENUM_PARAMS_Z(1, N, a)); 21 } 22 so somehow, calling the object returned by py_get_existing appears to return a null pointer. -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 mike at nospam.com Sat Aug 14 01:14:56 2004 From: mike at nospam.com (Mike Rovner) Date: Fri, 13 Aug 2004 16:14:56 -0700 Subject: [C++-sig] Re: Re: creating an instance of a class_<> object in c++ an d exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy wrote: > Here is what I tried (in slightly simplified form): > object PythonInstanceOfA = PythonTypeA( py_get_existing() ); object PythonInstanceOfA = py_get_existing(); py_get_existing is already a factory function returning (python) instance of A. HTH, Mike From dave at boost-consulting.com Sat Aug 14 01:50:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 Aug 2004 19:50:11 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ an d exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: "Mike Rovner" writes: > Francois Ostiguy wrote: >> Here is what I tried (in slightly simplified form): >> object PythonInstanceOfA = PythonTypeA( py_get_existing() ); > > object PythonInstanceOfA = py_get_existing(); > > py_get_existing is already a factory function returning (python) instance of > A. To put it another way, at this point you're done. Whatever you're doing with PythonTypeA is (no offense) bogus. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From chezdique at yahoo.com Sat Aug 14 12:56:39 2004 From: chezdique at yahoo.com (dique) Date: Sat, 14 Aug 2004 03:56:39 -0700 (PDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python In-Reply-To: Message-ID: <20040814105639.1772.qmail@web41506.mail.yahoo.com> Does the following sample code let you do what you want? Essentially you can inject any C++ instance into Python namespace, as long as you have defined the 'class_<>' for the C++ class. Note particular the use of ObjectWrap. //---START--- // An ObjectWrap to wrap any object which is to be manipulated by Python. template class ObjectWrap { public: typedef T element_type; ObjectWrap(T& t) : p_(&t) { } ObjectWrap(T* p) : p_(p) { } virtual ~ObjectWrap() { } T* get() const { return p_; } T& operator*() const { return *p_; } T* operator->() const { return p_; } private: T * p_; }; namespace boost { // Some internal boost functions require get_pointer to be defined. // Define this before including template inline T * get_pointer(ObjectWrap const & p) { return p.get(); } } #include #include using namespace boost::python; /// A Singleton class which makes embedding Python easy. class Python { public: Python() { Py_Initialize(); mainModule = object(handle<>(borrowed(PyImport_AddModule("__main__") ))); mainNamespace = mainModule.attr("__dict__"); } ~Python() { //Py_Finalize(); // XXX } // Inject a C++ instance into the current Python module. template void addObject(const char* name, T& obj) { ObjectWrap o(&obj); currentNamespace[name] = object(o); } // Run Python script. void run(const char* script) const { try { object result(handle<>(PyRun_String(script, Py_file_input, mainNamespace.ptr(), mainNamespace.ptr()))); } catch(error_already_set) { PyErr_Print(); } } // Get current module. object getModule() const { return currentModule; } // Set current module. void setModule(const char* module = 0) { if (module == 0) // __main__ module { currentModule = mainModule; currentNamespace = mainNamespace; } else { currentModule = object(handle<>(borrowed(PyImport_AddModule(const_cast(module))))); currentNamespace = currentModule.attr("__dict__"); } } static Python& Instance() { static Python p; return p; } private: object mainModule; object mainNamespace; object currentModule; object currentNamespace; }; class A { public: A(int v) : value(v) { } int getValue() const { return value; } void setValue(int v) { value = v; } void add(int v) { value += v; } private: int value; }; void addObject(const char* name, A& a) { static bool isRegistered = false; if (!isRegistered) // Only register the class once. { // Make sure we define the class in the current module. scope s(Python::Instance().getModule()); class_, boost::noncopyable>("A", no_init) .add_property("value", &A::getValue, &A::setValue) .def("add", &A::add) ; isRegistered = true; } Python::Instance().addObject(name, a); } int main() { Python::Instance().setModule("mymodule"); A* a = new A(10); A* b = new A(20); addObject("a1", *a); addObject("a2", *a); addObject("b", *b); std::cout << "In C++:" << std::endl; std::cout << "a: " << a->getValue() << std::endl; std::cout << "b: " << b->getValue() << std::endl << std::endl; Python::Instance().run( "import mymodule\n" "print 'Now we are in Python:'\n" "print 'dir():'\n" "print dir()\n" "print 'dir(mymodule):'\n" "print dir(mymodule)\n" "print\n" "print 'mymodule.a1, mymodule.a2 are " "references to the same \\'a\\' instance.'\n" "print 'a1:', mymodule.a1.value\n" "print 'a2:', mymodule.a2.value\n" "print\n" "mymodule.a1.value -= 2\n" "print 'After mymodule.a1.value -= 2:'\n" "print 'a1:', mymodule.a1.value\n" "print 'a2:', mymodule.a2.value\n" "print\n" "print 'b is different from a1, a2, of course.'\n" "mymodule.b.add(-19)\n" "print 'After mymodule.b.add(-19):'\n" "print 'b:', mymodule.b.value\n" "print\n" "mymodule.a2.add(3)\n" "print 'After mymodule.a2.add(3):'\n" "print 'a1:', mymodule.a1.value\n" "print 'a2:', mymodule.a2.value\n" "print 'a1 == a2?', mymodule.a1 == mymodule.a2\n" "print\n" ); std::cout << "Now we are back to C++ again:" << std::endl; std::cout << "a: " << a->getValue() << std::endl; std::cout << "b: " << b->getValue() << std::endl; delete a; return 0; } //---END--- --- Francois Ostiguy wrote: > > Dave and Max - > > Many thanks. With your suggestions, I am getting much closer ... but it is > not quite working yet. > > Here is what I tried (in slightly simplified form): > > > ... > > class A; > > class_ PythonTypeA; > > A* aptr = new A(); > > A* get_existing() { return aptr; } > > object py_get_existing = > make_function( &get_existing, > return_value_policy() ); > > object PythonInstanceOfA = PythonTypeA( py_get_existing() ); > > ... > > The code compiles cleanly. Unfortunately, I get a core dump when the last > line is executed. The debugger tells me that the problem originates from > line 154 in return_from_python.hpp > > 151 inline T return_object_manager_from_python::operator()(PyObject* obj) const > 152 { > 153 return T( > 154 object_manager_traits::adopt(expect_non_null(obj)) > 155 ); > 156 } > 157 } > 158 > 159 }}} // namespace boost::python::converter > 160 > > obj is null and expect_non_null(obj) throws an exception. This function is > called from line 20 in object_call.cpp > > > 13 > 14 template > 15 typename detail::dependent::type > 16 operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) const > 17 { > 18 typedef typename detail::dependent::type obj; > 19 U const& self = *static_cast(this); > 20 return call(get_managed_object(self, tag), BOOST_PP_ENUM_PARAMS_Z(1, N, a)); > 21 } > 22 > > so somehow, calling the object returned by py_get_existing appears > to return a null pointer. > > > -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 > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Sat Aug 14 14:45:27 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 14 Aug 2004 08:45:27 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python References: <20040814105639.1772.qmail@web41506.mail.yahoo.com> Message-ID: dique writes: > namespace boost > { > // Some internal boost functions require get_pointer to be > defined. But not in namespace boost. Never, ever make a definition in a library's namespace unless the documentation tells you to. Put this in the same namespace as ObjectWrap, or if your compiler is broken like vc6/7, put it in the global namespace. > // Define this before including > template > inline T * get_pointer(ObjectWrap const & p) > { > return p.get(); > } > } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ndbecker2 at verizon.net Sun Aug 15 03:55:14 2004 From: ndbecker2 at verizon.net (Neal Becker) Date: Sat, 14 Aug 2004 21:55:14 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: OK, I agree the previous version sucked. Here is a new one I think is much better. The boost-python code is simple, and I'm not including it. The harder part is to supply the underlying c++ library for doing the vector-vector and vector-scalar arithmetic. I think I have a pretty good design for that, which I'd like to share. The tests at the bottom compile with gcc34/boost-cvs. -------------- next part -------------- A non-text attachment was scrubbed... Name: vector_arith.hpp Type: text/x-c++src Size: 6965 bytes Desc: not available URL: From dave at boost-consulting.com Sun Aug 15 04:56:28 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 14 Aug 2004 22:56:28 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: Neal Becker writes: > OK, I agree the previous version sucked. I wouldn't go that far. > Here is a new one I think is much > better. > > The boost-python code is simple, and I'm not including it. The > harder part is to supply the underlying c++ library for doing the > vector-vector and vector-scalar arithmetic. I think I have a pretty > good design for that, which I'd like to share. I think you're posting in the wrong forum then. I have only 2 quick comments in this one: 1. You should never use std::[binary|unary]_function because it suppresses EBO. Consider what happens when you have a compressed_pair,plus >. 2. Isn't something appropriate already present in uBlas? Cheers, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From talsit at talsit.org Mon Aug 16 03:11:58 2004 From: talsit at talsit.org (tALSit de CoD) Date: Mon, 16 Aug 2004 11:11:58 +1000 (EST) Subject: [C++-sig] yet another: TypeError: No to_python (by-value) converter found for C++ type: Message-ID: <1580.61.29.35.206.1092618718.squirrel@61.29.35.206> Hey guys! I know this has been answered to some extent before, but I just can't get to grips with it, so i know i'm doing something wrong... I export the following: //---------------------------------------------------------------- class_ ("cNodeDescriptor", no_init) .def ("getClassId",&cNodeDescriptor::getClassId) .def ("getName",&cNodeDescriptor::getName, return_value_policy ()) ; //---------------------------------------------------------------- class_ > ("cNodeDescriptorList") .def ("__iter__", iterator > ()) ; And then, in python, i grab a cNodeDescriptorList, and when i try to iterate through it, it spits out: TypeError: No to_python (by-value) converter found for C++ type: class kikura::cNodeDescriptor * So... what am i doing wrong? If more info is needed, i'd be glad to supply it... Cheers!! // talsit.org From dave at boost-consulting.com Mon Aug 16 05:29:49 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 15 Aug 2004 23:29:49 -0400 Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: References: <1580.61.29.35.206.1092618718.squirrel@61.29.35.206> Message-ID: "tALSit de CoD" writes: > Hey guys! > I know this has been answered to some extent before, but I just can't get > to grips with it, so i know i'm doing something wrong... > > I export the following: > > //---------------------------------------------------------------- class_ > ("cNodeDescriptor", no_init) > .def ("getClassId",&cNodeDescriptor::getClassId) > .def ("getName",&cNodeDescriptor::getName, return_value_policy > ()) > ; > > //---------------------------------------------------------------- class_ > > ("cNodeDescriptorList") > .def ("__iter__", iterator > ()) ; > > And then, in python, i grab a cNodeDescriptorList, and when i try to > iterate through it, it spits out: > > TypeError: No to_python (by-value) converter found for C++ type: class > kikura::cNodeDescriptor * > > So... what am i doing wrong? > > If more info is needed, i'd be glad to supply it... Try using range (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) with a functions that return boost::indirect_iterator::iterator> wrapped around the vector's begin() and end(). (http://www.boost.org/libs/iterator/doc/indirect_iterator.html) HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From xavier.warin at der.edfgdf.fr Mon Aug 16 11:06:08 2004 From: xavier.warin at der.edfgdf.fr (Xavier WARIN(Compte LOCAL) - I23) Date: Mon, 16 Aug 2004 09:06:08 -0000 Subject: [C++-sig] Re: Boost Python and Intel C++ 7.1 windows In-Reply-To: References: <3F85489C.9060203@der.edfgdf.fr> Message-ID: <3F8A6F88.8000705@der.edfgdf.fr> Hi David, No in fact i was trying to do a new project from scratch. I manage to get rid of the error while taking the options of the Jam file : -D_NATIVE_WCHAR_T_DEFINED -/Zc:wchar_t Thank you David Xavier David Abrahams wrote: > "Xavier WARIN(Compte LOCAL) - I23" writes: > > >>Hi, >> >>While compiling with Intel C++ 7.1 Boost Python , i get this kind of >>error on class.cpp and a lot of other Boost Python files : >> >>C:\boost-1.30.2\boost/type_traits/is_integral.hpp(39): error: class >>"boost::is_integral" has already been defined >> BOOST_TT_AUX_BOOL_TRAIT_CV_SPEC1(is_integral,wchar_t,true) >> >>I think that there must be a define that i missed somewhere ! I don't >>find it >>Any idea ? > > > Are you using Boost.Build? Are you using the CVS version of > Boost.Python? > > Works fine for Intel7.1/windows when I do it. > > bjam -sTOOLS=intel7 class.obj > ...found 909 targets... > ...updating 4 targets... > vc-C++ c:\build\bin\boost\libs\python\build\libboost_python.lib\intel7\debug-python\class.obj > class.cpp > vc-C++ c:\build\bin\boost\libs\python\build\boost_python.dll\intel7\debug-python\class.obj > class.cpp > MkDir1 c:\build\bin\boost\libs\python\build\boost_python.dll\intel7\debug-python\debug- > symbols-off > vc-C++ c:\build\bin\boost\libs\python\build\boost_python.dll\intel7\debug-python\debug-symbo > ls-off\class.obj > class.cpp > ...updated 4 targets... > From ndbecker2 at verizon.net Mon Aug 16 14:23:25 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 16 Aug 2004 08:23:25 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: David Abrahams wrote: > Neal Becker writes: > >> OK, I agree the previous version sucked. > > I wouldn't go that far. > >> Here is a new one I think is much >> better. >> >> The boost-python code is simple, and I'm not including it. The >> harder part is to supply the underlying c++ library for doing the >> vector-vector and vector-scalar arithmetic. I think I have a pretty >> good design for that, which I'd like to share. > > I think you're posting in the wrong forum then. > Vector processing is in my view one of the primary interests for boost-python. By processing vectors, the overhead involved with python and the python-c++ interface becomes acceptable. I believe a suitable container for interfacing between python and c++ is of fundamental interest to the boost-python community. I'm sure there must be a lot of interest in this subject. I have tried to investigate 3 candidates. 1) std::vector 2) ublas 3) numarray So far the results are: 1) std::vector - pros: universal availability easily understood supports required operations (insert, erase...) vector_indexing_suite already implemented (could be optimized more) cons: lacks vector arithmetic - but I just implemented this and it isn't difficult even for an amateur like myself 2) ublas: pros: already has vector arithmetic cons: lacks required operations (e.g., erase) no indexing_suite (see above) 3) numarray pros: ? cons: I had a hard time finding documentation. Heavy-weight interface -> high learning curve Summary: It appears that std::vector is a good choice. Ublas might be better in the future, but at present it lacks some required functionality. A ublas vector does not fulfill all the requirements of Sequence. This topic is known to ublas developers and may be addressed in the future. > I have only 2 quick comments in this one: > > 1. You should never use std::[binary|unary]_function because it > suppresses EBO. Consider what happens when you have a > compressed_pair,plus >. OK. I assume this means "Empty Base Optimization?" > > 2. Isn't something appropriate already present in uBlas? > See above. From ndbecker2 at verizon.net Mon Aug 16 15:23:07 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 16 Aug 2004 09:23:07 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: In case anyone else is interested, here is complete code that seems to be fully functional: -------------- next part -------------- A non-text attachment was scrubbed... Name: mismatch.H Type: text/x-csrc Size: 169 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Scalar.H Type: text/x-csrc Size: 198 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: vector_arith.hpp Type: text/x-csrc Size: 8410 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: vector.cc Type: text/x-c++src Size: 4066 bytes Desc: not available URL: From ndbecker2 at verizon.net Mon Aug 16 16:10:31 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 16 Aug 2004 10:10:31 -0400 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> <41183D40.9070301@boost-consulting.com> Message-ID: David Abrahams wrote: > Joel de Guzman writes: > >> David Abrahams wrote: >> >>> Joel de Guzman writes: >>> >>>>Neal D. Becker wrote: >>>> >>>> >>>>>vector_indexing_suite set_slice does: 1) erase 2) insert >>>>>Shouldn't this be optimized to simply do copy? >>>> >>>>You mean this: >>>> >>>> container.erase(container.begin()+from, container.begin()+to); >>>> container.insert(container.begin()+from, v); >>>> >>>>Pardon me for being slow, but how? Could you spell it out for me? >>> It's not as simple as "copy", but if you think hard about it you can >>> see how to avoid any redundant moves or copies. The pseudocode is >>> complicated so I'm not writing it out in full here, but: >>> if new_size <= old_size: >>> erase(old_finish + (new_size - old_size), old_finish) >>> if new_size < old_size: >>> copy(new_start, new_finish, old_start) >>> else: >>> # fill in the details here >> >> I see. Yeah, same ol' buffer management. Ok, I'll optimize it. >> But it'll have to be after 1.32. Ok? > > Sure thing. > Something wrong with this? Index: vector_indexing_suite.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/python/suite/indexing/vector_indexing_suite.hpp,v retrieving revision 1.8 diff -c -r1.8 vector_indexing_suite.hpp *** vector_indexing_suite.hpp 25 Jul 2004 17:00:37 -0000 1.8 --- vector_indexing_suite.hpp 16 Aug 2004 14:07:51 -0000 *************** *** 114,121 **** --- 114,126 ---- container.insert(container.begin()+from, first, last); } else { + if (to < container.size()) { + std::copy (first, last, container.begin()+from); + } + else { container.erase(container.begin()+from, container.begin()+to); container.insert(container.begin()+from, first, last); + } } } From dave at boost-consulting.com Mon Aug 16 16:20:19 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 16 Aug 2004 10:20:19 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: "Neal D. Becker" writes: > David Abrahams wrote: > >> Neal Becker writes: >> >>> OK, I agree the previous version sucked. >> >> I wouldn't go that far. >> >>> Here is a new one I think is much >>> better. >>> >>> The boost-python code is simple, and I'm not including it. The >>> harder part is to supply the underlying c++ library for doing the >>> vector-vector and vector-scalar arithmetic. I think I have a pretty >>> good design for that, which I'd like to share. >> >> I think you're posting in the wrong forum then. >> > > Vector processing is in my view one of the primary interests for > boost-python. By processing vectors, the overhead involved with python and > the python-c++ interface becomes acceptable. > > I believe a suitable container for interfacing between python and c++ is of > fundamental interest to the boost-python community. I'm sure there must be > a lot of interest in this subject. Sure, but if you're writing good mathematical vector components, there ought to be more interest in the whole Boost developer community at large. > I have tried to investigate 3 candidates. > > 1) std::vector > 2) ublas > 3) numarray > > So far the results are: > > 1) std::vector - > pros: > universal availability > easily understood > supports required operations (insert, erase...) > vector_indexing_suite already implemented (could be optimized more) > > cons: > lacks vector arithmetic - but I just implemented this and it isn't difficult > even for an amateur like myself Depends how fast you need it, I guess. > 2) ublas: > pros: > already has vector arithmetic > > cons: > lacks required operations (e.g., erase) > no indexing_suite (see above) > > 3) numarray > pros: ? > > cons: > I had a hard time finding documentation. > Heavy-weight interface -> high learning curve > > > Summary: > It appears that std::vector is a good choice. Ublas might be better in the > future, but at present it lacks some required functionality. A ublas > vector does not fulfill all the requirements of Sequence. This topic is > known to ublas developers and may be addressed in the future. Yeah, I know. >> I have only 2 quick comments in this one: >> >> 1. You should never use std::[binary|unary]_function because it >> suppresses EBO. Consider what happens when you have a >> compressed_pair,plus >. > > OK. I assume this means "Empty Base Optimization?" Yep. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ndbecker2 at verizon.net Mon Aug 16 18:33:18 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 16 Aug 2004 12:33:18 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: > >>> I have only 2 quick comments in this one: >>> >>> 1. You should never use std::[binary|unary]_function because it >>> suppresses EBO. Consider what happens when you have a >>> compressed_pair,plus >. >> >> OK. I assume this means "Empty Base Optimization?" > > Yep. > Why is this important? Is this comment just made as a general principle, or does it relate to the actual use in the vector arithmetic I wrote? I assume the only signficance of EBO is a size issue, in which case it wouldn't matter in the way I used it for vector arithmetic. Or, is there something I'm missing? (I went ahead and made the change you suggested anyway, but I'm curious). From ostiguy at fnal.gov Mon Aug 16 19:21:38 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Mon, 16 Aug 2004 12:21:38 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Thank You Dave, Max and Chez for your insights. I am getting closer to my goal, but it is not quite working yet. In the process I am slowly gaining more understanding of the way boost.python works. I have to say that I never cease to be amazed at how carefully crafted boost.python is. It is truly a remarkable piece of work. Back to my problem: Last Friday, following Max and Dave's suggestions I tried (in simplified form): class A; class_ PythonTypeA; A* get_existing() { return aptr; } ... A* aptr = new A(); object py_get_existing = make_function( &get_existing, return_value_policy() ); object PythonInstanceOfA = PythonTypeA( py_get_existing() ); ... Another poster pointed out that make_function is a factory for python objects and therefore the last line was incorrect. Dave added that it was "bogus". When I remove this last line, everything compiles properly, but of course when I print the "py_get_existing" object in python I get ; which is not a wrapped class A object. After thinking about this a bit, it occured to me that what I needed was more along the lines of object PythonInstanceOfA = PythonTypeA( aptr ); /// If I understand correctly, this should instantiate an object using the automatic converter defined by the extended python type class_ PythonTypeA. The code compiles without a hitch, but I get a core dump when the statement is executed. I am still investigating what might be going on (*** see note below ***) ). The approach suggested by Chez (chezdique AT yahoo.com) appears more promising. I have yet to try his code, but a cursory look gives me the impression that what he is doing is not fundamentally not different from what I just described. He defines an an empty ObjectWrapper and a correcponding get_ptr() function. Once again, correct me if I am wrong, but this appers superflous since T& and T* converters should automatically be generated by boost.python. An ObjectWrapper class would be useful to support some kind of smart pointers. I apologize for the lengthy post. I hope this is not too confusing and I would greatly appreciate more comments/feedback. -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 *** note: one complication is that I want to keep all the extended python type definitions together. This means that somehow the PythonTypeA object has to be global. Since there are typically a large number of types declared in each modules, the simplest thing seemed to use a global class_* PythonTypeAPtr and set PythonTypeAPtr = &PythonTypeA. From dave at boost-consulting.com Mon Aug 16 20:51:43 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 16 Aug 2004 14:51:43 -0400 Subject: [C++-sig] Re: My latest project References: Message-ID: "Neal D. Becker" writes: >> >>>> I have only 2 quick comments in this one: >>>> >>>> 1. You should never use std::[binary|unary]_function because it >>>> suppresses EBO. Consider what happens when you have a >>>> compressed_pair,plus >. >>> >>> OK. I assume this means "Empty Base Optimization?" >> >> Yep. >> > > Why is this important? consider the size of bind(times, bind(plus, _1, _2), bind(minus, _1, _2)) > Is this comment just made as a general principle, or does it relate > to the actual use in the vector arithmetic I wrote? It will probably be relevant eventually since you seem to be trying to write general-purpose standalone vector arithmetic. Who knows how your vectors (etc.) may be used? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Mon Aug 16 20:53:38 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 16 Aug 2004 14:53:38 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy writes: > Back to my problem: > > Last Friday, following Max and Dave's suggestions I tried (in simplified > form): > > class A; > > class_ PythonTypeA; > > A* get_existing() { return aptr; } > > ... > > A* aptr = new A(); > > object py_get_existing = > make_function( &get_existing, > return_value_policy() ); > > object PythonInstanceOfA = PythonTypeA( py_get_existing() ); > > ... > > Another poster pointed out that make_function is a factory for python > objects and therefore the last line was incorrect. Dave added that it was > "bogus". > > When I remove this last line, everything compiles properly, but of > course when I print the "py_get_existing" object in python I get > > ; > > which is not a wrapped class A object. As Mike and I wrote, just do this: object PythonInstanceOfA = py_get_existing(); -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ostiguy at fnal.gov Mon Aug 16 23:51:17 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Mon, 16 Aug 2004 16:51:17 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: > > As Mike and I wrote, just do this: > > object PythonInstanceOfA = py_get_existing(); > Unfortunately, that does not seem to do quite what I want. I constructed a simple complete toy example to demonstrate. Note the following: (1) creating python_object_a forces an undesired instantiation of a type A (i.e. in addition to the the existing instance a) (2) if the interface defines a python object without an __init__ function, the result is a runtime error: "Object cannot by created from python." (3) if you compile the example, here is what you get when the module is imported from python Python 2.3.3 (#1, Jul 7 2004, 13:43:38) [GCC 3.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from inject import * >>> a >>> dir() ['A', '__builtins__', '__doc__', '__name__', 'a'] >>> dir (a) ['A', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__instance_size__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] >>> Note that the object instance "a" has been injected. However, for a reason that escapes me, the method "dummy" which is part of the specified interface is not correctly exported. Again, my goal is to wrap an existing instance of A, without having to create a spurious object (basically without having to call the A constructor more than once). Comments, suggestions ??? -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 /////// *************** example: inject.cpp **************** ///////// #include class A { public: A(int d) { _dummy = d; } int dummy() { return _dummy;} private: int _dummy; }; A* a = 0; A* get_existing() { return a; } void inject_object(); using namespace boost::python; class_ * PythonTypeAPtr; BOOST_PYTHON_MODULE( inject ) { static class_ PythonTypeA("A", init()); //*** note: using no_init here will cause a runtime error !! PythonTypeA.def("A", &A::dummy); /***** this does not seem to export the dummy function to python. Why ? PythonTypeAPtr = &PythonTypeA; inject_object(); } void inject_object() { a = new A(99); object py_get_existing = make_function( &get_existing, return_value_policy< reference_existing_object>() ); object python_object_a = (*PythonTypeAPtr)(2); // <<<<<<========== //****** instantiation of a spurious object python_object_a = py_get_existing(); handle<> main_module ( boost::python::borrowed( PyImport_AddModule("__main__") ) ); handle<> main_dict ( boost::python::borrowed( PyModule_GetDict(main_module.get()) )); PyDict_SetItemString ( main_dict.get(), "a", python_object_a.ptr() ); } From MKhesin at liquidnet.com Tue Aug 17 00:05:13 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Mon, 16 Aug 2004 18:05:13 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + and exporting it to python Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050AF0@exchange.lnholdings.com> I believe that you will not see the "dummy" method by doing dir(). IIRC boost.python hijacks __getattr__ to delegate the lookup to the c++ implemented code. Just try a.dummy(), does it work? max > -----Original Message----- > From: Francois Ostiguy [mailto:ostiguy at fnal.gov] > Sent: Monday, August 16, 2004 5:51 PM > To: c++-sig at python.org > Subject: Re: [C++-sig] Re: creating an instance of a class_<> > object in > c++ and exporting it to python > > > > > > > As Mike and I wrote, just do this: > > > > object PythonInstanceOfA = py_get_existing(); > > > > Unfortunately, that does not seem to do quite what I want. > I constructed a simple complete toy example to demonstrate. > > Note the following: > > (1) creating python_object_a forces an undesired instantiation of > a type A (i.e. in addition to the the existing instance a) > > (2) if the interface defines a python object without > an __init__ function, the result is a runtime error: > "Object cannot by created from python." > > (3) if you compile the example, here is what you get when the > module is imported from python > > > Python 2.3.3 (#1, Jul 7 2004, 13:43:38) > [GCC 3.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more > information. > >>> from inject import * > >>> a > > >>> dir() > ['A', '__builtins__', '__doc__', '__name__', 'a'] > >>> dir (a) > ['A', '__class__', '__delattr__', '__dict__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__instance_size__', > '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', > '__setattr__', '__str__', '__weakref__'] > >>> > > Note that the object instance "a" has been injected. However, for a > reason that escapes me, the method "dummy" which is > part of the specified interface is not correctly exported. > > Again, my goal is to wrap an existing instance of A, without > having to create a spurious object (basically without having to > call the A constructor more than once). > > Comments, suggestions ??? > > -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 > > > /////// *************** example: inject.cpp **************** ///////// > > #include > > class A { > public: > A(int d) { _dummy = d; } > int dummy() { return _dummy;} > private: > > int _dummy; > }; > > A* a = 0; > > A* get_existing() { return a; } > > void inject_object(); > > using namespace boost::python; > > class_ * PythonTypeAPtr; > > BOOST_PYTHON_MODULE( inject ) > { > > > static class_ > PythonTypeA("A", init()); > > //*** note: using no_init here will cause a runtime error !! > > PythonTypeA.def("A", &A::dummy); > > /***** this does not seem to export the dummy function to > python. Why ? > > PythonTypeAPtr = &PythonTypeA; > > inject_object(); > > } > > void inject_object() { > > a = new A(99); > > object py_get_existing = > make_function( &get_existing, return_value_policy< > reference_existing_object>() ); > > object python_object_a = (*PythonTypeAPtr)(2); // <<<<<<========== > //****** instantiation of a spurious object > > python_object_a = py_get_existing(); > > > handle<> main_module ( boost::python::borrowed( > PyImport_AddModule("__main__") ) ); > handle<> main_dict ( boost::python::borrowed( > PyModule_GetDict(main_module.get()) )); > PyDict_SetItemString ( main_dict.get(), "a", > python_object_a.ptr() ); > > } > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric at enthought.com Tue Aug 17 00:47:52 2004 From: eric at enthought.com (eric jones) Date: Mon, 16 Aug 2004 17:47:52 -0500 Subject: [C++-sig] ANN: Python/Scientific Job openings at Enthought Message-ID: <41213998.4070709@enthought.com> Hey Folks, Enthought continues to grow, and we're hiring again. There are several positions open, and most of them involve python+scientific computing. A couple of the positions also involve support of SciPy. I'm very interested in finding a person for the "scientist" job posting that is both able to work well with our customers and also has the personality and interest to work with the SciPy community to help push the library forward. More information is available on our web site. http://www.enthought.com/careers.htm Our current development efforts are in the areas of electromagnetics, geophysics, and graphics (2D and 3D). If you have any questions, please feel free to contact me. Please forward the link to anyone you feel might be interested. thanks, eric From ostiguy at fnal.gov Tue Aug 17 02:46:32 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Mon, 16 Aug 2004 19:46:32 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + and exporting it to python In-Reply-To: <4B6FB7F60D37D41188C300B0D022E0C003050AF0@exchange.lnholdings.com> References: <4B6FB7F60D37D41188C300B0D022E0C003050AF0@exchange.lnholdings.com> Message-ID: > I believe that you will not see the "dummy" method by doing dir(). IIRC > boost.python hijacks __getattr__ to delegate the lookup to the c++ > implemented code. Just try a.dummy(), does it work? > max > I used boost.python in the past to wrap a fairly large API. The exposed interface is always correctly reported by dir(). In answer to your question, here is what I get: GCC 3.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from inject import * >>> print a.dummy Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'dummy' >>> -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 chezdique at yahoo.com Tue Aug 17 04:26:20 2004 From: chezdique at yahoo.com (dique) Date: Mon, 16 Aug 2004 19:26:20 -0700 (PDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: Message-ID: <20040817022620.58242.qmail@web41502.mail.yahoo.com> I think my sample code illustrates exactly what you want. Perhaps you should compile and run it? The reason that I use ObjectWrap as the HeldType is because you can't do object(a) for a raw pointer 'a', but you can do object(objectWrapOfA) where objectWrapOfA = ObjectWrap(a). By the way, your code should work if you make a few changes. > > PythonTypeA.def("A", &A::dummy); > should be PythonTypeA.def("dummy", &A::dummy); > object python_object_a = (*PythonTypeAPtr)(2); // <<<<<<========== remove the above line > > python_object_a = py_get_existing(); > Just need to do this: object python_object_a = py_get_existing(); __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail From chezdique at yahoo.com Tue Aug 17 04:39:03 2004 From: chezdique at yahoo.com (dique) Date: Mon, 16 Aug 2004 19:39:03 -0700 (PDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python In-Reply-To: Message-ID: <20040817023903.457.qmail@web41511.mail.yahoo.com> Ah... it never comes to my mind that I can define it elsewhere. Perhaps I was illuded by the fact that several get_pointer functions were all defined in namespace boost. Anyway VC7 still chokes if I put it in the global namespace. The good news is that I have upgraded to VC++ Toolkit 2003 recently... --- David Abrahams wrote: > dique writes: > > > namespace boost > > { > > // Some internal boost functions require get_pointer to be > > defined. > > But not in namespace boost. Never, ever make a definition in a > library's namespace unless the documentation tells you to. > Put this in the same namespace as ObjectWrap, or if your compiler is > broken like vc6/7, put it in the global namespace. > > > // Define this before including > > template > > inline T * get_pointer(ObjectWrap const & p) > > { > > return p.get(); > > } > > } > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From dave at boost-consulting.com Tue Aug 17 15:01:51 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 17 Aug 2004 09:01:51 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy writes: >> >> As Mike and I wrote, just do this: >> >> object PythonInstanceOfA = py_get_existing(); >> > > Unfortunately, that does not seem to do quite what I want. > I constructed a simple complete toy example to demonstrate. > > Note the following: > > (1) creating python_object_a forces an undesired instantiation of > a type A (i.e. in addition to the the existing instance a) So don't do that. It's not needed and it wasn't in the code Mike posted. Please just read his directions very carefully and don't add anything else. > (2) if the interface defines a python object without > an __init__ function, the result is a runtime error: > "Object cannot by created from python." The result of what? > (3) if you compile the example, here is what you get when the > module is imported from python > > > Python 2.3.3 (#1, Jul 7 2004, 13:43:38) > [GCC 3.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from inject import * > >>> a > > >>> dir() > ['A', '__builtins__', '__doc__', '__name__', 'a'] > >>> dir (a) > ['A', '__class__', '__delattr__', '__dict__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__instance_size__', > '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', > '__setattr__', '__str__', '__weakref__'] > >>> > > Note that the object instance "a" has been injected. However, for a > reason that escapes me, the method "dummy" which is > part of the specified interface is not correctly exported. Because you called it "A", not "dummy". > Again, my goal is to wrap an existing instance of A, without > having to create a spurious object (basically without having to > call the A constructor more than once). > > Comments, suggestions ??? Read and follow directions more carefully. Sorry to be blunt, but that is the best I can do. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Aug 17 15:02:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 17 Aug 2004 09:02:26 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AF0@exchange.lnholdings.com> Message-ID: Max Khesin writes: > From: Max Khesin > Subject: RE: Re: creating an instance of a class_<> object in c+ + and exporting it to python > Newsgroups: gmane.comp.python.c++ > Date: Mon, 16 Aug 2004 18:05:13 -0400 > Reply-To: Development of Python/C++ integration > > I believe that you will not see the "dummy" method by doing dir(). IIRC > boost.python hijacks __getattr__ to delegate the lookup to the c++ > implemented code. Just try a.dummy(), does it work? No it doesn't. The problem is that he used a different name, "A", for the method. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From MKhesin at liquidnet.com Tue Aug 17 15:58:36 2004 From: MKhesin at liquidnet.com (Max Khesin) Date: Tue, 17 Aug 2004 09:58:36 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c+ + and exporting it to python Message-ID: <4B6FB7F60D37D41188C300B0D022E0C003050AF8@exchange.lnholdings.com> Yep, sorry for disinformation. > > I believe that you will not see the "dummy" method by doing > dir(). IIRC > > boost.python hijacks __getattr__ to delegate the lookup to the c++ > > implemented code. Just try a.dummy(), does it work? > > No it doesn't. The problem is that he used a different name, "A", > for the method. > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. From ostiguy at fnal.gov Tue Aug 17 17:27:31 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Tue, 17 Aug 2004 10:27:31 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: > >> As Mike and I wrote, just do this: > >> > >> object PythonInstanceOfA = py_get_existing(); > >> > > > > Unfortunately, that does not seem to do quite what I want. > > I constructed a simple complete toy example to demonstrate. > > Dave, Mike, and all the others that took the time to reply to my posts: Your patience is greatly appreciated. I tried too many things ... and I should have tested my toy example more carefully before posting it. The bottom line is that by following your instructions I got my example to work just as expected. Although I think I understand what it going on, I would be interested in your feedback. Tell me if I got this right: I understand that object PythonInstanceOfA = py_get_existing(); [ or alternatively, object PythonInstanceOfA( py_get_existing() ); ] creates python object wrapper and initializes it with the the object returned by py_get_existing(). Since neither py_get_existing() or PythonInstanceOfA explicitly know anything about the "A" object exported type, I presume this means that instantiating class_< A, A*, boost:noncopyable> registers a type converter from A* to Python and it is through this converter that the object becomes an instance of the Python type A. Does this mean that only one Python type can/should be declared as holder of a A* ? In other words, is it possible to declare two Python types, say A1 and A2, both holding a A* but with different exported interfaces ? Finally, the py_get_existing() gymnastics was required because object PythonInstanceOfA( a ) ; // a is a raw ptr to A does not work. But, apparently object PythonInstanceOfA( aw ) ; // aw is an instance of a wrapper class which defines get_pointer() does work. Can you briefly explain what is happening ? At what point is the type conversion occuring ? My reading of the documentation led me into thinking that although the get_pointer() method is not defined, conversion from raw pointers (and references) should automatically be supported. Again, 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 mike at nospam.com Tue Aug 17 20:45:37 2004 From: mike at nospam.com (Mike Rovner) Date: Tue, 17 Aug 2004 11:45:37 -0700 Subject: [C++-sig] Re: Re: creating an instance of a class_<> object in c++and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy wrote: > class_< A, A*, boost:noncopyable> > > registers a type converter from A* to Python and it is through this > converter that the object becomes an instance of the Python type A. It's (a) create a pytype wrapper class and (b) registers a type converter unless you specify boost:noncopyable as you did. > Does this mean that only one Python type can/should be declared as > holder of a A* ? In other words, is it possible to declare two > Python types, say A1 and A2, both holding a A* but with different > exported interfaces ? You can't have multiple converters. You'll get a boost compile error trying. > object PythonInstanceOfA( a ) ; // a is a raw ptr to A > > does not work. boost:noncopyable prevents converting c++ value to python. My .02. Let's Dave correct me. Mike From dave at boost-consulting.com Tue Aug 17 20:55:38 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 17 Aug 2004 14:55:38 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy writes: >> >> As Mike and I wrote, just do this: >> >> >> >> object PythonInstanceOfA = py_get_existing(); >> >> >> > >> > Unfortunately, that does not seem to do quite what I want. >> > I constructed a simple complete toy example to demonstrate. >> > > > Dave, Mike, and all the others that took the time to reply to my posts: > > Your patience is greatly appreciated. > > I tried too many things ... and I should have tested my toy example more > carefully before posting it. The bottom line is that by following your > instructions I got my example to work just as expected. Although I think > I understand what it going on, I would be interested in your feedback. > > Tell me if I got this right: > > I understand that > > object PythonInstanceOfA = py_get_existing(); > > [ or alternatively, object PythonInstanceOfA( py_get_existing() ); ] > > creates python object wrapper and initializes it with the the object > returned by py_get_existing(). Since neither py_get_existing() or > PythonInstanceOfA explicitly know anything about the "A" object > exported type, I presume this means that instantiating > > class_< A, A*, boost:noncopyable> ^^^^ this should be completely unneccessary > > registers a type converter from A* to Python and it is through this > converter that the object becomes an instance of the Python type A. Not quite. It registers type converters from A to Python, but to handle A* (because the pointer might be owned or just a reference as in your case) you need a return value policy. So the conversion is handled by the make_function call that created py_get_existing. However, you need class_ in order to create the Python class object corresponding to A. > Does this mean that only one Python type can/should be declared as > holder of a A* ? In other words, is it possible to declare two Python > types, say A1 and A2, both holding a A* but with different > exported interfaces ? Maybe. It would probably at least warn you at runtime, though, and it's probably a bad idea. > Finally, the py_get_existing() gymnastics was required because > > object PythonInstanceOfA( a ) ; // a is a raw ptr to A > > does not work. Right, it tries to _copy_ a into the A object held by PythonInstanceOfA. > But, apparently > > object PythonInstanceOfA( aw ) ; // aw is an instance of a wrapper > class which defines get_pointer() > does work. > > Can you briefly explain what is happening ? Boost.Python recognizes that it's a wrapper class that contains a PyObject* referring to a Python object, and just extracts that pointer. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Aug 17 22:17:57 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 17 Aug 2004 16:17:57 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: "Mike Rovner" writes: > Francois Ostiguy wrote: >> class_< A, A*, boost:noncopyable> >> >> registers a type converter from A* to Python and it is through this >> converter that the object becomes an instance of the Python type A. > > It's (a) create a pytype wrapper class and (b) registers a type > converter unless you specify boost:noncopyable as you did. That's about right. >> Does this mean that only one Python type can/should be declared as >> holder of a A* ? In other words, is it possible to declare two >> Python types, say A1 and A2, both holding a A* but with different >> exported interfaces ? > > You can't have multiple converters. You'll get a boost compile error trying. Runtime error/warning, I'm fairly certain. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ostiguy at fnal.gov Tue Aug 17 23:43:35 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Tue, 17 Aug 2004 16:43:35 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Dave, Mike (and others): Thank you for the explanations. This is truly very helpful. More questions if I may: > > class_< A, A*, boost:noncopyable> > ^^^^ > this should be completely unneccessary > If I omit A*, how does class A infer that I am trying to wrap a pointer ? > Boost.Python recognizes that it's a wrapper class that contains a > PyObject* referring to a Python object, and just extracts that > pointer. I am confused by the above statement. Which wrapper class are you talking about ? Consider the class (presented in another post): class Wrapper { public: typedef T element_type; Wrapper(T * a): _a(a) { } T* get() const { return _a ;} T* operator->() const { return _a ;} ... etc .. private: T* _a; }; this class does not contain a PyObject* ... Yet it is OK to do class_< A, Wrapper, boost:noncopyable>("A", no_init); ... A* a = new A(); object PythonTypeA ( Wrapper(a) ); Finally, when an object holds a pointer to an existing instance, destroying the python wrapper object also deletes the held pointer. If the c++ object pointed to by the held pointer is deleted first, when the python object reference count goes to 0, the held c++ is invalid. Any suggestion on how to deal with this issue ? -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 Aug 18 14:18:32 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 18 Aug 2004 08:18:32 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy writes: > Dave, Mike (and others): > > Thank you for the explanations. This is truly very helpful. > > More questions if I may: > >> > class_< A, A*, boost:noncopyable> >> ^^^^ >> this should be completely unneccessary >> > > If I omit A*, how does class A infer that I am trying to > wrap a pointer ? It doesn't. I explained where the pointer-to-Python conversion comes from in my previous message. >> Boost.Python recognizes that it's a wrapper class that contains a >> PyObject* referring to a Python object, and just extracts that >> pointer. > > I am confused by the above statement. Which wrapper class are you > talking about ? > > Consider the class (presented in another post): > > class Wrapper { > > public: > > typedef T element_type; > > Wrapper(T * a): _a(a) { } > T* get() const { return _a ;} > T* operator->() const { return _a ;} > > ... etc .. > > private: > > T* _a; > > }; > > this class does not contain a PyObject* ... That's not a wrapper class; it's a smart pointer. A wrapper class is something like BaseWrap shown at http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html > Yet it is OK > to do > > class_< A, Wrapper, boost:noncopyable>("A", no_init); > ... > > A* a = new A(); > > object PythonTypeA ( Wrapper(a) ); In that case the smart-pointer-to-Python conversion is registered by the class_ ...> construction. > Finally, when an object holds a pointer to an existing instance, > destroying the python wrapper object also deletes the held pointer. Not if py_get_existing is created with return_value_policy. In that case it's just held by a plain dumb pointer. If you want the Python wrapper object to manage the lifetime of the C++ object, you need return_value_policy. > If the c++ object pointed to by the held pointer is deleted first, > when the python object reference count goes to 0, the held c++ is > invalid. Any suggestion on how to deal with this issue ? Hold the c++ object by shared_ptr, or if you need strict single-owner semantics, by auto_ptr. The latter is the result of using return_value_policy anyway. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From groups at DavidBrownell.com Wed Aug 18 01:24:14 2004 From: groups at DavidBrownell.com (David Brownell) Date: Tue, 17 Aug 2004 16:24:14 -0700 Subject: [C++-sig] Newbie vector_indexing_suite Link Errors Message-ID: I apologize if this is a duplicate post, technical difficulties.... I just discovered vector_indexing_suite, and am trying to compile the sample application that is linked from the documentation. When I compile the C++ code, I get the following unresolved externals: __declspec(dllimport) void __cdecl boost::python::objects::register_dynamic_id_aux __declspec(dllimport) void * __cdecl boost::python::objects::find_static_type __declspec(dllimport) public: __thiscall boost::python::converter::detail::arg_to_python_base::arg_to_python_base __declspec(dllimport) void * __cdecl boost::python::objects::find_dynamic_type __declspec(dllimport) class boost::python::api::object const & __cdecl boost::python::objects::identity_function __declspec(dllimport) struct _object * __cdecl boost::python::objects::make_nurse_and_patient __declspec(dllimport) void __cdecl boost::python::objects::stop_iteration_error It seems strange to me that the symbols are decoared with dllimport rather than dllexport, but I didn't see any unusual preprocessor magic going on in the code or described in the documentation that would ensure that these symbols are exported rather than imported. Is there something that I am missing to compile the example? Compiler: Microsoft Visual Studio v7.1 OS: Win XP Boost: linking with $(PYTHON_ROOT)\libs\python23.lib and libboost_python-vc71-mt-gd-1_31.lib (which was compiled using bjam) Python: 2.3 Thanks in advance for your help! David Brownell From ostiguy at fnal.gov Wed Aug 18 16:28:03 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Wed, 18 Aug 2004 09:28:03 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: -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 groups at DavidBrownell.com Wed Aug 18 16:17:52 2004 From: groups at DavidBrownell.com (David Brownell) Date: Wed, 18 Aug 2004 07:17:52 -0700 Subject: [C++-sig] Newbie vector_indexing_suite Link Errors Message-ID: I just discovered vector_indexing_suite, and am trying to compile the sample application that is linked from the documentation. When I compile the C++ code, I get the following unresolved externals: __declspec(dllimport) void __cdecl boost::python::objects::register_dynamic_id_aux __declspec(dllimport) void * __cdecl boost::python::objects::find_static_type __declspec(dllimport) public: __thiscall boost::python::converter::detail::arg_to_python_base::arg_to_python_base __declspec(dllimport) void * __cdecl boost::python::objects::find_dynamic_type __declspec(dllimport) class boost::python::api::object const & __cdecl boost::python::objects::identity_function __declspec(dllimport) struct _object * __cdecl boost::python::objects::make_nurse_and_patient __declspec(dllimport) void __cdecl boost::python::objects::stop_iteration_error It seems strange to me that the symbols are decoared with dllimport rather than dllexport, but I didn't see any unusual preprocessor magic going on in the code or described in the documentation that would ensure that these symbols are exported rather than imported. Is there something that I am missing to compile the example? Compiler: Microsoft Visual Studio v7.1 OS: Win XP Boost: linking with $(PYTHON_ROOT)\libs\python23.lib and libboost_python-vc71-mt-gd-1_31.lib (which was compiled using bjam) Python: 2.3 Thanks in advance for your help! David Brownell From dave at boost-consulting.com Wed Aug 18 20:46:57 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 18 Aug 2004 14:46:57 -0400 Subject: [C++-sig] Re: Newbie vector_indexing_suite Link Errors References: Message-ID: "David Brownell" writes: > I just discovered vector_indexing_suite, and am trying to compile the sample > application that is linked from the documentation. Which one, please? Linked from where in the documentation? > When I compile the C++ > code, You mean when you try to link. > I get the following unresolved externals: > > __declspec(dllimport) void __cdecl > boost::python::objects::register_dynamic_id_aux > __declspec(dllimport) void * __cdecl > boost::python::objects::find_static_type > __declspec(dllimport) public: __thiscall > boost::python::converter::detail::arg_to_python_base::arg_to_python_base > > __declspec(dllimport) void * __cdecl > boost::python::objects::find_dynamic_type > __declspec(dllimport) class boost::python::api::object const & __cdecl > boost::python::objects::identity_function > __declspec(dllimport) struct _object * __cdecl > boost::python::objects::make_nurse_and_patient > __declspec(dllimport) void __cdecl > boost::python::objects::stop_iteration_error > It seems strange to me that the symbols are decoared with dllimport rather > than dllexport, but I didn't see any unusual preprocessor magic going on in > the code or described in the documentation that would ensure that these > symbols are exported rather than imported. Is there something that I am > missing to compile the example? > > Compiler: Microsoft Visual Studio v7.1 > OS: Win XP > Boost: linking with $(PYTHON_ROOT)\libs\python23.lib and > libboost_python-vc71-mt-gd-1_31.lib (which was compiled using bjam) > Python: 2.3 Did you use bjam to build the "sample application?" If not, do so. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ostiguy at fnal.gov Wed Aug 18 21:01:50 2004 From: ostiguy at fnal.gov (Francois Ostiguy) Date: Wed, 18 Aug 2004 14:01:50 -0500 (CDT) Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python In-Reply-To: References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: > > > That's not a wrapper class; it's a smart pointer. Dave = I apologize for the the poor wording. One might argue that the particular smart pointer in my example is a "wrapper" around a regular pointer. I agree that "wrapper class", especially in the context of the boost.python library, has a more precise meaning. Let me try to ask my questions differently. Q1 - Your explanation of how the conversion is handled is "So the conversion is handled by the make_function call that created py_get_existing. However, you need class_ in order to create the Python class object corresponding to A." When make_function() converts a c++ A* into a python object "A", "conversion" implies (1) knowing what the python type A interface is, which is why class_ is needed. (2) deciding what will be held in that object. In my case, the return value policy implies that I want the object to hold a dumb pointer. What determines the valid held types ? Do I understand correctly that A*, A&, auto_ptr are automatically valid held types and therefore explicitly specifying A* is uncessary ? In other words, the only held types that need to be explicitly specified are those that are not already supported ? Q2 - When I do ... class("A", no_init); class, boost:noncopyable>("B", no_init); A* a; B* b; ... object PythonInstanceofA ( a ); // error [1] object PythonInstanceofB ( SmartPointer(b) ); // OK [2] according to your previous explanations: [1] "fails because there is an attempt to copy "a" directly into the A object held by PythonInstanceofA" object is generic object. By what mechanism would it know prior to construction that it should be holding an instance of A ? I would think that PythonInstanceofA can only acquire its identity as a type "A" by infering it from the argument in the constructor. So I do not understand the statement "copy "a" directly into the A object held by PythonInstanceofA". [2] "succeeds because Boost.Python recognizes that it's a wrapper class that contains a PyObject* referring to a Python object, and just extracts that pointer" Which "wrapper" class are you refering to ? SmartPointer ? Does class, boost:noncopyable> register a converter from SmartPointer to Python ? Thank you in advance. Your patience 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 db at DavidBrownell.com Wed Aug 18 22:08:27 2004 From: db at DavidBrownell.com (David Brownell) Date: Wed, 18 Aug 2004 13:08:27 -0700 Subject: [C++-sig] Re: Newbie vector_indexing_suite Link Errors Message-ID: <20040818200830.94BF51E4005@bag.python.org> I was attempting to compile and link vector_indexing_suite.cpp, located in the python\test directory. It looks like #define'ing BOOST_PYTHON_STATIC_LIB was all I needed. Seems strange that I didn't have to #define this until I started working with the vector_indexing_suite. Thanks for your help! David Brownell "David Abrahams" wrote in message news:... > "David Brownell" writes: > > > I just discovered vector_indexing_suite, and am trying to compile the sample > > application that is linked from the documentation. > > Which one, please? Linked from where in the documentation? > > > When I compile the C++ > > code, > > You mean when you try to link. > > > I get the following unresolved externals: > > > > __declspec(dllimport) void __cdecl > > boost::python::objects::register_dynamic_id_aux > > __declspec(dllimport) void * __cdecl > > boost::python::objects::find_static_type > > __declspec(dllimport) public: __thiscall > > boost::python::converter::detail::arg_to_python_base::arg_to_python_base > > > > __declspec(dllimport) void * __cdecl > > boost::python::objects::find_dynamic_type > > __declspec(dllimport) class boost::python::api::object const & __cdecl > > boost::python::objects::identity_function > > __declspec(dllimport) struct _object * __cdecl > > boost::python::objects::make_nurse_and_patient > > __declspec(dllimport) void __cdecl > > boost::python::objects::stop_iteration_error > > > It seems strange to me that the symbols are decoared with dllimport rather > > than dllexport, but I didn't see any unusual preprocessor magic going on in > > the code or described in the documentation that would ensure that these > > symbols are exported rather than imported. Is there something that I am > > missing to compile the example? > > > > Compiler: Microsoft Visual Studio v7.1 > > OS: Win XP > > Boost: linking with $(PYTHON_ROOT)\libs\python23.lib and > > libboost_python-vc71-mt-gd-1_31.lib (which was compiled using bjam) > > Python: 2.3 > > Did you use bjam to build the "sample application?" If not, do so. > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com From dave at boost-consulting.com Thu Aug 19 00:59:14 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 18 Aug 2004 18:59:14 -0400 Subject: [C++-sig] Re: Newbie vector_indexing_suite Link Errors References: <20040818200830.94BF51E4005@bag.python.org> Message-ID: "David Brownell" writes: > I was attempting to compile and link vector_indexing_suite.cpp, located in > the python\test directory. It looks like #define'ing > BOOST_PYTHON_STATIC_LIB was all I needed. Seems strange that I didn't have > to #define this until I started working with the vector_indexing_suite. > > Thanks for your help! Don't do it that way; you probably aren't getting correct results. Go to the test directory and invoke "bjam ... test", specifying your toolset, etc. where "..." is. That will compile and run all the tests. Or invoke "bjam ... vector_indexing_suite" and it will compile and run just that suite. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Thu Aug 19 15:17:59 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 Aug 2004 09:17:59 -0400 Subject: [C++-sig] Re: creating an instance of a class_<> object in c++ and exporting it to python References: <4B6FB7F60D37D41188C300B0D022E0C003050AE4@exchange.lnholdings.com> Message-ID: Francois Ostiguy writes: >> >> >> That's not a wrapper class; it's a smart pointer. > > Dave = > > I apologize for the the poor wording. No problem, but it made it hard for me to help you since I thought you were talking about something else. > One might argue that the particular smart pointer in my example is a > "wrapper" around a regular pointer. I agree that "wrapper class", > especially in the context of the boost.python library, has a more > precise meaning. > > Let me try to ask my questions differently. > > Q1 - > > Your explanation of how the conversion is handled is > > "So the conversion is > handled by the make_function call that created py_get_existing. > However, you need class_ in order to create the Python class > object corresponding to A." > > When make_function() converts a c++ A* into a python object "A", > "conversion" implies > (1) knowing what the python type A interface is, which is why class_ > is needed. Not sure about the word "interface". I'd say, "knowing how to find the python type A, which is why..." (1a) creating a Python instance of that class. > (2) deciding what will be held in that object. In my case, the return > value policy implies that I want the object to hold a dumb > pointer. Sort of. That decision is made at compile-time. [note: what we're saying above is true _in this case_, but in general it just implies "knowing how to come up with an instance of Python type A" -- any details are determined by the specific converter] > What determines the valid held types ? See http://www.boost.org/libs/python/doc/v2/class.html#class_-spec > Do I understand correctly > that A*, A&, auto_ptr are automatically valid held types Not A&. > and therefore explicitly specifying A* is uncessary ? The HeldType parameter to class_<...> is used to determine how the objects will be held when created via __init__, i.e. when you invoke the Python class object to create an instance of that class: >>> x = A() or in C++ object x = PythonClassA(); class_ also registers some automatic to-python converters when HeldType is a smart pointer. However, none of that matters in your particular case; conversion to Python is handled by the return value policy on your wrapped function. > Q2 - > > When I do > ... > > class("A", no_init); > class, boost:noncopyable>("B", no_init); > > A* a; > B* b; > ... > > object PythonInstanceofA ( a ); // error [1] > object PythonInstanceofB ( SmartPointer(b) ); // OK [2] > > according to your previous explanations: > > [1] "fails because there is an attempt to copy "a" directly into the > A object held by PythonInstanceofA" > > object is generic object. By what mechanism would it know prior > to construction that it should be holding an instance of A ? The magic of templates. You're passing it an A*. > I would think that PythonInstanceofA can only acquire its identity as a > type "A" by infering it from the argument in the constructor. Right. > So I do not understand the statement "copy "a" directly into the A > object held by PythonInstanceofA". It tries to copy *a. But nonetheless, I don't understand what you don't understand about that. > [2] "succeeds because Boost.Python recognizes that it's a wrapper class > that contains a PyObject* referring to a Python object, and > just extracts that pointer" > > Which "wrapper" class are you refering to ? SmartPointer ? > Does class, boost:noncopyable> register a > converter from SmartPointer to Python ? No, I'm referring to a _wrapper_ class derived from B (not a smart pointer), which is what I thought you were describing at that point. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ndbecker2 at verizon.net Thu Aug 19 21:27:59 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Thu, 19 Aug 2004 15:27:59 -0400 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> <41183D40.9070301@boost-consulting.com> Message-ID: How does this patch look? This attempts to optimize for the case in set_slice that the slice being replaced is the same size as the replacement, in which case a simple copy is performed rather than erase/insert. -------------- next part -------------- A non-text attachment was scrubbed... Name: *vc-diff* Type: text/x-diff Size: 863 bytes Desc: not available URL: From dave at boost-consulting.com Thu Aug 19 23:14:45 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 Aug 2004 17:14:45 -0400 Subject: [C++-sig] Re: Optimize vector_indexing_suite set_slice References: <4116F946.8060006@boost-consulting.com> <41183D40.9070301@boost-consulting.com> Message-ID: "Neal D. Becker" writes: > How does this patch look? > > This attempts to optimize for the case in set_slice that the slice being > replaced is the same size as the replacement, in which case a simple copy > is performed rather than erase/insert. > > Index: vector_indexing_suite.hpp > =================================================================== > RCS file: /cvsroot/boost/boost/boost/python/suite/indexing/vector_indexing_suite.hpp,v > retrieving revision 1.8 > diff -c -r1.8 vector_indexing_suite.hpp > *** vector_indexing_suite.hpp 25 Jul 2004 17:00:37 -0000 1.8 > --- vector_indexing_suite.hpp 19 Aug 2004 19:25:06 -0000 > *************** > *** 114,121 **** > --- 114,126 ---- > container.insert(container.begin()+from, first, last); > } > else { > + if (to - from == std::distance (first, last)) { > + std::copy (first, last, container.begin()+from); > + } > + else { > container.erase(container.begin()+from, container.begin()+to); > container.insert(container.begin()+from, first, last); > + } > } > } Shouldn't you generalize it? There's no need to do erase + insert. Suppose you're replacing 100 items with 99 or 101 items? If the sizes don't match should either be insert + copy or copy[_backward] + erase (where the erase happens at the end of the container). Some handwaving here, but it should be easy enough to figure out how to make it optimal. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From asutton at cs.kent.edu Fri Aug 20 04:50:40 2004 From: asutton at cs.kent.edu (Andrew Sutton) Date: Thu, 19 Aug 2004 22:50:40 -0400 Subject: [C++-sig] pyste question Message-ID: <200408192250.40615.asutton@cs.kent.edu> hi... pyste noob here. i'm building some python interfaces for a library i've written and i'm trying to make the exposed python classes as "python-friendly" as possible (like nice iteration support). to do this, i'm trying to inject methods into my classes using add_method(). unfortunately, pyste is not finding the methods i'm requesting to be added. it seems to be related to the fact that the methods i'm having pyste add to the class aren't located in the same header file as the class. for example: [list.hpp] class list { ...; } [list_ext.hpp] iterator list_iterator(); [list.pyste] List = Class("list", "list.hpp") ListIterator = Function("list_iterator, "list_iterator.hpp") add_method(List, "list_iterator", "__iter__") or something very similar to that. it seems that the behavior of add_method only looks for methods defined in the file with the class - because this doesn't work with includes or added code either - quite frustrating. am i going about this completely wrong? any help would be appreciated. thanks in advance. andrew sutton asutton at cs.kent.edu From gaiacrtn at free.fr Mon Aug 23 08:54:08 2004 From: gaiacrtn at free.fr (Baptiste Lepilleur) Date: Mon, 23 Aug 2004 08:54:08 +0200 Subject: [C++-sig] pyste question References: <200408192250.40615.asutton@cs.kent.edu> Message-ID: <00c001c488dd$ffa57540$63a8223e@lain> If I remember correctly, you need to add an 'Include' statement with a file that contains the function you are refering to in add_method(). If it fails, you can still fallback in 'class_code' to inject your method definition (you can find some example of this at: http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ). Baptiste. ----- Original Message ----- From: "Andrew Sutton" To: Sent: Friday, August 20, 2004 4:50 AM Subject: [C++-sig] pyste question > hi... pyste noob here. > > i'm building some python interfaces for a library i've written and i'm trying > to make the exposed python classes as "python-friendly" as possible (like > nice iteration support). to do this, i'm trying to inject methods into my > classes using add_method(). unfortunately, pyste is not finding the methods > i'm requesting to be added. it seems to be related to the fact that the > methods i'm having pyste add to the class aren't located in the same header > file as the class. for example: > > [list.hpp] > class list { > ...; > } > > [list_ext.hpp] > iterator list_iterator(); > > [list.pyste] > List = Class("list", "list.hpp") > ListIterator = Function("list_iterator, "list_iterator.hpp") > add_method(List, "list_iterator", "__iter__") > > or something very similar to that. it seems that the behavior of add_method > only looks for methods defined in the file with the class - because this > doesn't work with includes or added code either - quite frustrating. > > am i going about this completely wrong? any help would be appreciated. thanks > in advance. > > andrew sutton > asutton at cs.kent.edu > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From talsit at talsit.org Mon Aug 23 09:06:44 2004 From: talsit at talsit.org (tALSit de CoD) Date: Mon, 23 Aug 2004 17:06:44 +1000 (EST) Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: Message-ID: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> Hmm... i've been trying to understand it, i've read the docs... but... ummm... i can't quite understand it very well... Does this mean that when my class does: const std::vector cRegistry::getDescriptors (); i have to replace that with this: boost::indirect_iterator::iterator> cRegistry::getDescriptors (); Or am i just totally missing the point? Most of the template magic voodoo still baffels me... :D David Abrahams wrote: > "tALSit de CoD" writes: > > >>Hey guys! >>I know this has been answered to some extent before, but I just can't get to grips with it, so i know i'm doing something wrong... >> >>I export the following: >> >>//---------------------------------------------------------------- class_ ("cNodeDescriptor", no_init) >> .def ("getClassId",&cNodeDescriptor::getClassId) >> .def ("getName",&cNodeDescriptor::getName, return_value_policy >> ()) >> ; >> >>//---------------------------------------------------------------- class_ > ("cNodeDescriptorList") >> .def ("__iter__", iterator > ()) ; >> >>And then, in python, i grab a cNodeDescriptorList, and when i try to iterate through it, it spits out: >> >>TypeError: No to_python (by-value) converter found for C++ type: class kikura::cNodeDescriptor * >> >>So... what am i doing wrong? >> >>If more info is needed, i'd be glad to supply it... > > > Try using range > (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) with a functions that return > boost::indirect_iterator::iterator> wrapped around the vector's begin() and end(). > (http://www.boost.org/libs/iterator/doc/indirect_iterator.html) > > HTH, // talsit.org From gaiacrtn at free.fr Mon Aug 23 09:52:41 2004 From: gaiacrtn at free.fr (Baptiste Lepilleur) Date: Mon, 23 Aug 2004 09:52:41 +0200 Subject: [C++-sig] boost.python extract and smart-pointer Message-ID: <00e701c488e6$2b22e7e0$63a8223e@lain> I'm running in some trouble with extract during unpickling of null smart-pointer. I have registered a intrusive_ptr based smart-pointer which works greatly. During pickling, my null smart-pointer converted into None. During unpickling, when I use extract on a null smart-pointer I get a conversion error saying that there is no conversion from NoneType to MyPtrType. Is this a known issue, or did I miss something ? As a work-around I tried to test if tuple[1] was None, but couldn't figure out how to do that in C++. Any tips ? Baptiste. From asutton at cs.kent.edu Mon Aug 23 14:00:40 2004 From: asutton at cs.kent.edu (Andrew Sutton) Date: Mon, 23 Aug 2004 08:00:40 -0400 Subject: [C++-sig] pyste question In-Reply-To: <00c001c488dd$ffa57540$63a8223e@lain> References: <200408192250.40615.asutton@cs.kent.edu> <00c001c488dd$ffa57540$63a8223e@lain> Message-ID: <200408230800.40739.asutton@cs.kent.edu> On Monday 23 August 2004 02:54 am, Baptiste Lepilleur wrote: > If I remember correctly, you need to add an 'Include' statement with a file > that contains the function you are refering to in add_method(). > > If it fails, you can still fallback in 'class_code' to inject your method > definition (you can find some example of this at: > http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ). thanks for the response. unfortunately, i just realized that pyste doesn't quite generate code that's entirely right me (i can't derive some of my classes like that). guess it's back to straight boost.python. thanks again, andrew sutton asutton at cs.kent.edu From dave at boost-consulting.com Mon Aug 23 17:09:53 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 23 Aug 2004 11:09:53 -0400 Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> Message-ID: "tALSit de CoD" writes: > Hmm... i've been trying to understand it, i've read the docs... but... > ummm... i can't quite understand it very well... > > Does this mean that when my class does: > > const std::vector cRegistry::getDescriptors (); > > i have to replace that with this: > > boost::indirect_iterator::iterator> > cRegistry::getDescriptors (); I have no idea what getDescriptors is, so it's hard to comment. > Or am i just totally missing the point? > > Most of the template magic voodoo still baffels me... :D There's no template magic voodoo to understand this. Try using range (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) Do you understand what range does? with functions that return boost::indirect_iterator::iterator> wrapped around the vector's begin() and end(). (http://www.boost.org/libs/iterator/doc/indirect_iterator.html) By this I mean boost::indirect_iterator::iterator> my_begin(std::vector& v) { return boost::make_indirect_iterator(v.begin()); }; boost::indirect_iterator::iterator> my_end(std::vector& v) { return boost::make_indirect_iterator(v.end()); }; so, something like: class_ > ("cNodeDescriptorList") .def("__iter__", range(my_begin, my_end)) ; HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Mon Aug 23 17:12:36 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 23 Aug 2004 11:12:36 -0400 Subject: [C++-sig] Re: boost.python extract and smart-pointer References: <00e701c488e6$2b22e7e0$63a8223e@lain> Message-ID: "Baptiste Lepilleur" writes: > I'm running in some trouble with extract during unpickling of > null smart-pointer. I have registered a intrusive_ptr based ^^^^^^^^^^ Registered how? Please show code. > smart-pointer which works greatly. > > During pickling, my null smart-pointer converted into None. During > unpickling, when I use extract on a null smart-pointer I get a > conversion error saying that there is no conversion from NoneType to > MyPtrType. > > Is this a known issue, or did I miss something ? > > As a work-around I tried to test if tuple[1] was None, but couldn't > figure out how to do that in C++. Any tips ? if (tuple[1].ptr() == object().ptr()) ... -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From talsit at talsit.org Tue Aug 24 04:22:32 2004 From: talsit at talsit.org (tALSit de CoD) Date: Tue, 24 Aug 2004 12:22:32 +1000 (EST) Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: In-Reply-To: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> Message-ID: <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> Thanks David.... I understand it more now, but, from what I've been trying to implement, it still doesnt work. Here's a simplification of the problem: class A { public: const std::string & getName (); private: std::string m_name; }; class B { public: const std::vector & getAs () { return m_listOfA; } private: std::vector m_listOfA; }; Now, i try to export the classes: boost::indirect_iterator ::iterator> ABegin (std::vector & v) { return boost::make_indirect_iterator (v.begin ()); }; boost::indirect_iterator ::iterator> AEnd (std::vector & v) { return boost::make_indirect_iterator (v.end ()); }; BOOST_PYTHON_MODULE (kikura) { class_ ("A") .def ("getName", &A::getName, return_internal_reference <> ()) ; class_ ("B") .def ("getAs", &B::getAs, return_internal_reference <> ()) ; //---------------------------------------------------------------- class_ > ("AList") .def("__iter__", range (ABegin, AEnd)) ; } Now, that will fail, and say that: TypeError: No to_python (by-value) converter found for C++ type: class A If I didn't use the range method, it would give me this: TypeError: No to_python (by-value) converter found for C++ type: class A* Any clues? Thanks for all help... > "tALSit de CoD" writes: > >> Hmm... i've been trying to understand it, i've read the docs... but... >> ummm... i can't quite understand it very well... >> >> Does this mean that when my class does: >> >> const std::vector cRegistry::getDescriptors (); >> >> i have to replace that with this: >> >> boost::indirect_iterator::iterator> >> cRegistry::getDescriptors (); > > I have no idea what getDescriptors is, so it's hard to comment. > >> Or am i just totally missing the point? >> >> Most of the template magic voodoo still baffels me... :D > > There's no template magic voodoo to understand this. > > Try using range > (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) > > Do you understand what range does? > > with functions that return > boost::indirect_iterator::iterator> > wrapped around the vector's begin() and end(). > (http://www.boost.org/libs/iterator/doc/indirect_iterator.html) > > By this I mean > > boost::indirect_iterator::iterator> > my_begin(std::vector& v) > { > return boost::make_indirect_iterator(v.begin()); > }; > > boost::indirect_iterator::iterator> > my_end(std::vector& v) > { > return boost::make_indirect_iterator(v.end()); > }; > > so, something like: > > class_ > ("cNodeDescriptorList") > .def("__iter__", range(my_begin, my_end)) > ; > > > HTH, > > -- > Dave Abrahams > Boost Consulting > http://www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > // talsit.org From talsit at talsit.org Tue Aug 24 07:55:50 2004 From: talsit at talsit.org (tALSit de CoD) Date: Tue, 24 Aug 2004 15:55:50 +1000 (EST) Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: In-Reply-To: <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> Message-ID: <2726.61.29.35.206.1093326950.squirrel@61.29.35.206> I've writen up a complete file that demostraits what i'm trying to do, i've posted it up here: http://talsit.org/image/boost_python_test.cpp Basically, i have an object (class B) that has a std::vector . If i return a reference to that vector, how can i iterate through it. If i do it with the straight iterator method, like i do with other basic data types (unsigned int), it complains about not been able to convert from A *. If i do it with the range method as suggested, it says that it can convert from A. Thing is, I don't know if i'm even doing the range method correctly. Hope this explains my problem better. Thanks a lot in advance > Thanks David.... > > I understand it more now, but, from what I've been trying to implement, it > still doesnt work. > > Here's a simplification of the problem: > > class A { > public: > const std::string & getName (); > private: > std::string m_name; > }; > > class B { > public: > const std::vector & getAs () { return m_listOfA; } > private: > std::vector m_listOfA; > }; > > Now, i try to export the classes: > > boost::indirect_iterator ::iterator> > ABegin (std::vector & v) { > return boost::make_indirect_iterator (v.begin ()); > }; > > boost::indirect_iterator ::iterator> > AEnd (std::vector & v) { > return boost::make_indirect_iterator (v.end ()); > }; > > > BOOST_PYTHON_MODULE (kikura) { > class_ ("A") > .def ("getName", &A::getName, return_internal_reference <> ()) > ; > > class_ ("B") > .def ("getAs", &B::getAs, return_internal_reference <> ()) > ; > > //---------------------------------------------------------------- > class_ > ("AList") > .def("__iter__", range (ABegin, AEnd)) > ; > > } > > Now, that will fail, and say that: > > TypeError: No to_python (by-value) converter found for C++ type: class A > > If I didn't use the range method, it would give me this: > > TypeError: No to_python (by-value) converter found for C++ type: class A* > > Any clues? > > Thanks for all help... > > >> "tALSit de CoD" writes: >> >>> Hmm... i've been trying to understand it, i've read the docs... but... >>> ummm... i can't quite understand it very well... >>> >>> Does this mean that when my class does: >>> >>> const std::vector cRegistry::getDescriptors (); >>> >>> i have to replace that with this: >>> >>> boost::indirect_iterator::iterator> >>> cRegistry::getDescriptors (); >> >> I have no idea what getDescriptors is, so it's hard to comment. >> >>> Or am i just totally missing the point? >>> >>> Most of the template magic voodoo still baffels me... :D >> >> There's no template magic voodoo to understand this. >> >> Try using range >> (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) >> >> Do you understand what range does? >> >> with functions that return >> boost::indirect_iterator::iterator> >> wrapped around the vector's begin() and end(). >> (http://www.boost.org/libs/iterator/doc/indirect_iterator.html) >> >> By this I mean >> >> boost::indirect_iterator::iterator> >> my_begin(std::vector& v) >> { >> return boost::make_indirect_iterator(v.begin()); >> }; >> >> boost::indirect_iterator::iterator> >> my_end(std::vector& v) >> { >> return boost::make_indirect_iterator(v.end()); >> }; >> >> so, something like: >> >> class_ > ("cNodeDescriptorList") >> .def("__iter__", range(my_begin, my_end)) >> ; >> >> >> HTH, >> >> -- >> Dave Abrahams >> Boost Consulting >> http://www.boost-consulting.com >> >> _______________________________________________ >> C++-sig mailing list >> C++-sig at python.org >> http://mail.python.org/mailman/listinfo/c++-sig >> >> > > > // talsit.org > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > // talsit.org From dave at boost-consulting.com Tue Aug 24 09:15:16 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 24 Aug 2004 03:15:16 -0400 Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> <2726.61.29.35.206.1093326950.squirrel@61.29.35.206> Message-ID: "tALSit de CoD" writes: > I've writen up a complete file that demostraits what i'm trying to do, > i've posted it up here: > http://talsit.org/image/boost_python_test.cpp > > Basically, i have an object (class B) that has a std::vector . If i > return a reference to that vector, how can i iterate through it. If i do > it with the straight iterator method, like i do with other basic data > types (unsigned int), it complains about not been able to convert from A > *. If i do it with the range method as suggested, it says that it can > convert from A. Because you wrapped A as noncopyable, it can't copy the A referenced by the iterator into a new Python object. You can fix this by removing the noncopyable, or by using the 2nd form of range, instead of the first: class_ > ("AList") .def("__iter__", range >(ABegin, AEnd)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; > Thing is, I don't know if i'm even doing the range method correctly. You are, but see above. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From talsit at talsit.org Tue Aug 24 10:23:24 2004 From: talsit at talsit.org (tALSit de CoD) Date: Tue, 24 Aug 2004 18:23:24 +1000 (EST) Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: In-Reply-To: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> <2726.61.29.35.206.1093326950.squirrel@61.29.35.206> Message-ID: <4258.61.29.35.206.1093335804.squirrel@61.29.35.206> YES!! Thanks heaps, that solved it perfectly... I have been bashing my head a bit on that one... couldn't quite figure it out. I don't completely comprehend templates, and the wierd and wonderful way that it works... Now, just a quicky: If i have two class methods: class A { public: const std::string & getName () { return m_name; } private: std::string m_name; }; class B { public const A * getA () const { return m_a; } A * getA () { return m_a; } private: A * m_a; }; How do i wrap that method? I need them both there, but when i try to wrap it like this: class_ ("B") .def ("getA", &B::getA, return_internal_reference <> ()) ; It complains quite a lot, since it is an overloaded method. David Abrahams wrote: > "tALSit de CoD" writes: > > >>I've writen up a complete file that demostraits what i'm trying to do, i've posted it up here: >>http://talsit.org/image/boost_python_test.cpp >>Basically, i have an object (class B) that has a std::vector . If i return a reference to that vector, how can i iterate through it. If i do it with the straight iterator method, like i do with other basic data types (unsigned int), it complains about not been able to convert from A *. If i do it with the range method as suggested, it says that it can convert from A. > > > Because you wrapped A as noncopyable, it can't copy the A referenced by the iterator into a new Python object. You can fix this by > removing the noncopyable, or by using the 2nd form of range, instead of the first: > > class_ > ("AList") > .def("__iter__", range >(ABegin, AEnd)) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > ; > > >>Thing is, I don't know if i'm even doing the range method correctly. > > > You are, but see above. > > From dave at boost-consulting.com Tue Aug 24 10:37:39 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 24 Aug 2004 04:37:39 -0400 Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> <2726.61.29.35.206.1093326950.squirrel@61.29.35.206> <4258.61.29.35.206.1093335804.squirrel@61.29.35.206> Message-ID: "tALSit de CoD" writes: > YES!! > Thanks heaps, that solved it perfectly... > I have been bashing my head a bit on that one... couldn't quite figure it > out. I don't completely comprehend templates, and the wierd and wonderful > way that it works... > > Now, just a quicky: > If i have two class methods: > class A { > public: > const std::string & getName () { return m_name; } > private: > std::string m_name; > }; > > class B { > public > const A * getA () const { return m_a; } > A * getA () { return m_a; } > private: > A * m_a; > }; > > How do i wrap that method? I need them both there, but when i try to wrap > it like this: > > > class_ ("B") > .def ("getA", &B::getA, return_internal_reference <> ()) > ; > > It complains quite a lot, since it is an overloaded method. Just wrap one of them; Python doesn't know/care about const. A* (B::*getA)() = &B::getA; class_ ("B") .def ("getA", getA, return_internal_reference <> ()) ; -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From nicodemus at esss.com.br Tue Aug 24 16:01:21 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Tue, 24 Aug 2004 11:01:21 -0300 Subject: [C++-sig] pyste question In-Reply-To: <200408230800.40739.asutton@cs.kent.edu> References: <200408192250.40615.asutton@cs.kent.edu> <00c001c488dd$ffa57540$63a8223e@lain> <200408230800.40739.asutton@cs.kent.edu> Message-ID: <412B4A31.8090802@esss.com.br> Hi Andrew, Andrew Sutton wrote: >On Monday 23 August 2004 02:54 am, Baptiste Lepilleur wrote: > >>If I remember correctly, you need to add an 'Include' statement with a file >>that contains the function you are refering to in add_method(). >> >>If it fails, you can still fallback in 'class_code' to inject your method >>definition (you can find some example of this at: >>http://cvs.sourceforge.net/viewcvs.py/ogre/ogreaddons/pyogre/src/pyogre/ ). >> > >thanks for the response. unfortunately, i just realized that pyste doesn't >quite generate code that's entirely right me (i can't derive some of my >classes like that). guess it's back to straight boost.python. > I guess one alternative would be to create a subclass with the special methods you want, and export that instead of the original class. Regards, Nicodemus. From asutton at cs.kent.edu Tue Aug 24 16:33:46 2004 From: asutton at cs.kent.edu (Andrew Sutton) Date: Tue, 24 Aug 2004 10:33:46 -0400 Subject: [C++-sig] pyste question In-Reply-To: <412B4A31.8090802@esss.com.br> References: <200408192250.40615.asutton@cs.kent.edu> <200408230800.40739.asutton@cs.kent.edu> <412B4A31.8090802@esss.com.br> Message-ID: <200408241033.46902.asutton@cs.kent.edu> > I guess one alternative would be to create a subclass with the special > methods you want, and export that instead of the original class. i don't think work for me. i'm dealing with a situation where objects can be instantiated from both python and the c++ library. what i ended up doing was creating simple C structs to wrap the classes i want and then build the python classes from C functions (no pyste). works nice. by the way, somebody should add some documentation warning users not to do this: Foo *f = new Foo; PyObject *ret = Py_None; if(...) { ret = object(f).ptr(); } return ret; it took me 2 weeks to figure out that the python object was being reclaimed before it was returned. that ends up in some pretty ugly bugs :) thanks for the feedback, andrew sutton asutton at cs.kent.edu From talsit at talsit.org Tue Aug 24 17:04:00 2004 From: talsit at talsit.org (tALSit de CoD) Date: Wed, 25 Aug 2004 01:04:00 +1000 Subject: [C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type: In-Reply-To: References: <1898.61.29.35.206.1093244804.squirrel@61.29.35.206> <2300.61.29.35.206.1093314152.squirrel@61.29.35.206> <2726.61.29.35.206.1093326950.squirrel@61.29.35.206> <4258.61.29.35.206.1093335804.squirrel@61.29.35.206> Message-ID: <412B58E0.5070403@talsit.org> Cheers!! This works really good!! Thanks! David Abrahams wrote: > "tALSit de CoD" writes: > > >>YES!! >>Thanks heaps, that solved it perfectly... >>I have been bashing my head a bit on that one... couldn't quite figure it >>out. I don't completely comprehend templates, and the wierd and wonderful >>way that it works... >> >>Now, just a quicky: >>If i have two class methods: >>class A { >>public: >> const std::string & getName () { return m_name; } >>private: >> std::string m_name; >>}; >> >>class B { >>public >> const A * getA () const { return m_a; } >> A * getA () { return m_a; } >>private: >> A * m_a; >>}; >> >>How do i wrap that method? I need them both there, but when i try to wrap >>it like this: >> >> >>class_ ("B") >> .def ("getA", &B::getA, return_internal_reference <> ()) >>; >> >>It complains quite a lot, since it is an overloaded method. > > > Just wrap one of them; Python doesn't know/care about const. > > A* (B::*getA)() = &B::getA; > > class_ ("B") > .def ("getA", getA, return_internal_reference <> ()) > ; > -- // talsit at talsit.org From caustin at gmail.com Wed Aug 25 00:35:14 2004 From: caustin at gmail.com (Chad Austin) Date: Tue, 24 Aug 2004 17:35:14 -0500 Subject: [C++-sig] Implicitly converting HeldTypes from Derived to Base? Message-ID: <2096514e04082415357b5e80ba@mail.gmail.com> I have a situation like this: // foo.cpp #include #include using namespace boost; using namespace boost::python; class RefCounted { public: RefCounted() { _count = 0; } virtual ~RefCounted() { } int _count; }; void intrusive_ptr_add_ref(RefCounted* ptr) { ++(ptr->_count); } void intrusive_ptr_release(RefCounted* ptr) { if (--(ptr->_count) == 0) { delete ptr; } } class A : public RefCounted { }; class B : public A { }; typedef intrusive_ptr APtr; typedef intrusive_ptr BPtr; void foo(APtr a) { } BOOST_PYTHON_MODULE(foo) { class_("A"); class_ >("B"); def("foo", &foo); // Without implicitly_convertible, foo(B()) fails with: // // Traceback (most recent call last): // File "", line 1, in ? // Boost.Python.ArgumentError: Python argument types in // foo.foo(B) // did not match C++ signature: // foo(boost::intrusive_ptr) implicitly_convertible(); } Is there any way that implicitly_convertible call from the Derived HeldType to the Base HeldType can be made automatic? Thanks, Chad From dave at boost-consulting.com Wed Aug 25 02:15:39 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 24 Aug 2004 20:15:39 -0400 Subject: [C++-sig] Re: Implicitly converting HeldTypes from Derived to Base? References: <2096514e04082415357b5e80ba@mail.gmail.com> Message-ID: Chad Austin writes: > I have a situation like this: > > > > BOOST_PYTHON_MODULE(foo) { > class_("A"); > class_ >("B"); > def("foo", &foo); > > // Without implicitly_convertible, foo(B()) fails with: > // > // Traceback (most recent call last): > // File "", line 1, in ? > // Boost.Python.ArgumentError: Python argument types in > // foo.foo(B) > // did not match C++ signature: > // foo(boost::intrusive_ptr) > implicitly_convertible(); > } > > > > Is there any way that implicitly_convertible call from the Derived > HeldType to the Base HeldType can be made automatic? Not in general. By the time class_ >("B"); is uttered, there's no *compile-time* information linking APtr with A, so there's no way to test for is_convertible ... and you need to test that before you utter implicitly_convertible(). Actually, without knowing about APtr, you can't even say implicitly_convertible(). One possibility would be to extend Boost.Python to allow: class_("A"); class_ >("B"); ^^^^ That would be a kind of shorthand. Another possibility would be to use partial specialization with template template parameters to deduce that BPtr is actually SomeTemplate, and check for implicit convertibility from SomeTemplate to SomeTemplate, and if that succeeds, then you can utter implicitly_convertible,SomeTemplate >(). That would rely on the HeldTypes both being specializations of the same template (admittedly likely) and on the compiler supporting both aforementioned features. The last approach is for all intents and purposes automatic. It's also a fair amount of work to implement. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From jbrandmeyer at earthlink.net Thu Aug 26 03:35:01 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Wed, 25 Aug 2004 21:35:01 -0400 Subject: [C++-sig] Slice tests failing on MSVC 7.1, 8.0 Message-ID: <1093484100.8635.94.camel@illuvatar> According to the automated regression testers here: http://www.meta-comm.com/engineering/boost-regression/developer/python_.html The slice test is failing on MSVC 7.1 and 8.0. First off, do you expect them to pass on these compilers? If so, the problem is that C++ functions that take a boost::python::slice argument raise a Boost.Python.AgumentError when called with a Python-created slice. The errors in the log take the form: ArgumentError: Python argument types in slice_ext.check_slice_get_indicies(slice) did not match C++ signature: check_slice_get_indicies(class boost::python::slice) Any ideas? Thanks, -Jonathan From dave at boost-consulting.com Thu Aug 26 16:12:01 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 26 Aug 2004 10:12:01 -0400 Subject: [C++-sig] Re: Slice tests failing on MSVC 7.1, 8.0 References: <1093484100.8635.94.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > According to the automated regression testers here: > http://www.meta-comm.com/engineering/boost-regression/developer/python_.html > > The slice test is failing on MSVC 7.1 and 8.0. First off, do you expect > them to pass on these compilers? They're your tests, aren't they?? Don't you expect them to pass? > If so, the problem is that C++ functions that take a > boost::python::slice argument raise a Boost.Python.AgumentError when > called with a Python-created slice. > > The errors in the log take the form: > ArgumentError: Python argument types in > slice_ext.check_slice_get_indicies(slice) > did not match C++ signature: > check_slice_get_indicies(class boost::python::slice) > > Any ideas? Did you register a converter that allows Python-created slices to be passed where boost::python::slice is required? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From jbrandmeyer at earthlink.net Fri Aug 27 01:27:31 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Thu, 26 Aug 2004 19:27:31 -0400 Subject: [C++-sig] Re: Slice tests failing on MSVC 7.1, 8.0 In-Reply-To: References: <1093484100.8635.94.camel@illuvatar> Message-ID: <1093562851.15043.33.camel@illuvatar> On Thu, 2004-08-26 at 10:12, David Abrahams wrote: > Jonathan Brandmeyer writes: > > > According to the automated regression testers here: > > http://www.meta-comm.com/engineering/boost-regression/developer/python_.html > > > > The slice test is failing on MSVC 7.1 and 8.0. First off, do you expect > > them to pass on these compilers? > > They're your tests, aren't they?? Don't you expect them to pass? Yes, of course I do. I was hoping someone more familiar with MS's toolchain might be aware of some quirk that would lead to the error I listed below. > > If so, the problem is that C++ functions that take a > > boost::python::slice argument raise a Boost.Python.AgumentError when > > called with a Python-created slice. > > > > The errors in the log take the form: > > ArgumentError: Python argument types in > > slice_ext.check_slice_get_indicies(slice) > > did not match C++ signature: > > check_slice_get_indicies(class boost::python::slice) > > > > Any ideas? > > Did you register a converter that allows Python-created slices to be > passed where boost::python::slice is required? Not explicitly, and maybe not at all. I expected the specialization of object_manager_traits<> to make it Just Work. It seems to be enough with several other platforms and compilers. At any rate, I managed to get the "Visual C++ Toolkit 2003" installed and working on my system and committed a workaround. It turns out that the following test compiles and links fine with MSVC 7.1, but fails at runtime when calling the exported function: #include using namespace boost::python; void accept_slice_arg( const slice ) { return; } BOOST_PYTHON_MODULE(slice_test) { def( "accept_slice_arg", &accept_slice_arg); } The workaround is to add a prototype that does not have the 'const' qualifier in the function argument - just like with MSVC 7.0 and earlier. Is there a reasonable way to make code like the above work for user programs? As far as I can tell, all of the object manager classes are affected. Thanks, -Jonathan From dave at boost-consulting.com Fri Aug 27 02:47:29 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 26 Aug 2004 20:47:29 -0400 Subject: [C++-sig] Re: Slice tests failing on MSVC 7.1, 8.0 References: <1093484100.8635.94.camel@illuvatar> <1093562851.15043.33.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Thu, 2004-08-26 at 10:12, David Abrahams wrote: >> Jonathan Brandmeyer writes: > > At any rate, I managed to get the "Visual C++ Toolkit 2003" installed > and working on my system and committed a workaround. It turns out that > the following test compiles and links fine with MSVC 7.1, but fails at > runtime when calling the exported function: > > #include > using namespace boost::python; > > void accept_slice_arg( const slice ) > { > return; > } > > BOOST_PYTHON_MODULE(slice_test) > { > def( "accept_slice_arg", &accept_slice_arg); > } > > The workaround is to add a prototype that does not have the 'const' > qualifier in the function argument - just like with MSVC 7.0 and > earlier. Yoikes, that's terrible! I thought they fixed that one for vc7.1. Not even for 8.0??? > Is there a reasonable way to make code like the above work for user > programs? As far as I can tell, all of the object manager classes > are affected. I declined to try to work around that compiler bug in the library; I just told people to make sure that the declaration of the function didn't use const (it has no effect there anyway). I don't know how hard it would be to make the library adjust automatically. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From jbrandmeyer at earthlink.net Fri Aug 27 03:03:21 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Thu, 26 Aug 2004 21:03:21 -0400 Subject: [C++-sig] Re: Slice tests failing on MSVC 7.1, 8.0 In-Reply-To: References: <1093484100.8635.94.camel@illuvatar> <1093562851.15043.33.camel@illuvatar> Message-ID: <1093568601.15043.42.camel@illuvatar> On Thu, 2004-08-26 at 20:47, David Abrahams wrote: > Jonathan Brandmeyer writes: > > The workaround is to add a prototype that does not have the 'const' > > qualifier in the function argument - just like with MSVC 7.0 and > > earlier. > > Yoikes, that's terrible! I thought they fixed that one for vc7.1. > Not even for 8.0??? I haven't personally tried with 8.0, but since the error message in the regression report was verbatim identical to the one for 7.1, I think it is broken for 8.0 as well. Intel C++ 7.1 on Windows is "compatable with" this bug, too. -Jonathan From python at cityofdreams.com Sat Aug 28 07:08:12 2004 From: python at cityofdreams.com (Peter) Date: Sat, 28 Aug 2004 01:08:12 -0400 Subject: [C++-sig] How to capture stdout/stderr? Message-ID: Hi, I am trying to capture stdout and stderr from Python using boost.python. I can do it using the Python C API but can't work out the correct way to do it using the boost wrappers. Using the C API I'd do something like: PyObject* pObj = Py_InitModule("stdout", my_methods); PySys_SetObject("stdout", pObj); PySys_SetObject("stderr", pObj); How should I do this with boost? Thanks Peter From python at cityofdreams.com Sat Aug 28 07:08:20 2004 From: python at cityofdreams.com (Peter) Date: Sat, 28 Aug 2004 01:08:20 -0400 Subject: [C++-sig] How to capture stdout/stderr? Message-ID: Hi, I am trying to capture stdout and stderr from Python using boost.python. I can do it using the Python C API but can't work out the correct way to do it using the boost wrappers. Using the C API I'd do something like: PyObject* pObj = Py_InitModule("stdout", my_methods); PySys_SetObject("stdout", pObj); PySys_SetObject("stderr", pObj); How should I do this with boost? Thanks Peter From python at cityofdreams.com Sat Aug 28 07:08:31 2004 From: python at cityofdreams.com (Peter) Date: Sat, 28 Aug 2004 01:08:31 -0400 Subject: [C++-sig] How to capture stdout/stderr? Message-ID: Hi, I am trying to capture stdout and stderr from Python using boost.python. I can do it using the Python C API but can't work out the correct way to do it using the boost wrappers. Using the C API I'd do something like: PyObject* pObj = Py_InitModule("stdout", my_methods); PySys_SetObject("stdout", pObj); PySys_SetObject("stderr", pObj); How should I do this with boost? Thanks Peter From python at cityofdreams.com Sat Aug 28 14:47:43 2004 From: python at cityofdreams.com (Peter) Date: Sat, 28 Aug 2004 08:47:43 -0400 Subject: [C++-sig] Instantiating a Python class from C++? Message-ID: Another question, and I really hope this doesn't get emailed four idnetical times like my last question. My sincere apologies in advance if it does. I have a C++ class with a virtual function that I want overridden in Python. I expose it to Python in the normal way: class_("CPP_Class", no_init) .def("vfunc", &MyClass::func); And in Python the user derives from this class overrides the virtual method, e.g.: class DerivedClass(CPP_Class): def vfunc(self): #do stuff in Python I want to create an instance of "DerivedClass" from C++ and assign it to the base class ptr and then call the overridden Python function via the virtual fn defined in the C++ base class. So my question is; how do I, from C++, create this instance of DerivedClass (assuming I know that the user called it DerivedClass)? Thank you very much for any help, Peter From pierre.barbier at cirad.fr Sat Aug 28 15:03:21 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Sat, 28 Aug 2004 15:03:21 +0200 Subject: [C++-sig] Instantiating a Python class from C++? In-Reply-To: References: Message-ID: <41308299.4060800@cirad.fr> I will suppose you have access to the module namespace containing the derived class. I'll call this "module_namespace". So, you can retrieve the class using Boost.Python very simply : boost::python::object cls = module_namespace["DerivedClass"] And now, you can create the object with : boost::python::object obj = cls(); And to get a pointer to the underlying C++ object : MyClass* cpp_obj = extract(obj); It should work ... Pierre Peter a ?crit : > Another question, and I really hope this doesn't get emailed four > idnetical times like my last question. My sincere apologies in advance > if it does. > > I have a C++ class with a virtual function that I want overridden in > Python. I expose it to Python in the normal way: > > class_("CPP_Class", no_init) > .def("vfunc", &MyClass::func); > > And in Python the user derives from this class overrides the virtual > method, e.g.: > > class DerivedClass(CPP_Class): > def vfunc(self): > #do stuff in Python > > I want to create an instance of "DerivedClass" from C++ and assign it to > the base class ptr and then call the overridden Python function via the > virtual fn defined in the C++ base class. So my question is; how do I, > from C++, create this instance of DerivedClass (assuming I know that the > user called it DerivedClass)? > > Thank you very much for any help, > Peter > > > > > > > _______________________________________________ > 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 bert.peers at chello.be Sat Aug 28 15:01:41 2004 From: bert.peers at chello.be (Bert Peers) Date: Sat, 28 Aug 2004 15:01:41 +0200 Subject: [C++-sig] How to capture stdout/stderr? In-Reply-To: Message-ID: <5.1.0.14.0.20040828145255.01323f58@mail.chello.be> At 01:08 28/08/2004 -0400, you wrote: >Hi, > >I am trying to capture stdout and stderr from Python using boost.python. Here is my, considerably low-tech, code : At init time, ----------- const std::string CatchOutput = "class StdoutCatcher:\n" "\tdef __init__(self):\n" "\t\tself.data = ''\n" "\tdef write(self, stuff):\n" "\t\tself.data = self.data + stuff\n" "\n" "import sys\n" "TheStdoutCatcher = StdoutCatcher()\n" "sys.stdout = TheStdoutCatcher\n"; Run (CatchOutput); // thin wrapper to run a snippet ----------- and then after some python code has run : ----------- using namespace boost::python; object Catcher (main_namespace ["TheStdoutCatcher"]); object CatcherData (borrowed (PyObject_GetAttrString (Catcher.ptr (), "data"))); const std::string &S = extract(CatcherData); Output += S; // some log string Run ("sys.stdout.data=''\n"); ----------- Note I'm pretty new at this, so the only warranty is "the above didn't crash so far" :) Now that I paste it, I'm not sure about that const ref to the result of extract. hth, bert From python at cityofdreams.com Sat Aug 28 16:33:47 2004 From: python at cityofdreams.com (Peter) Date: Sat, 28 Aug 2004 10:33:47 -0400 Subject: [C++-sig] Instantiating a Python class from C++? Message-ID: That worked wonderfully, thank you. I did have to make a small change to accomadate VC++ 6: module_namespace["DerivedClass"] changed to module_namespace.get("DerivedClass") > I will suppose you have access to the module namespace containing the > derived class. I'll call this "module_namespace". So, you can retrieve > the class using Boost.Python very simply : > > boost::python::object cls = module_namespace["DerivedClass"] > > And now, you can create the object with : > > boost::python::object obj = cls(); > > And to get a pointer to the underlying C++ object : > > MyClass* cpp_obj = extract(obj); > > It should work ... > > Pierre > > Peter a ?crit : > > Another question, and I really hope this doesn't get emailed four > > idnetical times like my last question. My sincere apologies in advance > > if it does. > > > > I have a C++ class with a virtual function that I want overridden in > > Python. I expose it to Python in the normal way: > > > > class_("CPP_Class", no_init) > > .def("vfunc", &MyClass::func); > > > > And in Python the user derives from this class overrides the virtual > > method, e.g.: > > > > class DerivedClass(CPP_Class): > > def vfunc(self): > > #do stuff in Python > > > > I want to create an instance of "DerivedClass" from C++ and assign it to > > the base class ptr and then call the overridden Python function via the > > virtual fn defined in the C++ base class. So my question is; how do I, > > from C++, create this instance of DerivedClass (assuming I know that the > > user called it DerivedClass)? > > > > Thank you very much for any help, > > Peter > > > > > > > > > > > > > > _______________________________________________ > > 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 > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From Benjamin.Golinvaux at euresys.com Sat Aug 28 23:47:51 2004 From: Benjamin.Golinvaux at euresys.com (Benjamin Golinvaux) Date: Sat, 28 Aug 2004 23:47:51 +0200 Subject: [C++-sig] CXX : getting a C++ object Message-ID: Hello I would like to wrap a small C++ library using CXX. I would like to know how I can extract the C++ instance from a PyObject passed to a function. Can I assume, after a correct type check, that I can safely downcast the PyObject ? (or using dynamic_cast ?) If I can't (or don't want to) use dynamic_cast , what could then be the best way to test that a PyObject is actually from a wrapped C++ "python type" class ? (sorry I'm a beginner in the Python C API) Thanks for your help Benjamin Golinvaux -------------------------------------------------------- The information contained in this message or any of its attachments may be privileged and confidential and intended for the exclusive use of the addressee. If you are not the addressee any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited. If you have received this transmission by error please notify the sender immediately and then delete this email. EURESYS shall not be liable for any loss of or damage to revenues, profits, goodwill, data, information systems or other special, incidental, indirect, consequential or punitive damages of any kind arising in connection with the use of information contained in this mail or its attachments. Email transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore is in no way liable for any errors or omissions in the content of this message, which may arise as a result of email transmission. If verification is required, please request a hard copy. Please note that neither EURESYS, nor the sender accepts any responsibility for viruses and it is your responsibility to scan attachments (if any). -------------------------------------------------------- From Benjamin.Golinvaux at euresys.com Sun Aug 29 00:40:22 2004 From: Benjamin.Golinvaux at euresys.com (Benjamin Golinvaux) Date: Sun, 29 Aug 2004 00:40:22 +0200 Subject: [C++-sig] CXX : getting a C++ object Message-ID: I have found the solution to my problem. The base class of the user-defined c++ python extension type provides a static bool check( PyObject* ) method that checks whether the object is of its kind. // somewhere : class MyExtensionType : public Py::PythonExtension { ... } //somewhere else Object someFunctionExposedToPython(const Tuple &a) { Object o = a[0]; if(MyExtensionType::check(o.ptr())) { MyExtensionType* cppObj = static_cast(cppObj); // do something with cppObj } else { // it's not a MyExtensionType*, do something else } } (of course this isn't needed for MyExtensionType methods where "this" is automatically set correctly) this is exactly what i needed. hope this can help someone else (although it seems everyone here uses boost :) Benjamin -----Message d'origine----- De : c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] De la part de Benjamin Golinvaux Envoy? : Saturday, August 28, 2004 11:48 PM ? : Development of Python/C++ integration Objet : [C++-sig] CXX : getting a C++ object Hello I would like to wrap a small C++ library using CXX. I would like to know how I can extract the C++ instance from a PyObject passed to a function. Can I assume, after a correct type check, that I can safely downcast the PyObject ? (or using dynamic_cast ?) If I can't (or don't want to) use dynamic_cast , what could then be the best way to test that a PyObject is actually from a wrapped C++ "python type" class ? (sorry I'm a beginner in the Python C API) Thanks for your help Benjamin Golinvaux -------------------------------------------------------- The information contained in this message or any of its attachments may be privileged and confidential and intended for the exclusive use of the addressee. If you are not the addressee any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited. If you have received this transmission by error please notify the sender immediately and then delete this email. EURESYS shall not be liable for any loss of or damage to revenues, profits, goodwill, data, information systems or other special, incidental, indirect, consequential or punitive damages of any kind arising in connection with the use of information contained in this mail or its attachments. Email transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore is in no way liable for any errors or omissions in the content of this message, which may arise as a result of email transmission. If verification is required, please request a hard copy. Please note that neither EURESYS, nor the sender accepts any responsibility for viruses and it is your responsibility to scan attachments (if any). -------------------------------------------------------- _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------------------------------------------------- The information contained in this message or any of its attachments may be privileged and confidential and intended for the exclusive use of the addressee. If you are not the addressee any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited. If you have received this transmission by error please notify the sender immediately and then delete this email. EURESYS shall not be liable for any loss of or damage to revenues, profits, goodwill, data, information systems or other special, incidental, indirect, consequential or punitive damages of any kind arising in connection with the use of information contained in this mail or its attachments. Email transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore is in no way liable for any errors or omissions in the content of this message, which may arise as a result of email transmission. If verification is required, please request a hard copy. Please note that neither EURESYS, nor the sender accepts any responsibility for viruses and it is your responsibility to scan attachments (if any). -------------------------------------------------------- From python at cityofdreams.com Sun Aug 29 14:21:07 2004 From: python at cityofdreams.com (Peter) Date: Sun, 29 Aug 2004 08:21:07 -0400 Subject: [C++-sig] How to capture stdout/stderr? Message-ID: Thanks Bert, that put on hopefully the right track to do the same thing in C++. I can almost do it completely, and I'll detail the code in another email. Thanks, Peter > > Here is my, considerably low-tech, code : > > At init time, > > ----------- > const std::string CatchOutput = > "class StdoutCatcher:\n" > "\tdef __init__(self):\n" > "\t\tself.data = ''\n" > "\tdef write(self, stuff):\n" > "\t\tself.data = self.data + stuff\n" > "\n" > "import sys\n" > "TheStdoutCatcher = StdoutCatcher()\n" > "sys.stdout = TheStdoutCatcher\n"; > > Run (CatchOutput); // thin wrapper to run a snippet > ----------- > > and then after some python code has run : > > ----------- > using namespace boost::python; > object Catcher (main_namespace ["TheStdoutCatcher"]); > object CatcherData (borrowed (PyObject_GetAttrString (Catcher.ptr (), > "data"))); > > const std::string &S = extract(CatcherData); > Output += S; // some log string > Run ("sys.stdout.data=''\n"); > ----------- > > Note I'm pretty new at this, so the only warranty is > "the above didn't crash so far" :) Now that I paste > it, I'm not sure about that const ref to the result of > extract. > > > hth, > bert > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From python at cityofdreams.com Sun Aug 29 14:51:56 2004 From: python at cityofdreams.com (Peter) Date: Sun, 29 Aug 2004 08:51:56 -0400 Subject: [C++-sig] PyImport_Import problems with a BOOST_PYTHON_MODULE defined module Message-ID: Thanks to some previous answers plus some intense googling, I've been able to use a C++ class to capture stdout and stderr. However, I have encountered a problem with PyImport_Import and a module defined with BOOST_PYTHON_MODULE. I created a StdoutCatcher C++ class (in a module named RuntimeSupport) and have got to the point where I can use it from within Python ok: >>> import sys, RuntimeSupport >>> sys.stdout = RuntimeSupport.StdoutCatcher() >>> sys.stderr = RuntimeSupport.StdoutCatcher() But my goal is to redirect stdout purely using the C APIs, but I still have much to learn and have hit a bit of a wall after experimenting all day. I found that PyImport_Import should accomplish what I want, but for all my experimenting I just can't get it to work. Below is the code and it would be great if anyone could critique my use of boost.python and the Python C API, and point out where I have gone wrong. All criticism would be very much appreciated. Building with MS VC++ 6 on w2k, using Python embedded in the app. //********************************************************* class StdoutCatcher { public: StdoutCatcher() { clear(); } void write( const std::string& str ) { text_ += str; } static const std::string& text(void) { return text_; } static void clear(void) { text_.erase(); } private: static std::string text_; }; std::string StdoutCatcher::text_; //********************************************************* // Python module BOOST_PYTHON_MODULE(RuntimeSupport) { class_("StdoutCatcher") .def( "write", &StdoutCatcher::write ) ; } ... initialize everything ... PyImport_AppendInittab("RuntimeSupport", initRuntimeSupport); Py_Initialize(); mainModule_ = new object(handle<>(borrowed( PyImport_AddModule("__main__") ) ) ); mainNamespace_ = new dict(mainModule_->attr("__dict__") ); ... everything now works ok if just using Python ... but I can't get it to work using just API calls, ... see below // import the RuntimeSupport module // --> I tried all import ways; // PyImport_ImportModuleEx, PyImport_Import, // PyImport_ImportModule boost::python::str supportModuleName("RuntimeSupport"); handle<> supportModule( PyImport_Import(supportModuleName.ptr()) ); // create an instance of StdoutCatcher // --> this bit doesn't work and returns NoneType // --> maybe because PyImport failed? object catcher = mainNamespace_->get("StdoutCatcher"); // --> is there a better way to check for NoneType // than a strcmp? PyObject* pObj = catcher.ptr(); if ( strcmp(pObj->ob_type->tp_name, "NoneType") == 0) { // ... why isn't StdoutCatcher being found? } else { // --> never get to this bit // create an instance of StdoutCatcher object catcherObj = catcher(); // set sys.stdout and sys.stderr to the // StdoutCatcher instance PySys_SetObject("stdout",catcherObj.ptr()); PySys_SetObject("stderr",catcherObj.ptr()); } ... so the main question is, why can't I import StdoutCatcher using the APIs? Thanks, Peter From kaben.nanlohy at gmail.com Mon Aug 30 18:21:00 2004 From: kaben.nanlohy at gmail.com (Kaben Nanlohy) Date: Mon, 30 Aug 2004 12:21:00 -0400 Subject: [C++-sig] Pyste docstring support ? Message-ID: <8da04e6704083009213834fbbd@mail.gmail.com> Hi; On this mailing list I have seen a patch to Boost.Python's Pyste providing some docstring support, but the patch does not appear to have been incorporated into cvs. Why is that ? Thanks -- K -- to contact me, use gmail.00 at kaben.stochastic.net to contact me without your email entering my gmail archive, use no.gmail.00 at kaben.stochastic.net From ndbecker2 at verizon.net Tue Aug 31 16:57:12 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Tue, 31 Aug 2004 10:57:12 -0400 Subject: [C++-sig] ublas vector based arithmetic Message-ID: Recently I proposed using std::vector for arithmetic. Since then it was suggested to look at ublas. I think this is a good idea for my requirements. The intended application is 1) signal processinging/communications 2) vectors of int, double, complex 3) python for high level control to interface to c++ algorithms 4) c++ algorithms operate on relatively large vectors of data, so that overheads of python/c++ conversion are relatively unimportant. I agree that ublas would be a useful base, because the C++ algorithm side could be able to take advantage of the performance features, such as ET. I have gotten an implementation working, based mostly on Pylinear-0.9 from Andreas Kloeckner,ak at ixion.net, http://pylinear.sf.net. My version is much smaller, simpler and without all the dependencies, but only handles vectors (not matrices). It adds some convenience features, like constructing vectors from tuples/lists. If there is interest I can post.