@@ -371,6 +371,8 @@ void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
371
371
372
372
void pysqlite_statement_dealloc (pysqlite_Statement * self )
373
373
{
374
+ PyTypeObject * tp = Py_TYPE (self );
375
+
374
376
if (self -> st ) {
375
377
Py_BEGIN_ALLOW_THREADS
376
378
sqlite3_finalize (self -> st );
@@ -385,7 +387,8 @@ void pysqlite_statement_dealloc(pysqlite_Statement* self)
385
387
PyObject_ClearWeakRefs ((PyObject * )self );
386
388
}
387
389
388
- Py_TYPE (self )-> tp_free ((PyObject * )self );
390
+ tp -> tp_free (self );
391
+ Py_DECREF (tp );
389
392
}
390
393
391
394
/*
@@ -458,50 +461,30 @@ static int pysqlite_check_remaining_sql(const char* tail)
458
461
return 0 ;
459
462
}
460
463
461
- PyTypeObject pysqlite_StatementType = {
462
- PyVarObject_HEAD_INIT (NULL , 0 )
463
- MODULE_NAME ".Statement" , /* tp_name */
464
- sizeof (pysqlite_Statement ), /* tp_basicsize */
465
- 0 , /* tp_itemsize */
466
- (destructor )pysqlite_statement_dealloc , /* tp_dealloc */
467
- 0 , /* tp_vectorcall_offset */
468
- 0 , /* tp_getattr */
469
- 0 , /* tp_setattr */
470
- 0 , /* tp_as_async */
471
- 0 , /* tp_repr */
472
- 0 , /* tp_as_number */
473
- 0 , /* tp_as_sequence */
474
- 0 , /* tp_as_mapping */
475
- 0 , /* tp_hash */
476
- 0 , /* tp_call */
477
- 0 , /* tp_str */
478
- 0 , /* tp_getattro */
479
- 0 , /* tp_setattro */
480
- 0 , /* tp_as_buffer */
481
- Py_TPFLAGS_DEFAULT , /* tp_flags */
482
- 0 , /* tp_doc */
483
- 0 , /* tp_traverse */
484
- 0 , /* tp_clear */
485
- 0 , /* tp_richcompare */
486
- offsetof(pysqlite_Statement , in_weakreflist ), /* tp_weaklistoffset */
487
- 0 , /* tp_iter */
488
- 0 , /* tp_iternext */
489
- 0 , /* tp_methods */
490
- 0 , /* tp_members */
491
- 0 , /* tp_getset */
492
- 0 , /* tp_base */
493
- 0 , /* tp_dict */
494
- 0 , /* tp_descr_get */
495
- 0 , /* tp_descr_set */
496
- 0 , /* tp_dictoffset */
497
- (initproc )0 , /* tp_init */
498
- 0 , /* tp_alloc */
499
- 0 , /* tp_new */
500
- 0 /* tp_free */
464
+ static PyMemberDef stmt_members [] = {
465
+ {"__weaklistoffset__" , T_PYSSIZET , offsetof(pysqlite_Statement , in_weakreflist ), READONLY },
466
+ {NULL },
467
+ };
468
+ static PyType_Slot stmt_slots [] = {
469
+ {Py_tp_members , stmt_members },
470
+ {Py_tp_dealloc , pysqlite_statement_dealloc },
471
+ {Py_tp_new , PyType_GenericNew },
472
+ {0 , NULL },
473
+ };
474
+
475
+ static PyType_Spec stmt_spec = {
476
+ .name = MODULE_NAME ".Statement" ,
477
+ .basicsize = sizeof (pysqlite_Statement ),
478
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE ,
479
+ .slots = stmt_slots ,
501
480
};
481
+ PyTypeObject * pysqlite_StatementType = NULL ;
502
482
503
- extern int pysqlite_statement_setup_types (void )
483
+ extern int pysqlite_statement_setup_types (PyObject * module )
504
484
{
505
- pysqlite_StatementType .tp_new = PyType_GenericNew ;
506
- return PyType_Ready (& pysqlite_StatementType );
485
+ pysqlite_StatementType = (PyTypeObject * )PyType_FromModuleAndSpec (module , & stmt_spec , NULL );
486
+ if (pysqlite_StatementType == NULL ) {
487
+ return -1 ;
488
+ }
489
+ return 0 ;
507
490
}
0 commit comments