|
2 | 2 | #include "structmember.h" |
3 | 3 | #include "accu.h" |
4 | 4 |
|
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 | | - |
19 | 5 | #ifdef __GNUC__ |
20 | 6 | #define UNUSED __attribute__((__unused__)) |
21 | 7 | #else |
@@ -129,33 +115,12 @@ static void |
129 | 115 | raise_errmsg(char *msg, PyObject *s, Py_ssize_t end); |
130 | 116 | static PyObject * |
131 | 117 | 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); |
136 | 118 | static PyObject * |
137 | 119 | encoder_encode_float(PyEncoderObject *s, PyObject *obj); |
138 | 120 |
|
139 | 121 | #define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"') |
140 | 122 | #define IS_WHITESPACE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r')) |
141 | 123 |
|
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 | | - |
159 | 124 | static Py_ssize_t |
160 | 125 | ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars) |
161 | 126 | { |
@@ -265,7 +230,7 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end) |
265 | 230 | if (errmsg_fn == NULL) |
266 | 231 | return; |
267 | 232 | } |
268 | | - pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s, _convertPyInt_FromSsize_t, &end); |
| 233 | + pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end); |
269 | 234 | if (pymsg) { |
270 | 235 | PyErr_SetObject(PyExc_ValueError, pymsg); |
271 | 236 | Py_DECREF(pymsg); |
@@ -524,7 +489,7 @@ py_scanstring(PyObject* self UNUSED, PyObject *args) |
524 | 489 | Py_ssize_t end; |
525 | 490 | Py_ssize_t next_end = -1; |
526 | 491 | 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)) { |
528 | 493 | return NULL; |
529 | 494 | } |
530 | 495 | if (PyUnicode_Check(pystr)) { |
@@ -1087,7 +1052,7 @@ scanner_call(PyObject *self, PyObject *args, PyObject *kwds) |
1087 | 1052 | PyScannerObject *s; |
1088 | 1053 | assert(PyScanner_Check(self)); |
1089 | 1054 | 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)) |
1091 | 1056 | return NULL; |
1092 | 1057 |
|
1093 | 1058 | if (PyUnicode_Check(pystr)) { |
@@ -1288,8 +1253,8 @@ encoder_call(PyObject *self, PyObject *args, PyObject *kwds) |
1288 | 1253 |
|
1289 | 1254 | assert(PyEncoder_Check(self)); |
1290 | 1255 | 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)) |
1293 | 1258 | return NULL; |
1294 | 1259 | if (_PyAccu_Init(&acc)) |
1295 | 1260 | return NULL; |
|
0 commit comments