[Pyrex] creating and populating Python/C structs

Christopher Armstrong radeex at gmail.com
Sun Sep 4 06:58:58 CEST 2005


Hi all,

I'm trying to write a small function to create Python Frame objects
from Python code. I've been having problems getting everything
working. I can get pyrex to compile to C well enough, but gcc is
barfing on compiling the C. I've been reading through the available
documentation, but haven't found anything enlightening. It seems
dealing with Python/C API *objects* (as opposed to functions) isn't
something that's done often?

Basically, I'm doing a cdef extern from *: and then declaring the
PyFrameObject struct like so:

    # Just defining the members that we need to manipulate
    struct _frame:
        _frame *f_back
        PyCodeObject *f_code
        PyObject *f_builtins
        PyObject *f_globals
        PyObject *f_locals
        PyObject *f_exc_type, *f_exc_value, *f_exc_traceback
        int f_lineno
    ctypedef _frame PyFrameObject

later, in a newframe function, I'm doing this to create the new frame object:

    cdef PyFrameObject *frame

When I try to compile the resulting C code, I get the following error:

_tbconstruct.c: In function `__pyx_f_12_tbconstruct_newframe':
_tbconstruct.c:57: error: `__pyx_v_frame' undeclared (first use in
this function)


I've attached the code (it's very short). I'm compiling it with 
    pyrexc _tbconstruct.pyx; gcc -c -fPIC -I/usr/include/python2.4
_tbconstruct.c


Thanks for any help.
-- 
  Twisted   |  Christopher Armstrong: International Man of Twistery
   Radix    |    -- http://radix.twistedmatrix.com
            |  Release Manager, Twisted Project
  \\\V///   |    -- http://twistedmatrix.com
   |o O|    |  
w----v----w-+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: _tbconstruct.pyx
Type: application/octet-stream
Size: 1107 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20050904/56b3bfc8/_tbconstruct.obj


More information about the Pyrex mailing list