After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 699356 - None from python non seen as NULL in c code
None from python non seen as NULL in c code
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 699435
 
 
Reported: 2013-04-30 21:54 UTC by Emmanuel Pacaud
Modified: 2013-09-26 02:06 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Emmanuel Pacaud 2013-04-30 21:54:42 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 ?
Comment 1 Simon Feltman 2013-05-01 02:33:10 UTC
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.
Comment 2 Emmanuel Pacaud 2013-05-01 11:55:15 UTC
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.
Comment 3 Simon Feltman 2013-05-02 01:51:01 UTC
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.
Comment 4 Simon Feltman 2013-09-26 02:06:06 UTC
This was fixed along with the commit for bug 688081.