Do python support pointers

Martin von Loewis loewis at informatik.hu-berlin.de
Thu May 24 12:27:46 EDT 2001


"Sameer Kshatriya" <sameerk at ruksun.com> writes:

> I have a problem is accessing a pointer variable.I have a dll, that
> iam loading in Python,one of its exported function returns a pointer
> to an interface using which iam suppose to call certain
> functions. Now iam not able to make call to functions using the
> pointer returned by the exported finction. How can i do this.

You need to create a Python wrapper object for the pointer. Suppose
the function returning the point is "foo", and the interface
operations are "bar" and "foobar". Then you'd do

PyObject *foo(...){
 ...
 return IWrapper_New(pointervalue);
}

PyObject*
IWrapper_bar(IWrapper* wr, PyObject*args){
  ... get args ...
  res = wr->wrapped_interface->bar(arguments);
  ... return result
}

PyObject*
IWrapper_foobar(IWrapper* wr, PyObject*args){
  ... get args ...
  res = wr->wrapped_interface->foobar(arguments);
  ... return result
}

>From Python, you'd then do

interface = mymod.foo(args)
interface.bar(other args)

Please see the xxmodule.c source for an example of creating new types
in Python. If you need to create many different wrapper objects, you
may consider using SWIG.

Regards,
Martin



More information about the Python-list mailing list