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 660056 - g_value_set_instance needs a type annotation for its gpointer parameter
g_value_set_instance needs a type annotation for its gpointer parameter
Status: RESOLVED DUPLICATE of bug 688081
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2011-09-25 13:43 UTC by Pavel Stupnikov
Modified: 2015-02-07 16:52 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Pavel Stupnikov 2011-09-25 13:43:15 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
  • #0 g_value_set_instance
    at gvalue.c line 337
  • #1 ffi_call_SYSV
    at ../src/x86/sysv.S line 64
  • #2 ffi_call
    at ../src/x86/ffi.c line 303
  • #3 ??
    from /usr/lib/libgirepository-1.0.so.1
  • #4 g_function_info_invoke
    from /usr/lib/libgirepository-1.0.so.1
  • #5 _invoke_callable
    at pygi-invoke.c line 52
  • #6 _wrap_g_callable_info_invoke
    at pygi-invoke.c line 623
  • #7 PyCFunction_Call
    from /usr/lib/libpython2.7.so.1.0

(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.
Comment 1 johnp 2011-10-21 18:14:02 UTC
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.
Comment 2 Simon Feltman 2013-09-13 23:43:36 UTC
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 ***
Comment 3 André Klapper 2015-02-07 16:52:18 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]