python: fix returning size_t values.
* python/libmu_py/address.c: Use PyInt_FromSize_t to return size_t and similar values. * python/libmu_py/auth.c: Likewise. * python/libmu_py/body.c: Likewise. * python/libmu_py/header.c: Likewise. * python/libmu_py/mailbox.c: Likewise. * python/libmu_py/mailcap.c: Likewise. * python/libmu_py/message.c: Likewise. * python/libmu_py/mime.c: Likewise. * python/libmu_py/sieve.c: Likewise. * python/libmu_py/stream.c: Likewise.
Showing
10 changed files
with
45 additions
and
49 deletions
... | @@ -183,7 +183,7 @@ api_address_get_count (PyObject *self, PyObject *args) | ... | @@ -183,7 +183,7 @@ api_address_get_count (PyObject *self, PyObject *args) |
183 | return NULL; | 183 | return NULL; |
184 | 184 | ||
185 | mu_address_get_count (py_addr->addr, &count); | 185 | mu_address_get_count (py_addr->addr, &count); |
186 | return _ro (PyInt_FromLong (count)); | 186 | return _ro (PyInt_FromSize_t (count)); |
187 | } | 187 | } |
188 | 188 | ||
189 | static PyObject * | 189 | static PyObject * | ... | ... |
... | @@ -201,42 +201,36 @@ _getattr4 (PyObject *self, char *name) | ... | @@ -201,42 +201,36 @@ _getattr4 (PyObject *self, char *name) |
201 | if (!ad) | 201 | if (!ad) |
202 | return NULL; | 202 | return NULL; |
203 | 203 | ||
204 | if (strcmp (name, "name") == 0) { | 204 | if (strcmp (name, "name") == 0) |
205 | return PyString_FromString (ad->name); | 205 | return PyString_FromString (ad->name); |
206 | } | 206 | else if (strcmp (name, "passwd") == 0) |
207 | else if (strcmp (name, "passwd") == 0) { | ||
208 | return PyString_FromString (ad->passwd); | 207 | return PyString_FromString (ad->passwd); |
209 | } | 208 | |
210 | else if (strcmp (name, "uid") == 0) { | 209 | /* FIXME: The use of PyInt_FromSize_t to convert uid_t and gid_t is |
211 | return PyInt_FromLong (ad->uid); | 210 | a bit dubious, but so far there's no other feasible way in Python, |
212 | } | 211 | save for converting uid (gid) to string and using PyInt_FromString. */ |
213 | else if (strcmp (name, "gid") == 0) { | 212 | else if (strcmp (name, "uid") == 0) |
214 | return PyInt_FromLong (ad->gid); | 213 | return PyInt_FromSize_t (ad->uid); |
215 | } | 214 | else if (strcmp (name, "gid") == 0) |
216 | else if (strcmp (name, "gecos") == 0) { | 215 | return PyInt_FromSize_t (ad->gid); |
216 | else if (strcmp (name, "gecos") == 0) | ||
217 | return PyString_FromString (ad->gecos); | 217 | return PyString_FromString (ad->gecos); |
218 | } | 218 | else if (strcmp (name, "dir") == 0) |
219 | else if (strcmp (name, "dir") == 0) { | ||
220 | return PyString_FromString (ad->dir); | 219 | return PyString_FromString (ad->dir); |
221 | } | 220 | else if (strcmp (name, "shell") == 0) |
222 | else if (strcmp (name, "shell") == 0) { | ||
223 | return PyString_FromString (ad->shell); | 221 | return PyString_FromString (ad->shell); |
224 | } | 222 | else if (strcmp (name, "mailbox") == 0) |
225 | else if (strcmp (name, "mailbox") == 0) { | ||
226 | return PyString_FromString (ad->mailbox); | 223 | return PyString_FromString (ad->mailbox); |
227 | } | 224 | else if (strcmp (name, "source") == 0) |
228 | else if (strcmp (name, "source") == 0) { | ||
229 | return PyString_FromString (ad->source); | 225 | return PyString_FromString (ad->source); |
230 | } | 226 | else if (strcmp (name, "quota") == 0) |
231 | else if (strcmp (name, "quota") == 0) { | 227 | /* FIXME: quota is mu_off_t rather than size_t. See comment for uid |
232 | return PyInt_FromLong (ad->quota); | 228 | above */ |
233 | } | 229 | return PyInt_FromSize_t (ad->quota); |
234 | else if (strcmp (name, "flags") == 0) { | 230 | else if (strcmp (name, "flags") == 0) |
235 | return PyInt_FromLong (ad->flags); | 231 | return PyInt_FromLong (ad->flags); |
236 | } | 232 | else if (strcmp (name, "change_uid") == 0) |
237 | else if (strcmp (name, "change_uid") == 0) { | ||
238 | return PyInt_FromLong (ad->change_uid); | 233 | return PyInt_FromLong (ad->change_uid); |
239 | } | ||
240 | return NULL; | 234 | return NULL; |
241 | } | 235 | } |
242 | 236 | ... | ... |
... | @@ -87,7 +87,7 @@ api_body_size (PyObject *self, PyObject *args) | ... | @@ -87,7 +87,7 @@ api_body_size (PyObject *self, PyObject *args) |
87 | return NULL; | 87 | return NULL; |
88 | 88 | ||
89 | status = mu_body_size (py_body->body, &size); | 89 | status = mu_body_size (py_body->body, &size); |
90 | return status_object (status, PyInt_FromLong (size)); | 90 | return status_object (status, PyInt_FromSize_t (size)); |
91 | } | 91 | } |
92 | 92 | ||
93 | static PyObject * | 93 | static PyObject * |
... | @@ -101,7 +101,7 @@ api_body_lines (PyObject *self, PyObject *args) | ... | @@ -101,7 +101,7 @@ api_body_lines (PyObject *self, PyObject *args) |
101 | return NULL; | 101 | return NULL; |
102 | 102 | ||
103 | status = mu_body_lines (py_body->body, &lines); | 103 | status = mu_body_lines (py_body->body, &lines); |
104 | return status_object (status, PyInt_FromLong (lines)); | 104 | return status_object (status, PyInt_FromSize_t (lines)); |
105 | } | 105 | } |
106 | 106 | ||
107 | static PyObject * | 107 | static PyObject * | ... | ... |
... | @@ -87,7 +87,7 @@ api_header_size (PyObject *self, PyObject *args) | ... | @@ -87,7 +87,7 @@ api_header_size (PyObject *self, PyObject *args) |
87 | return NULL; | 87 | return NULL; |
88 | 88 | ||
89 | status = mu_header_size (py_hdr->hdr, &size); | 89 | status = mu_header_size (py_hdr->hdr, &size); |
90 | return status_object (status, PyInt_FromLong (size)); | 90 | return status_object (status, PyInt_FromSize_t (size)); |
91 | } | 91 | } |
92 | 92 | ||
93 | static PyObject * | 93 | static PyObject * |
... | @@ -101,7 +101,7 @@ api_header_lines (PyObject *self, PyObject *args) | ... | @@ -101,7 +101,7 @@ api_header_lines (PyObject *self, PyObject *args) |
101 | return NULL; | 101 | return NULL; |
102 | 102 | ||
103 | status = mu_header_lines (py_hdr->hdr, &lines); | 103 | status = mu_header_lines (py_hdr->hdr, &lines); |
104 | return status_object (status, PyInt_FromLong (lines)); | 104 | return status_object (status, PyInt_FromSize_t (lines)); |
105 | } | 105 | } |
106 | 106 | ||
107 | static PyObject * | 107 | static PyObject * |
... | @@ -161,7 +161,7 @@ api_header_get_field_count (PyObject *self, PyObject *args) | ... | @@ -161,7 +161,7 @@ api_header_get_field_count (PyObject *self, PyObject *args) |
161 | return NULL; | 161 | return NULL; |
162 | 162 | ||
163 | status = mu_header_get_field_count (py_hdr->hdr, &count); | 163 | status = mu_header_get_field_count (py_hdr->hdr, &count); |
164 | return status_object (status, PyInt_FromLong (count)); | 164 | return status_object (status, PyInt_FromSize_t (count)); |
165 | } | 165 | } |
166 | 166 | ||
167 | static PyObject * | 167 | static PyObject * | ... | ... |
... | @@ -174,7 +174,7 @@ api_mailbox_messages_count (PyObject *self, PyObject *args) | ... | @@ -174,7 +174,7 @@ api_mailbox_messages_count (PyObject *self, PyObject *args) |
174 | return NULL; | 174 | return NULL; |
175 | 175 | ||
176 | status = mu_mailbox_messages_count (py_mbox->mbox, &total); | 176 | status = mu_mailbox_messages_count (py_mbox->mbox, &total); |
177 | return status_object (status, PyInt_FromLong (total)); | 177 | return status_object (status, PyInt_FromSize_t (total)); |
178 | } | 178 | } |
179 | 179 | ||
180 | static PyObject * | 180 | static PyObject * |
... | @@ -188,7 +188,7 @@ api_mailbox_messages_recent (PyObject *self, PyObject *args) | ... | @@ -188,7 +188,7 @@ api_mailbox_messages_recent (PyObject *self, PyObject *args) |
188 | return NULL; | 188 | return NULL; |
189 | 189 | ||
190 | status = mu_mailbox_messages_recent (py_mbox->mbox, &recent); | 190 | status = mu_mailbox_messages_recent (py_mbox->mbox, &recent); |
191 | return status_object (status, PyInt_FromLong (recent)); | 191 | return status_object (status, PyInt_FromSize_t (recent)); |
192 | } | 192 | } |
193 | 193 | ||
194 | static PyObject * | 194 | static PyObject * |
... | @@ -202,7 +202,7 @@ api_mailbox_message_unseen (PyObject *self, PyObject *args) | ... | @@ -202,7 +202,7 @@ api_mailbox_message_unseen (PyObject *self, PyObject *args) |
202 | return NULL; | 202 | return NULL; |
203 | 203 | ||
204 | status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen); | 204 | status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen); |
205 | return status_object (status, PyInt_FromLong (unseen)); | 205 | return status_object (status, PyInt_FromSize_t (unseen)); |
206 | } | 206 | } |
207 | 207 | ||
208 | static PyObject * | 208 | static PyObject * |
... | @@ -276,7 +276,7 @@ uidls_extractor (void *data, PyObject **dst) | ... | @@ -276,7 +276,7 @@ uidls_extractor (void *data, PyObject **dst) |
276 | struct mu_uidl *uidl = (struct mu_uidl *)data; | 276 | struct mu_uidl *uidl = (struct mu_uidl *)data; |
277 | 277 | ||
278 | *dst = PyTuple_New (2); | 278 | *dst = PyTuple_New (2); |
279 | PyTuple_SetItem (*dst, 0, PyInt_FromLong (uidl->msgno)); | 279 | PyTuple_SetItem (*dst, 0, PyInt_FromSize_t (uidl->msgno)); |
280 | PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl)); | 280 | PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl)); |
281 | return 0; | 281 | return 0; |
282 | } | 282 | } |
... | @@ -339,7 +339,9 @@ api_mailbox_get_size (PyObject *self, PyObject *args) | ... | @@ -339,7 +339,9 @@ api_mailbox_get_size (PyObject *self, PyObject *args) |
339 | return NULL; | 339 | return NULL; |
340 | 340 | ||
341 | status = mu_mailbox_get_size (py_mbox->mbox, &size); | 341 | status = mu_mailbox_get_size (py_mbox->mbox, &size); |
342 | return status_object (status, PyInt_FromLong (size)); | 342 | /* FIXME: Using PyInt_FromSize_t to convert mu_off_t can cause truncation |
343 | for very large mailboxes. */ | ||
344 | return status_object (status, PyInt_FromSize_t (size)); | ||
343 | } | 345 | } |
344 | 346 | ||
345 | static PyObject * | 347 | static PyObject * | ... | ... |
... | @@ -178,7 +178,7 @@ api_mailcap_entries_count (PyObject *self, PyObject *args) | ... | @@ -178,7 +178,7 @@ api_mailcap_entries_count (PyObject *self, PyObject *args) |
178 | return NULL; | 178 | return NULL; |
179 | 179 | ||
180 | status = mu_mailcap_entries_count (py_mc->mc, &count); | 180 | status = mu_mailcap_entries_count (py_mc->mc, &count); |
181 | return status_object (status, PyInt_FromLong (count)); | 181 | return status_object (status, PyInt_FromSize_t (count)); |
182 | } | 182 | } |
183 | 183 | ||
184 | static PyObject * | 184 | static PyObject * |
... | @@ -209,7 +209,7 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject *args) | ... | @@ -209,7 +209,7 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject *args) |
209 | return NULL; | 209 | return NULL; |
210 | 210 | ||
211 | status = mu_mailcap_entry_fields_count (py_entry->entry, &count); | 211 | status = mu_mailcap_entry_fields_count (py_entry->entry, &count); |
212 | return status_object (status, PyInt_FromLong (count)); | 212 | return status_object (status, PyInt_FromSize_t (count)); |
213 | } | 213 | } |
214 | 214 | ||
215 | static PyObject * | 215 | static PyObject * | ... | ... |
... | @@ -131,7 +131,7 @@ api_message_size (PyObject *self, PyObject *args) | ... | @@ -131,7 +131,7 @@ api_message_size (PyObject *self, PyObject *args) |
131 | return NULL; | 131 | return NULL; |
132 | 132 | ||
133 | status = mu_message_size (py_msg->msg, &size); | 133 | status = mu_message_size (py_msg->msg, &size); |
134 | return status_object (status, PyInt_FromLong (size)); | 134 | return status_object (status, PyInt_FromSize_t (size)); |
135 | } | 135 | } |
136 | 136 | ||
137 | static PyObject * | 137 | static PyObject * |
... | @@ -145,7 +145,7 @@ api_message_lines (PyObject *self, PyObject *args) | ... | @@ -145,7 +145,7 @@ api_message_lines (PyObject *self, PyObject *args) |
145 | return NULL; | 145 | return NULL; |
146 | 146 | ||
147 | status = mu_message_lines (py_msg->msg, &lines); | 147 | status = mu_message_lines (py_msg->msg, &lines); |
148 | return status_object (status, PyInt_FromLong (lines)); | 148 | return status_object (status, PyInt_FromSize_t (lines)); |
149 | } | 149 | } |
150 | 150 | ||
151 | static PyObject * | 151 | static PyObject * |
... | @@ -223,7 +223,7 @@ api_message_get_num_parts (PyObject *self, PyObject *args) | ... | @@ -223,7 +223,7 @@ api_message_get_num_parts (PyObject *self, PyObject *args) |
223 | return NULL; | 223 | return NULL; |
224 | 224 | ||
225 | status = mu_message_get_num_parts (py_msg->msg, &parts); | 225 | status = mu_message_get_num_parts (py_msg->msg, &parts); |
226 | return status_object (status, PyInt_FromLong (parts)); | 226 | return status_object (status, PyInt_FromSize_t (parts)); |
227 | } | 227 | } |
228 | 228 | ||
229 | static PyObject * | 229 | static PyObject * |
... | @@ -254,7 +254,7 @@ api_message_get_uid (PyObject *self, PyObject *args) | ... | @@ -254,7 +254,7 @@ api_message_get_uid (PyObject *self, PyObject *args) |
254 | return NULL; | 254 | return NULL; |
255 | 255 | ||
256 | status = mu_message_get_uid (py_msg->msg, &uid); | 256 | status = mu_message_get_uid (py_msg->msg, &uid); |
257 | return status_object (status, PyInt_FromLong (uid)); | 257 | return status_object (status, PyInt_FromSize_t (uid)); |
258 | } | 258 | } |
259 | 259 | ||
260 | static PyObject * | 260 | static PyObject * | ... | ... |
... | @@ -133,7 +133,7 @@ api_mime_get_num_parts (PyObject *self, PyObject *args) | ... | @@ -133,7 +133,7 @@ api_mime_get_num_parts (PyObject *self, PyObject *args) |
133 | return NULL; | 133 | return NULL; |
134 | 134 | ||
135 | status = mu_mime_get_num_parts (py_mime->mime, &nparts); | 135 | status = mu_mime_get_num_parts (py_mime->mime, &nparts); |
136 | return status_object (status, PyInt_FromLong (nparts)); | 136 | return status_object (status, PyInt_FromSize_t (nparts)); |
137 | } | 137 | } |
138 | 138 | ||
139 | static PyObject * | 139 | static PyObject * | ... | ... |
... | @@ -263,7 +263,7 @@ _sieve_action_printer (void *data, mu_stream_t stream, | ... | @@ -263,7 +263,7 @@ _sieve_action_printer (void *data, mu_stream_t stream, |
263 | Py_INCREF (py_msg); | 263 | Py_INCREF (py_msg); |
264 | 264 | ||
265 | PyDict_SetItemString (py_dict, "msgno", | 265 | PyDict_SetItemString (py_dict, "msgno", |
266 | PyInt_FromLong (msgno)); | 266 | PyInt_FromSize_t (msgno)); |
267 | PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg); | 267 | PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg); |
268 | PyDict_SetItemString (py_dict, "action", | 268 | PyDict_SetItemString (py_dict, "action", |
269 | PyString_FromString (action ? action : "")); | 269 | PyString_FromString (action ? action : "")); | ... | ... |
... | @@ -294,7 +294,7 @@ api_stream_read (PyObject *self, PyObject *args) | ... | @@ -294,7 +294,7 @@ api_stream_read (PyObject *self, PyObject *args) |
294 | py_ret = PyTuple_New (3); | 294 | py_ret = PyTuple_New (3); |
295 | PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status)); | 295 | PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status)); |
296 | PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf)); | 296 | PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf)); |
297 | PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count)); | 297 | PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count)); |
298 | return _ro (py_ret); | 298 | return _ro (py_ret); |
299 | } | 299 | } |
300 | 300 | ||
... | @@ -315,7 +315,7 @@ api_stream_write (PyObject *self, PyObject *args) | ... | @@ -315,7 +315,7 @@ api_stream_write (PyObject *self, PyObject *args) |
315 | return NULL; | 315 | return NULL; |
316 | } | 316 | } |
317 | status = mu_stream_write (py_stm->stm, wbuf, size, &write_count); | 317 | status = mu_stream_write (py_stm->stm, wbuf, size, &write_count); |
318 | return status_object (status, PyInt_FromLong (write_count)); | 318 | return status_object (status, PyInt_FromSize_t (write_count)); |
319 | } | 319 | } |
320 | 320 | ||
321 | static PyObject * | 321 | static PyObject * |
... | @@ -337,7 +337,7 @@ api_stream_readline (PyObject *self, PyObject *args) | ... | @@ -337,7 +337,7 @@ api_stream_readline (PyObject *self, PyObject *args) |
337 | py_ret = PyTuple_New (3); | 337 | py_ret = PyTuple_New (3); |
338 | PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status)); | 338 | PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status)); |
339 | PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf)); | 339 | PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf)); |
340 | PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count)); | 340 | PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count)); |
341 | return _ro (py_ret); | 341 | return _ro (py_ret); |
342 | } | 342 | } |
343 | 343 | ... | ... |
-
Please register or sign in to post a comment