From tj_summers at naughtydog.com Wed Feb 1 00:10:37 2006
From: tj_summers at naughtydog.com (TJ Summers)
Date: Tue, 31 Jan 2006 15:10:37 -0800
Subject: [C++-sig] Opportunities at Naughty Dog...
Message-ID: <005901c626bb$8d1f0cc0$6401a8c0@DAMLT1>
Hello Hamilton-
My name is T.J. Summers and I am the recruiter at Naughty Dog in Santa
Monica, CA. Naughty Dog is owned by Sony Computer Entertainment of America
and is developer of the Jak and Daxter franchise.
The reason for my email is that I want to ask if you might be interested in
hearing about job opportunities at Naughty Dog. We are actively hiring
talented programmer/engineers as we are currently ramping up on our new
Playstation 3 game and engine development teams. I have listed the top
priority positions at Naughty Dog.
* Senior Tools Programmer for GAME team and ENGINE team
* Senior Renderer Programmer for GAME team
* Senior Game Programmers (either Senior Renderer Programmers,
Assembler Programmers, or Generalists for ENGINE development)
* Gameplay Programmers
* Senior Audio Programmer
Please let me know when we can schedule a time to discuss.
Regards,
T.J. Summers
Naughty Dog
1601 Cloverfield Blvd.
Suite 6000 North
Santa Monica, CA 90404
www.naughtydog.com
Phone: 310-633-9275
mailto:tj_summers at naughtydog.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From ndbecker2 at gmail.com Wed Feb 1 04:07:25 2006
From: ndbecker2 at gmail.com (Neal Becker)
Date: Tue, 31 Jan 2006 22:07:25 -0500
Subject: [C++-sig] variable # args?
Message-ID:
How do I create a function in c++ that appears to python as a function
taking a variable #args?
What I'm doing now is like:
F (object& o) {
int size = extract (o.attr ("__len__")());
for (int i = 0; i < size; ++i) {
const out_t& v = extract (o[i]);
...
This works for passing a single object that is a sequence, e.g., tuple:
F ((a,b,c))
But what I really want is
F (a,b,c)
From roman.yakovenko at gmail.com Wed Feb 1 06:09:09 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Wed, 1 Feb 2006 07:09:09 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601252149i3c597589t15d686f027567ab8@mail.gmail.com>
<7465b6170601290507m3c2cc0edied458d60932dfa04@mail.gmail.com>
<7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com>
<7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
Message-ID: <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
On 1/31/06, Matthias Baas wrote:
> >> Anyway, I'll continue my test and move on to the more complex classes
> >> that needed some manual intervention using Pyste....
>
> The next class I've added to the module has two methods that require a
> call policy. The methods just return a reference to its instance, so I
> want to specify the 'return_self' policy. How do I do that? (I've had a
> short glimpse at those examples you mentioned two mails ago, but didn't
> really spot a place where a policy was assigned)
You have 2 choices:
1. To create "callable" object that for a given declaration will
return call policies.
For example py_easybmp uses this technique.
See: http://tinyurl.com/crjzf
In this case you also need to switch from module_creator.create
function to using
class module_creator.creator_t. EasyBMP example will help you.
2. After you created extension module tree you can find relevant code creator
and then set call policies.
The relevant code for find functionality you can find in
pygccxml/declarations/algorithm.py
and pyplusplus/code_creators/algorithm.py
2.1 You also can iterate on all code creators:
creators = code_creators.make_flatten( extmodule )
fmfunctions = filter( lambda creator: isinstance( creator,
code_creators.function_t )
, creators )
for creator in fmfunctions:
if not creator.call_policies:
print 'missing call policies: ',
declarations.full_name( creator.declaration )
print ' function will not be exported'
creator.parent.remove_creator( creator )
As for me the first way is better then other. It does not degrade performance.
Also 2.1 it useful to remove function with missing call policies, and
thus to see result
much faster.
Small hint: If the SDK you are wrapping has code convention, than you
can reuse it.
For example if all classes has method "clone" that returns raw pointer
to new object,
then you can set call policies base on function name only.
An other small hint: pygccxml has type_traits. The idea is similar as
in boost.type_traits.
You can analyze the return type of function, and only then to decide
what call policies you
will set.
> Then there's another class that has a private destructor. This class
> only has static methods and is not meant to be instantiated. So for the
> wrappers I'd like to add the 'noncopyable' and 'no_init' specifiers.
> Does pyplusplus allow that?
pyplusplus does not allows this right now. The main reason for this is:
pyplusplus checks whether class has private constructor (fixed yesterday)
or does not have accessible copy constructor and generates right code.
I forgot about public destructor. I will fix it. If you still need to
control those properties
just say it.
> Now I also noticed another thing that'll get more serious the more
> classes I wrap. Whenever I create the source code for the bindings
> (using the multiple_files feature) *all* files are recreated, even when
> the actual contents is the same than before. When I then compile the
> module (using distutils) *every* file is recompiled which will take
> quite some time once I've wrapped the entire SDK (which has about 300
> classes). Is there a way to tell pyplusplus to only generate a source
> file when the contents will be different from a previous run?
I will fix this.
> - Matthias -
>
I will post to the list when fixes are ready.
Thanks
Roman Yakovenko
From roman.yakovenko at gmail.com Wed Feb 1 09:14:46 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Wed, 1 Feb 2006 10:14:46 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601252149i3c597589t15d686f027567ab8@mail.gmail.com>
<7465b6170601290507m3c2cc0edied458d60932dfa04@mail.gmail.com>
<7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com>
<7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
Message-ID: <7465b6170602010014m546da17y7e5bd7653b7dd288@mail.gmail.com>
On 2/1/06, Roman Yakovenko wrote:
> > Then there's another class that has a private destructor. This class
> > only has static methods and is not meant to be instantiated. So for the
> > wrappers I'd like to add the 'noncopyable' and 'no_init' specifiers.
> > Does pyplusplus allow that?
>
> pyplusplus does not allows this right now. The main reason for this is:
> pyplusplus checks whether class has private constructor (fixed yesterday)
> or does not have accessible copy constructor and generates right code.
>
> I forgot about public destructor. I will fix it. If you still need to
> control those properties
> just say it.
Fixed.
> > Now I also noticed another thing that'll get more serious the more
> > classes I wrap. Whenever I create the source code for the bindings
> > (using the multiple_files feature) *all* files are recreated, even when
> > the actual contents is the same than before. When I then compile the
> > module (using distutils) *every* file is recompiled which will take
> > quite some time once I've wrapped the entire SDK (which has about 300
> > classes). Is there a way to tell pyplusplus to only generate a source
> > file when the contents will be different from a previous run?
>
> I will fix this.
Fixed. This bug was so silly, I don't know what I thought that moment.
Thanks for reporting those bugs. You need to take CVS version.
Roman Yakovenko.
From baas at ira.uka.de Wed Feb 1 18:24:05 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Wed, 01 Feb 2006 18:24:05 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170601252149i3c597589t15d686f027567ab8@mail.gmail.com> <7465b6170601290507m3c2cc0edied458d60932dfa04@mail.gmail.com> <7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com> <7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
[setting call policies]
> You have 2 choices:
> [...]
As you recommended the first option I took the code from EasyBMP and
modified it accordingly, so this is working now.
> Small hint: If the SDK you are wrapping has code convention, than you
> can reuse it.
> [...]
In the above case, this was not the case, but I'll keep it in mind.
>> Then there's another class that has a private destructor. This class
>> only has static methods and is not meant to be instantiated. So for the
>> wrappers I'd like to add the 'noncopyable' and 'no_init' specifiers.
>> Does pyplusplus allow that?
>
> pyplusplus does not allows this right now. The main reason for this is:
> pyplusplus checks whether class has private constructor (fixed yesterday)
> or does not have accessible copy constructor and generates right code.
>
> I forgot about public destructor. I will fix it. If you still need to
> control those properties just say it.
Thanks for fixing that. With the latest cvs, the noncopyable and no_init
specifiers are added, but on Linux (using gcc) it still doesn't compile
because of the *_wrapper class which is derived from the original class.
I still get an error message that the destructor is private. I suppose
in this case, such a *_wrapper class wouldn't be required anyway and the
original class could be wrapped directly. Can I somehow suppress the
creation of such wrapper classes?
By the way, on Windows (using VC7.1) the code compiles without
problems....?!
>> Now I also noticed another thing that'll get more serious the more
>> classes I wrap. Whenever I create the source code for the bindings
>> (using the multiple_files feature) *all* files are recreated, even when
>> the actual contents is the same than before. When I then compile the
>> module (using distutils) *every* file is recompiled which will take
>> quite some time once I've wrapped the entire SDK (which has about 300
>> classes). Is there a way to tell pyplusplus to only generate a source
>> file when the contents will be different from a previous run?
>
> I will fix this.
Basically, it works, but there is still a problem. Whenever I add a new
class there's a new header file that gets included into *all* files
automatically which wouldn't be necessary. So the files still change and
get recompiled. I don't know how pyplusplus determines the files that
it'll include in the output but I hope that there's a way to include
only those header files that are really required.
(Just out of curiosity, how do you determine whether a file has to be
written or not, do you really compare the contents of the existing file
with the data you're about to write?)
By the way, after the cvs update I got a new warning from gcc. The
compiler complains that the last line in the generated source files
doesn't have a newline.
Then there's a new thing that came up. Pyplusplus also adds protected
methods to the generated wrappers which breaks compilation for me. How
can I disable that feature?
I thought I could just filter them out, but then I noticed something
else that I don't understand. I already have my user defined filter
function that filters out everything but my desired classes. The
function basically looks like this:
def filter(decl):
return decl.name in [......]
But now that I come to think about it, I don't understand why this works
at all. I noticed that the filter function is also applied to class
methods in which case the function returns False. But why are the
methods then exposed? (I thought this would be a way to filter out the
protected methods, but obviously this is not how it's supposed to work...)
- Matthias -
From vladimir at inktomi.com Wed Feb 1 05:37:38 2006
From: vladimir at inktomi.com (Vladimir Ofitserov)
Date: Tue, 31 Jan 2006 20:37:38 -0800
Subject: [C++-sig] How to create instance using existing C++ object
Message-ID:
Let say I have a C++ function that gets instance of noncopyable object
(CDoc for example) and I want to implement this function in python
module, wrapping CDoc class using Boost.Python:
void MyFunction( CDoc *pDoc ) {
// want a wrapper that is just a pointer/reference/shared_ptr
class_ cdoc( "CDoc", noinit );
cdoc.def(...);
cdoc.def(...);
// now how do I create instance of "cdoc" around pDoc
// using cdoc::operator()?
object odoc = cdoc( *pDoc );
// calling python module with new object instance
call_method( pymodule, "myfunction", odoc );
}
The main problem is that I could not find any documentation on how to
create python wrapper around existing object. Only thing I've seen is
Python Wiki FAQ article that has correct problem statement but
*incorrect* answer:
http://wiki.python.org/moin/boost.python/FAQ
-------------------------------------------
Is it is possible to convert pointers to existing classes to
PyObjects* and then be able to pass an existing instance of an
object directly to and from python?
It is.
Example: In C++ I create a CWheel and I set its member m_diameter to
1233. In python I have a function that receives a CWheel and displays
the diameter (Let's suppose that Python knows the CWheel from Boost.Python):
def printCWheelDiam(awheel):
print awheel.m_diameter
The safest thing to do is to create the CWheel by invoking its class
wrapper:
// Declare the CWheel extension class
object wheel_class =
class_("CWheel")
.def_readonly("m_diameter", &CWheel::m_diameter)
.def("some_member_function", &CWheel::some_member_function)
...
;
object wheel_obj = wheel_class(); // construct one
Now you can pass wheel_obj back to python, and all reference counts are
nicely managed. You don't need to "map" anything between C++ and Python;
the library takes care of that for you.
If you really want to pass pointers around, it's certainly possible to
tell the library to build a Python object around the pointer, but then
you need to make sure the lifetime of the C++ object being referenced by
the pointer extends past the lifetime of all Python references to the
object or your program will crash.
--------------------------------------------------------------------------------------
This answer above is no way match to the question because there is *new*
object created (wheel_obj) using default constructor and it no way an
*existing* object as was asked in the question. The last paragraph says
exactly what I want but it only mentions that "it's certainly possible
to tell the library to build a Python object around pointer" but I must
be really stupid because I just can figure out how :-)
Thanks for help,
-vladimir
From dave at boost-consulting.com Wed Feb 1 22:40:50 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 01 Feb 2006 16:40:50 -0500
Subject: [C++-sig] How to create instance using existing C++ object
References:
Message-ID:
Vladimir Ofitserov writes:
> Let say I have a C++ function that gets instance of noncopyable object
> (CDoc for example) and I want to implement this function in python
> module, wrapping CDoc class using Boost.Python:
>
> void MyFunction( CDoc *pDoc ) {
>
> // want a wrapper that is just a pointer/reference/shared_ptr
> class_ cdoc( "CDoc", noinit );
^
!! What is that supposed to be?
The library definitely does not expect a
reference type here!
> cdoc.def(...);
> cdoc.def(...);
>
> // now how do I create instance of "cdoc" around pDoc
> // using cdoc::operator()?
> object odoc = cdoc( *pDoc );
>
> // calling python module with new object instance
> call_method( pymodule, "myfunction", odoc );
> }
You've left out a *lot* of information! E.g., what is
cdoc::operator()? But anyway...
> The main problem is that I could not find any documentation on how to
> create python wrapper around existing object. Only thing I've seen is
> Python Wiki FAQ article that has correct problem statement but
> *incorrect* answer:
>
> http://wiki.python.org/moin/boost.python/FAQ
You might try this:
namespace python = boost::python;
python::object identity(python::object o) { return o; }
python::object py_id(identity);
python::object py_cdoc_instance
= py_id(boost::ref(some_cpp_cdoc_instance));
// Warning: if some_cpp_cdoc_instance is destroyed before
// py_cdoc_instance, crashses may ensue!
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From dave at boost-consulting.com Wed Feb 1 22:44:25 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 01 Feb 2006 16:44:25 -0500
Subject: [C++-sig] variable # args?
References:
Message-ID:
Neal Becker writes:
> How do I create a function in c++ that appears to python as a function
> taking a variable #args?
>
> What I'm doing now is like:
>
> F (object& o) {
> int size = extract (o.attr ("__len__")());
>
> for (int i = 0; i < size; ++i) {
> const out_t& v = extract (o[i]);
> ...
>
> This works for passing a single object that is a sequence, e.g., tuple:
>
> F ((a,b,c))
>
> But what I really want is
>
> F (a,b,c)
Sounds like you're looking for:
http://www.boost.org/libs/python/doc/v2/raw_function.html
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From ndbecker2 at gmail.com Thu Feb 2 00:34:57 2006
From: ndbecker2 at gmail.com (Neal Becker)
Date: Wed, 01 Feb 2006 18:34:57 -0500
Subject: [C++-sig] variable # args?
References:
Message-ID:
David Abrahams wrote:
> Neal Becker writes:
>
>> How do I create a function in c++ that appears to python as a function
>> taking a variable #args?
>>
>> What I'm doing now is like:
>>
>> F (object& o) {
>> int size = extract (o.attr ("__len__")());
>>
>> for (int i = 0; i < size; ++i) {
>> const out_t& v = extract (o[i]);
>> ...
>>
>> This works for passing a single object that is a sequence, e.g., tuple:
>>
>> F ((a,b,c))
>>
>> But what I really want is
>>
>> F (a,b,c)
>
> Sounds like you're looking for:
>
> http://www.boost.org/libs/python/doc/v2/raw_function.html
>
Excellent.
Now, can this be used with make_constructor? e.g.:
.def("__init__", make_constructor(raw_function (F)))
Doesn't seem to work:
/usr/include/nb/boost/python/make_constructor.hpp:230:
error: no matching function for call to 'get_signature(boost::python::api::object&)'
From roman.yakovenko at gmail.com Thu Feb 2 06:59:11 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 2 Feb 2006 07:59:11 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601290507m3c2cc0edied458d60932dfa04@mail.gmail.com>
<7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com>
<7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
Message-ID: <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
On 2/1/06, Matthias Baas wrote:
> Thanks for fixing that. With the latest cvs, the noncopyable and no_init
> specifiers are added, but on Linux (using gcc) it still doesn't compile
> because of the *_wrapper class which is derived from the original class.
> I still get an error message that the destructor is private. I suppose
> in this case, such a *_wrapper class wouldn't be required anyway and the
> original class could be wrapped directly. Can I somehow suppress the
> creation of such wrapper classes?
> By the way, on Windows (using VC7.1) the code compiles without
> problems....?!
I did not test my changes with GCC. I will test them. As a temporal solution
you can remove the wrapper code creator. Try to use finalize method on
class code creator.
> >> Now I also noticed another thing that'll get more serious the more
> >> classes I wrap. Whenever I create the source code for the bindings
> >> (using the multiple_files feature) *all* files are recreated, even when
> >> the actual contents is the same than before. When I then compile the
> >> module (using distutils) *every* file is recompiled which will take
> >> quite some time once I've wrapped the entire SDK (which has about 300
> >> classes). Is there a way to tell pyplusplus to only generate a source
> >> file when the contents will be different from a previous run?
> >
> > I will fix this.
>
> Basically, it works, but there is still a problem. Whenever I add a new
> class there's a new header file that gets included into *all* files
> automatically which wouldn't be necessary. So the files still change and
> get recompiled. I don't know how pyplusplus determines the files that
> it'll include in the output but I hope that there's a way to include
> only those header files that are really required.
The problem is that I ( pyplusplus ) can not build set of required files.
Consider next case:
file a.h
class A{};
file b.h
#include "a.h"
class B{};
You want to export A and B. pyplusplus will generate include to a.h
and b.h. While
writing those lines I think that I found solution, but requires
modification of pygccxml.
I am not going to implement this for next release, but still
pyplusplus provide nice way to solve this situation.
TnFOX has one header that include all other header files. Before
generating code,
we modify extension module. We remove all includes for TnFOX and replace them
with include to main header.
Here is relevant code:
#extmodule defined somewhere
includes = filter( lambda creator: isinstance( creator,
code_creators.include_t )
, extmodule.creators )
includes = includes[2:] #all includes except boost\python.hpp and
__array_1.pypp.hpp
map( lambda creator: extmodule.remove_creator( creator ), includes )
extmodule.adopt_include( code_creators.include_t( header="fx.h" ) )
> (Just out of curiosity, how do you determine whether a file has to be
> written or not, do you really compare the contents of the existing file
> with the data you're about to write?)
Yes, this is the only way, that I know, that does it reliably.
Don't warry about performance. It takes only 90 - 100 second to create\generate
Boost.Python bindings for TnFOX, 625 files.
> By the way, after the cvs update I got a new warning from gcc. The
> compiler complains that the last line in the generated source files
> doesn't have a newline.
Next time before I do check in I will check it first on Linux. Sorry
for inconvinince. :-(
> Then there's a new thing that came up. Pyplusplus also adds protected
> methods to the generated wrappers which breaks compilation for me. How
> can I disable that feature?
Right now there is no way to disable it. Could you send me simple test
case that breaks
your compilation. I tested this behaviour and it works fine. Also if I
fix this bug, do you
still need to be able to disable this feature?
> I thought I could just filter them out, but then I noticed something
> else that I don't understand. I already have my user defined filter
> function that filters out everything but my desired classes. The
> function basically looks like this:
>
> def filter(decl):
> return decl.name in [......]
>
> But now that I come to think about it, I don't understand why this works
> at all. I noticed that the filter function is also applied to class
> methods in which case the function returns False. But why are the
> methods then exposed? (I thought this would be a way to filter out the
> protected methods, but obviously this is not how it's supposed to work...)
You found a bug. Thanks. I will fix it.
> - Matthias -
Thanks for bug reporting
Roman Yakovenko
From meine at kogs1.informatik.uni-hamburg.de Thu Feb 2 12:57:38 2006
From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine)
Date: Thu, 2 Feb 2006 12:57:38 +0100
Subject: [C++-sig] variable # args?
In-Reply-To:
References:
Message-ID: <200602021257.38706.meine@kogs.informatik.uni-hamburg.de>
On Thursday 02 February 2006 00:34, Neal Becker wrote:
> David Abrahams wrote:
> > Sounds like you're looking for:
> >
> > http://www.boost.org/libs/python/doc/v2/raw_function.html
>
> Excellent.
>
> Now, can this be used with make_constructor? e.g.:
> .def("__init__", make_constructor(raw_function (F)))
>
> Doesn't seem to work:
> /usr/include/nb/boost/python/make_constructor.hpp:230:
> error: no matching function for call to
> 'get_signature(boost::python::api::object&)'
No, that does not work. (Both functions wrap a C++ function into a callable
object, so they can't work together.)
Have a look at my "Raw constructor (i.e. combination of make_constructor and
raw_function)" thread (I say "my .. thread" because it was mostly me
discussing with myself ;-p) in the archives, where I finally posted a
solution.
--
Ciao, / /
/--/
/ / ANS
From ndbecker2 at gmail.com Thu Feb 2 13:25:15 2006
From: ndbecker2 at gmail.com (Neal Becker)
Date: Thu, 02 Feb 2006 07:25:15 -0500
Subject: [C++-sig] variable # args?
References:
<200602021257.38706.meine@kogs.informatik.uni-hamburg.de>
Message-ID:
Hans Meine wrote:
> On Thursday 02 February 2006 00:34, Neal Becker wrote:
>> David Abrahams wrote:
>> > Sounds like you're looking for:
>> >
>> > http://www.boost.org/libs/python/doc/v2/raw_function.html
>>
>> Excellent.
>>
>> Now, can this be used with make_constructor? e.g.:
>> .def("__init__", make_constructor(raw_function (F)))
>>
>> Doesn't seem to work:
>> /usr/include/nb/boost/python/make_constructor.hpp:230:
>> error: no matching function for call to
>> 'get_signature(boost::python::api::object&)'
>
> No, that does not work. (Both functions wrap a C++ function into a
> callable object, so they can't work together.)
>
> Have a look at my "Raw constructor (i.e. combination of make_constructor
> and raw_function)" thread (I say "my .. thread" because it was mostly me
> discussing with myself ;-p) in the archives, where I finally posted a
> solution.
>
Hey thanks! Just what I needed. Can we please add this to boost::python?
From dave at boost-consulting.com Thu Feb 2 15:59:52 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Thu, 02 Feb 2006 09:59:52 -0500
Subject: [C++-sig] variable # args?
References:
<200602021257.38706.meine@kogs.informatik.uni-hamburg.de>
Message-ID:
Neal Becker writes:
> Hans Meine wrote:
>
>> On Thursday 02 February 2006 00:34, Neal Becker wrote:
>>> David Abrahams wrote:
>>> > Sounds like you're looking for:
>>> >
>>> > http://www.boost.org/libs/python/doc/v2/raw_function.html
>>>
>>> Excellent.
>>>
>>> Now, can this be used with make_constructor? e.g.:
>>> .def("__init__", make_constructor(raw_function (F)))
>>>
>>> Doesn't seem to work:
>>> /usr/include/nb/boost/python/make_constructor.hpp:230:
>>> error: no matching function for call to
>>> 'get_signature(boost::python::api::object&)'
>>
>> No, that does not work. (Both functions wrap a C++ function into a
>> callable object, so they can't work together.)
>>
>> Have a look at my "Raw constructor (i.e. combination of make_constructor
>> and raw_function)" thread (I say "my .. thread" because it was mostly me
>> discussing with myself ;-p) in the archives, where I finally posted a
>> solution.
>>
>
> Hey thanks! Just what I needed. Can we please add this to boost::python?
Patches are welcome.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From baas at ira.uka.de Thu Feb 2 18:19:18 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Thu, 02 Feb 2006 18:19:18 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170601290507m3c2cc0edied458d60932dfa04@mail.gmail.com> <7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com> <7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com> <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
<7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
> On 2/1/06, Matthias Baas wrote:
>> Thanks for fixing that. With the latest cvs, the noncopyable and no_init
>> specifiers are added, but on Linux (using gcc) it still doesn't compile
>> because of the *_wrapper class which is derived from the original class.
>> [...]
>
> I did not test my changes with GCC. I will test them. As a temporal solution
> you can remove the wrapper code creator. Try to use finalize method on
> class code creator.
Uhm, I didn't see any finalize() method anywhere...?
By "class code creator" you probably don't mean the object I create with
module_creator.creator_t(), right? Then how do I obtain the class code
creator that corresponds to my particular class?
>> Basically, it works, but there is still a problem. Whenever I add a new
>> class there's a new header file that gets included into *all* files
>> automatically which wouldn't be necessary. So the files still change and
>> get recompiled. [...]
>
> The problem is that I ( pyplusplus ) can not build set of required files.
> Consider next case:
> file a.h
> class A{};
>
> file b.h
> #include "a.h"
>
> class B{};
>
> You want to export A and B. pyplusplus will generate include to a.h
> and b.h.
Why don't you just include the header that actually defines the
corresponding class (i.e. "a.h" when wrapping A and "b.h" when wrapping
B)? If a header depends on other stuff the appropriate #include
statement has to be in that header anyway (in the above example, b.h
does already include a.h).
In my case, I have to add some headers manually because Boost.Python
requires the full definition of a class whereas the original headers
only contain forward declarations. But that's ok with me.
>> (Just out of curiosity, how do you determine whether a file has to be
>> written or not, do you really compare the contents of the existing file
>> with the data you're about to write?)
>
> Yes, this is the only way, that I know, that does it reliably.
> Don't warry about performance. It takes only 90 - 100 second to create\generate
> Boost.Python bindings for TnFOX, 625 files.
Do you generate the bindings on a local drive or on a network drive?
Maybe performance could become an issue once the data has to be
transferred over a network...?
By the way, an alternative to comparing the entire file could be storing
a checksum (such as CRC32, see zlib.crc32()) somewhere at the top of the
file and comparing only that value.
But so far, this is really a minor issue. If I get the above header
thing sorted out, the current performance is good enough for me (and I
am already on a network drive).
>> By the way, after the cvs update I got a new warning from gcc. The
>> compiler complains that the last line in the generated source files
>> doesn't have a newline.
>
> Next time before I do check in I will check it first on Linux. Sorry
> for inconvinince. :-(
No problem, it's only a warning anyway (and actually, I don't understand
why gcc insists on that newline...).
>> Then there's a new thing that came up. Pyplusplus also adds protected
>> methods to the generated wrappers which breaks compilation for me. How
>> can I disable that feature?
>
> Right now there is no way to disable it. Could you send me simple test
> case that breaks
> your compilation. I tested this behaviour and it works fine. Also if I
> fix this bug, do you
> still need to be able to disable this feature?
I don't think it's a bug in pyplusplus, it's just that those protected
methods use a class whose full definition is not available. For example,
there's a protected method 'void setPtr(MPtrBase*);' and a full
definition of MPtrBase is not available, the header only contains a
forward declaration. When compiling the bindings I then get the error:
.../type_id.hpp:71: error: invalid use of undefined type `struct MPtrBase'
../MObject.h:94: error: forward declaration of `struct MPtrBase'
>> def filter(decl):
>> return decl.name in [......]
>>
>> But now that I come to think about it, I don't understand why this works
>> at all. I noticed that the filter function is also applied to class
>> methods in which case the function returns False. But why are the
>> methods then exposed? (I thought this would be a way to filter out the
>> protected methods, but obviously this is not how it's supposed to work...)
>
> You found a bug. Thanks. I will fix it.
Does that mean my above filter won't work anymore (as it would produce
'empty' classes) and I will have to return True when called on the
actual class methods? (and if so, how would the updated filter look like?)
- Matthias -
From roman.yakovenko at gmail.com Sun Feb 5 08:37:22 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Sun, 5 Feb 2006 09:37:22 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com>
<7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
<7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
Message-ID: <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
On 2/2/06, Matthias Baas wrote:
> > I did not test my changes with GCC. I will test them. As a temporal solution
> > you can remove the wrapper code creator. Try to use finalize method on
> > class code creator.
>
> Uhm, I didn't see any finalize() method anywhere...?
> By "class code creator" you probably don't mean the object I create with
> module_creator.creator_t(), right? Then how do I obtain the class code
> creator that corresponds to my particular class?
Take a look on this UML diagram. It is incomplete but will give you some
understanding of existent code creators:
http://www.language-binding.net/pyplusplus/code_creators.png
module_creator.creator_t() function returns instance of class module_t.
This class contains module_body_t code creator( accessible via body property ).
As you can see from the UML diagram they both derive from compound_t code
creator. This means that they contain other code creators. You can get access
to them via "creators" property. There are few functions that will
help you to find
particular code creator. You can find them in code_creators\algorithm.py module.
Take a look on py_easybmp example. You can also take a look on unit test:
http://tinyurl.com/ckux9
( see creator_finder_tester_t tester )
> >> Basically, it works, but there is still a problem. Whenever I add a new
> >> class there's a new header file that gets included into *all* files
> >> automatically which wouldn't be necessary. So the files still change and
> >> get recompiled. [...]
> >
> > The problem is that I ( pyplusplus ) can not build set of required files.
> > Consider next case:
> > file a.h
> > class A{};
> >
> > file b.h
> > #include "a.h"
> >
> > class B{};
> >
> > You want to export A and B. pyplusplus will generate include to a.h
> > and b.h.
>
> Why don't you just include the header that actually defines the
> corresponding class (i.e. "a.h" when wrapping A and "b.h" when wrapping
> B)?
This is exactly what I do. May be I did not explain my self well.
> >> (Just out of curiosity, how do you determine whether a file has to be
> >> written or not, do you really compare the contents of the existing file
> >> with the data you're about to write?)
> >
> > Yes, this is the only way, that I know, that does it reliably.
> > Don't warry about performance. It takes only 90 - 100 second to create\generate
> > Boost.Python bindings for TnFOX, 625 files.
>
> Do you generate the bindings on a local drive or on a network drive?
> Maybe performance could become an issue once the data has to be
> transferred over a network...?
> By the way, an alternative to comparing the entire file could be storing
> a checksum (such as CRC32, see zlib.crc32()) somewhere at the top of the
> file and comparing only that value.
> But so far, this is really a minor issue. If I get the above header
> thing sorted out, the current performance is good enough for me (and I
> am already on a network drive).
I test it on local drive only. Also on my laptop the drive speed is
5400. So the
performance are really important. Right now I am quite satisfied with
performance.
I see from your posting that you too. If it will become an issue, I am
sure we can find some way to solve it.
> >> def filter(decl):
> >> return decl.name in [......]
> >>
> >> But now that I come to think about it, I don't understand why this works
> >> at all. I noticed that the filter function is also applied to class
> >> methods in which case the function returns False. But why are the
> >> methods then exposed? (I thought this would be a way to filter out the
> >> protected methods, but obviously this is not how it's supposed to work...)
> >
> > You found a bug. Thanks. I will fix it.
>
> Does that mean my above filter won't work anymore (as it would produce
> 'empty' classes) and I will have to return True when called on the
> actual class methods? (and if so, how would the updated filter look like?)
First of all you are right. Now small explanation how filtering works.
pygccxml defines make_flatten function. This function takes declaration
and returns list of all declarations found\located\defined in that declaration,
including it self. Filter functions use this function to create list
that contains
all declarations and after this then call "match" function on every declaration.
This approach has advantage ( fine control ) and disadvantage(
a little bit complex "match" function ).
Now how do you write filter function:
def should_stay(decl):
if isinstance( decl.parent, pygccxml.declarations.class_t ):
return True #This will leave all declarations defined under classes
if ....
if you need even grater control on exported declarations you can use
next filter:
if isinstance( decl, pygccxml.declarations.member_calldef_t):
if decl.access_type != pygccxml.declaration.ACCESS_TYPES.PUBLIC:
return False
Be sure to take a look on py_qtxml example: http://tinyurl.com/9uhv4
This examples reuse Qt XML class naming convention. It leaves only classes
that their name start with 'QDom' or 'QXml'. Also it removes
constructor, that as input
takes a pointer to implementation details class instance.
An other example is py_date_time: http://tinyurl.com/e44kh. This example
defines pretty complex "should_stay_ function. This is also should help you.
I hope this was helpful. Also I fixed bug you reported in previous
post. Thanks for
reporting them. As always fixes in CVS.
> - Matthias -
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From baas at ira.uka.de Mon Feb 6 19:07:13 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Mon, 06 Feb 2006 19:07:13 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170601300808o7c99bd6cgf936f22fb40ed6b6@mail.gmail.com> <7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com> <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com> <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
<7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
>> Why don't you just include the header that actually defines the
>> corresponding class (i.e. "a.h" when wrapping A and "b.h" when wrapping
>> B)?
>
> This is exactly what I do. May be I did not explain my self well.
Do you mean that should already work with the version in cvs? I cannot
confirm that. Here, pyplusplus adds all headers that were parsed.
>>>> def filter(decl):
>>>> return decl.name in [......]
>>>>
>>>> But now that I come to think about it, I don't understand why this works
>>>> at all. I noticed that the filter function is also applied to class
>>>> methods in which case the function returns False. But why are the
>>>> methods then exposed? (I thought this would be a way to filter out the
>>>> protected methods, but obviously this is not how it's supposed to work...)
>>>
>>> You found a bug. Thanks. I will fix it.
>>[...]
ok, I'll wait until the bug is fixed before I go on with my filtering
attempts...
- Matthias -
From benveal92 at hotmail.com Tue Feb 7 03:07:58 2006
From: benveal92 at hotmail.com (Ben Veal)
Date: Tue, 07 Feb 2006 02:07:58 +0000
Subject: [C++-sig] linking with non-python libraries
Message-ID:
Hi,
I am trying to build a python extension for a derived class whose base class
I only have as a shared library object & declaration file.
The base class contains many virtual functions of which I only need a few,
and also involves some threading. It contains various functions for getting
data from a remote server.
I manage to build the extension OK (both manually and using pyplusplus),
however when I try to import it, I get the following message:
ImportError: /usr/lib/python2.3/MyClient.so: undefined symbol:
_ZN8BaseClassC2ERKS_
I suppose it can't find the library containing the base class. I use the
following lines in my Jamfile to link with the appropriate libraries:
extension DerivedClass
:
sourcefile.cpp
@boost/libs/python/build/extension
: /usr/include/BaseClassDir
/usr/lib/BaseClass.so
/usr/lib/pthread
__LINUX
;
Is is possible to link to a non-python library from a python module?
If so, what am I doing wrong (surely something simple?).
If I manage to get over this linking hurdle, is it likely that I will be
able to get my extension to work with all the threading?
Thanks.
From seefeld at sympatico.ca Tue Feb 7 03:23:16 2006
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Mon, 06 Feb 2006 21:23:16 -0500
Subject: [C++-sig] linking with non-python libraries
In-Reply-To:
References:
Message-ID: <43E80494.8050202@sympatico.ca>
Ben Veal wrote:
> I manage to build the extension OK (both manually and using pyplusplus),
> however when I try to import it, I get the following message:
>
> ImportError: /usr/lib/python2.3/MyClient.so: undefined symbol:
> _ZN8BaseClassC2ERKS_
>
> I suppose it can't find the library containing the base class. I use the
> following lines in my Jamfile to link with the appropriate libraries:
The error message is emitted at runtime, not link time. Therefor, you
should instruct the loader how to find the library, not the linker.
Since you mention linux, I suggest you set the LD_LIBRARY_PATH variable
to contain the path to your library. (Running 'ldd' on your extension
module will tell you what third-party libraries it depends on and whether
and where it finds them.)
HTH,
Stefan
From roman.yakovenko at gmail.com Tue Feb 7 06:41:25 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Tue, 7 Feb 2006 07:41:25 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
<7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
<7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
Message-ID: <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
On 2/6/06, Matthias Baas wrote:
> Roman Yakovenko wrote:
> >> Why don't you just include the header that actually defines the
> >> corresponding class (i.e. "a.h" when wrapping A and "b.h" when wrapping
> >> B)?
> >
> > This is exactly what I do. May be I did not explain my self well.
>
> Do you mean that should already work with the version in cvs? I cannot
> confirm that. Here, pyplusplus adds all headers that were parsed.
>
> >>>> def filter(decl):
> >>>> return decl.name in [......]
> >>>>
> >>>> But now that I come to think about it, I don't understand why this works
> >>>> at all. I noticed that the filter function is also applied to class
> >>>> methods in which case the function returns False. But why are the
> >>>> methods then exposed? (I thought this would be a way to filter out the
> >>>> protected methods, but obviously this is not how it's supposed to work...)
> >>>
> >>> You found a bug. Thanks. I will fix it.
> >>[...]
>
> ok, I'll wait until the bug is fixed before I go on with my filtering
> attempts...
May be you missed my previuos letter or I was unclear, but I fixed
"filter" bug and provided explanation how you can use filter.
Here is the link to relevant mail:
http://mail.python.org/pipermail/c++-sig/2006-February/010123.html
> - Matthias -
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Tue Feb 7 06:47:07 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Tue, 7 Feb 2006 07:47:07 +0200
Subject: [C++-sig] linking with non-python libraries
In-Reply-To:
References:
Message-ID: <7465b6170602062147v5a18bb18sa865fc9127e8fa82@mail.gmail.com>
On 2/7/06, Ben Veal wrote:
> Hi,
> I am trying to build a python extension for a derived class whose base class
> I only have as a shared library object & declaration file.
> The base class contains many virtual functions of which I only need a few,
> and also involves some threading. It contains various functions for getting
> data from a remote server.
> I manage to build the extension OK (both manually and using pyplusplus),
Congratulation! What do you mean "both manually and using pyplusplus"?
Also could you provide link to your project? If you don't mind I will add it
to the "who is using pyplusplus" list.
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From baas at ira.uka.de Tue Feb 7 10:09:04 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Tue, 07 Feb 2006 10:09:04 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170601302132o26dbdaa6x6c6e412764ac2509@mail.gmail.com> <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com> <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com> <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
<7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
>>>>>> But now that I come to think about it, I don't understand why this works
>>>>>> at all. I noticed that the filter function is also applied to class
>>>>>> methods in which case the function returns False. But why are the
>>>>>> methods then exposed? (I thought this would be a way to filter out the
>>>>>> protected methods, but obviously this is not how it's supposed to work...)
>>>>>
>>>>> You found a bug. Thanks. I will fix it.
>>>>[...]
>>
>> ok, I'll wait until the bug is fixed before I go on with my filtering
>> attempts...
>
> May be you missed my previuos letter or I was unclear, but I fixed
> "filter" bug and provided explanation how you can use filter.
I saw the mail, but after I updated from cvs I still got the same
behavior as above, i.e. my filter still returns False on all class
methods but the methods are included in the output nevertheless, so I
was under the impression that the bug hasn't been fixed yet.
What exactly is/was the bug you were referring to? (maybe we have
different understandings of what the bug actually is...)
- Matthias -
From cavok at tiscali.it Tue Feb 7 10:12:51 2006
From: cavok at tiscali.it (Domenico Andreoli)
Date: Tue, 7 Feb 2006 10:12:51 +0100
Subject: [C++-sig] linking with non-python libraries
In-Reply-To: <43E80494.8050202@sympatico.ca>
References:
<43E80494.8050202@sympatico.ca>
Message-ID: <20060207091251.GB15287@raptus.dandreoli.com>
hi,
On Mon, Feb 06, 2006 at 09:23:16PM -0500, Stefan Seefeld wrote:
> Ben Veal wrote:
>
> > I manage to build the extension OK (both manually and using pyplusplus),
> > however when I try to import it, I get the following message:
> >
> > ImportError: /usr/lib/python2.3/MyClient.so: undefined symbol:
> > _ZN8BaseClassC2ERKS_
> >
> > I suppose it can't find the library containing the base class. I use the
> > following lines in my Jamfile to link with the appropriate libraries:
>
> The error message is emitted at runtime, not link time. Therefor, you
> should instruct the loader how to find the library, not the linker.
> Since you mention linux, I suggest you set the LD_LIBRARY_PATH variable
> to contain the path to your library. (Running 'ldd' on your extension
> module will tell you what third-party libraries it depends on and whether
> and where it finds them.)
i'm not sure that setting LD_LIBRARY_PATH would solve the problem. this
is because the loader can't load a library that has not been linked at
link time. i'm instead pretty sure that ldd does not print about any
missing library for your module. go ahead and link it.
to save time, in my boost.python projects i try to import the module
at build time. this way i discover immediately that the module is
not usable.
ciao
domenico
-----[ Domenico Andreoli, aka cavok
--[ http://people.debian.org/~cavok/gpgkey.asc
---[ 3A0F 2F80 F79C 678A 8936 4FEE 0677 9033 A20E BC50
From roman.yakovenko at gmail.com Tue Feb 7 11:23:29 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Tue, 7 Feb 2006 12:23:29 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com>
<7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
<7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
<7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
Message-ID: <7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
On 2/7/06, Matthias Baas wrote:
> I saw the mail, but after I updated from cvs I still got the same
> behavior as above, i.e. my filter still returns False on all class
> methods but the methods are included in the output nevertheless, so I
> was under the impression that the bug hasn't been fixed yet.
> What exactly is/was the bug you were referring to? (maybe we have
> different understandings of what the bug actually is...)
module_creator.creator_t class.
When it comes to create code creators for class member function/variables it
did not take into account filtered out declarations. I fixed that bug.
May be there is an other bug. Could you create simple usecase?
> - Matthias -
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Tue Feb 7 17:08:09 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Tue, 7 Feb 2006 18:08:09 +0200
Subject: [C++-sig] Open Source Development Conference Boost.Python
pyplusplus presentation
Message-ID: <7465b6170602070808x935de7esd14c44f769479b62@mail.gmail.com>
Hi.
I am going to give a talk on OSDC::Israel::2006 about Boost.Python and
pyplusplus, multi-language development and code generation.
Link to conference page http://www.osdc.org.il/index.html .
I'd like to show my talk before I actually give it. I will be glad, if
somebody will take
a look on it and give me a feedback.
Please contact me privatly to get the talk.
( It is top secret :-) )
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From baas at ira.uka.de Tue Feb 7 17:18:48 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Tue, 07 Feb 2006 17:18:48 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170601312109i484ff1d5pf0a6afd7821d6e92@mail.gmail.com> <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com> <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com> <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
<7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
> On 2/7/06, Matthias Baas wrote:
>> I saw the mail, but after I updated from cvs I still got the same
>> behavior as above, i.e. my filter still returns False on all class
>> methods but the methods are included in the output nevertheless, so I
>> was under the impression that the bug hasn't been fixed yet.
>> What exactly is/was the bug you were referring to? (maybe we have
>> different understandings of what the bug actually is...)
>
> module_creator.creator_t class.
> When it comes to create code creators for class member function/variables it
> did not take into account filtered out declarations. I fixed that bug.
>
> May be there is an other bug. Could you create simple usecase?
Below is a simple header and a pyplusplus script that creates
Boost.Python code for the header. Even though the filter function
returns False on the spam() method, the method is included in the output.
- Matthias -
///////////////////////////////////////////////////////
// File: class.h
class Foo
{
public:
Foo();
void spam();
};
///////////////////////////////////////////////////////
##########################################################
# pyplusplus script
import os, os.path
from pygccxml import parser
from pygccxml import declarations
from pyplusplus import code_creators
from pyplusplus import module_creator
from pyplusplus import file_writers
def declfilter(decl):
"""Only return True when the name is 'Foo'."""
res = decl.name in ["Foo"]
print decl.name,"...",res
return res
parser_config = parser.config_t(working_directory = "tmp")
decls_all = parser.parse(["class.h"], parser_config )
decls = declarations.filtering.user_defined( decls_all, declfilter )
creator = module_creator.creator_t(
decls = decls,
module_name = "_api",
recursive = True,
)
extmodule = creator.create()
file_writers.write_file( extmodule, 'bindings.cpp' )
##########################################################
From benveal92 at hotmail.com Wed Feb 8 02:22:49 2006
From: benveal92 at hotmail.com (Ben Veal)
Date: Wed, 08 Feb 2006 01:22:49 +0000
Subject: [C++-sig] linking with non-python libraries
Message-ID:
>On Mon, Feb 06, 2006 at 09:23:16PM -0500, Stefan Seefeld wrote:
>>Ben Veal wrote:
> >
> >> I manage to build the extension OK (both manually and using
>pyplusplus), >> however when I try to import it, I get the following
>message:
> >> >> ImportError: /usr/lib/python2.3/MyClient.so: undefined symbol: >>
>_ZN8BaseClassC2ERKS_
> >> >> I suppose it can't find the library containing the base class. I use
>the >> following lines in my Jamfile to link with the appropriate
>libraries:
>>
>>The error message is emitted at runtime, not link time. Therefor, you
>>should instruct the loader how to find the library, not the linker.
>>Since you mention linux, I suggest you set the LD_LIBRARY_PATH variable
>>to contain the path to your library. (Running 'ldd' on your extension
>>module will tell you what third-party libraries it depends on and whether
>>and where it finds them.)
>
>i'm not sure that setting LD_LIBRARY_PATH would solve the problem. this
>is because the loader can't load a library that has not been linked at
>link time. i'm instead pretty sure that ldd does not print about any
>missing library for your module. go ahead and link it.
You're right, ldd says that it is linked OK.
When I build normal c++ executables (not python extensions) I have no
problems.
Here is the relevant linking command that is produced by my makefile:
g++ -o output.exe input.o -L. -s /usr/lib/libBaseClass.so -lpthread
I notice that there is no -l preceeding '/usr/lib/libBaseClass.so' is this
important?
Could it be anything to do with the '-s' option? (what is the equivalent
Jamfile requirement?)
Thanks.
Also, in reply to the comments from Roman Yakovenko:
>Congratulation! What do you mean "both manually and using pyplusplus"?
I mean with & without using pyplusplus (I was unsure of my initial attempt
so I used pyplusplus aswell)
>Also could you provide link to your project? If you don't mind I will add
>it
>to the "who is using pyplusplus" list.
Eventually, if I can get it to work properly.
From seefeld at sympatico.ca Wed Feb 8 02:40:21 2006
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Tue, 07 Feb 2006 20:40:21 -0500
Subject: [C++-sig] linking with non-python libraries
In-Reply-To:
References:
Message-ID: <43E94C05.2090507@sympatico.ca>
Ben Veal wrote:
> Here is the relevant linking command that is produced by my makefile:
>
> g++ -o output.exe input.o -L. -s /usr/lib/libBaseClass.so -lpthread
>
> I notice that there is no -l preceeding '/usr/lib/libBaseClass.so' is this
> important?
Good question. Why don't you call
g++ -o output.exe input.o -lBaseClass -lpthread
instead as everybody else ? :-)
Regards,
Stefan
From roman.yakovenko at gmail.com Wed Feb 8 06:46:15 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Wed, 8 Feb 2006 07:46:15 +0200
Subject: [C++-sig] linking with non-python libraries
In-Reply-To:
References:
Message-ID: <7465b6170602072146r4521640cs8e9577005878d149@mail.gmail.com>
On 2/8/06, Ben Veal wrote:
> Also, in reply to the comments from Roman Yakovenko:
>
> >Congratulation! What do you mean "both manually and using pyplusplus"?
>
> I mean with & without using pyplusplus (I was unsure of my initial attempt
> so I used pyplusplus aswell)
>
> >Also could you provide link to your project? If you don't mind I will add
> >it
> >to the "who is using pyplusplus" list.
>
> Eventually, if I can get it to work properly.
Thanks
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Wed Feb 8 07:49:57 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Wed, 8 Feb 2006 08:49:57 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com>
<7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
<7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
<7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
Message-ID: <7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
On 2/7/06, Matthias Baas wrote:
> ...
> decls = declarations.filtering.user_defined( decls_all, declfilter )
> creator = module_creator.creator_t(
> decls = decls,
> module_name = "_api",
> recursive = True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive should be set to False
> ...
Explanation:
When you should set recursive to true?
In case you want to export all declarations found in class or namespace.
Example:
//file foo.h
namespace foo{
struct person{
std::string name;
};
struct team{
std::vector members;
};
}
namespace details{
void sort_team( foo::team& );
}
Lets say you want to expose only declarations found in namespace foo.
The best way to do it is next:
decls = parser.parse(["foo.h"])
namespace_foo = declarations.find_declaration( decls
,
type=declarations.namespace_t
, name="foo" )
extmodule = module_creator.create( decls=namespace_foo
, module_name="foo"
, recursive=True )
In all other cases recursive should be set to False.
Now I understand why you have been confused.
1. Lack of documentation.
2. The way how filters work:
As input to filters you give declarations tree, as output you get
a list, that contains
all declarations, that filter input function has said true for them.
There are few reasons why this is done in this way:
1. To mimic Python build-in filter function behaviour
1.1 don't modify a state of input argument
1.2 construct new list
1.3 Fill it with items, for them input function has returned true.
2. Performance reasons:
I can create a copy of all declarations and return declarations tree,
but this approach is too expensive in time and memory
3. I could modify an input argument - input declarations tree. But
this approach
has price: it removes valuable information and could lead to
generated code that
could not be compiled.
Example:
struct person{
void set_birthday(unsigned int year, unsigned int
month, unsigned int day);
void set_birthday(const std::string& birthday);
};
Lets say that you want to expose first member function and not second.
Using filter functionality you removes second set_birthday
declaration from
declarations tree. Now you are missing important information:
whether function
is overloaded or not.
Hope, this explanation was helpful. I am open to suggestions and comments.
It would be nice to get your opinion how I can improve the interface.
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From s_sourceforge at nedprod.com Wed Feb 8 18:25:21 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Wed, 08 Feb 2006 17:25:21 -0000
Subject: [C++-sig] Patch implementing void * support
In-Reply-To:
Message-ID: <43EA2981.17513.9FBBB364@s_sourceforge.nedprod.com>
On 26 Jan 2006 at 15:03, David Abrahams wrote:
> Your patch must pass the Boost.Python test suite against the CVS in
> order to be accepted.
I have tried repeatedly to get Boost from CVS during the last few
days. Sourceforge says it rejects access to /cvsroot/boost for user
anonymous. I have other CVS repositories on sourceforge working so I
give up - I hate CVS anyway, it has never worked satisfactorily for
me.
If someone else wants to apply the patch to CVS and submit please
feel free. Otherwise this patch is dead until the next release of
Boost when I'll try again.
Cheers,
Niall
From s_sourceforge at nedprod.com Wed Feb 8 18:25:21 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Wed, 08 Feb 2006 17:25:21 -0000
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <7465b6170602080603g45d58217r971d844beb421e74@mail.gmail.com>
References: <43E9DAB8.1946.9E87F24B@s_sourceforge.nedprod.com>
Message-ID: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
As requested moved onto the python C++ SIG mailing list.
> > Tried it with CVS pyplusplus this morning and it's still not ordering
> > registrations correctly. If you try loading in the TnFOX.pyd module
> > you will get the "No to_python (by-value) converter found for C++
> > type: class FX::FXACLEntity" fatal exception because
> > register_FXACL_class() needs register_FXACLEntity_class() before it.
>
> This is what I don't understand and can not create with simple use case,
> that will reproduce the problem.
>
> See this mail:
> http://mail.python.org/pipermail/c++-sig/2006-January/010100.html
This email is incorrect. Here is the backtrace for when the exception
is thrown:
TnFOX.dll!boost::python::throw_error_already_set() Line 61 C++
TnFOX.dll!boost::python::converter::registration::to_python(const
void * source=0x605dc654) Line 53 C++
TnFOX.dll!boost::python::converter::detail::arg_to_python_base::arg_to
_python_base(const void * source=0x605dc654, const
boost::python::converter::registration & converters={...}) Line 24 +
0x13 C++
TnFOX.dll!boost::python::api::object_initializer_impl<0,0>::get(const FX::FXACLEntity & x={...}, boost::mpl::bool_<0>
__formal={...}) Line 368 + 0x12 C++
TnFOX.dll!boost::python::api::object_base_initializer
(const FX::FXACLEntity & x={...}) Line 290 + 0xd C++
TnFOX.dll!boost::python::detail::keywords<1>::operator=() Line 74 + 0x9 C++
TnFOX.dll!register_FXACL_class() Line 285 + 0x54 C++
TnFOX.dll!init_module_TnFOX() + 0x19 C++
This localises the problem code to:
void register_FXACL_class(){
if( true ){
typedef bp::class_< FXACL_wrapper > FXACL_exposer_t;
FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL",
bp::init< FX::FXACL::EntityType, FX::FXACLEntity const & >((
bp::arg("type")=::FX::FXACL::Unknown,
bp::arg("owner")=FX::FXACLEntity::currentUser( ) ))/*[ undefined call
policies ]*/ );
In other words, the requirement for the FXACLEntity definition to BPL
is coming from its use in the constructor for FXACL - specifically
the bit ' bp::arg("owner")= ' - which I am guessing from the
boost::python::detail::keywords<1>::operator=() just
above it in the backtrace.
Dave - does boost::python::arg()= require the type of the parameter
being set to be already registered? I would imagine that it surely
does.
> I attach test file, can you take a look on them? May be you have some ideas?
> What can cause this error?
Really, the best thing is to build the full TnFOX Python bindings and
test them. It's probably a little slow on your computer though, so I
understand if you don't want to do so.
> > > > There's a simple solution - ensure that registrations occur in
> > > > exactly the same order of class definitions in the parsed header. I
> > > > vaguely remember a problem with this as GCCXML doesn't always do what
> > > > one expect here, but you're more an expert here than I.
> > >
> > > pyplusplus has class class_organizer_t that is responsible for order of classes.
> > > It uses topological sort in order to decide it. If needed, I can add
> > > an other condition
> > > to it.
> >
> > If you examine the fx.xml file you will see that FXACLEntity is given
> > id=_27958 and FXACL is given id=_28827. Now I don't know if the id
> > number is incremented linearly, but I do notice that incomplete
> > declarations can happen and these would screw with the correct
> > ordering. You need to order registrations in the same order as
> > *complete* declarations. This may mean running your own counter which
> > is only incremented with every complete declaration, then later
> > ordering in terms of this count.
>
> Niall, I don't understand what cause the problem. So I can not solve it.
> I need to understand it first. After this I am sure we can find some solution.
I had the same problem with pyste, hence Bruno implemented the
solution I suggested above and it worked.
> I do not want to prevent you from working. I give you few ideas for
> work around:
It's okay - I have an obscene amount of work on right now (I am
organising a lecture series in addition to my normal workload, and it
begins next week).
> 1. exclude those class
> very simple solution, you can implement this in few minutes,
>
> 2. change the order of classes: you can find FXACL and FXACLEntity code creators
> and to adjust their positions. I can implement this solution for
> you. Tell me if you
> want me to do it for you. If you want to try to implement it
> itself, then take a look
> on code_creators.compound_t class. It has to members remove_creator and
> adopt_creator. adopt_creator allows you to place creator to
> specific position.
> code_creators.creator_finder class provides functionality to find
> code creator
> base on some criteria.
If you try either of these you run into major problems - there are
too many dependency issues to do it manually. I did try shuffling
around the registrations but gave up after I had moved ten.
Cheers,
Niall
From dave at boost-consulting.com Wed Feb 8 21:38:16 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 08 Feb 2006 15:38:16 -0500
Subject: [C++-sig] Patch implementing void * support
References:
<43EA2981.17513.9FBBB364@s_sourceforge.nedprod.com>
Message-ID:
"Niall Douglas" writes:
> On 26 Jan 2006 at 15:03, David Abrahams wrote:
>
>> Your patch must pass the Boost.Python test suite against the CVS in
>> order to be accepted.
>
> I have tried repeatedly to get Boost from CVS during the last few
> days. Sourceforge says it rejects access to /cvsroot/boost for user
> anonymous. I have other CVS repositories on sourceforge working so I
> give up - I hate CVS anyway, it has never worked satisfactorily for
> me.
>
> If someone else wants to apply the patch to CVS and submit please
> feel free. Otherwise this patch is dead until the next release of
> Boost when I'll try again.
You can get a tarball of the current Boost CVS state at
http://www.boost-consulting.com/boost.tar.bz2
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From baas at ira.uka.de Wed Feb 8 23:54:46 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Wed, 08 Feb 2006 23:54:46 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170602012159h5f78b334s9238f6f30f842371@mail.gmail.com> <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com> <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com> <7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
<7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive should be set to False
Hm, with my first attempt of using pyplusplus I only got empty source
files unless I set recursive to True (see the beginning of this thread),
but when I test it again now, it actually works....?
Anyway, it's a bit odd that an apparently "unrelated" option changes the
semantics of the filter function. Why is the filter then called on
objects such as class methods where the return value of the filter has
no effect at all? It would be a little less confusing if the filter
wouldn't be called at all in those cases.
It's the same with classes that were already rejected by a filter call,
I noticed that in this case the filter is still invoked on the methods
of the already rejected class which also has no effect and could be
entirely left out.
> Now I understand why you have been confused.
>
> 1. Lack of documentation.
Definitely! ;)
Thanks to the tip with the recursive flag I could go on with my wrapping
efforts. I could wrap a whole bunch of new classes before I hit another
bug in pyplusplus. There is this one class method that takes an unsigned
int with default value as argument. Pyplusplus then generates code like
this:
.def( "foo",
&MyClass::foo,
(bp::arg("index")=unsigned int(0)),
bp::default_call_policies() )
When compiled with gcc I get a syntax error in the third line. The code
only compiles when I put brackets around the "unsigned int":
(bp::arg("index")=(unsigned int)(0)),
- Matthias -
From roman.yakovenko at gmail.com Thu Feb 9 06:59:58 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 07:59:58 +0200
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
References: <43E9DAB8.1946.9E87F24B@s_sourceforge.nedprod.com>
<7465b6170602080603g45d58217r971d844beb421e74@mail.gmail.com>
<43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
Message-ID: <7465b6170602082159v626da3dau7eed49bab1a409c8@mail.gmail.com>
On 2/8/06, Niall Douglas wrote:
> As requested moved onto the python C++ SIG mailing list.
Thanks
> > > Tried it with CVS pyplusplus this morning and it's still not ordering
> > > registrations correctly. If you try loading in the TnFOX.pyd module
> > > you will get the "No to_python (by-value) converter found for C++
> > > type: class FX::FXACLEntity" fatal exception because
> > > register_FXACL_class() needs register_FXACLEntity_class() before it.
> >
> > This is what I don't understand and can not create with simple use case,
> > that will reproduce the problem.
> >
> > See this mail:
> > http://mail.python.org/pipermail/c++-sig/2006-January/010100.html
>
> This email is incorrect. Here is the backtrace for when the exception
> is thrown:
>
> TnFOX.dll!boost::python::throw_error_already_set() Line 61 C++
>
> TnFOX.dll!boost::python::converter::registration::to_python(const
> void * source=0x605dc654) Line 53 C++
>
> TnFOX.dll!boost::python::converter::detail::arg_to_python_base::arg_to
> _python_base(const void * source=0x605dc654, const
> boost::python::converter::registration & converters={...}) Line 24 +
> 0x13 C++
>
> TnFOX.dll!boost::python::api::object_initializer_impl<0,0>::get ACLEntity>(const FX::FXACLEntity & x={...}, boost::mpl::bool_<0>
> __formal={...}) Line 368 + 0x12 C++
>
> TnFOX.dll!boost::python::api::object_base_initializer
> (const FX::FXACLEntity & x={...}) Line 290 + 0xd C++
>
> TnFOX.dll!boost::python::detail::keywords<1>::operator= y>() Line 74 + 0x9 C++
>
> TnFOX.dll!register_FXACL_class() Line 285 + 0x54 C++
>
> TnFOX.dll!init_module_TnFOX() + 0x19 C++
>
>
> This localises the problem code to:
>
> void register_FXACL_class(){
> if( true ){
> typedef bp::class_< FXACL_wrapper > FXACL_exposer_t;
> FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL",
> bp::init< FX::FXACL::EntityType, FX::FXACLEntity const & >((
> bp::arg("type")=::FX::FXACL::Unknown,
> bp::arg("owner")=FX::FXACLEntity::currentUser( ) ))/*[ undefined call
> policies ]*/ );
Thank you very much, now I understand the whole problem. See end of the email
for solution.
> In other words, the requirement for the FXACLEntity definition to BPL
> is coming from its use in the constructor for FXACL - specifically
> the bit ' bp::arg("owner")= ' - which I am guessing from the
> boost::python::detail::keywords<1>::operator=() just
> above it in the backtrace.
>
> Dave - does boost::python::arg()= require the type of the parameter
> being set to be already registered? I would imagine that it surely
> does.
I will start an other thread. I have simple test case that reproduce the problem
> Really, the best thing is to build the full TnFOX Python bindings and
> test them. It's probably a little slow on your computer though, so I
> understand if you don't want to do so.
I do want but I am not able. pyplusplus generates +- 300 cpp files. It
takes 2.5 minutes
to compile every file on my laptop at home. So in order to compile
TnFOX I need more or
less 12-13 hours. On my work we have compilation farm from 15
computers. So it takes
10 - 15 minutes to compile it. But I do not have time to setup whole
environment.
And the main reason: I want to setup unit test for pyplusplus.
>
> > > > > There's a simple solution - ensure that registrations occur in
> > > > > exactly the same order of class definitions in the parsed header. I
> > > > > vaguely remember a problem with this as GCCXML doesn't always do what
> > > > > one expect here, but you're more an expert here than I.
> > > >
> > > > pyplusplus has class class_organizer_t that is responsible for order of classes.
> > > > It uses topological sort in order to decide it. If needed, I can add
> > > > an other condition
> > > > to it.
> > >
> > > If you examine the fx.xml file you will see that FXACLEntity is given
> > > id=_27958 and FXACL is given id=_28827. Now I don't know if the id
> > > number is incremented linearly, but I do notice that incomplete
> > > declarations can happen and these would screw with the correct
> > > ordering. You need to order registrations in the same order as
> > > *complete* declarations. This may mean running your own counter which
> > > is only incremented with every complete declaration, then later
> > > ordering in terms of this count.
> >
> > Niall, I don't understand what cause the problem. So I can not solve it.
> > I need to understand it first. After this I am sure we can find some solution.
>
> I had the same problem with pyste, hence Bruno implemented the
> solution I suggested above and it worked.
I am sure this solution works. I have only one problem with this
solution: it works
only in case you want to export declarations, from single header file.
Solution for the problem:
function_t and constructor_t code creators has property "use_keywords"
This property is responcible for generation of keyword arguments. If you set
it to False, then keyword arguments will not be generated.
Here is relevant code:
relevant_classes = (code_creators.function_t, code_creators.constructor_t )
calldefs = filter( lambda creator: isinstance( creator, relevant_classes )
, code_creators.make_flatten( extmodule.creators ) )
for calldef in calldefs:
calldef.use_keywords = False
Your version of pyplusplus already has this functionality, but it has few bug.
Please, use latest CVS version.
> Cheers,
> Niall
>
Thanks.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From umangjaipuria at gmail.com Thu Feb 9 06:55:17 2006
From: umangjaipuria at gmail.com (Umang Jaipuria)
Date: Thu, 9 Feb 2006 11:25:17 +0530
Subject: [C++-sig] segmentation fault in Boost.Python/Python C api
Message-ID:
My application uses Boost.Python 1.33.1 and there was a segfault with a core
dump. The stack trace follows.
I'll grateful if anyone can point me in the right direction to figuring out
what the problem is.
Thanks,
Umang Jaipuria
#0 0x00c6d002 in free () from /lib/tls/libc.so.6
#1 0x00da92de in PyObject_Free (p=0x5c30) at Objects/obmalloc.c:774
#2 0x00da8d5d in PyMem_Free (p=0x0) at Objects/object.c:2111
#3 0x0043b3a9 in boost::python::instance_holder::deallocate () from
/usr/local/lib/libboost_python-gcc-mt-1_33_1.so.1.33.1
#4 0x0043b412 in boost::python::instance_holder::deallocate () from
/usr/local/lib/libboost_python-gcc-mt-1_33_1.so.1.33.1
#5 0x00db44ff in subtype_dealloc (self=0xb746ff2c) at
Objects/typeobject.c:703
#6 0x00db25d1 in tupledealloc (op=0xb74659bc) at Objects/tupleobject.c:145
#7 0x00ddd6a0 in eval_frame (f=0xa37737c) at Python/ceval.c:3652
#8 0x00dde27b in PyEval_EvalCodeEx (co=0xb745f420, globals=0x4, locals=0x0,
args=0x0, argcount=2, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
at Python/ceval.c:2669
#9 0x00d94458 in function_call (func=0xb7466294, arg=0xb7470eec, kw=0x0) at
Objects/funcobject.c:504
#10 0x00d7c0d7 in PyObject_Call (func=0x1, arg=0x0, kw=0x0) at
Objects/abstract.c:1755
#11 0x00dd7818 in PyEval_CallObjectWithKeywords (func=0x0, arg=0xb7470eec,
kw=0x0) at Python/ceval.c:3352
#12 0x00e004a9 in PyEval_CallFunction (obj=0x0, format=0x0) at
Python/modsupport.c:477
#13 0x0114f9bc in boost::python::call,
boost::reference_wrapper > (callable=0x0, a0=@0x0,
a1=@0x0) at handle.hpp:63
From roman.yakovenko at gmail.com Thu Feb 9 07:23:26 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 08:23:26 +0200
Subject: [C++-sig] registration order
Message-ID: <7465b6170602082223q49782950pcb6628169f53f783@mail.gmail.com>
Hi.
Please take a look on next code:
struct item{
explicit item( int i )
: m_value( i )
{}
int m_value;
};
struct container{
public:
explicit container( const item& x = item( 2 ) )
: my_item( x )
{}
item my_item;
};
BOOST_PYTHON_MODULE(class_order){
bp::class_< container >( "container"
, bp::init< item const & >((
bp::arg("x")=item( 1 ) ) ) )
.def_readwrite( "my_item", &container::my_item );
bp::class_< item >( "item"
, bp::init< int >(( bp::arg("i") ) ) )
.def_readwrite( "m_value", &item::m_value );
}
Module class_order can not be loaded. The reason is that
bp::arg("x")=::class_order::item( 1 )
expression requires class "item" to be already registered.
I see from the doc
Class arg operator =
template arg &operator = (T const &value);
Requires: The argument must convertible to python.
that this is intentional behaviour. Is it possible to remove this requirement?
Thanks.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Thu Feb 9 08:10:52 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 09:10:52 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com>
<7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
<7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
<7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
Message-ID: <7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
On 2/9/06, Matthias Baas wrote:
> Roman Yakovenko wrote:
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive should be set to False
>
> Hm, with my first attempt of using pyplusplus I only got empty source
> files unless I set recursive to True (see the beginning of this thread),
> but when I test it again now, it actually works....?
Because I fixed the bug you reported.
> Anyway, it's a bit odd that an apparently "unrelated" option changes the
> semantics of the filter function.
You are welcome to suggest interface improvments :-)
> Why is the filter then called on
> objects such as class methods where the return value of the filter has
> no effect at all? It would be a little less confusing if the filter
> wouldn't be called at all in those cases.
Because I did not think about it. Although question: If you exclude namespace,
does it mean that you want to exclude all declaration found in that namespace?
> It's the same with classes that were already rejected by a filter call,
> I noticed that in this case the filter is still invoked on the methods
> of the already rejected class which also has no effect and could be
> entirely left out.
>
> > Now I understand why you have been confused.
> >
> > 1. Lack of documentation.
>
> Definitely! ;)
>
>
> Thanks to the tip with the recursive flag I could go on with my wrapping
> efforts. I could wrap a whole bunch of new classes before I hit another
> bug in pyplusplus.
I appreciate every contribution :-).
> There is this one class method that takes an unsigned
> int with default value as argument. Pyplusplus then generates code like
> this:
>
> .def( "foo",
> &MyClass::foo,
> (bp::arg("index")=unsigned int(0)),
> bp::default_call_policies() )
>
> When compiled with gcc I get a syntax error in the third line. The code
> only compiles when I put brackets around the "unsigned int":
>
> (bp::arg("index")=(unsigned int)(0)),
May be it sound stupid, but I can not reproduce your problem. Sorry :-(
I tried next function declaration and pyplusplus generates valid code:
fix_fundamental( unsigned int arg=(unsigned int)(0) );
bp::def( "fix_fundamental"
, &fundamental::fix_fundamental
, ( bp::arg("arg0")=0 )
, bp::default_call_policies() );
Could you create simple test case?
Also as temporal work around:
function_t and constructor_t code creators has use_default_arguments property.
You can set it to False in order to disable generation of default arguments.
Using use_keywords property on function_t and constructor_t code creators
will disable generation of keyword arguments at all.
It is up to you to decide what is the best solution.
> - Matthias -
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From baas at ira.uka.de Thu Feb 9 11:11:20 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Thu, 09 Feb 2006 11:11:20 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170602042337g6720a7f8q242b4dfd0c5b5b5a@mail.gmail.com> <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com> <7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com> <7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
<7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
>> Why is the filter then called on
>> objects such as class methods where the return value of the filter has
>> no effect at all? It would be a little less confusing if the filter
>> wouldn't be called at all in those cases.
>
> Because I did not think about it. Although question: If you exclude namespace,
> does it mean that you want to exclude all declaration found in that namespace?
I guess so. What other semantics would you suggest?
I was thinking that rejecting one node in the declaration tree actually
prunes the entire subtree.
> May be it sound stupid, but I can not reproduce your problem. Sorry :-(
> I tried next function declaration and pyplusplus generates valid code:
>
> fix_fundamental( unsigned int arg=(unsigned int)(0) );
>
> bp::def( "fix_fundamental"
> , &fundamental::fix_fundamental
> , ( bp::arg("arg0")=0 )
> , bp::default_call_policies() );
Sorry, the example in my previous mail was not the original example. I
left away the actual default argument that I deemed only to be a minor
detail, but as it turned out it's actually the key to produce the
failure. Now here's another (verified!) example:
enum spam { eggs };
void foo(unsigned int v=eggs);
If I wrap this code pyplusplus generates:
bp::def( "foo"
, &foo
, ( bp::arg("arg0")=unsigned int( ::::eggs ) )
, bp::default_call_policies() );
This code generates a compile error (using gcc 3.3.4). You have to
replace "unsigned int" with "(unsigned int)".
This example even reveals two more bugs that my original code doesn't
show. The four colons before "eggs" also produce a compile error, this
should only be two colons.
And then, for some reason, pyplusplus doesn't see the correct name ("v")
of the argument and just calls it "arg0" in the bindings.
- Matthias -
From s_sourceforge at nedprod.com Thu Feb 9 11:21:24 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 10:21:24 -0000
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <7465b6170602082159v626da3dau7eed49bab1a409c8@mail.gmail.com>
References: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
Message-ID: <43EB17A4.32067.A35DEAA5@s_sourceforge.nedprod.com>
On 9 Feb 2006 at 7:59, Roman Yakovenko wrote:
> I am sure this solution works. I have only one problem with this
> solution: it works
> only in case you want to export declarations, from single header file.
Indeed. Pyste only worked correctly when you did this because of this
exact reason.
> Solution for the problem:
> function_t and constructor_t code creators has property "use_keywords"
> This property is responcible for generation of keyword arguments. If you set
> it to False, then keyword arguments will not be generated.
Seems a shame. Pyste never told python about default arguments, so if
you asked for help on that API from within python you couldn't see
what the defaults were. Furthermore, later on, I'm sure you will want
to integrate docstrings pulled from doxygen output and if the
parameter names are not known you won't be able to print per-
parameter (\param) docs.
> Here is relevant code:
>
> relevant_classes = (code_creators.function_t, code_creators.constructor_t )
> calldefs = filter( lambda creator: isinstance( creator, relevant_classes )
> , code_creators.make_flatten( extmodule.creators ) )
> for calldef in calldefs:
> calldef.use_keywords = False
>
> Your version of pyplusplus already has this functionality, but it has few bug.
> Please, use latest CVS version.
No chance of sorting based on arg() usage being added?
Your other email where arg() doesn't need predefinition is equally a
solution. BPL could lazily add in the type info later, but it would
involve maintaining a list of where that type has been used in an
arg() and retrospectively linking it in when the definition is made.
I have a feeling that Dave won't want that extra complexity when you
can just reorder the registrations.
Cheers,
Niall
From s_sourceforge at nedprod.com Thu Feb 9 12:32:41 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 11:32:41 -0000
Subject: [C++-sig] Patch implementing void * support
In-Reply-To:
Message-ID: <43EB2859.10577.A39F2F72@s_sourceforge.nedprod.com>
On 8 Feb 2006 at 15:38, David Abrahams wrote:
> >> Your patch must pass the Boost.Python test suite against the CVS in
> >> order to be accepted.
> >
> > I have tried repeatedly to get Boost from CVS during the last few
> > days. Sourceforge says it rejects access to /cvsroot/boost for user
> > anonymous. I have other CVS repositories on sourceforge working so I
> > give up - I hate CVS anyway, it has never worked satisfactorily for
> > me.
> >
> > If someone else wants to apply the patch to CVS and submit please
> > feel free. Otherwise this patch is dead until the next release of
> > Boost when I'll try again.
>
> You can get a tarball of the current Boost CVS state at
> http://www.boost-consulting.com/boost.tar.bz2
The attached applies cleanly to Boost CVS 06-02-09-0100 and compiles
and passes the test suite on MSVC7.1 and GCC 4.0.2.
Cheers,
Niall
-------------- next part --------------
The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any other MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.
---- File information -----------
File: voidptrpatch.diff
Date: 9 Feb 2006, 11:29
Size: 10126 bytes.
Type: Unknown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: voidptrpatch.diff
Type: application/octet-stream
Size: 10126 bytes
Desc: not available
URL:
From roman.yakovenko at gmail.com Thu Feb 9 12:45:54 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 13:45:54 +0200
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com>
<7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
<7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
<7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
Message-ID: <7465b6170602090345j7644b7a3w6e8bb6c7bc3e3e10@mail.gmail.com>
On 2/9/06, Matthias Baas wrote:
> Roman Yakovenko wrote:
> Sorry, the example in my previous mail was not the original example. I
> left away the actual default argument that I deemed only to be a minor
> detail, but as it turned out it's actually the key to produce the
> failure. Now here's another (verified!) example:
>
> enum spam { eggs };
> void foo(unsigned int v=eggs);
>
> If I wrap this code pyplusplus generates:
>
> bp::def( "foo"
> , &foo
> , ( bp::arg("arg0")=unsigned int( ::::eggs ) )
> , bp::default_call_policies() );
>
> This code generates a compile error (using gcc 3.3.4). You have to
> replace "unsigned int" with "(unsigned int)".
Now you are talking :-).
First of all the bug has been fixed. You can check out only pygccxml package.
Second. There are few things happen here. GCC-XML sometimes generates
invalid default argument string. pygccxml tries to fix it. So the
exact case\source
is important.
> This example even reveals two more bugs that my original code doesn't
> show. The four colons before "eggs" also produce a compile error, this
> should only be two colons.
> And then, for some reason, pyplusplus doesn't see the correct name ("v")
> of the argument and just calls it "arg0" in the bindings.
There is nothing I can do. GCC-XML does not report argument name :-(.
I have to find time and to submit few bugs to GCC-XML.
Any way, :-), if the name of argument is important to you, there is
something you can do:
you can find relevant function, and then you can rename arguments.
Relevant classes are:
pygccxml.declarations.calldef_t -
it contains "arguments" property - list of all function arguments.
pygccxml.declarations.argument_t - class that defines argument
:-)
> - Matthias -
Thanks for bug reporting.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Thu Feb 9 12:54:15 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 13:54:15 +0200
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <43EB17A4.32067.A35DEAA5@s_sourceforge.nedprod.com>
References: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
<7465b6170602082159v626da3dau7eed49bab1a409c8@mail.gmail.com>
<43EB17A4.32067.A35DEAA5@s_sourceforge.nedprod.com>
Message-ID: <7465b6170602090354u34ceb88fg6a15574ef2241857@mail.gmail.com>
On 2/9/06, Niall Douglas wrote:
> Seems a shame. Pyste never told python about default arguments, so if
> you asked for help on that API from within python you couldn't see
> what the defaults were. Furthermore, later on, I'm sure you will want
> to integrate docstrings pulled from doxygen output and if the
> parameter names are not known you won't be able to print per-
> parameter (\param) docs.
Yes. I definitely will do it.
> No chance of sorting based on arg() usage being added?
I will do it. But it will take some time. 19 - 28 I have a trip to Dead Sea.
So I do not want to insert this functionality before it. Also CVS version
is much better then previous released one. I'd like to make a release
before I implement this. Work around I provided you is temporal.
You can continue to work, me too. After I implement the functionality
the only thing that you will have to do is delete few lines of code.
> Your other email where arg() doesn't need predefinition is equally a
> solution. BPL could lazily add in the type info later, but it would
> involve maintaining a list of where that type has been used in an
> arg() and retrospectively linking it in when the definition is made.
> I have a feeling that Dave won't want that extra complexity when you
> can just reorder the registrations.
I will explain my point in that thread.
> Cheers,
> Niall
>
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From roman.yakovenko at gmail.com Thu Feb 9 13:08:30 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 14:08:30 +0200
Subject: [C++-sig] registration order
In-Reply-To: <7465b6170602082223q49782950pcb6628169f53f783@mail.gmail.com>
References: <7465b6170602082223q49782950pcb6628169f53f783@mail.gmail.com>
Message-ID: <7465b6170602090408k40509840q11b67d75f1ce9ab5@mail.gmail.com>
Hi. I think that I should explain why I think that removing that ( see
previous mail ) requirement
is good.
This behaviour can surprise a developer. Think about this:
The developer created bindings for a library. After few month the
library has been in usage,
customers asks to add default argument to a function. Surprise:
instead of simple change in
one well defined place, developer should re-consider class registration order.
In big projects, with high level of dependencies between components it
could be a challenge.
Also, this requirement complicates a sorting algorithm within
pyplusplus. This is true.
But this is not a point, not at all.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From s_sourceforge at nedprod.com Thu Feb 9 13:09:21 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 12:09:21 -0000
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <7465b6170602082159v626da3dau7eed49bab1a409c8@mail.gmail.com>
References: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
Message-ID: <43EB30F1.32059.A3C0BD98@s_sourceforge.nedprod.com>
On 9 Feb 2006 at 7:59, Roman Yakovenko wrote:
> Solution for the problem:
> function_t and constructor_t code creators has property "use_keywords"
> This property is responcible for generation of keyword arguments. If you set
> it to False, then keyword arguments will not be generated.
>
> Here is relevant code:
>
> relevant_classes = (code_creators.function_t, code_creators.constructor_t )
> calldefs = filter( lambda creator: isinstance( creator, relevant_classes )
> , code_creators.make_flatten( extmodule.creators ) )
> for calldef in calldefs:
> calldef.use_keywords = False
>
> Your version of pyplusplus already has this functionality, but it has few bug.
> Please, use latest CVS version.
I updated to CVS, but the use_keywords property is already False by
default and furthermore, there is no code in _keywords_args() to test
the state of use_keywords and generate alternative code
appropriately.
Did you commit your changes to CVS?
Cheers,
Niall
From roman.yakovenko at gmail.com Thu Feb 9 13:18:43 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 9 Feb 2006 14:18:43 +0200
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <43EB30F1.32059.A3C0BD98@s_sourceforge.nedprod.com>
References: <43EA2981.10080.9FBBB3B2@s_sourceforge.nedprod.com>
<7465b6170602082159v626da3dau7eed49bab1a409c8@mail.gmail.com>
<43EB30F1.32059.A3C0BD98@s_sourceforge.nedprod.com>
Message-ID: <7465b6170602090418t7577dd4ftbb482f98517ef488@mail.gmail.com>
On 2/9/06, Niall Douglas wrote:
> On 9 Feb 2006 at 7:59, Roman Yakovenko wrote:
> I updated to CVS, but the use_keywords property is already False by
> default and furthermore, there is no code in _keywords_args() to test
> the state of use_keywords and generate alternative code
> appropriately.
>
> Did you commit your changes to CVS?
Yes I do. May be it takes some time?
Any way I attach relevant file. Please, place it to code_creators package.
> Cheers,
> Niall
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: calldef.py
Type: application/x-python
Size: 39813 bytes
Desc: not available
URL:
From s_sourceforge at nedprod.com Thu Feb 9 15:25:01 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 14:25:01 -0000
Subject: [C++-sig] Registration order in pyplusplus
In-Reply-To: <7465b6170602090418t7577dd4ftbb482f98517ef488@mail.gmail.com>
References: <43EB30F1.32059.A3C0BD98@s_sourceforge.nedprod.com>
Message-ID: <43EB50BD.27824.A43CF4F8@s_sourceforge.nedprod.com>
On 9 Feb 2006 at 14:18, Roman Yakovenko wrote:
> > Did you commit your changes to CVS?
>
> Yes I do. May be it takes some time?
> Any way I attach relevant file. Please, place it to code_creators package.
Obviously it takes time to propogate on sourceforge. God I hate CVS.
Bring on subversion!
You're still missing something - where currently it outputs:
FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL",
bp::init< FX::FXACL::EntityType, FX::FXACLEntity const & >()/*[
undefined call policies ]*/ );
... it should be:
FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL",
bp::init< bp::optional< FX::FXACL::EntityType, FX::FXACLEntity const
& > >()/*[ undefined call policies ]*/ );
... because otherwise you must always specify construction parameters
even when defaults are available.
I think this is a very easy fix.
Cheers,
Niall
From pedro.crespovalero at epfl.ch Thu Feb 9 14:55:16 2006
From: pedro.crespovalero at epfl.ch (Pedro Crespo Valero)
Date: Thu, 09 Feb 2006 14:55:16 +0100
Subject: [C++-sig] Problems when Building Boost.python with Borland compiler
Message-ID: <43EB49C4.4050109@epfl.ch>
Hello everybody,
I am a new user of boost.python. I followed the documentation but I can
not manage to get the boost.python library built .
Any help is greatly appreciated. Here below I show what I did:
- Windows 2000
- Compiler: Borland Bcc55 from Free C++BUILDER command line tools (
D:\PrgFiles\Borland\BCC55 )
- Boost version: boost_1_33_1 (D:\PrgFiles\boost_1_33_1)
-Evironment variables were set as:
PYTHON_ROOT=D:\PrgFiles\python24
PYTHON_VERSION=2.4
-Command line:
D:\PrgFiles\boost_1_33_1\libs\python\build>bjam "-sTOOLS=borland"
"-sBCCROOT=D:\PrgFiles\Borland\BCC55"
and the result is
**** skipping build of <@boost!libs!python!build>boost_python.dll;
toolset= borland variant= debug ****
**** skipping build of <@boost!libs!python!build>libboost_python.lib;
toolset= borland variant= debug ****
**** skipping build of <@boost!libs!python!build>boost_python.dll;
toolset= borland variant= debug ****
**** skipping build of <@boost!libs!python!build>boost_python.dll;
toolset= borland variant= release ****
**** skipping build of <@boost!libs!python!build>libboost_python.lib;
toolset= borland variant= debug ****
**** skipping build of <@boost!libs!python!build>libboost_python.lib;
toolset= borland variant= release ****
...found 8 targets...
THANK YOU VERY MUCH FOR YOUR ATTENTION!!!
From stiraspo at yahoo.com Thu Feb 9 15:59:23 2006
From: stiraspo at yahoo.com (Sergey Tiraspolsky)
Date: Thu, 9 Feb 2006 06:59:23 -0800 (PST)
Subject: [C++-sig] Problems Compiling in VS 2005
Message-ID: <20060209145923.42390.qmail@web60017.mail.yahoo.com>
I'm attempting to upgrade my solution to 2005 from 2003 and it compiles
fine until it gets to boost then I get errors. Here's the error:
Error 889 error C2665: 'boost::python::detail::make_getter' :
none of the 3 overloads could convert all the argument types
...\boost-1.32.0\include\boost\python\data_members.hpp 277
I thought it may be related to having an older version of Boost so I
upgraded to 1.33.1 and am still having the same error:
boost-1.33.1\include\boost\python\data_members.hpp(277) : error C2665:
'boost::python::detail::make_getter' : none of the 3 overloads could
convert all the argument types
Any ideas?
---------------------------------
Brings words and photos together (easily) with
PhotoMail - it's free and works with Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From baas at ira.uka.de Thu Feb 9 17:39:11 2006
From: baas at ira.uka.de (Matthias Baas)
Date: Thu, 09 Feb 2006 17:39:11 +0100
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To: <7465b6170602090345j7644b7a3w6e8bb6c7bc3e3e10@mail.gmail.com>
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com> <7465b6170602062141r12330e26w4770ed9d7ee0ce0c@mail.gmail.com> <7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com> <7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com> <7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
<7465b6170602090345j7644b7a3w6e8bb6c7bc3e3e10@mail.gmail.com>
Message-ID:
Roman Yakovenko wrote:
> First of all the bug has been fixed. You can check out only pygccxml package.
Thanks, this has led to another bunch of classes being wrapped
successfully...
>> And then, for some reason, pyplusplus doesn't see the correct name ("v")
>> of the argument and just calls it "arg0" in the bindings.
>
> There is nothing I can do. GCC-XML does not report argument name :-(.
> I have to find time and to submit few bugs to GCC-XML.
But the argument names are correct in my original code and do appear in
the generated bindings...? Do you know under what circumstances gccxml
drops the argument names?
Meanwhile I have a few cases where I need to reject some particular
class methods. For example, I have a class with methods of the following
kind:
class Foo
{
...
float& spam(int i);
float spam(int i) const;
...
};
The spam() method returns a float value that is stored inside the class.
For the Python bindings I'd like to ignore the first version that
returns the reference. What is the recommended way to do this?
Is there a convenience function that can easily check if a declaration
actually represents a method "float& Foo::spam(int)" or do I really have
to inspect every little detail myself (i.e. check if the name of the
declaration matches "spam", check if the parent declaration is a class
declaration called "Foo", check if it has one single argument of type
int, check if it has a return type of type float&, etc.)? I found the
function find_first_declaration() that looked closest to what I want to
accomplish when used with the 'fullname' argument. But this only takes
the class and the method name into account, but not the arguments and
return type.
Then I have two more questions:
- How do you add new methods to a (Python) class? In my case, I want to
wrap a class whose Python version should have an additional static
method (which I'd like to implement as a C++ function).
- Is there already a way to specify doc strings?
- Matthias -
From s_sourceforge at nedprod.com Thu Feb 9 18:28:02 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 17:28:02 -0000
Subject: [C++-sig] Static public variable definition not working
Message-ID: <43EB7BA2.26136.A4E483CF@s_sourceforge.nedprod.com>
In FXGLContext.pypp.cpp:
FXGLContext_exposer.def_readonly( "metaClass",
FX::FXGLContext::metaClass );
This throws an exception of:
exceptions.AttributeError, can't set attribute
This is caused by pyplusplus trying to expose the public static
variable:
static const FX::FXMetaClass metaClass;
As far as I can see pyplusplus is doing the right thing. It may be a
problem in BPL.
The offending line is in boost\libs\python\src\object\class.cpp in
BPL where class_base::setattr() calls PyObject_SetAttrString(). It's
simply failing with the above exception:
void class_base::setattr(char const* name, object const& x)
{
if (PyObject_SetAttrString(this->ptr(),
const_cast(name), x.ptr()) < 0)
throw_error_already_set();
}
Is it possible that because FXGLContext has a base of FXId that the
wrapper for FXId has already set "metaClass" to its own metaClass? If
so, BPL should be rewritten as follows:
void class_base::setattr(char const* name, object const& x)
{
if (PyObject_HasAttrString(this->ptr(),
const_cast(name))
{
if (PyObject_DelAttrString(this->ptr(),
const_cast(name), x.ptr()) < 0)
throw_error_already_set();
}
if (PyObject_SetAttrString(this->ptr(),
const_cast(name), x.ptr()) < 0)
throw_error_already_set();
}
In other words, if you set an attribute for a second time in BPL, you
overwrite the old one rather than generate an error.
Cheers,
Niall
From s_sourceforge at nedprod.com Thu Feb 9 18:30:34 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Thu, 09 Feb 2006 17:30:34 -0000
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170602090345j7644b7a3w6e8bb6c7bc3e3e10@mail.gmail.com>
Message-ID: <43EB7C3A.17680.A4E6D446@s_sourceforge.nedprod.com>
On 9 Feb 2006 at 17:39, Matthias Baas wrote:
> But the argument names are correct in my original code and do appear in
> the generated bindings...? Do you know under what circumstances gccxml
> drops the argument names?
This problem has been fixed in CVS gccxml - however, using that means
the assumptions of breakages in v0.6 are no longer valid - hence
pygccxml would need altering.
Cheers,
Niall
From dave at boost-consulting.com Thu Feb 9 19:49:52 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Thu, 09 Feb 2006 13:49:52 -0500
Subject: [C++-sig] Problems when Building Boost.python with Borland
compiler
References: <43EB49C4.4050109@epfl.ch>
Message-ID:
Pedro Crespo Valero writes:
> Hello everybody,
>
> I am a new user of boost.python. I followed the documentation but I can
> not manage to get the boost.python library built .
> Any help is greatly appreciated. Here below I show what I did:
>
> - Windows 2000
> - Compiler: Borland Bcc55 from Free C++BUILDER command line tools (
> D:\PrgFiles\Borland\BCC55 )
Boost.Python has never supported Borland. Borland is just too badly
broken.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From dave at boost-consulting.com Thu Feb 9 19:50:45 2006
From: dave at boost-consulting.com (David Abrahams)
Date: Thu, 09 Feb 2006 13:50:45 -0500
Subject: [C++-sig] Problems Compiling in VS 2005
References: <20060209145923.42390.qmail@web60017.mail.yahoo.com>
Message-ID:
Sergey Tiraspolsky writes:
> I'm attempting to upgrade my solution to 2005 from 2003 and it compiles
> fine until it gets to boost then I get errors. Here's the error:
> Error 889 error C2665: 'boost::python::detail::make_getter' :
> none of the 3 overloads could convert all the argument types
> ...\boost-1.32.0\include\boost\python\data_members.hpp 277
>
> I thought it may be related to having an older version of Boost so I
> upgraded to 1.33.1 and am still having the same error:
>
> boost-1.33.1\include\boost\python\data_members.hpp(277) : error C2665:
> 'boost::python::detail::make_getter' : none of the 3 overloads could
> convert all the argument types
>
> Any ideas?
Post a minimal, reproducible example, and we can try to debug it for
you.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
From nick at ilm.com Thu Feb 9 20:11:58 2006
From: nick at ilm.com (Nick Rasmussen)
Date: Thu, 09 Feb 2006 11:11:58 -0800
Subject: [C++-sig] CallPolicies postcall not being called when an
exception's raised?
Message-ID: <43EB93FE.5060801@ilm.com>
The docs at first glance seem to indicate that the postcall of a call
policy gets invoked even if an exception is raised:
------------------------------------------------------------------------
|x.postcall(a, r)
|convertible to |PyObject*
|
0 |0| and |PyErr_Occurred() != 0| upon failure. Must "conserve references"
even in the event of an exception. In other words, if |r| is not returned,
its reference count must be decremented; if another existing object is
returned, its reference count must be incremented.
------------------------------------------------------------------------
Which led me initially to believe that the call order looked something like:
precall();
handle_exception(invoke());
postcall();
Looking at the code, however, it seems like this is what's actually
happening is:
call() {
precall();
invoke();
postcall();
}
handle_exception(call());
Which in retrospect makes a lot of sense if you want to ensure you don't
propagate exceptions back into the interpreter :)
For better or worse, we have a mechanism that raises c++ exceptions from
floating point exceptions. We obviously don't want this mechanism active
inside the python interpreter, but would like to have it active when
certain functions are invoked. Although CallPolicies are designed to
deal with object ownership issues, it seemed like a place where we could
hook entry and exit of our functions to enable and disable this exception
generation, basically:
def("f",&f,with_fpe_exceptions_on());
But as the postcall of a policy is skipped if an exception is thrown, we're
potentially leaving the FPE->exception translation on. My question is:
Is there a better way to hook this?
If the CallPolicies mechanism is the right thing to use for this, should
there be an additional function called when an exception's raised?
call() {
precall();
try {
invoke();
catch(...) {
postcall_exception();
throw;
}
postcall();
}
handle_exception(call());
-nick
From benveal92 at hotmail.com Fri Feb 10 00:18:28 2006
From: benveal92 at hotmail.com (Ben Veal)
Date: Thu, 09 Feb 2006 23:18:28 +0000
Subject: [C++-sig] linking with non-python libraries
Message-ID:
>>Here is the relevant linking command that is produced by my makefile:
>>
>>g++ -o output.exe input.o -L. -s /usr/lib/libBaseClass.so -lpthread
>>
>>I notice that there is no -l preceeding '/usr/lib/libBaseClass.so' is this
>>important?
>
>Good question. Why don't you call
>
>g++ -o output.exe input.o -lBaseClass -lpthread
>
>instead as everybody else ? :-)
I am new to programming in Linux, and the makefile wasn't written by me.
Anyway it doesn't explain the linking problem, can anyone help me?
Thanks.
From s_sourceforge at nedprod.com Fri Feb 10 02:36:39 2006
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Fri, 10 Feb 2006 01:36:39 -0000
Subject: [C++-sig] CallPolicies postcall not being called when an
exception's raised?
In-Reply-To: <43EB93FE.5060801@ilm.com>
Message-ID: <43EBEE27.20447.A6A3DA9B@s_sourceforge.nedprod.com>
On 9 Feb 2006 at 11:11, Nick Rasmussen wrote:
> But as the postcall of a policy is skipped if an exception is thrown, we're
> potentially leaving the FPE->exception translation on. My question is:
>
> Is there a better way to hook this?
You may find the hacks done to BPL to support locking and unlocking
the python GIL around entrances and exits from Python at
http://svn.berlios.de/viewcvs/tnfox/trunk/Python/BoostPatches.zip?rev=
607&view=log useful. Just compare the files.
Cheers,
Niall
From rwgk at yahoo.com Fri Feb 10 05:34:03 2006
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Thu, 9 Feb 2006 20:34:03 -0800 (PST)
Subject: [C++-sig] Problems Compiling in VS 2005
In-Reply-To:
Message-ID: <20060210043403.45710.qmail@web31501.mail.mud.yahoo.com>
--- David Abrahams wrote:
> Sergey Tiraspolsky writes:
>
> > I'm attempting to upgrade my solution to 2005 from 2003 and it compiles
> > fine until it gets to boost then I get errors. Here's the error:
> > Error 889 error C2665: 'boost::python::detail::make_getter' :
> > none of the 3 overloads could convert all the argument types
> > ...\boost-1.32.0\include\boost\python\data_members.hpp 277
> >
> > I thought it may be related to having an older version of Boost so I
> > upgraded to 1.33.1 and am still having the same error:
> >
> > boost-1.33.1\include\boost\python\data_members.hpp(277) : error C2665:
> > 'boost::python::detail::make_getter' : none of the 3 overloads could
> > convert all the argument types
> >
> > Any ideas?
>
> Post a minimal, reproducible example, and we can try to debug it for
> you.
FWIW: I am using Boost.Python (very recent CVS) with VS 2005 Professional. I
know all boost/libs/python/tests work OK. We have 50+ extensions which also
work just fine.
Once you get past the compilation errors: you have to run the "manifest tool"
on the .pyd files. Example cl, link and mt commands are here (the page will
disappear some time in the future):
http://cci.lbl.gov/cctbx_build/results/2006_01_31_2306/win_xp_vc80_py242_build_log
Cheers,
Ralf
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
From rwgk at yahoo.com Fri Feb 10 05:45:27 2006
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Thu, 9 Feb 2006 20:45:27 -0800 (PST)
Subject: [C++-sig] segmentation fault in Boost.Python/Python C api
In-Reply-To:
Message-ID: <20060210044527.6116.qmail@web31508.mail.mud.yahoo.com>
Compile with -O0 -g, then run your application or script with valgrind
(http://valgrind.org/). Be sure to use the valgrind suppression file
Misc/valgrind-python.supp that comes with Python 2.4 or higher. There should be
0 valgrind errors, otherwise there are almost certainly bugs in your code. I
run valgrind 3.1.0 routinely on both 32-bit and 64-bit Linux and I know all of
Boost.Python is clean.
Cheers,
Ralf
--- Umang Jaipuria wrote:
> My application uses Boost.Python 1.33.1 and there was a segfault with a core
> dump. The stack trace follows.
> I'll grateful if anyone can point me in the right direction to figuring out
> what the problem is.
>
> Thanks,
> Umang Jaipuria
>
> #0 0x00c6d002 in free () from /lib/tls/libc.so.6
> #1 0x00da92de in PyObject_Free (p=0x5c30) at Objects/obmalloc.c:774
> #2 0x00da8d5d in PyMem_Free (p=0x0) at Objects/object.c:2111
> #3 0x0043b3a9 in boost::python::instance_holder::deallocate () from
> /usr/local/lib/libboost_python-gcc-mt-1_33_1.so.1.33.1
> #4 0x0043b412 in boost::python::instance_holder::deallocate () from
> /usr/local/lib/libboost_python-gcc-mt-1_33_1.so.1.33.1
> #5 0x00db44ff in subtype_dealloc (self=0xb746ff2c) at
> Objects/typeobject.c:703
> #6 0x00db25d1 in tupledealloc (op=0xb74659bc) at Objects/tupleobject.c:145
> #7 0x00ddd6a0 in eval_frame (f=0xa37737c) at Python/ceval.c:3652
> #8 0x00dde27b in PyEval_EvalCodeEx (co=0xb745f420, globals=0x4, locals=0x0,
> args=0x0, argcount=2, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
> at Python/ceval.c:2669
> #9 0x00d94458 in function_call (func=0xb7466294, arg=0xb7470eec, kw=0x0) at
> Objects/funcobject.c:504
> #10 0x00d7c0d7 in PyObject_Call (func=0x1, arg=0x0, kw=0x0) at
> Objects/abstract.c:1755
> #11 0x00dd7818 in PyEval_CallObjectWithKeywords (func=0x0, arg=0xb7470eec,
> kw=0x0) at Python/ceval.c:3352
> #12 0x00e004a9 in PyEval_CallFunction (obj=0x0, format=0x0) at
> Python/modsupport.c:477
> #13 0x0114f9bc in boost::python::call boost::reference_wrapper,
> boost::reference_wrapper > (callable=0x0, a0=@0x0,
> a1=@0x0) at handle.hpp:63
>
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
From pedro.crespovalero at epfl.ch Fri Feb 10 10:30:06 2006
From: pedro.crespovalero at epfl.ch (pedro)
Date: Fri, 10 Feb 2006 10:30:06 +0100
Subject: [C++-sig] Problems when Building Boost.python with
Borland compiler
In-Reply-To:
References: <43EB49C4.4050109@epfl.ch>
Message-ID: <43EC5D1E.5040009@epfl.ch>
David Abrahams a ?crit :
> Pedro Crespo Valero writes:
>
>
>> Hello everybody,
>>
>> I am a new user of boost.python. I followed the documentation but I can
>> not manage to get the boost.python library built .
>> Any help is greatly appreciated. Here below I show what I did:
>>
>> - Windows 2000
>> - Compiler: Borland Bcc55 from Free C++BUILDER command line tools (
>> D:\PrgFiles\Borland\BCC55 )
>>
>
> Boost.Python has never supported Borland. Borland is just too badly
> broken.
>
>
Thanks I really appreciate your help.
I will install then MinGW and try using gcc.
Kind regards,
Pedro.
From koen_van_herck at yahoo.com Fri Feb 10 13:11:14 2006
From: koen_van_herck at yahoo.com (Koen Van Herck)
Date: Fri, 10 Feb 2006 13:11:14 +0100
Subject: [C++-sig] Inheritance question
Message-ID:
Hello,
I want to expose the following classes in Python:
class Base
{
public:
virtual void f() = 0;
};
class Derived: public Base
{
public:
void f() { std::cout << "Derived::f" << std::endl; }
void g() { std::cout << "Derived::g" << std::endl; }
};
class User
{
public:
void useBase(Base & b) { b.f(); }
};
I've created the following code in my BOOST_PYTHON_MODULE
class_("User")
.def("useBase", &User::useBase)
;
class_("Derived")
.def("g", &Derived::g)
;
However, when I do in Python:
u = User()
d = Derived()
u.useBase(d)
I get an error:
u.useBase(d)
Boost.Python.ArgumentError: Python argument types in
User.useBase(User, Derived)
did not match C++ signature:
useBase(class User {lvalue}, class Base {lvalue})
I also tried to create a wrapper for Derived as follows:
class DerivedWrap: public Derived, public wrapper
{
};
and
class_("DerivedWrap")
.def("g", &Derived::g)
;
But then I get following error when calling d.g():
d.g()
Boost.Python.ArgumentError: Python argument types in
DerivedWrap.g(DerivedWrap)
did not match C++ signature:
g(class Derived {lvalue})
What is the proper way to expose Derived and User ?
Regards,
Koen Van Herck.
From seefeld at sympatico.ca Fri Feb 10 14:32:37 2006
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Fri, 10 Feb 2006 08:32:37 -0500
Subject: [C++-sig] Inheritance question
In-Reply-To:
References:
Message-ID: <43EC95F5.7010001@sympatico.ca>
Koen Van Herck wrote:
> Hello,
>
> I want to expose the following classes in Python:
>
> class Base
> {
> public:
> virtual void f() = 0;
> };
>
> class Derived: public Base
> {
> public:
> void f() { std::cout << "Derived::f" << std::endl; }
> void g() { std::cout << "Derived::g" << std::endl; }
> };
>
> class User
> {
> public:
> void useBase(Base & b) { b.f(); }
> };
>
> I've created the following code in my BOOST_PYTHON_MODULE
>
> class_("User")
> .def("useBase", &User::useBase)
> ;
>
> class_("Derived")
> .def("g", &Derived::g)
> ;
This should be class_ > ...
Regards,
Stefan
From koen_van_herck at yahoo.com Fri Feb 10 14:58:05 2006
From: koen_van_herck at yahoo.com (Koen Van Herck)
Date: Fri, 10 Feb 2006 14:58:05 +0100
Subject: [C++-sig] Inheritance question
In-Reply-To: <43EC95F5.7010001@sympatico.ca>
Message-ID:
Stefan Seefeld wrote:
>
> Koen Van Herck wrote:
> > Hello,
> >
> > I want to expose the following classes in Python:
> >
> > class Base
> > {
> > public:
> > virtual void f() = 0;
> > };
> >
> > class Derived: public Base
> > {
> > public:
> > void f() { std::cout << "Derived::f" << std::endl; }
> > void g() { std::cout << "Derived::g" << std::endl; }
> > };
> >
> > class User
> > {
> > public:
> > void useBase(Base & b) { b.f(); }
> > };
> >
> > I've created the following code in my BOOST_PYTHON_MODULE
> >
> > class_("User")
> > .def("useBase", &User::useBase)
> > ;
> >
> > class_("Derived")
> > .def("g", &Derived::g)
> > ;
>
> This should be class_ > ...
Doesn't work, because I have not exposed Base.
I do expose Base, using a BaseWrap class as follows:
class BaseWrap: public Base, public wrapper
{
public:
void f()
{
this->get_override("f")();
}
};
But this does not let me use bases. I get the following error when
importing my module:
RuntimeError: extension class wrapper for base class class Base has not been
created yet
From seefeld at sympatico.ca Fri Feb 10 15:47:53 2006
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Fri, 10 Feb 2006 09:47:53 -0500
Subject: [C++-sig] Inheritance question
In-Reply-To:
References:
Message-ID: <43ECA799.8020405@sympatico.ca>
Koen Van Herck wrote:
> Stefan Seefeld wrote:
>
>>Koen Van Herck wrote:
>>> class_("Derived")
>>> .def("g", &Derived::g)
>>> ;
>>
>>This should be class_ > ...
>
>
> Doesn't work, because I have not exposed Base.
Oh, sorry ! I hadn't realized that.
> I do expose Base, using a BaseWrap class as follows:
>
> class BaseWrap: public Base, public wrapper
> {
> public:
> void f()
> {
> this->get_override("f")();
> }
> };
I'm not sure what you mean by 'expose', but you certainly didn't
expose it to python that way. If you want to be able to dispatch
to methods expecting a 'Base' from within python, python has to know
the 'Base' type. Alternatively, you can write a little wrapper
function with the right signature that downcasts for you:
void useBase(User & u, Derived & d) { u.useBase(d); }
and then use that instead of the member pointer:
class_ user("User");
user.def("useBase", useBase);
HTH,
Stefan
From koen_van_herck at yahoo.com Fri Feb 10 16:46:24 2006
From: koen_van_herck at yahoo.com (Koen Van Herck)
Date: Fri, 10 Feb 2006 16:46:24 +0100
Subject: [C++-sig] Inheritance question
In-Reply-To: <43ECA799.8020405@sympatico.ca>
Message-ID:
Stefan Seefeld wrote:
>
> Koen Van Herck wrote:
> > Stefan Seefeld wrote:
> >
> >>Koen Van Herck wrote:
>
> >>> class_("Derived")
> >>> .def("g", &Derived::g)
> >>> ;
> >>
> >>This should be class_ > ...
> >
> >
> > Doesn't work, because I have not exposed Base.
>
> Oh, sorry ! I hadn't realized that.
>
> > I do expose Base, using a BaseWrap class as follows:
> >
> > class BaseWrap: public Base, public wrapper
> > {
> > public:
> > void f()
> > {
> > this->get_override("f")();
> > }
> > };
>
> I'm not sure what you mean by 'expose', but you certainly didn't
> expose it to python that way. If you want to be able to dispatch
> to methods expecting a 'Base' from within python, python has to know
> the 'Base' type. Alternatively, you can write a little wrapper
> function with the right signature that downcasts for you:
With 'expose' I meant using the class from Python. I didn't show the module
definition,
which follows Boost.Python's tutorial for virtual functions:
BOOST_PYTHON_MODULE(inheritance)
{
class_("Base")
.def("f", pure_virtual(&Base::f))
;
class_("User")
.def("useBase", &User::useBase)
;
}
This allows me to write following Python code:
class PyDerived(inheritance.Base):
def f(self):
print 'PyDerived.f'
u = inheritance.User()
d = PyDerived()
u.useBase(d)
and this works fine.
I was looking for a way to do
u = inheritance.User()
d = inheritance.Derived()
u.useBase(d)
with inheritance.Derived() being the C++ Derived class (or some wrapper of
it).
>
> void useBase(User & u, Derived & d) { u.useBase(d); }
>
> and then use that instead of the member pointer:
>
> class_ user("User");
> user.def("useBase", useBase);
I'll try this.
How should I use this if I have more than one Derived? Like this:
void useBase1(User & u, Derived1 & d) { u.useBase(d); }
void useBase2(User & u, Derived2 & d) { u.useBase(d); }
user.def("useBase", useBase1);
user.def("useBase", useBase2);
>
> HTH,
> Stefan
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
From seefeld at sympatico.ca Fri Feb 10 17:01:12 2006
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Fri, 10 Feb 2006 11:01:12 -0500
Subject: [C++-sig] Inheritance question
In-Reply-To:
References:
Message-ID: <43ECB8C8.9060607@sympatico.ca>
Koen Van Herck wrote:
> With 'expose' I meant using the class from Python. I didn't show the module
> definition,
> which follows Boost.Python's tutorial for virtual functions:
>
> BOOST_PYTHON_MODULE(inheritance)
> {
> class_("Base")
> .def("f", pure_virtual(&Base::f))
> ;
Ok, you expose 'BaseWrap', not 'Base'. I think you should still be able
to expose 'Derived' with 'bases' without problems. See
boost/libs/python/test/polymorphism2.cpp for where this is used / tested.
Regards,
Stefan
From roman.yakovenko at gmail.com Fri Feb 10 17:53:01 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Fri, 10 Feb 2006 20:53:01 +0400
Subject: [C++-sig] pyplusplus tutorials & GUI wizard
In-Reply-To:
References: <7465b6170601232249u7ca7741ncf71a6973fc12c45@mail.gmail.com>
<7465b6170602070223scc61a4m3cb12484dddcb5de@mail.gmail.com>
<7465b6170602072249j274d4d39s6e80eef7823ba6bf@mail.gmail.com>
<7465b6170602082310j79f663a0i54a6e1a0ee7354e5@mail.gmail.com>
<7465b6170602090345j7644b7a3w6e8bb6c7bc3e3e10@mail.gmail.com>
Message-ID: <7465b6170602100853l72f56e05s517356117b1918d4@mail.gmail.com>
On 2/9/06, Matthias Baas wrote:
> But the argument names are correct in my original code and do appear in
> the generated bindings...? Do you know under what circumstances gccxml
> drops the argument names?
No, I don't. In an other post in this thread Niall writes, that this
problem has been fixed
in CVS version of GCC-XML. You can try it. pygccxml works well with
CVS version of GCC-XML. On Linux I running GCC-XML CVS + gcc 4.1
> Meanwhile I have a few cases where I need to reject some particular
> class methods. For example, I have a class with methods of the following
> kind:
>
> class Foo
> {
> ...
> float& spam(int i);
> float spam(int i) const;
> ...
> };
>
> The spam() method returns a float value that is stored inside the class.
> For the Python bindings I'd like to ignore the first version that
> returns the reference. What is the recommended way to do this?
pygccxml.declarations package has type traits. Their functionality is
very similar to
boost.type_traits.
#f is declaration of function spam
if pygccxml.declarations.is_reference( f.return_type ):
if pygccxml.declarations.is_floating_point( f.return_type.base ):
pass#do your things
Take a look on pygccxml type traits. It worth it.
> Is there a convenience function that can easily check if a declaration
> actually represents a method "float& Foo::spam(int)" or do I really have
> to inspect every little detail myself (i.e. check if the name of the
> declaration matches "spam", check if the parent declaration is a class
> declaration called "Foo", check if it has one single argument of type
> int, check if it has a return type of type float&, etc.)? I found the
> function find_first_declaration() that looked closest to what I want to
> accomplish when used with the 'fullname' argument. But this only takes
> the class and the method name into account, but not the arguments and
> return type.
There is no such convenience method :-(. But you don't have to check
every little detail.
For example all member function declarations derived from
member_function_t class.
I think that in your case you will need to right your own match
method. I thought
to add an other set of find_* functions that will take as argument
some callable
object. But it will take some time.
> Then I have two more questions:
>
> - How do you add new methods to a (Python) class? In my case, I want to
> wrap a class whose Python version should have an additional static
> method (which I'd like to implement as a C++ function).
Best way is to use custom_text_t code creator. Just put it somewhere
within relevant code creator. Take a look on boost.date_time
pyplusplus example. I use it there.
> - Is there already a way to specify doc strings?
No, but I do plan to add such functionality in future.
>
> - Matthias -
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
From koen_van_herck at yahoo.com Fri Feb 10 17:47:16 2006
From: koen_van_herck at yahoo.com (Koen Van Herck)
Date: Fri, 10 Feb 2006 17:47:16 +0100
Subject: [C++-sig] Inheritance question
In-Reply-To: <43ECB8C8.9060607@sympatico.ca>
Message-ID:
OK, it works now, if I expose User, BaseWrap and Derived and use
bases