From: David Bremner Date: Sun, 27 Sep 2015 15:32:00 +0000 (+2100) Subject: [Patch v4 6/9] python: update bindings for new count API X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5dbd561fc2667e6537403286e7dd0c067f96dcb0;p=notmuch-archives.git [Patch v4 6/9] python: update bindings for new count API --- diff --git a/ef/1ed936428b10700a74ee5d45c39d5ada3a7000 b/ef/1ed936428b10700a74ee5d45c39d5ada3a7000 new file mode 100644 index 000000000..d010f1d92 --- /dev/null +++ b/ef/1ed936428b10700a74ee5d45c39d5ada3a7000 @@ -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 50B206DE1413 + for ; Sun, 27 Sep 2015 08:35:11 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.108 +X-Spam-Level: +X-Spam-Status: No, score=0.108 tagged_above=-999 required=5 tests=[AWL=0.108] + 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 lxlJctPL7Az4 for ; + Sun, 27 Sep 2015 08:35:05 -0700 (PDT) +Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 715336DE1003 + for ; Sun, 27 Sep 2015 08:35:05 -0700 (PDT) +Received: from remotemail by gitolite.debian.net with local (Exim 4.80) + (envelope-from ) + id 1ZgDy3-0008FH-DS; Sun, 27 Sep 2015 15:34:23 +0000 +Received: (nullmailer pid 11941 invoked by uid 1000); Sun, 27 Sep 2015 + 15:32:11 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [Patch v4 6/9] python: update bindings for new count API +Date: Sun, 27 Sep 2015 12:32:00 -0300 +Message-Id: <1443367923-11867-7-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.5.3 +In-Reply-To: <1443367923-11867-1-git-send-email-david@tethera.net> +References: <1443367923-11867-1-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 15:35:11 -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 +