• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

example/H21-Aug-2019-

fixtures/emails/H21-Aug-2019-

.gitignoreH A D21-Aug-201919

.gitlab-ci.ymlH A D21-Aug-2019380

AUTHORSH A D21-Aug-201975

COPYINGH A D21-Aug-2019696

MakefileH A D21-Aug-2019585

README-INTERNALS.mdH A D21-Aug-20192.2 KiB

README.mdH A D21-Aug-2019619

alloc_test.goH A D21-Aug-2019843

configList.goH A D21-Aug-20191.3 KiB

cstruct.goH A D21-Aug-20192.6 KiB

db.goH A D21-Aug-20197.3 KiB

db_test.goH A D21-Aug-20198 KiB

doc.goH A D21-Aug-20191.3 KiB

errors.goH A D21-Aug-20193.8 KiB

filenames.goH A D21-Aug-2019895

go.modH A D21-Aug-201946

message.goH A D21-Aug-20196.4 KiB

message_test.goH A D21-Aug-201910.7 KiB

messages.goH A D21-Aug-20192 KiB

messages_test.goH A D21-Aug-2019673

query.goH A D21-Aug-20194.2 KiB

query_test.goH A D21-Aug-20193.6 KiB

tag.goH A D21-Aug-2019426

tags.goH A D21-Aug-20191.2 KiB

thread.goH A D21-Aug-20193.4 KiB

thread_test.goH A D21-Aug-20195.8 KiB

threads.goH A D21-Aug-20191.2 KiB

README-INTERNALS.md

1This document describes some general patterns in the implementation.
2
3# Resource reclamation.
4
5The library is written such that all resources will be released when the
6garbage collector claims an object. However, we also export Close()
7methods on each type that needs explicit cleanup. This is because the Go
8garbage collector [isn't always able to make the right decisions about
9objects with pointers to C memory][1].
10
11## Tracking dependencies
12
13Each notmuch object has a corresponding wrapper object:
14notmuch_database_t is wrapped by DB, notmuch_query_t is wrapped by Query
15and so on. Each of these wrappers is an alias for the type cStruct,
16which holds a pointer to the underlying C object, and also to the
17wrappers for any objects referenced by the underlying C object (via the
18`parent` field).  This keeps the GC from collecting parent objects if
19the children are still in use.
20
21## Creating objects
22
23When creating an object, the caller should set the `parent` field to a
24pointer to the object's immediate parent object, and set cptr to the
25underlying c pointer. Finally, calling setGcClose on the object will
26cause it to be released properly by the garbage collector.
27
28## Cleaning up
29
30Calling the `Close()` method on an object a second time is a no-op, and
31thus always safe. The primary reason for this is that it makes dealing
32with mixing GC and manual reclamation simple.
33
34The Close methods also clear all of their references to parent objects
35explicitly. While this isn't strictly necessary, it means the GC
36will know that they are unreachable sooner, if that becomes the case.
37Per the documentation for `runtime.SetFinalizer`, once the finalizer is
38called, the object will stick around until the next time the GC looks at
39it. Because of this, it won't otherwise even consider parent objects
40until the third pass at least.
41
42In some cases, invoking the `*_destroy` function on an object also
43cleans up its children, in which case it becomes unsafe to then invoke
44their `*_destroy` function. cStruct handles all of the bookkeeping and
45synchronization necessary to deal with this; derived types just need to
46make proper use of doClose() in their Close() implementation (see the
47comments in cstruct.go)
48
49[1]: https://gist.github.com/dwbuiten/c9865c4afb38f482702e#cleaning
50

README.md

1[![Build Status][ci-img]][ci]
2
3Go binding for [notmuch mail][notmuch].
4
5Licensed under the GPLv3 or later (like notmuch itself).
6
7# Development
8
9## Running tests
10The project uses `make` to setup and download additional assets for the tests.
11
12Run `make test` to run the tests.
13
14## Pre PR checks
15Next to the tests, you should also run gofmt on the sourcecode.
16Running `make fmtcheck` checks for formatting issues.
17
18To run both tests and format checks, use `make ci`.
19
20[notmuch]: http://notmuchmail.org/
21[ci-img]: https://gitlab.com/isd/go-notmuch/badges/master/build.svg
22[ci]: https://gitlab.com/isd/go-notmuch/pipelines
23