unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Floris Bruynooghe <flub@devork.be>
To: Michael J Gruber <git@grubix.eu>,
	Austin Lund <austin.lund@gmail.com>,
	notmuch@notmuchmail.org
Subject: Re: Python binding SIGABRT/SIGSEGV
Date: Wed, 16 Feb 2022 21:31:34 +0100	[thread overview]
Message-ID: <875ypepn89.fsf@powell.devork.be> (raw)
In-Reply-To: <164449537318.6325.7517307804708659382.git@grubix.eu>

On Thu 10 Feb 2022 at 13:16 +0100, Michael J Gruber wrote:

> Austin Lund venit, vidit, dixit 2022-02-10 06:56:12:
>> I'm clearly doing this python code wrong by not using the iterator correctly:
>> 
>> > import notmuch2
>> > 
>> > d = notmuch2.Database()
>> > m = list(d.messages("since:today"))
>> > p = m[0].path
>> > print(p)
>> 
>> But I seem to be getting a SIGABRT instead of a python stack trace.  Is
>> this the expected behaviour?
>
> You didn't expect it :)
>
> And this can be confusing. d.messages() returns an iterator through
> Message objects whose lifetime depends on the iterator. In contrast,
> thread.get_messages() returns on iterator through OwnedMessage objects
> whose lifetime depends on the thread.
>
> As soon as the iterator is depleted, the returned objects are (possibly)
> gone. (Well, because it's return by reference in Python, and ...)
>
> If you're interested in m[0] only you can "cheat" by not depleting the
> iterator:
>
> mm = next(d.messages("since:today"))
>
> p = mm.path
>
> This never frees the object (I think).
>
> My attempts with notmuch2._message.OwnedMessage (and db as parent)
> failed. There must be a better way, possibly using a context manager or
> search.
>
> I guess usually people just use the iterator in a for loop and do
> something with the message inside the loop (while the iterator is not
> depleted), such as converting it into a proper email.Message object
> (i.e. instantiating a new object from it).

Hum, to be fair I consider this a serious bug in the notmuch2 bindings.
You should not be able to crash whatever you do and not need to
understand the internal notmuch memory model.  I tried to build the
bindings so they would keep alive what they need, but it seems it fails
here.  It would be good to figure out if this can be fixed.

Cheers,
Floris

  reply	other threads:[~2022-02-16 20:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10  5:56 Python binding SIGABRT/SIGSEGV Austin Lund
2022-02-10 12:16 ` Michael J Gruber
2022-02-16 20:31   ` Floris Bruynooghe [this message]
     [not found] ` <164449516783.6325.11211773003514272352.github@grubix.eu>
2022-02-10 22:21   ` Austin Lund
2022-02-11  9:19     ` Michael J Gruber
2022-02-11  9:41       ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875ypepn89.fsf@powell.devork.be \
    --to=flub@devork.be \
    --cc=austin.lund@gmail.com \
    --cc=git@grubix.eu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).