Good method for storing C pointer?
gmcm at hypernet.com
Mon Mar 6 15:15:55 CET 2000
Grant Munsey writes:
> I have several kinds of 'cookies' that need to be
> passed back into Python which will then be
> given as parameters to Python covers for low level
> 'C' calls. An example would be Windows HWND
> Currently I define a new type for each of these cookies
> so that I can do good parameter checking. Problem
> is that some of the cookie types are used by multiple
> modules ... which might or might not be loaded in a
> particular app.
> As I understand it you can't create a type multiple times
> because you'll end up with multiple addresses for the
> low level type structure ... and type compares will
> So right now I have a separate module that defines all
> the shared types. I don't like this ... would rather
> the first module that needs a type define it and then
> post the type structure address somewhere that other
> modules can get at.
> Anyone have a clean way to do this?
You could use a CObject to pass an opaque pointer around.
But why not leave it in a separate module and just import it
into the other extensions (using PyImport_Import)?
More information about the Python-list