From: David Bremner Date: Sun, 27 Sep 2015 03:01:18 +0000 (+2100) Subject: [PATCH] python: update bindings for new count API X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=832fa516e44f40b7dbad400f8f1fd44aaf56fb16;p=notmuch-archives.git [PATCH] python: update bindings for new count API --- diff --git a/c7/06408b63caf0d943c96881c807af4c35fef1bd b/c7/06408b63caf0d943c96881c807af4c35fef1bd new file mode 100644 index 000000000..ed001e0c1 --- /dev/null +++ b/c7/06408b63caf0d943c96881c807af4c35fef1bd @@ -0,0 +1,111 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 2CB6F6DE0924 + for ; Sat, 26 Sep 2015 20:02:40 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.111 +X-Spam-Level: +X-Spam-Status: No, score=0.111 tagged_above=-999 required=5 tests=[AWL=0.111] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id R2eOL-SiqFhU for ; + Sat, 26 Sep 2015 20:02:37 -0700 (PDT) +Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 7E9CA6DE025E + for ; Sat, 26 Sep 2015 20:02:37 -0700 (PDT) +Received: from remotemail by gitolite.debian.net with local (Exim 4.80) + (envelope-from ) + id 1Zg2Dq-0005fC-2f; Sun, 27 Sep 2015 03:01:54 +0000 +Received: (nullmailer pid 12847 invoked by uid 1000); Sun, 27 Sep 2015 + 03:01:35 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [PATCH] python: update bindings for new count API +Date: Sun, 27 Sep 2015 00:01:18 -0300 +Message-Id: <1443322878-12807-1-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.5.3 +In-Reply-To: <1443322213-31075-5-git-send-email-david@tethera.net> +References: <1443322213-31075-5-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 27 Sep 2015 03:02:40 -0000 + +Note that any mismatches are not detected until runtime (if at all) +with the python bindings, so tests are crucial +--- + bindings/python/notmuch/query.py | 24 ++++++++++++++++-------- + 1 file changed, 16 insertions(+), 8 deletions(-) + +diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py +index 94773ac..378aa47 100644 +--- a/bindings/python/notmuch/query.py ++++ b/bindings/python/notmuch/query.py +@@ -17,7 +17,7 @@ along with notmuch. If not, see . + Copyright 2010 Sebastian Spaeth + """ + +-from ctypes import c_char_p, c_uint ++from ctypes import c_char_p, c_uint, POINTER, byref + from .globals import ( + nmlib, + Enum, +@@ -178,8 +178,8 @@ class Query(object): + raise NullPointerError + return Messages(msgs_p, self) + +- _count_messages = nmlib.notmuch_query_count_messages +- _count_messages.argtypes = [NotmuchQueryP] ++ _count_messages = nmlib.notmuch_query_count_messages_st ++ _count_messages.argtypes = [NotmuchQueryP, POINTER(c_uint)] + _count_messages.restype = c_uint + + def count_messages(self): +@@ -191,10 +191,14 @@ class Query(object): + :rtype: int + ''' + self._assert_query_is_initialized() +- return Query._count_messages(self._query) +- +- _count_threads = nmlib.notmuch_query_count_threads +- _count_threads.argtypes = [NotmuchQueryP] ++ count = c_uint(0) ++ status = Query._count_messages(self._query, byref(count)) ++ if status != 0: ++ raise NotmuchError(status) ++ return count.value ++ ++ _count_threads = nmlib.notmuch_query_count_threads_st ++ _count_threads.argtypes = [NotmuchQueryP, POINTER(c_uint)] + _count_threads.restype = c_uint + + def count_threads(self): +@@ -210,7 +214,11 @@ class Query(object): + :rtype: int + ''' + self._assert_query_is_initialized() +- return Query._count_threads(self._query) ++ count = c_uint(0) ++ status = Query._count_threads(self._query, byref(count)) ++ if status != 0: ++ raise NotmuchError(status) ++ return count.value + + _destroy = nmlib.notmuch_query_destroy + _destroy.argtypes = [NotmuchQueryP] +-- +2.5.3 +