Commit 1236f0ab 1236f0ab24b50e76da6554c305dedda8a1e6d8bb by Sergey Poznyakoff

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.
1 parent 37944b11
......@@ -183,7 +183,7 @@ api_address_get_count (PyObject *self, PyObject *args)
return NULL;
mu_address_get_count (py_addr->addr, &count);
return _ro (PyInt_FromLong (count));
return _ro (PyInt_FromSize_t (count));
}
static PyObject *
......
......@@ -201,42 +201,36 @@ _getattr4 (PyObject *self, char *name)
if (!ad)
return NULL;
if (strcmp (name, "name") == 0) {
if (strcmp (name, "name") == 0)
return PyString_FromString (ad->name);
}
else if (strcmp (name, "passwd") == 0) {
else if (strcmp (name, "passwd") == 0)
return PyString_FromString (ad->passwd);
}
else if (strcmp (name, "uid") == 0) {
return PyInt_FromLong (ad->uid);
}
else if (strcmp (name, "gid") == 0) {
return PyInt_FromLong (ad->gid);
}
else if (strcmp (name, "gecos") == 0) {
/* FIXME: The use of PyInt_FromSize_t to convert uid_t and gid_t is
a bit dubious, but so far there's no other feasible way in Python,
save for converting uid (gid) to string and using PyInt_FromString. */
else if (strcmp (name, "uid") == 0)
return PyInt_FromSize_t (ad->uid);
else if (strcmp (name, "gid") == 0)
return PyInt_FromSize_t (ad->gid);
else if (strcmp (name, "gecos") == 0)
return PyString_FromString (ad->gecos);
}
else if (strcmp (name, "dir") == 0) {
else if (strcmp (name, "dir") == 0)
return PyString_FromString (ad->dir);
}
else if (strcmp (name, "shell") == 0) {
else if (strcmp (name, "shell") == 0)
return PyString_FromString (ad->shell);
}
else if (strcmp (name, "mailbox") == 0) {
else if (strcmp (name, "mailbox") == 0)
return PyString_FromString (ad->mailbox);
}
else if (strcmp (name, "source") == 0) {
else if (strcmp (name, "source") == 0)
return PyString_FromString (ad->source);
}
else if (strcmp (name, "quota") == 0) {
return PyInt_FromLong (ad->quota);
}
else if (strcmp (name, "flags") == 0) {
else if (strcmp (name, "quota") == 0)
/* FIXME: quota is mu_off_t rather than size_t. See comment for uid
above */
return PyInt_FromSize_t (ad->quota);
else if (strcmp (name, "flags") == 0)
return PyInt_FromLong (ad->flags);
}
else if (strcmp (name, "change_uid") == 0) {
else if (strcmp (name, "change_uid") == 0)
return PyInt_FromLong (ad->change_uid);
}
return NULL;
}
......
......@@ -87,7 +87,7 @@ api_body_size (PyObject *self, PyObject *args)
return NULL;
status = mu_body_size (py_body->body, &size);
return status_object (status, PyInt_FromLong (size));
return status_object (status, PyInt_FromSize_t (size));
}
static PyObject *
......@@ -101,7 +101,7 @@ api_body_lines (PyObject *self, PyObject *args)
return NULL;
status = mu_body_lines (py_body->body, &lines);
return status_object (status, PyInt_FromLong (lines));
return status_object (status, PyInt_FromSize_t (lines));
}
static PyObject *
......
......@@ -87,7 +87,7 @@ api_header_size (PyObject *self, PyObject *args)
return NULL;
status = mu_header_size (py_hdr->hdr, &size);
return status_object (status, PyInt_FromLong (size));
return status_object (status, PyInt_FromSize_t (size));
}
static PyObject *
......@@ -101,7 +101,7 @@ api_header_lines (PyObject *self, PyObject *args)
return NULL;
status = mu_header_lines (py_hdr->hdr, &lines);
return status_object (status, PyInt_FromLong (lines));
return status_object (status, PyInt_FromSize_t (lines));
}
static PyObject *
......@@ -161,7 +161,7 @@ api_header_get_field_count (PyObject *self, PyObject *args)
return NULL;
status = mu_header_get_field_count (py_hdr->hdr, &count);
return status_object (status, PyInt_FromLong (count));
return status_object (status, PyInt_FromSize_t (count));
}
static PyObject *
......
......@@ -174,7 +174,7 @@ api_mailbox_messages_count (PyObject *self, PyObject *args)
return NULL;
status = mu_mailbox_messages_count (py_mbox->mbox, &total);
return status_object (status, PyInt_FromLong (total));
return status_object (status, PyInt_FromSize_t (total));
}
static PyObject *
......@@ -188,7 +188,7 @@ api_mailbox_messages_recent (PyObject *self, PyObject *args)
return NULL;
status = mu_mailbox_messages_recent (py_mbox->mbox, &recent);
return status_object (status, PyInt_FromLong (recent));
return status_object (status, PyInt_FromSize_t (recent));
}
static PyObject *
......@@ -202,7 +202,7 @@ api_mailbox_message_unseen (PyObject *self, PyObject *args)
return NULL;
status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen);
return status_object (status, PyInt_FromLong (unseen));
return status_object (status, PyInt_FromSize_t (unseen));
}
static PyObject *
......@@ -276,7 +276,7 @@ uidls_extractor (void *data, PyObject **dst)
struct mu_uidl *uidl = (struct mu_uidl *)data;
*dst = PyTuple_New (2);
PyTuple_SetItem (*dst, 0, PyInt_FromLong (uidl->msgno));
PyTuple_SetItem (*dst, 0, PyInt_FromSize_t (uidl->msgno));
PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl));
return 0;
}
......@@ -339,7 +339,9 @@ api_mailbox_get_size (PyObject *self, PyObject *args)
return NULL;
status = mu_mailbox_get_size (py_mbox->mbox, &size);
return status_object (status, PyInt_FromLong (size));
/* FIXME: Using PyInt_FromSize_t to convert mu_off_t can cause truncation
for very large mailboxes. */
return status_object (status, PyInt_FromSize_t (size));
}
static PyObject *
......
......@@ -178,7 +178,7 @@ api_mailcap_entries_count (PyObject *self, PyObject *args)
return NULL;
status = mu_mailcap_entries_count (py_mc->mc, &count);
return status_object (status, PyInt_FromLong (count));
return status_object (status, PyInt_FromSize_t (count));
}
static PyObject *
......@@ -209,7 +209,7 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject *args)
return NULL;
status = mu_mailcap_entry_fields_count (py_entry->entry, &count);
return status_object (status, PyInt_FromLong (count));
return status_object (status, PyInt_FromSize_t (count));
}
static PyObject *
......
......@@ -131,7 +131,7 @@ api_message_size (PyObject *self, PyObject *args)
return NULL;
status = mu_message_size (py_msg->msg, &size);
return status_object (status, PyInt_FromLong (size));
return status_object (status, PyInt_FromSize_t (size));
}
static PyObject *
......@@ -145,7 +145,7 @@ api_message_lines (PyObject *self, PyObject *args)
return NULL;
status = mu_message_lines (py_msg->msg, &lines);
return status_object (status, PyInt_FromLong (lines));
return status_object (status, PyInt_FromSize_t (lines));
}
static PyObject *
......@@ -223,7 +223,7 @@ api_message_get_num_parts (PyObject *self, PyObject *args)
return NULL;
status = mu_message_get_num_parts (py_msg->msg, &parts);
return status_object (status, PyInt_FromLong (parts));
return status_object (status, PyInt_FromSize_t (parts));
}
static PyObject *
......@@ -254,7 +254,7 @@ api_message_get_uid (PyObject *self, PyObject *args)
return NULL;
status = mu_message_get_uid (py_msg->msg, &uid);
return status_object (status, PyInt_FromLong (uid));
return status_object (status, PyInt_FromSize_t (uid));
}
static PyObject *
......
......@@ -133,7 +133,7 @@ api_mime_get_num_parts (PyObject *self, PyObject *args)
return NULL;
status = mu_mime_get_num_parts (py_mime->mime, &nparts);
return status_object (status, PyInt_FromLong (nparts));
return status_object (status, PyInt_FromSize_t (nparts));
}
static PyObject *
......
......@@ -263,7 +263,7 @@ _sieve_action_printer (void *data, mu_stream_t stream,
Py_INCREF (py_msg);
PyDict_SetItemString (py_dict, "msgno",
PyInt_FromLong (msgno));
PyInt_FromSize_t (msgno));
PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg);
PyDict_SetItemString (py_dict, "action",
PyString_FromString (action ? action : ""));
......
......@@ -294,7 +294,7 @@ api_stream_read (PyObject *self, PyObject *args)
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count));
return _ro (py_ret);
}
......@@ -315,7 +315,7 @@ api_stream_write (PyObject *self, PyObject *args)
return NULL;
}
status = mu_stream_write (py_stm->stm, wbuf, size, &write_count);
return status_object (status, PyInt_FromLong (write_count));
return status_object (status, PyInt_FromSize_t (write_count));
}
static PyObject *
......@@ -337,7 +337,7 @@ api_stream_readline (PyObject *self, PyObject *args)
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count));
return _ro (py_ret);
}
......