From gabrieljoel at gmail.com Wed Apr 1 20:00:15 2009 From: gabrieljoel at gmail.com (Gabriel Joel Perez) Date: Wed, 1 Apr 2009 14:00:15 -0400 Subject: [C++-sig] Problems building my Python binding with Bjam Message-ID: <9a442d030904011100s2b3d1a38oe42f9908ccc19f3d@mail.gmail.com> Hello! I've been trying to build a binding for a C++ class with Boost.Python. This is what I'm using Boost.Jam version is 03.1.17, Python 2.5.2, boost 1.38.0 and Ubuntu 8.04. I used Py++ 1.0 to automatically generate the interface file. This is the error I get when I try to to build my bindings with bjam: warn: Unable to construct ./pyplusplus > ...found 1 target... > How can I debug this problem? Is there a troubleshooting guide available? Does anybody what usually causes this? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Wed Apr 1 21:17:02 2009 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 01 Apr 2009 15:17:02 -0400 Subject: [C++-sig] std_map_indexing_suite In-Reply-To: <49CA36CB.9080209@resophonic.com> References: <49CA36CB.9080209@resophonic.com> Message-ID: <49D3BDAE.5000702@resophonic.com> troy d. straszheim wrote: > I'm wondering why the current map_indexing_suite is the way it is. Is > there any reason not to enhance it to support now standard methods like > keys(), values(), popitem() and the like? A colleague and I have been working on an indexing suite that gives a wrapped std::map essentially the same interface as a python dict. The main reason is that the minimal interface of the current map_indexing_suite has the effect of making the python-wrapper abstraction 'leaky'... that is, beginners who know nothing of C++ naturally ask why they can do these things with a dict 'd': d = dict([('one',1), ('two', 2)]) for k,v in d.iteritems(): print k, v*2 d.keys() d.values() d.items() d.iterkeys() (and a few others) but they cannot do so with a python class that is a wrapped std::map... This is a big hassle for the architect who wants to be able to allow some of the userbase to remain completely ignorant of the C++ side of things. Any interest in getting this documented and in to the library? Current version attached. May still have some bugs and/or need some refactoring. -t -------------- next part -------------- A non-text attachment was scrubbed... Name: std_map_indexing_suite.hpp Type: text/x-c++hdr Size: 16402 bytes Desc: not available URL: From divinekid at gmail.com Wed Apr 1 22:07:52 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Thu, 2 Apr 2009 04:07:52 +0800 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support Message-ID: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> Hi, I did some preliminary work on BPL py3k support in these days. With Troy's help we have a py3k SVN tree in sandbox now, which is branched from trunk. I also tried to compile BPL with Python 3, and by following the error report of the compiler, I did some patch - now we have 14 .cpp files out of 28 in total can be compiled. The patch is committed, you can see it here: [2]. Please point me out if the code has something don't conform to Boost coding policy. There's also something interesting, maybe a bug I caught, for example: (Search the changeset to see details) 39 // XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference 40 // const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast("__module__"))); 41 PyObject *mod = PyObject_GetAttrString( self_, "__module__"); Also I found some potential problem with Py_ssize_t, I will take this as a chance to fix them. The biggest problem I see still is the "Text Vs. Data Instead Of Unicode Vs. 8-bit" in py3k. As we discussed and the suggestion by Niall [3], we have a clear solution for this and I will work towarding this. The other changes in py3k such as PyObject_HEAD change, int type removal and unbound method removal also affected Boost.Python's code, but they don't require logical change of BPL code and easy to handle. Hopefully in the end of this summer, we will have a Boost.Python library with Python 3 support! Thanks again for many people's help! References: [1] https://svn.boost.org/trac/boost/browser/sandbox-branches [2] https://svn.boost.org/trac/boost/changeset/52118 [3] ?Nabble - Python - c++-sig - Some thoughts on py3k support,? http://www.nabble.com/Some-thoughts-on-py3k-support-td22564813.html. -- Haoyu Bai From s_sourceforge at nedprod.com Thu Apr 2 10:02:28 2009 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 02 Apr 2009 09:02:28 +0100 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support In-Reply-To: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> References: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> Message-ID: <49D47F24.29828.8E316AB@s_sourceforge.nedprod.com> Surely your project hasn't been approved by Google yet? Otherwise, good to see such progress. BPL always had hard to find resource leaks because of the lack of Py_Finalize support - I used to Glowcode my bindings and I was never quite sure where leaks came from. None were serious mind e.g. hanging onto a C++ object after it was supposed to die. Good stuff, but don't go too far without Google funding unless you're happy doing this this summer anyway. Niall On 2 Apr 2009 at 4:07, Haoyu Bai wrote: > Hi, > > I did some preliminary work on BPL py3k support in these days. > > With Troy's help we have a py3k SVN tree in sandbox now, which is > branched from trunk. I also tried to compile BPL with Python 3, and by > following the error report of the compiler, I did some patch - now we > have 14 .cpp files out of 28 in total can be compiled. The patch is > committed, you can see it here: [2]. Please point me out if the code > has something don't conform to Boost coding policy. There's also > something interesting, maybe a bug I caught, for example: (Search the > changeset to see details) > > 39 // XXX(bhy) Potentional memory leak here since > PyObject_GetAttrString returns a new reference > 40 // const char *mod = > PyString_AsString(PyObject_GetAttrString( self_, > const_cast("__module__"))); > 41 PyObject *mod = PyObject_GetAttrString( self_, "__module__"); > > Also I found some potential problem with Py_ssize_t, I will take this > as a chance to fix them. > > The biggest problem I see still is the "Text Vs. Data Instead Of > Unicode Vs. 8-bit" in py3k. As we discussed and the suggestion by > Niall [3], we have a clear solution for this and I will work towarding > this. The other changes in py3k such as PyObject_HEAD change, int type > removal and unbound method removal also affected Boost.Python's code, > but they don't require logical change of BPL code and easy to handle. > > Hopefully in the end of this summer, we will have a Boost.Python > library with Python 3 support! > > Thanks again for many people's help! > > References: > [1] https://svn.boost.org/trac/boost/browser/sandbox-branches > [2] https://svn.boost.org/trac/boost/changeset/52118 > [3] "Nabble - Python - c++-sig - Some thoughts on py3k support," > http://www.nabble.com/Some-thoughts-on-py3k-support-td22564813.html. > > -- Haoyu Bai > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From divinekid at gmail.com Thu Apr 2 17:10:14 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Thu, 2 Apr 2009 23:10:14 +0800 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support In-Reply-To: <49D47F24.29828.8E316AB@s_sourceforge.nedprod.com> References: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> <49D47F24.29828.8E316AB@s_sourceforge.nedprod.com> Message-ID: <1d7983e80904020810j56084f1p2205fa6e2b4432fb@mail.gmail.com> On Thu, Apr 2, 2009 at 4:02 PM, Niall Douglas wrote: > Surely your project hasn't been approved by Google yet? > > Otherwise, good to see such progress. BPL always had hard to find > resource leaks because of the lack of Py_Finalize support - I used to > Glowcode my bindings and I was never quite sure where leaks came > from. None were serious mind e.g. hanging onto a C++ object after it > was supposed to die. > > Good stuff, but don't go too far without Google funding unless you're > happy doing this this summer anyway. > > Niall > > Hi, The project haven't been approved yet. I just did some proof-of-concept work to have a sense of how the project will be and show the feasibility of my time estimation. It also give me more understanding of BPL code. Thanks Niall! :) -- Haoyu Bai From ndbecker2 at gmail.com Fri Apr 3 03:26:46 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 02 Apr 2009 21:26:46 -0400 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support References: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> <49D47F24.29828.8E316AB@s_sourceforge.nedprod.com> <1d7983e80904020810j56084f1p2205fa6e2b4432fb@mail.gmail.com> Message-ID: In case you haven't seen it: http://docs.python.org/3.0/howto/cporting.html#cporting-howto From beau at open-source-staffing.com Fri Apr 3 04:12:22 2009 From: beau at open-source-staffing.com (Beau Gould (OSS)) Date: Thu, 2 Apr 2009 22:12:22 -0400 Subject: [C++-sig] [JOB] C/C++/Linux Developers, NYC - Relo OK Message-ID: <5CCCF28C42E64AF38DEDBBB755FC16FD@EMACHINE> I'm recruiting C/C++/Linux Developers for a NYC client. Successful candidates: * will be around 5 years out of school * have a Bachelors at least in CS/Eng from a top university * do NOT have financial industry experience * have fluency in C/C++, stl, pthreads, shared memory, networking and everything UNIX * have at least 3-5 years engineering solutions and writing code * Python experience a plus Competitive salaries and generous performance driven bonuses (20-50%) as well as full benefits and a slew of other plusses come along with these positions. Local candidates preferred, but all considered. Relocation packages available. If you are interested in this opportunity and are a US Citizen, green card holder or exceptional H1B, please submit your resume and salary requirements to beau at open-source-staffing.com Thank you, Beau J. Gould Open Source Staffing www.open-source-staffing.com beau at open-source-staffing.com From divinekid at gmail.com Fri Apr 3 07:59:26 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Fri, 3 Apr 2009 13:59:26 +0800 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support In-Reply-To: References: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> <49D47F24.29828.8E316AB@s_sourceforge.nedprod.com> <1d7983e80904020810j56084f1p2205fa6e2b4432fb@mail.gmail.com> Message-ID: <1d7983e80904022259r5b48ef8cj456fae16ffa53eb6@mail.gmail.com> On Fri, Apr 3, 2009 at 9:26 AM, Neal Becker wrote: > In case you haven't seen it: > > http://docs.python.org/3.0/howto/cporting.html#cporting-howto > > > Hi, I know that, thanks! But the guide just haven't covered every coiners. There's also an wiki page which is almost summarized from my SWIG py3k porting experience, provides more details: http://wiki.python.org/moin/Py3kExtensionModules Thanks! -- Haoyu Bai From ndbecker2 at gmail.com Fri Apr 3 15:42:35 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 03 Apr 2009 09:42:35 -0400 Subject: [C++-sig] [JOB] C/C++/Linux Developers, NYC - Relo OK References: <5CCCF28C42E64AF38DEDBBB755FC16FD@EMACHINE> Message-ID: Beau Gould (OSS) wrote: > I'm recruiting C/C++/Linux Developers for a NYC client. Successful > candidates: ... > * do NOT have financial industry experience Wow, I've never seen _that_ before! What does it suggest?? Are those with financial experience tainted? From rogeeff at gmail.com Fri Apr 3 16:40:57 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Fri, 3 Apr 2009 14:40:57 +0000 (UTC) Subject: [C++-sig] instantiate python classes in c++ References: <1238428534.49d0eb768108f@web-mail1.uibk.ac.at> Message-ID: Gregor Burger uibk.ac.at> writes: > is it possible to use boost.python to define classes > in a script (like in the one below), register the defined > classes and later on create instances of the class? Yes > Is it possible to provide the same globals and locals to call_method > so that Flow and other classes are defined? No. You can't "update" global dictionary at the call point. This is the issue I am very much familiar with. You can find 2 posts from me with pretty much the same content. The only viable solution I found is to *compile* the script first before executing it. If I do this global dictionary is bound to the class methods and you code will work fine. Gennadiy From madcitymann at gmail.com Fri Apr 3 18:56:29 2009 From: madcitymann at gmail.com (mad city) Date: Fri, 3 Apr 2009 11:56:29 -0500 Subject: [C++-sig] quickstart ? Message-ID: I have just installed boost 1.38. I got the quickstart example to build. 1 - Why does bjam erase the extended.pyd file after running the tests? 2 - What options do I need, or changes to jamroot to prevent bjam from erasing this file? -------------- next part -------------- An HTML attachment was scrubbed... URL: From madcitymann at gmail.com Fri Apr 3 20:49:58 2009 From: madcitymann at gmail.com (mad city) Date: Fri, 3 Apr 2009 13:49:58 -0500 Subject: [C++-sig] embedded python ? Message-ID: Just starting out with boost-python. I have a python script that I want to call from C++ code. I have the quickstart example working. I'm running into a problem. The python script I'm calling includes import statements - for example 'import os', and these are causing an exception ImportError: __import__ not found How do I resolve? -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Apr 3 20:55:32 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 03 Apr 2009 14:55:32 -0400 Subject: [C++-sig] embedded python ? In-Reply-To: References: Message-ID: <49D65BA4.10003@sympatico.ca> mad city wrote: > Just starting out with boost-python. I have a python script that I > want to call from C++ code. I have the quickstart example working. I'm > running into a problem. The python script I'm calling includes import > statements - for example 'import os', and these are causing an exception > > ImportError: __import__ not found Not having seen your code, I'd suggest you start by looking at the existing tests that use the functionality you want. In this case, this means the 'import' and 'exec' tests in boost/libs/python/test. It's generally most likely to get help if you provide some details, such as a chunk of code that we could run to reproduce the issue. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From madcitymann at gmail.com Fri Apr 3 21:49:39 2009 From: madcitymann at gmail.com (mad city) Date: Fri, 3 Apr 2009 14:49:39 -0500 Subject: [C++-sig] embedded python ? In-Reply-To: <49D65BA4.10003@sympatico.ca> References: <49D65BA4.10003@sympatico.ca> Message-ID: Thanks. Good advice. >From the quickstart project, the embedded.cpp file function void exec_file_test(std::string const &script) { std::cout << "running file " << script << "..." << std::endl; // Run a python script in an empty environment. python::dict global; python::object result = python::exec_file(script.c_str(), global, global); // Extract an object the script stored in the global dictionary. BOOST_TEST(python::extract(global["number"]) == 42); std::cout << "success!" << std::endl; } calls my python script file - parseLogs.py which starts with import os.path import stat import csv import re import pickle import operator import time import msvcrt from optparse import OptionParser import sys The 'import' call throws the exception - ImportError: __import__ not found. I'm looking into the PyInitialize() and how the interpreter gets loaded. Thanks. On Fri, Apr 3, 2009 at 1:55 PM, Stefan Seefeld wrote: > mad city wrote: > >> Just starting out with boost-python. I have a python script that I want to >> call from C++ code. I have the quickstart example working. I'm running into >> a problem. The python script I'm calling includes import statements - for >> example 'import os', and these are causing an exception >> >> ImportError: __import__ not found >> > > Not having seen your code, I'd suggest you start by looking at the existing > tests that use the functionality you want. In this case, this means the > 'import' and 'exec' tests in boost/libs/python/test. > > It's generally most likely to get help if you provide some details, such as > a chunk of code that we could run to reproduce the issue. > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Fri Apr 3 22:01:10 2009 From: troy at resophonic.com (troy d. straszheim) Date: Fri, 03 Apr 2009 16:01:10 -0400 Subject: [C++-sig] embedded python ? In-Reply-To: References: <49D65BA4.10003@sympatico.ca> Message-ID: <49D66B06.90801@resophonic.com> mad city wrote: > Thanks. Good advice. > > From the quickstart project, the embedded.cpp file function > > > void exec_file_test(std::string const &script) > { > std::cout << "running file " << script << "..." << std::endl; > > // Run a python script in an empty environment. > python::dict global; > python::object result = python::exec_file(script.c_str(), global, > global); > > // Extract an object the script stored in the global dictionary. > BOOST_TEST(python::extract(global["number"]) == 42); > > std::cout << "success!" << std::endl; > } > > calls my python script file - parseLogs.py which starts with try something like this. When you exec the file you have to supply a globals dictionary that contains whatever globals you want to use (like import) Py_Initialize(); bp::object main = bp::import("__main__"); bp::object py_ = main.attr("__dict__"); bp::exec_file("conf.py", py_, py_); int = bp::extract(py_["some_int_is_here"]; -t From seefeld at sympatico.ca Fri Apr 3 22:50:49 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 03 Apr 2009 16:50:49 -0400 Subject: [C++-sig] embedded python ? In-Reply-To: References: <49D65BA4.10003@sympatico.ca> Message-ID: <49D676A9.5020809@sympatico.ca> mad city wrote: > Thanks. Good advice. > > From the quickstart project, the embedded.cpp file function > > > void exec_file_test(std::string const &script) > { > std::cout << "running file " << script << "..." << std::endl; > > // Run a python script in an empty environment. > python::dict global; > python::object result = python::exec_file(script.c_str(), global, > global); I'm not sure who suggested this, but I don't think this works, if the script runs anything interesting, as the builtin stuff is missing. (See the other mail for how to do it right.) Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From j.reid at mail.cryst.bbk.ac.uk Sat Apr 4 11:21:28 2009 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Sat, 04 Apr 2009 10:21:28 +0100 Subject: [C++-sig] Python exception traceback infomation in C++ Message-ID: I call my C++ extension from python and the C++ code in turn calls back into python code. When the python callbacks raise exceptions I can't easily find out the tracebacks, they stop short at the C++ interface. I might put decorators on all my python callbacks to log the tracebacks. Is there any better way to do this failing an extension of boost.python to propagate this information through the C++ layer? Did anything ever happen with the discussion in this thread? http://thread.gmane.org/gmane.comp.python.c++/12693/focus=12701 Regards, John. From gregor.burger at uibk.ac.at Sat Apr 4 11:23:55 2009 From: gregor.burger at uibk.ac.at (Gregor Burger) Date: Sat, 4 Apr 2009 11:23:55 +0200 Subject: [C++-sig] instantiate python classes in c++ In-Reply-To: References: <1238428534.49d0eb768108f@web-mail1.uibk.ac.at> Message-ID: <11bd6bba0904040223v18bab8c5v6c11d0250d900cd0@mail.gmail.com> On Fri, Apr 3, 2009 at 4:40 PM, Gennadiy Rozental wrote: > Gregor Burger uibk.ac.at> writes: > > > is it possible to use boost.python to define classes > > in a script (like in the one below), register the defined > > classes and later on create instances of the class? > > Yes thank god! ;-) > > > > Is it possible to provide the same globals and locals to call_method > > so that Flow and other classes are defined? > > No. You can't "update" global dictionary at the call point. > > This is the issue I am very much familiar with. You can find 2 posts from > me > with pretty much the same content. Maybe you can point me to the posts. I found you questions but not the answer including the solution. > > > The only viable solution I found is to *compile* the script first before > executing it. If I do this global dictionary is bound to the class methods > and > you code will work fine. > > Gennadiy > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogeeff at gmail.com Sat Apr 4 20:35:27 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Sat, 4 Apr 2009 18:35:27 +0000 (UTC) Subject: [C++-sig] instantiate python classes in c++ References: <1238428534.49d0eb768108f@web-mail1.uibk.ac.at> <11bd6bba0904040223v18bab8c5v6c11d0250d900cd0@mail.gmail.com> Message-ID: Gregor Burger uibk.ac.at> writes: > Maybe you can point me to the posts. I found you questions > but not theanswer including the solution.? The only solution I know is right below. >> The only viable solution I found is to *compile* the script first before >> executing it. If I do this global dictionary is bound to the class methods and >> you code will work fine. Gennadiy From macke at yar.nu Tue Apr 7 09:39:31 2009 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 07 Apr 2009 09:39:31 +0200 Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? Message-ID: Hi, We're in a spot where we're using third-party libraries that use different python wrappers. (Boost.Python, SIP currently, possibly SWIG later). Our own C++-classes are wrapped with Boost.Python a.t.m, but some of them contain Qt-objects, so PyQT needs to be used for that. Python is dynamic, so this ought to be doable, if not easy. :) Has anyone attempted to get this to work? What is the best strategy? Any pitfalls? Any code? :) I did manage to write a __getattr__ for my boost.python-wrapped qobject-inheriting classes that forwards to pyqt, but it won't work for dir() and I haven't managed to write __dir__ for my class as I need the self-object to be able to get the pyqt/sip wrapped instance. All help greatly appreciated. Cheers, /Marcus From mmmnow at gmail.com Wed Apr 8 13:24:56 2009 From: mmmnow at gmail.com (=?ISO-8859-2?Q?Micha=B3_Nowotka?=) Date: Wed, 8 Apr 2009 13:24:56 +0200 Subject: [C++-sig] indexing suite and py++ Message-ID: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> Hello, I want to expose following classes: class A { public: A(int a, int b) :a_(a),b_(b) {} int a_; int b_; int compute(){return a_ + b_;} }; class C : public A { public: C(int a, int b) :A(a,b){} }; struct TypeExposer // I have to add this class, otherwise Py++ won't expose std::deque - why? { typedef std::deque CDeque; CDeque deq; }; class F : public std::deque { public: F(){} int dlugosc() {return this->size();} }; In order to expose I use Py++ with indexing_suite_version = 2 parameter. Py++ generates code for boost.python without any warnings and generated code compiles well. But then in python I get TypeError: import test c = test.C(2,3) f = test.F() f.append(c) f[0] this causes: Traceback (most recent call last): File "", line 1, in TypeError: No to_python (by-value) converter found for C++ type: C When class C is base class everything works well. What should I change to get this code working with derived classes? And another problem - why do I have to define TypeExposer class? Now i must define it because otherwise Py++ won't expose std::deque. But IMO it should notice that F dirives from std::deque so std::deque must be exposed... Below I paste Py++ and Py++-generated code: import os from pyplusplus import module_builder from pygccxml import utils from pygccxml.declarations import matchers from pyplusplus.module_builder import call_policies mb = module_builder.module_builder_t( [r"test.h"] , gccxml_path=r"./bin_gccxml/gccxml --gccxml-compiler gcc-4.3" , working_directory=r"." , include_paths=['.'] , define_symbols=[] , indexing_suite_version = 2) mb.build_code_creator( module_name='test' ) mb.code_creator.precompiled_header = 'boost/python.hpp' mb.write_module( 'test.cpp' ) ////////////////////////////////////////////////////////////////////////////////////////////// // This file has been generated by Py++. #include "boost/python.hpp" #include "indexing_suite/value_traits.hpp" #include "indexing_suite/container_suite.hpp" #include "indexing_suite/deque.hpp" #include "test.h" namespace bp = boost::python; namespace boost { namespace python { namespace indexing { template<> struct value_traits< C >{ static bool const equality_comparable = false; static bool const less_than_comparable = false; template static void visit_container_class(PythonClass &, Policy const &){ } }; }/*indexing*/ } /*python*/ } /*boost*/ BOOST_PYTHON_MODULE(test){ { //::std::deque< C > typedef bp::class_< std::deque< C > > CDeque_exposer_t; CDeque_exposer_t CDeque_exposer = CDeque_exposer_t( "CDeque" ); bp::scope CDeque_scope( CDeque_exposer ); CDeque_exposer.def( bp::indexing::deque_suite< std::deque< C > >() ); } bp::class_< A >( "A", bp::init< int, int >(( bp::arg("a"), bp::arg("b") )) ) .def( "compute" , (int ( ::A::* )( ) )( &::A::compute ) ) .def_readwrite( "a_", &A::a_ ) .def_readwrite( "b_", &A::b_ ); bp::class_< C, bp::bases< A >, boost::noncopyable >( "C", bp::init< int, int >(( bp::arg("a"), bp::arg("b") )) ); bp::class_< F, bp::bases< std::deque< C > >, boost::noncopyable >( "F", bp::init< >() ) .def( "dlugosc" , (int ( ::F::* )( ) )( &::F::dlugosc ) ); bp::class_< TypeExposer, boost::noncopyable >( "TypeExposer", bp::no_init ) .def_readwrite( "deq", &TypeExposer::deq ); } -- Regards, Micha? Nowotka From troy at resophonic.com Wed Apr 8 14:01:59 2009 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 08 Apr 2009 08:01:59 -0400 Subject: [C++-sig] c++-sig page out of date Message-ID: <49DC9237.3030801@resophonic.com> I just stumbled on this, which is way out of date: http://www.python.org/community/sigs/current/cplusplus-sig/ Anybody know how to get it updated? -t From dave at boostpro.com Wed Apr 8 17:08:20 2009 From: dave at boostpro.com (David Abrahams) Date: Wed, 08 Apr 2009 11:08:20 -0400 Subject: [C++-sig] Preliminary progress on Boost.Python py3k support References: <1d7983e80904011307p76d4bfcdx9fb0a651f01cf13b@mail.gmail.com> Message-ID: on Wed Apr 01 2009, Haoyu Bai wrote: > Hi, > > I did some preliminary work on BPL py3k support in these days. > > With Troy's help we have a py3k SVN tree in sandbox now, which is > branched from trunk. I also tried to compile BPL with Python 3, and by > following the error report of the compiler, I did some patch - now we > have 14 .cpp files out of 28 in total can be compiled. The patch is > committed, you can see it here: [2]. Haoyu, Just FYI, the existing codebase was written to support MSVC6 and 7.0, and as such has lots of hacks and/or inferior idioms. I have basically dropped support for those compilers, so feel free to replace that code with more modern stuff as needed. > Please point me out if the code > has something don't conform to Boost coding policy. There's also > something interesting, maybe a bug I caught, for example: (Search the > changeset to see details) > > 39 // XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference > 40 // const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast("__module__"))); > 41 PyObject *mod = PyObject_GetAttrString( self_, "__module__"); Yes, looks like a bug, thanks. > Also I found some potential problem with Py_ssize_t, I will take this > as a chance to fix them. Please do. > The biggest problem I see still is the "Text Vs. Data Instead Of > Unicode Vs. 8-bit" in py3k. I think it makes sense to convert char const* to string in py3k... > As we discussed and the suggestion by > Niall [3], we have a clear solution for this ...I guess I'd better be more careful to keep up with that mailing list! I haven't had a chance to read Niall's post yet. > and I will work towarding this. The other changes in py3k such as > PyObject_HEAD change, int type removal and unbound method removal also > affected Boost.Python's code, but they don't require logical change of > BPL code and easy to handle. > > Hopefully in the end of this summer, we will have a Boost.Python > library with Python 3 support! Awesome; thanks for your efforts! -- Dave Abrahams BoostPro Computing http://www.boostpro.com From dave at boostpro.com Wed Apr 8 17:22:11 2009 From: dave at boostpro.com (David Abrahams) Date: Wed, 08 Apr 2009 11:22:11 -0400 Subject: [C++-sig] Some thoughts on py3k support References: <1d7983e80903171107m490ed2b2vd26cfae8e3bae853@mail.gmail.com> <49C18C44.4069.1A32860E@s_sourceforge.nedprod.com> Message-ID: on Wed Mar 18 2009, "Niall Douglas" wrote: > On 18 Mar 2009 at 2:07, Haoyu Bai wrote: > >> According to the current behavior of Boost.Python converters, the >> wrapped function in Python 3 will return a b"Hello" (which is a bytes >> object but not a string). So code like this will broken: >> >> if "Hello" == hello(): ... >> >> Because string object "Hello" is not equal to bytes object b"Hello" >> returned by hello(). We may change the behavior of converter to return >> a unicode string in Python 3, that would keep most of existing code >> compatible. Anyway there will be code really need a single byte string >> returned, a new converter can be explicitly specified for this. > > One shouldn't be doing such a comparison anyway IMHO, though the > idiom of equivalence between C++ immutable strings and python > immutable strings is long-standing. Well, that sort of thing comes up in the test suites, so we at least need to adjust. > Also, we need to fix booleans not working quite properly in BPL. Good one. >> There are more issues similar to this. I'll figure out more and write >> a detailed proposal as soon as possible. > > I have my own opinion on unicode and judging by the other posts, I'll > be disagreeing with just about everyone else. > > Firstly, I'd like to state that Python v3 has ditched the old string > system for very good reasons and this change more than any other has > created source incompatibilites in most code. One cannot expect much > difference in Boost.Python - code *should* need to be explicitly > ported. I'd rather say, "we shouldn't bend over backwards to maintain 100% backward compatibility because it's impossible." It should still be a goal to avoid forcing the authors of bindings to make changes where it's reasonable to do so. > Much like the open() function with text (and reusing its machinery), > I propose you need to specify the *default* encoding for immutable > const char * though it defaults from LC_LANG in most cases to UTF-8 - > that's right, const char * will be UTF-8 by default though it's > overridable. Are you suggesting that when converting to Python string, char const* should be interpreted by Boost.Python as UTF-8? I think that's pretty reasonable. Any bytes found in a C++ string that fall outside of 7-bit ASCII aren't portable anyway, are they? > This default encoding should be a per-python interpreter > setting (i.e. it uses whatever open() uses) though it can be > temporarily overridden using a specifier template. Now I"m a little confused about what you mean. > const unsigned char * looks better to me for immutable byte data Yes, if it's really just a bag of bytes and not text, I agree. > - I agree that some compilers have the option for char * == unsigned > char *, but these are rare and it's an unwise option in most cases. No, they're always different types. The option that some compilers support is that char can be an unsigned or a signed type. That's a big difference, and it means Haoyu doesn't need to worry about it. > std::vector is definitely the fellow for mutable byte > data. std::vector smells too much like a mutable string. I don't see what practical impact that should have on this project. > I appreciate that const char * defaulting to UTF-8 might be > controversial - after all, ISO C++ has remained very agnostic about > the matter (see http://www.open- > std.org/jtc1/sc22/wg21/docs/papers/2007/n2442.htm for a proposed > slight change). I have rationales though: > > 1. While unicode in C++ source anywhere other than in string literals > is a very bad idea, both MSVC and GCC support having the entire source > file in UTF-8 text and unicode characters in string literals being > incorporated as-is. This method of incorporating non-European letters > into string literals is too easy to avoid using ;). It's certainly > very common in Asia and until the u8 literal specifier is added to C++ > there isn't an easy workaround. It wouldn't be very open minded of us > to assume the world can still easily make do with ASCII- 7. Makes sense. > 2. A *lot* of library code e.g. GUI library code, most of Linux or > indeed the GNU C library, has moved to UTF-8 for its string literals. > Interfacing strings between BPL and this library code is made much > easier and natural if it takes UTF-8 as default. ditto > 3. "char *" in C and C++ means "a string" in the minds of most > programmers. char const* does. What to do about char* is a separate question. And don't forget char const (&)[N] > Having it be a set of bytes might be standards correct > but let's be clear, C style strings have always had escape sequences > so they have never been entirely pure byte sequences. I don't know what that means. Escape sequences disappear between the source file and the in-memory representation of the string. > Making this immutable bytes instead will make BPL unnatural to use - > expect questions here on c++-sig :) Agreed. > 4. Chances are that world + dog is going to move to UTF-8 eventually > anyway and that means all C++ source code. Might as well make that > the least typing required scenario. > > Anyway, I expect few will agree with me, but that's my opinion. I think you raised a number of irrelevant issues whose relevance I can't see, but I agree with the substance of your argument. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From dave at boostpro.com Wed Apr 8 17:28:45 2009 From: dave at boostpro.com (David Abrahams) Date: Wed, 08 Apr 2009 11:28:45 -0400 Subject: [C++-sig] Some thoughts on py3k support References: <1d7983e80903171107m490ed2b2vd26cfae8e3bae853@mail.gmail.com> <49C18C44.4069.1A32860E@s_sourceforge.nedprod.com> <1d7983e80903190653j4340b4a0u6044e5015ab300c0@mail.gmail.com> <49C27809.3055.1DCB7DA2@s_sourceforge.nedprod.com> Message-ID: on Thu Mar 19 2009, "Niall Douglas" wrote: > On 19 Mar 2009 at 21:53, Haoyu Bai wrote: > >> I'm felling the difference between char*, unsinged char* and the >> constant version and std::vector version of them would be a bit >> complicated and confusing. We may document it clearly, but things are >> still complicated. Any thoughts? > > Well, the whole concept of BPL is that it is extensible via overload > and partial specialisation. One might provide these as default out-of- > the-box but any client code is more than free to add their own type > specialisations. That's not true when it comes to the converters for builtin types like char const*. Maybe it should be true, but it's not. > The only actual concern is whether my proposed > overloads are a bit too generic and might interfere with client code, > but then that's why we have namespaces with Koenig lookup. > > I should add that this philosophical difference is why I am not a > Booster - I strongly feel that utility and power lies within flexible > structure rather than simple abstraction. This is why I went off and > wrote my own integrated metaprogramming library in TnFOX rather than > use Boost's - I was more than happy to sacrifice support for non- > compliant C++ compilers in return for vastly cleaner and more > powerful code. That said, as we are contributing towards BPL, I will > be sticking my philosophical hat into a drawer for the duration :) Interesting that you should say that. Boost.MPL makes few or no concessions to broken compilers in its interface design (only in the implementation). What is cleaner and more powerful about the TnFox appraoch? I can't find any details on the web. -- Dave Abrahams BoostPro Computing http://www.boostpro.com From brian.buras at verigy.com Wed Apr 8 18:06:39 2009 From: brian.buras at verigy.com (Buras, Brian) Date: Wed, 8 Apr 2009 11:06:39 -0500 Subject: [C++-sig] method chaining in noncopyable derived class Message-ID: <5E07F2A85589E74798B02EC48B8B01E60A3816@usplmvpbe002.ent.rt.verigy.net> I'm trying to wrap an API that uses method chaining (methods that return reference to same object) and restricts assignment/copy. Is there a reason I can't use return_internal_reference? # want to be able to do this in Python d = myexample.Derived("name") d.setSomething(500).execute() But I get a segfault at return of setSomething() If I separate the 2 method calls it works. Here is the API and boost::python wrapper: enum MODES {A,B}; class Base { public: Base(const string& p); virtual ~Base(); void execute(MODES mode = A); private: string pn; Base& operator=(const Base& rhs); Base(const Base&); }; class Derived : public Base { public: Derived(const string& p); virtual ~Derived(); Derived& setSomething(int a); private: int aa; }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(d_o,execute,0,1) BOOST_PYTHON_MODULE(myexample) { class_("Base",no_init); class_,boost::noncopyable >("Derived",init()) .def("execute",&Derived::execute,d_o()) .def("setSomething",&Derived::setSomething, return_internal_reference<>()) //.def("setSomething",&Derived::setSomething, return_value_policy()) //.def("setSomething",&Derived::setSomething, return_value_policy()); } -------------- next part -------------- An HTML attachment was scrubbed... URL: From renatox at gmail.com Wed Apr 8 18:33:32 2009 From: renatox at gmail.com (Renato Araujo) Date: Wed, 8 Apr 2009 13:33:32 -0300 Subject: [C++-sig] method chaining in noncopyable derived class In-Reply-To: <5E07F2A85589E74798B02EC48B8B01E60A3816@usplmvpbe002.ent.rt.verigy.net> References: <5E07F2A85589E74798B02EC48B8B01E60A3816@usplmvpbe002.ent.rt.verigy.net> Message-ID: <95291a80904080933i76ef7537sccb7e005c32ccb1d@mail.gmail.com> Hi Brian, in this case I think the correct solution is use "return_self<>()" verify documentation in: http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/return_arg.html#return_self-spec BR On Wed, Apr 8, 2009 at 1:06 PM, Buras, Brian wrote: > I'm trying to wrap an API that uses method chaining (methods that return > reference to same object) and restricts assignment/copy. Is there a reason I > can't use return_internal_reference? > > # want to be able to do this in Python > d = myexample.Derived("name") > d.setSomething(500).execute() > > But I get a segfault at return of setSomething() > If I separate the 2 method calls it works. > > Here is the API and boost::python wrapper: > enum MODES {A,B}; > > class Base { > public: > ??????? Base(const string& p); > ??????? virtual ~Base(); > ??????? void execute(MODES mode = A); > > private: > ??????? string pn; > ??????? Base& operator=(const Base& rhs); > ??????? Base(const Base&); > }; > > class Derived : public Base { > public: > ??????? Derived(const string& p); > ??????? virtual ~Derived(); > > ??????? Derived& setSomething(int a); > > private: > ??????? int aa; > }; > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(d_o,execute,0,1) > > BOOST_PYTHON_MODULE(myexample) { > > ??????? class_("Base",no_init); > ??????? class_,boost::noncopyable >>("Derived",init()) > ??????? ??????? .def("execute",&Derived::execute,d_o()) > ??????? ??????? .def("setSomething",&Derived::setSomething, > return_internal_reference<>()) > ??????? ??????? //.def("setSomething",&Derived::setSomething, > return_value_policy()) > ??????? ??????? //.def("setSomething",&Derived::setSomething, > return_value_policy()); > } > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Renato Araujo Oliveira Filho From justru at comcast.net Wed Apr 8 14:26:56 2009 From: justru at comcast.net (Russell McQueeney) Date: Wed, 08 Apr 2009 08:26:56 -0400 Subject: [C++-sig] Boost.Python help Message-ID: <49DC9810.9020007@comcast.net> I'm trying to build the tutorial example in the Boost.Python package (the package itself compiled and works (I think)) bjam says the test passes and gives output redirected to a file, but when I try to run the python script myself, it says it can't find module hello_ext. I have attached an example of me trying to get it to work. Thanks for helping! -------------- next part -------------- A non-text attachment was scrubbed... Name: test.doc Type: application/msword Size: 38139 bytes Desc: not available URL: From roman.yakovenko at gmail.com Wed Apr 8 23:14:54 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 9 Apr 2009 00:14:54 +0300 Subject: [C++-sig] indexing suite and py++ In-Reply-To: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> References: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> Message-ID: <7465b6170904081414x6534b742o7914cf9b42a3cf19@mail.gmail.com> 2009/4/8 Micha? Nowotka : > Hello, Good evening > I want to expose following classes: > > class A > { > public: > ? ? ? ?A(int a, int b) > ? ? ? ?:a_(a),b_(b) > ? ? ? ?{} > ? ? ? ?int a_; > ? ? ? ?int b_; > > int compute(){return a_ + b_;} > > }; > > class C : public A > { > > public: > > ? ? ? ?C(int a, int b) > ? ? ? ?:A(a,b){} > }; > > struct TypeExposer // I have to add this class, otherwise Py++ won't > expose std::deque - why? > { > ? ? ? ?typedef std::deque CDeque; > ? ? ? ?CDeque deq; > }; You can read the following documents: http://language-binding.net/pyplusplus/documentation/how_to/templates.html?highlight=templates http://language-binding.net/pyplusplus/documentation/how_to/hints.html?highlight=templates The short answer: gccxml doesn't dump information about template classes, so you need to instantiate it. > class F : ?public std::deque > { > ? ? ? ?public: > ? ? ? ? ? ? ? ?F(){} > ? ? ? ? ? ? ? ?int dlugosc() {return this->size();} > }; I am not sure how well Py++ support this use case ( deriving from std container ). I never had it. > In order to expose I use Py++ with indexing_suite_version = 2 > parameter. Py++ generates code for boost.python without any warnings > and generated code compiles well. > But then in python I get TypeError: > > import test > c = test.C(2,3) > f = test.F() > f.append(c) > f[0] > > this causes: > > Traceback (most recent call last): > ?File "", line 1, in > TypeError: No to_python (by-value) converter found for C++ type: C > > When class C is base class everything works well. What should I change > to get this code working with derived classes? I created the following test case and it works: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1699 I tested it on Wndows, VS 2003, using pygccxml and Py++ SVN version and boost version 1.37. I believe the same code will work on Linux too. Can you verify this? > And another problem - why do I have to define TypeExposer class? Now i > must define it because otherwise Py++ won't expose std::deque. But > IMO it should notice that F dirives from std::deque so > std::deque must be exposed... I don't see the TypeExposer definition. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rwgk at yahoo.com Thu Apr 9 01:19:44 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 8 Apr 2009 16:19:44 -0700 (PDT) Subject: [C++-sig] c++-sig page out of date In-Reply-To: <49DC9237.3030801@resophonic.com> References: <49DC9237.3030801@resophonic.com> Message-ID: <353762.66054.qm@web111416.mail.gq1.yahoo.com> I and David wrote the page currently shown seven years ago. A few years ago I sent a query to the Python people, about updating the page, but I never got a reply. I guess it is time to try again! My best idea for an updated page is simply this shortened version: SIG for development of Python/C++ integration The Python C++ SIG is a forum for discussions about the integration of Python and C++, with an emphasis on the development of the Boost.Python library. Suggestions regarding the direction of the development work and contributions in the form of source code should be posted to this SIG. About Boost.Python Boost.Python is a popular open-source tool for interfacing Python and C++. Boost.Python is built on accessible, well maintained, well documented components (the Boost C++ Library), so it does not tie its users to the services of any one programmer or organization. Developers worldwide have contributed significant unsolicited improvements to the project. The main developer and coordinator of the library is David Abrahams. Any suggestions, please let me know. ----- Original Message ---- From: troy d. straszheim To: Development of Python/C++ integration Sent: Wednesday, April 8, 2009 5:01:59 AM Subject: [C++-sig] c++-sig page out of date I just stumbled on this, which is way out of date: http://www.python.org/community/sigs/current/cplusplus-sig/ Anybody know how to get it updated? -t _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From rwgk at yahoo.com Thu Apr 9 01:32:07 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 8 Apr 2009 16:32:07 -0700 (PDT) Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? In-Reply-To: References: Message-ID: <3026.28072.qm@web111412.mail.gq1.yahoo.com> Since I didn't see any other responses, I'll offer what I know, even though it doesn't directly answer your question. A few years ago I experimented with SWIG - Boost.Python integration, where you can get easy access from C++ to SWIG-wrapped objects, inside a function wrapped with Boost.Python. The code is here: http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ Look for the files swig_arg.hpp, swig_args_ext.cpp, and search for "libswig" in the SConscript. I haven't tried this out for a long time. Anyway, I hope it gives you a start. Ralf ----- Original Message ---- From: Marcus Lindblom To: cplusplus-sig at python.org Sent: Tuesday, April 7, 2009 12:39:31 AM Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? Hi, We're in a spot where we're using third-party libraries that use different python wrappers. (Boost.Python, SIP currently, possibly SWIG later). Our own C++-classes are wrapped with Boost.Python a.t.m, but some of them contain Qt-objects, so PyQT needs to be used for that. Python is dynamic, so this ought to be doable, if not easy. :) Has anyone attempted to get this to work? What is the best strategy? Any pitfalls? Any code? :) I did manage to write a __getattr__ for my boost.python-wrapped qobject-inheriting classes that forwards to pyqt, but it won't work for dir() and I haven't managed to write __dir__ for my class as I need the self-object to be able to get the pyqt/sip wrapped instance. All help greatly appreciated. Cheers, /Marcus _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From lucianomw at gmail.com Thu Apr 9 15:21:02 2009 From: lucianomw at gmail.com (Luciano M. Wolf) Date: Thu, 9 Apr 2009 10:21:02 -0300 Subject: [C++-sig] Recursion problem while testing inheritance Message-ID: Hi, I'm doing some experiments calling methods from parent (or grandparent) class. I have a "Base" class defining a "test" virtual method. Class "Derived" inherits from "Base" but does not implement "test". At Python side (test.py) I redefine test and do a call to "Base.test()". The program ends up with a "RuntimeError: maximum recursion depth exceeded" error message. Any idea about this? Find attached a small example showing how to reproduce this problem. Regards, Luciano -------------- next part -------------- A non-text attachment was scrubbed... Name: boost_testing.tar.gz Type: application/x-gzip Size: 1285 bytes Desc: not available URL: From seefeld at sympatico.ca Thu Apr 9 16:21:44 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 09 Apr 2009 10:21:44 -0400 Subject: [C++-sig] Recursion problem while testing inheritance In-Reply-To: References: Message-ID: <49DE0478.5060604@sympatico.ca> Hi Luciano, Luciano M. Wolf wrote: > Hi, > > I'm doing some experiments calling methods from parent (or > grandparent) class. I have a "Base" class defining a "test" virtual > method. Class "Derived" inherits from "Base" but does not implement > "test". At Python side (test.py) I redefine test and do a call to > "Base.test()". The program ends up with a "RuntimeError: maximum > recursion depth exceeded" error message. Any idea about this? Find > attached a small example showing how to reproduce this problem. > That's an interesting problem ! I think it is clear what is going on here: when you invoke 'base.test()' from python, the interpreter looks up the 'right' method (i.e., picking the 'test' attribute from the right base class dictionary. However, the way that is implemented means it does its own lookup...including derived classes' dictionaries. Thus the circularity that leads to the endless loop. I'm not sure how to solve this, on a language level. I don't think there is a way to convey the fact that the function lookup is (what C++ calls) qualified, and thus, that it should be limited to a specific scope (the base class). May be someone else has ideas how to do this ? Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From rwgk at yahoo.com Thu Apr 9 19:44:44 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 9 Apr 2009 10:44:44 -0700 (PDT) Subject: [C++-sig] strange behavior with respect to numeric and Booleanoverloads In-Reply-To: <49C29CBC.4010006@resophonic.com> References: <32490DFF7774554A85D65D23A9F0F9380A42B084@chiex01> <32490DFF7774554A85D65D23A9F0F9380A4C913B@chiex01> <7465b6170903162240u29c034b2y8f7d1b95b68301fc@mail.gmail.com> <200903171103.11258.meine@informatik.uni-hamburg.de> <32490DFF7774554A85D65D23A9F0F9380A4C933C@chiex01> <49BFE68E.7090507@resophonic.com> <49C128A3.3060108@resophonic.com> <191399.71254.qm@web111407.mail.gq1.yahoo.com> <49C29CBC.4010006@resophonic.com> Message-ID: <677285.29224.qm@web111408.mail.gq1.yahoo.com> I checked in (svn rev. 52299) Troy's patch with an additional condition, e.g.: #if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT) I.e. the default behavior is unchanged, but people can add -DBOOST_PYTHON_BOOL_INT_STRICT to experiement. When I did this in my project, it took me several hours to correct bool/int mismatches. I also had to introduce a special trick to easily make bool arrays (mainly for unit tests), e.g. before it was array.bool([0,1,0,1]) but now it is array.int([0,1,0,1]).as_bool(). Because if things like this, I decided it is best not to make the new behavior the default. Ideas: Maybe we'll have a comprehensive overload solution after the summer, which will mean the current patch and the define will be obsolete. If not, it may be best to turn the compile-time choice into a runtime choice, similar to the docstring options (http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/docstring_options.html). I could do that if necessary. Ralf ----- Original Message ---- From: troy d. straszheim To: Development of Python/C++ integration Sent: Thursday, March 19, 2009 12:27:56 PM Subject: Re: [C++-sig] strange behavior with respect to numeric and Booleanoverloads Ralf W. Grosse-Kunstleve wrote: > The comprehensive solution sounds like a project. Do we have someone to work on this? > > I'm asking because I think Troy's proposed simple solution is better than the status quo. > I'm willing to work on it. I'd have to look at Daniel W's code to see if I want to push back on the simple solution or not... haven't done that yet. Maybe we want to get Haoyu thinking about this in the background, as well, he might be done with py3k support before the end of the gsoc summer. -t From troy at resophonic.com Thu Apr 9 20:28:04 2009 From: troy at resophonic.com (troy d. straszheim) Date: Thu, 09 Apr 2009 14:28:04 -0400 Subject: [C++-sig] strange behavior with respect to numeric and Booleanoverloads In-Reply-To: <677285.29224.qm@web111408.mail.gq1.yahoo.com> References: <32490DFF7774554A85D65D23A9F0F9380A42B084@chiex01> <32490DFF7774554A85D65D23A9F0F9380A4C913B@chiex01> <7465b6170903162240u29c034b2y8f7d1b95b68301fc@mail.gmail.com> <200903171103.11258.meine@informatik.uni-hamburg.de> <32490DFF7774554A85D65D23A9F0F9380A4C933C@chiex01> <49BFE68E.7090507@resophonic.com> <49C128A3.3060108@resophonic.com> <191399.71254.qm@web111407.mail.gq1.yahoo.com> <49C29CBC.4010006@resophonic.com> <677285.29224.qm@web111408.mail.gq1.yahoo.com> Message-ID: <49DE3E34.4040206@resophonic.com> Ralf W. Grosse-Kunstleve wrote: > I checked in (svn rev. 52299) Troy's patch with an additional condition, e.g.: > > #if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT) > > I.e. the default behavior is unchanged, but people can add -DBOOST_PYTHON_BOOL_INT_STRICT > to experiement. > > When I did this in my project, it took me several hours to correct bool/int mismatches. > I also had to introduce a special trick to easily make bool arrays (mainly for unit tests), > e.g. before it was array.bool([0,1,0,1]) but now it is array.int([0,1,0,1]).as_bool(). > Because if things like this, I decided it is best not to make the new behavior the default. Agree with the decision to #ifdef it... This might be worse than first-match, and the overload-order-bug has been around a long time without surfacing. It'd be hard to justify going that direction. Note that exactly the same situation exists for float and int, see https://svn.boost.org/trac/boost/browser/trunk/libs/python/test/test_overload_resolution.cpp which I checked in but didn't enable in the jamfiles. call each of those overloads functions with bools ints and floats and you get different results. So maybe there's a call for BOOST_PYTHON_STRICT_OVERLOADS, or somesuch. I dunno. > > Ideas: Maybe we'll have a comprehensive overload solution after the summer, which will mean > the current patch and the define will be obsolete. > If not, it may be best to turn the compile-time choice into a runtime choice, similar to > the docstring options (http://www.boost.org/doc/libs/1_38_0/libs/python/doc/v2/docstring_options.html). > > I could do that if necessary. So with strict checking turned *on*, you disambiguate manually: foo(bool(1), 'hi') but turning on strict checking breaks all kind of stuff. For the vast majority of cases, it seems, what's there is fine. So either grok and implement something like d. wallin / luabind's method, as dave suggests. Meanwhile, just riffing a little bit: maybe give the user a way to dig a particular overload out of the function. So if foo is overloaded so: void foo(int, std::string); void foo(bool, std::string); and both are wrapped, and I'm in python and want the second one, how about foo[ (bool, string) ](1, 'hi') where the bracket operator essentially returns the one exact-matching overload of foo for the type arguments provided. Or something. This makes overloading a leaky abstraction to some degree (you have to know c++ details to choose your overload), but then again they're already foreign to python; this would be for emergency cases. (moments later) After writing all that I'm inclined to have a closer look at the luabind implementation. -t > > Ralf > > > > ----- Original Message ---- > From: troy d. straszheim > To: Development of Python/C++ integration > Sent: Thursday, March 19, 2009 12:27:56 PM > Subject: Re: [C++-sig] strange behavior with respect to numeric and Booleanoverloads > > Ralf W. Grosse-Kunstleve wrote: >> The comprehensive solution sounds like a project. Do we have someone to work on this? >> >> I'm asking because I think Troy's proposed simple solution is better than the status quo. >> > > I'm willing to work on it. I'd have to look at Daniel W's code to see if I want to push back on the simple solution or not... haven't done that yet. Maybe we want to get Haoyu thinking about this in the background, as well, he might be done with py3k support before the end of the gsoc summer. > > -t > From dave at boostpro.com Fri Apr 10 04:35:45 2009 From: dave at boostpro.com (David Abrahams) Date: Thu, 09 Apr 2009 22:35:45 -0400 Subject: [C++-sig] Some thoughts on py3k support References: <1d7983e80903171107m490ed2b2vd26cfae8e3bae853@mail.gmail.com> <49C18C44.4069.1A32860E@s_sourceforge.nedprod.com> Message-ID: on Wed Apr 08 2009, David Abrahams wrote: > I think you raised a number of irrelevant issues whose relevance I can't > see, but I agree with the substance of your argument. And I raised a number of redundant issues that were redundant with one another... sorry, I didn't mean to hammer that point so hard; it just happened during editing :( -- Dave Abrahams BoostPro Computing http://www.boostpro.com From troy at resophonic.com Fri Apr 10 04:40:11 2009 From: troy at resophonic.com (troy d. straszheim) Date: Thu, 09 Apr 2009 22:40:11 -0400 Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? In-Reply-To: <3026.28072.qm@web111412.mail.gq1.yahoo.com> References: <3026.28072.qm@web111412.mail.gq1.yahoo.com> Message-ID: <49DEB18B.3080305@resophonic.com> Ralf W. Grosse-Kunstleve wrote: > Since I didn't see any other responses, I'll offer what I know, even though it doesn't directly answer > your question. > > A few years ago I experimented with SWIG - Boost.Python integration, where you can get easy access > from C++ to SWIG-wrapped objects, inside a function wrapped with Boost.Python. The code is here: > > http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ > > Look for the files swig_arg.hpp, swig_args_ext.cpp, and search for "libswig" in the > SConscript. > > I haven't tried this out for a long time. > Anyway, I hope it gives you a start. > Well, I asked in #python and #python-dev, got referred to webmaster at python.org, got an autoreply and then silence. Maybe I'll have to join some python dev lists and shout to find out who runs this thing. We'll see. -t From troy at resophonic.com Fri Apr 10 04:41:15 2009 From: troy at resophonic.com (troy d. straszheim) Date: Thu, 09 Apr 2009 22:41:15 -0400 Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? In-Reply-To: <49DEB18B.3080305@resophonic.com> References: <3026.28072.qm@web111412.mail.gq1.yahoo.com> <49DEB18B.3080305@resophonic.com> Message-ID: <49DEB1CB.6060104@resophonic.com> troy d. straszheim wrote: > Ralf W. Grosse-Kunstleve wrote: > > Well, I asked in #python and #python-dev, got referred to > webmaster at python.org, got an autoreply and then silence. Maybe I'll > have to join some python dev lists and shout to find out who runs this > thing. We'll see. > WHOOPS I was actually replying to the "c++-sig page out of date" thread. -t From rogeeff at gmail.com Sat Apr 11 01:59:36 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Fri, 10 Apr 2009 23:59:36 +0000 (UTC) Subject: [C++-sig] Exported class as mixin Message-ID: Hi, I've got exported class: class_( "MyInterface" ) ... And I've got class in Python: class ABC(object): ... I am doing some processing of the class definition in Python and want to be able to do the following (clazz here is ABC: clazz.__bases__ = (MyInterface,) + clazz.__bases__ I am getting following error: TypeError: __bases__ assignment: 'MyInterface' deallocator differs from 'object' I can add mixins defined in Python fine. Only mixins exported from C++ giving me a problem. Any advise? Gennadiy From rwgk at yahoo.com Mon Apr 13 18:59:35 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 13 Apr 2009 09:59:35 -0700 (PDT) Subject: [C++-sig] strange behavior with respect to numeric and Booleanoverloads In-Reply-To: <49DE3E34.4040206@resophonic.com> References: <32490DFF7774554A85D65D23A9F0F9380A42B084@chiex01> <32490DFF7774554A85D65D23A9F0F9380A4C913B@chiex01> <7465b6170903162240u29c034b2y8f7d1b95b68301fc@mail.gmail.com> <200903171103.11258.meine@informatik.uni-hamburg.de> <32490DFF7774554A85D65D23A9F0F9380A4C933C@chiex01> <49BFE68E.7090507@resophonic.com> <49C128A3.3060108@resophonic.com> <191399.71254.qm@web111407.mail.gq1.yahoo.com> <49C29CBC.4010006@resophonic.com> <677285.29224.qm@web111408.mail.gq1.yahoo.com> <49DE3E34.4040206@resophonic.com> Message-ID: <477273.39676.qm@web111415.mail.gq1.yahoo.com> > Agree with the decision to #ifdef it... This might be worse than > first-match, and the overload-order-bug has been around a long time > without surfacing. I wouldn't say it is a bug, more a missing feature. Dave and I knew about the drawbacks from the start, but we didn't have the time for the comprehensive solution. I've been using Boost.Python heavily for 8+ years now, and it has only been a few times that I found the simple first-match solution annoying. In the worst case, you just give the overloads different names in Python. (I don't know how easy this is with Py++, though.) > It'd be hard to justify going that direction. Note that exactly the > same situation exists for float and int, There is an important difference: int and float are numeric types. bool really isn't (I think it is highly undesirable that bool and int are implicitly convertible in Python and C++). In a very early stage of the Boost.Python v2 reimplementation, even str matched float or int! bool matching float or int is similar, only we couldn't do anything about it since bool didn't exist as a type in Python 2.2, which is all we had during the v2 reimplementation. > So with strict checking turned *on*, you disambiguate manually: > > foo(bool(1), 'hi') > > but turning on strict checking breaks all kind of stuff. It wasn't that bad for me, just a little boring having to retrofit the mountains of old code. The end-result is cleaner, so it's worth it. But it think it would be bad to force it on people. We need a soft approach, so that everybody can do it at his own schedule. > For the > vast majority of cases, it seems, what's there is fine. So either > grok and implement something like d. wallin / luabind's method, > as dave suggests. I haven't thought about this very much at all, so this may be stupid: Could the C++ template matching rules be a role model? These rules are time tested and I believe are very well spelled out. > and both are wrapped, and I'm in python and want the second one, how about > > foo[ (bool, string) ](1, 'hi') That seems like it could be a lot of work to implement, and it would be very unusual. You can achieve the same via: foo_int_string(1, 'hi') foo_float_string(1, 'hi') In the few cases that I had the int/float problem, on second thought it turned out to be better to use more telling (different) names for the functions. I.e. I never found myself resorting to appending the argument type names. Another nice solution is to disambiguate via keywords. Ralf From mmmnow at gmail.com Mon Apr 13 22:22:47 2009 From: mmmnow at gmail.com (=?ISO-8859-2?Q?Micha=B3_Nowotka?=) Date: Mon, 13 Apr 2009 22:22:47 +0200 Subject: [C++-sig] indexing suite and py++ In-Reply-To: <7465b6170904081414x6534b742o7914cf9b42a3cf19@mail.gmail.com> References: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> <7465b6170904081414x6534b742o7914cf9b42a3cf19@mail.gmail.com> Message-ID: <3acfd39a0904131322lcb4d16ds9463c6fa8332403b@mail.gmail.com> >I created the following test case and it works: >http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1699 > >I tested it on Wndows, VS 2003, using pygccxml and Py++ SVN version >and boost version 1.37. I believe the same code will work on Linux >too. > >Can you verify this? Yes, I found that I used official (from ubuntu repositories) version of gccxml. When I switched to binaries from gccxml_bin/v09/linux2/bin everything went ok (whith one exception: pygccxml/gccxml_bin/v09/linux2/share/gccxml-0.9/GCC/4.3 directory from SVN version is empty and this causes an error. I copied gccxml_biuldins.h from pygccxml/gccxml_bin/v09/win32/share/gccxml-0.9/GCC/4.3). Ok, but now I want to run all test included. First of all I can't do it because of an error: Traceback (most recent call last): File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/test_all.py", line 113, in import indexing_suites_v2_bug_tester File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/indexing_suites_v2_bug_tester.py", line 14, in import dl ImportError: No module named dl As far I know, this was a bug in python on x86_64 enviroments. Is there any way around this dependency? Secondly, when I exclude indexing_suites_v2_bug test I can see that not all the other tests were completed successfully: ! test (custom_smart_ptr_classes_tester.tester_t) - FAIL ! test (deepcopy_tester.tester_t) - FAIL ! test (virtual_inheritance_tester.tester_t) - ERROR Does it mean smart pointers and virtual inheritance is not supported under linux? Are there any workarounds? And finally another use case. Consider following code: #include //here is std::pair defined class I { public: I(int a, int b) { pair_.first = a; pair_.second = b; } std::pair pair_; int compute(){return pair_.first + pair_.second;} }; After parsing it Py++ produces warning: WARNING: std::pair [struct] > execution error W1040: The declaration is unexposed, but there are other > declarations, which refer to it. This could cause "no to_python converter > found" run time error. Declarations: I::pair_ [variable] I don't understand it because indexing suite v2 can handle vectors, sets, deques etc. so why pair is here an exception? There is pair.hpp file in indexing_suite directory so I guess this package can work with std::pair. Even if I add following lines (IMO completely useless in this case): namespace pyplusplus{ namespace aliases{ typedef std::pair< std::string, int > PairOfStringInt; void instantiate( PairOfStringInt psi){} typedef std::pair< std::string, double > PairOfStringDouble; void instantiate( PairOfStringDouble psd){} } } or: int a = sizeof(std::pair< std::string, int >); int b = sizeof(std::pair< std::string, double >); I still get this warning. I also read this discussion: http://sourceforge.net/tracker/index.php?func=detail&aid=1991168&group_id=118209&atid=684318 but adding these lines: mb.class_('PairOfStringInt').include() mb.class_('PairOfStringDouble').include() or: mb.class_('std::pair< std::string, int >').include() mb.class_('std::pair< std::string, double >').include() doesn't solve the problem and generate error: pygccxml.declarations.matcher.declaration_not_found_t: Unable to find declaration. matcher: [(decl type==class_t) and (name==std::pair< std::string, double >)] so how should I modify the code to get std::pair exposed? From macke at yar.nu Tue Apr 14 14:03:36 2009 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 14 Apr 2009 14:03:36 +0200 Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? In-Reply-To: <3026.28072.qm@web111412.mail.gq1.yahoo.com> References: <3026.28072.qm@web111412.mail.gq1.yahoo.com> Message-ID: <49E47B98.9060704@yar.nu> Ralf W. Grosse-Kunstleve wrote: > Since I didn't see any other responses, I'll offer what I know, even though it doesn't directly answer > your question. > > A few years ago I experimented with SWIG - Boost.Python integration, where you can get easy access > from C++ to SWIG-wrapped objects, inside a function wrapped with Boost.Python. The code is here: > > http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ > > Look for the files swig_arg.hpp, swig_args_ext.cpp, and search for "libswig" in the > SConscript. > > I haven't tried this out for a long time. > Anyway, I hope it gives you a start. Thanks. Hm. I've currently done this in python: *** f = MyWidget() # MyWidget is a boost::python wrapped object that # inherits QTimer, that has start() # def _q_getattr(self, attr): if type(self) == type(type(MyWidget)): raise AttributeError else: return getattr(sip.wrapinstance(self.myself(), QObject), attr) MyWidget.__getattr__ = _q_getattr f.start() # works! :) *** But I want to implement __dir__ in the same way to get full coverage, and that's trickier. Cheers, /Marcus From macke at yar.nu Tue Apr 14 14:03:36 2009 From: macke at yar.nu (Marcus Lindblom) Date: Tue, 14 Apr 2009 14:03:36 +0200 Subject: [C++-sig] PyQt (SIP) and Boost.Python interop? In-Reply-To: <3026.28072.qm@web111412.mail.gq1.yahoo.com> References: <3026.28072.qm@web111412.mail.gq1.yahoo.com> Message-ID: <49E47B98.9060704@yar.nu> Ralf W. Grosse-Kunstleve wrote: > Since I didn't see any other responses, I'll offer what I know, even though it doesn't directly answer > your question. > > A few years ago I experimented with SWIG - Boost.Python integration, where you can get easy access > from C++ to SWIG-wrapped objects, inside a function wrapped with Boost.Python. The code is here: > > http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ > > Look for the files swig_arg.hpp, swig_args_ext.cpp, and search for "libswig" in the > SConscript. > > I haven't tried this out for a long time. > Anyway, I hope it gives you a start. Thanks. Hm. I've currently done this in python: *** f = MyWidget() # MyWidget is a boost::python wrapped object that # inherits QTimer, that has start() # def _q_getattr(self, attr): if type(self) == type(type(MyWidget)): raise AttributeError else: return getattr(sip.wrapinstance(self.myself(), QObject), attr) MyWidget.__getattr__ = _q_getattr f.start() # works! :) *** But I want to implement __dir__ in the same way to get full coverage, and that's trickier. Cheers, /Marcus From josh.davidson at lmco.com Tue Apr 14 22:30:30 2009 From: josh.davidson at lmco.com (Davidson, Josh) Date: Tue, 14 Apr 2009 14:30:30 -0600 Subject: [C++-sig] pygccxml and multidimensional arrays Message-ID: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> Machine: x86_64 running RH EL 5.0 Pygccxml version 1.0.0 Gcc-xml version 0.9.0 If I create a struct similar to: typedef struct { uint16_t a[4][2][3]; } blah; And use pygccxml to parse it, the type attribute for the field "a" is set to: uint16_t[3][2][4]. Does anyone know why the dimensions are reversed? -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Apr 16 07:04:24 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 16 Apr 2009 08:04:24 +0300 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> Message-ID: <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> On Tue, Apr 14, 2009 at 11:30 PM, Davidson, Josh wrote: > Machine: x86_64 running RH EL 5.0 > > Pygccxml version 1.0.0 > > Gcc-xml version 0.9.0 > > > > If I create a struct similar to: > > > > typedef struct { > > ??? uint16_t a[4][2][3]; > > } blah; > > > > And use pygccxml to parse it, the type attribute for the field ?a? is set > to: uint16_t[3][2][4].? Does anyone know why the dimensions are reversed? I guess this is Py++/pygccxml bug. Can you create small test case of what you are trying to do. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Thu Apr 16 08:00:06 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 16 Apr 2009 09:00:06 +0300 Subject: [C++-sig] indexing suite and py++ In-Reply-To: <3acfd39a0904131322lcb4d16ds9463c6fa8332403b@mail.gmail.com> References: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> <7465b6170904081414x6534b742o7914cf9b42a3cf19@mail.gmail.com> <3acfd39a0904131322lcb4d16ds9463c6fa8332403b@mail.gmail.com> Message-ID: <7465b6170904152300l3430ef12o4230d0ec50158a7b@mail.gmail.com> 2009/4/13 Micha? Nowotka : > Ok, but now I want to run all test included. Okey. > First of all I can't do it because of an error: > > Traceback (most recent call last): > ?File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/test_all.py", > line 113, in > ? ?import indexing_suites_v2_bug_tester > ?File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/indexing_suites_v2_bug_tester.py", > line 14, in > ? ?import dl > ImportError: No module named dl > As far I know, this was a bug in python on x86_64 enviroments. Is > there any way around this dependency? I guess so. Python-Ogre project, was built and used in such environment and it doesn't have such problem. > Secondly, when I exclude indexing_suites_v2_bug test I can see that > not all the other tests were completed successfully: > > ! ?test (custom_smart_ptr_classes_tester.tester_t) ?- ?FAIL This one should fail. I need to free some time to investigate it. > ! ?test (deepcopy_tester.tester_t) ?- ?FAIL I would like to see the error. Basically that test checks that exception is raised in "copy.deepcopy" function. > ! ?test (virtual_inheritance_tester.tester_t) ?- ?ERROR The test is very simple, it checks that Py++ generates the right code. It is interesting to see the error. > Does it mean smart pointers and virtual inheritance is not supported > under linux? Are there any workarounds? No, it doesn't. The only conclusion you can do right now: Py++ tests are broken on your platform and need some investigation. > And finally another use case. Consider following code: > > #include //here is std::pair defined > > class I > { > public: > ? ? ? ?I(int a, int b) > ? ? ? ?{ > ? ? ? ? ? pair_.first = a; > ? ? ? ? ? pair_.second = b; > ? ? ? ?} > ? ? ? ?std::pair pair_; > > int compute(){return pair_.first + pair_.second;} > }; > > After parsing it Py++ produces warning: > > WARNING: std::pair [struct] >> execution error W1040: The declaration is unexposed, but there are other >> declarations, which refer to it. This could cause "no to_python converter >> found" run time error. Declarations: ? I::pair_ [variable] > > I don't understand it because indexing suite v2 can handle vectors, > sets, deques etc. so why pair is here an exception? Well, code generation process is about "special case" treatment. Please open ticket on SourceForge, so I could add this functionality before next release. > There is pair.hpp > file in indexing_suite directory so I guess this package can work with > std::pair. Even if I add following lines > (IMO completely useless in this case): > > namespace pyplusplus{ > > ? ? namespace aliases{ > > > ? ? ? ?typedef std::pair< std::string, int > PairOfStringInt; > ? ? ? ?void instantiate( PairOfStringInt psi){} > ? ? ? ?typedef std::pair< std::string, double > PairOfStringDouble; > ? ? ? ?void instantiate( PairOfStringDouble psd){} > > > > ? ? } > ?} > > or: > > int a = sizeof(std::pair< std::string, int >); > int b = sizeof(std::pair< std::string, double >); > > I still get this warning. > > I also read this discussion: > http://sourceforge.net/tracker/index.php?func=detail&aid=1991168&group_id=118209&atid=684318 > > but adding these lines: > mb.class_('PairOfStringInt').include() > mb.class_('PairOfStringDouble').include() > > or: > mb.class_('std::pair< std::string, int >').include() > mb.class_('std::pair< std::string, double >').include() > > doesn't solve the problem and generate error: > > pygccxml.declarations.matcher.declaration_not_found_t: Unable to find > declaration. ?matcher: [(decl type==class_t) and (name==std::pair< > std::string, double >)] > > so how should I modify the code to get std::pair exposed? I committed new test: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev Basically, I suggest you to read the following article: http://language-binding.net/pygccxml/query_interface.html The short version: if you cant select the desired class, than check it name first and than use it: mb = module_builder_t( ... ) pair = mb.classes( lambda cls: cls.name.startswith( 'pair' ) ) for p in pair: print p.name HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From josh.davidson at lmco.com Thu Apr 16 18:03:34 2009 From: josh.davidson at lmco.com (Davidson, Josh) Date: Thu, 16 Apr 2009 10:03:34 -0600 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> Message-ID: <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> Sure. 1) Put the following into a file named mdim.h: #ifndef MDIM_H_ #define MDIM_H_ #include typedef struct { uint16_t a[4][2][3]; } blah; #endif 2) Put the following into a file named parse.py: #!/usr/bin/env python import os import sys from pygccxml import parser from pygccxml import declarations includePaths = [] defineSymbols = [] config = parser.config_t(gccxml_path="gccxml") decls = parser.parse(["mdim.h"]) xml = declarations.get_global_namespace(decls) cls = xml.classes()[0] for var in cls.variables(): print var.name, var.type 3) Execute: python parse.py Observe the following print statement: "a uint16_t[3][2][4]" -----Original Message----- From: cplusplus-sig-bounces+josh.davidson=lmco.com at python.org [mailto:cplusplus-sig-bounces+josh.davidson=lmco.com at python.org] On Behalf Of Roman Yakovenko Sent: Wednesday, April 15, 2009 11:04 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] pygccxml and multidimensional arrays On Tue, Apr 14, 2009 at 11:30 PM, Davidson, Josh wrote: > Machine: x86_64 running RH EL 5.0 > > Pygccxml version 1.0.0 > > Gcc-xml version 0.9.0 > > > > If I create a struct similar to: > > > > typedef struct { > > ??? uint16_t a[4][2][3]; > > } blah; > > > > And use pygccxml to parse it, the type attribute for the field "a" is set > to: uint16_t[3][2][4].? Does anyone know why the dimensions are reversed? I guess this is Py++/pygccxml bug. Can you create small test case of what you are trying to do. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From mmmnow at gmail.com Fri Apr 17 00:46:42 2009 From: mmmnow at gmail.com (=?ISO-8859-2?Q?Micha=B3_Nowotka?=) Date: Fri, 17 Apr 2009 00:46:42 +0200 Subject: [C++-sig] indexing suite and py++ In-Reply-To: <7465b6170904152300l3430ef12o4230d0ec50158a7b@mail.gmail.com> References: <3acfd39a0904080424lffe6e82i8ee705f643fbf0db@mail.gmail.com> <7465b6170904081414x6534b742o7914cf9b42a3cf19@mail.gmail.com> <3acfd39a0904131322lcb4d16ds9463c6fa8332403b@mail.gmail.com> <7465b6170904152300l3430ef12o4230d0ec50158a7b@mail.gmail.com> Message-ID: <3acfd39a0904161546y467e8c5bi759cdc0e0549a8a6@mail.gmail.com> 2009/4/16 Roman Yakovenko : > ! test (deepcopy_tester.tester_t) - FAIL >I would like to see the error. Basically that test checks that >exception is raised in "copy.deepcopy" function. Here you are: 140736560794048 140736560794032 140736560794016 FAIL ====================================================================== FAIL: test (__main__.tester_t) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 153, in test self.run_tests(pypp) File "deepcopy_tester.py", line 30, in run_tests self.failIfNotRaisesAny( copy.deepcopy, items ) File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 50, in failIfNotRaisesAny self.failUnless(was_exception, 'exception has not been raised during execution.') AssertionError: exception has not been raised during execution. > ! test (virtual_inheritance_tester.tester_t) - ERROR >The test is very simple, it checks that Py++ generates the right code. >It is interesting to see the error. That's the log of compilation errors you asked: g++ -o virtual_inheritance.os -c -fPIC -I/usr/include/boost -I/usr/include/python2.5 -I. -I/home/mnowotka/pygccxml/pyplusplus_dev/unittests/data virtual_inheritance.cpp /usr/include/boost/python/class.hpp: In static member function 'static void boost::python::detail::error::virtual_function_default::must_be_derived_class_member(const Default&) [with Default = void (derived_wrapper::*)(), T = derived_wrapper, Fn = void (base::*)()]': /usr/include/boost/python/class.hpp:565: instantiated from 'void boost::python::class_::def_default(const char*, Fn, const Helper&, mpl_::bool_) [with Fn = void (base::*)(), Helper = boost::python::detail::def_helper, W = derived_wrapper, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:548: instantiated from 'void boost::python::class_::def_impl(T*, const char*, Fn, const Helper&, ...) [with T = derived, Fn = void (base::*)(), Helper = boost::python::detail::def_helper, W = derived_wrapper, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:608: instantiated from 'void boost::python::class_::def_maybe_overloads(const char*, Fn, const A1&, ...) [with Fn = void (base::*)(), A1 = void (derived_wrapper::*)(), W = derived_wrapper, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' /usr/include/boost/python/class.hpp:244: instantiated from 'boost::python::class_& boost::python::class_::def(const char*, A1, const A2&) [with A1 = void (base::*)(), A2 = void (derived_wrapper::*)(), W = derived_wrapper, X1 = boost::python::bases, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' virtual_inheritance.cpp:85: instantiated from here /usr/include/boost/python/class.hpp:146: error: pointer to member conversion via virtual base 'base' scons: *** [virtual_inheritance.os] Error 1 scons: building terminated because of errors. ERROR ====================================================================== ERROR: test (__main__.tester_t) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 151, in test autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' --file=%s' % self.__generated_scons_file_name ) File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/autoconfig.py", line 95, in compile raise RuntimeError( "unable to compile extension. See output for the errors." ) RuntimeError: unable to compile extension. See output for the errors. ---------------------------------------------------------------------- Ran 1 test in 2.188s I think that it is worth to mention that I work on ubuntu 8.10. >Please open ticket on SourceForge, so I could add this functionality >before next release. OK: http://sourceforge.net/tracker/?func=detail&aid=2768337&group_id=118209&atid=684321 When could I expect next release? I guess you are busy. >I committed new test: >http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev OK, test passed but: 1. If I change run_tests method defined in std_pair_tester to: def run_tests( self, module): pairA = module.pair_less__int_comma__int__greater_(2,3) pairB = module.pair_less__int_comma__int__greater_(2,3) self.failUnless( pairA.first == pairB.first and pairA.second == pairB.second ) self.failUnless( pairA == pairB ) I get: Traceback (most recent call last): File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 153, in test self.run_tests(pypp) File "std_pair_tester.py", line 29, in run_tests self.failUnless( pairA == pairB ) AssertionError 2. When I add indexing_suite_version=2 parameter to __init__ in std_pair_tester.py I get an error: Traceback (most recent call last): File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 148, in test self._create_extension_source_file() File "/home/mnowotka/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py", line 105, in _create_extension_source_file , compiler=autoconfig.cxx_parsers_cfg.gccxml.compiler) File "/usr/lib/python2.5/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 95, in __init__ , indexing_suite_version) File "/usr/lib/python2.5/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 149, in __parse_declarations for cls in global_ns.decls(decl_type=decls_package.class_declaration_t): File "/usr/lib/python2.5/site-packages/pygccxml/declarations/scopedef.py", line 399, in decls , allow_empty=allow_empty) File "/usr/lib/python2.5/site-packages/pygccxml/declarations/scopedef.py", line 377, in _find_multiple raise RuntimeError( "Multi declaration query returned 0 declarations." ) RuntimeError: Multi declaration query returned 0 declarations. >The short version: if you cant select the desired class, than check it >name first and than use it: >mb = module_builder_t( ... ) >pair = mb.classes( lambda cls: cls.name.startswith( 'pair' ) ) >for p in pair: > print p.name OK, so in my project I found classes names: pair pair and included it: mb.class_('pair').include() mb.class_('pair').include() Now, warnings dissapeared but in generated wrapper code file "indexing_suite/pair.hpp" is not included (although I have indexing_suite_version=2 set). Luckily i don't get error like in std_pair_tester.py when using second version of indexing suite. So once again: Why I want std::pair export to be handled by indexing suite v2? 1. Because I belive a pair exported with this package will pass the assertion: [(pairA.first == pairB.first && pairA.second == pairB.second) <==> pairA == pairB] 2. It will be consistent with other STL containers wich are automaticaly handled by py++ with indexing suite v2. And last issue: I don't understand why upgrading GCCXML version helped in derived_from_deque test case. In such case generated wrapper code should be different depending on GCCXML version. And code generated by older version is so "strange" that it makes it possible to insert derived class into vector but access to this inserted element is impossible. This sounds suspiciously. -- Regards, Micha? Nowotka From frankinshtein at bk.ru Sun Apr 19 15:12:32 2009 From: frankinshtein at bk.ru (Denis) Date: Sun, 19 Apr 2009 19:12:32 +0600 Subject: [C++-sig] boost python and shared_ptr Message-ID: <49EB2340.5030609@bk.ru> Hi, sorry for my English, but I hope you will understand and help me find solution. Thanks! there are C++ (pseudo) code: class A { public: void test() { printf(__FUNCTION__); } } shared_ptr gA; shared_ptr GetA() { return gA; } //wrapping code: class_ , boost::noncopyable> ("A") .def("test", &A::test) ; def("getA", GetA); and Python code: a = GetA() a.test() #works proxy = weakref.proxy(a) proxy.test() #works del a proxy.test() # failed!!! #but object is still live in C++ please help me fix it. I know it is not Python/Boost bug, it is correct behaviour. What I want? I want to create PyObject for every object from C++ and save it inside of my C++ class. something like this(pseudocode): class A { object _self; }; if (a->_self == 0) a->_self = makePyObjectForExistingClass(this) return _self and this PyObject should be deleted automatically when object will die in C++ Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From renatox at gmail.com Sun Apr 19 17:12:56 2009 From: renatox at gmail.com (Renato Araujo) Date: Sun, 19 Apr 2009 12:12:56 -0300 Subject: [C++-sig] boost python and shared_ptr In-Reply-To: <49EB2340.5030609@bk.ru> References: <49EB2340.5030609@bk.ru> Message-ID: <95291a80904190812m28bb033ag489055f3680cf347@mail.gmail.com> I don't know if this is exactly what do you want. take a look in this doc: http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#xref BR On Sun, Apr 19, 2009 at 10:12 AM, Denis wrote: > Hi, sorry for my English, > but I hope you will understand and help me find solution. > Thanks! > > there are C++ (pseudo) code: > > class A > { > public: > ? ??? void test() > ??? { > ??? ??? printf(__FUNCTION__); > ??? } > } > > shared_ptr gA; > shared_ptr? GetA() > { > ????????????? return gA; > } > > //wrapping code: > class_ , boost::noncopyable> ("A") > ??? ??? .def("test", &A::test) ; > def("getA", GetA); > > > and Python code: > > a = GetA() > a.test()? #works > > proxy = weakref.proxy(a) > proxy.test()? #works > > del a > proxy.test() # failed!!! > #but object is still live in C++ > > please help me fix it. > I know it is not Python/Boost? bug, it is correct behaviour. > > What I want? > > I want to create PyObject for every object from C++? and save it inside of > my C++ class. > something like this(pseudocode): > class A? {?? object _self;???? }; > > if (a->_self == 0) > ?? a->_self = makePyObjectForExistingClass(this) > return _self > > > and this PyObject should be deleted automatically when object will die in > C++ > > > > Thanks! > > > > > > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Renato Araujo Oliveira Filho From glok_twen at yahoo.com Mon Apr 20 07:53:02 2009 From: glok_twen at yahoo.com (glok_twen) Date: Sun, 19 Apr 2009 22:53:02 -0700 (PDT) Subject: [C++-sig] boost python in visual c++ 2008 Message-ID: <23130743.post@talk.nabble.com> hi. i have used boost python to create the sample from the doc within visual studio. a dll has resulted. but when i copy that dll to any of numerous places on my path, and run a python shell, i keep getting: ImportError: no module named hello Here is the code, it's contained in 2 modules within visual c++ (maybe that part of the problem?): ***** first module ***** // boost_pyth_01.cpp : Defines the exported functions for the DLL application. // #include using namespace boost::python; //#include "stdafx.h" __declspec(dllexport) struct World { void set(std::string msg) { this->msg = msg; } std::string greet() { return msg; } std::string msg; }; BOOST_PYTHON_MODULE(hello) { class_("World") .def("greet", &World::greet) .def("set", &World::set) ; } ***** and, second module ***** // dllmain.cpp : Defines the entry point for the DLL application. #include "stdafx.h" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } it does build a dll, named after my project name in the first module. i copied this dll to numerous places on my path. still get the error above in the python shell. also i get this warning during the link: 1>d:\cpp_testing\boost_pyth_01\boost_pyth_01.cpp(15) : warning C4091: '__declspec(dllexport)' : ignored on left of 'World' when no variable is declared -- View this message in context: http://www.nabble.com/boost-python-in-visual-c%2B%2B-2008-tp23130743p23130743.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From mmmnow at gmail.com Mon Apr 20 09:18:36 2009 From: mmmnow at gmail.com (=?ISO-8859-2?Q?Micha=B3_Nowotka?=) Date: Mon, 20 Apr 2009 09:18:36 +0200 Subject: [C++-sig] boost python in visual c++ 2008 In-Reply-To: <23130743.post@talk.nabble.com> References: <23130743.post@talk.nabble.com> Message-ID: <3acfd39a0904200018k547fee29v1495f2f7dfe0d825@mail.gmail.com> Try renaming hello.dll to hello.pyc. -- Regards Micha? Nowotka From divinekid at gmail.com Mon Apr 20 09:20:32 2009 From: divinekid at gmail.com (Haoyu Bai) Date: Mon, 20 Apr 2009 15:20:32 +0800 Subject: [C++-sig] boost python in visual c++ 2008 In-Reply-To: <23130743.post@talk.nabble.com> References: <23130743.post@talk.nabble.com> Message-ID: <1d7983e80904200020r9d4e498w1a9fcc2f98e81556@mail.gmail.com> On Mon, Apr 20, 2009 at 1:53 PM, glok_twen wrote: > > hi. > > i have used boost python to create the sample from the doc within visual > studio. a dll has resulted. but when i copy that dll to any of numerous > places on my path, and run a python shell, i keep getting: > > ImportError: no module named hello > > Here is the code, it's contained in 2 modules within visual c++ (maybe that > part of the problem?): > > ***** first module ***** > > // boost_pyth_01.cpp : Defines the exported functions for the DLL > application. > // > > #include > using namespace boost::python; > > > //#include "stdafx.h" > > __declspec(dllexport) struct World > { > ? ?void set(std::string msg) { this->msg = msg; } > ? ?std::string greet() { return msg; } > ? ?std::string msg; > }; > > > BOOST_PYTHON_MODULE(hello) > { > ? ?class_("World") > ? ? ? ?.def("greet", &World::greet) > ? ? ? ?.def("set", &World::set) > ? ?; > } > > ***** and, second module ***** > > // dllmain.cpp : Defines the entry point for the DLL application. > #include "stdafx.h" > > BOOL APIENTRY DllMain( HMODULE hModule, > ? ? ? ? ? ? ? ? ? ? ? DWORD ?ul_reason_for_call, > ? ? ? ? ? ? ? ? ? ? ? LPVOID lpReserved > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ) > { > ? ? ? ?switch (ul_reason_for_call) > ? ? ? ?{ > ? ? ? ?case DLL_PROCESS_ATTACH: > ? ? ? ?case DLL_THREAD_ATTACH: > ? ? ? ?case DLL_THREAD_DETACH: > ? ? ? ?case DLL_PROCESS_DETACH: > ? ? ? ? ? ? ? ?break; > ? ? ? ?} > ? ? ? ?return TRUE; > } > > > it does build a dll, named after my project name in the first module. i > copied this dll to numerous places on my path. still get the error above in > the python shell. > > also i get this warning during the link: > > 1>d:\cpp_testing\boost_pyth_01\boost_pyth_01.cpp(15) : warning C4091: > '__declspec(dllexport)' : ignored on left of 'World' when no variable is > declared > > -- > View this message in context: http://www.nabble.com/boost-python-in-visual-c%2B%2B-2008-tp23130743p23130743.html > Sent from the Python - c++-sig mailing list archive at Nabble.com. > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > Hi, Are you compiled your module to a file with '.dll' extension? Accord to Python document, the '.dll' extension will not be recognized by Python after version 2.5. (http://docs.python.org/extending/windows.html) You should change the extension name to '.pyd'. -- Haoyu Bai From mmmnow at gmail.com Mon Apr 20 09:24:56 2009 From: mmmnow at gmail.com (=?ISO-8859-2?Q?Micha=B3_Nowotka?=) Date: Mon, 20 Apr 2009 09:24:56 +0200 Subject: [C++-sig] boost python in visual c++ 2008 In-Reply-To: <1d7983e80904200020r9d4e498w1a9fcc2f98e81556@mail.gmail.com> References: <23130743.post@talk.nabble.com> <1d7983e80904200020r9d4e498w1a9fcc2f98e81556@mail.gmail.com> Message-ID: <3acfd39a0904200024q236639abl787999ac7241bfbe@mail.gmail.com> > You should change the extension name to '.pyd'. My mistake. Of course it is 'pyd' not 'pyc'. From glok_twen at yahoo.com Mon Apr 20 19:50:03 2009 From: glok_twen at yahoo.com (glok_twen) Date: Mon, 20 Apr 2009 10:50:03 -0700 (PDT) Subject: [C++-sig] boost python in visual c++ 2008 In-Reply-To: <3acfd39a0904200024q236639abl787999ac7241bfbe@mail.gmail.com> References: <23130743.post@talk.nabble.com> <1d7983e80904200020r9d4e498w1a9fcc2f98e81556@mail.gmail.com> <3acfd39a0904200024q236639abl787999ac7241bfbe@mail.gmail.com> Message-ID: <23141591.post@talk.nabble.com> thank you, got it working. turns out visual studio actually had indeed automatically created a file called "hello.pyd". i just hadn't been looking for it. so i copied that into my Python25/DLLs/ directory. then i needed to copy the boost_python dll itself (that i had built from the actual boost code) into the windows/system32 directory and everything worked. Micha? Nowotka wrote: > >> You should change the extension name to '.pyd'. > > My mistake. Of course it is 'pyd' not 'pyc'. > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > -- View this message in context: http://www.nabble.com/boost-python-in-visual-c%2B%2B-2008-tp23130743p23141591.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From brian.o'kennedy at vicon.com Tue Apr 21 17:12:08 2009 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Tue, 21 Apr 2009 16:12:08 +0100 Subject: [C++-sig] Extending python and using debug interpreter on Linux Message-ID: <6BF44CD613458D479057BDB27207F2E0038E9B71@omgsvr02.omg.local> Hi, I've built a local copy of Python with PY_DEBUG enabled and tried import a simple module which only defs a single c++ function returning a std::string. My test involves importing the module, and then quitting the interpreter; I'm not trying to call anything in the module. This works as expected in Release mode on linux (as well as working correctly on Windows for Release and Debug(with PY_DEBUG). However, on Linux using the debug interpreter I get a "Fatal Python error: UNREF invalid object" with the callstack as follows: #0 0xb7f3e430 in __kernel_vsyscall () #1 0xb7bf48a0 in raise () from /lib/tls/i686/cmov/libc.so.6 #2 0xb7bf6268 in abort () from /lib/tls/i686/cmov/libc.so.6 #3 0xb7ea2837 in Py_FatalError (msg=0xb7ed7ed4 "UNREF invalid object") at Python/pythonrun.c:1561 #4 0xb7dfe3d2 in _Py_ForgetReference (op=0xb7b87754) at Objects/object.c:1918 #5 0xb7dfe431 in _Py_Dealloc (op=0xb7b87754) at Objects/object.c:1937 #6 0xb7df2b12 in insertdict (mp=0xb7b89714, key=0xb7b7a208, hash=1901421549, value=0xb7efa8a8) at Objects/dictobject.c:420 #7 0xb7df33e0 in PyDict_SetItem (op=0xb7b89714, key=0xb7b7a208, value=0xb7efa8a8) at Objects/dictobject.c:645 #8 0xb7e8f4b7 in PyImport_Cleanup () at Python/import.c:475 #9 0xb7e9f44c in Py_Finalize () at Python/pythonrun.c:399 #10 0xb7ea2a1e in Py_Exit (sts=0) at Python/pythonrun.c:1618 #11 0xb7ea0e0a in handle_system_exit () at Python/pythonrun.c:1054 #12 0xb7ea0e3b in PyErr_PrintEx (set_sys_last_vars=1) at Python/pythonrun.c:1064 #13 0xb7ea0af1 in PyErr_Print () at Python/pythonrun.c:978 #14 0xb7ea00ca in PyRun_InteractiveOneFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", flags=0xbf83f4ac) at Python/pythonrun.c:795 #15 0xb7e9fcda in PyRun_InteractiveLoopFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", flags=0xbf83f4ac) at Python/pythonrun.c:723 #16 0xb7e9fb06 in PyRun_AnyFileExFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", closeit=0, flags=0xbf83f4ac) at Python/pythonrun.c:692 #17 0xb7eb0ade in Py_Main (argc=1, argv=0xbf83f5b4) at Modules/main.c:532 #18 0x080485e2 in main (argc=Cannot access memory at address 0x3392 Anyone have any ideas what is going wrong? I'm aware that there are issues with Boost Python and Py_Finalize, but is that what is causing this problem? Using Boost 1.38.0 and Python 2.5.4, both built from source on both Linux Ubuntu gcc42 and Windows Vista using VS2005. Thanks, Brian ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ From robin.gilks at tait.co.nz Wed Apr 22 01:33:32 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Wed, 22 Apr 2009 11:33:32 +1200 Subject: [C++-sig] Expanding embedded code Message-ID: <49EE57CC.9070803@tait.co.nz> A difficult question to put a title to so I'll paint a brief scenario... The application is written in c++ It receives a data message and instantiates a message decoder class. Based on the contends that are extracted into the class variables, a response is built by instantiating an encoder class and setting its class variables with setter methods. At this point I want to pass control over to a Python script so that it can modify the encoder class variables (via the accessors) if required before the response is actually sent. These accessors would form an extension to the interpreter. Note that doing more work in the Python script is not an option - too much data in too short a time!! I've got as far as embedding the interpreter and calling the correct method in a script but I've hit a problem in extending the interpreter to access the decoder and encoder classes in my main app. Note that I want to access the specific instances of the classes to manipulate the class variables that were set before entering the Python domain. Now the questions... * My understanding is that extending Python *always* uses a dynamically loaded library (i.e. a run time linkage) as part of the import mechanism - is there something in the C/API that will override this? If I load an extra library, even one built from the same source as my classes in the main app, I won't be accessing the same instance of them. * Since the class has already be instantiated in the main app, how do I pass the instance pointer to Python so that it can pass it back when it makes the extension call to my class methods (assuming I can get past the previous point!!). I would assume that it involves a PyCObject but none of the code examples I have found give much clue as to how the extension is invoked from the Python side with the instance pointer apart from when using a new_class constructor call. I'm sure I'm close, I just can't get past the two points above... Cheers -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From seefeld at sympatico.ca Wed Apr 22 03:39:40 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 21 Apr 2009 21:39:40 -0400 Subject: [C++-sig] Expanding embedded code In-Reply-To: <49EE57CC.9070803@tait.co.nz> References: <49EE57CC.9070803@tait.co.nz> Message-ID: <49EE755C.8080105@sympatico.ca> Robin Gilks wrote: > A difficult question to put a title to so I'll paint a brief scenario... > > The application is written in c++ > It receives a data message and instantiates a message decoder class. > Based on the contends that are extracted into the class variables, a > response is built by instantiating an encoder class and setting its > class variables with setter methods. At this point I want to pass > control over to a Python script so that it can modify the encoder > class variables (via the accessors) if required before the response is > actually sent. These accessors would form an extension to the > interpreter. Note that doing more work in the Python script is not an > option - too much data in too short a time!! You say "The application is written in c++" which I read as the above already exists, and is not subject to (re-)design. Otherwise I would suggest to do most of this inside Python itself, given the highly dynamic nature of the problem. > > I've got as far as embedding the interpreter and calling the correct > method in a script but I've hit a problem in extending the interpreter > to access the decoder and encoder classes in my main app. Some nit-picking: You are not extending the interpreter. You are adding to the runtime (environment). > > Note that I want to access the specific instances of the classes to > manipulate the class variables that were set before entering the > Python domain. Now the questions... > > * My understanding is that extending Python *always* uses a > dynamically loaded library (i.e. a run time linkage) as part of the > import mechanism - is there something in the C/API that will override > this? If I load an extra library, even one built from the same source > as my classes in the main app, I won't be accessing the same instance > of them. Indeed, there is no reason to having to dlopen() (or however your platform does this). You can entirely operate within the same compilation unit. For an example, see the boost/libs/python/test/exec.cpp test that defines an 'embedded_hello' module, then injects it directly into the Python runtime module map via 'PyImport_AppendInitTab()'. See https://svn.boost.org/trac/boost/browser/trunk/libs/python/test/exec.cpp > > * Since the class has already be instantiated in the main app, how do > I pass the instance pointer to Python so that it can pass it back when > it makes the extension call to my class methods (assuming I can get > past the previous point!!). I would assume that it involves a > PyCObject but none of the code examples I have found give much clue as > to how the extension is invoked from the Python side with the instance > pointer apart from when using a new_class constructor call. I hope the following is intuitive enough. If not, please ask: -8<--------------------------------- using namespace boost; ... python::class_ type("Type", ...); // create wrapper ... python::object instance = type(); // instantiate it python::object main = import("__main__"); python::object global = main.attr("__dict__"); global["instance"] = ptr(instance); // ptr() makes sure the object is passed by-reference. python::object result = python::exec_file(script, global, global); -8<--------------------------------- At this point, the script will have had its opportunity to interact with your 'instance' object directly. But, it may also have stored other stuff into the 'global' dictionary, which you can extract now that the script has returned: -8<--------------------------------- python::object something = global["something"]; extract e(something); if (e.check()) // is this a SomethingElse instance ? { SomethingElse &something_else = e(); // extract it... ... // ...and use it. } -8<--------------------------------- You get the idea... Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From brian.o'kennedy at vicon.com Wed Apr 22 15:31:04 2009 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Wed, 22 Apr 2009 14:31:04 +0100 Subject: [C++-sig] Extending python and using debug interpreter on Linux In-Reply-To: <6BF44CD613458D479057BDB27207F2E0038E9B71@omgsvr02.omg.local> References: <6BF44CD613458D479057BDB27207F2E0038E9B71@omgsvr02.omg.local> Message-ID: <6BF44CD613458D479057BDB27207F2E0038E9DE4@omgsvr02.omg.local> After diving deeper into boost.python and python than I felt comfortable with, I found my own stupid mistake. On Windows, the presence of _DEBUG causes Py_DEBUG to be defined, but this is not the case on Linux. When I include boost/python.hpp I need to define both BOOST_DEBUG_PYTHON and Py_DEBUG: Currently I'm wrapping includes of boost.python like so: ------------------------------------------------------------- #define BOOST_PYTHON_NO_LIB #ifdef _DEBUG #define BOOST_DEBUG_PYTHON #ifndef WIN32 #define Py_DEBUG #endif #pragma comment(lib, "boost_python-vc80-mt-gyd-1_38.lib" ) #else #pragma comment(lib, "boost_python-vc80-mt-1_38.lib" ) #endif #include ------------------------------------------------------------- -----Original Message----- From: cplusplus-sig-bounces+brian.okennedy=vicon.com at python.org [mailto:cplusplus-sig-bounces+brian.okennedy=vicon.com at python.org] On Behalf Of Brian O'Kennedy Sent: 21 April 2009 16:12 To: Cplusplus-sig at python.org Subject: [C++-sig] Extending python and using debug interpreter on Linux Hi, I've built a local copy of Python with PY_DEBUG enabled and tried import a simple module which only defs a single c++ function returning a std::string. My test involves importing the module, and then quitting the interpreter; I'm not trying to call anything in the module. This works as expected in Release mode on linux (as well as working correctly on Windows for Release and Debug(with PY_DEBUG). However, on Linux using the debug interpreter I get a "Fatal Python error: UNREF invalid object" with the callstack as follows: #0 0xb7f3e430 in __kernel_vsyscall () #1 0xb7bf48a0 in raise () from /lib/tls/i686/cmov/libc.so.6 #2 0xb7bf6268 in abort () from /lib/tls/i686/cmov/libc.so.6 #3 0xb7ea2837 in Py_FatalError (msg=0xb7ed7ed4 "UNREF invalid object") at Python/pythonrun.c:1561 #4 0xb7dfe3d2 in _Py_ForgetReference (op=0xb7b87754) at Objects/object.c:1918 #5 0xb7dfe431 in _Py_Dealloc (op=0xb7b87754) at Objects/object.c:1937 #6 0xb7df2b12 in insertdict (mp=0xb7b89714, key=0xb7b7a208, hash=1901421549, value=0xb7efa8a8) at Objects/dictobject.c:420 #7 0xb7df33e0 in PyDict_SetItem (op=0xb7b89714, key=0xb7b7a208, value=0xb7efa8a8) at Objects/dictobject.c:645 #8 0xb7e8f4b7 in PyImport_Cleanup () at Python/import.c:475 #9 0xb7e9f44c in Py_Finalize () at Python/pythonrun.c:399 #10 0xb7ea2a1e in Py_Exit (sts=0) at Python/pythonrun.c:1618 #11 0xb7ea0e0a in handle_system_exit () at Python/pythonrun.c:1054 #12 0xb7ea0e3b in PyErr_PrintEx (set_sys_last_vars=1) at Python/pythonrun.c:1064 #13 0xb7ea0af1 in PyErr_Print () at Python/pythonrun.c:978 #14 0xb7ea00ca in PyRun_InteractiveOneFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", flags=0xbf83f4ac) at Python/pythonrun.c:795 #15 0xb7e9fcda in PyRun_InteractiveLoopFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", flags=0xbf83f4ac) at Python/pythonrun.c:723 #16 0xb7e9fb06 in PyRun_AnyFileExFlags (fp=0xb7d23420, filename=0xb7eeaf07 "", closeit=0, flags=0xbf83f4ac) at Python/pythonrun.c:692 #17 0xb7eb0ade in Py_Main (argc=1, argv=0xbf83f5b4) at Modules/main.c:532 #18 0x080485e2 in main (argc=Cannot access memory at address 0x3392 Anyone have any ideas what is going wrong? I'm aware that there are issues with Boost Python and Py_Finalize, but is that what is causing this problem? Using Boost 1.38.0 and Python 2.5.4, both built from source on both Linux Ubuntu gcc42 and Windows Vista using VS2005. Thanks, Brian ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ From troy at resophonic.com Wed Apr 22 16:05:29 2009 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 22 Apr 2009 10:05:29 -0400 Subject: [C++-sig] Extending python and using debug interpreter on Linux In-Reply-To: <6BF44CD613458D479057BDB27207F2E0038E9DE4@omgsvr02.omg.local> References: <6BF44CD613458D479057BDB27207F2E0038E9B71@omgsvr02.omg.local> <6BF44CD613458D479057BDB27207F2E0038E9DE4@omgsvr02.omg.local> Message-ID: <49EF2429.80505@resophonic.com> Brian O'Kennedy wrote: > After diving deeper into boost.python and python than I felt comfortable > with, I found my own stupid mistake. > > On Windows, the presence of _DEBUG causes Py_DEBUG to be defined, but > this is not the case on Linux. When I include boost/python.hpp I need to > define both BOOST_DEBUG_PYTHON and Py_DEBUG: Currently I'm wrapping > includes of boost.python like so: > > ------------------------------------------------------------- > #define BOOST_PYTHON_NO_LIB > > #ifdef _DEBUG > #define BOOST_DEBUG_PYTHON > #ifndef WIN32 > #define Py_DEBUG > #endif > #pragma comment(lib, "boost_python-vc80-mt-gyd-1_38.lib" ) > #else > #pragma comment(lib, "boost_python-vc80-mt-1_38.lib" ) > #endif > > #include > ------------------------------------------------------------- > Hi, Do you know how Py_DEBUG is getting set on windows? I'm wondering where to fix this. Boost.build? in boost/python.hpp itself? -t From brian.o'kennedy at vicon.com Wed Apr 22 16:39:10 2009 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Wed, 22 Apr 2009 15:39:10 +0100 Subject: [C++-sig] Extending python and using debug interpreter on Linux In-Reply-To: <49EF2429.80505@resophonic.com> References: <6BF44CD613458D479057BDB27207F2E0038E9B71@omgsvr02.omg.local><6BF44CD613458D479057BDB27207F2E0038E9DE4@omgsvr02.omg.local> <49EF2429.80505@resophonic.com> Message-ID: <6BF44CD613458D479057BDB27207F2E0038E9E3E@omgsvr02.omg.local> I think the configure step on linux generates the pyconfig.h file which contains #define Py_DEBUG 1 On Windows, the pyconfig.h file comes from Python/PCBuild/pyconfig.h which seems to be hand generated and contains: #ifdef _DEBUG # define Py_DEBUG #endif I suppose the reason this was done is that configure is not used on Windows; instead we rely on the configuration types of Visual Studio to pick between debug and release builds. Most users of Boost.python would not want this set anyway which is why boost/python/detail/wrap_python.hpp exists to suppress the automatic definition of Py_DEBUG on windows in debug builds. Brian -----Original Message----- From: cplusplus-sig-bounces+brian.okennedy=vicon.com at python.org [mailto:cplusplus-sig-bounces+brian.okennedy=vicon.com at python.org] On Behalf Of troy d. straszheim Sent: 22 April 2009 15:05 To: Development of Python/C++ integration Subject: Re: [C++-sig] Extending python and using debug interpreter on Linux Brian O'Kennedy wrote: > After diving deeper into boost.python and python than I felt comfortable > with, I found my own stupid mistake. > > On Windows, the presence of _DEBUG causes Py_DEBUG to be defined, but > this is not the case on Linux. When I include boost/python.hpp I need to > define both BOOST_DEBUG_PYTHON and Py_DEBUG: Currently I'm wrapping > includes of boost.python like so: > > ------------------------------------------------------------- > #define BOOST_PYTHON_NO_LIB > > #ifdef _DEBUG > #define BOOST_DEBUG_PYTHON > #ifndef WIN32 > #define Py_DEBUG > #endif > #pragma comment(lib, "boost_python-vc80-mt-gyd-1_38.lib" ) > #else > #pragma comment(lib, "boost_python-vc80-mt-1_38.lib" ) > #endif > > #include > ------------------------------------------------------------- > Hi, Do you know how Py_DEBUG is getting set on windows? I'm wondering where to fix this. Boost.build? in boost/python.hpp itself? -t _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ From renatox at gmail.com Wed Apr 22 17:07:57 2009 From: renatox at gmail.com (Renato Araujo) Date: Wed, 22 Apr 2009 12:07:57 -0300 Subject: [C++-sig] python objects not is the same in separated modules Message-ID: <95291a80904220807m6b8349e6r3e15d458b11219f4@mail.gmail.com> Hi guys, I found a problems with my binds when I work with separated modules. In my function where return a c++ pointer to a object, this not return the same python object used in setter function. The main point here is because this works fine when all classes are exported in the same module but when I split the module this stop work. Module pybase ========================= class Base { private: Base *_child; public: void setChild(Base *parent); Base* child(); virtual ~Base(); }; class BaseWrapper : public Base, public wrapper { public: typedef class_ class_type; }; BOOST_PYTHON_MODULE(pybase) { BaseWrapper::class_type foo("Base"); foo.def("setChild", &Base::setChild); foo.def("child", &Base::child, return_internal_reference<>()); } Module pyother =================================== class Other : public Base { public: virtual ~Other(); }; class OtherWrapper : public Other, public wrapper { public: typedef class_, noncopyable > class_type; }; BOOST_PYTHON_MODULE(pyother) { OtherWrapper::class_type other("Other"); } Python test ========================================== #create a class exported in module pyother t = Other() #create a class exported in module pybase o = Base() #set base child o.setChild(t) #get object used in previous function c = o.child() #compare both object this need be true print t print c print t == c this happen when I use "Other" object in "setChild" and "child" function. when I use "Base" object works fine. I put a small example annexed in this e-mail. -- BR Renato Araujo Oliveira Filho -------------- next part -------------- A non-text attachment was scrubbed... Name: boosttest.tar.gz Type: application/x-gzip Size: 2566 bytes Desc: not available URL: From josh.davidson at lmco.com Wed Apr 22 22:43:03 2009 From: josh.davidson at lmco.com (Davidson, Josh) Date: Wed, 22 Apr 2009 14:43:03 -0600 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> Message-ID: <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> Is this a confirmed bug? Thanks, Josh -----Original Message----- From: cplusplus-sig-bounces+josh.davidson=lmco.com at python.org [mailto:cplusplus-sig-bounces+josh.davidson=lmco.com at python.org] On Behalf Of Davidson, Josh Sent: Thursday, April 16, 2009 10:04 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] pygccxml and multidimensional arrays Sure. 1) Put the following into a file named mdim.h: #ifndef MDIM_H_ #define MDIM_H_ #include typedef struct { uint16_t a[4][2][3]; } blah; #endif 2) Put the following into a file named parse.py: #!/usr/bin/env python import os import sys from pygccxml import parser from pygccxml import declarations includePaths = [] defineSymbols = [] config = parser.config_t(gccxml_path="gccxml") decls = parser.parse(["mdim.h"]) xml = declarations.get_global_namespace(decls) cls = xml.classes()[0] for var in cls.variables(): print var.name, var.type 3) Execute: python parse.py Observe the following print statement: "a uint16_t[3][2][4]" -----Original Message----- From: cplusplus-sig-bounces+josh.davidson=lmco.com at python.org [mailto:cplusplus-sig-bounces+josh.davidson=lmco.com at python.org] On Behalf Of Roman Yakovenko Sent: Wednesday, April 15, 2009 11:04 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] pygccxml and multidimensional arrays On Tue, Apr 14, 2009 at 11:30 PM, Davidson, Josh wrote: > Machine: x86_64 running RH EL 5.0 > > Pygccxml version 1.0.0 > > Gcc-xml version 0.9.0 > > > > If I create a struct similar to: > > > > typedef struct { > > ??? uint16_t a[4][2][3]; > > } blah; > > > > And use pygccxml to parse it, the type attribute for the field "a" is set > to: uint16_t[3][2][4].? Does anyone know why the dimensions are reversed? I guess this is Py++/pygccxml bug. Can you create small test case of what you are trying to do. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From robin.gilks at tait.co.nz Thu Apr 23 04:15:38 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Thu, 23 Apr 2009 14:15:38 +1200 Subject: [C++-sig] Expanding embedded code In-Reply-To: <49EE755C.8080105@sympatico.ca> References: <49EE57CC.9070803@tait.co.nz> <49EE755C.8080105@sympatico.ca> Message-ID: <49EFCF4A.4050104@tait.co.nz> Stefan Seefeld wrote: > Robin Gilks wrote: >> A difficult question to put a title to so I'll paint a brief scenario... >> >> The application is written in c++ >> It receives a data message and instantiates a message decoder class. >> Based on the contends that are extracted into the class variables, a >> response is built by instantiating an encoder class and setting its >> class variables with setter methods. At this point I want to pass >> control over to a Python script so that it can modify the encoder >> class variables (via the accessors) if required before the response >> is actually sent. These accessors would form an extension to the >> interpreter. Note that doing more work in the Python script is not an >> option - too much data in too short a time!! > > You say "The application is written in c++" which I read as the above > already exists, and is not subject to (re-)design. > Otherwise I would suggest to do most of this inside Python itself, > given the highly dynamic nature of the problem. > >> >> I've got as far as embedding the interpreter and calling the correct >> method in a script but I've hit a problem in extending the >> interpreter to access the decoder and encoder classes in my main app. > > Some nit-picking: You are not extending the interpreter. You are > adding to the runtime (environment). > >> >> Note that I want to access the specific instances of the classes to >> manipulate the class variables that were set before entering the >> Python domain. Now the questions... >> >> * My understanding is that extending Python *always* uses a >> dynamically loaded library (i.e. a run time linkage) as part of the >> import mechanism - is there something in the C/API that will override >> this? If I load an extra library, even one built from the same source >> as my classes in the main app, I won't be accessing the same instance >> of them. > > Indeed, there is no reason to having to dlopen() (or however your > platform does this). You can entirely operate within the same > compilation unit. For an example, see the > boost/libs/python/test/exec.cpp test that defines an 'embedded_hello' > module, then injects it directly into the Python runtime module map > via 'PyImport_AppendInitTab()'. > > See > https://svn.boost.org/trac/boost/browser/trunk/libs/python/test/exec.cpp > >> >> * Since the class has already be instantiated in the main app, how do >> I pass the instance pointer to Python so that it can pass it back >> when it makes the extension call to my class methods (assuming I can >> get past the previous point!!). I would assume that it involves a >> PyCObject but none of the code examples I have found give much clue >> as to how the extension is invoked from the Python side with the >> instance pointer apart from when using a new_class constructor call. > > I hope the following is intuitive enough. If not, please ask: > > -8<--------------------------------- > > using namespace boost; > ... > python::class_ type("Type", ...); // create wrapper > ... > python::object instance = type(); // instantiate it > python::object main = import("__main__"); > python::object global = main.attr("__dict__"); > global["instance"] = ptr(instance); // ptr() makes sure the object is > passed by-reference. > > python::object result = python::exec_file(script, global, global); > > -8<--------------------------------- > > At this point, the script will have had its opportunity to interact > with your 'instance' object directly. > But, it may also have stored other stuff into the 'global' dictionary, > which you can extract now that the script has returned: > > -8<--------------------------------- > > python::object something = global["something"]; > extract e(something); > if (e.check()) // is this a SomethingElse instance ? > { > SomethingElse &something_else = e(); // extract it... > ... // ...and use it. > } > > -8<--------------------------------- > > You get the idea... > > Regards, > Stefan > I'm still having a problem with the python side of things - the c++ side mostly makes sense. For example, the "class instances" section of the page at http://wiki.cacr.caltech.edu/danse/index.php/Lots_more_details_on_writing_wrappers I can follow with no problems but I've no idea how to invoke it from python with either the "wrap_new_Numbers" call or the subsequent "wrap_Numbers_MemberMult" call. I just don't get what the python code should look like to get the void pointer to the class instance at all! Any chance of a Python 3 liner that shows how its done? -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From roman.yakovenko at gmail.com Thu Apr 23 19:11:21 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 23 Apr 2009 20:11:21 +0300 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> Message-ID: <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> On Wed, Apr 22, 2009 at 11:43 PM, Davidson, Josh wrote: > Is this a confirmed bug? > > Thanks, I am sorry, but I am pretty busy these days ( too much production problems and too litle people who handles them ). I will try to take a look on your problem this evening. I will let you know. Do you have some concrete usage example, so may be, I will be able to provide quick work-around? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From josh.davidson at lmco.com Thu Apr 23 19:17:45 2009 From: josh.davidson at lmco.com (Davidson, Josh) Date: Thu, 23 Apr 2009 11:17:45 -0600 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> Message-ID: <5A2986C73A1DCC4EB5CC1C22D82700090FF61E05@emss02m11.us.lmco.com> I'm using information provided by pygccxml to generate Construct objects (http://construct.wikispaces.com/) that are capable of reading and writing to data structures stored in shared memory. Right now, I just manually reverse the indices any time I detect an array type before I generate a Construct. Josh -----Original Message----- From: cplusplus-sig-bounces+josh.davidson=lmco.com at python.org [mailto:cplusplus-sig-bounces+josh.davidson=lmco.com at python.org] On Behalf Of Roman Yakovenko Sent: Thursday, April 23, 2009 11:11 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] pygccxml and multidimensional arrays On Wed, Apr 22, 2009 at 11:43 PM, Davidson, Josh wrote: > Is this a confirmed bug? > > Thanks, I am sorry, but I am pretty busy these days ( too much production problems and too litle people who handles them ). I will try to take a look on your problem this evening. I will let you know. Do you have some concrete usage example, so may be, I will be able to provide quick work-around? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From roman.yakovenko at gmail.com Thu Apr 23 20:21:28 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 23 Apr 2009 21:21:28 +0300 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <5A2986C73A1DCC4EB5CC1C22D82700090FF61E05@emss02m11.us.lmco.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF61E05@emss02m11.us.lmco.com> Message-ID: <7465b6170904231121o17cee0acm47d847328c3d1dce@mail.gmail.com> On Thu, Apr 23, 2009 at 8:17 PM, Davidson, Josh wrote: > I'm using information provided by pygccxml to generate Construct objects > (http://construct.wikispaces.com/) that are capable of reading and > writing to data structures stored in shared memory. ?Right now, I just > manually reverse the indices any time I detect an array type before I > generate a Construct. Okey. P.S. You have interesting project. Some time ago I was playing with idea to generate serialize\unserialize\[upgrade] for C++ classes based on ASN.1, but dropped it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Thu Apr 23 20:23:48 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 23 Apr 2009 21:23:48 +0300 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <7465b6170904231121o17cee0acm47d847328c3d1dce@mail.gmail.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF61E05@emss02m11.us.lmco.com> <7465b6170904231121o17cee0acm47d847328c3d1dce@mail.gmail.com> Message-ID: <7465b6170904231123x7c7fbb73j9b95aee05786c757@mail.gmail.com> On Thu, Apr 23, 2009 at 9:21 PM, Roman Yakovenko wrote: > On Thu, Apr 23, 2009 at 8:17 PM, Davidson, Josh wrote: >> I'm using information provided by pygccxml to generate Construct objects >> (http://construct.wikispaces.com/) that are capable of reading and >> writing to data structures stored in shared memory. ?Right now, I just >> manually reverse the indices any time I detect an array type before I >> generate a Construct. > > Okey. Sorry, I forgot to add, can you open bug on SourceForge project page? Thanks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From seefeld at sympatico.ca Thu Apr 23 22:22:26 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 23 Apr 2009 16:22:26 -0400 Subject: [C++-sig] Expanding embedded code In-Reply-To: <49EFCF4A.4050104@tait.co.nz> References: <49EE57CC.9070803@tait.co.nz> <49EE755C.8080105@sympatico.ca> <49EFCF4A.4050104@tait.co.nz> Message-ID: <49F0CE02.4020604@sympatico.ca> Robin Gilks wrote: > I'm still having a problem with the python side of things - the c++ > side mostly makes sense. For example, the "class instances" section of > the page at > > http://wiki.cacr.caltech.edu/danse/index.php/Lots_more_details_on_writing_wrappers > > I can follow with no problems but I've no idea how to invoke it from > python with either the "wrap_new_Numbers" call or the subsequent > "wrap_Numbers_MemberMult" call. I just don't get what the python code > should look like to get the void pointer to the class instance at all! > Any chance of a Python 3 liner that shows how its done? > I'm not sure what you are asking. Sticking to my example code, when you run the python script, 'instance' will be available in the global namespace, so you can make calls into it from Python. If that is not what you want, can you come up with another example ? Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From robin.gilks at tait.co.nz Fri Apr 24 07:19:38 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Fri, 24 Apr 2009 17:19:38 +1200 Subject: [C++-sig] Expanding embedded code In-Reply-To: <49F0CE02.4020604@sympatico.ca> References: <49EE57CC.9070803@tait.co.nz> <49EE755C.8080105@sympatico.ca><49EFCF4A.4050104@tait.co.nz> <49F0CE02.4020604@sympatico.ca> Message-ID: <49F14BEA.6040902@tait.co.nz> Stefan Seefeld wrote: > > I'm not sure what you are asking. Sticking to my example code, when > you run the python script, 'instance' will be available in the global > namespace, so you can make calls into it from Python. If that is not > what you want, can you come up with another example ? > > Thanks, > Stefan > The problem is my lack of Python knowledge - the 35+ years assembler experience doesn't seem to count!! I've attached a minimal set of files and a make file that I hope will illustrate the problem. I'm generating the bindings using pybindgen (version 0.10.0). I hope that just typing make will show all my mistakes!! The test1.py python script has the questions - how do I get the specific instance of the class already instantiated before calling the script to be referenced rather than a new instance. I'm passing the class pointer across to the script in a PyCObject but once in the python domain I don't have a clue as to what to do with it!! Note - I'm specifically using pybindgen so I can read the generated code - Boost makes my brain hurt... Cheers -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Makefile URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test1.py Type: text/x-python Size: 565 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: testclass.C Type: text/x-csrc Size: 2037 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: testclass.H Type: text/x-chdr Size: 584 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: testclassgen.py Type: text/x-python Size: 1083 bytes Desc: not available URL: From robin.gilks at tait.co.nz Mon Apr 27 04:01:11 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Mon, 27 Apr 2009 14:01:11 +1200 Subject: [C++-sig] pybindgen add_function_as_constructor Message-ID: <49F511E7.3010203@tait.co.nz> Following on from my expanding embedded code thread, I'm making progress in that if I hack the class instantiation in the wrapper that pybindgen produces I can get it all to work. With that in mind, I'm trying to use add_function_as_constructor but it won't let me use a 'void *' or 'PyObject *' pointer as a parameter. I have to use 'uint32_t *' and then edit the code!! My generator code looks like this... testclass = mod.add_class('testclass') testclass.add_function_as_constructor('PyCObject_AsVoidPtr', None, [Parameter.new(''PyObject *', 'instance', transfer_ownership = False)]) which results in the traceback of... Traceback (most recent call last): File "testclassgen.py", line 31, in my_module_gen(sys.stdout) File "testclassgen.py", line 28, in my_module_gen mod.generate(FileCodeSink(out_file) ) File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", line 839, in generate self.do_generate(sink_manager, module_file_base_name) File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", line 721, in do_generate class_.generate(sink, self) File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", line 1481, in generate have_constructor = self._generate_constructor(code_sink) File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", line 1620, in _generate_constructor overload.generate(code_sink) File "/usr/local/lib/python2.5/site-packages/pybindgen/overloading.py", line 183, in generate (code_sink,), {}, self.all_wrappers[0]) File "/usr/local/lib/python2.5/site-packages/pybindgen/utils.py", line 124, in call_with_error_handling return callback(*args, **kwargs) File "/usr/local/lib/python2.5/site-packages/pybindgen/cppmethod.py", line 520, in generate % self._class.name) AssertionError: something went wrong with the type handlers; constructors need parameter names, yet no names were given for the class testclass constructor If I change the 'PyObject *' to a 'void *' I get...Traceback (most recent call last): File "testclassgen.py", line 31, in my_module_gen(sys.stdout) File "testclassgen.py", line 16, in my_module_gen testclass.add_function_as_constructor('PyCObject_AsVoidPtr', None, [Parameter.new('void *', 'instance', transfer_ownership = False)]) File "/usr/local/lib/python2.5/site-packages/pybindgen/typehandlers/base.py", line 1221, in new param_type_matcher.lookup(ctype) File "/usr/local/lib/python2.5/site-packages/pybindgen/typehandlers/base.py", line 1350, in lookup raise TypeLookupError(tried_names) pybindgen.typehandlers.base.TypeLookupError: ['void *'] but looking at pybindgen-0.10.0/pybindgen/typehandlers/base.py it looks like at least void * should be OK!! I either still missing something (very likely) or there is a problem here! -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From robin.gilks at tait.co.nz Mon Apr 27 06:06:11 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Mon, 27 Apr 2009 16:06:11 +1200 Subject: [C++-sig] pybindgen add_function_as_constructor In-Reply-To: <49F511E7.3010203@tait.co.nz> References: <49F511E7.3010203@tait.co.nz> Message-ID: <49F52F33.1010304@tait.co.nz> Robin Gilks wrote: > Following on from my expanding embedded code thread, I'm making > progress in that if I hack the class instantiation in the wrapper that > pybindgen produces I can get it all to work. > > With that in mind, I'm trying to use add_function_as_constructor but > it won't let me use a 'void *' or 'PyObject *' pointer as a parameter. > I have to use 'uint32_t *' and then edit the code!! > > My generator code looks like this... > > testclass = mod.add_class('testclass') > testclass.add_function_as_constructor('PyCObject_AsVoidPtr', None, > [Parameter.new(''PyObject *', 'instance', transfer_ownership = False)]) > which results in the traceback of... > Traceback (most recent call last): > File "testclassgen.py", line 31, in > my_module_gen(sys.stdout) > File "testclassgen.py", line 28, in my_module_gen > mod.generate(FileCodeSink(out_file) ) > File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", > line 839, in generate > self.do_generate(sink_manager, module_file_base_name) > File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", > line 721, in do_generate > class_.generate(sink, self) > File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", > line 1481, in generate > have_constructor = self._generate_constructor(code_sink) > File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", > line 1620, in _generate_constructor > overload.generate(code_sink) > File > "/usr/local/lib/python2.5/site-packages/pybindgen/overloading.py", > line 183, in generate > (code_sink,), {}, self.all_wrappers[0]) > File "/usr/local/lib/python2.5/site-packages/pybindgen/utils.py", > line 124, in call_with_error_handling > return callback(*args, **kwargs) > File "/usr/local/lib/python2.5/site-packages/pybindgen/cppmethod.py", > line 520, in generate > % self._class.name) > AssertionError: something went wrong with the type handlers; > constructors need parameter names, yet no names were given for the > class testclass constructor > I've found the pybindgen commit for revision 628 and that fixes the PyObject problem - got a new one now!! I can't work out the syntax to return any sort of pointer for example mod.add_method('methodA', ReturnValue.new('uint8_t *'), []) This is probably me again not understanding the Python side of things - how would I return a string otherwise? I see that some of the fixes are in the NS-3 project as pybindgen-0.10.0.630 (I assume this means up to and including commit 630) but there is no waf included in this project so I can't build it :-( Again, any help would be appreciated... Cheers -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From robin.gilks at tait.co.nz Mon Apr 27 07:15:09 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Mon, 27 Apr 2009 17:15:09 +1200 Subject: [C++-sig] pybindgen add_function_as_constructor In-Reply-To: <49F52F33.1010304@tait.co.nz> References: <49F511E7.3010203@tait.co.nz> <49F52F33.1010304@tait.co.nz> Message-ID: <49F53F5D.3020200@tait.co.nz> Robin Gilks wrote: > I've found the pybindgen commit for revision 628 and that fixes the > PyObject problem - got a new one now!! I can't work out the syntax to > return any sort of pointer for example > mod.add_method('methodA', ReturnValue.new('uint8_t *'), []) > This is probably me again not understanding the Python side of things > - how would I return a string otherwise? > > > I see that some of the fixes are in the NS-3 project as > pybindgen-0.10.0.630 (I assume this means up to and including commit > 630) but there is no waf included in this project so I can't build it :-( > Sorry about constantly replying to myself but the further I get into the pybindgen code, the more I get lost!! I've temporarily solved my 'uint8_t *' problem by using 'char *' but since I'll be using strings that may have embedded nulls I'm moving everything across to std::string types so that problem goes away:-) Where I've got to now is I can't find how to declare a docstring for a function or method. Any clues? Cheers -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From gjcarneiro at gmail.com Mon Apr 27 12:21:19 2009 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Mon, 27 Apr 2009 11:21:19 +0100 Subject: [C++-sig] pybindgen add_function_as_constructor In-Reply-To: <49F53F5D.3020200@tait.co.nz> References: <49F511E7.3010203@tait.co.nz> <49F52F33.1010304@tait.co.nz> <49F53F5D.3020200@tait.co.nz> Message-ID: 2009/4/27 Robin Gilks > Robin Gilks wrote: > >> I've found the pybindgen commit for revision 628 and that fixes the >> PyObject problem - got a new one now!! I can't work out the syntax to return >> any sort of pointer for example >> mod.add_method('methodA', ReturnValue.new('uint8_t *'), []) >> This is probably me again not understanding the Python side of things - >> how would I return a string otherwise? >> >> >> I see that some of the fixes are in the NS-3 project as >> pybindgen-0.10.0.630 (I assume this means up to and including commit 630) >> but there is no waf included in this project so I can't build it :-( >> >> > Sorry about constantly replying to myself but the further I get into the > pybindgen code, the more I get lost!! I've temporarily solved my 'uint8_t *' > problem by using 'char *' but since I'll be using strings that may have > embedded nulls I'm moving everything across to std::string types so that > problem goes away:-) Sounds good. Sorry I wasn't online to help with the other questions. I assume those problems are solved, if not please ask again the questions. > Where I've got to now is I can't find how to declare a docstring for a > function or method. Doesn't this work? module.add_function(..., docstring="this is a docstring") OK, looking at the code I found two bugs in pybindgen wrt docstrings: 1. there is a bug with handling docstrings with overloaded functions; they will only work if the function is not overloaded with another function with the same name; 2. I forgot to add a docstring parameter to method objects. But it's a simple workaround, just: method = MyClass.add_method(...) method.docstring = "this is a docstring" Again, only works if the method is not overloaded. Regards, -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin.gilks at tait.co.nz Mon Apr 27 23:43:19 2009 From: robin.gilks at tait.co.nz (Robin Gilks) Date: Tue, 28 Apr 2009 09:43:19 +1200 Subject: [C++-sig] pybindgen add_function_as_constructor In-Reply-To: References: <49F511E7.3010203@tait.co.nz> <49F52F33.1010304@tait.co.nz><49F53F5D.3020200@tait.co.nz> Message-ID: <49F626F7.6090701@tait.co.nz> Gustavo Carneiro wrote: > > Sounds good. > > Sorry I wasn't online to help with the other questions. I assume > those problems are solved, if not please ask again the questions. > > > Where I've got to now is I can't find how to declare a docstring > for a function or method. > > > Doesn't this work? > > module.add_function(..., docstring="this is a docstring") > > OK, looking at the code I found two bugs in pybindgen wrt docstrings: > > 1. there is a bug with handling docstrings with overloaded > functions; they will only work if the function is not overloaded with > another function with the same name; > > 2. I forgot to add a docstring parameter to method objects. But > it's a simple workaround, just: > > method = MyClass.add_method(...) > method.docstring = "this is a docstring" > > Again, only works if the method is not overloaded. > Thanks Gustavo That gave me all the clues I needed. I've only just started using Python so my patch (below) is very much derived from the 'suck it and see' philosophy. It seems to work for me however!! diff -PurN pybindgen/cppmethod.py ../../pybindgen-0.10.0/pybindgen/cppmethod.py --- pybindgen/cppmethod.py 2008-11-08 07:55:41.000000000 +1300 +++ ../../pybindgen-0.10.0/pybindgen/cppmethod.py 2009-04-27 23:05:27.000000000 +1200 @@ -19,7 +19,7 @@ Class that generates a wrapper to a C++ class method """ - def __init__(self, method_name, return_value, parameters, is_static=False, + def __init__(self, method_name, return_value, parameters, is_static=False, docstring=None, template_parameters=(), is_virtual=False, is_const=False, unblock_threads=None, is_pure_virtual=False, custom_template_method_name=None, visibility='public', @@ -95,7 +95,7 @@ #self.static_decl = True self._class = None self._helper_class = None - self.docstring = None + self.docstring = docstring self.wrapper_base_name = None self.wrapper_actual_name = None self.return_value = None Cheers -- Robin ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. ======================================================================= From gjcarneiro at gmail.com Tue Apr 28 12:23:43 2009 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 28 Apr 2009 11:23:43 +0100 Subject: [C++-sig] pybindgen add_function_as_constructor In-Reply-To: <49F626F7.6090701@tait.co.nz> References: <49F511E7.3010203@tait.co.nz> <49F52F33.1010304@tait.co.nz> <49F53F5D.3020200@tait.co.nz> <49F626F7.6090701@tait.co.nz> Message-ID: 2009/4/27 Robin Gilks > Gustavo Carneiro wrote: > >> >> Sounds good. >> >> Sorry I wasn't online to help with the other questions. I assume those >> problems are solved, if not please ask again the questions. >> >> >> Where I've got to now is I can't find how to declare a docstring >> for a function or method. >> >> >> Doesn't this work? >> >> module.add_function(..., docstring="this is a docstring") >> >> OK, looking at the code I found two bugs in pybindgen wrt docstrings: >> >> 1. there is a bug with handling docstrings with overloaded functions; >> they will only work if the function is not overloaded with another function >> with the same name; >> >> 2. I forgot to add a docstring parameter to method objects. But it's >> a simple workaround, just: >> >> method = MyClass.add_method(...) >> method.docstring = "this is a docstring" >> >> Again, only works if the method is not overloaded. >> >> > > Thanks Gustavo > > That gave me all the clues I needed. I've only just started using Python so > my patch (below) is very much derived from the 'suck it and see' philosophy. > It seems to work for me however!! > > diff -PurN pybindgen/cppmethod.py > ../../pybindgen-0.10.0/pybindgen/cppmethod.py > --- pybindgen/cppmethod.py 2008-11-08 07:55:41.000000000 +1300 > +++ ../../pybindgen-0.10.0/pybindgen/cppmethod.py 2009-04-27 > 23:05:27.000000000 +1200 > @@ -19,7 +19,7 @@ > Class that generates a wrapper to a C++ class method > """ > > - def __init__(self, method_name, return_value, parameters, > is_static=False, > + def __init__(self, method_name, return_value, parameters, > is_static=False, docstring=None, > template_parameters=(), is_virtual=False, is_const=False, > unblock_threads=None, is_pure_virtual=False, > custom_template_method_name=None, visibility='public', > @@ -95,7 +95,7 @@ > #self.static_decl = True > self._class = None > self._helper_class = None > - self.docstring = None > + self.docstring = docstring > self.wrapper_base_name = None > self.wrapper_actual_name = None > self.return_value = None > > > Thanks, applied. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruce.sherwood at gmail.com Tue Apr 28 19:52:54 2009 From: bruce.sherwood at gmail.com (Bruce Sherwood) Date: Tue, 28 Apr 2009 13:52:54 -0400 Subject: [C++-sig] numpy.int32 -> double? Message-ID: I'm not sure this is the right forum for my question; it's quite possible that this is a numpy question. VPython (vpython.org) is the name of Python plus the 3D Visual module, which is mostly written in C++ and connected to Python using the Boost libraries. Visual imports numpy. When I build Visual for Python 2.6 and numpy 1.3.0, I get a failure on something that works on Python 2.5 with numpy 1.2.1. There is a vector(double,double,double) class in Visual which now fails if handed numpy.int32 arguments (works fine with numpy.float64 arguments). I was using Boost 1.35 with Python 2.5 and am using Boost 1.38 with Python 2.6. Any ideas or suggestions? Thanks. Bruce Sherwood -------------- next part -------------- An HTML attachment was scrubbed... URL: