@@ -1122,127 +1122,83 @@ _PyTestCapi_Init_Heaptype(PyObject *m) {
1122
1122
return -1 ;
1123
1123
}
1124
1124
1125
+ #define ADD (name , value ) do { \
1126
+ if (PyModule_Add(m, name, value) < 0) { \
1127
+ return -1; \
1128
+ } \
1129
+ } while (0)
1130
+
1125
1131
PyObject * HeapDocCType = PyType_FromSpec (& HeapDocCType_spec );
1126
- if (HeapDocCType == NULL ) {
1127
- return -1 ;
1128
- }
1129
- PyModule_AddObject (m , "HeapDocCType" , HeapDocCType );
1132
+ ADD ("HeapDocCType" , HeapDocCType );
1130
1133
1131
1134
/* bpo-41832: Add a new type to test PyType_FromSpec()
1132
1135
now can accept a NULL tp_doc slot. */
1133
1136
PyObject * NullTpDocType = PyType_FromSpec (& NullTpDocType_spec );
1134
- if (NullTpDocType == NULL ) {
1135
- return -1 ;
1136
- }
1137
- PyModule_AddObject (m , "NullTpDocType" , NullTpDocType );
1137
+ ADD ("NullTpDocType" , NullTpDocType );
1138
1138
1139
1139
PyObject * HeapGcCType = PyType_FromSpec (& HeapGcCType_spec );
1140
- if (HeapGcCType == NULL ) {
1141
- return -1 ;
1142
- }
1143
- PyModule_AddObject (m , "HeapGcCType" , HeapGcCType );
1140
+ ADD ("HeapGcCType" , HeapGcCType );
1144
1141
1145
1142
PyObject * HeapCType = PyType_FromSpec (& HeapCType_spec );
1146
1143
if (HeapCType == NULL ) {
1147
1144
return -1 ;
1148
1145
}
1149
1146
PyObject * subclass_bases = PyTuple_Pack (1 , HeapCType );
1147
+ Py_DECREF (HeapCType );
1150
1148
if (subclass_bases == NULL ) {
1151
1149
return -1 ;
1152
1150
}
1153
1151
PyObject * HeapCTypeSubclass = PyType_FromSpecWithBases (& HeapCTypeSubclass_spec , subclass_bases );
1154
- if (HeapCTypeSubclass == NULL ) {
1155
- return -1 ;
1156
- }
1157
1152
Py_DECREF (subclass_bases );
1158
- PyModule_AddObject ( m , "HeapCTypeSubclass" , HeapCTypeSubclass );
1153
+ ADD ( "HeapCTypeSubclass" , HeapCTypeSubclass );
1159
1154
1160
1155
PyObject * HeapCTypeWithDict = PyType_FromSpec (& HeapCTypeWithDict_spec );
1161
- if (HeapCTypeWithDict == NULL ) {
1162
- return -1 ;
1163
- }
1164
- PyModule_AddObject (m , "HeapCTypeWithDict" , HeapCTypeWithDict );
1156
+ ADD ("HeapCTypeWithDict" , HeapCTypeWithDict );
1165
1157
1166
1158
PyObject * HeapCTypeWithDict2 = PyType_FromSpec (& HeapCTypeWithDict2_spec );
1167
- if (HeapCTypeWithDict2 == NULL ) {
1168
- return -1 ;
1169
- }
1170
- PyModule_AddObject (m , "HeapCTypeWithDict2" , HeapCTypeWithDict2 );
1159
+ ADD ("HeapCTypeWithDict2" , HeapCTypeWithDict2 );
1171
1160
1172
1161
PyObject * HeapCTypeWithNegativeDict = PyType_FromSpec (& HeapCTypeWithNegativeDict_spec );
1173
- if (HeapCTypeWithNegativeDict == NULL ) {
1174
- return -1 ;
1175
- }
1176
- PyModule_AddObject (m , "HeapCTypeWithNegativeDict" , HeapCTypeWithNegativeDict );
1162
+ ADD ("HeapCTypeWithNegativeDict" , HeapCTypeWithNegativeDict );
1177
1163
1178
1164
PyObject * HeapCTypeWithManagedDict = PyType_FromSpec (& HeapCTypeWithManagedDict_spec );
1179
- if (HeapCTypeWithManagedDict == NULL ) {
1180
- return -1 ;
1181
- }
1182
- PyModule_AddObject (m , "HeapCTypeWithManagedDict" , HeapCTypeWithManagedDict );
1165
+ ADD ("HeapCTypeWithManagedDict" , HeapCTypeWithManagedDict );
1183
1166
1184
1167
PyObject * HeapCTypeWithManagedWeakref = PyType_FromSpec (& HeapCTypeWithManagedWeakref_spec );
1185
- if (HeapCTypeWithManagedWeakref == NULL ) {
1186
- return -1 ;
1187
- }
1188
- PyModule_AddObject (m , "HeapCTypeWithManagedWeakref" , HeapCTypeWithManagedWeakref );
1168
+ ADD ("HeapCTypeWithManagedWeakref" , HeapCTypeWithManagedWeakref );
1189
1169
1190
1170
PyObject * HeapCTypeWithWeakref = PyType_FromSpec (& HeapCTypeWithWeakref_spec );
1191
- if (HeapCTypeWithWeakref == NULL ) {
1192
- return -1 ;
1193
- }
1194
- PyModule_AddObject (m , "HeapCTypeWithWeakref" , HeapCTypeWithWeakref );
1171
+ ADD ("HeapCTypeWithWeakref" , HeapCTypeWithWeakref );
1195
1172
1196
1173
PyObject * HeapCTypeWithWeakref2 = PyType_FromSpec (& HeapCTypeWithWeakref2_spec );
1197
- if (HeapCTypeWithWeakref2 == NULL ) {
1198
- return -1 ;
1199
- }
1200
- PyModule_AddObject (m , "HeapCTypeWithWeakref2" , HeapCTypeWithWeakref2 );
1174
+ ADD ("HeapCTypeWithWeakref2" , HeapCTypeWithWeakref2 );
1201
1175
1202
1176
PyObject * HeapCTypeWithBuffer = PyType_FromSpec (& HeapCTypeWithBuffer_spec );
1203
- if (HeapCTypeWithBuffer == NULL ) {
1204
- return -1 ;
1205
- }
1206
- PyModule_AddObject (m , "HeapCTypeWithBuffer" , HeapCTypeWithBuffer );
1177
+ ADD ("HeapCTypeWithBuffer" , HeapCTypeWithBuffer );
1207
1178
1208
1179
PyObject * HeapCTypeSetattr = PyType_FromSpec (& HeapCTypeSetattr_spec );
1209
- if (HeapCTypeSetattr == NULL ) {
1210
- return -1 ;
1211
- }
1212
- PyModule_AddObject (m , "HeapCTypeSetattr" , HeapCTypeSetattr );
1180
+ ADD ("HeapCTypeSetattr" , HeapCTypeSetattr );
1213
1181
1214
1182
PyObject * subclass_with_finalizer_bases = PyTuple_Pack (1 , HeapCTypeSubclass );
1215
1183
if (subclass_with_finalizer_bases == NULL ) {
1216
1184
return -1 ;
1217
1185
}
1218
1186
PyObject * HeapCTypeSubclassWithFinalizer = PyType_FromSpecWithBases (
1219
1187
& HeapCTypeSubclassWithFinalizer_spec , subclass_with_finalizer_bases );
1220
- if (HeapCTypeSubclassWithFinalizer == NULL ) {
1221
- return -1 ;
1222
- }
1223
1188
Py_DECREF (subclass_with_finalizer_bases );
1224
- PyModule_AddObject ( m , "HeapCTypeSubclassWithFinalizer" , HeapCTypeSubclassWithFinalizer );
1189
+ ADD ( "HeapCTypeSubclassWithFinalizer" , HeapCTypeSubclassWithFinalizer );
1225
1190
1226
1191
PyObject * HeapCTypeMetaclass = PyType_FromMetaclass (
1227
1192
& PyType_Type , m , & HeapCTypeMetaclass_spec , (PyObject * ) & PyType_Type );
1228
- if (HeapCTypeMetaclass == NULL ) {
1229
- return -1 ;
1230
- }
1231
- PyModule_AddObject (m , "HeapCTypeMetaclass" , HeapCTypeMetaclass );
1193
+ ADD ("HeapCTypeMetaclass" , HeapCTypeMetaclass );
1232
1194
1233
1195
PyObject * HeapCTypeMetaclassCustomNew = PyType_FromMetaclass (
1234
1196
& PyType_Type , m , & HeapCTypeMetaclassCustomNew_spec , (PyObject * ) & PyType_Type );
1235
- if (HeapCTypeMetaclassCustomNew == NULL ) {
1236
- return -1 ;
1237
- }
1238
- PyModule_AddObject (m , "HeapCTypeMetaclassCustomNew" , HeapCTypeMetaclassCustomNew );
1197
+ ADD ("HeapCTypeMetaclassCustomNew" , HeapCTypeMetaclassCustomNew );
1239
1198
1240
1199
PyObject * HeapCTypeMetaclassNullNew = PyType_FromMetaclass (
1241
1200
& PyType_Type , m , & HeapCTypeMetaclassNullNew_spec , (PyObject * ) & PyType_Type );
1242
- if (HeapCTypeMetaclassNullNew == NULL ) {
1243
- return -1 ;
1244
- }
1245
- PyModule_AddObject (m , "HeapCTypeMetaclassNullNew" , HeapCTypeMetaclassNullNew );
1201
+ ADD ("HeapCTypeMetaclassNullNew" , HeapCTypeMetaclassNullNew );
1246
1202
1247
1203
PyObject * HeapCCollection = PyType_FromMetaclass (
1248
1204
NULL , m , & HeapCCollection_spec , NULL );
0 commit comments