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