Is there an extension library?

Letbetter, Jason letbetter at ti.com
Fri Sep 26 09:21:51 EDT 2003


I'm creating Python extensions for several c/c++ components.    I'm using
swig to create the extensions.  The biggest challenge so far is working with
the c args between Python and the Python extension.  Is there a 3rd party
library of extension helpers that assist in representing c-types between
Python and c?  Are there any tips and tricks?

Here are some specific scenarios I am running into.

1) Refrencing and derefrencing:
For example, condsider this c api:

void foo_alloc(void** handle_ptr);
void foo_use(void* handle);

In c &handle.  How to get pointer to pointer in Python?
In c *handle_ptr.  How to derefrence a pointer in Python?


2) Coercion:
For example, suppose you want to initialize a char array in Python.

buf = CharArray(100)
for i in range(100):
   buf[i] = i

The above results in:
"TypeError: CharArray___setitem__() argument 3 must be char, not int"
In c, buf[i] = (char)i, is implicit.  How do I do it in Python.  Why doesn't
Python make this conversion implicitly?


3) It seems like I'm doing something unatural with my Python extension.  It
seems someone else may have already figured out the best way to transform c
arguments between Python and Python extensions genericly.

Thanks,
Jason

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030926/87654c8d/attachment.html>


More information about the Python-list mailing list