PyCObject subtype PyObject

Michael Hudson mwh at python.net
Mon Jun 10 15:25:45 CEST 2002


Benjamin Tai <bt98 at doc.ic.ac.uk> writes:

> 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.

Oh, that makes sense.  Hmm, you're probably going to be OK but I doubt
you get a standard-backed guarantee any more.

> > > 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?

I think so.

Cheers,
M.

-- 
  I'm a keen cyclist and I stop at red lights.  Those who don't need
  hitting with a great big slapping machine.
                                           -- Colin Davidson, cam.misc



More information about the Python-list mailing list