Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d7 / fc64336f47e73c31bfaa650d2630e683cd72e3
1 Return-Path: <jw2328@jameswestby.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 88628429E25\r
6         for <notmuch@notmuchmail.org>; Thu,  1 Dec 2011 15:13:21 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id yagjbKrKZvF9 for <notmuch@notmuchmail.org>;\r
16         Thu,  1 Dec 2011 15:13:20 -0800 (PST)\r
17 Received: from jameswestby.net (jameswestby.net [89.145.97.141])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 8E534431FD0\r
21         for <notmuch@notmuchmail.org>; Thu,  1 Dec 2011 15:13:20 -0800 (PST)\r
22 Received: from [74.220.184.116] (helo=dim.jameswestby.net)\r
23         by jameswestby.net with esmtpa (Exim 4.69)\r
24         (envelope-from <jw2328@jameswestby.net>)\r
25         id 1RWFoc-0006b9-II; Thu, 01 Dec 2011 23:13:19 +0000\r
26 Received: by dim.jameswestby.net (Postfix, from userid 1000)\r
27         id 230BB5A4AE0; Thu,  1 Dec 2011 18:13:18 -0500 (EST)\r
28 From: James Westby <jw+debian@jameswestby.net>\r
29 To: notmuch@notmuchmail.org\r
30 Subject: [PATCH] python: Store pointers as c_void_p to keep references\r
31 Date: Thu,  1 Dec 2011 18:13:05 -0500\r
32 Message-Id: <1322781185-15923-1-git-send-email-jw+debian@jameswestby.net>\r
33 X-Mailer: git-send-email 1.7.5.4\r
34 In-Reply-To: <87pqg8b9hx.fsf@jameswestby.net>\r
35 References: <87pqg8b9hx.fsf@jameswestby.net>\r
36 Cc: James Westby <james.westby@linaro.org>\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Thu, 01 Dec 2011 23:13:21 -0000\r
50 \r
51 From: James Westby <james.westby@linaro.org>\r
52 \r
53 ctypes doesn't return c_void_p return values as that, it returns them as\r
54 32-bit integers instead. This has two problems:\r
55 \r
56   1 - On 64-bit machines anything higher than the max 32-bit integer\r
57       will overflow when passed back in to another function expecting,\r
58       a pointer giving the wrong value.\r
59 \r
60   2 - If the value isn't stored as a pointer then the memory can be\r
61       re-used and so the object will be corrupted.\r
62 \r
63 The fix for both of these is to store the values as pointers.\r
64 ---\r
65  bindings/python/notmuch/database.py |   18 +++++++++---------\r
66  bindings/python/notmuch/message.py  |   10 +++++-----\r
67  bindings/python/notmuch/thread.py   |    6 +++---\r
68  3 files changed, 17 insertions(+), 17 deletions(-)\r
69 \r
70 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py\r
71 index f4bc53e..e5188fb 100644\r
72 --- a/bindings/python/notmuch/database.py\r
73 +++ b/bindings/python/notmuch/database.py\r
74 @@ -152,7 +152,7 @@ class Database(object):\r
75          if res is None:\r
76              raise NotmuchError(\r
77                  message="Could not create the specified database")\r
78 -        self._db = res\r
79 +        self._db = c_void_p(res)\r
80  \r
81      def open(self, path, mode=0):\r
82          """Opens an existing database\r
83 @@ -171,7 +171,7 @@ class Database(object):\r
84  \r
85          if res is None:\r
86              raise NotmuchError(message="Could not open the specified database")\r
87 -        self._db = res\r
88 +        self._db = c_void_p(res)\r
89  \r
90      def get_path(self):\r
91          """Returns the file path of an open database"""\r
92 @@ -297,7 +297,7 @@ class Database(object):\r
93          dir_p = Database._get_directory(self._db, _str(path))\r
94  \r
95          # return the Directory, init it with the absolute path\r
96 -        return Directory(_str(abs_dirpath), dir_p, self)\r
97 +        return Directory(_str(abs_dirpath), c_void_p(dir_p), self)\r
98  \r
99      def add_message(self, filename, sync_maildir_flags=False):\r
100          """Adds a new message to the database\r
101 @@ -466,7 +466,7 @@ class Database(object):\r
102          tags_p = Database._get_all_tags(self._db)\r
103          if tags_p == None:\r
104              raise NotmuchError(STATUS.NULL_POINTER)\r
105 -        return Tags(tags_p, self)\r
106 +        return Tags(c_void_p(tags_p), self)\r
107  \r
108      def create_query(self, querystring):\r
109          """Returns a :class:`Query` derived from this database\r
110 @@ -600,7 +600,7 @@ class Query(object):\r
111          query_p = Query._create(db.db_p, _str(querystr))\r
112          if query_p is None:\r
113              raise NullPointerError\r
114 -        self._query = query_p\r
115 +        self._query = c_void_p(query_p)\r
116  \r
117      def set_sort(self, sort):\r
118          """Set the sort order future results will be delivered in\r
119 @@ -630,7 +630,7 @@ class Query(object):\r
120  \r
121          if threads_p is None:\r
122              raise NullPointerError\r
123 -        return Threads(threads_p, self)\r
124 +        return Threads(c_void_p(threads_p), self)\r
125  \r
126      def search_messages(self):\r
127          """Filter messages according to the query and return\r
128 @@ -644,7 +644,7 @@ class Query(object):\r
129  \r
130          if msgs_p is None:\r
131              raise NullPointerError\r
132 -        return Messages(msgs_p, self)\r
133 +        return Messages(c_void_p(msgs_p), self)\r
134  \r
135      def count_messages(self):\r
136          """Estimate the number of messages matching the query\r
137 @@ -793,7 +793,7 @@ class Directory(object):\r
138          """\r
139          self._assert_dir_is_initialized()\r
140          files_p = Directory._get_child_files(self._dir_p)\r
141 -        return Filenames(files_p, self)\r
142 +        return Filenames(c_void_p(files_p), self)\r
143  \r
144      def get_child_directories(self):\r
145          """Gets a :class:`Filenames` iterator listing all the filenames of\r
146 @@ -804,7 +804,7 @@ class Directory(object):\r
147          """\r
148          self._assert_dir_is_initialized()\r
149          files_p = Directory._get_child_directories(self._dir_p)\r
150 -        return Filenames(files_p, self)\r
151 +        return Filenames(c_void_p(files_p), self)\r
152  \r
153      @property\r
154      def path(self):\r
155 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py\r
156 index 4bf90c2..672a169 100644\r
157 --- a/bindings/python/notmuch/message.py\r
158 +++ b/bindings/python/notmuch/message.py\r
159 @@ -140,7 +140,7 @@ class Messages(object):\r
160  \r
161          if tags_p == None:\r
162              raise NotmuchError(STATUS.NULL_POINTER)\r
163 -        return Tags(tags_p, self)\r
164 +        return Tags(c_void_p(tags_p), self)\r
165  \r
166      def __iter__(self):\r
167          """ Make Messages an iterator """\r
168 @@ -154,7 +154,7 @@ class Messages(object):\r
169              self._msgs = None\r
170              raise StopIteration\r
171  \r
172 -        msg = Message(Messages._get(self._msgs), self)\r
173 +        msg = Message(c_void_p(Messages._get(self._msgs)), self)\r
174          nmlib.notmuch_messages_move_to_next(self._msgs)\r
175          return msg\r
176  \r
177 @@ -350,7 +350,7 @@ class Message(object):\r
178          if msgs_p is None:\r
179              return None\r
180  \r
181 -        return Messages(msgs_p, self)\r
182 +        return Messages(c_void_p(msgs_p), self)\r
183  \r
184      def get_date(self):\r
185          """Returns time_t of the message date\r
186 @@ -418,7 +418,7 @@ class Message(object):\r
187  \r
188          files_p = Message._get_filenames(self._msg)\r
189  \r
190 -        return Filenames(files_p, self).as_generator()\r
191 +        return Filenames(c_void_p(files_p), self).as_generator()\r
192  \r
193      def get_flag(self, flag):\r
194          """Checks whether a specific flag is set for this message\r
195 @@ -468,7 +468,7 @@ class Message(object):\r
196          tags_p = Message._get_tags(self._msg)\r
197          if tags_p == None:\r
198              raise NotmuchError(STATUS.NULL_POINTER)\r
199 -        return Tags(tags_p, self)\r
200 +        return Tags(c_void_p(tags_p), self)\r
201  \r
202      def add_tag(self, tag, sync_maildir_flags=False):\r
203          """Adds a tag to the given message\r
204 diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py\r
205 index 5e08eb3..ee4b71d 100644\r
206 --- a/bindings/python/notmuch/thread.py\r
207 +++ b/bindings/python/notmuch/thread.py\r
208 @@ -113,7 +113,7 @@ class Threads(object):\r
209              self._threads = None\r
210              raise StopIteration\r
211  \r
212 -        thread = Thread(Threads._get(self._threads), self)\r
213 +        thread = Thread(c_void_p(Threads._get(self._threads)), self)\r
214          nmlib.notmuch_threads_move_to_next(self._threads)\r
215          return thread\r
216  \r
217 @@ -265,7 +265,7 @@ class Thread(object):\r
218          if msgs_p is None:\r
219              raise NotmuchError(STATUS.NULL_POINTER)\r
220  \r
221 -        return Messages(msgs_p, self)\r
222 +        return Messages(c_void_p(msgs_p), self)\r
223  \r
224      def get_matched_messages(self):\r
225          """Returns the number of messages in 'thread' that matched the query\r
226 @@ -359,7 +359,7 @@ class Thread(object):\r
227          tags_p = Thread._get_tags(self._thread)\r
228          if tags_p == None:\r
229              raise NotmuchError(STATUS.NULL_POINTER)\r
230 -        return Tags(tags_p, self)\r
231 +        return Tags(c_void_p(tags_p), self)\r
232  \r
233      def __str__(self):\r
234          """A str(Thread()) is represented by a 1-line summary"""\r
235 -- \r
236 1.7.5.4\r
237 \r