GNOME Bugzilla – Bug 699356
None from python non seen as NULL in c code
Last modified: 2013-09-26 02:06:06 UTC
Hi. I have the following declaration in my code: /** * arv_buffer_new: * @size: payload size * @preallocated: (allow-none) (transfer none): preallocated memory buffer * * Creates a new buffer for the storage of the video stream images. * The data space can be either preallocated, and the caller is responsible * for it's deallocation, or allocated by this function. If it is the case, * data memory will be freed when the buffer is destroyed. * * Returns: a new #ArvBuffer object * * Since: 0.2.0 */ ArvBuffer * arv_buffer_new (size_t size, void *preallocated) {... } If I use this function from python: buffer_a = Aravis.Buffer.new (1024, None) I get some crash, because preallocated is not seen as NULL in the c code. Is there something wrong with my code ?
Moving to PyGObject. This may even be considered a dup of bug 688081, but I think specifically converting None to NULL would be a good first step. Patches welcome. You can also expose a more introspection friendly version which does not take the arg and uses a "Rename to:" annotation to mask the less friendly version.
Thanks Simon for the workaround suggestion. There's something I don't get, though. How do the other library for handling optional parameters (allow-none) ? It's a pretty common feature.
This problem is specific to void pointers which don't have a known convention with GI. Typed pointers will allow None as NULL and the cases where methods take void pointers usually have a well known convention which is explicitly described by GI (callback user_data for example). This is the first time I've seen this particular problem but there are many related problems.
This was fixed along with the commit for bug 688081.