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 654564 - Querying EDS address book in Python results in a segfault
Querying EDS address book in Python results in a segfault
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
3.2.x
Other Linux
: Normal major
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-13 15:57 UTC by David Klasinc
Modified: 2014-01-28 07:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (296 bytes, text/x-python)
2012-04-23 18:30 UTC, Sebastian Pölsterl
Details

Description David Klasinc 2011-07-13 15:57:18 UTC
When accessing EDS address book the code below will successfully crash python and no contact list is obtained. :(


from gi.repository import EBook
book = EBook.Book.new_system_addressbook()

# ??
book.open(book)

contactlist = []

field = EBook.ContactField.FULL_NAME
fieldtest = EBook.BookQueryTest.BEGINS_WITH
query = EBook.book_query_field_test(field, fieldtest, "John")
status = EBook.Book.get_contacts(book, 	query, contactlist)

Tested on the latest Ubuntu Oneiric.
Comment 1 André Klapper 2011-07-15 14:29:00 UTC
Stacktrace is very welcome.
Comment 2 David Klasinc 2011-07-24 16:34:58 UTC
Sorry for the late reply, but here's the backtrace as gdb reports it:

  • #0 e_book_get_contacts
    at e-book.c line 2228
  • #1 ffi_call_unix64
    from /usr/lib/x86_64-linux-gnu/libffi.so.6
  • #2 ffi_call
    from /usr/lib/x86_64-linux-gnu/libffi.so.6
  • #3 ??
    from /usr/lib/libgirepository-1.0.so.1
  • #4 g_function_info_invoke
    from /usr/lib/libgirepository-1.0.so.1
  • #5 ??
    from /usr/lib/python2.7/dist-packages/gi/_gi.so
  • #6 PyEval_EvalFrameEx
  • #7 PyEval_EvalCodeEx
  • #8 ??
  • #9 PyObject_Call
  • #10 ??
  • #11 PyObject_Call
  • #12 PyEval_EvalFrameEx
  • #13 PyEval_EvalCodeEx
  • #14 PyEval_EvalCode
  • #15 ??
  • #16 PyRun_InteractiveOneFlags
  • #17 PyRun_InteractiveLoopFlags
  • #18 PyRun_AnyFileExFlags
  • #19 Py_Main
  • #20 __libc_start_main
    from /lib/x86_64-linux-gnu/libc.so.6
  • #21 _start

Comment 3 Rodrigo Moya 2011-07-26 17:21:36 UTC
The introspection stuff just maps the C API, so there is nothing in between that translates from a Python list to a GSList, which is what get_contacts_sync expects. Also, you need to pass all arguments the C API expects, as not doing so will send uninitialized values to the C API. So:

EBook.BookClient.get_contacts_sync(client, query_string, contactlist, None, None)

and contactlist needs to be a GSList.
Comment 4 Rodrigo Moya 2011-07-26 21:33:20 UTC
This looks indeed like a problem in pygobject, as it seems this function, should work like this in Python:

(ret, contacts) = book.get_contacts_sync(client, sexp)

as explained here:

https://live.gnome.org/PyGObject/IntrospectionPorting#Output_arguments

so, I'd say this needs to be reported to PyGObject
Comment 5 David Klasinc 2011-07-27 15:42:45 UTC
The non-working code in question and the result are below:

#!/usr/bin/python
from gi.repository import EBook

contacts = []

client = EBook.BookClient.new_system()
query_string = "(contains \"full_name\" \"N\")"
ret = EBook.BookClient.get_contacts_sync(client, query_string, contacts, None)

print contacts

if not ret:
  print "*sob*"

---

bigwhale@thefish:~/Code/Gwibber/eds$ ./python-eds-1.py 

(process:23434): libebook-CRITICAL **: e_book_client_get_contacts_sync: assertion `contacts != NULL' failed
[]
*sob*
bigwhale@thefish:~/Code/Gwibber/eds$
Comment 6 johnp 2011-07-28 17:18:34 UTC
But an empty GSList is NULL so how can contacts allow empty lists without accepting NULL?
Comment 7 johnp 2011-07-28 17:23:26 UTC
Oh, so the contacts list is an out value.  Can you please post the relevant section the EBook .gir file?  The part that describes the get_contacts_sync method
Comment 8 Rodrigo Moya 2011-08-08 15:15:50 UTC
<method name="get_contacts_sync"
              c:identifier="e_book_client_get_contacts_sync"
              version="3.2"
              throws="1">
        <doc xml:whitespace="preserve">Query @client with @sexp, receiving a list of contacts which matched.
If successful, then the @contacts is set to newly allocated #GSList of
#EContact-s, which should be freed with e_client_util_free_object_slist().
to a string with e_book_query_to_string().</doc>
        <return-value transfer-ownership="none">
          <doc xml:whitespace="preserve">%TRUE if successful, %FALSE otherwise.</doc>
          <type name="gboolean" c:type="gboolean"/>
        </return-value>
        <parameters>
          <parameter name="sexp" transfer-ownership="none">
            <doc xml:whitespace="preserve">an S-expression representing the query</doc>
            <type name="utf8" c:type="gchar*"/>
          </parameter>
          <parameter name="contacts" transfer-ownership="none">
            <doc xml:whitespace="preserve">(out) a #GSList of matched #EContact-s</doc>
            <type name="GLib.SList" c:type="GSList**">
              <type name="gpointer" c:type="gpointer"/>
            </type>
          </parameter>
          <parameter name="cancellable"
                     transfer-ownership="none"
                     allow-none="1">
            <doc xml:whitespace="preserve">a #GCancellable; can be %NULL</doc>
            <type name="Gio.Cancellable" c:type="GCancellable*"/>
          </parameter>
        </parameters>
      </method>

the .gir file contents
Comment 9 johnp 2011-08-14 08:10:29 UTC
(out) a #GSList of matched
#EContact-s

needs to be

(out): a #GSList of matched
#EContact-s

You are missing a colon in the docstring
Comment 10 Sebastian Pölsterl 2012-04-23 18:30:43 UTC
Created attachment 212630 [details]
Test case

Running the attached test case results in a crash using pygobject 3.2.0 on Fedora 17:

  • #0 e_book_get_contacts
    at e-book.c line 2230
  • #1 ffi_call_unix64
    at ../src/x86/unix64.S line 75
  • #2 ffi_call
    at ../src/x86/ffi64.c line 486
  • #3 g_callable_info_invoke
    from /opt/gnome3/lib64/libgirepository-1.0.so.1
  • #4 g_function_info_invoke
    from /opt/gnome3/lib64/libgirepository-1.0.so.1
  • #5 _invoke_callable
    from /opt/gnome3/lib64/python2.7/site-packages/gi/_gi.so
  • #6 _wrap_g_callable_info_invoke
    from /opt/gnome3/lib64/python2.7/site-packages/gi/_gi.so
  • #7 ext_do_call
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4408
  • #8 PyEval_EvalFrameEx
  • #9 PyEval_EvalCodeEx
  • #10 function_call
  • #11 PyObject_Call
  • #12 instancemethod_call
  • #13 PyObject_Call
  • #14 do_call
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4316
  • #15 call_function
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4121
  • #16 PyEval_EvalFrameEx
  • #17 PyEval_EvalCodeEx
  • #18 PyEval_EvalCode
  • #19 run_mod
  • #20 PyRun_FileExFlags
  • #21 PyRun_SimpleFileExFlags
    at /usr/src/debug/Python-2.7.3/Python/pythonrun.c line 951
  • #22 PyRun_AnyFileExFlags
    at /usr/src/debug/Python-2.7.3/Python/pythonrun.c line 755
  • #23 Py_Main
    at /usr/src/debug/Python-2.7.3/Modules/main.c line 639
  • #24 __libc_start_main
    at libc-start.c line 226
  • #25 _start

Comment 11 Sebastian Pölsterl 2012-04-23 18:40:32 UTC
Ignore the previous stacktrace, I was missing debug symbols.

  • #0 e_book_get_contacts
    at e-book.c line 2230
  • #1 ffi_call_unix64
    at ../src/x86/unix64.S line 75
  • #2 ffi_call
    at ../src/x86/ffi64.c line 486
  • #3 g_callable_info_invoke
    at girepository/gicallableinfo.c line 610
  • #4 g_function_info_invoke
    at girepository/gifunctioninfo.c line 274
  • #5 _invoke_callable
    at pygi-invoke.c line 52
  • #6 _wrap_g_callable_info_invoke
  • #7 ext_do_call
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4408
  • #8 PyEval_EvalFrameEx
  • #9 PyEval_EvalCodeEx
  • #10 function_call
  • #11 PyObject_Call
  • #12 instancemethod_call
  • #13 PyObject_Call
  • #14 do_call
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4316
  • #15 call_function
    at /usr/src/debug/Python-2.7.3/Python/ceval.c line 4121
  • #16 PyEval_EvalFrameEx
  • #17 PyEval_EvalCodeEx
  • #18 PyEval_EvalCode
  • #19 run_mod
  • #20 PyRun_FileExFlags
  • #21 PyRun_SimpleFileExFlags
    at /usr/src/debug/Python-2.7.3/Python/pythonrun.c line 951
  • #22 PyRun_AnyFileExFlags
    at /usr/src/debug/Python-2.7.3/Python/pythonrun.c line 755
  • #23 Py_Main
    at /usr/src/debug/Python-2.7.3/Modules/main.c line 639
  • #24 __libc_start_main
    at libc-start.c line 226
  • #25 _start

Comment 12 Vadim Rutkovsky 2013-01-10 12:42:37 UTC
Cannot reproduce in e-d-s 3.7.4, the following code works:

from gi.repository import EDataServer
from gi.repository import EBook
registry = EDataServer.SourceRegistry.new_sync(None)
source = registry.ref_default_address_book()
address_book = EBook.BookClient.new(source)
address_book.open_sync(False, None)

query_string = '(contains "full_name" "N")'
ret, contacts = EBook.BookClient.get_contacts_sync(address_book, query_string, None)
print contacts
print ret
Comment 13 Martin Pitt 2013-02-27 14:59:44 UTC
Sebastian's example in comment 10 doesn't seem to work with eds 3.6.x any more:

Traceback (most recent call last):
  • File "/tmp/eds_test.py", line 2 in <module>
    book = EBook.Book.new_system_addressbook()
AttributeError: type object 'Book' has no attribute 'new_system_addressbook'

Vadim's example from comment 12 works fine with eds 3.6.x as well.

So is this still actually an issue? Have e-d-s' annotations been fixed (see John's comment 9)?
Comment 14 Simon Feltman 2014-01-28 07:25:40 UTC
Closing since there seems to be working code noted in comment 12