You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When wrapping a function pointer inside a structure, there is not corresponding
CFUNCTYPE prototype type provided so we can initialize the prototype. Like
struct ui_interface {
void (*post_warning)(const char *title,const char *statement,...);
char *(*open_file)(const char *title, const char *defaultfile,
const char *initial_filter);
}
ctypesgen correctly defined the types for post_warning and open_file as
functype like:
struct_ui_interface._fields_ = [
('post_warning', CFUNCTYPE(UNCHECKED(None), String, String)),
('open_file', CFUNCTYPE(UNCHECKED(String), String, String, String)),
]
But it should provide struct_ui_interface_post_warning_func and
struct_ui_interface_open_file_func so that we can create the CFUNCTYPE object
easily.
struct_ui_interface_post_warning_func = CFUNCTYPE(UNCHECKED(None), String,
String))
struct_ui_interface_open_file_func = CFUNCTYPE(UNCHECKED(String), String,
String, String))
Original issue reported on code.google.com by mozbug...@gmail.com on 21 May 2011 at 12:42
The text was updated successfully, but these errors were encountered:
If I understood this correctly, I'm facing the same in my project. This is my current solution:
defset_callback(struct, fname, callback):
# hack to extract CFUNCTYPE definition and wrap callbacksetattr(struct, fname, type(getattr(struct, fname))(callback))
Example usage:
# `_buffer_writer` is a callable factory, and `buffer` an io.BufferedReader or similarwriter=pdfium_c.FPDF_FILEWRITE(version=1)
set_callback(writer, "WriteBlock", _buffer_writer(buffer))
It's none too nice this is left to the caller. Ideally, assigning a function to a field should just do the CFUNCTYPE wrapping automatically, if that were possible to implement in ctypes/python.
I don't think such templates belong in ctypesgen, though. Maybe rather in a separate ctypes-extensions package or something, if need be. But overall standalone ctypes is fairly complete these days.
Original issue reported on code.google.com by
mozbug...@gmail.com
on 21 May 2011 at 12:42The text was updated successfully, but these errors were encountered: