aboutsummaryrefslogtreecommitdiff
path: root/bindings/python-cffi/notmuch2
diff options
context:
space:
mode:
authorLars Kotthoff <lars@larsko.org>2025-02-05 19:52:51 -0700
committerDavid Bremner <david@tethera.net>2025-02-07 12:13:16 -0400
commit9c1f6cf746725af7bbbb66e746c5d694723ac0eb (patch)
treef3c1b7b0fc87fa2970bddadb1f9efedf2102bee0 /bindings/python-cffi/notmuch2
parent409ad6b2a897c1571044bf6e4021a35fbd85b122 (diff)
fix segfaults in Python cFFI API and add tests
Several iterators in the Python cFFI API destroyed the objects they iterated over too early (when the iterator was exhausted), causing subsequent segfaults in common cases like creating a list from the iterator. This patch fixes the segfaults and add tests to ensure that they don't happen again.
Diffstat (limited to 'bindings/python-cffi/notmuch2')
-rw-r--r--bindings/python-cffi/notmuch2/_base.py3
-rw-r--r--bindings/python-cffi/notmuch2/_message.py3
-rw-r--r--bindings/python-cffi/notmuch2/_query.py2
3 files changed, 3 insertions, 5 deletions
diff --git a/bindings/python-cffi/notmuch2/_base.py b/bindings/python-cffi/notmuch2/_base.py
index 1cf03c88..c83abd01 100644
--- a/bindings/python-cffi/notmuch2/_base.py
+++ b/bindings/python-cffi/notmuch2/_base.py
@@ -167,7 +167,7 @@ class NotmuchIter(NotmuchObject, collections.abc.Iterator):
It is tempting to use a generator function instead, but this would
not correctly respect the :class:`NotmuchObject` memory handling
protocol and in some unsuspecting cornercases cause memory
- trouble. You probably want to sublcass this in order to wrap the
+ trouble. You probably want to subclass this in order to wrap the
value returned by :meth:`__next__`.
:param parent: The parent object.
@@ -223,7 +223,6 @@ class NotmuchIter(NotmuchObject, collections.abc.Iterator):
def __next__(self):
if not self._fn_valid(self._iter_p):
- self._destroy()
raise StopIteration()
obj_p = self._fn_get(self._iter_p)
self._fn_next(self._iter_p)
diff --git a/bindings/python-cffi/notmuch2/_message.py b/bindings/python-cffi/notmuch2/_message.py
index d4b34e91..abe37db6 100644
--- a/bindings/python-cffi/notmuch2/_message.py
+++ b/bindings/python-cffi/notmuch2/_message.py
@@ -610,7 +610,7 @@ class PropertiesMap(base.NotmuchObject, collections.abc.MutableMapping):
def getall(self, prefix='', *, exact=False):
"""Return an iterator yielding all properties for a given key prefix.
- The returned iterator yields all peroperties which start with
+ The returned iterator yields all properties which start with
a given key prefix as ``(key, value)`` namedtuples. If called
with ``exact=True`` then only properties which exactly match
the prefix are returned, those a key longer than the prefix
@@ -655,7 +655,6 @@ class PropertiesIter(base.NotmuchIter):
def __next__(self):
if not self._fn_valid(self._iter_p):
- self._destroy()
raise StopIteration
key = capi.lib.notmuch_message_properties_key(self._iter_p)
value = capi.lib.notmuch_message_properties_value(self._iter_p)
diff --git a/bindings/python-cffi/notmuch2/_query.py b/bindings/python-cffi/notmuch2/_query.py
index 1db6ec96..169fcf27 100644
--- a/bindings/python-cffi/notmuch2/_query.py
+++ b/bindings/python-cffi/notmuch2/_query.py
@@ -52,7 +52,7 @@ class Query(base.NotmuchObject):
This executes the query and returns an iterator over the
:class:`Message` objects found.
"""
- msgs_pp = capi.ffi.new('notmuch_messages_t**')
+ msgs_pp = capi.ffi.new('notmuch_messages_t **')
ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp)
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)