26
26
27
27
void pysqlite_row_dealloc (pysqlite_Row * self )
28
28
{
29
+ PyTypeObject * tp = Py_TYPE (self );
30
+
29
31
Py_XDECREF (self -> data );
30
32
Py_XDECREF (self -> description );
31
33
32
- Py_TYPE (self )-> tp_free ((PyObject * )self );
34
+ tp -> tp_free (self );
35
+ Py_DECREF (tp );
33
36
}
34
37
35
38
static PyObject *
@@ -192,7 +195,7 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
192
195
if (opid != Py_EQ && opid != Py_NE )
193
196
Py_RETURN_NOTIMPLEMENTED ;
194
197
195
- if (PyObject_TypeCheck (_other , & pysqlite_RowType )) {
198
+ if (PyObject_TypeCheck (_other , pysqlite_RowType )) {
196
199
pysqlite_Row * other = (pysqlite_Row * )_other ;
197
200
int eq = PyObject_RichCompareBool (self -> description , other -> description , Py_EQ );
198
201
if (eq < 0 ) {
@@ -206,73 +209,40 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
206
209
Py_RETURN_NOTIMPLEMENTED ;
207
210
}
208
211
209
- PyMappingMethods pysqlite_row_as_mapping = {
210
- /* mp_length */ (lenfunc )pysqlite_row_length ,
211
- /* mp_subscript */ (binaryfunc )pysqlite_row_subscript ,
212
- /* mp_ass_subscript */ (objobjargproc )0 ,
213
- };
214
-
215
- static PySequenceMethods pysqlite_row_as_sequence = {
216
- /* sq_length */ (lenfunc )pysqlite_row_length ,
217
- /* sq_concat */ 0 ,
218
- /* sq_repeat */ 0 ,
219
- /* sq_item */ (ssizeargfunc )pysqlite_row_item ,
220
- };
221
-
222
-
223
- static PyMethodDef pysqlite_row_methods [] = {
212
+ static PyMethodDef row_methods [] = {
224
213
{"keys" , (PyCFunction )pysqlite_row_keys , METH_NOARGS ,
225
214
PyDoc_STR ("Returns the keys of the row." )},
226
215
{NULL , NULL }
227
216
};
228
217
218
+ static PyType_Slot row_slots [] = {
219
+ {Py_tp_dealloc , pysqlite_row_dealloc },
220
+ {Py_tp_hash , pysqlite_row_hash },
221
+ {Py_tp_methods , row_methods },
222
+ {Py_tp_richcompare , pysqlite_row_richcompare },
223
+ {Py_tp_iter , pysqlite_iter },
224
+ {Py_mp_length , pysqlite_row_length },
225
+ {Py_mp_subscript , pysqlite_row_subscript },
226
+ {Py_sq_length , pysqlite_row_length },
227
+ {Py_sq_item , pysqlite_row_item },
228
+ {Py_tp_new , pysqlite_row_new },
229
+ {0 , NULL },
230
+ };
229
231
230
- PyTypeObject pysqlite_RowType = {
231
- PyVarObject_HEAD_INIT (NULL , 0 )
232
- MODULE_NAME ".Row" , /* tp_name */
233
- sizeof (pysqlite_Row ), /* tp_basicsize */
234
- 0 , /* tp_itemsize */
235
- (destructor )pysqlite_row_dealloc , /* tp_dealloc */
236
- 0 , /* tp_vectorcall_offset */
237
- 0 , /* tp_getattr */
238
- 0 , /* tp_setattr */
239
- 0 , /* tp_as_async */
240
- 0 , /* tp_repr */
241
- 0 , /* tp_as_number */
242
- 0 , /* tp_as_sequence */
243
- 0 , /* tp_as_mapping */
244
- (hashfunc )pysqlite_row_hash , /* tp_hash */
245
- 0 , /* tp_call */
246
- 0 , /* tp_str */
247
- 0 , /* tp_getattro */
248
- 0 , /* tp_setattro */
249
- 0 , /* tp_as_buffer */
250
- Py_TPFLAGS_DEFAULT |Py_TPFLAGS_BASETYPE , /* tp_flags */
251
- 0 , /* tp_doc */
252
- (traverseproc )0 , /* tp_traverse */
253
- 0 , /* tp_clear */
254
- (richcmpfunc )pysqlite_row_richcompare , /* tp_richcompare */
255
- 0 , /* tp_weaklistoffset */
256
- (getiterfunc )pysqlite_iter , /* tp_iter */
257
- 0 , /* tp_iternext */
258
- pysqlite_row_methods , /* tp_methods */
259
- 0 , /* tp_members */
260
- 0 , /* tp_getset */
261
- 0 , /* tp_base */
262
- 0 , /* tp_dict */
263
- 0 , /* tp_descr_get */
264
- 0 , /* tp_descr_set */
265
- 0 , /* tp_dictoffset */
266
- 0 , /* tp_init */
267
- 0 , /* tp_alloc */
268
- 0 , /* tp_new */
269
- 0 /* tp_free */
232
+ static PyType_Spec row_spec = {
233
+ .name = MODULE_NAME ".Row" ,
234
+ .basicsize = sizeof (pysqlite_Row ),
235
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
236
+ .slots = row_slots ,
270
237
};
271
238
272
- extern int pysqlite_row_setup_types (void )
239
+ PyTypeObject * pysqlite_RowType = NULL ;
240
+
241
+ extern int pysqlite_row_setup_types (PyObject * module )
273
242
{
274
- pysqlite_RowType .tp_new = pysqlite_row_new ;
275
- pysqlite_RowType .tp_as_mapping = & pysqlite_row_as_mapping ;
276
- pysqlite_RowType .tp_as_sequence = & pysqlite_row_as_sequence ;
277
- return PyType_Ready (& pysqlite_RowType );
243
+ pysqlite_RowType = (PyTypeObject * )PyType_FromModuleAndSpec (module , & row_spec , NULL );
244
+ if (pysqlite_RowType == NULL ) {
245
+ return -1 ;
246
+ }
247
+ return 0 ;
278
248
}
0 commit comments