summaryrefslogtreecommitdiff
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-01-03 03:38:38 +0100
committerVictor Stinner <victor.stinner@gmail.com>2013-01-03 03:38:38 +0100
commit79d172aa6fd74928f50bce6afab86026c8a9896e (patch)
tree37bc089d1e0855ebe304b7f77d3af833a45381cd /Modules/_json.c
parent4460d8cf8f09cc7ac186388086c08eefa7900cce (diff)
parentddb0902d81cd45f66e8e8976cb426d33b3650f8d (diff)
downloadcpython-79d172aa6fd74928f50bce6afab86026c8a9896e.tar.gz
(Merge 3.3) Issue #16367: Fix FileIO.readall() on Windows for files larger than 2 GB.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c66
1 files changed, 15 insertions, 51 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 5b42f6f718..9b6bbd398f 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -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 @@ static void
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)
{
@@ -174,14 +139,13 @@ ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars)
default:
if (c >= 0x10000) {
/* UTF-16 surrogate pair */
- Py_UCS4 v = c - 0x10000;
- c = 0xd800 | ((v >> 10) & 0x3ff);
+ Py_UCS4 v = Py_UNICODE_HIGH_SURROGATE(c);
output[chars++] = 'u';
- output[chars++] = Py_hexdigits[(c >> 12) & 0xf];
- output[chars++] = Py_hexdigits[(c >> 8) & 0xf];
- output[chars++] = Py_hexdigits[(c >> 4) & 0xf];
- output[chars++] = Py_hexdigits[(c ) & 0xf];
- c = 0xdc00 | (v & 0x3ff);
+ output[chars++] = Py_hexdigits[(v >> 12) & 0xf];
+ output[chars++] = Py_hexdigits[(v >> 8) & 0xf];
+ output[chars++] = Py_hexdigits[(v >> 4) & 0xf];
+ output[chars++] = Py_hexdigits[(v ) & 0xf];
+ c = Py_UNICODE_LOW_SURROGATE(c);
output[chars++] = '\\';
}
output[chars++] = 'u';
@@ -266,7 +230,7 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end)
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);
@@ -431,7 +395,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
}
}
/* Surrogate pair */
- if ((c & 0xfc00) == 0xd800) {
+ if (Py_UNICODE_IS_HIGH_SURROGATE(c)) {
Py_UCS4 c2 = 0;
if (end + 6 >= len) {
raise_errmsg("Unpaired high surrogate", pystr, end - 5);
@@ -462,13 +426,13 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
goto bail;
}
}
- if ((c2 & 0xfc00) != 0xdc00) {
+ if (!Py_UNICODE_IS_LOW_SURROGATE(c2)) {
raise_errmsg("Unpaired high surrogate", pystr, end - 5);
goto bail;
}
- c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00));
+ c = Py_UNICODE_JOIN_SURROGATES(c, c2);
}
- else if ((c & 0xfc00) == 0xdc00) {
+ else if (Py_UNICODE_IS_LOW_SURROGATE(c)) {
raise_errmsg("Unpaired low surrogate", pystr, end - 5);
goto bail;
}
@@ -525,7 +489,7 @@ py_scanstring(PyObject* self UNUSED, PyObject *args)
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)) {
@@ -1088,7 +1052,7 @@ scanner_call(PyObject *self, PyObject *args, PyObject *kwds)
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)) {
@@ -1289,8 +1253,8 @@ encoder_call(PyObject *self, PyObject *args, PyObject *kwds)
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;