15
15
16
16
static void
17
17
dtypemeta_dealloc (PyArray_DTypeMeta * self ) {
18
- /*
19
- * PyType_Type asserts Py_TPFLAGS_HEAPTYPE as well. Do not rely on
20
- * a python debug build though.
21
- */
18
+ /* Do not accidentally delete a statically defined DType: */
22
19
assert (((PyTypeObject * )self )-> tp_flags & Py_TPFLAGS_HEAPTYPE );
20
+
23
21
Py_XDECREF (self -> scalar_type );
22
+ Py_XDECREF (self -> singleton );
24
23
PyType_Type .tp_dealloc ((PyObject * ) self );
25
24
}
26
25
27
26
static PyObject *
28
- dtypemeta_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
27
+ dtypemeta_new (PyTypeObject * NPY_UNUSED (type ),
28
+ PyObject * NPY_UNUSED (args ), PyObject * NPY_UNUSED (kwds ))
29
29
{
30
30
PyErr_SetString (PyExc_TypeError ,
31
31
"Preliminary-API: Cannot subclass DType." );
32
32
return NULL ;
33
33
}
34
34
35
35
static int
36
- dtypemeta_init (PyTypeObject * type , PyObject * args , PyObject * kwds )
36
+ dtypemeta_init (PyTypeObject * NPY_UNUSED (type ),
37
+ PyObject * NPY_UNUSED (args ), PyObject * NPY_UNUSED (kwds ))
37
38
{
38
39
PyErr_SetString (PyExc_TypeError ,
39
- "Preliminary-API: Cannot initialize DType class." );
40
+ "Preliminary-API: Cannot __init__ DType class." );
40
41
return -1 ;
41
42
}
42
43
@@ -46,8 +47,8 @@ dtypemeta_init(PyTypeObject *type, PyObject *args, PyObject *kwds)
46
47
*
47
48
* Python Type objects are either statically created (typical C-Extension type)
48
49
* or HeapTypes (typically created in Python).
49
- * HeapTypes have the Py_TPFLAGS_HEAPTYPE flag, and are garbage collected, our
50
- * DTypeMeta instances (`np.dtype` and its subclasses) *may* be HeapTypes
50
+ * HeapTypes have the Py_TPFLAGS_HEAPTYPE flag and are garbage collected.
51
+ * Our DTypeMeta instances (`np.dtype` and its subclasses) *may* be HeapTypes
51
52
* if the Py_TPFLAGS_HEAPTYPE flag is set (they are created from Python).
52
53
* They are not for legacy DTypes or np.dtype itself.
53
54
*
@@ -67,10 +68,12 @@ dtypemeta_traverse(PyArray_DTypeMeta *type, visitproc visit, void *arg)
67
68
/*
68
69
* We have to traverse the base class (if it is a HeapType).
69
70
* PyType_Type will handle this logic for us.
70
- * This function is currently not used, but may be necessary in the future
71
- * when we implement HeapTypes (python/dynamically defined types).
71
+ * This function is currently not used, but will probably be necessary
72
+ * in the future when we implement HeapTypes (python/dynamically
73
+ * defined types). It should be revised at that time.
72
74
*/
73
- assert (!type -> is_legacy && (PyTypeObject * )type != & PyArrayDescr_Type );
75
+ assert (0 );
76
+ assert (!type -> legacy && (PyTypeObject * )type != & PyArrayDescr_Type );
74
77
Py_VISIT (type -> singleton );
75
78
Py_VISIT (type -> scalar_type );
76
79
return PyType_Type .tp_traverse ((PyObject * )type , visit , arg );
@@ -82,7 +85,7 @@ legacy_dtype_default_new(PyArray_DTypeMeta *self,
82
85
PyObject * args , PyObject * kwargs )
83
86
{
84
87
/* TODO: This should allow endianess and possibly metadata */
85
- if (self -> is_parametric ) {
88
+ if (self -> parametric ) {
86
89
/* reject parametric ones since we would need to get unit, etc. info */
87
90
PyErr_Format (PyExc_TypeError ,
88
91
"Preliminary-API: Flexible/Parametric legacy DType '%S' can "
@@ -193,8 +196,8 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr)
193
196
.tp_base = & PyArrayDescr_Type ,
194
197
.tp_new = (newfunc )legacy_dtype_default_new ,
195
198
},},
196
- .is_legacy = 1 ,
197
- .is_abstract = 0 , /* this is a concrete DType */
199
+ .legacy = 1 ,
200
+ .abstract = 0 , /* this is a concrete DType */
198
201
/* Further fields are not common between DTypes */
199
202
};
200
203
memcpy (dtype_class , & prototype , sizeof (PyArray_DTypeMeta ));
@@ -217,15 +220,13 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr)
217
220
dtype_class -> type = descr -> type ;
218
221
dtype_class -> f = descr -> f ;
219
222
dtype_class -> kind = descr -> kind ;
220
- dtype_class -> itemsize = descr -> elsize ;
221
223
222
224
if (PyTypeNum_ISDATETIME (descr -> type_num )) {
223
225
/* Datetimes are flexible, but were not considered previously */
224
- dtype_class -> is_parametric = NPY_TRUE ;
226
+ dtype_class -> parametric = NPY_TRUE ;
225
227
}
226
228
else if (PyTypeNum_ISFLEXIBLE (descr -> type_num )) {
227
- dtype_class -> is_parametric = NPY_TRUE ;
228
- dtype_class -> itemsize = -1 ; /* itemsize is not fixed */
229
+ dtype_class -> parametric = NPY_TRUE ;
229
230
}
230
231
231
232
/* Finally, replace the current class of the descr */
@@ -240,29 +241,29 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr)
240
241
* preliminary (the flags should also return bools).
241
242
*/
242
243
static PyMemberDef dtypemeta_members [] = {
243
- {"_abstract" ,
244
- T_BYTE , offsetof(PyArray_DTypeMeta , is_abstract ), READONLY , NULL },
245
- {"type" ,
246
- T_OBJECT , offsetof(PyArray_DTypeMeta , scalar_type ), READONLY , NULL },
247
- {"_parametric" ,
248
- T_BYTE , offsetof(PyArray_DTypeMeta , is_parametric ), READONLY , NULL },
249
- {NULL , 0 , 0 , 0 , NULL },
244
+ {"_abstract" ,
245
+ T_BYTE , offsetof(PyArray_DTypeMeta , abstract ), READONLY , NULL },
246
+ {"type" ,
247
+ T_OBJECT , offsetof(PyArray_DTypeMeta , scalar_type ), READONLY , NULL },
248
+ {"_parametric" ,
249
+ T_BYTE , offsetof(PyArray_DTypeMeta , parametric ), READONLY , NULL },
250
+ {NULL , 0 , 0 , 0 , NULL },
250
251
};
251
252
252
253
253
254
NPY_NO_EXPORT PyTypeObject PyArrayDTypeMeta_Type = {
254
- PyVarObject_HEAD_INIT (NULL , 0 )
255
- .tp_name = "numpy._DTypeMeta" ,
256
- .tp_basicsize = sizeof (PyArray_DTypeMeta ),
257
- .tp_dealloc = (destructor )dtypemeta_dealloc ,
258
- /* Types are garbage collected (see dtypemeta_is_gc documentation) */
259
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
260
- .tp_doc = "Preliminary NumPy API: The Type of NumPy DTypes (metaclass)" ,
261
- .tp_members = dtypemeta_members ,
262
- .tp_base = NULL , /* set to PyType_Type at import time */
263
- .tp_init = (initproc )dtypemeta_init ,
264
- .tp_new = dtypemeta_new ,
265
- .tp_is_gc = dtypemeta_is_gc ,
266
- .tp_traverse = (traverseproc )dtypemeta_traverse ,
255
+ PyVarObject_HEAD_INIT (NULL , 0 )
256
+ .tp_name = "numpy._DTypeMeta" ,
257
+ .tp_basicsize = sizeof (PyArray_DTypeMeta ),
258
+ .tp_dealloc = (destructor )dtypemeta_dealloc ,
259
+ /* Types are garbage collected (see dtypemeta_is_gc documentation) */
260
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
261
+ .tp_doc = "Preliminary NumPy API: The Type of NumPy DTypes (metaclass)" ,
262
+ .tp_members = dtypemeta_members ,
263
+ .tp_base = NULL , /* set to PyType_Type at import time */
264
+ .tp_init = (initproc )dtypemeta_init ,
265
+ .tp_new = dtypemeta_new ,
266
+ .tp_is_gc = dtypemeta_is_gc ,
267
+ .tp_traverse = (traverseproc )dtypemeta_traverse ,
267
268
};
268
269
0 commit comments