Serhiy Storchaka added the comment:
I saw nothing that could lead to a bug, except a few of the obsolete functions
for work with size_t (for compatibility with versions <2.6). Here is a patch
that gets rid of this outdated code. I don't have enough memory to check if
this will help, but I think that at least for 3.4 it is worth to apply as a
code cleanup.
----------
keywords: +patch
Added file: http://bugs.python.org/file28171/json_size_t_cleanup.patch
Added file: http://bugs.python.org/file28172/json_size_t_cleanup-2.7.patch
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16586>
_______________________________________
diff -r ce3f0399ea33 Modules/_json.c
--- a/Modules/_json.c Thu Nov 29 10:58:43 2012 -0500
+++ b/Modules/_json.c Sat Dec 01 00:32:05 2012 +0200
@@ -2,20 +2,6 @@
#include "structmember.h"
#include "accu.h"
-#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TYPE)
-#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
-#endif
-#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-#define PyInt_FromSsize_t PyInt_FromLong
-#define PyInt_AsSsize_t PyInt_AsLong
-#endif
-#ifndef Py_IS_FINITE
-#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
-#endif
-
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
#else
@@ -129,33 +115,12 @@
raise_errmsg(char *msg, PyObject *s, Py_ssize_t end);
static PyObject *
encoder_encode_string(PyEncoderObject *s, PyObject *obj);
-static int
-_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr);
-static PyObject *
-_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr);
static PyObject *
encoder_encode_float(PyEncoderObject *s, PyObject *obj);
#define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"')
#define IS_WHITESPACE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') ||
((c) == '\r'))
-static int
-_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr)
-{
- /* PyObject to Py_ssize_t converter */
- *size_ptr = PyLong_AsSsize_t(o);
- if (*size_ptr == -1 && PyErr_Occurred())
- return 0;
- return 1;
-}
-
-static PyObject *
-_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr)
-{
- /* Py_ssize_t to PyObject converter */
- return PyLong_FromSsize_t(*size_ptr);
-}
-
static Py_ssize_t
ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars)
{
@@ -265,7 +230,7 @@
if (errmsg_fn == NULL)
return;
}
- pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s,
_convertPyInt_FromSsize_t, &end);
+ pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
if (pymsg) {
PyErr_SetObject(PyExc_ValueError, pymsg);
Py_DECREF(pymsg);
@@ -524,7 +489,7 @@
Py_ssize_t end;
Py_ssize_t next_end = -1;
int strict = 1;
- if (!PyArg_ParseTuple(args, "OO&|i:scanstring", &pystr,
_convertPyInt_AsSsize_t, &end, &strict)) {
+ if (!PyArg_ParseTuple(args, "On|i:scanstring", &pystr, &end, &strict)) {
return NULL;
}
if (PyUnicode_Check(pystr)) {
@@ -1087,7 +1052,7 @@
PyScannerObject *s;
assert(PyScanner_Check(self));
s = (PyScannerObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:scan_once", kwlist,
&pystr, _convertPyInt_AsSsize_t, &idx))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:scan_once", kwlist,
&pystr, &idx))
return NULL;
if (PyUnicode_Check(pystr)) {
@@ -1288,8 +1253,8 @@
assert(PyEncoder_Check(self));
s = (PyEncoderObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:_iterencode", kwlist,
- &obj, _convertPyInt_AsSsize_t, &indent_level))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:_iterencode", kwlist,
+ &obj, &indent_level))
return NULL;
if (_PyAccu_Init(&acc))
return NULL;
diff -r 1e614dae8448 Modules/_json.c
--- a/Modules/_json.c Fri Nov 30 16:15:24 2012 -0500
+++ b/Modules/_json.c Sat Dec 01 00:25:45 2012 +0200
@@ -1,18 +1,5 @@
#include "Python.h"
#include "structmember.h"
-#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TYPE)
-#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
-#endif
-#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-#define PyInt_FromSsize_t PyInt_FromLong
-#define PyInt_AsSsize_t PyInt_AsLong
-#endif
-#ifndef Py_IS_FINITE
-#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
-#endif
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
@@ -121,10 +108,6 @@
raise_errmsg(char *msg, PyObject *s, Py_ssize_t end);
static PyObject *
encoder_encode_string(PyEncoderObject *s, PyObject *obj);
-static int
-_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr);
-static PyObject *
-_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr);
static PyObject *
encoder_encode_float(PyEncoderObject *s, PyObject *obj);
@@ -138,23 +121,6 @@
#define MAX_EXPANSION MIN_EXPANSION
#endif
-static int
-_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr)
-{
- /* PyObject to Py_ssize_t converter */
- *size_ptr = PyInt_AsSsize_t(o);
- if (*size_ptr == -1 && PyErr_Occurred())
- return 0;
- return 1;
-}
-
-static PyObject *
-_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr)
-{
- /* Py_ssize_t to PyObject converter */
- return PyInt_FromSsize_t(*size_ptr);
-}
-
static Py_ssize_t
ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars)
{
@@ -354,7 +320,7 @@
if (errmsg_fn == NULL)
return;
}
- pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s,
_convertPyInt_FromSsize_t, &end);
+ pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
if (pymsg) {
PyErr_SetObject(PyExc_ValueError, pymsg);
Py_DECREF(pymsg);
@@ -791,7 +757,7 @@
Py_ssize_t next_end = -1;
char *encoding = NULL;
int strict = 1;
- if (!PyArg_ParseTuple(args, "OO&|zi:scanstring", &pystr,
_convertPyInt_AsSsize_t, &end, &encoding, &strict)) {
+ if (!PyArg_ParseTuple(args, "On|zi:scanstring", &pystr, &end, &encoding,
&strict)) {
return NULL;
}
if (encoding == NULL) {
@@ -1663,7 +1629,7 @@
PyScannerObject *s;
assert(PyScanner_Check(self));
s = (PyScannerObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:scan_once", kwlist,
&pystr, _convertPyInt_AsSsize_t, &idx))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:scan_once", kwlist,
&pystr, &idx))
return NULL;
if (PyString_Check(pystr)) {
@@ -1883,8 +1849,8 @@
PyEncoderObject *s;
assert(PyEncoder_Check(self));
s = (PyEncoderObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:_iterencode", kwlist,
- &obj, _convertPyInt_AsSsize_t, &indent_level))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:_iterencode", kwlist,
+ &obj, &indent_level))
return NULL;
rval = PyList_New(0);
if (rval == NULL)
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com