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 670863 - PyGObject segfaults/aborts when reading/writing [respectively] a GObject pointer property that's been annotated to a GCallback
PyGObject segfaults/aborts when reading/writing [respectively] a GObject poin...
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
3.2.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 726999
Blocks:
 
 
Reported: 2012-02-27 08:42 UTC by C Anthony
Modified: 2018-01-10 20:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
testcase SIGSEGV and SIGABORT (1.61 KB, application/x-shellscript)
2012-02-27 11:39 UTC, C Anthony
Details
testcase SIGSEGV and SIGABORT (revised) (1.61 KB, text/plain)
2012-04-25 03:53 UTC, C Anthony
Details

Description C Anthony 2012-02-27 08:42:47 UTC
######


SUMMARY: PyGObject segfaults/aborts when reading/writing [respectively] a GObject pointer property that's been annotated to a GCallback (or any other function/signature)


###### SIGSEGV on read [G_DEBUG=fatal-warnings]
-------------------------------------------------------------------------------
(Pdb) [...]
(Pdb) print self.listener.props.hicallback

** CRITICAL **: g_registered_type_info_get_g_type: assertion `GI_IS_REGISTERED_TYPE_INFO (info)' failed

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff57da0d3 in g_logv () from /usr/lib/libglib-2.0.so.0
(gdb) bt full
  • #0 g_logv
    from /usr/lib/libglib-2.0.so.0
  • #1 g_log
    from /usr/lib/libglib-2.0.so.0
  • #2 g_registered_type_info_get_g_type
    at girepository/giregisteredtypeinfo.c line 132
  • #3 pygi_get_property_value_real
    at pygi-property.c line 155
  • #4 pygi_get_property_value
    at ../../gi/pygi.h line 122
  • #5 PyGProps_getattro
    at pygobject.c line 240
  • #6 PyEval_EvalFrameEx
    from /usr/lib/libpython2.7.so.1.0
  • #7 PyEval_EvalCodeEx
    from /usr/lib/libpython2.7.so.1.0
  • #0 raise
    from /lib/libc.so.6
  • #1 abort
    from /lib/libc.so.6
  • #2 g_assertion_message
    from /usr/lib/libglib-2.0.so.0
  • #3 _pygi_argument_from_object
    at pygi-argument.c line 1022
  • #4 pygi_set_property_value_real
    at pygi-property.c line 249
  • #5 pygi_set_property_value
    at ../../gi/pygi.h line 133
  • #6 PyGProps_setattro
    at pygobject.c line 338
  • #7 PyObject_SetAttr
    from /usr/lib/libpython2.7.so.1.0
  • #8 PyEval_EvalFrameEx
    from /usr/lib/libpython2.7.so.1.0
[...]
-------------------------------------------------------------------------------

###### source header
-------------------------------------------------------------------------------
typedef void (*WebKitDOMEventListenerCallback) (WebKitDOMEvent* event);

[...]

/**
 * WebKitDOMEventListener:hicallback:
 *
 * Type: WebKitDOMEventListenerCallback
 */

[...]
-------------------------------------------------------------------------------

###### source impl [WEBKIT_PARAM_READWRITE===G_PARAM_READWRITE w/cast for C++]
-------------------------------------------------------------------------------
[...]
    g_object_class_install_property(
        gobjectClass,
        PROP_HICALLBACK,
        g_param_spec_pointer(
            "hicallback",
            "event_listener_hicallback",
            "read-write GCallback* WebKitDOMEventListener.hicallback",
            WEBKIT_PARAM_READWRITE
        )
    );
[...]
-------------------------------------------------------------------------------

###### generated GIR excerpt
-------------------------------------------------------------------------------
[...]
    <class name="DOMEventListener"
           c:symbol-prefix="dom_event_listener"
           c:type="WebKitDOMEventListener"
           parent="DOMObject"
           glib:type-name="WebKitDOMEventListener"
           glib:get-type="webkit_dom_event_listener_get_type"
           glib:type-struct="DOMEventListenerClass">
      <method name="handle_event"
              c:identifier="webkit_dom_event_listener_handle_event">
        <doc xml:whitespace="preserve">Returns:</doc>
        <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
        </return-value>
        <parameters>
          <parameter name="evt" transfer-ownership="none">
            <doc xml:whitespace="preserve">A #WebKitDOMEvent</doc>
            <type name="DOMEvent" c:type="WebKitDOMEvent*"/>
          </parameter>
        </parameters>
      </method>
      <property name="handler" writable="1" transfer-ownership="none">
        <type name="GObject.Closure"/>
      </property>
      <property name="hicallback" writable="1" transfer-ownership="none">
        <type name="DOMEventListenerCallback"/>
      </property>
      <field name="parent_instance">
        <type name="DOMObject" c:type="WebKitDOMObject"/>
      </field>
      <field name="handler">
        <type name="GObject.Closure" c:type="GClosure*"/>
      </field>
    </class>
    <callback name="DOMEventListenerCallback"
              c:type="WebKitDOMEventListenerCallback">
      <return-value transfer-ownership="none">
        <type name="none" c:type="void"/>
      </return-value>
      <parameters>
        <parameter name="event" transfer-ownership="none">
          <type name="DOMEvent" c:type="WebKitDOMEvent*"/>
        </parameter>
      </parameters>
    </callback>
[...]
-------------------------------------------------------------------------------
Comment 1 C Anthony 2012-02-27 08:49:38 UTC
(for some reason bugzilla ate/squashed the SIGABRT trace, this was suppose to follow the first ... will try to make a test case tomorrow)


###### SIGABRT on write
-------------------------------------------------------------------------------
(Pdb) [...]
(Pdb) self.listener.props.hicallback = lambda *x: x
**
ERROR:pygi-argument.c:1022:_pygi_argument_from_object: code should not be reached

Program received signal SIGABRT, Aborted.
0x00007ffff7496975 in raise () from /lib/libc.so.6
(gdb) bt full
  • #0 raise
    from /lib/libc.so.6
  • #1 abort
    from /lib/libc.so.6
  • #2 g_assertion_message
    from /usr/lib/libglib-2.0.so.0
  • #3 _pygi_argument_from_object
    at pygi-argument.c line 1022
  • #4 pygi_set_property_value_real
    at pygi-property.c line 249
  • #5 pygi_set_property_value
    at ../../gi/pygi.h line 133
  • #6 PyGProps_setattro
    at pygobject.c line 338
  • #7 PyObject_SetAttr
    from /usr/lib/libpython2.7.so.1.0
  • #8 PyEval_EvalFrameEx
    from /usr/lib/libpython2.7.so.1.0
[...]
-------------------------------------------------------------------------------
Comment 2 C Anthony 2012-02-27 08:58:48 UTC
also, unless i'm missing something critical, it seems appropriate that a property based GCallback should *not require* a DestroyNotify callback, or any other special scope.  once the property is replaced by a new pointer, or set to NULL, the FFI can be freed ... the caller [python] is in full control of this, and both python and any C-code should subscribe to property changes to be informed of the status (eg, C-code keeping a ref around and calling it after invalidation is a bug, but not in pygobject).
Comment 3 C Anthony 2012-02-27 11:39:23 UTC
Created attachment 208481 [details]
testcase SIGSEGV and SIGABORT

simply chmod and run ... and maybe look it over too ;-)

pulls 2 files from the gobject-introspection 1.3.0 tree and demonstrates the bug after ~5 seconds.
Comment 4 Martin Pitt 2012-04-24 15:16:25 UTC
Confirmed with 3.2.0 using the attached test case. I just had to fix the linking order of the gcc call, for the record:

gcc annotation.c $(pkg-config --cflags --libs gobject-2.0) -fPIC -shared -Wl,-soname,libannotation.so -o libannotation.so
Comment 5 C Anthony 2012-04-25 03:53:55 UTC
Created attachment 212746 [details]
testcase SIGSEGV and SIGABORT (revised)

ahh .. yeah i'm still a bit n00b-esque in that regard.  IIRC i just looked at the man page, which lists infile last; what gives?  i seem to recall reading the output file should be first ... but meh, gcc does what it wants i guess!  i'm not surprised in the least.

uploaded a revised testcase. however, both versions work for me on latest GCC [archlinux/4.7.0])
Comment 6 GNOME Infrastructure Team 2018-01-10 20:14:21 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/24.