Need help with C extension module

chris chris.stromberger at gmail.com
Thu Sep 8 12:42:57 EDT 2005


Ok, I found further examples on the Internet and got something working
(it seems), but I have a question about the memory management.  The
example I found did not include any of the PyMem_... functions.

Here's roughly what I have working:

cdef extern from "my.h":
  cdef struct inputs:
    char   *x

  cdef struct outputs:
      int     y

  outputs *func(inputs *x, outputs *y)
  int init(char* fname)

class Analyzer:
  def __init__(self, fname):
    init(fname)

  # inp is my python "Inputs" object.
  def myfunc(self, inp):
    cdef inputs* i
    i.x= inp.x

    cdef outputs* o
    o = func(i, o)
    return o.y

class Inputs:
  def __init__(self):
    self.x = ""

So there is no explicit memory management going on there as in Robert's
example.  Is this ok?  

Thanks,
Chris




More information about the Python-list mailing list