[Pyrex] Cannot cdef __init__?

Andrew Bennetts andrew-pyrex at puzzling.org
Mon Jan 19 01:03:12 CET 2004


On Sun, Jan 18, 2004 at 03:25:13PM -0800, Paul Prescod wrote:
> Andrew Bennetts wrote:
> 
> >...
> >
> >After all these examples, you've shown me how to do almost everything 
> >except
> >exactly what I want!  :)
> 
> You're shifting what you want. ;)

Yeah, I know.  Sorry about that; I'm new enough to this that I'm still
struggling a little to express myself concisely but precisely.  You've been
very helpful despite that :)

> In the very first example you were doing mallocs and frees which 
> indicated to me that your library does NOT create these objects for you. 
> You were also hand-initializing each struct field, rather than using an 
> external module to do the initialization. So now I need to know what you 
> really, really want. ;) How much does the external library do 
> (allocation? initialization?) and how much do you want Pyrex to do?
> If the library does does it expect a pointer to a pointer that it will 
> mutate or does it return a pointer? And how are the objects documented 
> to be freed? (many libraries have matching allocate/deallocate pairs so 
> that they can do cleanup beyond what "free" does).

Okay, here's what I understand about it (I'm new to the library I'm working
with here, so that doesn't help either!).

In at least some places there are functions of the form:

    bool_t foo_create_something(..., **FooThing, ...);

(where bool_t indicates success or failure; in the case of failure, I need
to do foo_check_error to find out what went wrong).

These can be fairly involved functions that take several structures as
arguments.  My hand-initialising of trivial structures in previous examples
was misleading; I was trying to boil the problem down to a simple
self-contained example.

The structs this library defines typically have functions associated with
them like:

    foo_ref(*FooThing);   /* increment ref count */
    foo_unref(*FooThing); /* decrement ref count */

So while I don't do malloc/free myself, the library does on the basis of the
refcounts of the objects.  I expect I need to call these in the
__new__/__dealloc__ (or __init__/__del__?) of my objects that wrap them.

There may be some structs that I do manage the allocation/deallocation of
myself; but thanks to you I now know how to handle that :)

Finally, I'm really just experimenting here.  I don't know either Pyrex or
this library well enough yet to be really confident that what I'm doing is
the best way -- but I'm learning rapidly!

Thanks again for your help,

-Andrew.





More information about the Pyrex mailing list