[C++-sig] Boost-python/pybindgen and wrapping member variables

Ben Fitzpatrick bfitzpatrick at vtiinstruments.com
Thu Jan 21 14:43:17 CET 2010


Interesting, I changed it to the format you suggest and it seems to work. However, I changed it back to this way:
global_annotations = {‘return_internal_reference’:’true’}

and it stopped working. I confirmed there was nothing in there before I added my annotation, so that seems strange to me. On the other hand, your solution works, so I’ll just use that.

Thanks again,
Ben


From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org [mailto:cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org] On Behalf Of Gustavo Carneiro
Sent: Wednesday, January 20, 2010 6:29 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Boost-python/pybindgen and wrapping member variables


On Wed, Jan 20, 2010 at 7:26 PM, Ben Fitzpatrick <bfitzpatrick at vtiinstruments.com<mailto:bfitzpatrick at vtiinstruments.com>> wrote:
Gustavo,

I think you win some sort of prize for not only fastest mailing list responses, but also fastest implementation of features. I reviewed the diff, and changed what I was adding to the global annotations table for these pointers to “{‘return_internal_reference’:’true’}” – this seems to be what the new code in foo.h was doing.  I am still getting the errors, though – is this the right way of using it?
I am not sure what is wrong.  Assuming you are using a "pre_scan_hook", and that you are doing something like global_annotations[‘return_internal_reference’] = True, in the proper attribute definition, then it should work.  Is it the same error message, or a different error?


And just to make sure, I grabbed a new checkout of pybindgen and re-installed it.

From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com<http://vtiinstruments.com>@python.org<http://python.org> [mailto:cplusplus-sig-bounces+bfitzpatrick<mailto:cplusplus-sig-bounces%2Bbfitzpatrick>=vtiinstruments.com<http://vtiinstruments.com>@python.org<http://python.org>] On Behalf Of Gustavo Carneiro
Sent: Wednesday, January 20, 2010 1:18 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Boost-python/pybindgen and wrapping member variables


On Wed, Jan 20, 2010 at 5:43 PM, Ben Fitzpatrick <bfitzpatrick at vtiinstruments.com<mailto:bfitzpatrick at vtiinstruments.com>> wrote:
Hi everyone,

I think I’m finally getting the hang of this, I seem to have gotten almost everything in my project working thanks to Gustavo’s latest pybindgen patch. One of the remaining things I am having difficulty with is putting annotations on member variables of a class. I have something of the form:

class foo{
 <stuff>
};

class baz {
  public:
  foo* var;
}

The error I am getting from pybindgen is “WrapperWarning: Return value ‘::foo *’ error (used in baz::var [variable]): TypeConfigurationError(‘Either caller_owns_return or self.reference_existing_object must be given’)

 I know that the issue is that I need to stick an annotation on there. Since the pointer is allocated and tracked by the underlying C++ code, I’m pretty sure that I need to put reference_existing_object on it. I’ve tried inserting “{‘reference_existing_object’ : ‘true’}” into the global_annotations table, and also inserting it into the parameter_annotations[“return”] dictionary. For kicks, I even tried both at once. No matter what I do I can’t get rid of the error, or see it show up in my final build, which leads me to believe there’s something I’m missing. I went and looked up the documentation for reference_existing_object, but of course none of their examples show how you could use it on a member variable. What am I missing?
You are not missing anything.  Annotations for member variables (pybindgen calls them "instance attributes") were not implemented.

An oversight easily fixed:

http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/742


Thanks,
Ben Fitzpatrick

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org<mailto:Cplusplus-sig at python.org>
http://mail.python.org/mailman/listinfo/cplusplus-sig



--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org<mailto:Cplusplus-sig at python.org>
http://mail.python.org/mailman/listinfo/cplusplus-sig



--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100121/9555a679/attachment-0001.htm>


More information about the Cplusplus-sig mailing list