@@ -124,7 +124,7 @@ static PyType_Slot Xxo_Type_slots[] = {
124
124
};
125
125
126
126
static PyType_Spec Xxo_Type_spec = {
127
- "xxlimited .Xxo" ,
127
+ "xxlimited_35 .Xxo" ,
128
128
sizeof (XxoObject ),
129
129
0 ,
130
130
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
@@ -189,7 +189,7 @@ static PyType_Slot Str_Type_slots[] = {
189
189
};
190
190
191
191
static PyType_Spec Str_Type_spec = {
192
- "xxlimited .Str" ,
192
+ "xxlimited_35 .Str" ,
193
193
0 ,
194
194
0 ,
195
195
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
@@ -212,7 +212,7 @@ static PyType_Slot Null_Type_slots[] = {
212
212
};
213
213
214
214
static PyType_Spec Null_Type_spec = {
215
- "xxlimited .Null" ,
215
+ "xxlimited_35 .Null" ,
216
216
0 , /* basicsize */
217
217
0 , /* itemsize */
218
218
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
@@ -236,52 +236,58 @@ static PyMethodDef xx_methods[] = {
236
236
PyDoc_STRVAR (module_doc ,
237
237
"This is a module for testing limited API from Python 3.5." );
238
238
239
+ static PyObject *
240
+ create_and_add_type (PyObject * module , const char * name , PyType_Spec * spec )
241
+ {
242
+ PyObject * type = PyType_FromSpec (spec );
243
+ if (type == NULL ) {
244
+ return NULL ;
245
+ }
246
+ int rc = PyModule_AddObject (module , name , type );
247
+ if (rc < 0 ) {
248
+ Py_DECREF (type );
249
+ return NULL ;
250
+ }
251
+ return type ;
252
+ }
253
+
239
254
static int
240
255
xx_modexec (PyObject * m )
241
256
{
242
- PyObject * o ;
243
-
244
257
/* Due to cross platform compiler issues the slots must be filled
245
258
* here. It's required for portability to Windows without requiring
246
259
* C++. */
247
260
Null_Type_slots [0 ].pfunc = & PyBaseObject_Type ;
248
261
Null_Type_slots [1 ].pfunc = PyType_GenericNew ;
249
262
Str_Type_slots [0 ].pfunc = & PyUnicode_Type ;
250
263
251
- Xxo_Type = PyType_FromSpec (& Xxo_Type_spec );
252
- if (Xxo_Type == NULL )
253
- goto fail ;
254
-
255
264
/* Add some symbolic constants to the module */
256
265
if (ErrorObject == NULL ) {
257
- ErrorObject = PyErr_NewException ("xxlimited.error" , NULL , NULL );
258
- if (ErrorObject == NULL )
259
- goto fail ;
266
+ ErrorObject = PyErr_NewException ("xxlimited_35.error" , NULL , NULL );
267
+ if (ErrorObject == NULL ) {
268
+ return -1 ;
269
+ }
260
270
}
261
271
Py_INCREF (ErrorObject );
262
- PyModule_AddObject (m , "error" , ErrorObject );
263
-
264
- /* Add Xxo */
265
- o = PyType_FromSpec (& Xxo_Type_spec );
266
- if (o == NULL )
267
- goto fail ;
268
- PyModule_AddObject (m , "Xxo" , o );
269
-
270
- /* Add Str */
271
- o = PyType_FromSpec (& Str_Type_spec );
272
- if (o == NULL )
273
- goto fail ;
274
- PyModule_AddObject (m , "Str" , o );
275
-
276
- /* Add Null */
277
- o = PyType_FromSpec (& Null_Type_spec );
278
- if (o == NULL )
279
- goto fail ;
280
- PyModule_AddObject (m , "Null" , o );
272
+ int rc = PyModule_AddObject (m , "error" , ErrorObject );
273
+ if (rc < 0 ) {
274
+ Py_DECREF (ErrorObject );
275
+ return -1 ;
276
+ }
277
+
278
+ /* Add Xxo, Str, and Null types */
279
+ Xxo_Type = create_and_add_type (m , "Xxo" , & Xxo_Type_spec );
280
+ if (Xxo_Type == NULL ) {
281
+ return -1 ;
282
+ }
283
+ if (create_and_add_type (m , "Str" , & Str_Type_spec ) == NULL ) {
284
+ return -1 ;
285
+ }
286
+ if (create_and_add_type (m , "Null" , & Null_Type_spec ) == NULL ) {
287
+ return -1 ;
288
+ }
289
+
281
290
return 0 ;
282
- fail :
283
- Py_XDECREF (m );
284
- return -1 ;
285
291
}
286
292
287
293
0 commit comments