GNOME Bugzilla – Bug 660056
g_value_set_instance needs a type annotation for its gpointer parameter
Last modified: 2015-02-07 16:52:18 UTC
I want to call a function passing NULL for gpointer argument, but python None is not converted to NULL, it stays Py_None instead (which is &_Py_NoneStruct, not NULL). It can be shown on simple function like g_value_set_intance, which is described in .gir as follows: <method name="set_instance" c:identifier="g_value_set_instance"> <doc xml:whitespace="preserve">Sets @value from an instantiatable type via the value_table's collect_value() function.</doc> <return-value transfer-ownership="none"> <type name="none" c:type="void"/> </return-value> <parameters> <parameter name="instance" transfer-ownership="none" allow-none="1"> <doc xml:whitespace="preserve">the instance</doc> <type name="gpointer" c:type="gpointer"/> </parameter> </parameters> </method> So i wrote python script: from gi.repository import GObject v = GObject.Value() v.set_instance(None) And checked it in gdb (some lines skipped): Breakpoint 1, g_value_set_instance (value=0x80ff960, instance=0x41a1b8cc) at (gdb) bt
+ Trace 228570
(gdb) print &_Py_NoneStruct $2 = (PyObject *) 0x41a1b8cc As you can see, argument "instance" was passed as 0x41a1b8cc (Py_None), whereas I wanted to pass NULL.
GPointers have no context so it is unclear what the right solution is since in some interfaces assuming a gpointer takes the raw python pointer is what is wanted. In fact it is the only way to set a python pointer (for instance in a treemodel). set_instance needs to be annotated to the correct parameter type for a Instance. See the set_object method for example.
The best we can do is allow None as NULL and integer/PyCapsules if you really know what your are doing. There is no way to annotate g_value_set_instance generically due to it relying on its own dynamically set type. *** This bug has been marked as a duplicate of bug 688081 ***
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]