unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* segfault using python bindings
@ 2018-11-09 14:49 David Čepelík
  2018-11-11 20:16 ` David Bremner
  2018-11-18 20:22 ` Dirk Van Haerenborgh
  0 siblings, 2 replies; 28+ messages in thread
From: David Čepelík @ 2018-11-09 14:49 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 3737 bytes --]

Hello Notmuch devs,

I'm facing an issue trying to use the Python bindings. This trivial
piece of code segfaults:

    import notmuch

    database = notmuch.Database()
    threads = database.create_query('tag:inbox and not tag:killed').search_threads()
    
    for t in threads:
        print("Thread:", t)
        msgs = t.get_toplevel_messages()
        for m in msgs:
            print("Message:", m)
        msgs = t.get_toplevel_messages()
        next(msgs)

The problem is triggered by the call to next. Doing this instead works:

    database = notmuch.Database()

    threads = database.create_query('tag:inbox and not tag:killed').search_threads()
    for t in threads:
        print("Thread:", t)
        msgs = t.get_toplevel_messages()
        for m in msgs:
            print("Message:", m)

    threads = database.create_query('tag:inbox and not tag:killed').search_threads()
    for t in threads:
        print("Thread:", t)
        msgs = t.get_toplevel_messages()
        for m in msgs:
            print("Message:", m)

It seems that the problem is caused by calling get_toplevel_messages
twice on the same Threads object.

I've been able to narrow the problem down using gdb. The first few
frames of the stack-trace are:

    #0  0x000055555557da90 in  ()
    #1  0x00007ffff665db5a in Xapian::Document::Internal::get_value[abi:cxx11](unsigned int) const () at /usr/lib/libxapian.so.30
    #2  0x00007ffff665db91 in Xapian::Document::get_value[abi:cxx11](unsigned int) const () at /usr/lib/libxapian.so.30
    #3  0x00007ffff6e3165a in notmuch_message_get_header(notmuch_message_t*, char const*)
        (message=0x5555556e6920, header=0x7ffff7195f78 "from") at lib/message.cc:549
    #4  0x00007ffff6efb1c8 in ffi_call_unix64 () at /usr/lib/libffi.so.6

The () seems to denote C++'s tuple class:

    (gdb) frame 0
    #0  0x000055555557da90 in ?? ()
    (gdb) lis
    1	// <tuple> -*- C++ -*-
    2	
    3	// Copyright (C) 2007-2018 Free Software Foundation, Inc.
    4	//
    5	// This file is part of the GNU ISO C++ Library.  This library is free
    6	// software; you can redistribute it and/or modify it under the
    7	// terms of the GNU General Public License as published by the
    8	// Free Software Foundation; either version 3, or (at your option)
    9	// any later version.
    10	

Searching further, I've arrived at the following piece of Xapian code
(xapian-core/backends/documentinternal.h):

    390     std::string get_value(Xapian::valueno slot) const {
    391         if (values) {
    392             auto i = values->find(slot);
    393             if (i != values->end())
    394                 return i->second;
    395             return std::string();
    396         }
    397
    398         return fetch_value(slot);
    399     }

Since the invalid dereference indicates a tuple, I suspect the crash
stems from the use `second' on line 394. (The (->) dereference likely
does not cause the crash since otherwise we wouldn't arrive at the
tuple.)

When I use alot with this version of notmuch/python bindings, it works
just fine, but I suspect that's because alot wraps all the provided
objects to avoid this sort of bugs (and allow for repeated iteration
over Threads objects, etc), and hence avoid calling get_toplevel_messages()
twice.

Does the problem lie with my fundamental misunderstanding of how the
bindings work, or is this a bug?

Linux x1 4.18.16-arch1-1-ARCH #1 SMP PREEMPT Sat Oct 20 22:06:45 UTC 2018 x86_64 GNU/Linux
Python 3.7.1
built from upstream @ 7f726c6 (AUR: notmuch-git 3:0.28.2.7.g7f726c6e-1)


                                            Regards, David

[-- Attachment #2: signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

-----BEGIN PGP SIGNATURE-----

iQEzBAABCAAdFiEE1W8XnnLsjcC3H4ylq55LF2s9c50FAlvlnmYACgkQq55LF2s9
c51CBwf/Tkm6EenR46QKCjgfbpC9yK6/S/9CQRjrsFXGdPQDZRqiszpARabOO16f
orflzuvmNkE7HomaS3U+fpFQiJs1HvSPFFM7uzl/39he9fofFJ8hfZXJZeVi9msg
nApO3aV1ei5+4TWx27MxI52FpXiy5ggNhT0NhgtUh6IYHGC2rn2PqfS6NfCVcqZ+
pLU7Y68Vb9eSPXwRfG2hInmGFcut7KTSGJRJ7r1WG0XG2Kdvh2mX8uVgWtJsQdls
jLKrKKfJyOq4SKKYifGBDZKgR/qJKllKIETiOmPVpVCwMUqGuo/wGXPcCj2KaAdw
8kVJfTGwsskQxJqoF0mLOdW1lIPOsQ==
=9oon
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2019-08-26 17:28 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09 14:49 segfault using python bindings David Čepelík
2018-11-11 20:16 ` David Bremner
2018-11-11 20:21   ` Gaute Hope
2018-11-15 21:13   ` Floris Bruynooghe
2018-11-16  4:44     ` Brian May
2018-11-16 10:29       ` David Bremner
2018-11-16 21:39         ` Floris Bruynooghe
2018-11-17  0:15           ` David Bremner
2018-11-16 10:27     ` David Bremner
2018-11-16 12:15       ` Daniel Kahn Gillmor
2018-11-16 22:07         ` Floris Bruynooghe
2019-08-14 19:20     ` David Bremner
2019-08-15  9:53       ` Floris Bruynooghe
2019-08-15 12:28         ` David Bremner
2019-08-20 17:20           ` Floris Bruynooghe
2019-08-21 16:02             ` Daniel Kahn Gillmor
2019-08-22 19:24               ` David Bremner
2019-08-22 19:37                 ` Rollins, Jameson
2019-08-23  0:09                   ` David Bremner
2019-08-23  1:59                   ` Daniel Kahn Gillmor
2019-08-23 12:07                     ` David Bremner
2019-08-23 20:43                       ` Daniel Kahn Gillmor
2019-08-23 22:58                         ` Rollins, Jameson
2019-08-26 17:09               ` Floris Bruynooghe
2019-08-26 17:28                 ` David Bremner
2018-11-18 20:22 ` Dirk Van Haerenborgh
2018-11-18 23:34   ` David Bremner
2018-11-19  9:09     ` Dirk Van Haerenborgh

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).