Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbb0284

Browse files
committed
Issue #16590: remove obsolete compatibility code from the _json module.
Patch by Serhiy Storchaka.
1 parent f02f280 commit cbb0284

1 file changed

Lines changed: 5 additions & 40 deletions

File tree

Modules/_json.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
#include "structmember.h"
33
#include "accu.h"
44

5-
#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TYPE)
6-
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
7-
#endif
8-
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
9-
typedef int Py_ssize_t;
10-
#define PY_SSIZE_T_MAX INT_MAX
11-
#define PY_SSIZE_T_MIN INT_MIN
12-
#define PyInt_FromSsize_t PyInt_FromLong
13-
#define PyInt_AsSsize_t PyInt_AsLong
14-
#endif
15-
#ifndef Py_IS_FINITE
16-
#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
17-
#endif
18-
195
#ifdef __GNUC__
206
#define UNUSED __attribute__((__unused__))
217
#else
@@ -129,33 +115,12 @@ static void
129115
raise_errmsg(char *msg, PyObject *s, Py_ssize_t end);
130116
static PyObject *
131117
encoder_encode_string(PyEncoderObject *s, PyObject *obj);
132-
static int
133-
_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr);
134-
static PyObject *
135-
_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr);
136118
static PyObject *
137119
encoder_encode_float(PyEncoderObject *s, PyObject *obj);
138120

139121
#define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"')
140122
#define IS_WHITESPACE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r'))
141123

142-
static int
143-
_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr)
144-
{
145-
/* PyObject to Py_ssize_t converter */
146-
*size_ptr = PyLong_AsSsize_t(o);
147-
if (*size_ptr == -1 && PyErr_Occurred())
148-
return 0;
149-
return 1;
150-
}
151-
152-
static PyObject *
153-
_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr)
154-
{
155-
/* Py_ssize_t to PyObject converter */
156-
return PyLong_FromSsize_t(*size_ptr);
157-
}
158-
159124
static Py_ssize_t
160125
ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars)
161126
{
@@ -265,7 +230,7 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end)
265230
if (errmsg_fn == NULL)
266231
return;
267232
}
268-
pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s, _convertPyInt_FromSsize_t, &end);
233+
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
269234
if (pymsg) {
270235
PyErr_SetObject(PyExc_ValueError, pymsg);
271236
Py_DECREF(pymsg);
@@ -524,7 +489,7 @@ py_scanstring(PyObject* self UNUSED, PyObject *args)
524489
Py_ssize_t end;
525490
Py_ssize_t next_end = -1;
526491
int strict = 1;
527-
if (!PyArg_ParseTuple(args, "OO&|i:scanstring", &pystr, _convertPyInt_AsSsize_t, &end, &strict)) {
492+
if (!PyArg_ParseTuple(args, "On|i:scanstring", &pystr, &end, &strict)) {
528493
return NULL;
529494
}
530495
if (PyUnicode_Check(pystr)) {
@@ -1087,7 +1052,7 @@ scanner_call(PyObject *self, PyObject *args, PyObject *kwds)
10871052
PyScannerObject *s;
10881053
assert(PyScanner_Check(self));
10891054
s = (PyScannerObject *)self;
1090-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:scan_once", kwlist, &pystr, _convertPyInt_AsSsize_t, &idx))
1055+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:scan_once", kwlist, &pystr, &idx))
10911056
return NULL;
10921057

10931058
if (PyUnicode_Check(pystr)) {
@@ -1288,8 +1253,8 @@ encoder_call(PyObject *self, PyObject *args, PyObject *kwds)
12881253

12891254
assert(PyEncoder_Check(self));
12901255
s = (PyEncoderObject *)self;
1291-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:_iterencode", kwlist,
1292-
&obj, _convertPyInt_AsSsize_t, &indent_level))
1256+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:_iterencode", kwlist,
1257+
&obj, &indent_level))
12931258
return NULL;
12941259
if (_PyAccu_Init(&acc))
12951260
return NULL;

0 commit comments

Comments
 (0)