24
24
#include <float.h>
25
25
#include <signal.h>
26
26
27
+ #include <ffi.h> /* required by ctypes.h */
28
+ #include "_ctypes/ctypes.h" /* To test metaclass inheritance */
29
+
27
30
#ifdef MS_WINDOWS
28
31
# include <winsock2.h> /* struct timeval */
29
32
#endif
@@ -1173,48 +1176,13 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
1173
1176
}
1174
1177
1175
1178
1176
- /*
1177
- * Small helper to import abc.ABC and ctypes.Array for testing. Both
1178
- * are (incompatible) MetaClass instances. If Array is NULL it is not filled.
1179
- */
1180
- static int
1181
- import_abc_and_array (PyObject * * ABC , PyObject * * Array )
1182
- {
1183
- PyObject * abc_mod = PyImport_ImportModule ("abc" );
1184
- if (abc_mod == NULL ) {
1185
- return -1 ;
1186
- }
1187
- * ABC = PyObject_GetAttrString (abc_mod , "ABC" );
1188
- Py_DECREF (abc_mod );
1189
- if (* ABC == NULL ) {
1190
- return -1 ;
1191
- }
1192
- if (Array == NULL ) {
1193
- return 0 ;
1194
- }
1195
-
1196
- PyObject * ctypes_mod = PyImport_ImportModule ("ctypes" );
1197
- if (ctypes_mod == NULL ) {
1198
- Py_CLEAR (* ABC );
1199
- return -1 ;
1200
- }
1201
- * Array = PyObject_GetAttrString (ctypes_mod , "Array" );
1202
- Py_DECREF (ctypes_mod );
1203
- if (* Array == NULL ) {
1204
- Py_CLEAR (* ABC );
1205
- return -1 ;
1206
- }
1207
- return 0 ;
1208
- }
1209
-
1210
-
1211
1179
static PyType_Slot MinimalType_slots [] = {
1212
1180
{0 , 0 },
1213
1181
};
1214
1182
1215
1183
static PyType_Spec MinimalType_spec = {
1216
1184
"_testcapi.MinimalSpecType" ,
1217
- 0 ,
1185
+ sizeof ( CDataObject ) ,
1218
1186
0 ,
1219
1187
Py_TPFLAGS_DEFAULT ,
1220
1188
MinimalType_slots
@@ -1224,31 +1192,22 @@ static PyType_Spec MinimalType_spec = {
1224
1192
static PyObject *
1225
1193
test_from_spec_metatype_inheritance (PyObject * self , PyObject * Py_UNUSED (ignored ))
1226
1194
{
1227
- /* Get two (incompatible) MetaTypes */
1228
- PyObject * ABC ;
1229
- if (import_abc_and_array (& ABC , NULL ) < 0 ) {
1230
- return NULL ;
1231
- }
1232
-
1233
- PyObject * bases = PyTuple_Pack (1 , ABC );
1195
+ PyObject * bases = PyTuple_Pack (1 , PyCArray_Type );
1234
1196
if (bases == NULL ) {
1235
- Py_DECREF (ABC );
1236
1197
return NULL ;
1237
1198
}
1199
+
1238
1200
PyObject * new = PyType_FromSpecWithBases (& MinimalType_spec , bases );
1239
1201
Py_DECREF (bases );
1240
1202
if (new == NULL ) {
1241
- Py_DECREF (ABC );
1242
1203
return NULL ;
1243
1204
}
1244
- if (Py_TYPE (new ) != Py_TYPE (ABC )) {
1205
+ if (Py_TYPE (new ) != Py_TYPE (& PyCArray_Type )) {
1245
1206
PyErr_SetString (PyExc_AssertionError ,
1246
1207
"MetaType appears not correctly inherited from ABC!" );
1247
- Py_DECREF (ABC );
1248
1208
Py_DECREF (new );
1249
1209
return NULL ;
1250
1210
}
1251
- Py_DECREF (ABC );
1252
1211
Py_DECREF (new );
1253
1212
Py_RETURN_NONE ;
1254
1213
}
@@ -1257,19 +1216,11 @@ test_from_spec_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(ignored)
1257
1216
static PyObject *
1258
1217
test_from_spec_invalid_metatype_inheritance (PyObject * self , PyObject * Py_UNUSED (ignored ))
1259
1218
{
1260
- /* Get two (incompatible) MetaTypes */
1261
- PyObject * ABC , * Array ;
1262
-
1263
- if (import_abc_and_array (& ABC , & Array ) < 0 ) {
1264
- return NULL ;
1265
- }
1266
-
1267
- PyObject * bases = PyTuple_Pack (2 , ABC , Array );
1268
- Py_DECREF (ABC );
1269
- Py_DECREF (Array );
1219
+ PyObject * bases = PyTuple_Pack (2 , PyCArray_Type , PyCFuncPtr_Type );
1270
1220
if (bases == NULL ) {
1271
1221
return NULL ;
1272
1222
}
1223
+
1273
1224
/*
1274
1225
* The following should raise a TypeError due to a MetaClass conflict.
1275
1226
*/
@@ -1286,7 +1237,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
1286
1237
1287
1238
PyErr_Fetch (& type , & value , & traceback );
1288
1239
Py_DECREF (type );
1289
- Py_XDECREF (traceback );
1240
+ Py_DECREF (traceback );
1290
1241
1291
1242
meta_error_string = PyUnicode_FromString ("metaclass conflict:" );
1292
1243
if (meta_error_string == NULL ) {
0 commit comments