unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Pointer ownership
@ 2018-12-16  7:42 Dirk Van Haerenborgh
  2018-12-16 23:22 ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: Dirk Van Haerenborgh @ 2018-12-16  7:42 UTC (permalink / raw)
  To: notmuch

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

Hi all,

I'm the main author for these notmuch rust bindings:
https://github.com/vhdirk/notmuch-rs
In making these bindings safe, it's very important to understand when
memory is reclaimed by notmuch (and when not). And I'm having a hard time
deducing that from the documentation. I've built a couple of c test
routines, but I'm getting none the wiser from that.

For instance, when iterating messages from a thread: Can one still use a
notmuch_message_t* when the thread is destroyed? Are the individual
messages 'owned' by the thread, or only by the query? Same question for
'replies'.

Could someone please shed some light on this? I'd very much appreciate it.

Kind regards
-Dirk

[-- Attachment #2: Type: text/html, Size: 949 bytes --]

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

* Re: Pointer ownership
  2018-12-16  7:42 Pointer ownership Dirk Van Haerenborgh
@ 2018-12-16 23:22 ` David Bremner
  2018-12-20  9:21   ` Dirk Van Haerenborgh
  2018-12-23 10:04   ` rhn
  0 siblings, 2 replies; 5+ messages in thread
From: David Bremner @ 2018-12-16 23:22 UTC (permalink / raw)
  To: Dirk Van Haerenborgh, notmuch

Dirk Van Haerenborgh <vhdirk@gmail.com> writes:


> For instance, when iterating messages from a thread: Can one still use a
> notmuch_message_t* when the thread is destroyed?
> Are the individual
> messages 'owned' by the thread, or only by the query? Same question for
> 'replies'.
>
> Could someone please shed some light on this? I'd very much appreciate it.

It's hierarchical (the underlying allocator is talloc). So threads are
owned by the corresponding query, and messages are owned by threads.

Assuming replies refers to notmuch_message_get_replies, then those are
owned by some thread as well.

Threads are somewhat lazily constructed, so there's a time where a
message is owned by a query before it is "stolen" by a thread.

This is all Carl's design, so hopefully he'll correct me if I said
anything outrageously wrong.

d

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

* Re: Pointer ownership
  2018-12-16 23:22 ` David Bremner
@ 2018-12-20  9:21   ` Dirk Van Haerenborgh
  2018-12-22  6:11     ` David Bremner
  2018-12-23 10:04   ` rhn
  1 sibling, 1 reply; 5+ messages in thread
From: Dirk Van Haerenborgh @ 2018-12-20  9:21 UTC (permalink / raw)
  To: David Bremner; +Cc: notmuch, Carl Worth

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

Thanks.

For the most part, that's what I ended up with, but the thread 'stealing' a
message will be quite hard to implement in Rust, I guess.
When using notmuch_query_search_messages, I was assuming the resulting
individual messages to be owned by the query.
So, if at a later point in time, one uses notmuch_query_search_threads,
will the ownership of a previous message abruptly be
transferred from query to thread?
I do want to be able to run *_destroy at some point :)

-Dirk


On Thu, 20 Dec 2018 at 10:11, David Bremner <david@tethera.net> wrote:

> Dirk Van Haerenborgh <vhdirk@gmail.com> writes:
>
>
> > For instance, when iterating messages from a thread: Can one still use a
> > notmuch_message_t* when the thread is destroyed?
> > Are the individual
> > messages 'owned' by the thread, or only by the query? Same question for
> > 'replies'.
> >
> > Could someone please shed some light on this? I'd very much appreciate
> it.
>
> It's hierarchical (the underlying allocator is talloc). So threads are
> owned by the corresponding query, and messages are owned by threads.
>
> Assuming replies refers to notmuch_message_get_replies, then those are
> owned by some thread as well.
>
> Threads are somewhat lazily constructed, so there's a time where a
> message is owned by a query before it is "stolen" by a thread.
>
> This is all Carl's design, so hopefully he'll correct me if I said
> anything outrageously wrong.
>
> d
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2040 bytes --]

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

* Re: Pointer ownership
  2018-12-20  9:21   ` Dirk Van Haerenborgh
@ 2018-12-22  6:11     ` David Bremner
  0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2018-12-22  6:11 UTC (permalink / raw)
  To: Dirk Van Haerenborgh; +Cc: notmuch, Carl Worth

Dirk Van Haerenborgh <vhdirk@gmail.com> writes:

> Thanks.
>
> For the most part, that's what I ended up with, but the thread 'stealing' a
> message will be quite hard to implement in Rust, I guess.
> When using notmuch_query_search_messages, I was assuming the resulting
> individual messages to be owned by the query.
> So, if at a later point in time, one uses notmuch_query_search_threads,
> will the ownership of a previous message abruptly be
> transferred from query to thread?
> I do want to be able to run *_destroy at some point :)

It's still (transitively) owned by the query in that case, since the
threads are owned by the query.

d

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

* Re: Pointer ownership
  2018-12-16 23:22 ` David Bremner
  2018-12-20  9:21   ` Dirk Van Haerenborgh
@ 2018-12-23 10:04   ` rhn
  1 sibling, 0 replies; 5+ messages in thread
From: rhn @ 2018-12-23 10:04 UTC (permalink / raw)
  To: David Bremner; +Cc: Dirk Van Haerenborgh, notmuch

On Mon, 17 Dec 2018 08:22:27 +0900
David Bremner <david@tethera.net> wrote:

> Dirk Van Haerenborgh <vhdirk@gmail.com> writes:
> 
> 
> > For instance, when iterating messages from a thread: Can one still use a
> > notmuch_message_t* when the thread is destroyed?
> > Are the individual
> > messages 'owned' by the thread, or only by the query? Same question for
> > 'replies'.
> >
> > Could someone please shed some light on this? I'd very much appreciate it.  
> 
> It's hierarchical (the underlying allocator is talloc). So threads are
> owned by the corresponding query, and messages are owned by threads.
> 
> Assuming replies refers to notmuch_message_get_replies, then those are
> owned by some thread as well.
> 
> Threads are somewhat lazily constructed, so there's a time where a
> message is owned by a query before it is "stolen" by a thread.
> 
> This is all Carl's design, so hopefully he'll correct me if I said
> anything outrageously wrong.
> 
> d
> 

Thanks for the answer. When you're saying that threads are "lazily constructed", I assume that it doesn't really matter for the actual API? From that, I'm guessing that the message handover starts and ends within a single API call, before the caller ever has a chance to see the message handle?

The importance of lifetimes in Rust only concerns what the API guarantees about the validity of handles/data, so the implementation is free to do whatever as long as those are not impacted.

BTW, I've submitted a patch making the guarantee explicitly stated in the docs, see 20181217175748.10814-1-gihu.rhn@porcupinefactory.org . Reviews welcome, a merge is even more welcome.

Cheers,
rhn

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

end of thread, other threads:[~2018-12-23 10:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-16  7:42 Pointer ownership Dirk Van Haerenborgh
2018-12-16 23:22 ` David Bremner
2018-12-20  9:21   ` Dirk Van Haerenborgh
2018-12-22  6:11     ` David Bremner
2018-12-23 10:04   ` rhn

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).