[C++-sig] Exposing C Array members to python using boost

Carpman, David dcarpman at ll.mit.edu
Fri Dec 28 19:02:46 CET 2007


> -----Original Message-----
> Message: 2
> Date: Sat, 22 Dec 2007 00:00:09 +0200
> From: "Roman Yakovenko"
> Subject: Re: [C++-sig] Exposing C Array members to python using boost
> To: "Development of Python/C++ integration" <c++-sig at python.org>
> Message-ID:
>         <7465b6170712211400p429b0abdg232e24692b407e06 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Dec 20, 2007 1:41 AM, Carpman, David wrote:
> > Here is my situation: I'm trying to wrap some legacy C-structures that
> define a network packet structure that will be written by python and read
> by some embedded computer. I have no control over the definition of these
> structures, nor can I add to or change the header files. My hang-up is
> that some of the members in these structures are defined as C-arrays, for
> example, int numsamples[32]. I would like to have access in python to the
> elements of these arrays for reading and writing. Scalar primitive members
> work fine.
>
> > I would like to avoid having to write C++ wrapper classes for the C-
> structs containing the C-arrays, as there are many dozens of them.
> > I'd be very thankful if someone could help!
>
> Take a look on next code:
>
> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusp
> lus/code_repository/array_1.py?revision=1097&view=markup
>
> search for register_array_1 function.
>
> You can also to try
> Py++(http://language-binding.net/pyplusplus/pyplusplus.html), code
> generator for Boost.Python library, it handles such cases
> automatically.
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
>

Thanks very much for the reply, Roman. I tried Py++ and it indeed automatically handles the case I outlined above concerning C-array members, and with much less tedious writing of registration code. I also found it convenient to use to insert some other C++ code for each of my structures that normally I wrote by hand. The API docs and examples on your webpage were very helpful.

Warm regards,

David Carpman



More information about the Cplusplus-sig mailing list