@@ -220,6 +220,8 @@ void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset
220220
221221void pysqlite_connection_dealloc (pysqlite_Connection * self )
222222{
223+ PyTypeObject * tp = Py_TYPE (self );
224+
223225 Py_XDECREF (self -> statement_cache );
224226
225227 /* Clean up if user has not called .close() explicitly. */
@@ -236,7 +238,9 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
236238 Py_XDECREF (self -> collations );
237239 Py_XDECREF (self -> statements );
238240 Py_XDECREF (self -> cursors );
239- Py_TYPE (self )-> tp_free ((PyObject * )self );
241+
242+ tp -> tp_free (self );
243+ Py_DECREF (tp );
240244}
241245
242246/*
@@ -281,13 +285,13 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args,
281285 }
282286
283287 if (factory == NULL ) {
284- factory = (PyObject * )& pysqlite_CursorType ;
288+ factory = (PyObject * )pysqlite_CursorType ;
285289 }
286290
287291 cursor = PyObject_CallOneArg (factory , (PyObject * )self );
288292 if (cursor == NULL )
289293 return NULL ;
290- if (!PyObject_TypeCheck (cursor , & pysqlite_CursorType )) {
294+ if (!PyObject_TypeCheck (cursor , pysqlite_CursorType )) {
291295 PyErr_Format (PyExc_TypeError ,
292296 "factory must return a cursor, not %.100s" ,
293297 Py_TYPE (cursor )-> tp_name );
@@ -1494,7 +1498,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
14941498 static char * keywords [] = {"target" , "pages" , "progress" , "name" , "sleep" , NULL };
14951499
14961500 if (!PyArg_ParseTupleAndKeywords (args , kwds , "O!|$iOsO:backup" , keywords ,
1497- & pysqlite_ConnectionType , & target ,
1501+ pysqlite_ConnectionType , & target ,
14981502 & pages , & progress , & name , & sleep_obj )) {
14991503 return NULL ;
15001504 }
@@ -1831,50 +1835,32 @@ static struct PyMemberDef connection_members[] =
18311835 {NULL }
18321836};
18331837
1834- PyTypeObject pysqlite_ConnectionType = {
1835- PyVarObject_HEAD_INIT (NULL , 0 )
1836- MODULE_NAME ".Connection" , /* tp_name */
1837- sizeof (pysqlite_Connection ), /* tp_basicsize */
1838- 0 , /* tp_itemsize */
1839- (destructor )pysqlite_connection_dealloc , /* tp_dealloc */
1840- 0 , /* tp_vectorcall_offset */
1841- 0 , /* tp_getattr */
1842- 0 , /* tp_setattr */
1843- 0 , /* tp_as_async */
1844- 0 , /* tp_repr */
1845- 0 , /* tp_as_number */
1846- 0 , /* tp_as_sequence */
1847- 0 , /* tp_as_mapping */
1848- 0 , /* tp_hash */
1849- (ternaryfunc )pysqlite_connection_call , /* tp_call */
1850- 0 , /* tp_str */
1851- 0 , /* tp_getattro */
1852- 0 , /* tp_setattro */
1853- 0 , /* tp_as_buffer */
1854- Py_TPFLAGS_DEFAULT |Py_TPFLAGS_BASETYPE , /* tp_flags */
1855- connection_doc , /* tp_doc */
1856- 0 , /* tp_traverse */
1857- 0 , /* tp_clear */
1858- 0 , /* tp_richcompare */
1859- 0 , /* tp_weaklistoffset */
1860- 0 , /* tp_iter */
1861- 0 , /* tp_iternext */
1862- connection_methods , /* tp_methods */
1863- connection_members , /* tp_members */
1864- connection_getset , /* tp_getset */
1865- 0 , /* tp_base */
1866- 0 , /* tp_dict */
1867- 0 , /* tp_descr_get */
1868- 0 , /* tp_descr_set */
1869- 0 , /* tp_dictoffset */
1870- (initproc )pysqlite_connection_init , /* tp_init */
1871- 0 , /* tp_alloc */
1872- 0 , /* tp_new */
1873- 0 /* tp_free */
1838+ static PyType_Slot connection_slots [] = {
1839+ {Py_tp_dealloc , pysqlite_connection_dealloc },
1840+ {Py_tp_doc , (void * )connection_doc },
1841+ {Py_tp_methods , connection_methods },
1842+ {Py_tp_members , connection_members },
1843+ {Py_tp_getset , connection_getset },
1844+ {Py_tp_new , PyType_GenericNew },
1845+ {Py_tp_init , pysqlite_connection_init },
1846+ {Py_tp_call , pysqlite_connection_call },
1847+ {0 , NULL },
1848+ };
1849+
1850+ static PyType_Spec connection_spec = {
1851+ .name = MODULE_NAME ".Connection" ,
1852+ .basicsize = sizeof (pysqlite_Connection ),
1853+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
1854+ .slots = connection_slots ,
18741855};
18751856
1876- extern int pysqlite_connection_setup_types (void )
1857+ PyTypeObject * pysqlite_ConnectionType = NULL ;
1858+
1859+ extern int pysqlite_connection_setup_types (PyObject * module )
18771860{
1878- pysqlite_ConnectionType .tp_new = PyType_GenericNew ;
1879- return PyType_Ready (& pysqlite_ConnectionType );
1861+ pysqlite_ConnectionType = (PyTypeObject * )PyType_FromModuleAndSpec (module , & connection_spec , NULL );
1862+ if (pysqlite_ConnectionType == NULL ) {
1863+ return -1 ;
1864+ }
1865+ return 0 ;
18801866}
0 commit comments