[ctypes-users] Function pointers as arguments or structure members
by Daniele Varrazzo other posts by this author
Nov 19 2006 10:38AM messages near this date
Re: [ctypes-users] Since I don't seem to be getting time to do the rest of the work any time soon
|
Re: [ctypes-users] Function pointers as arguments or structure members
Hello,
i am trying (mostly successfully, thank you! :D) to wrap the
SpiderMonkey library (http://www.mozilla.org/js/spidermonkey/) into
Python using ctypes. The wrapper has been built using the ctypeslib
CodeGenerator.
I have to set up a structure, basically a vtable, so i have to fill a
structure members with function pointers. These function are provided by
the library itself, i don't have to setup Python callbacks here.
The structure defined like:
struct JSClass {
const char *name;
uint32 flags;
JSPropertyOp addProperty;
JSPropertyOp delProperty;
... and so on...
}
I have to do the C equivalent of:
JSClass global_class = {
"global",0,
JS_PropertyStub,JS_PropertyStub,
... etc
};
Up to now, the only way i managed to make it work is:
global_class = JSClass('global', 0,
JSPropertyOp(JS_PropertyStub),
JSPropertyOp(JS_PropertyStub),
...
while the most obvious solution (directly passing JS_PropertyStub to the
Python wrapped structure) leads to a TypeError (incompatible types,
_FuncPtr instance instead of CFunctionType instance).
Even if the above solution works, i am concerned that, when C code will
access this vtable, it will call a Python function which in turn will
call the desired function, resulting in an extra Python roundtrip for
each call where only C code should have been involved.
Is it true? If so, how can i pass a pointer to a C function without such
double wrapping?
Thanks in advance,
Daniele
P.S. what is the best place to report a bug in the CodeGenerator?
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
ctypes-users mailing list
ctypes-users@[...].net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Thread:
Daniele Varrazzo
Thomas Heller
|