function pointer

Andrew H. Chatham andrew.spambgone.chatham at duke.edu
Tue Dec 12 03:43:52 CET 2000


You could use a CObject, which is what I've done before, though it has
limitations. A CObject is really just a Python object that holds a C pointer.
See http://python.org/doc/current/api/cObjects.html . Of course, doing it this
way, you'd have to already know what kind of arguments and return values the
function takes and there's also the possibility that someone could pass a bad
pointer if they had a CObject from another module, since you cast it to a "void
*" to store and retrieve it from the CObject. So if you already know what kind
of function it will be a pointer to and don't expect people to go out of their
way to break your module, a CObject would be a good choice.

Andrew

On Mon, 11 Dec 2000 17:51:01 -0800, Curtis Jensen <cjensen at bioeng.ucsd.edu>
wrote:
>Is there a way to pass a pointer to a function from a module in a shared
>library?  e.g. We have a compiled C module that has the function "foo" in it
>(foo is not wrapped, it's straight C code).  We have another copiled C module.
>We want "foo" to be passed in to a function in the second module as a
>paramater.  Is this possible?  Hope this makes sence.
>
>-- Curtis Jensen cjensen at bioeng.ucsd.edu http://www-bioeng.ucsd.edu/~cjensen/
>FAX (425) 740-1451


-- 
Andrew Chatham
Duke University '02
andrew.chatham at duke.edu



More information about the Python-list mailing list