mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
C extensions: fix use of self->ob_type everywhere
Part of general preparations for the python3 port.
This commit is contained in:
parent
acd683b3ac
commit
2761fd5bd0
@ -123,7 +123,7 @@ static uint16_t data_from_python(void *params, void *priv, uint32_t wantlen, uns
|
||||
static PyObject* build_file_metadata(LIBMTP_file_t *nf, uint32_t storage_id) {
|
||||
PyObject *ans = NULL;
|
||||
|
||||
ans = Py_BuildValue("{s:s, s:k, s:k, s:k, s:K, s:L, s:O}",
|
||||
ans = Py_BuildValue("{s:s, s:k, s:k, s:k, s:K, s:L, s:O}",
|
||||
"name", nf->filename,
|
||||
"id", (unsigned long)nf->item_id,
|
||||
"parent_id", (unsigned long)nf->parent_id,
|
||||
@ -184,7 +184,7 @@ Device_dealloc(Device* self)
|
||||
Py_XDECREF(self->serial_number); self->serial_number = NULL;
|
||||
Py_XDECREF(self->device_version); self->device_version = NULL;
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -225,9 +225,9 @@ Device_init(Device *self, PyObject *args, PyObject *kwds)
|
||||
}
|
||||
|
||||
if (rawdevs != NULL) free(rawdevs);
|
||||
if (dev == NULL) {
|
||||
if (tried_count == 0) PyErr_Format(MTPError, "No device with busnum=%lu and devnum=%u found", busnum, devnum);
|
||||
else PyErr_Format(MTPError, "Unable to open MTP device with busnum=%lu and devnum=%u, tried %d such devices", busnum, devnum, tried_count);
|
||||
if (dev == NULL) {
|
||||
if (tried_count == 0) PyErr_Format(MTPError, "No device with busnum=%lu and devnum=%u found", busnum, devnum);
|
||||
else PyErr_Format(MTPError, "Unable to open MTP device with busnum=%lu and devnum=%u, tried %d such devices", busnum, devnum, tried_count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -341,8 +341,8 @@ Device_storage_info(Device *self, void *closure) {
|
||||
// Check if read only storage
|
||||
if (storage->StorageType == ST_FixedROM || storage->StorageType == ST_RemovableROM || (storage->id & 0x0000FFFFU) == 0x00000000U || storage->AccessCapability == AC_ReadOnly || storage->AccessCapability == AC_ReadOnly_with_Object_Deletion) ro = 1;
|
||||
|
||||
loc = Py_BuildValue("{s:k,s:O,s:K,s:K,s:K,s:s,s:s,s:O}",
|
||||
"id", (unsigned long)storage->id,
|
||||
loc = Py_BuildValue("{s:k,s:O,s:K,s:K,s:K,s:s,s:s,s:O}",
|
||||
"id", (unsigned long)storage->id,
|
||||
"removable", ((storage->StorageType == ST_RemovableRAM) ? Py_True : Py_False),
|
||||
"capacity", (unsigned long long)storage->MaxCapacity,
|
||||
"freespace_bytes", (unsigned long long)storage->FreeSpaceInBytes,
|
||||
@ -352,7 +352,7 @@ Device_storage_info(Device *self, void *closure) {
|
||||
"rw", (ro) ? Py_False : Py_True
|
||||
);
|
||||
|
||||
if (loc == NULL) return NULL;
|
||||
if (loc == NULL) return NULL;
|
||||
if (PyList_Append(ans, loc) != 0) return NULL;
|
||||
Py_DECREF(loc);
|
||||
|
||||
@ -382,12 +382,12 @@ static int recursive_get_files(LIBMTP_mtpdevice_t *dev, uint32_t storage_id, uin
|
||||
recurse = (r != NULL && PyObject_IsTrue(r)) ? 1 : 0;
|
||||
Py_XDECREF(r);
|
||||
if (PyList_Append(ans, entry) != 0) { ok = 0; }
|
||||
Py_DECREF(entry);
|
||||
Py_DECREF(entry);
|
||||
}
|
||||
|
||||
if (ok && recurse && f->filetype == LIBMTP_FILETYPE_FOLDER) {
|
||||
if (!recursive_get_files(dev, storage_id, f->item_id, ans, errs, callback, level+1)) {
|
||||
ok = 0;
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -409,7 +409,7 @@ Device_get_filesystem(Device *self, PyObject *args) {
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "kO", &storage_id, &callback)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "kO", &storage_id, &callback)) return NULL;
|
||||
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback is not a callable"); return NULL; }
|
||||
ans = PyList_New(0);
|
||||
errs = PyList_New(0);
|
||||
@ -439,7 +439,7 @@ Device_get_file(Device *self, PyObject *args) {
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
|
||||
|
||||
if (!PyArg_ParseTuple(args, "kO|O", &fileid, &stream, &callback)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "kO|O", &fileid, &stream, &callback)) return NULL;
|
||||
errs = PyList_New(0);
|
||||
if (errs == NULL) { PyErr_NoMemory(); return NULL; }
|
||||
if (callback == NULL || !PyCallable_Check(callback)) callback = NULL;
|
||||
@ -451,7 +451,7 @@ Device_get_file(Device *self, PyObject *args) {
|
||||
PyEval_RestoreThread(cb.state);
|
||||
Py_XDECREF(callback); Py_DECREF(stream);
|
||||
|
||||
if (ret != 0) {
|
||||
if (ret != 0) {
|
||||
dump_errorstack(self->device, errs);
|
||||
}
|
||||
Py_XDECREF(PyObject_CallMethod(stream, "flush", NULL));
|
||||
@ -472,7 +472,7 @@ Device_put_file(Device *self, PyObject *args) {
|
||||
|
||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "kksOK|O", &storage_id, &parent_id, &name, &stream, &filesize, &callback)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "kksOK|O", &storage_id, &parent_id, &name, &stream, &filesize, &callback)) return NULL;
|
||||
errs = PyList_New(0);
|
||||
if (errs == NULL) { PyErr_NoMemory(); return NULL; }
|
||||
if (callback == NULL || !PyCallable_Check(callback)) callback = NULL;
|
||||
@ -569,32 +569,32 @@ static PyMethodDef Device_methods[] = {
|
||||
};
|
||||
|
||||
static PyGetSetDef Device_getsetters[] = {
|
||||
{(char *)"friendly_name",
|
||||
{(char *)"friendly_name",
|
||||
(getter)Device_friendly_name, NULL,
|
||||
(char *)"The friendly name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"manufacturer_name",
|
||||
{(char *)"manufacturer_name",
|
||||
(getter)Device_manufacturer_name, NULL,
|
||||
(char *)"The manufacturer name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"model_name",
|
||||
{(char *)"model_name",
|
||||
(getter)Device_model_name, NULL,
|
||||
(char *)"The model name of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"serial_number",
|
||||
{(char *)"serial_number",
|
||||
(getter)Device_serial_number, NULL,
|
||||
(char *)"The serial number of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"device_version",
|
||||
{(char *)"device_version",
|
||||
(getter)Device_device_version, NULL,
|
||||
(char *)"The device version of this device, can be None.",
|
||||
NULL},
|
||||
|
||||
{(char *)"ids",
|
||||
{(char *)"ids",
|
||||
(getter)Device_ids, NULL,
|
||||
(char *)"The ids of the device (busnum, devnum, vendor_id, product_id, usb_serialnum)",
|
||||
NULL},
|
||||
@ -719,7 +719,7 @@ initlibmtp(void) {
|
||||
DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&DeviceType) < 0)
|
||||
return;
|
||||
|
||||
|
||||
m = Py_InitModule3("libmtp", libmtp_methods, "Interface to libmtp.");
|
||||
if (m == NULL) return;
|
||||
|
||||
|
@ -21,10 +21,10 @@ dealloc(Device* self)
|
||||
|
||||
if (self->bulk_properties != NULL) { self->bulk_properties->Release(); self->bulk_properties = NULL; }
|
||||
|
||||
if (self->device != NULL) {
|
||||
if (self->device != NULL) {
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
self->device->Close(); self->device->Release();
|
||||
self->device = NULL;
|
||||
self->device = NULL;
|
||||
Py_END_ALLOW_THREADS;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ dealloc(Device* self)
|
||||
|
||||
Py_XDECREF(self->device_information); self->device_information = NULL;
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -74,7 +74,7 @@ update_data(Device *self, PyObject *args) {
|
||||
Py_XDECREF(self->device_information); self->device_information = di;
|
||||
Py_RETURN_NONE;
|
||||
} // }}}
|
||||
|
||||
|
||||
// get_filesystem() {{{
|
||||
static PyObject*
|
||||
py_get_filesystem(Device *self, PyObject *args) {
|
||||
@ -194,7 +194,7 @@ Device_data(Device *self, void *closure) {
|
||||
|
||||
|
||||
static PyGetSetDef Device_getsetters[] = {
|
||||
{(char *)"data",
|
||||
{(char *)"data",
|
||||
(getter)Device_data, NULL,
|
||||
(char *)"The basic device information.",
|
||||
NULL},
|
||||
@ -244,4 +244,3 @@ PyTypeObject wpd::DeviceType = { // {{{
|
||||
0, /* tp_alloc */
|
||||
0, /* tp_new */
|
||||
}; // }}}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
static PyObject *FreeTypeError = NULL;
|
||||
@ -47,7 +47,7 @@ Face_dealloc(Face* self)
|
||||
Py_XDECREF(self->data);
|
||||
self->data = NULL;
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -84,12 +84,12 @@ Face_init(Face *self, PyObject *args, PyObject *kwds)
|
||||
static PyObject *
|
||||
family_name(Face *self, void *closure) {
|
||||
return Py_BuildValue("s", self->face->family_name);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
style_name(Face *self, void *closure) {
|
||||
return Py_BuildValue("s", self->face->style_name);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
supports_text(Face *self, PyObject *args) {
|
||||
@ -124,12 +124,12 @@ glyph_id(Face *self, PyObject *args) {
|
||||
}
|
||||
|
||||
static PyGetSetDef Face_getsetters[] = {
|
||||
{(char *)"family_name",
|
||||
{(char *)"family_name",
|
||||
(getter)family_name, NULL,
|
||||
(char *)"The family name of this font.",
|
||||
NULL},
|
||||
|
||||
{(char *)"style_name",
|
||||
{(char *)"style_name",
|
||||
(getter)style_name, NULL,
|
||||
(char *)"The style name of this font.",
|
||||
NULL},
|
||||
@ -160,7 +160,7 @@ dealloc(FreeType* self)
|
||||
}
|
||||
self->library = NULL;
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -288,7 +288,7 @@ static PyTypeObject FreeTypeType = { // {{{
|
||||
0, /* tp_new */
|
||||
}; // }}}
|
||||
|
||||
static
|
||||
static
|
||||
PyMethodDef methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
@ -319,4 +319,3 @@ initfreetype(void) {
|
||||
PyModule_AddObject(m, "FreeType", (PyObject *)&FreeTypeType);
|
||||
PyModule_AddObject(m, "Face", (PyObject *)&FaceType);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ static void
|
||||
PDFDoc_dealloc(PDFDoc* self)
|
||||
{
|
||||
if (self->doc != NULL) delete self->doc;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -13,7 +13,7 @@ using namespace pdf;
|
||||
static void
|
||||
dealloc(PDFOutlineItem* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
@ -138,5 +138,3 @@ PyTypeObject pdf::PDFOutlineItemType = {
|
||||
|
||||
};
|
||||
// }}}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user