From: David Bremner Date: Sat, 7 Mar 2015 08:43:17 +0000 (+0100) Subject: [PATCH 4/4] python: update bindings for new count API X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=20107875fc7ea4451c6122968da94e1572180c35;p=notmuch-archives.git [PATCH 4/4] python: update bindings for new count API --- diff --git a/79/f8c86e1326ed0498c386ebe11d19e931288b2a b/79/f8c86e1326ed0498c386ebe11d19e931288b2a new file mode 100644 index 000000000..ea938dfd2 --- /dev/null +++ b/79/f8c86e1326ed0498c386ebe11d19e931288b2a @@ -0,0 +1,115 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0D558431FC0 + for ; Sat, 7 Mar 2015 00:45:15 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id tWZTYvvh6+nY for ; + Sat, 7 Mar 2015 00:45:11 -0800 (PST) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8BD03431FC4 + for ; Sat, 7 Mar 2015 00:45:11 -0800 (PST) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YUALW-0002KF-G3; Sat, 07 Mar 2015 08:44:30 +0000 +Received: (nullmailer pid 20414 invoked by uid 1000); Sat, 07 Mar 2015 + 08:43:24 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 4/4] python: update bindings for new count API +Date: Sat, 7 Mar 2015 09:43:17 +0100 +Message-Id: <1425717797-19990-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1425717797-19990-1-git-send-email-david@tethera.net> +References: <1419971380-10307-6-git-send-email-david@tethera.net> + <1425717797-19990-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Sat, 07 Mar 2015 08:45:15 -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.1.4 +