[Pyrex] simple and direct wrapping of structures

Phil Frost indigo at bitglue.com
Sat Jun 19 05:37:58 CEST 2004


I have a C structure, and I'd like to write a coresponding Python type
that wraps it. Previously I have done so by something like:

cdef class Wrapper:
  cdef wrapped_struct *w
  # methods to indirectly manipulate the wrapped structure

This has worked quite well so far as most structures in the C api I am
wrapping have C methods to manipulate them. However, I now have a rather
large structure where the intended use in C is:

typedef struct {
  // imagine many members here
} wrap_me;

wrap_me w;
get_structure( &w );
// manipulate w's members directly here
save_structure( &w );

While I could again define an extension type to manipulate it indirectly
as I have done previously, I'm wondering if there's a simpler way to
make an extension type who's methods manipulate directly the C
structure's members, without the need to write accessor functions for
each member. Is there a better way?




More information about the Pyrex mailing list