@@ -89,16 +89,12 @@ static PyObject *
89
89
_build_rval_index_tuple (PyObject * rval , Py_ssize_t idx );
90
90
static PyObject *
91
91
scanner_new (PyTypeObject * type , PyObject * args , PyObject * kwds );
92
- static int
93
- scanner_init (PyObject * self , PyObject * args , PyObject * kwds );
94
92
static void
95
93
scanner_dealloc (PyObject * self );
96
94
static int
97
95
scanner_clear (PyObject * self );
98
96
static PyObject *
99
97
encoder_new (PyTypeObject * type , PyObject * args , PyObject * kwds );
100
- static int
101
- encoder_init (PyObject * self , PyObject * args , PyObject * kwds );
102
98
static void
103
99
encoder_dealloc (PyObject * self );
104
100
static int
@@ -1200,38 +1196,21 @@ static PyObject *
1200
1196
scanner_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
1201
1197
{
1202
1198
PyScannerObject * s ;
1203
- s = (PyScannerObject * )type -> tp_alloc (type , 0 );
1204
- if (s != NULL ) {
1205
- s -> strict = NULL ;
1206
- s -> object_hook = NULL ;
1207
- s -> object_pairs_hook = NULL ;
1208
- s -> parse_float = NULL ;
1209
- s -> parse_int = NULL ;
1210
- s -> parse_constant = NULL ;
1211
- }
1212
- return (PyObject * )s ;
1213
- }
1214
-
1215
- static int
1216
- scanner_init (PyObject * self , PyObject * args , PyObject * kwds )
1217
- {
1218
- /* Initialize Scanner object */
1219
1199
PyObject * ctx ;
1220
1200
static char * kwlist [] = {"context" , NULL };
1221
- PyScannerObject * s ;
1222
-
1223
- assert (PyScanner_Check (self ));
1224
- s = (PyScannerObject * )self ;
1225
1201
1226
1202
if (!PyArg_ParseTupleAndKeywords (args , kwds , "O:make_scanner" , kwlist , & ctx ))
1227
- return -1 ;
1203
+ return NULL ;
1228
1204
1229
- if (s -> memo == NULL ) {
1230
- s -> memo = PyDict_New ();
1231
- if (s -> memo == NULL )
1232
- goto bail ;
1205
+ s = (PyScannerObject * )type -> tp_alloc (type , 0 );
1206
+ if (s == NULL ) {
1207
+ return NULL ;
1233
1208
}
1234
1209
1210
+ s -> memo = PyDict_New ();
1211
+ if (s -> memo == NULL )
1212
+ goto bail ;
1213
+
1235
1214
/* All of these will fail "gracefully" so we don't need to verify them */
1236
1215
s -> strict = PyObject_GetAttrString (ctx , "strict" );
1237
1216
if (s -> strict == NULL )
@@ -1252,16 +1231,11 @@ scanner_init(PyObject *self, PyObject *args, PyObject *kwds)
1252
1231
if (s -> parse_constant == NULL )
1253
1232
goto bail ;
1254
1233
1255
- return 0 ;
1234
+ return ( PyObject * ) s ;
1256
1235
1257
1236
bail :
1258
- Py_CLEAR (s -> strict );
1259
- Py_CLEAR (s -> object_hook );
1260
- Py_CLEAR (s -> object_pairs_hook );
1261
- Py_CLEAR (s -> parse_float );
1262
- Py_CLEAR (s -> parse_int );
1263
- Py_CLEAR (s -> parse_constant );
1264
- return -1 ;
1237
+ Py_DECREF (s );
1238
+ return NULL ;
1265
1239
}
1266
1240
1267
1241
PyDoc_STRVAR (scanner_doc , "JSON scanner object" );
@@ -1303,7 +1277,7 @@ PyTypeObject PyScannerType = {
1303
1277
0 , /* tp_descr_get */
1304
1278
0 , /* tp_descr_set */
1305
1279
0 , /* tp_dictoffset */
1306
- scanner_init , /* tp_init */
1280
+ 0 , /* tp_init */
1307
1281
0 ,/* PyType_GenericAlloc, */ /* tp_alloc */
1308
1282
scanner_new , /* tp_new */
1309
1283
0 ,/* PyObject_GC_Del, */ /* tp_free */
@@ -1312,48 +1286,30 @@ PyTypeObject PyScannerType = {
1312
1286
static PyObject *
1313
1287
encoder_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
1314
1288
{
1315
- PyEncoderObject * s ;
1316
- s = (PyEncoderObject * )type -> tp_alloc (type , 0 );
1317
- if (s != NULL ) {
1318
- s -> markers = NULL ;
1319
- s -> defaultfn = NULL ;
1320
- s -> encoder = NULL ;
1321
- s -> indent = NULL ;
1322
- s -> key_separator = NULL ;
1323
- s -> item_separator = NULL ;
1324
- s -> sort_keys = NULL ;
1325
- s -> skipkeys = NULL ;
1326
- }
1327
- return (PyObject * )s ;
1328
- }
1329
-
1330
- static int
1331
- encoder_init (PyObject * self , PyObject * args , PyObject * kwds )
1332
- {
1333
- /* initialize Encoder object */
1334
1289
static char * kwlist [] = {"markers" , "default" , "encoder" , "indent" , "key_separator" , "item_separator" , "sort_keys" , "skipkeys" , "allow_nan" , NULL };
1335
1290
1336
1291
PyEncoderObject * s ;
1337
1292
PyObject * markers , * defaultfn , * encoder , * indent , * key_separator ;
1338
1293
PyObject * item_separator , * sort_keys , * skipkeys ;
1339
1294
int allow_nan ;
1340
1295
1341
- assert (PyEncoder_Check (self ));
1342
- s = (PyEncoderObject * )self ;
1343
-
1344
1296
if (!PyArg_ParseTupleAndKeywords (args , kwds , "OOOOUUOOp:make_encoder" , kwlist ,
1345
1297
& markers , & defaultfn , & encoder , & indent ,
1346
1298
& key_separator , & item_separator ,
1347
1299
& sort_keys , & skipkeys , & allow_nan ))
1348
- return -1 ;
1300
+ return NULL ;
1349
1301
1350
1302
if (markers != Py_None && !PyDict_Check (markers )) {
1351
1303
PyErr_Format (PyExc_TypeError ,
1352
1304
"make_encoder() argument 1 must be dict or None, "
1353
1305
"not %.200s" , Py_TYPE (markers )-> tp_name );
1354
- return -1 ;
1306
+ return NULL ;
1355
1307
}
1356
1308
1309
+ s = (PyEncoderObject * )type -> tp_alloc (type , 0 );
1310
+ if (s == NULL )
1311
+ return NULL ;
1312
+
1357
1313
s -> markers = markers ;
1358
1314
s -> defaultfn = defaultfn ;
1359
1315
s -> encoder = encoder ;
@@ -1380,7 +1336,7 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
1380
1336
Py_INCREF (s -> item_separator );
1381
1337
Py_INCREF (s -> sort_keys );
1382
1338
Py_INCREF (s -> skipkeys );
1383
- return 0 ;
1339
+ return ( PyObject * ) s ;
1384
1340
}
1385
1341
1386
1342
static PyObject *
@@ -1911,7 +1867,7 @@ PyTypeObject PyEncoderType = {
1911
1867
0 , /* tp_descr_get */
1912
1868
0 , /* tp_descr_set */
1913
1869
0 , /* tp_dictoffset */
1914
- encoder_init , /* tp_init */
1870
+ 0 , /* tp_init */
1915
1871
0 , /* tp_alloc */
1916
1872
encoder_new , /* tp_new */
1917
1873
0 , /* tp_free */
@@ -1954,10 +1910,8 @@ PyInit__json(void)
1954
1910
PyObject * m = PyModule_Create (& jsonmodule );
1955
1911
if (!m )
1956
1912
return NULL ;
1957
- PyScannerType .tp_new = PyType_GenericNew ;
1958
1913
if (PyType_Ready (& PyScannerType ) < 0 )
1959
1914
goto fail ;
1960
- PyEncoderType .tp_new = PyType_GenericNew ;
1961
1915
if (PyType_Ready (& PyEncoderType ) < 0 )
1962
1916
goto fail ;
1963
1917
Py_INCREF ((PyObject * )& PyScannerType );
0 commit comments