Thomas Heller <thel...@ctypes.org> added the comment: There is a problem returning arbitrary complicated ctypes types from callbacks. Consider that a callback function returns a structure; the structure itself may contain 'char *' field for example. The callback function creates the structure and fills in the fields. The 'char *' field contains a pointer to a nul-terminated string; the ctypes structure object must keep the Python string alive as long as the structure itself. It does this via the private '_objects' instance variable. If the callback function now returns the structure, the Python ctypes object usually will go out of scope and will be garbage collected, together with its '_objects'. So, the pointer(s) contained in the structure will become invalid now, and even simple structure fields will become invalid.
However, the callback function result will be used by some other code and will surely crash. In principle it should be possible to make code like this work; one would have to maintain the returned objects elsewhere and clean them up when they are no longer used anywhere; but I think this gets too complicated. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5710> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com