From dave at boost-consulting.com Sat Oct 1 01:01:42 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 30 Sep 2005 19:01:42 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <433DB20E.3205.577B33@localhost> Message-ID: "Niall Douglas" writes: > On 30 Sep 2005 at 7:49, David Abrahams wrote: > >> No, all the tests passed for vc7.1 upon release of 1.33.0, so it's >> surprising to see a problem here. Do you have any idea what T is in >> this case? A full instantiation backtrace might help. > > Here's the testcase: > > #include "boost/python.hpp" > > using namespace boost::python; > > typedef void *FXID; > > class FXWindow > { > public: > void attach(FXID w) { } > }; > > int main(void) > { > class_("FXWindow") > .def("attach", &FXWindow::attach); > return 0; > } > > This compiles on v1.32 but not v1.33. Here's the compiler error: You yourself said that void* isn't supported: http://www.boost.org/libs/python/doc/v2/faq.html#voidptr Are you sure that this change is portable, or is it just exploiting a vc7.1 bugfeature? -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Sat Oct 1 01:58:39 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 01 Oct 2005 00:58:39 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <433DDF3F.28774.1080163@localhost> On 30 Sep 2005 at 19:01, David Abrahams wrote: > You yourself said that void* isn't supported: It's only unsupported because BPL hasn't been coded to support it. One can specialise for the void type after all, it's just a rather unique integral type. > http://www.boost.org/libs/python/doc/v2/faq.html#voidptr > > Are you sure that this change is portable, or is it just exploiting a > vc7.1 bugfeature? As the test case I posted illustrates, I am using no dodgy casting whatsoever. This is simply a case where MSVC7.1 isn't able to deduce from a void& return type, probably because void& can't exist and type_traits::add_reference<> somehow bypasses MSVC's sanity check for this. The question now becomes how to work around it. Here are my solutions: 1. The best solution is to patch type_traits::add_reference<> with a specialisation for void whereby it won't ever add a reference to a void. AFAIK it's an illegal type anyway. While you're at it, patch type_traits::add_cv<> to never add const volatile to void either as that also never makes sense. 2. The other solution is to replace registered.hpp with what I have attached. I particularly dislike the "const volatile void" template specialisation :( Cheers, Niall -------------- next part -------------- // Copyright David Abrahams 2002. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef REGISTERED_DWA2002710_HPP # define REGISTERED_DWA2002710_HPP # include # include # include # include # include # include namespace boost { // You'll see shared_ptr mentioned in this header because we need to // note which types are shared_ptrs in their registrations, to // implement special shared_ptr handling for rvalue conversions. template class shared_ptr; namespace python { namespace converter { struct registration; namespace detail { template struct registered_base { static registration const& converters; }; } template struct registered : detail::registered_base< typename add_reference< typename add_cv::type >::type > { }; # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) // collapses a few more types to the same static instance. MSVC7.1 // fails to strip cv-qualification from array types in typeid. For // some reason we can't use this collapse there or array converters // will not be found. template struct registered : registered {}; # endif // // implementations // namespace detail { inline void register_shared_ptr0(...) { } template inline void register_shared_ptr0(shared_ptr*) { registry::lookup_shared_ptr(type_id >()); } template inline void register_shared_ptr1(T const volatile*) { detail::register_shared_ptr0((T*)0); } template registration const& registry_lookup() { detail::register_shared_ptr1((T*)0); return registry::lookup(type_id()); } template <> registration const& registry_lookup() { detail::register_shared_ptr1((void*)0); return registry::lookup(type_id()); } template registration const& registered_base::converters = detail::registry_lookup::type>(); } }}} // namespace boost::python::converter #endif // REGISTERED_DWA2002710_HPP From amohr at cs.wisc.edu Tue Oct 4 19:55:25 2005 From: amohr at cs.wisc.edu (Alex Mohr) Date: Tue, 04 Oct 2005 10:55:25 -0700 Subject: [C++-sig] Getting a Python type object for a c++ type in wrapper code... Message-ID: <4342C20D.5030709@cs.wisc.edu> Hi folks, I'm a relative boost.python newbie but I've been doing a ton with it and I'm having a blast. Thanks for such an awesome package. Here's my first newbie question. Suppose I have two C++ classes that I'm wrapping -- Foo and Bar. In the wrapper for Bar, I want there to be an attribute which holds the type Foo. That is, from python I wan to be able to say: >>> Module.Bar.fooType == Module.Foo True Something like def_readonly("fooType", ) would be ideal. I'd also like to be able to do this for python types, like python's float. Is there a simple way to do this in my Boost.Python code? Thanks, Alex From nick at ilm.com Tue Oct 4 20:53:42 2005 From: nick at ilm.com (Nick Rasmussen) Date: Tue, 4 Oct 2005 11:53:42 -0700 Subject: [C++-sig] Getting a Python type object for a c++ type in wrapper code... In-Reply-To: <4342C20D.5030709@cs.wisc.edu> References: <4342C20D.5030709@cs.wisc.edu> Message-ID: <20051004185342.GA22288@vortex.lucasfilm.com> Perhaps something like: #include #include using namespace boost::python; struct Foo { }; struct Bar { static object fooType; }; object Bar::fooType; BOOST_PYTHON_MODULE(test) { class_ fooType("Foo"); Bar::fooType = fooType; class_ barType("Bar"); barType .def_readonly("fooType",&Bar::fooType); } -nick On Tue, 04 Oct 2005, Alex Mohr wrote: > Hi folks, > > I'm a relative boost.python newbie but I've been doing a ton with it and > I'm having a blast. Thanks for such an awesome package. > > Here's my first newbie question. > > Suppose I have two C++ classes that I'm wrapping -- Foo and Bar. In the > wrapper for Bar, I want there to be an attribute which holds the type > Foo. That is, from python I wan to be able to say: > > >>> Module.Bar.fooType == Module.Foo > True > > Something like def_readonly("fooType", ) > would be ideal. I'd also like to be able to do this for python types, > like python's float. Is there a simple way to do this in my > Boost.Python code? > > Thanks, > > Alex > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From mrovner at propel.com Tue Oct 4 20:47:27 2005 From: mrovner at propel.com (Mike Rovner) Date: Tue, 04 Oct 2005 11:47:27 -0700 Subject: [C++-sig] Getting a Python type object for a c++ type in wrapper code... In-Reply-To: <4342C20D.5030709@cs.wisc.edu> References: <4342C20D.5030709@cs.wisc.edu> Message-ID: Alex Mohr wrote: > Something like def_readonly("fooType", ) > would be ideal. I'd also like to be able to do this for python types, > like python's float. Is there a simple way to do this in my > Boost.Python code? object foo_type = class_("Foo") /*.defs*/ ; scope().attr("fooType") = foo_type; HTH, Mike From amohr at pixar.com Tue Oct 4 21:21:57 2005 From: amohr at pixar.com (Alex Mohr) Date: Tue, 04 Oct 2005 12:21:57 -0700 Subject: [C++-sig] Getting a Python type object for a c++ type in wrapper code... In-Reply-To: <20051004185342.GA22288@vortex.lucasfilm.com> References: <4342C20D.5030709@cs.wisc.edu> <20051004185342.GA22288@vortex.lucasfilm.com> Message-ID: <4342D655.4020008@pixar.com> Of course! That makes perfect sense. Thanks Nick and Mike. The only remaining question is if there's an easy way to do this with types like python's 'float' type instead of my own. Would I have to create something like boost::python::long_ for floats, or is there a better way? Thanks again, Alex Nick Rasmussen wrote: > Perhaps something like: > > #include > #include > > using namespace boost::python; > > struct Foo { > > }; > > struct Bar { > static object fooType; > }; > > object Bar::fooType; > > BOOST_PYTHON_MODULE(test) > { > class_ fooType("Foo"); > Bar::fooType = fooType; > class_ barType("Bar"); > barType > .def_readonly("fooType",&Bar::fooType); > } > > -nick > > > On Tue, 04 Oct 2005, Alex Mohr wrote: > > >>Hi folks, >> >>I'm a relative boost.python newbie but I've been doing a ton with it and >>I'm having a blast. Thanks for such an awesome package. >> >>Here's my first newbie question. >> >>Suppose I have two C++ classes that I'm wrapping -- Foo and Bar. In the >>wrapper for Bar, I want there to be an attribute which holds the type >>Foo. That is, from python I wan to be able to say: >> >> >>> Module.Bar.fooType == Module.Foo >>True >> >>Something like def_readonly("fooType", ) >>would be ideal. I'd also like to be able to do this for python types, >>like python's float. Is there a simple way to do this in my >>Boost.Python code? >> >>Thanks, >> >>Alex >> >>_______________________________________________ >>C++-sig mailing list >>C++-sig at python.org >>http://mail.python.org/mailman/listinfo/c++-sig > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From nick at ilm.com Tue Oct 4 22:13:09 2005 From: nick at ilm.com (Nick Rasmussen) Date: Tue, 4 Oct 2005 13:13:09 -0700 Subject: [C++-sig] Getting a Python type object for a c++ type in wrapper code... In-Reply-To: <4342D655.4020008@pixar.com> References: <4342C20D.5030709@cs.wisc.edu> <20051004185342.GA22288@vortex.lucasfilm.com> <4342D655.4020008@pixar.com> Message-ID: <20051004201309.GE22288@vortex.lucasfilm.com> object(handle<>(borrowed(&PyFloat_Type)))? not sure if there's a more boost-ish way of doing it... -nick On Tue, 04 Oct 2005, Alex Mohr wrote: > Of course! That makes perfect sense. Thanks Nick and Mike. > > The only remaining question is if there's an easy way to do this with > types like python's 'float' type instead of my own. Would I have to > create something like boost::python::long_ for floats, or is there a > better way? > > Thanks again, > > Alex > > > Nick Rasmussen wrote: > > Perhaps something like: > > > > #include > > #include > > > > using namespace boost::python; > > > > struct Foo { > > > > }; > > > > struct Bar { > > static object fooType; > > }; > > > > object Bar::fooType; > > > > BOOST_PYTHON_MODULE(test) > > { > > class_ fooType("Foo"); > > Bar::fooType = fooType; > > class_ barType("Bar"); > > barType > > .def_readonly("fooType",&Bar::fooType); > > } > > > > -nick > > > > > > On Tue, 04 Oct 2005, Alex Mohr wrote: > > > > > >>Hi folks, > >> > >>I'm a relative boost.python newbie but I've been doing a ton with it and > >>I'm having a blast. Thanks for such an awesome package. > >> > >>Here's my first newbie question. > >> > >>Suppose I have two C++ classes that I'm wrapping -- Foo and Bar. In the > >>wrapper for Bar, I want there to be an attribute which holds the type > >>Foo. That is, from python I wan to be able to say: > >> > >> >>> Module.Bar.fooType == Module.Foo > >>True > >> > >>Something like def_readonly("fooType", ) > >>would be ideal. I'd also like to be able to do this for python types, > >>like python's float. Is there a simple way to do this in my > >>Boost.Python code? > >> > >>Thanks, > >> > >>Alex > >> > >>_______________________________________________ > >>C++-sig mailing list > >>C++-sig at python.org > >>http://mail.python.org/mailman/listinfo/c++-sig > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From roman.yakovenko at gmail.com Thu Oct 6 07:29:55 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 6 Oct 2005 08:29:55 +0300 Subject: [C++-sig] small operators bug Message-ID: <7465b6170510052229l2f6eff9dv17eb4cfaf8fb82db@mail.gmail.com> Hi. I think I found bug in boost.python operators treatment. Consider next code: C++ code: template< typename derived_type, typename value_type > struct number{ value_type value; derived_type operator+( const derived_type& x ){ derived_type tmp; tmp.value = value + x.value; return tmp; } }; struct integral : public number< integral, int >{ integral operator+( int x ){ integral tmp; tmp.value = value + x; return tmp; } }; BOOST_PYTHON_MODULE(dummy){ bp::class_< number >( "number" ) .def( bp::self + bp::other< integral >() ) .def_readwrite( "value", &number::value ); bp::class_< integral, bp::bases< number > >( "integral" ) .def( bp::self + bp::other< int >() ); } Python code: i = dummy.integral() i.value = 25 j = i + i The last python statement raises exception: unsupported operand type(s) for +: 'integral' and 'integral' If I remove this line ".def( bp::self + bp::other< int >() );", then all works as expected. Thanks Roman Yakovenko From dave at boost-consulting.com Thu Oct 6 15:09:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 06 Oct 2005 09:09:54 -0400 Subject: [C++-sig] small operators bug References: <7465b6170510052229l2f6eff9dv17eb4cfaf8fb82db@mail.gmail.com> Message-ID: Roman Yakovenko writes: > Hi. I think I found bug in boost.python operators treatment. > Consider next code: > > C++ code: > > The last python statement raises exception: > unsupported operand type(s) for +: 'integral' and 'integral' > > If I remove this line ".def( bp::self + bp::other< int >() );", > then all works as expected. It's not a bug. The behavior matches the usual function hiding behavior in C++ derived classes, and, I believe, it also matches the behavior of regular Python classes. -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Thu Oct 6 15:46:44 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 6 Oct 2005 16:46:44 +0300 Subject: [C++-sig] small operators bug In-Reply-To: References: <7465b6170510052229l2f6eff9dv17eb4cfaf8fb82db@mail.gmail.com> Message-ID: <7465b6170510060646p3c6e78c1x7184d4983c9ff6f1@mail.gmail.com> On 10/6/05, David Abrahams wrote: > Roman Yakovenko writes: > > It's not a bug. The behavior matches the usual function hiding > behavior in C++ derived classes, and, I believe, it also matches the > behavior of regular Python classes. You are right. I introduce the wrong use case. What I tried to introduce is next use case: ( taken from http://boost.org/libs/utility/operators.htm tutorials ) class MyInt : public boost::operators {...}; And in this case I can write, I think, MyInt x, y; MyInt z = x + y; I tried to export class similar to MyInt, but failed. I will try to bring correct use case. Any way if you understand what I talked about, could you explain how this functionality ( overloading operators ) should be exported? Thanks > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com Roman Yakovenko From mjkeyes at sbcglobal.net Thu Oct 6 15:33:00 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Thu, 6 Oct 2005 08:33:00 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost and Python Using Derived Classes Message-ID: Hey all, i'm trying to create an application that both embeds and extends python through boost. i've got a rough framework up and running, but now that i'm finally to the python part i'm having troubles. Please know that i'm a noob to boost and to boost.python, so if you see any obvious noob idiocies in my code please point them out (we've all got to start learning somewhere :)). Here's a rough run-down of my code: Base class (pure): template InputHandler { public: /*...*/ virtual void Enter(commandtype *pOutput) = 0; }; Derived class: class PythonInputHandler : public InputHandler { public: PythonInputHandler(PyObject *pSelf) : m_pSelf(pSelf) {} PythonInputHandler(const PythonInputHandler &rhs) : InputHandler(rhs) //doesn't really do anything , m_pSelf(rhs.m_pSelf) { if(m_pSelf) Py_XINCREF(m_pSelf); } virtual ~PythonInputHandler() {Py_XDECREF(m_pSelf);} //overriden pure function: virtual void Enter(std::string *pOutput) { //this is where the nasty heap crash comes in, more below *pOutput = call_method(m_pSelf, "Enter"); } } BOOST_PYTHON_MODULE(PyInputHandler) { class_, PythonInputHandler, boost::noncopyable>("PythonInputHandler"); } Now, when the executable runs, this happens: if( PyImport_AppendInittab( "PyInputHandler", initPyInputHandler ) == -1 ) throw runtime_error("blah"); Py_Initialize(); PyObject *pInit = PyImport_ImportModule("Python.MyTest"); if(pInit == NULL) //...error handling PythonInputHandler *pHandler = new PythonInputHandler(call_method(pInit, "CreateInputHandler")); std::string sTest; pHandler->Enter(&sTest); //big heap crash Py_XDECREF(pInit); /*...*/ Here is the Python code: from PyInputHandler import * class PyLogonHandler(PythonInputHandler): def Enter(Output): return "Welcome from Python!" def CreateInitialHandler(): return PyLogonHandler() Now then, if i change "Welcome from Python!" to a shorter string, like "Hiya!", then it works, no error. As it stands, i get a _BLOCK_TYPE_IS_VALID error in what looks like the destructor of the std::string during the *pOutput = call_method... portion of the code (i'm assuming the destructor before the assignment to pOutput occurs). However, in the destructor, i do see the data consisting of "Welcome from Python!" Now i'm also a complete noob to boost and python. i've only been working on this for about 5 hours or so (the python side of things at any rate), so any tips to improve what i'm doing in addition to helping with this error is greatly appreciated. i'm finding it difficult to find some boost.python tutorials that are comprehensive enough. If you can't tell, i'm trying to expose a version of my InputHandler class to python so that it can be overriden and created from scripts instead of being hard-coded into the C++. Thanks for the help!!!! From dave at boost-consulting.com Thu Oct 6 17:53:57 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 06 Oct 2005 11:53:57 -0400 Subject: [C++-sig] small operators bug References: <7465b6170510052229l2f6eff9dv17eb4cfaf8fb82db@mail.gmail.com> <7465b6170510060646p3c6e78c1x7184d4983c9ff6f1@mail.gmail.com> Message-ID: Roman Yakovenko writes: > I tried to export class similar to MyInt, but failed. I will try to > bring correct use case. > Any way if you understand what I talked about, could you explain how > this functionality > ( overloading operators ) should be exported? Put all the overloads in the same class. Functions in a derived class hide all those with the same name in a base class, regardless of signature. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Thu Oct 6 21:29:13 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Thu, 6 Oct 2005 14:29:13 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost and Python UsingDerived Classes References: Message-ID: Just a quick note... if i switch the Enter function in the PythonInputHandler to: virtual void Enter(std::string *pOutput) { PyObject *pObject = PyObject_CallMethod(m_pSelf, "Enter", NULL); *pOutput = PyString_AsString(pObject); Py_XDECREF(pObject); } Everything works hunky-dory. Evidentally, it is something to do with the boost stuff (i think) which means i've got something wrong. Any help is appreciated. "Matt" wrote in message news:di3997$hfu$1 at sea.gmane.org... > Hey all, > > i'm trying to create an application that both embeds and extends python > through boost. i've got a rough framework up and running, but now that > i'm finally to the python part i'm having troubles. Please know that i'm > a > noob to boost and to boost.python, so if you see any obvious noob > idiocies in my code please point them out (we've all got to start learning > somewhere :)). > > Here's a rough run-down of my code: > > Base class (pure): > > template > InputHandler > { > public: > /*...*/ > virtual void Enter(commandtype *pOutput) = 0; > }; > > Derived class: > class PythonInputHandler : public InputHandler > { > public: > PythonInputHandler(PyObject *pSelf) : m_pSelf(pSelf) {} > PythonInputHandler(const PythonInputHandler &rhs) > : InputHandler(rhs) //doesn't really do anything > , m_pSelf(rhs.m_pSelf) > { > if(m_pSelf) > Py_XINCREF(m_pSelf); > } > virtual ~PythonInputHandler() {Py_XDECREF(m_pSelf);} > > //overriden pure function: > virtual void Enter(std::string *pOutput) > { > //this is where the nasty heap crash comes in, more below > *pOutput = call_method(m_pSelf, "Enter"); > } > } > > BOOST_PYTHON_MODULE(PyInputHandler) > { > class_, PythonInputHandler, > boost::noncopyable>("PythonInputHandler"); > } > > Now, when the executable runs, this happens: > if( PyImport_AppendInittab( "PyInputHandler", initPyInputHandler ) == > -1 ) > throw runtime_error("blah"); > > Py_Initialize(); > > PyObject *pInit = PyImport_ImportModule("Python.MyTest"); > if(pInit == NULL) > //...error handling > > PythonInputHandler *pHandler = new > PythonInputHandler(call_method(pInit, > "CreateInputHandler")); > > std::string sTest; > pHandler->Enter(&sTest); //big heap crash > > Py_XDECREF(pInit); > /*...*/ > > Here is the Python code: > from PyInputHandler import * > > class PyLogonHandler(PythonInputHandler): > def Enter(Output): > return "Welcome from Python!" > > def CreateInitialHandler(): > return PyLogonHandler() > > Now then, if i change "Welcome from Python!" to a shorter string, like > "Hiya!", then it works, no error. As it stands, i get a > _BLOCK_TYPE_IS_VALID error in what looks like the destructor of the > std::string during the *pOutput = call_method... portion of the code > (i'm assuming the destructor before the assignment to pOutput occurs). > However, in the destructor, i do see the data consisting of "Welcome > from Python!" > > Now i'm also a complete noob to boost and python. i've only been > working on this for about 5 hours or so (the python side of things at > any rate), so any tips to improve what i'm doing in addition to helping > with this error is greatly appreciated. i'm finding it difficult to > find some boost.python tutorials that are comprehensive enough. If you > can't tell, i'm trying to expose a version of my InputHandler class to > python so that it can be overriden and created from scripts instead of > being hard-coded into the C++. > > Thanks for the help!!!! From reg3777 at yahoo.com Thu Oct 6 22:34:20 2005 From: reg3777 at yahoo.com (Reggie Smith) Date: Thu, 6 Oct 2005 13:34:20 -0700 (PDT) Subject: [C++-sig] Trying to install a module (Agrepy) Message-ID: <20051006203421.46570.qmail@web54301.mail.yahoo.com> Hello, everyone. I am trying to install a python module called agrepy which is a fuzzy string search tool. However, when the makefile runs I get many errors like this: "undefined reference to '_Pystring.... referencing one of the C files that the makefile uses. I am using GCC 3.4.4 and Cygwin 1.5.18 on Win XP SP2. >From scanning previous threads I feel very sure this is a Cygwin specific problem. Am I having it point to the wrong library or something? The makefile is below: VERSION=1.2 # Edit this to point to the directory tree in which Python is found #PYTHONROOT=/sw PYTHONROOT=/usr/local # Linux CC = gcc # When testing # Uncomment one of these when creating C only version for testing (see also output below) # CFLAGS = -g -Wall -Wshaddow -DDEBUG -DDEBUGDEBUG # for agrepy_test # CFLAGS = -g # for agrepy_test (free standing C application) OPTFLAGS = -O3 # The following flag is relevant to Linux but is not not recognized # by MacOS X posix compiler so comment it out LDFLAGS = -shared # Some compilers (not Mac) insist you add -fpic when compiling to get .so LDFLAGS = -shared #-fPIC # For Mac OSX # You will need to make the final argument refer to where the binary lives LDFLAGS = $(PYTHONROOT)/bin/python2.3 CFLAGS= -DPYTHON $(FPIC) $(OPTFLAGS) INCLUDES = -I$(PYTHONROOT)/include/python2.3 ALLOBJS = sagrepy.o lagrepy.o agrepy.o agrepy_wrap.o TESTOBJS = sagrepy.o lagrepy.o agrepy.o # Uncomment output : agrepy_test when building C only version for testing output : _agrepy.pyd # output : agrepy_test # This is a C-only implementation for testing purposes agrepy_test: $(TESTOBJS) $(CC) $(CFLAGS) -o agrepy_test $(TESTOBJS) \usr\local\lib\python2.3 libpython2.3.dll.a _agrepy.pyd : $(ALLOBJS) $(CC) $(LDFLAGS) $(INCLUDES) $(ALLOBJS) -o $@ agrepy_wrap.o : agrepy_wrap.c $(CC) $(CFLAGS) -c agrepy_wrap.c $(INCLUDES) agrepy_wrap.c : agrepy.i swig -python agrepy.i $(ALLOBJS): agrepy.h clean: rm -f $(ALLOBJS) agrepy_wrap.doc new: rm -f $(ALLOBJS) make tarfile: mkdir agrepy_${VERSION} cp `cat FILES` agrepy_${VERSION} cp FILES agrepy_${VERSION} tar cvf agrepy_${VERSION}.tar agrepy_${VERSION} gzip agrepy_${VERSION}.tar /bin/rm -r agrepy_${VERSION} Thanks for any help. Reggie __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From baas at ira.uka.de Fri Oct 7 15:12:41 2005 From: baas at ira.uka.de (Matthias Baas) Date: Fri, 07 Oct 2005 15:12:41 +0200 Subject: [C++-sig] Wrapping a class with private operator&() Message-ID: Hi, I'm having problems wrapping a C++ class that has a private reference operator (operator&()). Here is a minimal example that shows the problem: #include using namespace boost::python; class Spam { public: Spam() {} private: Spam* operator&() {return this;} }; BOOST_PYTHON_MODULE(mod) { class_("Spam", init<>()); } When I compile this code (either using gcc 3.3.4 on Linux or MSVC 7.1 on WinXP, both with Python 2.4 and boost-1.33.0) I get an error like that attached at the end of this mail. I suppose the relevant part of the message is this: /client/include/boost/python/detail/def_helper.hpp:79: instantiated from here mod.cpp:13: error: `Spam* Spam::operator&()' is private I can compile the code if I specify the class with no_init, but then the wrapper would be useless as it must be possible to create instances of the class. It would be acceptable to have a factory function that actually creates the instances but when I tried that it also didn't compile. So does anybody know how to wrap a class like the above? - Matthias - Error message from gcc: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/client/include -I/sw/i386_linux-2.0_glibc2/Python-2.4.1/include/python2.4 -c mod.cpp -o build/temp.linux-i686-2.4/mod.o mod.cpp: In constructor ` boost::python::objects::value_holder::value_holder(PyObject*) [with Value = Spam]': /client/include/boost/python/object/make_holder.hpp:83: instantiated from `static void boost::python::objects::make_holder<0>::apply::execute(PyObject*) [with Holder = boost::python::objects::value_holder, ArgList = boost::mpl::vector0]' /client/include/boost/python/detail/make_keyword_range_fn.hpp:60: instantiated from `boost::python::api::object boost::python::detail::make_keyword_range_constructor(const CallPolicies&, const boost::python::detail::keyword_range&, Holder*, ArgList*, Arity*) [with ArgList = boost::mpl::vector0, Arity = boost::mpl::size >, Holder = boost::python::objects::value_holder, CallPolicies = boost::python::default_call_policies]' /client/include/boost/python/init.hpp:330: instantiated from `void boost::python::detail::def_init_aux(ClassT&, const Signature&, NArgs, const CallPoliciesT&, const char*, const boost::python::detail::keyword_range&) [with ClassT = boost::python::class_, CallPoliciesT = boost::python::default_call_policies, Signature = boost::mpl::vector0, NArgs = boost::mpl::size >]' /client/include/boost/python/init.hpp:399: instantiated from `static void boost::python::detail::define_class_init_helper<0>::apply(ClassT&, const CallPoliciesT&, const Signature&, NArgs, const char*, const boost::python::detail::keyword_range&) [with ClassT = boost::python::class_, CallPoliciesT = boost::python::default_call_policies, Signature = boost::mpl::vector0, NArgs = boost::mpl::size >]' /client/include/boost/python/init.hpp:171: instantiated from `void boost::python::init_base::visit(classT&) const [with classT = boost::python::class_, DerivedT = boost::python::init]' /client/include/boost/python/def_visitor.hpp:31: instantiated from `static void boost::python::def_visitor_access::visit(const V&, classT&) [with V = boost::python::def_visitor >, classT = boost::python::class_]' /client/include/boost/python/def_visitor.hpp:67: instantiated from `void boost::python::def_visitor::visit(classT&) const [with classT = boost::python::class_, DerivedVisitor = boost::python::init]' /client/include/boost/python/class.hpp:225: instantiated from `boost::python::class_& boost::python::class_::def(const boost::python::def_visitor&) [with Derived = boost::python::init, W = Spam, X1 = boost::noncopyable, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' /client/include/boost/python/class.hpp:501: instantiated from `void boost::python::class_::initialize(const DefVisitor&) [with DefVisitor = boost::python::init_base >, W = Spam, X1 = boost::noncopyable, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' /client/include/boost/python/class.hpp:208: instantiated from `boost::python::class_::class_(const char*, const boost::python::init_base&) [with DerivedT = boost::python::init, W = Spam, X1 = boost::noncopyable, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' mod.cpp:19: instantiated from here mod.cpp:13: error: `Spam* Spam::operator&()' is private /client/include/boost/python/object/value_holder.hpp:134: error: within this context mod.cpp: In member function `void* boost::python::objects::value_holder::holds(boost::python::type_info, bool) [with Value = Spam]': /client/include/boost/python/detail/def_helper.hpp:79: instantiated from here mod.cpp:13: error: `Spam* Spam::operator&()' is private /client/include/boost/python/object/value_holder.hpp:89: error: within this context mod.cpp:13: error: `Spam* Spam::operator&()' is private /client/include/boost/python/object/value_holder.hpp:89: error: within this context /client/include/boost/python/detail/def_helper.hpp:79: instantiated from here mod.cpp:13: error: `Spam* Spam::operator&()' is private /client/include/boost/python/object/value_holder.hpp:93: error: within this context mod.cpp:13: error: `Spam* Spam::operator&()' is private /client/include/boost/python/object/value_holder.hpp:93: error: within this context From mjkeyes at sbcglobal.net Fri Oct 7 15:53:25 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 7 Oct 2005 08:53:25 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: Hey all, i know i just posted about something else yesterday, but i have found a number of memory leaks that crop up when i use BOOST_PYTHON_MODULE. Here's what it looks like: //NOTE SocketLib and PythonLib are two of my namespaces BOOST_PYTHON_MODULE(PyInputHandler) { class_("PythonInputHandler") .def("HandleInput",pure_virtual(&SocketLib::InputHandler::HandleInput)) .def("Enter", pure_virtual(&SocketLib::InputHandler::Enter)) .def("Leave", pure_virtual(&SocketLib::InputHandler::Leave)) .def("Hungup",pure_virtual(&SocketLib::InputHandler::Hungup)) .def("Flooded",pure_virtual(&SocketLib::InputHandler::Flooded)) .def("NoRoom",pure_virtual(&SocketLib::InputHandler::NoRoom)) .def("Quit", &PythonLib::PythonInputHandler::Quit) .def("ShutDown", &PythonLib::PythonInputHandler::ShutDown) .def("SendGlobal", &PythonLib::PythonInputHandler::SendGlobal) .def("AddInputHandler", &PythonLib::PythonInputHandler::AddInputHandler) ;}The leaks (17 of them) come from the init_module_PyInputHandler call that isgenerated from this macro.Here is what I call to instantiate my Python class in C++: PyObject *pInit = PyImport_ImportModule( "Python.SnakeMUD" ); if( pInit == NULL ) { PyErr_Print(); //throw custom exception handling } //call the python method to create our initial input handler handle<> hClassPtr(PyObject_CallMethod(pInit, "CreateInitialHandler",NULL)); //wrap the handle in a boost class object Handler(hClassPtr); //Get out class out of the boost class PythonLib::PythonInputHandler *pHandler =extract(Handler); //this will call Py_XINCREF on the PyObject *, which will allow ourhandler to continue to exist after this function exits pHandler->SetPyObject(Handler.ptr()); //cleanup the module call Py_XDECREF(pInit); //add our new handler AddInputHandler(pHandler);Nothing really fancy unless i'm doing something completely stupid. Anyadvice?Thanks in advance!Matt From brakhane at googlemail.com Fri Oct 7 18:02:17 2005 From: brakhane at googlemail.com (Dennis Brakhane) Date: Fri, 07 Oct 2005 18:02:17 +0200 Subject: [C++-sig] Wrapping a class with private operator&() In-Reply-To: References: Message-ID: <43469C09.4090809@googlemail.com> Matthias Baas wrote: > Hi, > > I'm having problems wrapping a C++ class that has a private reference > operator (operator&()). Here is a minimal example that shows the problem: Why would anyone do such a thing? You could create a wrapper (see the tutorial) class Foo { //private & }; struct FooWrap : Foo { Bar *operator& {return this;} }; class_("Foo") .def(...); From rwgk at yahoo.com Fri Oct 7 18:39:23 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 7 Oct 2005 09:39:23 -0700 (PDT) Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: Message-ID: <20051007163924.10208.qmail@web31514.mail.mud.yahoo.com> Your posting is missing new-lines and therefore very difficult to read. Over the last couple of year I ran our 50+ Boost.Python extension repeatedly with valgrind, incl leak check. It is a very long time ago (3+ years) that I found the last memory leak in Boost.Python. If there are still memory leaks in Boost.Python they must be in very obscure places. I'd bet that any leaks you are seeing are in your code. Seeing manual INCREF and DECREF in your code makes this seem all the more likely to me. I'd consider using boost::python::handle<> and boost::python::object to automate the reference counting. The key to resolving issues like your is always the same: carefully reduce your code just until the error goes away. Then put back the last code removed so that the error appears again. Keep reducing the code until you have a minimal example. If the problem is not in your code, post the minimal example to this list, complete with information about your platform and instructions how to compile. Cheers, Ralf --- Matt wrote: > Hey all, > > i know i just posted about something else yesterday, but i have found a > number of memory leaks that crop up when i use BOOST_PYTHON_MODULE. Here's > what it looks like: > > //NOTE SocketLib and PythonLib are two of my namespaces > > BOOST_PYTHON_MODULE(PyInputHandler) > { > > class_("PythonInputHandler") > > .def("HandleInput",pure_virtual(&SocketLib::InputHandler::HandleInput)) > .def("Enter", pure_virtual(&SocketLib::InputHandler::Enter)) > .def("Leave", pure_virtual(&SocketLib::InputHandler::Leave)) > .def("Hungup",pure_virtual(&SocketLib::InputHandler::Hungup)) > .def("Flooded",pure_virtual(&SocketLib::InputHandler::Flooded)) > .def("NoRoom",pure_virtual(&SocketLib::InputHandler::NoRoom)) > .def("Quit", &PythonLib::PythonInputHandler::Quit) .def("ShutDown", > &PythonLib::PythonInputHandler::ShutDown) .def("SendGlobal", > &PythonLib::PythonInputHandler::SendGlobal) .def("AddInputHandler", > &PythonLib::PythonInputHandler::AddInputHandler) ;}The leaks (17 of them) > come from the init_module_PyInputHandler call that isgenerated from this > macro.Here is what I call to instantiate my Python class in C++: PyObject > *pInit = PyImport_I! > mportModule( "Python.SnakeMUD" ); if( pInit == NULL ) { PyErr_Print(); > //throw custom exception handling } //call the python method to create > our initial input handler handle<> hClassPtr(PyObject_CallMethod(pInit, > "CreateInitialHandler",NULL)); //wrap the handle in a boost class object > Handler(hClassPtr); //Get out class out of the boost class > PythonLib::PythonInputHandler *pHandler > =extract(Handler); //this will call > Py_XINCREF on the PyObject *, which will allow ourhandler to continue to > exist after this function exits pHandler->SetPyObject(Handler.ptr()); > //cleanup the module call Py_XDECREF(pInit); //add our new handler > AddInputHandler(pHandler);Nothing really fancy unless i'm doing something > completely stupid. Anyadvice?Thanks in advance!Matt __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From mjkeyes at sbcglobal.net Fri Oct 7 20:21:45 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 7 Oct 2005 13:21:45 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE References: <20051007163924.10208.qmail@web31514.mail.mud.yahoo.com> Message-ID: Thanks for your reply! I do apologize for the lack of line breaks - I'm not sure how that happened. Anywho, I am new to boost, so please bear with me a little bit here :). I didn't realize that I could use a handle object like that to handle internal references to the PyObject*. However, I have modified the code, and here it is (modified): handle<> hInitPtr(PyImport_ImportModule( "Python.SnakeMUD" )); handle<> hClassPtr( PyObject_CallMethod(hInitPtr.get(), "CreateInitialHandler", NULL)); object Handler(hClassPtr); PythonLib::PythonInputHandler *pHandler = extract(Handler); //so that the returned pHandler doesn't destruct //from the boost references above pHandler->SetPyObject(Handler.ptr()); AddInputHandler(pHandler); I still get the memory leaks, and I'm not doing any IncRef's or DecRef's anywhere else. I have commented out all the code, and I receive no memory leaks. However, when I uncomment even just the first line (the hInitPtr), I get 17 leaks. Any advice? Also, does the above code look reasonable? Like I said, I'm new to boost so I don't know if it looks clean or not. Thanks again! "Ralf W. Grosse-Kunstleve" wrote in message news:20051007163924.10208.qmail at web31514.mail.mud.yahoo.com... > Your posting is missing new-lines and therefore very difficult to read. > > Over the last couple of year I ran our 50+ Boost.Python extension > repeatedly > with valgrind, incl leak check. It is a very long time ago (3+ years) that > I > found the last memory leak in Boost.Python. If there are still memory > leaks in > Boost.Python they must be in very obscure places. I'd bet that any leaks > you > are seeing are in your code. Seeing manual INCREF and DECREF in your code > makes > this seem all the more likely to me. I'd consider using > boost::python::handle<> > and boost::python::object to automate the reference counting. > > The key to resolving issues like your is always the same: carefully reduce > your > code just until the error goes away. Then put back the last code removed > so > that the error appears again. Keep reducing the code until you have a > minimal > example. If the problem is not in your code, post the minimal example to > this > list, complete with information about your platform and instructions how > to > compile. > > Cheers, > Ralf > > --- Matt wrote: > >> Hey all, >> >> i know i just posted about something else yesterday, but i have found a >> number of memory leaks that crop up when i use BOOST_PYTHON_MODULE. >> Here's >> what it looks like: >> >> //NOTE SocketLib and PythonLib are two of my namespaces >> >> BOOST_PYTHON_MODULE(PyInputHandler) >> { >> >> > class_("PythonInputHandler") >> >> > .def("HandleInput",pure_virtual(&SocketLib::InputHandler::HandleInput)) >> .def("Enter", >> pure_virtual(&SocketLib::InputHandler::Enter)) >> .def("Leave", pure_virtual(&SocketLib::InputHandler::Leave)) >> .def("Hungup",pure_virtual(&SocketLib::InputHandler::Hungup)) >> .def("Flooded",pure_virtual(&SocketLib::InputHandler::Flooded)) >> .def("NoRoom",pure_virtual(&SocketLib::InputHandler::NoRoom)) >> .def("Quit", &PythonLib::PythonInputHandler::Quit) .def("ShutDown", >> &PythonLib::PythonInputHandler::ShutDown) .def("SendGlobal", >> &PythonLib::PythonInputHandler::SendGlobal) .def("AddInputHandler", >> &PythonLib::PythonInputHandler::AddInputHandler) ;}The leaks (17 of >> them) >> come from the init_module_PyInputHandler call that isgenerated from this >> macro.Here is what I call to instantiate my Python class in C++: >> PyObject >> *pInit = PyImport_I! >> mportModule( "Python.SnakeMUD" ); if( pInit == NULL ) { >> PyErr_Print(); >> //throw custom exception handling } //call the python method to >> create >> our initial input handler handle<> hClassPtr(PyObject_CallMethod(pInit, >> "CreateInitialHandler",NULL)); //wrap the handle in a boost class >> object >> Handler(hClassPtr); //Get out class out of the boost class >> PythonLib::PythonInputHandler *pHandler >> =extract(Handler); //this will call >> Py_XINCREF on the PyObject *, which will allow ourhandler to continue to >> exist after this function exits pHandler->SetPyObject(Handler.ptr()); >> //cleanup the module call Py_XDECREF(pInit); //add our new handler >> AddInputHandler(pHandler);Nothing really fancy unless i'm doing something >> completely stupid. Anyadvice?Thanks in advance!Matt > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com From mjkeyes at sbcglobal.net Fri Oct 7 20:30:17 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 7 Oct 2005 13:30:17 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE References: <20051007163924.10208.qmail@web31514.mail.mud.yahoo.com> Message-ID: One more quick note - in doing some google searches on this subject, I found a couple of things: 1. People were told to ignore the boost memory leaks because modern computers can handle it (which sounds like a BAD BAD BAD approach to me) 2. People were told not to call Py_Finalize() Are either of these correct, and can I ignore my Py_Finalize call? "Ralf W. Grosse-Kunstleve" wrote in message news:20051007163924.10208.qmail at web31514.mail.mud.yahoo.com... > Your posting is missing new-lines and therefore very difficult to read. > > Over the last couple of year I ran our 50+ Boost.Python extension > repeatedly > with valgrind, incl leak check. It is a very long time ago (3+ years) that > I > found the last memory leak in Boost.Python. If there are still memory > leaks in > Boost.Python they must be in very obscure places. I'd bet that any leaks > you > are seeing are in your code. Seeing manual INCREF and DECREF in your code > makes > this seem all the more likely to me. I'd consider using > boost::python::handle<> > and boost::python::object to automate the reference counting. > > The key to resolving issues like your is always the same: carefully reduce > your > code just until the error goes away. Then put back the last code removed > so > that the error appears again. Keep reducing the code until you have a > minimal > example. If the problem is not in your code, post the minimal example to > this > list, complete with information about your platform and instructions how > to > compile. > > Cheers, > Ralf > > --- Matt wrote: > >> Hey all, >> >> i know i just posted about something else yesterday, but i have found a >> number of memory leaks that crop up when i use BOOST_PYTHON_MODULE. >> Here's >> what it looks like: >> >> //NOTE SocketLib and PythonLib are two of my namespaces >> >> BOOST_PYTHON_MODULE(PyInputHandler) >> { >> >> > class_("PythonInputHandler") >> >> > .def("HandleInput",pure_virtual(&SocketLib::InputHandler::HandleInput)) >> .def("Enter", >> pure_virtual(&SocketLib::InputHandler::Enter)) >> .def("Leave", pure_virtual(&SocketLib::InputHandler::Leave)) >> .def("Hungup",pure_virtual(&SocketLib::InputHandler::Hungup)) >> .def("Flooded",pure_virtual(&SocketLib::InputHandler::Flooded)) >> .def("NoRoom",pure_virtual(&SocketLib::InputHandler::NoRoom)) >> .def("Quit", &PythonLib::PythonInputHandler::Quit) .def("ShutDown", >> &PythonLib::PythonInputHandler::ShutDown) .def("SendGlobal", >> &PythonLib::PythonInputHandler::SendGlobal) .def("AddInputHandler", >> &PythonLib::PythonInputHandler::AddInputHandler) ;}The leaks (17 of >> them) >> come from the init_module_PyInputHandler call that isgenerated from this >> macro.Here is what I call to instantiate my Python class in C++: >> PyObject >> *pInit = PyImport_I! >> mportModule( "Python.SnakeMUD" ); if( pInit == NULL ) { >> PyErr_Print(); >> //throw custom exception handling } //call the python method to >> create >> our initial input handler handle<> hClassPtr(PyObject_CallMethod(pInit, >> "CreateInitialHandler",NULL)); //wrap the handle in a boost class >> object >> Handler(hClassPtr); //Get out class out of the boost class >> PythonLib::PythonInputHandler *pHandler >> =extract(Handler); //this will call >> Py_XINCREF on the PyObject *, which will allow ourhandler to continue to >> exist after this function exits pHandler->SetPyObject(Handler.ptr()); >> //cleanup the module call Py_XDECREF(pInit); //add our new handler >> AddInputHandler(pHandler);Nothing really fancy unless i'm doing something >> completely stupid. Anyadvice?Thanks in advance!Matt > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com From rwgk at yahoo.com Sat Oct 8 01:29:09 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 7 Oct 2005 16:29:09 -0700 (PDT) Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: Message-ID: <20051007232909.9702.qmail@web31514.mail.mud.yahoo.com> --- Matt wrote: > handle<> hInitPtr(PyImport_ImportModule( "Python.SnakeMUD" )); I think this is correct code, and I know for sure the handle<> constructor doesn't introduce memory leaks. But I don't know what "Python.SnakeMUD" is. What happens if you import "sys" instead? > However, when I uncomment even just the first line (the hInitPtr), > I get 17 leaks. How do you measure memory leaks? E.g. dynamically loading modules is irreversible in C Python. I could imagine some associated allocation overhead that is not de-allocated until the process finishes. If I suspect a leak somewhere my usual response is to call the corresponding functions repeatedly in an infinite loop and manually monitor the total allocation of the process (e.g. "top" under Linux or the Task Manager under Windows). With this method even tiny leaks usually show up very quickly on the radar, while one-time static allocations connected to imports or other static initializers don't create any visible noise. Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From rwgk at yahoo.com Sat Oct 8 01:36:17 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 7 Oct 2005 16:36:17 -0700 (PDT) Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: Message-ID: <20051007233617.37646.qmail@web31511.mail.mud.yahoo.com> --- Matt wrote: > One more quick note - in doing some google searches on this subject, > I found a couple of things: > > 1. People were told to ignore the boost memory leaks because modern > computers can handle it (which sounds like a BAD BAD BAD approach > to me) Sounds bad to me, too, but it depends on the context. > 2. People were told not to call Py_Finalize() That's correct. Boost.Python doesn't support cleanup for Py_Finalize. Isn't that documented somewhere? (I never use embedding.) > Are either of these correct, and can I ignore my Py_Finalize call? Yes, you have to comment out Py_Finalize. If you can, make Python the main. IMHO embedding is a plan B. Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From dave at boost-consulting.com Sat Oct 8 15:15:31 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 08 Oct 2005 09:15:31 -0400 Subject: [C++-sig] Wrapping a class with private operator&() References: Message-ID: Matthias Baas writes: > Hi, > > I'm having problems wrapping a C++ class that has a private reference > operator (operator&()). Well, first of all, don't do that. A class whose address-of operator doesn't do the normal thing is going to **break** just about every generic library you try to use it with in exactly this way. It's generally agreed that overloading operator& is pure evil except in very special circumstances. It doesn't do anything, really, to protect you: there's a function template in Boost called addressof that can produce a pointer to the object anyway. > Here is a minimal example that shows the problem: In the enclosed patch, I replaced enough uses of "&" with addressof to make your example compile, but I'm almost certain there will be other such instances. If you try it and it works for you, I'll check it in. -------------- next part -------------- A non-text attachment was scrubbed... Name: value_holder.patch Type: text/x-patch Size: 1485 bytes Desc: not available URL: -------------- next part -------------- -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Sat Oct 8 19:05:23 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Sat, 8 Oct 2005 12:05:23 -0500 Subject: [C++-sig] Help With Embedded Pure Virtual Classes Message-ID: Hey all, (there is quite some code below... my apologies in advance, but there should be a fairly simple solution to this question I'm sure) My apologies for spamming the mailing list lately... i'm just trying to get off to a good start working with embedding Python in C//C++. (Thanks to Ralf thus far for his help, too!) Anyways, here's my current problem. i am finally able to get an instance of a class derived in Python from a pure virtual class in C++ created. However, i am not able to call any of the pure virtual methods. One of the base classes from the intermediate "wrapper" class is the boost::python::wrapper class, but it's own internal object never gets set (and i don't think there is a way to manually set it since it is a private variable). Here is some of my code: /***********************************************************/ //Base pure class: template class InputHandler { //Pure Functions public: virtual commandtype HandleInput(const commandtype &Input) = 0; virtual commandtype Enter() = 0; virtual commandtype Leave() = 0; virtual commandtype Hungup() = 0; virtual commandtype Flooded() = 0; virtual commandtype NoRoom() = 0; //End Pure Functions /*...*/ }; //Intermediate class: class PythonInputHandler : public InputHandler, public wrapper > { public: PythonInputHandler(PyObject *pSelf = NULL) : m_Self(pSelf) {} PythonInputHandler(PyObject *pSelf, const InputHandler &rhs) : InputHandler(rhs) , m_Self(pSelf) {} virtual ~PythonInputHandler() {} std::string HandleInput(const std::string &Input) { const char *p = ""; //note, std::string always causes heap error, so use char try { #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // Workaround for vc6/vc7 p = call(this->get_override("HandleInput").ptr(), Input.c_str()); #else p = this->get_override("HandleInput")(Input); #endif } catch(...) { PyErr_Print(); p = ""; } return (p != NULL ? p : ""); } /*..other overriden pure methods...*/ }; //NOTE, SORRY AT THIS POINT I HAVE TO DOUBLESPACE EVERYTHING //BECAUSE MY NEWSGROUP READER WANTS TO WRAP EVERYTHING IN ONE LINE BOOST_PYTHON_MODULE(PyInputHandler) { class_,PythonLib::PythonInputHandler,boost::noncopyable>("PythonInputHandler") .def("HandleInput", pure_virtual(&InputHandler::HandleInput)) /*...other exposed pure methods...*/ ; } //Python code: from PyInputHandler import * class PyLogonHandler(PythonInputHandler): def HandleInput(self,Input): if Input == "/quit": self.Quit() elif Input == "/shutdown": self.ShutDown() else: return Input #other expose methods... //Code to instantiate the object in C++: try { handle<> hModulePtr(PyImport_ImportModule( "MyModule" )); handle<> hNamespace(borrowed(PyModule_GetDict(hModulePtr.get()))); handle<> hClassPtr(PyRun_String("PyLogonHandler", Py_eval_input, hNamespace.get(), hNamespace.get())); object oClass(hClassPtr); PyErr_Print(); object oHandler = oClass(); PythonLib::PythonInputHandler *pHandler = extract(oHandler); m_Obj.push(oHandler); //so the object doesn't destruct itself after this is finished (making the pointer invalid) AddInputHandler(pHandler); pHandler->HandleInput("testing"); } catch(...) { PyErr_Print(); } /***********************************************************/ Now then, everything works great. However, when I call the pure functions from C++, the following occurs: //code from above in PythonInputHandler std::string HandleInput(const std::string &Input) { const char *p = ""; //note, std::string always causes heap error, so use char try { #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // Workaround for vc6/vc7 p = call(this->get_override("HandleInput").ptr(), Input.c_str()); #else p = this->get_override("HandleInput")(Input); //THROWS EXCEPTION BECAUSE INTERNAL OBJECT IS NULL #endif } catch(...) { PyErr_Print(); p = ""; } I can't seem to get the internal wrapper's internal object (representing the acutal Python class) set. I'm sure I'm missing something simple, but I'm having difficulty tracking it down (and I can't find any tutorials that tie all this together in a way that will allow me to do what I'm trying to do). Thanks in advance!! Matt From mjkeyes at sbcglobal.net Mon Oct 10 12:45:05 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Mon, 10 Oct 2005 05:45:05 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <000001c5cd87$aec5ba00$210110ac@CROW> Ralf (et. al), (note - I hope my newsgroup reader doesn't wrap all this in one line) I've been playing around with this and I'm still thinking boost leaks memory in an embedded and extended application. I use Visual Leak Detector 1.0 to track memory leaks, and here is where the leak comes from (in my code): BOOST_PYTHON_MODULE(PyInputHandler) { class_("PythonInputHa ndler") .def("HandleInput", pure_virtual(&SocketLib::InputHandler::HandleInput)) .def("Enter", pure_virtual(&SocketLib::InputHandler::Enter)) .def("Leave", pure_virtual(&SocketLib::InputHandler::Leave)) .def("Hungup", pure_virtual(&SocketLib::InputHandler::Hungup)) .def("Flooded", pure_virtual(&SocketLib::InputHandler::Flooded)) .def("NoRoom", pure_virtual(&SocketLib::InputHandler::NoRoom)) .def("Quit", &Extensions::PythonInputHandler::Quit) .def("ShutDown", &Extensions::PythonInputHandler::ShutDown) .def("SendGlobal", &Extensions::PythonInputHandler::SendGlobal) .def("AddInputHandler", &Extensions::PythonInputHandler::AddInputHandler) ; } If I insert VLDDisable() before this class_ block and VLDEnable() after (which temporarily disables the leak detection for this function call), I get zero leaks. With it turned on, here is what I see (repeated 17 times): (note - the block varies for each leak) ---------- Block 166 at 0x003A7520: 8 bytes ---------- Call Stack: f:\vs70builds\3077\vc\crtbld\crt\src\newop.cpp (12): operator new d:\devltool\boost\boost_1_33_0\boost\python\object\py_function.hpp (121): boost::python::objects::py_function::py_function > > d:\devltool\boost\boost_1_33_0\boost\python\make_function.hpp (62): boost::python::detail::make_function_aux,boost::mpl::int_<0> > d:\devltool\boost\boost_1_33_0\boost\python\detail\make_keyword_range_fn .hpp (32): boost::python::detail::make_keyword_range_function d:\devltool\boost\boost_1_33_0\boost\python\detail\make_keyword_range_fn .hpp (64): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\init.hpp (338): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\init.hpp (399): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\init.hpp (177): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\def_visitor.hpp (32): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\def_visitor.hpp (67): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\class.hpp (226): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\class.hpp (502): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devltool\boost\boost_1_33_0\boost\python\class.hpp (631): boost::python::detail::make_keyword_range_constructor,boost::mpl::size >,boost::python::objects::value_holder,b oost::python::default_call_policies> d:\devl\muds\testbed\completelibtest\thirdlibtest\lib\pythoninputhandler .h (153): init_module_PyInputHandler 0x10006C2B (File and line number not available): boost::python::detail::exception_handler::operator= 0x1000EC23 (File and line number not available): boost::python::detail::init_module 0x1E0682B1 (File and line number not available): PyImport_FindModule 0x48747570 (File and line number not available): (Function name unavailable) Data: ... (whatever data leaked) It appears in py_function.hpp, the following line is the culprit: struct py_function { template py_function(Caller const& caller) (line 120 - leak): : m_impl(new caller_py_function_impl(caller)) {} /*...*/ }; This m_impl is a std::auto_ptr, and the constructor is given a new caller_py_function_impl. However, I don't know that this is ever deallocated. I could be terribly wrong here, but if I run my code without this BOOST_INIT_MODULE call, I get no leaks. Is this something that Python will deallocate? Any advice is appreciated! Thanks! Matt "Ralf W. Grosse-Kunstleve" wrote in message news:<20051007232909.9702.qmail at web31514.mail.mud.yahoo.com>... > --- Matt wrote: > > handle<> hInitPtr(PyImport_ImportModule( "Python.SnakeMUD" )); > > I think this is correct code, and I know for sure the handle<> > constructor doesn't introduce memory leaks. But I don't know what > "Python.SnakeMUD" is. What happens if you import "sys" instead? > > > However, when I uncomment even just the first line (the hInitPtr), I > > get 17 leaks. > > How do you measure memory leaks? > E.g. dynamically loading modules is irreversible in C Python. I could > imagine some associated allocation overhead that is not de-allocated > until the process finishes. If I suspect a leak somewhere my usual > response is to call the corresponding functions repeatedly in an > infinite loop and manually monitor the total allocation of the process > (e.g. "top" under Linux or the Task Manager under Windows). With this > method even tiny leaks usually show up very quickly on the radar, > while one-time static allocations connected to imports or other static > initializers don't create any visible noise. > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com From mjkeyes at sbcglobal.net Mon Oct 10 12:45:10 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Mon, 10 Oct 2005 05:45:10 -0500 Subject: [C++-sig] Help With Embedded Pure Virtual Classes Message-ID: <000101c5cd87$afc74b80$210110ac@CROW> Easy fix: BOOST_PYTHON_MODULE(PyInputHandler) { class_,PythonLib::PythonInputHandler,boost::no ncopyable>("PythonInputHandler") .def("HandleInput", pure_virtual(&InputHandler::HandleInput)) /*...other exposed pure methods...*/ ; } Should be: BOOST_PYTHON_MODULE(PyInputHandler) { class_("PythonInputHan dler") .def("HandleInput", pure_virtual(&InputHandler::HandleInput)) /*...other exposed pure methods...*/ ; } "Matt" wrote in message news:... > Hey all, > > (there is quite some code below... my apologies in advance, but there > should > be a fairly simple solution to this question I'm sure) > > My apologies for spamming the mailing list lately... i'm just trying > to get > off to a good start working with embedding Python in C//C++. (Thanks to > Ralf thus far for his help, too!) > > Anyways, here's my current problem. i am finally able to get an > instance of > a class derived in Python from a pure virtual class in C++ created. > However, i am not able to call any of the pure virtual methods. One of the > base classes from the intermediate "wrapper" class is the > boost::python::wrapper class, but it's own internal object never gets set > (and i don't think there is a way to manually set it since it is a private > variable). > > Here is some of my code: > > /***********************************************************/ > //Base pure class: > template > class InputHandler > { > //Pure Functions > public: > virtual commandtype HandleInput(const commandtype &Input) = 0; > virtual commandtype Enter() = 0; virtual commandtype Leave() = 0; > virtual commandtype Hungup() = 0; > virtual commandtype Flooded() = 0; > virtual commandtype NoRoom() = 0; > //End Pure Functions > /*...*/ > }; > > //Intermediate class: > class PythonInputHandler : public InputHandler, public > wrapper > > { > public: > PythonInputHandler(PyObject *pSelf = NULL) : m_Self(pSelf) {} > PythonInputHandler(PyObject *pSelf, const InputHandler &rhs) : > InputHandler(rhs) , m_Self(pSelf) {} > virtual ~PythonInputHandler() {} > > std::string HandleInput(const std::string &Input) > { > const char *p = ""; //note, std::string always causes heap error, so > use > char > try > { > #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // Workaround for vc6/vc7 > p = call(this->get_override("HandleInput").ptr(), Input.c_str()); > #else > p = this->get_override("HandleInput")(Input); > #endif > } > catch(...) > { > PyErr_Print(); > p = ""; > } > > return (p != NULL ? p : ""); > } > /*..other overriden pure methods...*/ > }; > > //NOTE, SORRY AT THIS POINT I HAVE TO DOUBLESPACE EVERYTHING //BECAUSE > MY NEWSGROUP READER WANTS TO WRAP EVERYTHING IN ONE LINE > > BOOST_PYTHON_MODULE(PyInputHandler) > > { > > class_,PythonLib::PythonInputHandler,boost:: > noncopyable>("PythonInputHandler") > > .def("HandleInput", > pure_virtual(&InputHandler::HandleInput)) > > /*...other exposed pure methods...*/ > > ; > > } > > > //Python code: > > from PyInputHandler import * > > > > class PyLogonHandler(PythonInputHandler): > > def HandleInput(self,Input): > > if Input == "/quit": > > self.Quit() > > elif Input == "/shutdown": > > self.ShutDown() > > else: > > return Input > > #other expose methods... > > > > //Code to instantiate the object in C++: > > try > > { > > handle<> hModulePtr(PyImport_ImportModule( "MyModule" )); > > handle<> hNamespace(borrowed(PyModule_GetDict(hModulePtr.get()))); > > > > handle<> hClassPtr(PyRun_String("PyLogonHandler", Py_eval_input, > hNamespace.get(), hNamespace.get())); > > object oClass(hClassPtr); > > PyErr_Print(); > > > > object oHandler = oClass(); > > PythonLib::PythonInputHandler *pHandler = > extract(oHandler); > > > > m_Obj.push(oHandler); //so the object doesn't destruct itself after > this is > finished (making the pointer invalid) > > AddInputHandler(pHandler); > > pHandler->HandleInput("testing"); > > } > > catch(...) > > { > > PyErr_Print(); > > } > > > > /***********************************************************/ > > Now then, everything works great. However, when I call the pure > functions > from C++, the following occurs: > > //code from above in PythonInputHandler > std::string HandleInput(const std::string &Input) > { > const char *p = ""; //note, std::string always causes heap error, so > use > char > try > { > #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // Workaround for vc6/vc7 > p = call(this->get_override("HandleInput").ptr(), Input.c_str()); > #else > p = this->get_override("HandleInput")(Input); //THROWS EXCEPTION BECAUSE > INTERNAL OBJECT IS NULL > #endif > } > catch(...) > { > PyErr_Print(); > p = ""; > } > > I can't seem to get the internal wrapper's internal object > (representing the > acutal Python class) set. I'm sure I'm missing something simple, but I'm > having difficulty tracking it down (and I can't find any tutorials that tie > all this together in a way that will allow me to do what I'm trying to do). > > Thanks in advance!! > Matt From postmaster at ristretto4u.f9.co.uk Mon Oct 10 16:13:10 2005 From: postmaster at ristretto4u.f9.co.uk (David Welch) Date: Mon, 10 Oct 2005 15:13:10 +0100 Subject: [C++-sig] Expression templates in python Message-ID: Hi, I am new to python and thought I would write a vector / matrix class in c++ and export to python. Is it possible to have vector operations done in python evaluate to some form of intermediate calculation object which can then be passed to the c++ code for evaluation? ie, V1 = [0.1,0.2,0.3] V2 = [0.7,0.4,0.7] V3 = V1*4 - V2*V1 so the operators in python would not actually do the calulation but construct an object which will call a c++ function on assignment to V3 ala expression templates in c++. Has this been done before in python, if so is there a link? Also, is it possible to pass a lambda function as an argument to a c function and get information about its contents? Any advice on how to do this, is it worth it? Thanks, Dave From seefeld at sympatico.ca Mon Oct 10 16:52:24 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 10 Oct 2005 10:52:24 -0400 Subject: [C++-sig] Expression templates in python In-Reply-To: References: Message-ID: <434A8028.9040702@sympatico.ca> David Welch wrote: > Hi, > > I am new to python and thought I would write a vector / matrix class in > c++ and export to python. > > Is it possible to have vector operations done in python evaluate to some > form of intermediate calculation object which can then be passed to the > c++ code for evaluation? > > ie, > V1 = [0.1,0.2,0.3] > V2 = [0.7,0.4,0.7] > V3 = V1*4 - V2*V1 Not really, at least not with that straight forward syntax. The reason is that the 'V1' name above is bound to the object '[0.1,0.2,0.3]', which has type 'list', i.e. python is 'dynamically typed'. May be you could play games if 'V1' is an attribute of an object, for which you overload the 'setattr' method ? Regards, Stefan From iluetkeb at gmail.com Mon Oct 10 17:03:58 2005 From: iluetkeb at gmail.com (=?ISO-8859-1?Q?Ingo_L=FCtkebohle?=) Date: Mon, 10 Oct 2005 17:03:58 +0200 Subject: [C++-sig] Expression templates in python In-Reply-To: References: Message-ID: David, not exactly what you describe but might be close enough: Using C/C++ inline in Python: http://www.scipy.org/documentation/weave/weaveusersguide.html and they link to http://pyinline.sourceforge.net/ which I have not used so far. Ingo From baas at ira.uka.de Mon Oct 10 18:21:35 2005 From: baas at ira.uka.de (Matthias Baas) Date: Mon, 10 Oct 2005 18:21:35 +0200 Subject: [C++-sig] Wrapping a class with private operator&() In-Reply-To: References: Message-ID: David Abrahams wrote: >>I'm having problems wrapping a C++ class that has a private reference >>operator (operator&()). > > Well, first of all, don't do that. A class whose address-of operator > doesn't do the normal thing is going to **break** just about every > generic library you try to use it with in exactly this way. It's > generally agreed that overloading operator& is pure evil except in > very special circumstances. This code was not written by myself, it's from an SDK I'm currently wrapping. The SDK belongs to Maya, a 3D modeling/animation tool by Alias (or soon by Autodesk). I have no idea why they made the operators private. The assignment operators are also private, maybe they just want to prevent anybody from passing such instances around...? >>Here is a minimal example that shows the problem: > > In the enclosed patch, I replaced enough uses of "&" with addressof to > make your example compile, but I'm almost certain there will be other > such instances. If you try it and it works for you, I'll check it in. I've tried the patch with the original code and it seems to be fine. The code compiles and can be used in Python. Thanks! The other suggestion by Dennis Brakhane to derive from the class and make the operator public is also a viable option that works as well. (I thought that the method would remain private just as it is the case with 'virtual'...). So thanks again! Regards, - Matthias - From rwgk at yahoo.com Mon Oct 10 21:06:42 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 10 Oct 2005 12:06:42 -0700 (PDT) Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: <000001c5cd87$aec5ba00$210110ac@CROW> Message-ID: <20051010190642.45158.qmail@web31502.mail.mud.yahoo.com> --- mjkeyes at sbcglobal.net wrote: > Ralf (et. al), > > (note - I hope my newsgroup reader doesn't wrap all this in one line) > > I've been playing around with this and I'm still thinking boost leaks > memory in an embedded and extended application. I use Visual Leak > Detector 1.0 to track memory leaks, and here is where the leak comes > from (in my code): > ... > If I insert VLDDisable() before this class_ block and VLDEnable() after > (which temporarily disables the leak detection for this function call), > I get zero leaks. With it turned on, here is what I see (repeated 17 > times): > ... > d:\devl\muds\testbed\completelibtest\thirdlibtest\lib\pythoninputhandler > .h (153): init_module_PyInputHandler > 0x10006C2B (File and line number not available): > boost::python::detail::exception_handler::operator= > 0x1000EC23 (File and line number not available): > boost::python::detail::init_module > 0x1E0682B1 (File and line number not available): PyImport_FindModule > 0x48747570 (File and line number not available): (Function name > unavailable) > Data: > ... (whatever data leaked) I believe these leaks are not actually leaks, but a documented (http://www.boost.org/libs/python/todo.html) feature of Boost.Python, directly connected to the lack of support for PyFinalize(). I think what you are seeing as leaks are actually just entries in the global converter registry. These are one-time static allocations. Since you cannot dlopen the same module multiple times there is no danger that these allocations become a real problem. See also: boost/libs/python/src/converter/registry.cpp Why is PyFinalize() support missing? -- Simply because the groups who invested money into Boost.Python development had no interest in embedding. To find real leaks, please consider my very simple approach of calling the code with the suspected problem in an infinite loop while monitoring the memory allocation of the process. Simple, quick, very effective, works the same on all platforms. I've done it many times, coincidentally a couple of days ago while testing new low-level code. I didn't see any real leaks. Cheers, Ralf __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/ From Keyes at simcrest.com Mon Oct 10 21:32:04 2005 From: Keyes at simcrest.com (Matthew B. Keyes) Date: Mon, 10 Oct 2005 14:32:04 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <6A26270516DF054BBB3B87AE01C831EC2CCAD1@SERVER01.simcrest.int> Ralf, Thanks tons again for the help! Needless to say, that will save me from pulling my hair out over this :) Thanks again, Matt "Ralf W. Grosse-Kunstleve" wrote in message news:<20051010190642.45158.qmail at web31502.mail.mud.yahoo.com>... > --- mjkeyes at sbcglobal.net wrote: > > > Ralf (et. al), > > > > (note - I hope my newsgroup reader doesn't wrap all this in one line) > > > > I've been playing around with this and I'm still thinking boost leaks > > memory in an embedded and extended application. I use Visual Leak > > Detector 1.0 to track memory leaks, and here is where the leak comes > > from (in my code): > > ... > > If I insert VLDDisable() before this class_ block and VLDEnable() after > > (which temporarily disables the leak detection for this function call), > > I get zero leaks. With it turned on, here is what I see (repeated 17 > > times): > > ... > > d:\devl\muds\testbed\completelibtest\thirdlibtest\lib\pythoninputhandler > > .h (153): init_module_PyInputHandler > > 0x10006C2B (File and line number not available): > > boost::python::detail::exception_handler::operator= > > 0x1000EC23 (File and line number not available): > > boost::python::detail::init_module > > 0x1E0682B1 (File and line number not available): PyImport_FindModule > > 0x48747570 (File and line number not available): (Function name > > unavailable) > > Data: > > ... (whatever data leaked) > > I believe these leaks are not actually leaks, but a documented > (http://www.boost.org/libs/python/todo.html) feature of Boost.Python, directly > connected to the lack of support for PyFinalize(). I think what you are seeing > as leaks are actually just entries in the global converter registry. These are > one-time static allocations. Since you cannot dlopen the same module multiple > times there is no danger that these allocations become a real problem. > See also: boost/libs/python/src/converter/registry.cpp > > Why is PyFinalize() support missing? -- Simply because the groups who invested > money into Boost.Python development had no interest in embedding. > > To find real leaks, please consider my very simple approach of calling the code > with the suspected problem in an infinite loop while monitoring the memory > allocation of the process. Simple, quick, very effective, works the same on all > platforms. I've done it many times, coincidentally a couple of days ago while > testing new low-level code. I didn't see any real leaks. > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ From roman.yakovenko at gmail.com Tue Oct 11 07:25:09 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 11 Oct 2005 08:25:09 +0300 Subject: [C++-sig] wrapper & HeldType Message-ID: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> Hi. I think I found bug in treatment of held type. Consider next code: struct data{ virtual From roman.yakovenko at gmail.com Tue Oct 11 07:48:08 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 11 Oct 2005 08:48:08 +0300 Subject: [C++-sig] wrapper & HeldType In-Reply-To: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> Message-ID: <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> Sorry, I pushed the wrong button. Hi. I think I found bug in treatment of held type. Consider next code: struct data{ virtual int f(); } There are 2 way to "override" f in Python. The first one is: struct data_wrapper : data, wrapper{...} And the second one: struct data_wrapper : data{ data_wrapper( PyObject* self,...) private: PyObject* m_self; } The problem is that if I want HeldType to be smart pointer, in my specific case is shared_ptr, then I can not use the first way as is. class_< data, data_wrapper, shared_ptr >(...) will not compile. The message, compiler gives, is too long to post, but it say something that data_wrapper does not have constructor that takes PyObject* as first argument. If I add PyObject* as first argument to data_wrapper constructor then all works as expected. There are a few things, that I think, are wrong here: 1. wrapper already has access to self. So the data_wrapper does not have to keep reference to self: struct data_wrapper : data, wrapper< data >{ data_wrapper( PyObject* self ) : data(), wrapper(){ //unused first argument } } 2. If I use first approach to wrap classes, then I write class_< data_wrapper >(...) in order to use custom HeldType I should switch to class_< data, data_wrapper, shared_ptr > syntax. I thing that this interface is not perfect. The better one is class_< data_wrapper, shared_ptr >. I think that Boost.Python can find out needed information about HeldType from HeldType itself. Hope I was clear. P.S. I tried to find out the place where fix should be done, but lost in ppl and mpl and recursive includes. Thanks Roman Yakovenko From postmaster at ristretto4u.f9.co.uk Tue Oct 11 10:12:13 2005 From: postmaster at ristretto4u.f9.co.uk (David Welch) Date: Tue, 11 Oct 2005 09:12:13 +0100 Subject: [C++-sig] Expression templates in python In-Reply-To: References: Message-ID: Ingo L?tkebohle wrote: > David, > > not exactly what you describe but might be close enough: > > Using C/C++ inline in Python: > http://www.scipy.org/documentation/weave/weaveusersguide.html > and they link to > http://pyinline.sourceforge.net/ > which I have not used so far. > > Ingo Weave looks interesting, thank you. Blitz is such a heavily optimised application it would be senseless trying to do all that again. From dave at boost-consulting.com Tue Oct 11 15:20:02 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 11 Oct 2005 09:20:02 -0400 Subject: [C++-sig] Wrapping a class with private operator&() References: Message-ID: David Abrahams writes: >> Here is a minimal example that shows the problem: > > In the enclosed patch, I replaced enough uses of "&" with addressof to > make your example compile, but I'm almost certain there will be other > such instances. If you try it and it works for you, I'll check it in. Done. -- Dave Abrahams Boost Consulting www.boost-consulting.com From skottmckay at gmail.com Tue Oct 11 21:27:49 2005 From: skottmckay at gmail.com (Scott McKay) Date: Tue, 11 Oct 2005 13:27:49 -0600 Subject: [C++-sig] wrapper & HeldType In-Reply-To: <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> Message-ID: <51d017870510111227y3b0de2e5w4a89d9e1c6b880a@mail.gmail.com> Have you tried class_< data_wrapper, shared_ptr< data_wrapper > >(...); implicitly_convertible< smart_ptr< data_wrapper >, smart_ptr< data > >(); That works for me. S On 10/10/05, Roman Yakovenko wrote: > > Sorry, I pushed the wrong button. > > Hi. I think I found bug in treatment of held type. > Consider next code: > > struct data{ > virtual int f(); > } > > There are 2 way to "override" f in Python. > The first one is: > struct data_wrapper : data, wrapper{...} > > And the second one: > > struct data_wrapper : data{ > data_wrapper( PyObject* self,...) > > private: > PyObject* m_self; > } > > The problem is that if I want HeldType to be smart pointer, in my > specific case is shared_ptr, then I can not use the first way as is. > > class_< data, data_wrapper, shared_ptr >(...) will not compile. > The message, compiler gives, is too long to post, but it say something > that data_wrapper does not have > constructor that takes PyObject* as first argument. If I add PyObject* > as first argument to > data_wrapper constructor then all works as expected. > > There are a few things, that I think, are wrong here: > 1. wrapper already has access to self. So the data_wrapper does > not have to > keep reference to self: > struct data_wrapper : data, wrapper< data >{ > data_wrapper( PyObject* self ) > : data(), wrapper(){ > //unused first argument > } > } > > 2. If I use first approach to wrap classes, then I write > class_< data_wrapper >(...) > in order to use custom HeldType I should switch to > class_< data, data_wrapper, shared_ptr > syntax. I thing that > this interface > is not perfect. The better one is > class_< data_wrapper, shared_ptr >. I think that > Boost.Python can find out > needed information about HeldType from HeldType itself. > > Hope I was clear. > > P.S. > I tried to find out the place where fix should be done, but lost in > ppl and mpl and > recursive includes. > > Thanks > > Roman Yakovenko > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan.walter.berlin at t-online.de Wed Oct 12 02:25:48 2005 From: jan.walter.berlin at t-online.de (jan.walter.berlin at t-online.de) Date: Wed, 12 Oct 2005 02:25:48 +0200 Subject: [C++-sig] (no subject) Message-ID: <1EPURI-0PIUy00@fwd35.aul.t-online.de> An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Oct 12 02:46:10 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 11 Oct 2005 20:46:10 -0400 Subject: [C++-sig] (no subject) In-Reply-To: <1EPURI-0PIUy00@fwd35.aul.t-online.de> References: <1EPURI-0PIUy00@fwd35.aul.t-online.de> Message-ID: <434C5CD2.3070900@sympatico.ca> jan.walter.berlin at t-online.de wrote: > Hi, > > Here is a question about Boost.Python and embedding/extending: > > I would like to read a Python script from a file within a plugin of a 3D > application. The Python script should contain some commands (functions) > which are NOT part of Python but should be implemented in C++ within the > SAME plugin. I've read the Tutorial Introduction ( > http://www.boost.org/libs/python/doc/tutorial/doc/html/index.html ) and > understand how to extend Python (creating a shared library) and how to > use the interpreter from within my plugin (embedding) but how can I mix > both approaches? > > Something like this: > > #include > ... > #include > using namespace boost::python; > ... > char const* greet() > { > return "hello, world"; > } > > BOOST_PYTHON_MODULE(hello) > { > def("greet", greet); > } > ... > void myCallback() > { > ... > Py_Initialize(); > object main_module((handle<>(borrowed(PyImport_AddModule("__main__"))))); I believe you are missing PyImport_AppendInittab("hello", inithello); > object main_namespace = main_module.attr("__dict__"); > handle<> result((allow_null(PyRun_String( > "import greet\n" And the above should be "import hello.greet\n". > "print hello.greet()", > Py_file_input, > main_namespace.ptr(), > main_namespace.ptr())))); > if (!result) PyErr_Print(); > ... > Py_Finalize(); Don't use Py_Finalize() right now. See http://www.boost-consulting.com/boost/libs/python/todo.html#pyfinalize-safety. In case you can use boost.python from HEAD (i.e. fresh from the repository), you may want to look into the boost/libs/python/test/exec.cpp test that shows how to do the above in a much more compact form, using a new API: if (PyImport_AppendInittab("hello", inithello) == -1) throw std::runtime_error("Failed to add hello to the interpreter's " "builtin modules"); // Retrieve the main module python::object main = python::import("__main__"); // Retrieve the main module's namespace python::object global(main.attr("__dict__")); // Run the inlined script. python::object result = python::exec( "import hello.greet \n" "print hello.greet() \n", global, global); HTH, Stefan From brakhane at googlemail.com Wed Oct 12 02:50:50 2005 From: brakhane at googlemail.com (Dennis Brakhane) Date: Wed, 12 Oct 2005 02:50:50 +0200 Subject: [C++-sig] (no subject) In-Reply-To: <434C5CD2.3070900@sympatico.ca> References: <1EPURI-0PIUy00@fwd35.aul.t-online.de> <434C5CD2.3070900@sympatico.ca> Message-ID: <434C5DEA.2030308@googlemail.com> Stefan Seefeld wrote: > I believe you are missing > > PyImport_AppendInittab("hello", inithello); Or you can just call inithello() right after Py_Initialize() From dave at boost-consulting.com Wed Oct 12 02:53:49 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 11 Oct 2005 20:53:49 -0400 Subject: [C++-sig] (no subject) References: <1EPURI-0PIUy00@fwd35.aul.t-online.de> Message-ID: "jan.walter.berlin at t-online.de" writes: > Hi, > > Here is a question about Boost.Python and embedding/extending: > > I would like to read a Python script from a file within a plugin of > a 3D application. The Python script should contain some commands > (functions) which are NOT part of Python but should be implemented > in C++ within the SAME plugin. What do you mean by "not part of Python?" Do you want your Python script to contain C++ code? > I've read the Tutorial Introduction ( http:// > www.boost.org/libs/python/doc/tutorial/doc/html/index.html ) and > understand how to extend Python (creating a shared library) and how > to use the interpreter from within my plugin (embedding) but how can > I mix both approaches? > > Something like this: > > #include > ... > #include > using namespace boost::python; > ... > char const* greet() > { > ? return "hello, world"; > } > > BOOST_PYTHON_MODULE(hello) > { > ? def("greet", greet); > } > ... > void myCallback() > { > ... > ? Py_Initialize(); > ? object main_module((handle<>(borrowed(PyImport_AddModule("__main__"))))); > ? object main_namespace = main_module.attr("__dict__"); > ? handle<> result((allow_null(PyRun_String( > ??? ??? ??? ??? ??? ?? "import greet\n" > ??? ??? ??? ??? ??? ?? "print hello.greet()", > ??? ??? ??? ??? ??? ?? Py_file_input, > ??? ??? ??? ??? ??? ?? main_namespace.ptr(), > ??? ??? ??? ??? ??? ?? main_namespace.ptr())))); > ? if (!result) PyErr_Print(); > ... > ? Py_Finalize(); Don't call Py_Finalize; it's not compatible with Boost.Python (or vice-versa). > ... > } > > This results in: > > Traceback (most recent call last): > ? File "", line 1, in ? > ImportError: No module named greet Of course it does; your module is called "hello." > I know that I could compile the extending part separately and put > the shared library somewhere where Python can find it but what I > really want is that I end up calling some C++ functions in my plugin > code by using a Python script which will run within the embedded > Python interpreter ... Any ideas? I don't understand the question, I'm afraid. -- Dave Abrahams Boost Consulting www.boost-consulting.com From jan.walter.berlin at t-online.de Wed Oct 12 03:10:59 2005 From: jan.walter.berlin at t-online.de (jan.walter.berlin at t-online.de) Date: Wed, 12 Oct 2005 03:10:59 +0200 Subject: [C++-sig] (no subject) In-Reply-To: <434C5CD2.3070900@sympatico.ca> References: <1EPURI-0PIUy00@fwd35.aul.t-online.de> <434C5CD2.3070900@sympatico.ca> Message-ID: <1EPV91-28dtfk0@fwd29.aul.t-online.de> Hi, Thanks, you are right, first of all the module is called "hello" (not "greet") and the line to call "inithello();" helps ;) Thanks also for the tip regarding "Py_Finalize();" Cheers, Jan From roman.yakovenko at gmail.com Wed Oct 12 08:40:51 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 12 Oct 2005 09:40:51 +0300 Subject: [C++-sig] wrapper & HeldType In-Reply-To: <51d017870510111227y3b0de2e5w4a89d9e1c6b880a@mail.gmail.com> References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <51d017870510111227y3b0de2e5w4a89d9e1c6b880a@mail.gmail.com> Message-ID: <7465b6170510112340p7b4be4edqc623294f84370c5c@mail.gmail.com> On 10/11/05, Scott McKay wrote: > Have you tried > > class_< data_wrapper, shared_ptr< data_wrapper > >(...); > implicitly_convertible< smart_ptr< data_wrapper >, smart_ptr< data > >(); smart_ptr is shared_ptr right? > That works for me. It doesn't work fork me. I have compile time error saying that: error C2440: 'initializing' : cannot convert from 'smart_pointers::data *' to 'data_wrapper *' Cast from base to derived requires dynamic_cast or static_cast I am using msvc 7.1 I do have solution, I just wanted to attract attention of boost.python developers. Any way, thanks for help. > S Roman Yakovenko From dave at boost-consulting.com Wed Oct 12 13:48:26 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 12 Oct 2005 07:48:26 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> Message-ID: Roman Yakovenko writes: > Hi. I think I found bug in treatment of held type. > Consider next code: > > struct data{ > virtual int f(); > } > > There are 2 way to "override" f in Python. > The first one is: > struct data_wrapper : data, wrapper{...} > > And the second one: > > struct data_wrapper : data{ > data_wrapper( PyObject* self,...) > > private: > PyObject* m_self; > } > > The problem is that if I want HeldType to be smart pointer, in my > specific case is shared_ptr, then I can not use the first way as is. Could you please post a minimal, complete example that you think should work? Thanks, Dave -- Dave Abrahams Boost Consulting www.boost-consulting.com From cludwig at cdc.informatik.tu-darmstadt.de Wed Oct 12 14:09:18 2005 From: cludwig at cdc.informatik.tu-darmstadt.de (Christoph Ludwig) Date: Wed, 12 Oct 2005 14:09:18 +0200 Subject: [C++-sig] [Python-Dev] GCC version compatibility In-Reply-To: <20050716101357.GC3607@lap200.cdc.informatik.tu-darmstadt.de> References: <42CDA654.2080106@v.loewis.de> <20050708072807.GC3581@lap200.cdc.informatik.tu-darmstadt.de> <42CEF948.3010908@v.loewis.de> <20050709102010.GA3836@lap200.cdc.informatik.tu-darmstadt.de> <42D0D215.9000708@v.loewis.de> <20050710125458.GA3587@lap200.cdc.informatik.tu-darmstadt.de> <42D15DB2.3020300@v.loewis.de> <20050716101357.GC3607@lap200.cdc.informatik.tu-darmstadt.de> Message-ID: <20051012120917.GA11058@lap200.cdc.informatik.tu-darmstadt.de> Hi, this is to continue a discussion started back in July by a posting by Dave Abrahams regarding the compiler (C vs. C++) used to compile python's main() and to link the executable. On Sat, Jul 16, 2005 at 12:13:58PM +0200, Christoph Ludwig wrote: > On Sun, Jul 10, 2005 at 07:41:06PM +0200, "Martin v. L?wis" wrote: > > Maybe. For Python 2.4, feel free to contribute a more complex test. For > > Python 2.5, I would prefer if the entire code around ccpython.cc was > > removed. > > I submitted patch #1239112 that implements the test involving two TUs for > Python 2.4. I plan to work on a more comprehensive patch for Python 2.5 but > that will take some time. I finally had the spare time to look into this problem again and submitted patch #1324762. The proposed patch implements the following: 1) The configure option --with-cxx is renamed --with-cxx-main. This was done to avoid surprising the user by the changed meaning. Furthermore, it is now possible that CXX has a different value than provided by --with-cxx-main, so the old name would have been confusing. 2) The compiler used to translate python's main() function is stored in the configure / Makefile variable MAINCC. By default, MAINCC=$(CC). If --with-cxx-main is given (without an appended compiler name), then MAINCC=$(CXX). If --with-cxx-main= is on the configure command line, then MAINCC=. Additionally, configure sets CXX= unless CXX was already set on the configure command line. 3) The command used to link the python executable is (as before) stored in LINKCC. By default, LINKCC='$(PURIFY) $(MAINCC)', i.e. the linker front-end is the compiler used to translate main(). If necessary, LINKCC can be set on the configure command line in which case it won't be altered. 4) If CXX is not set by the user (on the command line or via --with-cxx-main), then configure tries several likely C++ compiler names. CXX is assigned the first name that refers to a callable program in the system. (CXX is set even if python is built with a C compiler only, so distutils can build C++ extensions.) 5) Modules/ccpython.cc is no longer used and can be removed. I think that makes it possible to build python appropriately on every platform: - By default, python is built with the C compiler only; CXX is assigned the name of a "likely" C++ compiler. This works fine, e.g., on ELF systems like x86 / Linux where python should not have any dependency on the C++ runtime to avoid conflicts with C++ extensions. distutils can still build C++ extensions since CXX names a callable C++ compiler. - On platforms that require main() to be a C++ function if C++ extensions are to be imported, the user can configure python --with-cxx-main. On platforms where one must compile main() with a C++ compiler, but does not need to link the executable with the same compiler, the user can specify both --with-cxx-main and LINKCC on the configure command line. Best regards Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html From skottmckay at gmail.com Wed Oct 12 16:35:11 2005 From: skottmckay at gmail.com (Scott McKay) Date: Wed, 12 Oct 2005 08:35:11 -0600 Subject: [C++-sig] wrapper & HeldType In-Reply-To: <7465b6170510112340p7b4be4edqc623294f84370c5c@mail.gmail.com> References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <51d017870510111227y3b0de2e5w4a89d9e1c6b880a@mail.gmail.com> <7465b6170510112340p7b4be4edqc623294f84370c5c@mail.gmail.com> Message-ID: <51d017870510120735s6e591b25hdc12f222989faa39@mail.gmail.com> > > > class_< data_wrapper, shared_ptr< data_wrapper > >(...); > > implicitly_convertible< smart_ptr< data_wrapper >, smart_ptr< data > > >(); > > smart_ptr is shared_ptr right? > Yes it is. Sorry. > That works for me. > > It doesn't work fork me. I have compile time error saying that: > > error C2440: 'initializing' : cannot convert from > 'smart_pointers::data *' to 'data_wrapper *' > Cast from base to derived requires dynamic_cast or static_cast Are you using boost::shared_ptr or 'smart_pointers'? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Oct 12 16:38:13 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 12 Oct 2005 10:38:13 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost and Python Using Derived Classes References: Message-ID: "Matt" writes: > Hey all, > > i'm trying to create an application that both embeds and extends python > through boost. i've got a rough framework up and running, but now that > i'm finally to the python part i'm having troubles. Please know that i'm a > noob to boost and to boost.python, so if you see any obvious noob > idiocies in my code please point them out (we've all got to start learning > somewhere :)). You should never be doing any Py_XINCREF or Py_XDECREF stuff when using Boost.Python. Also, you're using an outdated approach to supporting virtual functions. I suggest you follow the example of http://www.boost-consulting.com/boost/libs/python/test/exec.cpp You'll need the latest Boost CVS state in order to use all the idioms therein, though. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Wed Oct 12 16:26:14 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 12 Oct 2005 15:26:14 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: <433DDF3F.28774.1080163@localhost> References: Message-ID: <434D2B16.10078.DB3EF01@localhost> Any movement on the below? Do you want me to submit a patch to type_traits or just to BPL? Cheers, Niall On 1 Oct 2005 at 0:58, Niall Douglas wrote: > On 30 Sep 2005 at 19:01, David Abrahams wrote: > > > You yourself said that void* isn't supported: > > It's only unsupported because BPL hasn't been coded to support it. > One can specialise for the void type after all, it's just a rather > unique integral type. > > > http://www.boost.org/libs/python/doc/v2/faq.html#voidptr > > > > Are you sure that this change is portable, or is it just exploiting a > > vc7.1 bugfeature? > > As the test case I posted illustrates, I am using no dodgy casting > whatsoever. This is simply a case where MSVC7.1 isn't able to deduce > from a void& return type, probably because void& can't exist and > type_traits::add_reference<> somehow bypasses MSVC's sanity check for > this. > > The question now becomes how to work around it. Here are my > solutions: > > 1. The best solution is to patch type_traits::add_reference<> with a > specialisation for void whereby it won't ever add a reference to a > void. AFAIK it's an illegal type anyway. While you're at it, patch > type_traits::add_cv<> to never add const volatile to void either as > that also never makes sense. > > 2. The other solution is to replace registered.hpp with what I have > attached. I particularly dislike the "const volatile void" template > specialisation :( > > Cheers, > Niall > > > > > From dave at boost-consulting.com Wed Oct 12 17:41:02 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 12 Oct 2005 11:41:02 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <434D2B16.10078.DB3EF01@localhost> Message-ID: "Niall Douglas" writes: > Any movement on the below? Do you want me to submit a patch to > type_traits or just to BPL? >> 1. The best solution is to patch type_traits::add_reference<> with a >> specialisation for void whereby it won't ever add a reference to a >> void. AFAIK it's an illegal type anyway. I am surprised that add_reference doesn't already act that way. If that is enough to fix your problem, I think you should post, and we should accept, the patch. >> While you're at it, patch >> type_traits::add_cv<> to never add const volatile to void either as >> that also never makes sense. That's incorrect. cv-qualified void is a legal type, and is essential in the formation of types like void const*. Note that char const* can't be converted to void*; you have to convert it to void const* or void const volatile*. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Oct 12 18:09:28 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 12 Oct 2005 12:09:28 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <434D2B16.10078.DB3EF01@localhost> Message-ID: David Abrahams writes: > "Niall Douglas" writes: > >> Any movement on the below? Do you want me to submit a patch to >> type_traits or just to BPL? > > >>> 1. The best solution is to patch type_traits::add_reference<> with a >>> specialisation for void whereby it won't ever add a reference to a >>> void. AFAIK it's an illegal type anyway. > > I am surprised that add_reference doesn't already act that way. If > that is enough to fix your problem, I think you should post, and we > should accept, the patch. BTW, the patch should go to the Boost developers' list, or to the SF patch tracker. If it goes here it will fall on the floor. -- Dave Abrahams Boost Consulting www.boost-consulting.com From skottmckay at gmail.com Thu Oct 13 02:31:49 2005 From: skottmckay at gmail.com (Scott McKay) Date: Wed, 12 Oct 2005 18:31:49 -0600 Subject: [C++-sig] setting up held smart pointer for pure virtual base class Message-ID: <51d017870510121731w1968f275td80a3fed6f565dd5@mail.gmail.com> I have a pure virtual base class (so no_init is set). The base class is held by a smart pointer. I want to implement that class in python. I know that calling the __init__ function of the base class sets up the smart pointer that is held by boost::python. Is there some other way to set that up given the base class has no __init__ function? If it isn't setup I get an ArgumentError as the types don't match. If I make the base class virtual (by providing dummy implementations for what were the pure virtual functions) and call the __init__ everything works. Thanks Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From mjkeyes at sbcglobal.net Thu Oct 13 09:30:26 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Thu, 13 Oct 2005 02:30:26 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <000001c5cfc7$fb14c0d0$210110ac@CROW> Hey again, I'm back. I've moved on to building an extension dll file in order to supplement my embedded application. Once again, I've got memory leaks. However, this is an easy one to test using your method of calling a function over and over. I did this and it chewed up the memory in my system like a hog (at least in task manager I see Python.exe growing steadily in memory consumption). Here is some pseudo-code of what I'm doing: class A { public: void SetString(const std::string &sVal) { m_sString = sVal; <--- Memory leak } void DoStuff() { SetString(msc_sString); } protected: static const std::string msc_sString; } class B { public: object CreateClassA() { return object(new CreateClassA()); <---- memory leak } } BOOST_PYTHON_MODULE(MyModule) { class_("ClassA") .def("DoStuff",&A::DoStuff) ; class_("ClassB") .def("CreateClassA",&B::CreateClassA) ; } Python: >>> from MyModule import * >>> A = ClassA() >>> A.DoStuff() <--- will call memory leak function >>> B = ClassB() >>> A = B.CreateClassA() <--- will call memory leak function Any suggestions? I'm not getting any errors from the interpreter. Thanks! "Ralf W. Grosse-Kunstleve" wrote in message news:<20051010190642.45158.qmail at web31502.mail.mud.yahoo.com>... > --- mjkeyes at sbcglobal.net wrote: > > > Ralf (et. al), > > > > (note - I hope my newsgroup reader doesn't wrap all this in one > > line) > > > > I've been playing around with this and I'm still thinking boost > > leaks memory in an embedded and extended application. I use Visual > > Leak Detector 1.0 to track memory leaks, and here is where the leak > > comes from (in my code): ... > > If I insert VLDDisable() before this class_ block and VLDEnable() after > > (which temporarily disables the leak detection for this function call), > > I get zero leaks. With it turned on, here is what I see (repeated 17 > > times): > > ... > > d:\devl\muds\testbed\completelibtest\thirdlibtest\lib\pythoninputhandler > > .h (153): init_module_PyInputHandler > > 0x10006C2B (File and line number not available): > > boost::python::detail::exception_handler::operator= > > 0x1000EC23 (File and line number not available): > > boost::python::detail::init_module > > 0x1E0682B1 (File and line number not available): PyImport_FindModule > > 0x48747570 (File and line number not available): (Function name > > unavailable) > > Data: > > ... (whatever data leaked) > > I believe these leaks are not actually leaks, but a documented > (http://www.boost.org/libs/python/todo.html) feature of Boost.Python, > directly connected to the lack of support for PyFinalize(). I think > what you are seeing as leaks are actually just entries in the global > converter registry. These are one-time static allocations. Since you > cannot dlopen the same module multiple times there is no danger that > these allocations become a real problem. See also: > boost/libs/python/src/converter/registry.cpp > > Why is PyFinalize() support missing? -- Simply because the groups who > invested money into Boost.Python development had no interest in > embedding. > > To find real leaks, please consider my very simple approach of calling > the code with the suspected problem in an infinite loop while > monitoring the memory allocation of the process. Simple, quick, very > effective, works the same on all platforms. I've done it many times, > coincidentally a couple of days ago while testing new low-level code. > I didn't see any real leaks. > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ From dave at boost-consulting.com Thu Oct 13 16:31:38 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 13 Oct 2005 10:31:38 -0400 Subject: [C++-sig] setting up held smart pointer for pure virtual base class References: <51d017870510121731w1968f275td80a3fed6f565dd5@mail.gmail.com> Message-ID: Scott McKay writes: > I have a pure virtual base class (so no_init is set). There's no such thing. I assume you mean an abstract base class? > The base class is held by a smart pointer. You mean in its Python wrapper class? > I want to implement that class in python. Do you mean you want to derive from that class in python? > I know that calling the __init__ function of the base class sets up the > smart pointer that is held by boost::python. Yes. > Is there some other way to set that up given the base class has no __init__ > function? Nope. > If it isn't setup I get an ArgumentError as the types don't match. > > If I make the base class virtual (by providing dummy implementations for > what were the pure virtual functions) That's not a virtual base class. A virtual base class is: // This-----------V class A : virtual B { ... }; > and call the __init__ everything works. You need to expose an __init__ so derived classes can initialize the base; there are no two ways about it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Oct 13 16:37:10 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 13 Oct 2005 10:37:10 -0400 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE References: <000001c5cfc7$fb14c0d0$210110ac@CROW> Message-ID: writes: > Hey again, I'm back. > > I've moved on to building an extension dll file in order to supplement > my embedded application. Once again, I've got memory leaks. > > However, this is an easy one to test using your method of calling a > function over and over. I did this and it chewed up the memory in my > system like a hog (at least in task manager I see Python.exe growing > steadily in memory consumption). > > Here is some pseudo-code of what I'm doing: Not the actual code? Please post actual, minimal code that fails. > class A > { > public: > void SetString(const std::string &sVal) > { > m_sString = sVal; <--- Memory leak I very much doubt that this line actually leaks memory unless there's a bug in your compiler's standard library implementation. > } > > void DoStuff() > { > SetString(msc_sString); > } > protected: > static const std::string msc_sString; > } > > class B > { > public: > object CreateClassA() > { > return object(new CreateClassA()); <---- memory leak AFAICT this one isn't even legal C++, so I doubt it leaks memory also ;-) However, object(new X) definitely leaks memory, for any X. When converting a pointer to Python, by default the pointee is copied into a new Python object, so the original pointer you dynamically allocated will always be leaked. -- Dave Abrahams Boost Consulting www.boost-consulting.com From skottmckay at gmail.com Thu Oct 13 17:28:12 2005 From: skottmckay at gmail.com (Scott McKay) Date: Thu, 13 Oct 2005 09:28:12 -0600 Subject: [C++-sig] setting up held smart pointer for pure virtual base class In-Reply-To: References: <51d017870510121731w1968f275td80a3fed6f565dd5@mail.gmail.com> Message-ID: <51d017870510130828q2a2d320and104fdd9a1fe2962@mail.gmail.com> > > I have a pure virtual base class (so no_init is set). > There's no such thing. I assume you mean an abstract base class? > Sorry for the loose terminology. Yes, an abstract base class. > The base class is held by a smart pointer. > > You mean in its Python wrapper class? Correct. > I want to implement that class in python. > > Do you mean you want to derive from that class in python? > Yes. Derive from it to implement the interface it defines. You need to expose an __init__ so derived classes can initialize the > base; there are no two ways about it. Fair enough. Thanks for the answer (and attempting to translate my poor terminology). S -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Thu Oct 13 17:59:14 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 13 Oct 2005 08:59:14 -0700 (PDT) Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: <000001c5cfc7$fb14c0d0$210110ac@CROW> Message-ID: <20051013155914.43599.qmail@web31505.mail.mud.yahoo.com> --- mjkeyes at sbcglobal.net wrote: > Hey again, I'm back. Hi Arnold! :) > Here is some pseudo-code of what I'm doing: Could you please turn this into a self-contained reproducer? Please explain exactly how you compile and link. Note that you have to be very careful to not mix debug and release builds under Windows. > class A > { > public: > void SetString(const std::string &sVal) > { > m_sString = sVal; <--- Memory leak I am doing things like this all the time and I am sure it doesn't leak for me. > } > > void DoStuff() > { > SetString(msc_sString); > } > protected: > static const std::string msc_sString; > } Probably a side issue: do you really want "static" here? > > class B > { > public: > object CreateClassA() > { > return object(new CreateClassA()); <---- memory leak What is this? Does this even compile? In any event, of course you get a memory leak if you use new like that. Ideally, you don't have any "unencapsulated" new in your code. Always use boost::shared_ptr(new T) or std::auto_ptr<>(new T) or any other smart pointer. > Any suggestions? I'm not getting any errors from the interpreter. We need a complete reproducer. Cheers, Ralf __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/ From Keyes at simcrest.com Fri Oct 14 00:17:52 2005 From: Keyes at simcrest.com (Matthew B. Keyes) Date: Thu, 13 Oct 2005 17:17:52 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <6A26270516DF054BBB3B87AE01C831EC2CCBD0@SERVER01.simcrest.int> Sorry guys, it was late when I posted this, so the typo: return object(new CreateClassA()); Meant to be: return object(new A()); I was under the impression that the object class functioned as a reference counting auto_ptr of sorts... That solves that one for me. I'll post more later on the string issue 'cause I'm out of time right now. Thanks for the help! "Ralf W. Grosse-Kunstleve" wrote in message news:<20051013155914.43599.qmail at web31505.mail.mud.yahoo.com>... > --- mjkeyes at sbcglobal.net wrote: > > > Hey again, I'm back. > > Hi Arnold! :) > > > Here is some pseudo-code of what I'm doing: > > Could you please turn this into a self-contained reproducer? Please explain > exactly how you compile and link. Note that you have to be very careful to not > mix debug and release builds under Windows. > > > class A > > { > > public: > > void SetString(const std::string &sVal) > > { > > m_sString = sVal; <--- Memory leak > > I am doing things like this all the time and I am sure it doesn't leak for me. > > > } > > > > void DoStuff() > > { > > SetString(msc_sString); > > } > > protected: > > static const std::string msc_sString; > > } > > Probably a side issue: do you really want "static" here? > > > > > class B > > { > > public: > > object CreateClassA() > > { > > return object(new CreateClassA()); <---- memory leak > > What is this? Does this even compile? > In any event, of course you get a memory leak if you use new like that. > Ideally, you don't have any "unencapsulated" new in your code. Always use > boost::shared_ptr(new T) or std::auto_ptr<>(new T) or any other smart > pointer. > > > Any suggestions? I'm not getting any errors from the interpreter. > > We need a complete reproducer. > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ From grafik.list at redshift-software.com Fri Oct 14 01:20:22 2005 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 13 Oct 2005 18:20:22 -0500 Subject: [C++-sig] Wrapping a class with private operator&() In-Reply-To: References: Message-ID: <434EEBB6.2080507@redshift-software.com> David Abrahams wrote: > David Abrahams writes: > >>>Here is a minimal example that shows the problem: >> >>In the enclosed patch, I replaced enough uses of "&" with addressof to >>make your example compile, but I'm almost certain there will be other >>such instances. If you try it and it works for you, I'll check it in. > > Done. That seems to have caused some problem on CodeWarrior compilers using MSL... http://engineering.meta-comm.com/boost-regression/CVS-RC_1_33_0/developer/output/sslapeta-bin-boost-libs-python-test-pointer_vector-test-cw-9_4-debug-threading-multi_release.html -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org From mjkeyes at sbcglobal.net Fri Oct 14 06:35:19 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Thu, 13 Oct 2005 23:35:19 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <000001c5d078$aee62b20$210110ac@CROW> Okay, I solved the second problem. Turns out it's something I wouldn't expect. Here's the situation - I have a C++ extended class to use in Python called AccountMgr. When I define a Python class, I do something like this: from MyModule import BaseClass #another extended class from C++ from MyModule import AccountMgr class MyClass(BaseClass): def UseAccountMgr(self): self.acctMgr.DoSomething() acctMgr = AccountMgr() Whenever this module is imported from another, it constructs the acctMgr object (even if I haven't instanced MyClass yet). However, this destructor is never called (I'm guessing because Py_Finalize isn't implemented?). Two followup questions: 1. How should I handle the construction of the acctMgr (or any other extended member variable in a Python class)? I tried supplying an __init__(self) function, but I get some interpreter errors about converting the C++ class to Python. Consequently, for now, I do something like this: class MyClass(BaseClass): def UseAccountMgr(self): if self.acctMgr == None: self.acctMgr = AccountMgr() self.acctMgr.DoSomething() acctMgr = None Can I declare the member variable as self.acctMgr = AccountMgr()? I haven't tried it. 2. Please offer any comments on the Python code above. I'm not green when it comes to C++, but I've only been using Python for about a week, so a little code review here would be helpful. Thanks again! "Matthew B. Keyes" wrote in message news:<6A26270516DF054BBB3B87AE01C831EC2CCBD0 at SERVER01.simcrest.int>... > Sorry guys, it was late when I posted this, so the typo: > > return object(new CreateClassA()); > > Meant to be: > > return object(new A()); > > I was under the impression that the object class functioned as a > reference counting auto_ptr of sorts... That solves that one for me. > > I'll post more later on the string issue 'cause I'm out of time right > now. Thanks for the help! > > "Ralf W. Grosse-Kunstleve" wrote in message > news:<20051013155914.43599.qmail at web31505.mail.mud.yahoo.com>... > > --- mjkeyes at sbcglobal.net wrote: > > > > > Hey again, I'm back. > > > > Hi Arnold! :) > > > > > Here is some pseudo-code of what I'm doing: > > > > Could you please turn this into a self-contained reproducer? Please > explain > > exactly how you compile and link. Note that you have to be very > careful to not > > mix debug and release builds under Windows. > > > > > class A > > > { > > > public: > > > void SetString(const std::string &sVal) > > > { > > > m_sString = sVal; <--- Memory leak > > > > I am doing things like this all the time and I am sure it doesn't > > leak > for me. > > > > > } > > > > > > void DoStuff() > > > { > > > SetString(msc_sString); > > > } > > > protected: > > > static const std::string msc_sString; > > > } > > > > Probably a side issue: do you really want "static" here? > > > > > > > > class B > > > { > > > public: > > > object CreateClassA() > > > { > > > return object(new CreateClassA()); <---- memory leak > > > > What is this? Does this even compile? > > In any event, of course you get a memory leak if you use new like > that. > > Ideally, you don't have any "unencapsulated" new in your code. > > Always > use > > boost::shared_ptr(new T) or std::auto_ptr<>(new T) or any other > smart > > pointer. > > > > > Any suggestions? I'm not getting any errors from the interpreter. > > > > We need a complete reproducer. > > > > Cheers, > > Ralf > > > > > > > > > > __________________________________ > > Yahoo! Music Unlimited > > Access over 1 million songs. Try it free. > > http://music.yahoo.com/unlimited/ From mjkeyes at sbcglobal.net Fri Oct 14 07:04:11 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Fri, 14 Oct 2005 00:04:11 -0500 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE Message-ID: <000001c5d07c$b774e2a0$210110ac@CROW> *********My apologies... The whitespace in my code was stripped (which makes the Python difficult to read) Here is the message again: Okay, I solved the second problem. Turns out it's something I wouldn't expect. Here's the situation - I have a C++ extended class to use in Python called AccountMgr. When I define a Python class, I do something like this: >>> from MyModule import BaseClass #another extended class from C++ >>> from MyModule import AccountMgr >>> class MyClass(BaseClass): >>> def UseAccountMgr(self): >>> self.acctMgr.DoSomething() >>> acctMgr = AccountMgr() Whenever this module is imported from another, it constructs the acctMgr object (even if I haven't instanced MyClass yet). However, this destructor is never called (I'm guessing because Py_Finalize isn't implemented?). Two followup questions: 1. How should I handle the construction of the acctMgr (or any other extended member variable in a Python class)? I tried supplying an __init__(self) function, but I get some interpreter errors about converting the C++ class to Python. Consequently, for now, I do something like this: >>> class MyClass(BaseClass): >>> def UseAccountMgr(self): >>> if self.acctMgr == None: >>> self.acctMgr = AccountMgr() >>> self.acctMgr.DoSomething() >>> acctMgr = None Can I declare the member variable as self.acctMgr = AccountMgr()? I haven't tried it. 2. Please offer any comments on the Python code above. I'm not green when it comes to C++, but I've only been using Python for about a week, so a little code review here would be helpful. Thanks again! wrote in message news:<000001c5d078$aee62b20$210110ac at CROW>... > Okay, I solved the second problem. Turns out it's something I > wouldn't expect. > > Here's the situation - I have a C++ extended class to use in Python > called AccountMgr. When I define a Python class, I do something like > this: > > from MyModule import BaseClass #another extended class from C++ from > MyModule import AccountMgr > > class MyClass(BaseClass): > def UseAccountMgr(self): > self.acctMgr.DoSomething() > > acctMgr = AccountMgr() > > Whenever this module is imported from another, it constructs the > acctMgr object (even if I haven't instanced MyClass yet). However, > this destructor is never called (I'm guessing because Py_Finalize > isn't implemented?). > > Two followup questions: > 1. How should I handle the construction of the acctMgr (or any other > extended member variable in a Python class)? I tried supplying an > __init__(self) function, but I get some interpreter errors about > converting the C++ class to Python. Consequently, for now, I do > something like this: > > class MyClass(BaseClass): > def UseAccountMgr(self): > if self.acctMgr == None: > self.acctMgr = AccountMgr() > self.acctMgr.DoSomething() > > acctMgr = None > > Can I declare the member variable as self.acctMgr = AccountMgr()? I > haven't tried it. > > 2. Please offer any comments on the Python code above. I'm not green > when it comes to C++, but I've only been using Python for about a > week, so a little code review here would be helpful. > > Thanks again! > > > "Matthew B. Keyes" wrote in message > news:<6A26270516DF054BBB3B87AE01C831EC2CCBD0 at SERVER01.simcrest.int>... > > Sorry guys, it was late when I posted this, so the typo: > > > > return object(new CreateClassA()); > > > > Meant to be: > > > > return object(new A()); > > > > I was under the impression that the object class functioned as a > > reference counting auto_ptr of sorts... That solves that one for me. > > > > I'll post more later on the string issue 'cause I'm out of time > > right > > now. Thanks for the help! > > > > "Ralf W. Grosse-Kunstleve" wrote in message > > news:<20051013155914.43599.qmail at web31505.mail.mud.yahoo.com>... > > > --- mjkeyes at sbcglobal.net wrote: > > > > > > > Hey again, I'm back. > > > > > > Hi Arnold! :) > > > > > > > Here is some pseudo-code of what I'm doing: > > > > > > Could you please turn this into a self-contained reproducer? > > > Please > > explain > > > exactly how you compile and link. Note that you have to be very > > careful to not > > > mix debug and release builds under Windows. > > > > > > > class A > > > > { > > > > public: > > > > void SetString(const std::string &sVal) > > > > { > > > > m_sString = sVal; <--- Memory leak > > > > > > I am doing things like this all the time and I am sure it doesn't > > > leak > > for me. > > > > > > > } > > > > > > > > void DoStuff() > > > > { > > > > SetString(msc_sString); > > > > } > > > > protected: > > > > static const std::string msc_sString; > > > > } > > > > > > Probably a side issue: do you really want "static" here? > > > > > > > > > > > class B > > > > { > > > > public: > > > > object CreateClassA() > > > > { > > > > return object(new CreateClassA()); <---- memory leak > > > > > > What is this? Does this even compile? > > > In any event, of course you get a memory leak if you use new like > > that. > > > Ideally, you don't have any "unencapsulated" new in your code. > > > Always > > use > > > boost::shared_ptr(new T) or std::auto_ptr<>(new T) or any other > > smart > > > pointer. > > > > > > > Any suggestions? I'm not getting any errors from the > > > > interpreter. > > > > > > We need a complete reproducer. > > > > > > Cheers, > > > Ralf > > > > > > > > > > > > > > > __________________________________ > > > Yahoo! Music Unlimited > > > Access over 1 million songs. Try it free. > > > http://music.yahoo.com/unlimited/ From lxu4net at gmail.com Fri Oct 14 08:09:45 2005 From: lxu4net at gmail.com (Liang Xu) Date: Fri, 14 Oct 2005 14:09:45 +0800 Subject: [C++-sig] [newbie] Question on thread-safe and embedding/extending with boost::python Message-ID: <6c98e4430510132309u279fd310m@mail.gmail.com> Hi all -- I'm working on an application that is embedding and extending with boost:python for extendability. I is dividing my requirments to the part of features and the part of business rules. The feature is what can i do and the business rule is when do i. The features are stable and the business rules are volatile. I is plan to implement the feature as a C++ method of domain object and the business rule in python script. The domain object's state is saved in C++ code. When The C++ code has received a event, it pass the event and the c++ object as context to python script. The script judge the state of the C++ object then call the C++ method. I have spend two weeks in the research and i have writed a simple application to validate it. But i'm newbie in python and boost.python. I have some questions : 1. Is the solution a good idea? I select the mixed solution because i haven't the experience in python and i really need the extendability. 2. Is it working in multithread application. From "Python/C API Reference Manual -- 8.1 Thread State and the Global Interpreter Lock", i read "The Python interpreter is not fully thread safe. In order to support multi-threaded Python programs, there's a global lock that must be held by the current thread before it can safely access Python objects. Without the lock, even the simplest operations could cause problems in a multi-threaded program: for example, when two threads simultaneously increment the reference count of the same object, the reference count could end up being incremented only once instead of twice. ". But in my application the python object is stateic and readonly after initial, and i just call method that is thread-safe in C++. Can i call the python method in multithread without lock? Or i can use an interpreter on each thread? Attachments are my test application code. -- Liang Xu -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: testPython.cpp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: statechart.py URL: From brakhane at googlemail.com Fri Oct 14 12:49:25 2005 From: brakhane at googlemail.com (Dennis Brakhane) Date: Fri, 14 Oct 2005 12:49:25 +0200 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE In-Reply-To: <000001c5d07c$b774e2a0$210110ac@CROW> References: <000001c5d07c$b774e2a0$210110ac@CROW> Message-ID: <434F8D35.6050708@googlemail.com> mjkeyes at sbcglobal.net wrote: >>>> acctMgr = AccountMgr() This defines MyClass.acctMgr as an instance of AccountMgr. And of course this is created when MyClass is defined. You probably meant: def __init__(self): self.acctMgr = AccountMgr() From s_sourceforge at nedprod.com Fri Oct 14 12:42:37 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 14 Oct 2005 11:42:37 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <434F99AD.3646.1733E9CC@localhost> On 12 Oct 2005 at 11:41, David Abrahams wrote: > > Any movement on the below? Do you want me to submit a patch to > > type_traits or just to BPL? > > >> 1. The best solution is to patch type_traits::add_reference<> with a > >> specialisation for void whereby it won't ever add a reference to a > >> void. AFAIK it's an illegal type anyway. > > I am surprised that add_reference doesn't already act that way. If > that is enough to fix your problem, I think you should post, and we > should accept, the patch. You were right that add_reference /does/ already act that way. I tried a test example with the same form as the bug and no matter what I do, the compiler compiles it just fine. Whatever is going on, it seems that you need to be deep down inside BPL to see it :( The easiest solution is a specialisation for const volatile void, exampled by the attached registered.hpp. Cheers, Niall -------------- next part -------------- // Copyright David Abrahams 2002. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef REGISTERED_DWA2002710_HPP # define REGISTERED_DWA2002710_HPP # include # include # include # include # include # include namespace boost { // You'll see shared_ptr mentioned in this header because we need to // note which types are shared_ptrs in their registrations, to // implement special shared_ptr handling for rvalue conversions. template class shared_ptr; namespace python { namespace converter { struct registration; namespace detail { template struct registered_base { static registration const& converters; }; } template struct registered : detail::registered_base< typename add_reference< typename add_cv::type >::type > { }; # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) // collapses a few more types to the same static instance. MSVC7.1 // fails to strip cv-qualification from array types in typeid. For // some reason we can't use this collapse there or array converters // will not be found. template struct registered : registered {}; # endif // // implementations // namespace detail { inline void register_shared_ptr0(...) { } template inline void register_shared_ptr0(shared_ptr*) { registry::lookup_shared_ptr(type_id >()); } template inline void register_shared_ptr1(T const volatile*) { detail::register_shared_ptr0((T*)0); } template registration const& registry_lookup() { detail::register_shared_ptr1((T*)0); return registry::lookup(type_id()); } template <> registration const& registry_lookup() { detail::register_shared_ptr1((void*)0); return registry::lookup(type_id()); } template registration const& registered_base::converters = detail::registry_lookup::type>(); } }}} // namespace boost::python::converter #endif // REGISTERED_DWA2002710_HPP From dave at boost-consulting.com Fri Oct 14 17:03:24 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 14 Oct 2005 11:03:24 -0400 Subject: [C++-sig] Wrapping a class with private operator&() References: <434EEBB6.2080507@redshift-software.com> Message-ID: Rene Rivera writes: > David Abrahams wrote: >> David Abrahams writes: >> >>>>Here is a minimal example that shows the problem: >>> >>>In the enclosed patch, I replaced enough uses of "&" with addressof to >>>make your example compile, but I'm almost certain there will be other >>>such instances. If you try it and it works for you, I'll check it in. >> >> Done. > > That seems to have caused some problem on CodeWarrior compilers using MSL... > > http://engineering.meta-comm.com/boost-regression/CVS-RC_1_33_0/developer/output/sslapeta-bin-boost-libs-python-test-pointer_vector-test-cw-9_4-debug-threading-multi_release.html Great; ADL bites again :( I'll fix it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 14 17:07:32 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 14 Oct 2005 11:07:32 -0400 Subject: [C++-sig] Memory Leaks In VS.NET 2003 With BOOST_PYTHON_MODULE References: <000001c5d07c$b774e2a0$210110ac@CROW> Message-ID: writes: > *********My apologies... The whitespace in my code was stripped (which > makes the Python difficult to read) Here is the message again: The first message looked fine to me. Maybe it's your mail/news reader that's stripping whitespace on incoming messages. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 14 17:08:53 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 14 Oct 2005 11:08:53 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <434F99AD.3646.1733E9CC@localhost> Message-ID: "Niall Douglas" writes: > On 12 Oct 2005 at 11:41, David Abrahams wrote: > >> > Any movement on the below? Do you want me to submit a patch to >> > type_traits or just to BPL? >> >> >> 1. The best solution is to patch type_traits::add_reference<> with a >> >> specialisation for void whereby it won't ever add a reference to a >> >> void. AFAIK it's an illegal type anyway. >> >> I am surprised that add_reference doesn't already act that way. If >> that is enough to fix your problem, I think you should post, and we >> should accept, the patch. > > You were right that add_reference /does/ already act that way. I > tried a test example with the same form as the bug and no matter what > I do, the compiler compiles it just fine. > > Whatever is going on, it seems that you need to be deep down inside > BPL to see it :( > > The easiest solution is a specialisation for const volatile void, > exampled by the attached registered.hpp. Please post a unified diff, so I can easily see what change you're proposing. Thanks, Dave -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Fri Oct 14 19:13:25 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 14 Oct 2005 18:13:25 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <434FF545.25151.1899B5ED@localhost> On 14 Oct 2005 at 11:08, David Abrahams wrote: > > The easiest solution is a specialisation for const volatile void, > > exampled by the attached registered.hpp. > > Please post a unified diff, so I can easily see what change you're > proposing. Attached. Cheers, Niall -------------- next part -------------- --- registered.hpp 2005-05-18 02:34:36.000000000 +0100 +++ registered_.hpp 2005-10-01 00:54:37.000000000 +0100 @@ -78,14 +78,23 @@ template registration const& - registry_lookup(T&(*)()) + registry_lookup() { detail::register_shared_ptr1((T*)0); return registry::lookup(type_id()); } + template <> + registration const& + registry_lookup() + { + detail::register_shared_ptr1((void*)0); + return registry::lookup(type_id()); + } + template - registration const& registered_base::converters = detail::registry_lookup((T(*)())0); + registration const& registered_base::converters = detail::registry_lookup::type>(); + } }}} // namespace boost::python::converter From dave at boost-consulting.com Fri Oct 14 23:29:01 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 14 Oct 2005 17:29:01 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <434FF545.25151.1899B5ED@localhost> Message-ID: "Niall Douglas" writes: > On 14 Oct 2005 at 11:08, David Abrahams wrote: > >> > The easiest solution is a specialisation for const volatile void, >> > exampled by the attached registered.hpp. >> >> Please post a unified diff, so I can easily see what change you're >> proposing. > > Attached. > > Cheers, > Niall Sorry, I can't accept that patch; it will break vc6 and vc7 at the very least. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Sat Oct 15 02:45:38 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 15 Oct 2005 01:45:38 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <43505F42.24419.F1246@localhost> On 14 Oct 2005 at 17:29, David Abrahams wrote: > Sorry, I can't accept that patch; it will break vc6 and vc7 at the > very least. It would be useful to tell me why so I can go fix it. I no longer have vc6 available to me. I didn't use partial template specialisation, so where is the breakage? Cheers, Niall From roman.yakovenko at gmail.com Sun Oct 16 07:03:35 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 16 Oct 2005 07:03:35 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> Message-ID: <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> On 10/12/05, David Abrahams wrote: > Could you please post a minimal, complete example that you think > should work? Yes of course. See attached files. C++ code to be exported smart_pointers_to_be_exported.hpp smart_pointers_to_be_exported.cpp boost.python wrappers: smart_pointers.cpp In order to show my point file smart_pointers.cpp could not be compiled. If you want it to be compiled uncomment PyObject* argument in wrapper constructors. An other way you can see my point to update boost.python unittests to use wrapper class. > Thanks, > Dave > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com Thanks for help Roman Yakovenko From roman.yakovenko at gmail.com Sun Oct 16 08:33:08 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 16 Oct 2005 08:33:08 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> Message-ID: <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> Sorry I forgot to attach files. On 10/16/05, Roman Yakovenko wrote: > On 10/12/05, David Abrahams wrote: > > > Could you please post a minimal, complete example that you think > > should work? > > Yes of course. See attached files. > > C++ code to be exported > > smart_pointers_to_be_exported.hpp > smart_pointers_to_be_exported.cpp > > boost.python wrappers: > > smart_pointers.cpp > > In order to show my point file smart_pointers.cpp could not be compiled. > If you want it to be compiled uncomment PyObject* argument in wrapper > constructors. > > An other way you can see my point to update boost.python unittests to > use wrapper > class. > > > Thanks, > > Dave > > > > -- > > Dave Abrahams > > Boost Consulting > > www.boost-consulting.com > > Thanks for help > > Roman Yakovenko > -------------- next part -------------- #ifndef __smart_pointers_to_be_exported_hpp__ #define __smart_pointers_to_be_exported_hpp__ #include #include "boost/shared_ptr.hpp" namespace smart_pointers{ struct base{ base() : base_value(19) {} int base_value; virtual int get_base_value(){ return base_value; } }; struct data : base{ data() : value(11){} int value; virtual int get_value(){ return value; } }; typedef std::auto_ptr< base > base_a_ptr; typedef boost::shared_ptr< base > base_s_ptr; typedef std::auto_ptr< data > data_a_ptr; typedef boost::shared_ptr< data > data_s_ptr; data_a_ptr create_auto(); data_s_ptr create_shared(); int ref_auto( data_a_ptr& a ); int ref_shared( data_s_ptr& a ); int val_auto( data_a_ptr a ); int val_shared( data_s_ptr a ); int const_ref_auto( const data_a_ptr& a ); int const_ref_shared( const data_s_ptr& a ); int ref_auto_base_value( base_a_ptr& a ); int ref_shared_base_value( base_s_ptr& a ); int val_auto_base_value( base_a_ptr a ); int val_shared_base_value( base_s_ptr a ); int const_ref_auto_base_value( const base_a_ptr& a ); int const_ref_shared_base_value( const base_s_ptr& a ); } #endif//__smart_pointers_to_be_exported_hpp__ -------------- next part -------------- #include "smart_pointers_to_be_exported.hpp" namespace smart_pointers{ data_a_ptr create_auto(){ return data_a_ptr( new data() ); } data_s_ptr create_shared(){ return data_s_ptr( new data() ); } int ref_auto( data_a_ptr& a ){ return a->get_value(); } int ref_shared( data_s_ptr& a ){ return a->get_value(); } int val_auto( data_a_ptr a ){ return a->get_value(); } int val_shared( data_s_ptr a ){ return a->get_value(); } int const_ref_auto( const data_a_ptr& a ){ return a->get_value(); } int const_ref_shared( const data_s_ptr& a ){ return a->get_value(); } int ref_auto_base_value( base_a_ptr& a ){ return a->get_base_value(); } int ref_shared_base_value( base_s_ptr& a ){ return a->get_base_value(); } int val_auto_base_value( base_a_ptr a ){ return a->get_base_value(); } int val_shared_base_value( base_s_ptr a ){ return a->get_base_value(); } int const_ref_auto_base_value( const base_a_ptr& a ){ return a->get_base_value(); } int const_ref_shared_base_value( const base_s_ptr& a ){ return a->get_base_value(); } } -------------- next part -------------- //std directories: ['d:\\boost_cvs', 'c:\\python\\include'] //user defined directories: ['d:\\pygccxml_sources\\source\\pyplusplus'] #include "boost/python.hpp" #include "unittests/data/smart_pointers_to_be_exported.hpp" namespace bp = boost::python; struct base_wrapper : smart_pointers::base, bp::wrapper< smart_pointers::base > { base_wrapper(/*PyObject**/, smart_pointers::base const & arg ) : smart_pointers::base( arg ) , bp::wrapper< smart_pointers::base >() {} base_wrapper(/*PyObject**/ ) : smart_pointers::base( ) , bp::wrapper< smart_pointers::base >() {} virtual int get_base_value( ){ if( bp::override get_base_value = this->get_override( "get_base_value" ) ) return get_base_value( ); else return smart_pointers::base::get_base_value( ); } virtual int default_get_base_value( ){ return this->smart_pointers::base::get_base_value( ); } }; struct data_wrapper : smart_pointers::data, bp::wrapper< smart_pointers::data > { data_wrapper(/*PyObject**/, smart_pointers::data const & arg ) : smart_pointers::data( arg ) , bp::wrapper< smart_pointers::data >() {} data_wrapper(/*PyObject**/ ) : smart_pointers::data( ) , bp::wrapper< smart_pointers::data >() {} virtual int get_value( ){ if( bp::override get_value = this->get_override( "get_value" ) ) return get_value( ); else return smart_pointers::data::get_value( ); } virtual int default_get_value( ){ return this->smart_pointers::data::get_value( ); } }; BOOST_PYTHON_MODULE(smart_pointers){ bp::class_< smart_pointers::base, base_wrapper, boost::shared_ptr< smart_pointers::base > >( "base" ) .def( bp::init< >()[bp::default_call_policies()] ) .def( "get_base_value" , &smart_pointers::base::get_base_value , &::base_wrapper::default_get_base_value , bp::default_call_policies() ) .def_readwrite( "base_value", &smart_pointers::base::base_value ); bp::register_ptr_to_python< boost::shared_ptr< smart_pointers::base > >(); bp::register_ptr_to_python< std::auto_ptr< smart_pointers::base > >(); bp::class_< smart_pointers::data, data_wrapper, bp::bases< smart_pointers::base >, boost::shared_ptr< smart_pointers::data > >( "data" ) .def( bp::init< >()[bp::default_call_policies()] ) .def( "get_value" , &smart_pointers::data::get_value , &::data_wrapper::default_get_value , bp::default_call_policies() ) .def_readwrite( "value", &smart_pointers::data::value ); bp::register_ptr_to_python< boost::shared_ptr< smart_pointers::data > >(); bp::implicitly_convertible< boost::shared_ptr< smart_pointers::data >, boost::shared_ptr< smart_pointers::base > >(); bp::register_ptr_to_python< std::auto_ptr< smart_pointers::data > >(); bp::implicitly_convertible< std::auto_ptr< smart_pointers::data >, std::auto_ptr< smart_pointers::base > >(); } From dave at boost-consulting.com Mon Oct 17 10:10:22 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 17 Oct 2005 04:10:22 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/16/05, Roman Yakovenko wrote: >> On 10/12/05, David Abrahams wrote: >> >> > Could you please post a minimal, complete example that you think >> > should work? >> >> Yes of course. See attached files. I'm sorry, that looks neither minimal nor complete. What I need is: one C++ file that, when compiled and linked with Boost.Python, creates an extension module one Python file that loads the extension module and does something. a description of what you expected the Python file to do, and what happens instead I'm _sure_ you can illustrate your point with just a few functions and one (or at most two) classes. No? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Oct 17 17:34:28 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 17 Oct 2005 11:34:28 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <43505F42.24419.F1246@localhost> Message-ID: "Niall Douglas" writes: > On 14 Oct 2005 at 17:29, David Abrahams wrote: > >> Sorry, I can't accept that patch; it will break vc6 and vc7 at the >> very least. > > It would be useful to tell me why so I can go fix it. I no longer > have vc6 available to me. > > I didn't use partial template specialisation, so where is the > breakage? At least in the near term, remove_reference relies on PTS. Also BOOST_NO_CV_VOID_SPECIALIZATIONS is defined for vc6/7, so your specialization will fail. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Mon Oct 17 20:16:44 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 17 Oct 2005 19:16:44 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <4353F89C.7240.E1E1775@localhost> On 17 Oct 2005 at 11:34, David Abrahams wrote: > > I didn't use partial template specialisation, so where is the > > breakage? > > At least in the near term, remove_reference relies on PTS. Also > BOOST_NO_CV_VOID_SPECIALIZATIONS is defined for vc6/7, so your > specialization will fail. Would you accept a patch whereby void * worked on MSVC7.1 and later but not before? In other words, I find a way to not use remove_reference and make the specialisation #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS. At least it wouldn't be any worse for vc6/7 than now. Cheers, Niall From dave at boost-consulting.com Mon Oct 17 21:46:18 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 17 Oct 2005 15:46:18 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <4353F89C.7240.E1E1775@localhost> Message-ID: "Niall Douglas" writes: > On 17 Oct 2005 at 11:34, David Abrahams wrote: > >> > I didn't use partial template specialisation, so where is the >> > breakage? >> >> At least in the near term, remove_reference relies on PTS. Also >> BOOST_NO_CV_VOID_SPECIALIZATIONS is defined for vc6/7, so your >> specialization will fail. > > Would you accept a patch whereby void * worked on MSVC7.1 and later > but not before? In other words, I find a way to not use > remove_reference and make the specialisation #ifndef > BOOST_NO_CV_VOID_SPECIALIZATIONS. > > At least it wouldn't be any worse for vc6/7 than now. Please just make it portable. It's not that hard. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Tue Oct 18 07:06:12 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Tue, 18 Oct 2005 00:06:12 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost and PythonUsing Derived Classes Message-ID: <000001c5d3a1$a96856b0$210110ac@CROW> When I use boost::python::import, I'm getting an unresolved external symbol linking error. Any advice? "David Abrahams" wrote in message news:... > "Matt" writes: > > > Hey all, > > > > i'm trying to create an application that both embeds and extends > > python through boost. i've got a rough framework up and running, > > but now that i'm finally to the python part i'm having troubles. > > Please know that i'm a noob to boost and to boost.python, so if you > > see any obvious noob idiocies in my code please point them out > > (we've all got to start learning somewhere :)). > > You should never be doing any Py_XINCREF or Py_XDECREF stuff when > using Boost.Python. Also, you're using an outdated approach to > supporting virtual functions. > > I suggest you follow the example of > http://www.boost-consulting.com/boost/libs/python/test/exec.cpp > > You'll need the latest Boost CVS state in order to use all the idioms > therein, though. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From mjkeyes at sbcglobal.net Tue Oct 18 07:15:34 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Tue, 18 Oct 2005 00:15:34 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost and PythonUsing Derived Classes Message-ID: <000001c5d3a2$f7e1f2f0$210110ac@CROW> One more note - I'm using the Visual Studio project included in the Boost folders for Python. Import.cpp was not part of this project - I added it, but I'm still getting the linking problems. "David Abrahams" wrote in message news:... > "Matt" writes: > > > Hey all, > > > > i'm trying to create an application that both embeds and extends > > python through boost. i've got a rough framework up and running, > > but now that i'm finally to the python part i'm having troubles. > > Please know that i'm a noob to boost and to boost.python, so if you > > see any obvious noob idiocies in my code please point them out > > (we've all got to start learning somewhere :)). > > You should never be doing any Py_XINCREF or Py_XDECREF stuff when > using Boost.Python. Also, you're using an outdated approach to > supporting virtual functions. > > I suggest you follow the example of > http://www.boost-consulting.com/boost/libs/python/test/exec.cpp > > You'll need the latest Boost CVS state in order to use all the idioms > therein, though. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From mjkeyes at sbcglobal.net Tue Oct 18 09:01:59 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Tue, 18 Oct 2005 02:01:59 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes Message-ID: <000001c5d3b1$d5af8850$210110ac@CROW> Sorry for the spam, but one final note: I used bjam and still got the linking error. If I add import.cpp to my project, the linking error goes away. Thoughts? I looked at the build files and see that exec.cpp and import.cpp have been added, but I'm still getting this linking error. wrote in message news:<000001c5d3a2$f7e1f2f0$210110ac at CROW>... > One more note - I'm using the Visual Studio project included in the > Boost folders for Python. Import.cpp was not part of this project - I > added it, but I'm still getting the linking problems. > > "David Abrahams" wrote in message > news:... > > "Matt" writes: > > > > > Hey all, > > > > > > i'm trying to create an application that both embeds and extends > > > python through boost. i've got a rough framework up and running, > > > but now that i'm finally to the python part i'm having troubles. > > > Please know that i'm a noob to boost and to boost.python, so if you > > > see any obvious noob idiocies in my code please point them out > > > (we've all got to start learning somewhere :)). > > > > You should never be doing any Py_XINCREF or Py_XDECREF stuff when > > using Boost.Python. Also, you're using an outdated approach to > > supporting virtual functions. > > > > I suggest you follow the example of > > http://www.boost-consulting.com/boost/libs/python/test/exec.cpp > > > > You'll need the latest Boost CVS state in order to use all the > > idioms > > therein, though. > > > > -- > > Dave Abrahams > > Boost Consulting > > www.boost-consulting.com From dave at boost-consulting.com Tue Oct 18 13:57:53 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 18 Oct 2005 07:57:53 -0400 Subject: [C++-sig] Issues with Overloading with Boost References: Message-ID: "Dirgesh Patel" writes: > I have listed many questions about overloading in the gmane.comp.python.c++ > newsgroup. > > Yet i still have not found a cure for my issue. The problem that I am having > is I have a function called > > bkimage* copy(bkimage *img, > xint32_t pln0, xint32_t row0, xint32_t col0, > xint32_t pln1, xint32_t row1, xint32_t col1) > > then i have a boost.cpp file which is running this line > > BOOST_PYTHON_FUNCTION_OVERLOADS(imageMorph_copy, copy, 1, 7) > and > def("copy", copy, imageMorph_copy() > [return_value_policy()] ); > > yet i still get errors Dirgesh, Part of the reason you're not getting better answers here may be that there isn't enough information in your question to see what the problem is. If you can post to gmane.comp.python.c++ the errors you're seeing with a minimal, complete example that fails for you, I'll try to help you sort it out. A minimal, complete example in this case would be a single .cpp file containing the declaration of copy, the use of BOOST_PYTHON_FUNCTION_OVERLOADS, and the call to def. Regards, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Oct 18 14:10:48 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 18 Oct 2005 08:10:48 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes References: <000001c5d3b1$d5af8850$210110ac@CROW> Message-ID: writes: > Sorry for the spam, but one final note: > > I used bjam and still got the linking error. With Boost.Build v1 or v2? The Jamfile.v2 for Boost.Python didn't include import.cpp and exec.cpp > If I add import.cpp to my project, What project? If you still have visual studio in the mix, I suggest you try to build everything with Boost.Build (as the Boost.Python build instructions suggest) using one of the Boost.Python tests or example files as a template. > the linking error goes away. Thoughts? I looked at the build > files and see that exec.cpp and import.cpp have been added, but I'm > still getting this linking error. What does the error say? -- Dave Abrahams Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Tue Oct 18 16:51:58 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 18 Oct 2005 10:51:58 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes In-Reply-To: <000001c5d3b1$d5af8850$210110ac@CROW> References: <000001c5d3b1$d5af8850$210110ac@CROW> Message-ID: <43550C0E.8000508@sympatico.ca> mjkeyes at sbcglobal.net wrote: > Sorry for the spam, but one final note: > > I used bjam and still got the linking error. If I add import.cpp to my > project, the linking error goes away. Thoughts? I looked at the build > files and see that exec.cpp and import.cpp have been added, but I'm > still getting this linking error. Sorry, that's still too vague to be of any help. The 'exec.cpp' test applet, which makes use of both, exec as well as import, gets built and run with bb1, and there are no linking errors on any of the tested platforms. I thus have no idea what could be the cause of the failure you are seeing. It's most probably related to your build procedure. (But since I don't have MSVC I'm totally unqualified to help if the problem is related to that.) Regards, Stefan From Keyes at simcrest.com Tue Oct 18 20:48:15 2005 From: Keyes at simcrest.com (Matthew B. Keyes) Date: Tue, 18 Oct 2005 13:48:15 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes Message-ID: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> Here is how I built my extension/embedded application and extension dll with MS Visual Studio .NET 2003: -Use the MSVC project supplied with Boost.Python to build boost_python.dll -Link to the boost_python.lib file for both projects -Build (and everything works fine and runs well) Now, in trying to add the import function, I retrieved the latest Boost files from CVS. I initially tried to use the supplied MSVC project to build the boost_python.dll, but I received linking errors when I use the import function. Thus, I fired up bjam and let it build the boost_python.dll file. However, when I rebuild my project that uses import (the extension/embedded application), I still receive the linking error. If I add import.cpp to the project, the linking error goes away. I tried looking at the exec.cpp test applet via bjam, but I receive several errors on some of the other applets and it is very difficult to filter out all the command line chatter to see what happened with the exec applet. That said, I do take your word for it that it works. The specific linking error I receive is this: error LNK2019: unresolved external symbol "class boost::python::api::object __cdecl boost::python::import(class boost::python::str)" (?import at python@boost@@YA?AVobject at api@12 at Vstr@12@@Z) referenced in function "public: virtual bool __thiscall PythonLib::PythonLibObjectContainer::CreateInstanceOfObject(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &)" (?CreateInstanceOfObject at PythonLibObjectContainer@PythonLib@@UAE_NABV?$b asic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@0 at Z) PythonLib::PythonLibObjectContainer is a class I have to persist a Boost.Python object after the function call (it basically maps an extracted pointer to its object until the object is no longer needed). Not that that part is important, but I thought I'd clarify as to what is being stated on the error above. Like I said, I can include import.cpp into the project and it builds fine. That solution works, but it is not as desirable as leaving all the Boost.Python files out and simply including the .hpp files. Thanks for any additional help. "Stefan Seefeld" wrote in message news:<43550C0E.8000508 at sympatico.ca>... > mjkeyes at sbcglobal.net wrote: > > Sorry for the spam, but one final note: > > > > I used bjam and still got the linking error. If I add import.cpp to my > > project, the linking error goes away. Thoughts? I looked at the build > > files and see that exec.cpp and import.cpp have been added, but I'm > > still getting this linking error. > > Sorry, that's still too vague to be of any help. The 'exec.cpp' test applet, > which makes use of both, exec as well as import, gets built and run with bb1, > and there are no linking errors on any of the tested platforms. > > I thus have no idea what could be the cause of the failure you are seeing. > It's most probably related to your build procedure. (But since I don't have > MSVC I'm totally unqualified to help if the problem is related to that.) > > Regards, > Stefan From seefeld at sympatico.ca Tue Oct 18 21:14:43 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 18 Oct 2005 15:14:43 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes In-Reply-To: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> References: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> Message-ID: <435549A3.2010005@sympatico.ca> Matthew B. Keyes wrote: > Here is how I built my extension/embedded application and extension dll > with MS Visual Studio .NET 2003: > > -Use the MSVC project supplied with Boost.Python to build > boost_python.dll > -Link to the boost_python.lib file for both projects > -Build (and everything works fine and runs well) I added new exec, exec_file, and import functions to boost python a while ago, and I adjusted the bb1 build system accordingly. I wasn't aware of the fact that boost.org supplies MSVC project files. Are they officially maintained at all ? I'm not able to adjust the project file you are talking about to include the new source files, as I would be unable to test the changes. David, what's the official procedure here ? If MSVC project files are provided, can't they simply be wrappers that delegate to bb1/bb2 internally ? Thanks, Stefan From dave at boost-consulting.com Tue Oct 18 23:57:17 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 18 Oct 2005 17:57:17 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes References: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> <435549A3.2010005@sympatico.ca> Message-ID: Stefan Seefeld writes: > I added new exec, exec_file, and import functions to boost python a while > ago, and I adjusted the bb1 build system accordingly. > I wasn't aware of the fact that boost.org supplies MSVC project files. > Are they officially maintained at all ? http://www.boost.org/libs/python/doc/building.html#VisualStudio shows that they're maintained by Brett Calcott. > I'm not able to adjust the project > file you are talking about to include the new source files, as I would be > unable to test the changes. David, what's the official procedure > here ? Well, I changed the CVS. > If MSVC project files are provided, can't they simply be wrappers that > delegate to bb1/bb2 internally ? Heck if I know. Understanding one build system is more than enough for me. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Oct 18 23:58:00 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 18 Oct 2005 17:58:00 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes References: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> Message-ID: "Matthew B. Keyes" writes: > Here is how I built my extension/embedded application and extension dll > with MS Visual Studio .NET 2003: > > -Use the MSVC project supplied with Boost.Python to build > boost_python.dll > -Link to the boost_python.lib file for both projects > -Build (and everything works fine and runs well) > > Now, in trying to add the import function, I retrieved the latest Boost > files from CVS. I initially tried to use the supplied MSVC project to > build the boost_python.dll, but I received linking errors when I use the > import function. Thus, I fired up bjam and let it build the > boost_python.dll file. However, when I rebuild my project that uses > import (the extension/embedded application), I still receive the linking > error. If I add import.cpp to the project, the linking error goes away. > > I tried looking at the exec.cpp test applet via bjam, but I receive > several errors on some of the other applets and it is very difficult to > filter out all the command line chatter to see what happened with the > exec applet. That said, I do take your word for it that it works. > > The specific linking error I receive is this: > > error LNK2019: unresolved external symbol "class > boost::python::api::object __cdecl boost::python::import(class > boost::python::str)" > (?import at python@boost@@YA?AVobject at api@12 at Vstr@12@@Z) referenced in > function "public: virtual bool __thiscall > PythonLib::PythonLibObjectContainer::CreateInstanceOfObject(class > std::basic_string,class > std::allocator > const &,class std::basic_string std::char_traits,class std::allocator > const &)" > (?CreateInstanceOfObject at PythonLibObjectContainer@PythonLib@@UAE_NABV?$b > asic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@0 at Z) Then you're clearly linking with the old library you built with the IDE and not the one you built with bjam. -- Dave Abrahams Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Wed Oct 19 00:14:29 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 18 Oct 2005 18:14:29 -0400 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 With Boost andPythonUsing Derived Classes In-Reply-To: References: <6A26270516DF054BBB3B87AE01C831EC2CCC77@SERVER01.simcrest.int> <435549A3.2010005@sympatico.ca> Message-ID: <435573C5.5050905@sympatico.ca> David Abrahams wrote: > http://www.boost.org/libs/python/doc/building.html#VisualStudio > > shows that they're maintained by Brett Calcott. >>If MSVC project files are provided, can't they simply be wrappers that >>delegate to bb1/bb2 internally ? > > > Heck if I know. Understanding one build system is more than enough for me. In another life, when I was forced to work with MSVC, I modified the project settings to simply run 'make' underneath. As a consequence, I never again touched the project file(s), but only maintained the make-based build system. The same should be possible with MSVC vs. bb1/bb2. However, as I don't know what the reason is for boost.org to provide MSVC project files in the first place, I don't know whether the above strategy would help anybody at all. Regards, Stefan From mjkeyes at sbcglobal.net Wed Oct 19 03:33:41 2005 From: mjkeyes at sbcglobal.net (mjkeyes at sbcglobal.net) Date: Tue, 18 Oct 2005 20:33:41 -0500 Subject: [C++-sig] Nasty Heap Error in MSVC 7.1 WithBoost andPythonUsing Derived Classes Message-ID: <000001c5d44d$238c6160$210110ac@CROW> I thought that at first, too. I've done a search on my entire computer for every boost_python* file there is and deleted them, but the error remains after I build again with bjam. I'm going to look into it a bit further tonight and see if I can find any other differences. Thanks for all the help guys. "David Abrahams" wrote in message news:... > "Matthew B. Keyes" writes: > > > Here is how I built my extension/embedded application and extension > > dll with MS Visual Studio .NET 2003: > > > > -Use the MSVC project supplied with Boost.Python to build > > boost_python.dll -Link to the boost_python.lib file for both > > projects -Build (and everything works fine and runs well) > > > > Now, in trying to add the import function, I retrieved the latest > > Boost files from CVS. I initially tried to use the supplied MSVC > > project to build the boost_python.dll, but I received linking errors > > when I use the import function. Thus, I fired up bjam and let it > > build the boost_python.dll file. However, when I rebuild my project > > that uses import (the extension/embedded application), I still > > receive the linking error. If I add import.cpp to the project, the > > linking error goes away. > > > > I tried looking at the exec.cpp test applet via bjam, but I receive > > several errors on some of the other applets and it is very difficult > > to filter out all the command line chatter to see what happened with > > the exec applet. That said, I do take your word for it that it > > works. > > > > The specific linking error I receive is this: > > > > error LNK2019: unresolved external symbol "class > > boost::python::api::object __cdecl boost::python::import(class > > boost::python::str)" > > (?import at python@boost@@YA?AVobject at api@12 at Vstr@12@@Z) referenced in > > function "public: virtual bool __thiscall > > PythonLib::PythonLibObjectContainer::CreateInstanceOfObject(class > > std::basic_string,class > > std::allocator > const &,class std::basic_string > std::char_traits,class std::allocator > const &)" > > (?CreateInstanceOfObject at PythonLibObjectContainer@PythonLib@@UAE_NAB > > V?$b > > asic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@0 at Z) > > Then you're clearly linking with the old library you built with the > IDE and not the one you built with bjam. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From roman.yakovenko at gmail.com Wed Oct 19 07:38:12 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 19 Oct 2005 07:38:12 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> Message-ID: <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> On 10/17/05, David Abrahams wrote: > I'm sorry, that looks neither minimal nor complete. > I'm _sure_ you can illustrate your point with just a few functions and > one (or at most two) classes. No? Yes I am. I am sorry for being unclear. Before proceeding, I would like to clear something. What I am trying to show are problems with boost.python interface to user and not functionality. All code that I show works okay. I will try to explain my self here and I attached files you've asked. I am talking about next use case: I have class with virtual function. In order to override it's virtual function I use boost::python::wrapper. Also I'd like to have std::auto_ptr ( or shared_ptr ) as it's held type. Now code. My class: struct data{ virtual int id() const{ return int(this); } } namespace bp = boost::python; struct data_wrapper : data, bp::wrapper< data > { //If you remove PyObject* code will stop to compile data_wrapper(PyObject*, data const & arg ) //-------------^^^^^^^^^^^ //1. bp::wrapper< data > will hold PyObject* self by it self //2. I need it here because otherwise // bp::register_ptr_to_python< std::auto_ptr< data > >() will not compile. : data( arg ) , bp::wrapper< data >() {} data_wrapper(PyObject*) //same point here : data() , bp::wrapper< data >() {} ... } bp::class_< data, data_wrapper, std::auto_ptr< data > >( "data" ) //------------^^^^ //I see no reasons to give class data as argument to class_ //I do it only for HeldType functionality. Better interface could be without requiring //class data as argument The point is that you introduced new cool class wrapper, but not all code has been adopted to work with it. Also within documentation for example here http://boost.org/libs/python/doc/v2/register_ptr_to_python.html and here http://boost.org/libs/python/doc/v2/call_method.html you are using old method of "overriding" virtual function in Python. If you try to re-write those examples using boost::python::wrapper class you will see my point. Hope this time I was clear. > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com Thanks Roman Yakovenko -------------- next part -------------- #include "boost/python.hpp" #include struct data{ virtual int id() const{ return int(this); } }; std::auto_ptr create_data() { return std::auto_ptr( new data ); } void do_nothing( std::auto_ptr& ){} namespace bp = boost::python; struct data_wrapper : data, bp::wrapper< data > { //If you remove PyObject* code will stop to compile data_wrapper(PyObject*, data const & arg ) //-------------^^^^^^^^^^^ //1. bp::wrapper< data > will hold PyObject* self by it self //2. I need it here because otherwise bp::register_ptr_to_python< std::auto_ptr< data > >() // will not compile. : data( arg ) , bp::wrapper< data >() {} data_wrapper(PyObject*) //same point here : data() , bp::wrapper< data >() {} virtual int id( ) const { if( bp::override id = this->get_override( "id" ) ) return id( ); else return data::id( ); } virtual int default_id( ) const { return this->data::id( ); } }; BOOST_PYTHON_MODULE(xyz){ bp::class_< data, data_wrapper, std::auto_ptr< data > >( "data" ) //------------^^^^ //I see no reasons to give class data as argument to class_ //I do it only for HeldType functionality. Better interface could be without requiring //class data as argument .def( "id", &data::id, &::data_wrapper::default_id, bp::default_call_policies() ); bp::register_ptr_to_python< std::auto_ptr< data > >(); bp::def( "do_nothing" , &do_nothing , ( bp::arg("arg0") ) , bp::default_call_policies() ); bp::def( "create_data", &create_data, bp::default_call_policies() ); } -------------- next part -------------- import xyz d = xyz.create_data() print d.id() xyz.do_nothing( d ) print d.id() From david at david.gordon.name Wed Oct 19 06:57:20 2005 From: david at david.gordon.name (david at david.gordon.name) Date: Wed, 19 Oct 2005 05:57:20 +0100 (BST) Subject: [C++-sig] Excluding overloads using Pyste In-Reply-To: <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> References: <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> Message-ID: <58974.193.203.83.22.1129697840.squirrel@www.david.gordon.name> Hi Folks, I'm sure this has come up here before but I wasn't able to find a solution in earlier posts. It's a very simple question: Using Pyste, I understand I can exclude methods using the exclude command. Is it possible for me to exclude individual overloaded methods? I think a syntax was suggested: exclude(Class.Method[2]) This would suffice, although something more robust that doesn't rely on method order would be better. Also, I need to exclude individual constructor and operator overloads, not just named methods. thanks, David From dave at boost-consulting.com Wed Oct 19 15:02:19 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 19 Oct 2005 09:02:19 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/17/05, David Abrahams wrote: >> I'm sorry, that looks neither minimal nor complete. > >> I'm _sure_ you can illustrate your point with just a few functions and >> one (or at most two) classes. No? > > Yes I am. I am sorry for being unclear. Before proceeding, I would > like to clear something. What I am trying to show are problems with > boost.python interface to user and not functionality. I understand. > All code that I show works okay. I will try to explain myself here > and I attached files you've asked. What I'm asking is that you show some code that doesn't work, but that you think ought to work, if the interface were better. I understand that I could probably modify your example to make it that way, but I'd appreciate it if you could do it; it will save me a lot of uncertainty. > I am talking about next use case: I have class with virtual > function. In order to override it's virtual function I use > boost::python::wrapper. Also I'd like to have std::auto_ptr ( or > shared_ptr ) as it's held type. I understand that. -- Dave Abrahams Boost Consulting www.boost-consulting.com From giovanniangeli at iquattrocastelli.it Wed Oct 19 15:51:17 2005 From: giovanniangeli at iquattrocastelli.it (giovanniangeli at iquattrocastelli.it) Date: Wed, 19 Oct 2005 15:51:17 +0200 (CEST) Subject: [C++-sig] cross compile python for embedded system Message-ID: <29139.82.88.14.108.1129729877.squirrel@www.iquattrocastelli.it> how can I cross-compile python for a Linux target (arm9 based) system, on a Linux host PC, using the cross gnu tool chain ? Thank you. Giovanni. From roman.yakovenko at gmail.com Wed Oct 19 15:53:46 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 19 Oct 2005 15:53:46 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> Message-ID: <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> On 10/19/05, David Abrahams wrote: > What I'm asking is that you show some code that doesn't work, but that > you think ought to work, if the interface were better. Do you mean under "doesn't work" - does not compile. If so I am resending my example, fixed to show my point. Now file contains code that I think I should write in order to export class with virtual methods and non default held type. If you mean "doesn't work" as run time error then such thing does not exists. The code I wrote in previous post works as expected. Thanks for your efforts. > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com Roman Yakovenko -------------- next part -------------- #include "boost/python.hpp" #include struct data{ virtual int id() const{ return int(this); } }; std::auto_ptr create_data() { return std::auto_ptr( new data ); } void do_nothing( std::auto_ptr& ){} namespace bp = boost::python; struct data_wrapper : data, bp::wrapper< data > { data_wrapper(data const & arg ) : data( arg ) , bp::wrapper< data >() {} data_wrapper() : data() , bp::wrapper< data >() {} virtual int id() const { if( bp::override id = this->get_override( "id" ) ) return id( ); else return data::id( ); } virtual int default_id( ) const { return this->data::id( ); } }; BOOST_PYTHON_MODULE(xyz){ bp::class_< data_wrapper, std::auto_ptr< data > >( "data" ) .def( "id", &data::id, &::data_wrapper::default_id, bp::default_call_policies() ); bp::register_ptr_to_python< std::auto_ptr< data > >(); bp::def( "do_nothing" , &do_nothing , ( bp::arg("arg0") ) , bp::default_call_policies() ); bp::def( "create_data", &create_data, bp::default_call_policies() ); } -------------- next part -------------- import xyz d = xyz.create_data() print d.id() xyz.do_nothing( d ) print d.id() From seefeld at sympatico.ca Wed Oct 19 16:04:53 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 19 Oct 2005 10:04:53 -0400 Subject: [C++-sig] cross compile python for embedded system In-Reply-To: <29139.82.88.14.108.1129729877.squirrel@www.iquattrocastelli.it> References: <29139.82.88.14.108.1129729877.squirrel@www.iquattrocastelli.it> Message-ID: <43565285.9070706@sympatico.ca> giovanniangeli at iquattrocastelli.it wrote: > how can I cross-compile python for a Linux target (arm9 based) system, on a > Linux host PC, using the cross gnu tool chain ? If you are asking about compiling Python itself (as opposed to boost.python), you should direct your question at a gcc-related mailing list such as gcc-help at gcc.gnu.org instead. Regards, Stefan From dave at boost-consulting.com Wed Oct 19 16:35:37 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 19 Oct 2005 10:35:37 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/19/05, David Abrahams wrote: >> What I'm asking is that you show some code that doesn't work, but that >> you think ought to work, if the interface were better. > > Do you mean under "doesn't work" - does not compile. I mean "doesn't compile" or "fails an assertion at runtime" > If so I am resending my example, fixed to show my point. Now file > contains code that I think I should write in order to export class > with virtual methods and non default held type. > > If you mean "doesn't work" as run time error then such thing does > not exists. Ideally, you'd also post runtime code that, even aftere compilation is fixed, would assert unless the compiled code had the effects you wanted. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ndbecker2 at gmail.com Wed Oct 19 16:48:35 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 19 Oct 2005 10:48:35 -0400 Subject: [C++-sig] wrapping typedef equivalent types Message-ID: What happens if, using boost::python, I try to wrap 2 type equivalent classes? For example (this is a trivial example): class_... class_... where int == int32_t My real objective is to wrap classes template class X {}; where int_t is int (natural int size) int32_t (force 32-bit) int64_t (force 64-bit) Can wrapped X, X, X co-exist in the same python module? From s_sourceforge at nedprod.com Wed Oct 19 16:44:48 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 19 Oct 2005 15:44:48 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <435669F0.26520.17A8CAA2@localhost> On 17 Oct 2005 at 15:46, David Abrahams wrote: > >> At least in the near term, remove_reference relies on PTS. Also > >> BOOST_NO_CV_VOID_SPECIALIZATIONS is defined for vc6/7, so your > >> specialization will fail. > > > > Would you accept a patch whereby void * worked on MSVC7.1 and later > > but not before? In other words, I find a way to not use > > remove_reference and make the specialisation #ifndef > > BOOST_NO_CV_VOID_SPECIALIZATIONS. > > > > At least it wouldn't be any worse for vc6/7 than now. > > Please just make it portable. It's not that hard. Try the attached. Cheers, Niall -------------- next part -------------- --- registered__.hpp 2005-05-18 02:34:36.000000000 +0100 +++ registered.hpp 2005-10-19 15:41:06.000000000 +0100 @@ -78,14 +78,32 @@ template registration const& - registry_lookup(T&(*)()) + registry_lookup2(T&(*)()) { detail::register_shared_ptr1((T*)0); return registry::lookup(type_id()); } template - registration const& registered_base::converters = detail::registry_lookup((T(*)())0); + registration const& + registry_lookup1() + { + return registry_lookup2((T(*)())0); + } + +#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS + template <> + registration const& + registry_lookup1() + { + detail::register_shared_ptr1((void*)0); + return registry::lookup(type_id()); + } +#endif + + template + registration const& registered_base::converters = detail::registry_lookup1(); + } }}} // namespace boost::python::converter From dave at boost-consulting.com Wed Oct 19 17:38:42 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 19 Oct 2005 11:38:42 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: Message-ID: Neal Becker writes: > What happens if, using boost::python, I try to wrap 2 type equivalent > classes? > > For example (this is a trivial example): > > class_... > class_... > where int == int32_t > > My real objective is to wrap classes > > template class X {}; > > where int_t is > int (natural int size) > int32_t (force 32-bit) > int64_t (force 64-bit) > > Can wrapped X, X, X co-exist in the same python > module? No, all wrapped classes have to have different types. You could add a dummy parameter to X in order to distinguish them. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ndbecker2 at gmail.com Wed Oct 19 17:59:22 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 19 Oct 2005 11:59:22 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: Message-ID: David Abrahams wrote: > Neal Becker writes: > >> What happens if, using boost::python, I try to wrap 2 type equivalent >> classes? >> >> For example (this is a trivial example): >> >> class_... >> class_... >> where int == int32_t >> >> My real objective is to wrap classes >> >> template class X {}; >> >> where int_t is >> int (natural int size) >> int32_t (force 32-bit) >> int64_t (force 64-bit) >> >> Can wrapped X, X, X co-exist in the same python >> module? > > No, all wrapped classes have to have different types. You could add a > dummy parameter to X in order to distinguish them. > I don't understand the dummy parameter suggestion. Could you elaborate? I found a different solution. I just expose the int32_t and int64_t versions, then use python code to set the equivalence. In python, I write something like: if (intsize() == 4): X = X32 I guess there's nothing wrong with that approach :) From skottmckay at gmail.com Wed Oct 19 18:21:06 2005 From: skottmckay at gmail.com (Scott McKay) Date: Wed, 19 Oct 2005 10:21:06 -0600 Subject: [C++-sig] Excluding overloads using Pyste In-Reply-To: <58974.193.203.83.22.1129697840.squirrel@www.david.gordon.name> References: <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <58974.193.203.83.22.1129697840.squirrel@www.david.gordon.name> Message-ID: <51d017870510190921j7db28d9dyced286afefcb6524@mail.gmail.com> Would you be able to achieve what you want (albeit in a more labour intensive way) by excluding something first, then adding wrappers for the pieces you really want to expose? Or maybe you could create a new header file with a dummy class that inherits from the class you want to expose, and makes the methods you don't wish to expose private, and adds stubs for non-virtual methods you wish to expose. You could use that with pyste (and you could possibly use pyste's Rename facility to give it the original class name in python) instead of the original. S On 10/18/05, david at david.gordon.name wrote: > > Hi Folks, > > I'm sure this has come up here before but I wasn't able to find a solution > in earlier posts. It's a very simple question: > > Using Pyste, I understand I can exclude methods using the exclude command. > Is it possible for me to exclude individual overloaded methods? I think a > syntax was suggested: > > exclude(Class.Method[2]) > > This would suffice, although something more robust that doesn't rely on > method order would be better. > > Also, I need to exclude individual constructor and operator overloads, not > just named methods. > > thanks, > > David > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Oct 19 20:10:19 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 19 Oct 2005 14:10:19 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/19/05, David Abrahams wrote: >> What I'm asking is that you show some code that doesn't work, but that >> you think ought to work, if the interface were better. > > Do you mean under "doesn't work" - does not compile. If so I am > resending my example, > fixed to show my point. Now file contains code that I think I should > write in order > to export class with virtual methods and non default held type. > > If you mean "doesn't work" as run time error then such thing does not exists. > The code I wrote in previous post works as expected. The enclosed patch to boost/python/object/class_metadata.hpp seems to do the trick. However, you'll have to stop using register_ptr_to_python > ;-) -------------- next part -------------- A non-text attachment was scrubbed... Name: class_metadata.patch Type: text/x-patch Size: 1157 bytes Desc: not available URL: -------------- next part -------------- -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Oct 19 20:14:02 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 19 Oct 2005 14:14:02 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: Message-ID: Neal Becker writes: > David Abrahams wrote: > >> Neal Becker writes: >> >>> What happens if, using boost::python, I try to wrap 2 type equivalent >>> classes? >>> >>> For example (this is a trivial example): >>> >>> class_... >>> class_... >>> where int == int32_t >>> >>> My real objective is to wrap classes >>> >>> template class X {}; >>> >>> where int_t is >>> int (natural int size) >>> int32_t (force 32-bit) >>> int64_t (force 64-bit) >>> >>> Can wrapped X, X, X co-exist in the same python >>> module? >> >> No, all wrapped classes have to have different types. You could add a >> dummy parameter to X in order to distinguish them. >> > > I don't understand the dummy parameter suggestion. Could you elaborate? template class X {}; X X X or template class X { typedef boost::int_t::fast int_t; ... }; > I found a different solution. I just expose the int32_t and int64_t > versions, then use python code to set the equivalence. In python, I write > something like: > > if (intsize() == 4): X = X32 > > I guess there's nothing wrong with that approach :) Not unless X32 and X64 are trying to be wrappers for the same underlying C++ class. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Wed Oct 19 22:46:59 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Wed, 19 Oct 2005 15:46:59 -0500 Subject: [C++-sig] Beginner Question on Pointers Passed to Python via Boost Message-ID: Hello again, To start with, let me provide a simple case scenario to elaborate on what I want to do: class UserData { public: UserData() : m_nID(0) {} virtual ~UserData() {} int GetID() {return m_nID;} void SetID(int nID) {m_nID = nID;} protected: int m_nID; }; class UserDataMgr { public: UserDataMgr() {} virtual ~UserDataMgr() {DeleteMappedUserData();} void RegisterUserData(int nID) { //do some checking to see if it already exists... left out for simplicity UserData *pData = new UserData(); pData->SetID(nID); m_MappedUserData[nID] = pData; } UserData * GetUserData(int nID) { return m_MappedUserData[nID]; } protected: void DeleteMappedUserData() { //iterate through the map and delete the pointers... } std::map m_MappedUserData; } BOOST_INIT_MODULE(MyModule) { class_("UserData") .def("GetID",&UserData::GetID) ; class_("UserDataMgr") //If I understand things correctly, the below will cause Python to manage the lifetime of the UserData * returned .def("GetUserData", &UserDataMgr::GetUserData, return_value_policy())) ; } What I'm hoping to accomplish is the above scenario *without* letting Python manage the lifetime of the UserData pointer. In other words, I want to be able to have a single copy of a UserData instance available in which Python can retrieve from the UserDataMgr and perform operations on (but not destroy or copy the underlying pointer). Is this possible? I'm sure this is a beginner question, but help is appreciated. Note - I imagine that the manage_new_object return policy will be changed, but I'm simply supplying what I have for illustration. Thanks! From Keyes at simcrest.com Wed Oct 19 23:37:53 2005 From: Keyes at simcrest.com (Matthew B. Keyes) Date: Wed, 19 Oct 2005 16:37:53 -0500 Subject: [C++-sig] Beginner Question on Pointers Passed to Python via Boost Message-ID: <6A26270516DF054BBB3B87AE01C831EC2CCCD2@SERVER01.simcrest.int> One quick note: If I use a return_value_policy of reference_existing_object, it seems to work. I know this is considered "dangerous" - would this be problematic in this case? Thanks again! "Matt" wrote in message news:... > Hello again, > > To start with, let me provide a simple case scenario to elaborate on what I > want to do: > > class UserData > { > public: > UserData() : m_nID(0) {} > virtual ~UserData() {} > > int GetID() {return m_nID;} > void SetID(int nID) {m_nID = nID;} > > protected: > int m_nID; > }; > > class UserDataMgr > { > public: > UserDataMgr() {} > virtual ~UserDataMgr() {DeleteMappedUserData();} > > void RegisterUserData(int nID) > { > //do some checking to see if it already exists... left out for > simplicity > > UserData *pData = new UserData(); > pData->SetID(nID); > m_MappedUserData[nID] = pData; > } > > UserData * GetUserData(int nID) > { > return m_MappedUserData[nID]; > } > > protected: > void DeleteMappedUserData() > { > //iterate through the map and delete the pointers... > } > > std::map m_MappedUserData; > } > > BOOST_INIT_MODULE(MyModule) > { > class_("UserData") > .def("GetID",&UserData::GetID) > ; > > class_("UserDataMgr") > //If I understand things correctly, the below will cause Python to > manage the lifetime of the UserData * returned > .def("GetUserData", &UserDataMgr::GetUserData, > return_value_policy())) > ; > } > > What I'm hoping to accomplish is the above scenario *without* letting Python > manage the lifetime of the UserData pointer. In other words, I want to be > able to have a single copy of a UserData instance available in which Python > can retrieve from the UserDataMgr and perform operations on (but not destroy > or copy the underlying pointer). Is this possible? I'm sure this is a > beginner question, but help is appreciated. > > Note - I imagine that the manage_new_object return policy will be changed, > but I'm simply supplying what I have for illustration. > > Thanks! From ndbecker2 at gmail.com Thu Oct 20 01:29:48 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 19 Oct 2005 19:29:48 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: Message-ID: David Abrahams wrote: > Neal Becker writes: > >> David Abrahams wrote: >> >>> Neal Becker writes: >>> >>>> What happens if, using boost::python, I try to wrap 2 type equivalent >>>> classes? >>>> >>>> For example (this is a trivial example): >>>> >>>> class_... >>>> class_... >>>> where int == int32_t >>>> >>>> My real objective is to wrap classes >>>> >>>> template class X {}; >>>> >>>> where int_t is >>>> int (natural int size) >>>> int32_t (force 32-bit) >>>> int64_t (force 64-bit) >>>> >>>> Can wrapped X, X, X co-exist in the same python >>>> module? >>> >>> No, all wrapped classes have to have different types. You could add a >>> dummy parameter to X in order to distinguish them. >>> >> >> I don't understand the dummy parameter suggestion. Could you elaborate? > > template class X {}; > > X > X > X > > or > > template > class X > { > typedef boost::int_t::fast int_t; > ... > }; > >> I found a different solution. I just expose the int32_t and int64_t >> versions, then use python code to set the equivalence. In python, I >> write something like: >> >> if (intsize() == 4): X = X32 >> >> I guess there's nothing wrong with that approach :) > > Not unless X32 and X64 are trying to be wrappers for the same > underlying C++ class. > Maybe I didn't explain this very well. What I want in python is Xint Xint32 Xint64 Where: Xint32 -> X Xint64 -> X Xint -> X So that Xint is type equivalent to Xint32 or Xint64, depending on the platform. From rwgk at yahoo.com Thu Oct 20 07:35:29 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 19 Oct 2005 22:35:29 -0700 (PDT) Subject: [C++-sig] wrapping typedef equivalent types In-Reply-To: Message-ID: <20051020053529.23470.qmail@web31502.mail.mud.yahoo.com> FWIW, I've used something like the following in a few places: .def("set_selected", (object(*)( object const&, af::const_ref const&, e_t const&)) set_selected_unsigned_s) ; if ( boost::python::type_info(typeid(af::const_ref)) != boost::python::type_info(typeid(af::const_ref))) { result .def("set_selected", (object(*)( object const&, af::const_ref const&, af::const_ref const&)) set_selected_unsigned_a) I.e. the trick is to compare boost::python::type_info(typeid(X)). For completeness, the full code is here: http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/include/scitbx/array_family/boost_python/flex_wrapper.h?rev=1.60&view=auto Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From roman.yakovenko at gmail.com Thu Oct 20 07:50:20 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 20 Oct 2005 07:50:20 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> Message-ID: <7465b6170510192250h58125e75tff15b7b9fc9aa830@mail.gmail.com> On 10/19/05, David Abrahams wrote: > The enclosed patch to boost/python/object/class_metadata.hpp seems to > do the trick. However, you'll have to stop using > register_ptr_to_python > ;-) Thanks. This is really makes user code more natural. Although may be I did something wrong but the patch you attached does not change anything to me. The code I post still could not be compiled. May be you forgot to attach other patches? I can send compilation errors to you. Also I think I can submit new tester to boost.python library - tester that will reflect those changes. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > Roman Yakovenko From dave at boost-consulting.com Thu Oct 20 18:05:48 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 20 Oct 2005 12:05:48 -0400 Subject: [C++-sig] wrapper & HeldType References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510102248h2f079863ufa3e13512eb91a31@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> <7465b6170510192250h58125e75tff15b7b9fc9aa830@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/19/05, David Abrahams wrote: >> The enclosed patch to boost/python/object/class_metadata.hpp seems to >> do the trick. However, you'll have to stop using >> register_ptr_to_python > ;-) > > Thanks. This is really makes user code more natural. > > Although may be I did something wrong but the patch you attached does not > change anything to me. The code I post still could not be compiled. > May be you forgot to attach other patches? Nope. The changes, and your test, are checked into CVS. Your test is passing for me. > I can send compilation errors to you. That might be interesting. If you're using vc6 or vc7, I had to make some more changes (since the patch) to support those compilers, so you should get the latest from CVS. > Also I think I can submit new tester to boost.python library - tester > that will reflect > those changes. It's already in there. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Oct 20 18:07:51 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 20 Oct 2005 12:07:51 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: <20051020053529.23470.qmail@web31502.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > FWIW, I've used something like the following in a few places: > > .def("set_selected", > (object(*)( > object const&, > af::const_ref const&, > e_t const&)) set_selected_unsigned_s) > ; > if ( boost::python::type_info(typeid(af::const_ref)) > != boost::python::type_info(typeid(af::const_ref))) { > result > .def("set_selected", > (object(*)( > object const&, > af::const_ref const&, > af::const_ref const&)) set_selected_unsigned_a) > > > I.e. the trick is to compare boost::python::type_info(typeid(X)). if ( boost::is_same< std::size_t, unsigned >() ) would be a whole lot cleaner, and would often generate less code since the check can be made at compile-time. -- Dave Abrahams Boost Consulting www.boost-consulting.com From giovanniangeli at iquattrocastelli.it Fri Oct 21 12:21:30 2005 From: giovanniangeli at iquattrocastelli.it (giovanniangeli at iquattrocastelli.it) Date: Fri, 21 Oct 2005 12:21:30 +0200 (CEST) Subject: [C++-sig] cross compile python for embedded system Message-ID: <32796.82.52.17.147.1129890090.squirrel@www.iquattrocastelli.it> thank you Stefan, I think that the difficulties arising in the cross-compilation procedure come essentially from the intricated sequence of configuration operations specific of the python package, hence someone who knows the details of the configure procedure performed by the automatic configure utility used in building Python could address me toward a solution. regards, Giovanni. Stefan Seefeld seefeld at sympatico.ca wrote: > giovanniangeli at iquattrocastelli.it wrote: > > how can I cross-compile python for a Linux target (arm9 based) system, on > > a > > Linux host PC, using the cross gnu tool chain ? > > If you are asking about compiling Python itself (as opposed to > boost.python), > you should direct your question at a gcc-related mailing list such as > gcc-help at gcc.gnu.org instead. > Regards, > Stefan From ericjardim at gmail.com Fri Oct 21 13:03:24 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 21 Oct 2005 08:03:24 -0300 Subject: [C++-sig] Can QPointer be used as a smart pointer? Message-ID: <432ec6c50510210403n3182edb7t@mail.gmail.com> Hi, The Qt4 library have a custom smart pointer type template, QPointer<...>: http://doc.trolltech.com/4.0/qt4-intro.html#qpointer-t http://doc.trolltech.com/4.0/qpointer.html Is it compatible with boost.python, like smart_ptr and auto_ptr are, or do I have to register (if possible) it? Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Fri Oct 21 13:17:11 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 21 Oct 2005 04:17:11 -0700 (PDT) Subject: [C++-sig] wrapping typedef equivalent types In-Reply-To: Message-ID: <20051021111711.15873.qmail@web31502.mail.mud.yahoo.com> --- David Abrahams wrote: > > I.e. the trick is to compare boost::python::type_info(typeid(X)). > > if ( boost::is_same< std::size_t, unsigned >() ) > > would be a whole lot cleaner, and would often generate less code since > the check can be made at compile-time. I see. Thanks! I chose the boost::python::type_info(typeid(X)) approach because this is exactly how the Boost.Python registry determines equivalence. boost/python/type_id.hpp has all kinds of platform-specific adjustments, e.g. the "signed int" vs. "int" workaround for "Older EDG-based compilers". Is it safe to assume that boost::is_same<> is true if and only if boost::python::type_info instances compare equal? Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From dave at boost-consulting.com Fri Oct 21 14:47:14 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 21 Oct 2005 08:47:14 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: <20051021111711.15873.qmail@web31502.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- David Abrahams wrote: >> > I.e. the trick is to compare boost::python::type_info(typeid(X)). >> >> if ( boost::is_same< std::size_t, unsigned >() ) >> >> would be a whole lot cleaner, and would often generate less code since >> the check can be made at compile-time. > > I see. Thanks! > > I chose the boost::python::type_info(typeid(X)) approach because this is > exactly how the Boost.Python registry determines equivalence. Well, you should be using type_id() rather than writing it out longhand. > boost/python/type_id.hpp has all kinds of platform-specific adjustments, e.g. > the "signed int" vs. "int" workaround for "Older EDG-based compilers". Is it > safe to assume that boost::is_same<> is true if and only if > boost::python::type_info instances compare equal? Except on implementations that we can effectively consider buggy, yes. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 21 14:49:26 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 21 Oct 2005 08:49:26 -0400 Subject: [C++-sig] Can QPointer be used as a smart pointer? References: <432ec6c50510210403n3182edb7t@mail.gmail.com> Message-ID: Eric Jardim writes: > Hi, > > The Qt4 library have a custom smart pointer type template, QPointer<...>: > http://doc.trolltech.com/4.0/qt4-intro.html#qpointer-t > http://doc.trolltech.com/4.0/qpointer.html > > Is it compatible with boost.python, like smart_ptr and auto_ptr are, or do I > have to register (if possible) it? You need to specialize pointee > so its nested ::type is T. Aside from that it should be exactly as compatible with Boost.Python as auto_ptr is. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 21 14:46:20 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 21 Oct 2005 08:46:20 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: <20051021111711.15873.qmail@web31502.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- David Abrahams wrote: >> > I.e. the trick is to compare boost::python::type_info(typeid(X)). >> >> if ( boost::is_same< std::size_t, unsigned >() ) >> >> would be a whole lot cleaner, and would often generate less code since >> the check can be made at compile-time. > > I see. Thanks! > > I chose the boost::python::type_info(typeid(X)) approach because this is > exactly how the Boost.Python registry determines equivalence. Well, you should be using type_id() rather than writing it out longhand. > boost/python/type_id.hpp has all kinds of platform-specific adjustments, e.g. > the "signed int" vs. "int" workaround for "Older EDG-based compilers". Is it > safe to assume that boost::is_same<> is true if and only if > boost::python::type_info instances compare equal? Except on implementations that we can effectively consider buggy, yes. -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Fri Oct 21 19:16:58 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 21 Oct 2005 10:16:58 -0700 (PDT) Subject: [C++-sig] wrapping typedef equivalent types In-Reply-To: Message-ID: <20051021171658.75386.qmail@web31514.mail.mud.yahoo.com> --- David Abrahams wrote: > Well, you should be using type_id() rather than writing it out > longhand. OK, I am doing that now. Thanks! The code shown previously is now: if ( boost::python::type_id >() != boost::python::type_id >()) { > > boost/python/type_id.hpp has all kinds of platform-specific adjustments, > e.g. > > the "signed int" vs. "int" workaround for "Older EDG-based compilers". Is > it > > safe to assume that boost::is_same<> is true if and only if > > boost::python::type_info instances compare equal? > > Except on implementations that we can effectively consider buggy, yes. Well, I spent years considering buggy implementations. I am going to stick to the boost::python::type_id<> comparisons as long as the Boost.Python registry does. Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From dave at boost-consulting.com Sat Oct 22 14:38:18 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 22 Oct 2005 08:38:18 -0400 Subject: [C++-sig] wrapping typedef equivalent types References: <20051021171658.75386.qmail@web31514.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- David Abrahams wrote: >> Well, you should be using type_id() rather than writing it out >> longhand. > > OK, I am doing that now. Thanks! The code shown previously is now: > > if ( boost::python::type_id >() > != boost::python::type_id >()) { > >> > boost/python/type_id.hpp has all kinds of platform-specific adjustments, >> e.g. >> > the "signed int" vs. "int" workaround for "Older EDG-based compilers". Is >> it >> > safe to assume that boost::is_same<> is true if and only if >> > boost::python::type_info instances compare equal? >> >> Except on implementations that we can effectively consider buggy, yes. > > Well, I spent years considering buggy implementations. By that I mean, of course, implementations where you can end up with two different typeids for the same type (old EDG) but now that I think of it, that can only happen across translation units (or maybe across dynamic link boundaries), so using is_same for the kind of comparison being done above is perfectly safe. > I am going to stick to the boost::python::type_id<> comparisons as > long as the Boost.Python registry does. Suit yourself, my friend! -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Sun Oct 23 08:19:27 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 23 Oct 2005 08:19:27 +0200 Subject: [C++-sig] wrapper & HeldType In-Reply-To: References: <7465b6170510102225n2ae2d385q4a4da0af956942c8@mail.gmail.com> <7465b6170510152203j5f5fa0cbwda343fb7c759baee@mail.gmail.com> <7465b6170510152333k11c8f22bm85796f0b88aae49@mail.gmail.com> <7465b6170510182238k535b0282s54059f715a1e6d8a@mail.gmail.com> <7465b6170510190653x2cff2ef2t5a3eec7604721e21@mail.gmail.com> <7465b6170510192250h58125e75tff15b7b9fc9aa830@mail.gmail.com> Message-ID: <7465b6170510222319t3b36e73bs737dc3597a937559@mail.gmail.com> Thank you. It works as expected. > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com Roman Yakovenko From charles.harris at sdl.usu.edu Sun Oct 23 20:00:01 2005 From: charles.harris at sdl.usu.edu (Charles Harris) Date: Sun, 23 Oct 2005 12:00:01 -0600 Subject: [C++-sig] boost/pending/disjoint_sets.hpp References: <20051021171658.75386.qmail@web31514.mail.mud.yahoo.com> Message-ID: This is really about boost, not boost/python, so ignore it if it doesn't interest you. Anyway, I have written a union-find class for my own use, but after finding disjoint_sets I hoped to replace it with a more standard version. I was unable to do so because of missing functionality. Typically, I want to do the following: 1) iterate over sets. 2) iterate over set elements 3) store element properties - color, position, etc. The set iterator is pretty easy to achieve, it is a filtered_iterator derived from an iterator over all elements in all sets. The set element iterator can be implemented by linking elements in a set into a circular list. All that is needed is a sibling link in addition to the parent link. The lists are then merged whenever the sets are unioned. All elements belonging to the same set as any given element are then easily accessible. The container properties may already be there: I haven't yet completely understood what the template implements. Just my $.02 . Chuck -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 3012 bytes Desc: not available URL: From dave at boost-consulting.com Mon Oct 24 01:43:11 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 23 Oct 2005 19:43:11 -0400 Subject: [C++-sig] boost/pending/disjoint_sets.hpp References: <20051021171658.75386.qmail@web31514.mail.mud.yahoo.com> Message-ID: "Charles Harris" writes: > This is really about boost, not boost/python, so ignore it > if it doesn't interest you. You should post it in a more appropriate mailing list, then: http://www.boost.org/more/mailing_lists.htm -- Dave Abrahams Boost Consulting www.boost-consulting.com From etaurel at cells.es Mon Oct 24 12:22:58 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Mon, 24 Oct 2005 12:22:58 +0200 Subject: [C++-sig] C++ singleton Message-ID: <0IOV00G2X0UGX6@cells-s02.cells.es> Hello everybody, I am actually writing an interface to python for an existing C++ library using Boost. This library has a C++ singleton class. This class has only one constructor (with arguments) which is "protected" because it's a singleton. I am not able to build a Boost interface to this class because the compiler complains that the constructor I have given to Boost in the class_xxx constructor argument is not public (which is true) ! Therefore, my question is simple : How is it possible to interface such a class with only one constructor which is protected and a static method to create/access the object ? Thank's very much for your answer. Sincerely Emmanuel Taurel (etaurel at cells.es) PS : By the way, is there a searchable archive of this mailing list ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Mon Oct 24 12:31:42 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 24 Oct 2005 12:31:42 +0200 Subject: [C++-sig] C++ singleton In-Reply-To: <0IOV00G2X0UGX6@cells-s02.cells.es> References: <0IOV00G2X0UGX6@cells-s02.cells.es> Message-ID: <7465b6170510240331g12e6a599gc570a73d3784fd30@mail.gmail.com> On 10/24/05, Emmanuel Taurel wrote: > Therefore, my question is simple : How is it possible to interface such a > class with only one constructor which is protected and a static method > to create/access the object ? Look for no_init here http://boost.org/libs/python/doc/v2/class.html Better solution is to try boost.python code generator Pyste ( an official one ) or pyplusplus http://pygccxml.sourceforge.net/pyplusplus/pyplusplus.html > Thank's very much for your answer. > Sincerely > > > > Emmanuel Taurel (etaurel at cells.es) > > > > PS : By the way, is there a searchable archive of this mailing list ? yes: http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/cpp-sig Roman Yakovenko From wl at flexis.de Mon Oct 24 12:50:30 2005 From: wl at flexis.de (Wolfgang Langner) Date: Mon, 24 Oct 2005 12:50:30 +0200 Subject: [C++-sig] C++ singleton In-Reply-To: <0IOV00G2X0UGX6@cells-s02.cells.es> References: <0IOV00G2X0UGX6@cells-s02.cells.es> Message-ID: <435CBC76.8000103@flexis.de> Hi, > I am actually writing an interface to python for an existing C++ library > using Boost. This library has a C++ singleton class. This class has only one > > constructor (with arguments) which is ?protected? because it?s a singleton. > > I am not able to build a Boost interface to this class because the > compiler complains that the constructor I have given to Boost > > in the class_xxx constructor argument is not public (which is true) ! > Therefore, my question is simple : How is it possible to interface such > a class with only one constructor which is protected and a static method > > to create/access the object ? Don't export the constructor, use no_init. Declare the static method which returns the only instance as staticmethod. Example code, not tested: class_("MySingleton", no_init) .def("get", &MySingleton::get, return_internal_reference<>()) .staticmethod("get") ; For more information see tutorial an reference: http://www.boost.org/libs/python/doc/index.html For code examples look at the unit tests or other projects using boost:python. bye by Wolfgang From etaurel at cells.es Tue Oct 25 11:13:27 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Tue, 25 Oct 2005 11:13:27 +0200 Subject: [C++-sig] One more question about method with argc, argv like arguments Message-ID: <0IOW00HK8SAMS0@cells-s02.cells.es> Hello everybody, Certainly this question has already been posted on this list but I don't really find example of how it could be solved. I want to wrap a class which has constructor taking arguments like the famous "int argc, char *argv[]" and build instance of this class in python using my_class(len(sys.argv),argv) It is a quite common problem. As the second parameter is a pointer to pointer I guess that there is a special trick to be used here. Can anyone send me brief example of how this could be wrapped ? Thank's in advance Emmanuel Taurel (etaurel at cells.es) -------------- next part -------------- An HTML attachment was scrubbed... URL: From wl at flexis.de Tue Oct 25 13:05:05 2005 From: wl at flexis.de (Wolfgang Langner) Date: Tue, 25 Oct 2005 13:05:05 +0200 Subject: [C++-sig] One more question about method with argc, argv like arguments In-Reply-To: <0IOW00HK8SAMS0@cells-s02.cells.es> References: <0IOW00HK8SAMS0@cells-s02.cells.es> Message-ID: <435E1161.6090909@flexis.de> Hello, > Certainly this question has already been posted on this list but I don?t > really find example of how it could be solved. > > I want to wrap a class which has constructor taking arguments like the > famous ?int argc, char *argv[]? > > and build instance of this class in python using > my_class(len(sys.argv),argv) Wrap it to use only a python list. > It is a quite common problem. As the second parameter is a pointer to > pointer I guess that > > there is a special trick to be used here. > Can anyone send me brief example of how this could be wrapped ? Use injected constructors for this: /* client_arg */ std::auto_ptr class_arg(boost::python::list args) { /* conversion here from python list to argc, argv */ std::auto_ptrmyC(new MyClass(&argc, argv)); /* cleanup */ } class_("MyClass") .def("__init__", make_constructor(class_arg)) ; Conversion is left as an example. :-) Look at test code for injected constructors ! bye by Wolfgang From dave at boost-consulting.com Tue Oct 25 16:42:58 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 25 Oct 2005 10:42:58 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <435669F0.26520.17A8CAA2@localhost> Message-ID: "Niall Douglas" writes: > On 17 Oct 2005 at 15:46, David Abrahams wrote: > >> >> At least in the near term, remove_reference relies on PTS. Also >> >> BOOST_NO_CV_VOID_SPECIALIZATIONS is defined for vc6/7, so your >> >> specialization will fail. >> > >> > Would you accept a patch whereby void * worked on MSVC7.1 and later >> > but not before? In other words, I find a way to not use >> > remove_reference and make the specialisation #ifndef >> > BOOST_NO_CV_VOID_SPECIALIZATIONS. >> > >> > At least it wouldn't be any worse for vc6/7 than now. >> >> Please just make it portable. It's not that hard. > > Try the attached. Closer, but if we're going to call this feature "supported," and it's possible, I want a patch that actually *works* portably. This one won't work on compilers that define BOOST_NO_CV_VOID_SPECIALIZATIONS. I also need a testcase for the test suite that will pass iff the feature works. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Wed Oct 26 13:24:02 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 26 Oct 2005 12:24:02 +0100 Subject: [C++-sig] Regression in Boost.Python v1.33 In-Reply-To: Message-ID: <435F7562.30075.3AFD7C78@localhost> On 25 Oct 2005 at 10:42, David Abrahams wrote: > Closer, but if we're going to call this feature "supported," and it's > possible, I want a patch that actually *works* portably. This one > won't work on compilers that define BOOST_NO_CV_VOID_SPECIALIZATIONS. > I also need a testcase for the test suite that will pass iff the > feature works. I can supply a testcase, but the problem with supporting older compilers is knowing when a void is being used without using specialisation to do it. I did try a number of methods, but all of them either rely on partial template specialisation (which is worse) or void specialisation. If you think about it, how can you detect a void type without using specialisation of some kind? Of course, you're the expert here, so if you know of some idiom I don't, please do suggest. Should I make the testcase always succeed on BOOST_NO_CV_VOID_SPECIALIZATIONS compilers? Cheers, Niall From etaurel at cells.es Wed Oct 26 15:10:12 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Wed, 26 Oct 2005 15:10:12 +0200 Subject: [C++-sig] Problem using the ptr() function Message-ID: <0IOY00IH9XX8UC@cells-s02.cells.es> Hello everybody, I am using Boost.python to interface a C++ set of classes. In one of my C+++ class, I am calling a method implemented in Python with the boost "call_method" call. This method has one parameter of our own data type and return a pointer to this type. I have installed converters for this type as it is adviced in the FAQ "How can I automatically convert my custom string type..." If I call my method like this MyType *ret = call_method(my_py_obj,"My_method", my_ptr) With my_ptr being a MyType *, it works. But if I call it like this MyType *ret = call_method(my_py_obj,"My_method", ptr(my_ptr)) to avoid a copy, I received a run time error complaining that "No Python class registered for C++..." Could someone explain me why it works in the first case and not in the second one. Many thanks in advance Emmanuel Taurel (etaurel at cells.es) -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Oct 26 15:45:07 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 26 Oct 2005 09:45:07 -0400 Subject: [C++-sig] Problem using the ptr() function In-Reply-To: <0IOY00IH9XX8UC@cells-s02.cells.es> References: <0IOY00IH9XX8UC@cells-s02.cells.es> Message-ID: <435F8863.7070202@sympatico.ca> Emmanuel Taurel wrote: > Hello everybody, > > > > I am using Boost.python to interface a C++ set of classes. In one of my > C+++ class, I am calling a method implemented in Python with the > boost ?call_method? call. This method has one parameter of our own data > type and return a pointer to this type. I have installed converters for > this type as it is adviced in the FAQ ?How can I automatically convert > my custom string type?..? If I call my method like this > > > > MyType *ret = call_method(my_py_obj,?My_method?, my_ptr) > > > > With my_ptr being a MyType *, it works. But if I call it like this > > > > MyType *ret = call_method(my_py_obj,?My_method?, ptr(my_ptr)) > to avoid a copy, I received a run time error complaining that > > > > ?No Python class registered for C++?..? I believe the reason is that strings in python are non-mutable, meaning that you can't modify them in-place. Instead, string variables are rebound to a new value when you modify them. That is incompatible with the way you want your string type to be handled. Regards, Stefan From etaurel at cells.es Wed Oct 26 15:59:18 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Wed, 26 Oct 2005 15:59:18 +0200 Subject: [C++-sig] Problem using the ptr() function In-Reply-To: <435F8863.7070202@sympatico.ca> Message-ID: <0IOZ00IM2072UC@cells-s02.cells.es> Hello Stefan, Thank's for your answer, but I don't use string at all. The data type I am using is our own data type. The problem I have is with the usage of My_ptr or ptr(My_ptr) in the last parameter of the boost call_method. Regards, Emmanuel Taurel (etaurel at cells.es) -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Wednesday, October 26, 2005 3:45 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Problem using the ptr() function Emmanuel Taurel wrote: > Hello everybody, > > > > I am using Boost.python to interface a C++ set of classes. In one of my > C+++ class, I am calling a method implemented in Python with the > boost "call_method" call. This method has one parameter of our own data > type and return a pointer to this type. I have installed converters for > this type as it is adviced in the FAQ "How can I automatically convert > my custom string type..." If I call my method like this > > > > MyType *ret = call_method(my_py_obj,"My_method", my_ptr) > > > > With my_ptr being a MyType *, it works. But if I call it like this > > > > MyType *ret = call_method(my_py_obj,"My_method", ptr(my_ptr)) > to avoid a copy, I received a run time error complaining that > > > > "No Python class registered for C++..." I believe the reason is that strings in python are non-mutable, meaning that you can't modify them in-place. Instead, string variables are rebound to a new value when you modify them. That is incompatible with the way you want your string type to be handled. Regards, Stefan _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From roman.yakovenko at gmail.com Thu Oct 27 10:49:21 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 27 Oct 2005 10:49:21 +0200 Subject: [C++-sig] [Announce] pyplusplus 0.5.0 Message-ID: <7465b6170510270149h2f76d04bxaf7197fdc850b08f@mail.gmail.com> Hi. I would like announce of new version of pyplusplus (0.5). What is this? The pyplusplus is a framework of components for creating C++ code generator for boost.python library Code generation with the pyplusplus framework is a very flexible and highly configurable process. You can find an introduction to pyplusplus at: 1. http://tinyurl.com/dbbrj 2. http://sue.mydnsbox9.net/~admin191/pyplusplus/pyplusplus.html Status: First of all, this project is under active development. Second I think from now this project could be used in production. Third: list of implemented features: * classes * class wrappers * two modes of code generation: * using scope - better error messages location from compiler * no scope * automatic detection of held type * nested classes * implicit conversion * functions * virtual methods * protected method, even non virtual ones can be accessed from `Python`_. * overloading * two modes of code generation: * with function type - good for exporting template instantiated functions and overloaded ones. * without function type * static methods * code generated for wrapped methods takes into account types of arguments * operators, both free and member ones * call policies resolver * enumerations * variables * namespace aliasing and using * writing multiple files * user code could be inserted almost any where * write code into file if there were changes * user licence is written at the top of every file * ... 4'th - examples. Now it has real world example. I created Python binding for boost.date_time library almost all functionality has been exported. Next functionality was not exported: facet, parsing and iterators. See this page for more information: 1. http://tinyurl.com/8zk8r 2. http://sue.mydnsbox9.net/~admin191/pyplusplus/examples/py_date_time/py_date_time.html 5'th - demo mode. In order to evaluate pyplusplus you don't have to learn new API. pyplusplus has nice and simple gui. For convenience this gui is packed as standalone executable for Windows and Linux. In order to use pyplusplus you have to have CVS version of boost.python. Ideas, comments, suggestions or help are welcomed. Roman Yakovenko From ndbecker2 at gmail.com Thu Oct 27 13:22:53 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 27 Oct 2005 07:22:53 -0400 Subject: [C++-sig] [Announce] pyplusplus 0.5.0 References: <7465b6170510270149h2f76d04bxaf7197fdc850b08f@mail.gmail.com> Message-ID: I'd like to try this, but I'm not having any luck installing gccxml-0.6 on Fedora 4. gccxml chokes on system headers, even if I force selection of older gcc-3.2.3: /usr/include/c++/3.2.3/new:79: error: `operator new' takes type `size_t' (` unsigned int') as first parameter Any hints? From dave at boost-consulting.com Thu Oct 27 13:30:00 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 27 Oct 2005 07:30:00 -0400 Subject: [C++-sig] Regression in Boost.Python v1.33 References: <435F7562.30075.3AFD7C78@localhost> Message-ID: "Niall Douglas" writes: > On 25 Oct 2005 at 10:42, David Abrahams wrote: > >> Closer, but if we're going to call this feature "supported," and it's >> possible, I want a patch that actually *works* portably. This one >> won't work on compilers that define BOOST_NO_CV_VOID_SPECIALIZATIONS. >> I also need a testcase for the test suite that will pass iff the >> feature works. > > I can supply a testcase, but the problem with supporting older > compilers is knowing when a void is being used without using > specialisation to do it. I did try a number of methods, but all of > them either rely on partial template specialisation (which is worse) > or void specialisation. > > If you think about it, how can you detect a void type without using > specialisation of some kind? > > Of course, you're the expert here, so if > you know of some idiom I don't, please do suggest. I could suggest a complicated dance that would work, but apparently an explicit specialization on void matches an argument of void const volatile on vc6. The is_void tests are passing there, and it doesn't do anything fancy. So just use is_void or an explicit specialization on void. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Oct 27 13:40:01 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 27 Oct 2005 07:40:01 -0400 Subject: [C++-sig] Problem using the ptr() function References: <0IOY00IH9XX8UC@cells-s02.cells.es> Message-ID: Emmanuel Taurel writes: > Hello everybody, > > > > I am using Boost.python to interface a C++ set of classes. In one of my C+++ > class, I am calling a method implemented in Python with the > boost "call_method" call. This method has one parameter of our own data type > and return a pointer to this type. I have installed converters for this type > as it is adviced in the FAQ "How can I automatically convert my custom > string type..." If I call my method like this > > > > MyType *ret = call_method(my_py_obj,"My_method", my_ptr) > > > > With my_ptr being a MyType *, it works. But if I call it like this > > > > MyType *ret = call_method(my_py_obj,"My_method", ptr(my_ptr)) to > avoid a copy, I received a run time error complaining that > > > > "No Python class registered for C++..." > > > > Could someone explain me why it works in the first case and not in the > second one. Please post a minimal, complete, reproducible testcase: one C++ file, one Python file, the result you expect and the result you got. Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Oct 27 14:00:11 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 27 Oct 2005 08:00:11 -0400 Subject: [C++-sig] [Announce] pyplusplus 0.5.0 References: <7465b6170510270149h2f76d04bxaf7197fdc850b08f@mail.gmail.com> Message-ID: Neal Becker writes: > I'd like to try this, but I'm not having any luck installing gccxml-0.6 on > Fedora 4. gccxml chokes on system headers, even if I force selection of > older gcc-3.2.3: > > /usr/include/c++/3.2.3/new:79: error: `operator new' takes type `size_t' (` > unsigned int') as first parameter > > Any hints? Only that there might be a better place to ask about this (Some GCC-XML list?) -- Dave Abrahams Boost Consulting www.boost-consulting.com From allenb at vrsource.org Thu Oct 27 16:48:42 2005 From: allenb at vrsource.org (Allen Bierbaum) Date: Thu, 27 Oct 2005 09:48:42 -0500 Subject: [C++-sig] [Announce] pyplusplus 0.5.0 In-Reply-To: References: <7465b6170510270149h2f76d04bxaf7197fdc850b08f@mail.gmail.com> Message-ID: <4360E8CA.9010701@vrsource.org> Use the gccxml from CVS. It works with gcc 4.0 which is needed for FC4. One other thing of note is that if you try to use gccxml to process code that includes boost/python.hpp it will bomb out because gccxml is missing an internal symbol that is used by boost python. I have submitted a patch to add this, but I don't know if they have accepted it yet. -Allen Neal Becker wrote: >I'd like to try this, but I'm not having any luck installing gccxml-0.6 on >Fedora 4. gccxml chokes on system headers, even if I force selection of >older gcc-3.2.3: > >/usr/include/c++/3.2.3/new:79: error: `operator new' takes type `size_t' (` > unsigned int') as first parameter > >Any hints? > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig > > > From etaurel at cells.es Thu Oct 27 18:31:32 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Thu, 27 Oct 2005 18:31:32 +0200 Subject: [C++-sig] Problem using the ptr() function In-Reply-To: Message-ID: <0IP100KDS1WTUS@cells-s02.cells.es> Hi Dave, I have attached to this e-mail five files which demonstrates my problem. These files are : 1 - ds.h : The C++ include file 2 - ds.cpp : The C++ implementation 3 - py_ds.cpp : The boost interface stuff 4 - py_ds.h : The boost interface include file 5 - main.py : The python code I am a beginner in both Python and boost. Therefore, they are certainly some piece of code in these files that you will find strange... I have isolated the problem as far as I am able to. If in file de.cpp, I use line 16, the python code outputs are ------------------------------------------------------------ In init_module function Conversion from MyStrArray to python installed in Boost In Device constructor with string a/b/c in the MyStrArray convert function to_python Input args = The first string Input args = The second string ------------------------------------------------------------ And it is correct. If I use line 15 (using the ptr() function), the python code outputs are ----------------------------------------------------------- In init_module function Conversion from MyStrArray to python installed in Boost In Device constructor with string a/b/c Traceback (most recent call last): File "main.py", line 23, in ? c.execute_device_method() TypeError: No Python class registered for C++ class std::vector > ------------------------------------------------------------ The principle of this software is : I create one python instance of the "MyContainer" class. Then I create one instance of the "MyDevice" class which is stored in a data member of the C++ class from which MyContainer inherits from. This is done by calling the create_device() method of the MyContainer object in the python code. Then, I call the execute_device_method() of the MyContainer class which is coded in C++ and which callback one of the MyDevice method defined in Python. This is this callback (C++ calls a Python method) which fails if I use the ptr() function. You will also certainly notice that I have installed my own converters >From my type which in this small example is a vector. In the real application, it is not a vector but something more complicated. Thank's for your help Emmanuel Taurel (etaurel at cells.es) -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of David Abrahams Sent: Thursday, October 27, 2005 1:40 PM To: c++-sig at python.org Subject: Re: [C++-sig] Problem using the ptr() function Emmanuel Taurel writes: > Hello everybody, > > > > I am using Boost.python to interface a C++ set of classes. In one of my C+++ > class, I am calling a method implemented in Python with the > boost "call_method" call. This method has one parameter of our own data type > and return a pointer to this type. I have installed converters for this type > as it is adviced in the FAQ "How can I automatically convert my custom > string type..." If I call my method like this > > > > MyType *ret = call_method(my_py_obj,"My_method", my_ptr) > > > > With my_ptr being a MyType *, it works. But if I call it like this > > > > MyType *ret = call_method(my_py_obj,"My_method", ptr(my_ptr)) to > avoid a copy, I received a run time error complaining that > > > > "No Python class registered for C++..." > > > > Could someone explain me why it works in the first case and not in the > second one. Please post a minimal, complete, reproducible testcase: one C++ file, one Python file, the result you expect and the result you got. Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- A non-text attachment was scrubbed... Name: py_ds.h Type: application/octet-stream Size: 731 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ds.cpp Type: application/octet-stream Size: 431 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ds.h Type: application/octet-stream Size: 615 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: main.py Type: application/octet-stream Size: 495 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: py_ds.cpp Type: application/octet-stream Size: 3571 bytes Desc: not available URL: From mjkeyes at sbcglobal.net Fri Oct 28 09:53:24 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 02:53:24 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python Message-ID: Hi all, Here's some sample code of what I'm trying to do: class Base { public: Base() {} virtual ~Base() {} }; class Derived : public Base { public: Derived() {} virtual ~Derived() {} virtual void DoSomething() {} }; Elsewhere: class MyUtility { static object ms_oDerived; static Derived * ms_pDerived; public: static Derived * GetDerived() {return ms_pDerived;} static void SetDerived(handle <>hDerived) { try { ms_oDerived = object(hDerived); ms_pDerived = extract(ms_oDerived); ms_pDerived->DoSomething(); } catch(...) { PyErr_Print(); } } }; BOOST_PYTHON_MODULE(MyModule) { class_("PyDerived"); def("PySetDerived", &MyUtility::SetDerived); } In Python: import MyModule def Foo(): MyModule.PySetDerived(MyModule.PyDerived()) When I run my code (which mimics the above), I get an error on the extract... line: "TypeError: No registered converter was able to extract a C++ pointer to type class Base from this Python object of type PyDerived" Any advice on this? Thanks! From mjkeyes at sbcglobal.net Fri Oct 28 10:08:06 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 03:08:06 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: Okay, I think I'm an idiot here. Python doesn't know the first thing about the base class (I'm guessing), so I'll have to expose that. Can anyone verify this? I won't be able to try it until tomorrow. Also, a code review of the concepts illustrated in my pseudocode below is always appreciated :) Thanks! "Matt" wrote in message news:djslcp$7fb$1 at sea.gmane.org... > Hi all, > > Here's some sample code of what I'm trying to do: > > class Base > { > public: > Base() {} > virtual ~Base() {} > }; > > class Derived : public Base > { > public: > Derived() {} > virtual ~Derived() {} > > virtual void DoSomething() {} > }; > > Elsewhere: > class MyUtility > { > static object ms_oDerived; > static Derived * ms_pDerived; > > public: > static Derived * GetDerived() {return ms_pDerived;} > > static void SetDerived(handle <>hDerived) > { > try > { > ms_oDerived = object(hDerived); > ms_pDerived = extract(ms_oDerived); > ms_pDerived->DoSomething(); > } > catch(...) > { > PyErr_Print(); > } > } > }; > > BOOST_PYTHON_MODULE(MyModule) > { > class_("PyDerived"); > > def("PySetDerived", &MyUtility::SetDerived); > } > > In Python: > > import MyModule > > def Foo(): > MyModule.PySetDerived(MyModule.PyDerived()) > > When I run my code (which mimics the above), I get an error on the > extract... line: > > "TypeError: No registered converter was able to extract a C++ pointer to > type class Base from this Python object of type PyDerived" > > Any advice on this? > > Thanks! From dave at boost-consulting.com Fri Oct 28 15:16:22 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 28 Oct 2005 09:16:22 -0400 Subject: [C++-sig] Problem using the ptr() function References: <0IP100KDS1WTUS@cells-s02.cells.es> Message-ID: Emmanuel Taurel writes: > Hi Dave, > > I have attached to this e-mail five files which demonstrates my problem. > These files are : > 1 - ds.h : The C++ include file > 2 - ds.cpp : The C++ implementation > 3 - py_ds.cpp : The boost interface stuff > 4 - py_ds.h : The boost interface include file > 5 - main.py : The python code Emmanuel, I asked for two files. Could you please save me the effort of consolidating these? Could you please also make an effort to reduce the code even further? Just the minimum amount to show the part that doesn't work, please. I don't need to see code that does work. Please also, as I asked, post the result you expect and the result you actually got. Thanks. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Fri Oct 28 16:48:54 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 09:48:54 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: Ack, that didn't work. I imagine I have to set a converter somehow, but I can't find any tutorials on it. Can someone help? "Matt" wrote in message news:djsm8b$a01$1 at sea.gmane.org... > Okay, I think I'm an idiot here. Python doesn't know the first thing > about the base class (I'm guessing), so I'll have to expose that. > > Can anyone verify this? I won't be able to try it until tomorrow. Also, > a code review of the concepts illustrated in my pseudocode below is always > appreciated :) > > Thanks! > > "Matt" wrote in message > news:djslcp$7fb$1 at sea.gmane.org... >> Hi all, >> >> Here's some sample code of what I'm trying to do: >> >> class Base >> { >> public: >> Base() {} >> virtual ~Base() {} >> }; >> >> class Derived : public Base >> { >> public: >> Derived() {} >> virtual ~Derived() {} >> >> virtual void DoSomething() {} >> }; >> >> Elsewhere: >> class MyUtility >> { >> static object ms_oDerived; >> static Derived * ms_pDerived; >> >> public: >> static Derived * GetDerived() {return ms_pDerived;} >> >> static void SetDerived(handle <>hDerived) >> { >> try >> { >> ms_oDerived = object(hDerived); >> ms_pDerived = extract(ms_oDerived); >> ms_pDerived->DoSomething(); >> } >> catch(...) >> { >> PyErr_Print(); >> } >> } >> }; >> >> BOOST_PYTHON_MODULE(MyModule) >> { >> class_("PyDerived"); >> >> def("PySetDerived", &MyUtility::SetDerived); >> } >> >> In Python: >> >> import MyModule >> >> def Foo(): >> MyModule.PySetDerived(MyModule.PyDerived()) >> >> When I run my code (which mimics the above), I get an error on the >> extract... line: >> >> "TypeError: No registered converter was able to extract a C++ pointer to >> type class Base from this Python object of type PyDerived" >> >> Any advice on this? >> >> Thanks! From dave at boost-consulting.com Fri Oct 28 19:05:37 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 28 Oct 2005 13:05:37 -0400 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: "Matt" writes: > Ack, that didn't work. I imagine I have to set a converter somehow, but I > can't find any tutorials on it. > > Can someone help? When you wrapped Base, did you also specify it in Derived's list of bases<...> ? -- Dave Abrahams Boost Consulting www.boost-consulting.com From mjkeyes at sbcglobal.net Fri Oct 28 20:15:55 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 13:15:55 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: Good catch! However, it's still giving me the same error... Here's my BOOST_INIT_MODULE stuff: BOOST_INIT_MODULE(MyModule) { class_("PyBase"); class_,boost::noncopyable>("PyDerived"); } Does that look right? "David Abrahams" wrote in message news:uzmottvvi.fsf at boost-consulting.com... > "Matt" writes: > >> Ack, that didn't work. I imagine I have to set a converter somehow, but >> I >> can't find any tutorials on it. >> >> Can someone help? > > > When you wrapped Base, did you also specify it in Derived's list of > bases<...> ? > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From mjkeyes at sbcglobal.net Fri Oct 28 20:25:10 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 13:25:10 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: Ack! Your fix did work... I made a typo in implementing it. Thanks so much for the help! You guys are awesome for your dedication to such a great project. "Matt" wrote in message news:djtq52$3pc$1 at sea.gmane.org... > Good catch! > > However, it's still giving me the same error... > > Here's my BOOST_INIT_MODULE stuff: > > BOOST_INIT_MODULE(MyModule) > { > class_("PyBase"); > > class_,boost::noncopyable>("PyDerived"); > } > > Does that look right? > > "David Abrahams" wrote in message > news:uzmottvvi.fsf at boost-consulting.com... >> "Matt" writes: >> >>> Ack, that didn't work. I imagine I have to set a converter somehow, but >>> I >>> can't find any tutorials on it. >>> >>> Can someone help? >> >> >> When you wrapped Base, did you also specify it in Derived's list of >> bases<...> ? >> -- >> Dave Abrahams >> Boost Consulting >> www.boost-consulting.com From mjkeyes at sbcglobal.net Fri Oct 28 23:50:38 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 16:50:38 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: Okay, now I have another question. Let's consider the same scenario with a slight modification: class Root { public: Root() {} virtual ~Root() {} } class Base : public Root, public wrapper { public: Base() {} virtual ~Base() {} virtual void DoSomethingBase() { try { this->get_override("DoSomething")(); } catch(...) { PyErr_Print(); } } virtual const char * GetNameBase() ( std::string sResult; try { const char *szResult = this->get_override("GetName")(); sResult = szResult; } catch(...) { PyErr_Print(); } } }; class Derived : public Base { public: Derived() {} virtual ~Derived() {} virtual void DoSomethingDefault() { const char *sName = GetNameBase(); //<-----Python error pops up here //...do stuff } virtual const char * GetNameDefault() {return m_sName.c_str();} std::string m_sName; }; BOOST_PYTHON_MODULE(MyModule) { class_("PyDerived"); .def("DoSomething", &Base::DoSomethingBase, &Derived::DoSomethingDefault) .def("GetName", &Base::GetNameBase, &Derived::GetNameDefault) ; } In Python: >>>import MyModule >>>x = PyDerived() >>>x.DoSomething() The result is this: "ReferenceError: Attempt to return dangling pointer to object of type: char" It occurs in PyDerived::DoSomethingDefault when GetNameBase is called (which calls back to PyDerived::GetName). I'm trying to implement this type of scenario on several objects to make them fully overrideable classes in Python. Any advice on why this would happen with the c_str in a std::string? Is there a better way (or a "right" way) to do this type of thing? Thanks again guys! From cramissor at aim.com Fri Oct 28 23:59:05 2005 From: cramissor at aim.com (cramissor at aim.com) Date: Fri, 28 Oct 2005 17:59:05 -0400 Subject: [C++-sig] extracting data from a tuple Message-ID: <8C7AA21F32024DB-57C-1785B@FWM-D08.sysops.aol.com> Hi all. Probably a newbie question here but how do you extract data from a tuple using boost::python? I've done some digging in the docs as well as the mailing list but have been unable to figure it out. For example, I have the following declared in my code: std::map widgets; I would like to extract the third item of the tuple associated with a particular widget. I have had no luck so far so any pointers would be much appreciated. TIA Marc ________________________________________________________________________ Check Out the new free AIM(R) Mail -- 2 GB of storage and industry-leading spam and email virus protection. From mjkeyes at sbcglobal.net Sat Oct 29 06:01:20 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Fri, 28 Oct 2005 23:01:20 -0500 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: I think I found a workaround. If I receive the call from the base class into a str object and extract a const char * from it, then I get no dangling references. I'm guessing that since this object is never passed to Python (I assume) that the dangling pointer comes from that. Not sure... "Matt" wrote in message news:dju6nq$ah8$1 at sea.gmane.org... > Okay, now I have another question. Let's consider the same scenario with > a slight modification: > > class Root > { > public: > Root() {} > virtual ~Root() {} > } > > class Base : public Root, public wrapper > { > public: > Base() {} > virtual ~Base() {} > > virtual void DoSomethingBase() > { > try > { > this->get_override("DoSomething")(); > } > catch(...) > { > PyErr_Print(); > } > } > > virtual const char * GetNameBase() > ( > std::string sResult; > try > { > const char *szResult = this->get_override("GetName")(); > sResult = szResult; > } > catch(...) > { > PyErr_Print(); > } > } > }; > > class Derived : public Base > { > public: > Derived() {} > virtual ~Derived() {} > > virtual void DoSomethingDefault() > { > const char *sName = GetNameBase(); //<-----Python error pops > up here > //...do stuff > } > > virtual const char * GetNameDefault() {return m_sName.c_str();} > > std::string m_sName; > }; > > BOOST_PYTHON_MODULE(MyModule) > { > class_("PyDerived"); > .def("DoSomething", &Base::DoSomethingBase, > &Derived::DoSomethingDefault) > .def("GetName", &Base::GetNameBase, > &Derived::GetNameDefault) > ; > } > > In Python: >>>>import MyModule >>>>x = PyDerived() >>>>x.DoSomething() > > The result is this: > "ReferenceError: Attempt to return dangling pointer to object of type: > char" > > It occurs in PyDerived::DoSomethingDefault when GetNameBase is called > (which calls back to PyDerived::GetName). I'm trying to implement this > type of scenario on several objects to make them fully overrideable > classes in Python. > > Any advice on why this would happen with the c_str in a std::string? Is > there a better way (or a "right" way) to do this type of thing? > > Thanks again guys! From dave at boost-consulting.com Sat Oct 29 14:35:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 29 Oct 2005 08:35:54 -0400 Subject: [C++-sig] Problem with extracting a C++ object from python References: Message-ID: "Matt" writes: Matt, see http://www.boost.org/libs/python/doc/v2/faq.html#dangling > I think I found a workaround. If I receive the call from the base class > into a str object and extract a const char * from it, then I get no dangling > references. Sounds to me like you've just found a way to silence the helpful protective error message without curing the actual problem, and even if it appears to work now, your code will probably crash one day. > I'm guessing that since this object is never passed to Python > (I assume) that the dangling pointer comes from that. Not sure... > > "Matt" wrote in message > news:dju6nq$ah8$1 at sea.gmane.org... >> Okay, now I have another question. Let's consider the same scenario with >> a slight modification: >> Please don't overquote; thanks. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sat Oct 29 14:36:49 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 29 Oct 2005 08:36:49 -0400 Subject: [C++-sig] extracting data from a tuple References: <8C7AA21F32024DB-57C-1785B@FWM-D08.sysops.aol.com> Message-ID: cramissor at aim.com writes: > Hi all. Probably a newbie question here but how do you extract data > from a tuple using boost::python? I've done some digging in the docs > as well as the mailing list but have been unable to figure it out. > > For example, I have the following declared in my code: > > std::map widgets; > > I would like to extract the third item of the tuple associated with a > particular widget. widgets[widgetindex][3] > I have had no luck so far so any pointers would be > much appreciated. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Sun Oct 30 06:01:29 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 30 Oct 2005 07:01:29 +0200 Subject: [C++-sig] [Announce] pyplusplus 0.5.0 In-Reply-To: References: <7465b6170510270149h2f76d04bxaf7197fdc850b08f@mail.gmail.com> Message-ID: <7465b6170510292201x3a639be1ped685155606d3ed3@mail.gmail.com> On 10/27/05, Neal Becker wrote: > I'd like to try this, but I'm not having any luck installing gccxml-0.6 on > Fedora 4. gccxml chokes on system headers, even if I force selection of > older gcc-3.2.3: > > /usr/include/c++/3.2.3/new:79: error: `operator new' takes type `size_t' (` > unsigned int') as first parameter > > Any hints? I don't have one. Next release of pygccxml will work with CVS version of gccxml. Roman Yakovenko From roman.yakovenko at gmail.com Sun Oct 30 06:17:11 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 30 Oct 2005 07:17:11 +0200 Subject: [C++-sig] Few questions about Pyste and pyplusplus Message-ID: <7465b6170510292217k1f6b6cd7l88631f21a4f40bc4@mail.gmail.com> Hi. I hope you saw my announcement about new version of pyplusplus. I would like to create some table that compares Pyste and pyplusplus. I think I need your agreement for this. I created pyplusplus after I studied Pyste and used it for few middle size projects. I think that I treat all weaknesses Pyste has. In this table pyplusplus will look much better, then Pyste. What do you think? Roman Yakovenko From roman.yakovenko at gmail.com Sun Oct 30 06:20:24 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 30 Oct 2005 07:20:24 +0200 Subject: [C++-sig] Few questions about Pyste and pyplusplus In-Reply-To: <7465b6170510292217k1f6b6cd7l88631f21a4f40bc4@mail.gmail.com> References: <7465b6170510292217k1f6b6cd7l88631f21a4f40bc4@mail.gmail.com> Message-ID: <7465b6170510292220g7b8378f1kbf800361f6df61fe@mail.gmail.com> This mail has been destined Bruno da Silva de Oliveira On 10/30/05, Roman Yakovenko wrote: > Hi. I hope you saw my announcement about new version of pyplusplus. > I would like to create some table that compares Pyste and pyplusplus. > I think I need your agreement for this. I created pyplusplus after I > studied Pyste > and used it for few middle size projects. I think that I treat all > weaknesses Pyste has. > In this table pyplusplus will look much better, then Pyste. > > What do you think? > > Roman Yakovenko > From roman.yakovenko at gmail.com Mon Oct 31 14:27:48 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 31 Oct 2005 15:27:48 +0200 Subject: [C++-sig] void* questions\thoughts Message-ID: <7465b6170510310527x5911ce7arf400bcc07591cce1@mail.gmail.com> Hi. There is nice explanation in boost.python FAQs how to export function that takes\returns void*. I have 2 questions: 1. Why void_ should be defined in each translation unit? If I understand right "translation unit" is cpp file? If there is no special reason to define void_ in every translation unit, then next question: 2. Why boost.python does not define void_ class and does not registrate it? BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID( void_ ) Thanks Roman Yakovenko From s_sourceforge at nedprod.com Mon Oct 31 15:12:22 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 31 Oct 2005 14:12:22 -0000 Subject: [C++-sig] void* questions\thoughts In-Reply-To: <7465b6170510310527x5911ce7arf400bcc07591cce1@mail.gmail.com> Message-ID: <43662646.28139.555766FF@localhost> On 31 Oct 2005 at 15:27, Roman Yakovenko wrote: > Hi. There is nice explanation in boost.python FAQs how to export > function that takes\returns > void*. I have 2 questions: > > 1. Why void_ should be defined in each translation unit? If I understand right > "translation unit" is cpp file? void_ is a placeholder type for void as BPL doesn't support the void type itself, but does support opaque types. Hence the unfortunate proxy use of void_ * for void *. > If there is no special reason to define void_ in every translation > unit, then next question: > > 2. Why boost.python does not define void_ class and does not registrate it? > BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID( void_ ) I would personally wonder why BPL doesn't automatically treat void as an opaque type, and thus you can use void *. A huge amount of C uses void *, and a good proportion of C++ so lacking it makes producing bindings for such C and C++ trickier than it needs to be - most importantly in wrapping virtual functions, where a void * is passed in and must be passed out as-is to the C++ default implementation. Dave, what was the rationale for not supporting void as an opaque type? Cheers, Niall From dave at boost-consulting.com Mon Oct 31 17:28:41 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 31 Oct 2005 11:28:41 -0500 Subject: [C++-sig] void* questions\thoughts References: <7465b6170510310527x5911ce7arf400bcc07591cce1@mail.gmail.com> <43662646.28139.555766FF@localhost> Message-ID: "Niall Douglas" writes: > Dave, what was the rationale for not supporting void as an opaque > type? I didn't design the opaque types support; I guess nobody considered void when it was designed. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Mon Oct 31 20:26:21 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 31 Oct 2005 19:26:21 -0000 Subject: [C++-sig] void* questions\thoughts In-Reply-To: Message-ID: <43666FDD.5167.5676DB41@localhost> On 31 Oct 2005 at 11:28, David Abrahams wrote: > "Niall Douglas" writes: It would be an idea if you didn't quote people's email address in your replies as spam crawlers pick it up, and some web based interfaces don't obscure them for you. > > Dave, what was the rationale for not supporting void as an opaque > > type? > > I didn't design the opaque types support; I guess nobody considered > void when it was designed. How easy would it be to bolt it on now? Cheers, Niall From dave at boost-consulting.com Mon Oct 31 20:42:51 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 31 Oct 2005 14:42:51 -0500 Subject: [C++-sig] void* questions\thoughts References: <43666FDD.5167.5676DB41@localhost> Message-ID: "Niall Douglas" writes: > On 31 Oct 2005 at 11:28, David Abrahams wrote: > >> "Niall Douglas" writes: > > It would be an idea if you didn't quote people's email address in > your replies as spam crawlers pick it up, and some web based > interfaces don't obscure them for you. It might be, but since your address is already all over the mailing list, I'm not adding much risk to you by quoting it. Anyone can subscribe their email address, including address harvesters. My email software does that by default, and I don't know how to change it. However, if you can figure out how to get Gnus/Message Mail to replace "@" with "-at-" there, I'll be happy to institute it in my .emacs file. >> > Dave, what was the rationale for not supporting void as an opaque >> > type? >> >> I didn't design the opaque types support; I guess nobody considered >> void when it was designed. > > How easy would it be to bolt it on now? I have no idea. Haven't you been submitting patches for that? Are you going to give me one with docs and regression tests? -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Mon Oct 31 21:03:49 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 31 Oct 2005 20:03:49 -0000 Subject: [C++-sig] void* questions\thoughts In-Reply-To: Message-ID: <436678A5.28245.56992A94@localhost> On 31 Oct 2005 at 14:42, David Abrahams wrote: > > It would be an idea if you didn't quote people's email address in > > your replies as spam crawlers pick it up, and some web based > > interfaces don't obscure them for you. > > It might be, but since your address is already all over the mailing > list, I'm not adding much risk to you by quoting it. Anyone can > subscribe their email address, including address harvesters. My email > software does that by default, and I don't know how to change it. > However, if you can figure out how to get Gnus/Message Mail to replace > "@" with "-at-" there, I'll be happy to institute it in my .emacs > file. Still, I'm pretty sure you didn't use to do that. Have you changed your config in the last six months? Don't use emacs, never have used emacs, therefore don't know. Anyone else know? > >> > Dave, what was the rationale for not supporting void as an opaque > >> > type? > >> > >> I didn't design the opaque types support; I guess nobody considered > >> void when it was designed. > > > > How easy would it be to bolt it on now? > > I have no idea. Haven't you been submitting patches for that? Are > you going to give me one with docs and regression tests? No, I've been submitting patches to undo the regression a recent change to BPL has caused. I found your previous suggestion on how to do it needs me to install vc6 which I'll get the time to do next weekend onwards. Right now, I have two class tests and an essay due for this week so everything is shelved until afterwards - but don't worry, I'll be getting back to you then. Would you integrate a patch adding void * as an opaque type if it came with docs, a testcase and ran on vc6? Cheers, Niall From dave at boost-consulting.com Mon Oct 31 22:29:07 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 31 Oct 2005 16:29:07 -0500 Subject: [C++-sig] void* questions\thoughts References: <436678A5.28245.56992A94@localhost> Message-ID: "Niall Douglas" writes: > On 31 Oct 2005 at 14:42, David Abrahams wrote: > >> > It would be an idea if you didn't quote people's email address in >> > your replies as spam crawlers pick it up, and some web based >> > interfaces don't obscure them for you. >> >> It might be, but since your address is already all over the mailing >> list, I'm not adding much risk to you by quoting it. Anyone can >> subscribe their email address, including address harvesters. My email >> software does that by default, and I don't know how to change it. >> However, if you can figure out how to get Gnus/Message Mail to replace >> "@" with "-at-" there, I'll be happy to institute it in my .emacs >> file. > > Still, I'm pretty sure you didn't use to do that. Have you changed > your config in the last six months? Nope; same as it ever was. And you can look back in the message history to see that I've been doing it that way for years. >> I have no idea. Haven't you been submitting patches for that? Are >> you going to give me one with docs and regression tests? > > No, I've been submitting patches to undo the regression a recent > change to BPL has caused. It's not really a regression if you were exploiting a feature that was unintentional and never supported. > I found your previous suggestion on how to do it needs me to install > vc6 which I'll get the time to do next weekend onwards. Right now, I > have two class tests and an essay due for this week so everything is > shelved until afterwards - but don't worry, I'll be getting back to > you then. > > Would you integrate a patch adding void * as an opaque type if it > came with docs, a testcase and ran on vc6? I'll go you one better. If you give me everything else -- docs, tests, and your best guess at a portable solution -- I'll make sure it works on vc6. The thing is, I suspect 1.33.1 is going to probably freeze any day now, so the chance of getting it in is evaporating fast. In fact, only by calling it a regression does it have a hope. -- Dave Abrahams Boost Consulting www.boost-consulting.com