PyCObject subtype PyObject

Benjamin Tai bt98 at doc.ic.ac.uk
Mon Jun 10 06:47:11 EDT 2002


Michael Hudson wrote:

> > 2) For function "PyCObject_FromVoidPtr()", it takes in a "void*" as the
> > first argument.
> > For function "PyCObject_AsVoidPtr()", it returns a "void*".
> > When implementing Python extension, what is the potential danger of
> > casting pointers, of different size, to and from "void*"?
>
> Doesn't C guarantee that you can cast a pointer of type (T*) to
> (void*) and back again for all T?  I was fairly sure it did.
>

I am extending a C++ application with Python. Before attempting other
possibilities, like Boost, I just want to document the work I have done so
far.

Simply speaking I am hiding a C++ pointer, as a PyCObject*, inside a Python
instance.

The scheme works OK. The C++ class hierarchy is reflected by Python classes.
The pair of C++ and Python object is passed around between the two
languages.



> > 4) Apart from exporting function between modules, are there any
> > examples of using PyCObject?
>

The example, in the Python/C API document, is talking about exporting
functions between Python modules. So I am wondering if my method is valid?



Thanks for your feedback.

Ben




More information about the Python-list mailing list