Skip to content
Snippets Groups Projects
Commit ca7a41bee6b3 authored by Bob Ippolito's avatar Bob Ippolito
Browse files
git-svn-id: http://simplejson.googlecode.com/svn/trunk@122 a4795897-2c25-0410-b006-0d3caba88fa1
parent 60228072a290
No related branches found
No related tags found
No related merge requests found
......@@ -297,6 +297,7 @@
PyObject *pymsg;
if (errmsg_fn == NULL) {
PyObject *decoder = PyImport_ImportModule("simplejson.decoder");
if (decoder == NULL) return;
if (decoder == NULL)
return;
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
Py_DECREF(decoder);
......@@ -301,9 +302,10 @@
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
Py_DECREF(decoder);
if (errmsg_fn == NULL) return;
if (errmsg_fn == NULL)
return;
}
#if PY_VERSION_HEX < 0x02050000
pymsg = PyObject_CallFunction(errmsg_fn, "(zOi)", msg, s, end);
#else
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
#endif
......@@ -304,9 +306,10 @@
}
#if PY_VERSION_HEX < 0x02050000
pymsg = PyObject_CallFunction(errmsg_fn, "(zOi)", msg, s, end);
#else
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
#endif
if (pymsg) {
PyErr_SetObject(PyExc_ValueError, pymsg);
Py_DECREF(pymsg);
}
......@@ -310,6 +313,7 @@
PyErr_SetObject(PyExc_ValueError, pymsg);
Py_DECREF(pymsg);
}
}
static PyObject *
join_list_string(PyObject *lst)
......@@ -317,7 +321,8 @@
static PyObject *joinfn = NULL;
if (joinfn == NULL) {
PyObject *ustr = PyString_FromStringAndSize(NULL, 0);
if (ustr == NULL) return NULL;
if (ustr == NULL)
return NULL;
joinfn = PyObject_GetAttrString(ustr, "join");
Py_DECREF(ustr);
......@@ -321,7 +326,8 @@
joinfn = PyObject_GetAttrString(ustr, "join");
Py_DECREF(ustr);
if (joinfn == NULL) return NULL;
if (joinfn == NULL)
return NULL;
}
return PyObject_CallFunctionObjArgs(joinfn, lst, NULL);
}
......@@ -804,7 +810,8 @@
char *encoding = PyString_AS_STRING(s->encoding);
int strict = PyObject_IsTrue(s->strict);
Py_ssize_t next_idx;
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
/* skip whitespace after { */
while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
......@@ -818,7 +825,8 @@
goto bail;
}
key = scanstring_str(pystr, idx + 1, encoding, strict, &next_idx);
if (key == NULL) goto bail;
if (key == NULL)
goto bail;
Py_INCREF(key);
idx = next_idx;
......@@ -833,5 +841,6 @@
/* read any JSON data type and de-tuplefy the (rval, idx) */
tpl = scan_once_str(s, pystr, idx);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
......@@ -837,6 +846,8 @@
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
if (next_idx == -1 && PyErr_Occurred()) goto bail;
if (PyDict_SetItem(rval, key, PyTuple_GET_ITEM(tpl, 0)) == -1) goto bail;
if (next_idx == -1 && PyErr_Occurred())
goto bail;
if (PyDict_SetItem(rval, key, PyTuple_GET_ITEM(tpl, 0)) == -1)
goto bail;
Py_DECREF(tpl);
idx = next_idx;
tpl = NULL;
......@@ -867,7 +878,8 @@
/* if object_hook is not None: rval = object_hook(rval) */
if (s->object_hook != Py_None) {
tpl = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
Py_DECREF(rval);
rval = tpl;
tpl = NULL;
......@@ -889,7 +901,8 @@
PyObject *key = NULL;
int strict = PyObject_IsTrue(s->strict);
Py_ssize_t next_idx;
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
/* skip whitespace after { */
while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
......@@ -903,7 +916,8 @@
goto bail;
}
key = scanstring_unicode(pystr, idx + 1, strict, &next_idx);
if (key == NULL) goto bail;
if (key == NULL)
goto bail;
idx = next_idx;
/* skip whitespace between key and : delimiter, read :, skip whitespace */
......@@ -917,5 +931,6 @@
/* read any JSON term and de-tuplefy the (rval, idx) */
tpl = scan_once_unicode(s, pystr, idx);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
......@@ -921,6 +936,8 @@
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
if (next_idx == -1 && PyErr_Occurred()) goto bail;
if (PyDict_SetItem(rval, key, PyTuple_GET_ITEM(tpl, 0)) == -1) goto bail;
if (next_idx == -1 && PyErr_Occurred())
goto bail;
if (PyDict_SetItem(rval, key, PyTuple_GET_ITEM(tpl, 0)) == -1)
goto bail;
Py_DECREF(tpl);
idx = next_idx;
tpl = NULL;
......@@ -953,7 +970,8 @@
/* if object_hook is not None: rval = object_hook(rval) */
if (s->object_hook != Py_None) {
tpl = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
Py_DECREF(rval);
rval = tpl;
tpl = NULL;
......@@ -973,7 +991,8 @@
PyObject *tpl = NULL;
PyObject *rval = PyList_New(0);
Py_ssize_t next_idx;
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
/* skip whitespace after [ */
while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
......@@ -984,5 +1003,6 @@
/* read any JSON term and de-tuplefy the (rval, idx) */
tpl = scan_once_str(s, pystr, idx);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
......@@ -988,6 +1008,8 @@
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
if (next_idx == -1 && PyErr_Occurred()) goto bail;
if (PyList_Append(rval, PyTuple_GET_ITEM(tpl, 0)) == -1) goto bail;
if (next_idx == -1 && PyErr_Occurred())
goto bail;
if (PyList_Append(rval, PyTuple_GET_ITEM(tpl, 0)) == -1)
goto bail;
Py_DECREF(tpl);
idx = next_idx;
tpl = NULL;
......@@ -1030,7 +1052,8 @@
PyObject *tpl = NULL;
PyObject *rval = PyList_New(0);
Py_ssize_t next_idx;
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
/* skip whitespace after [ */
while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++;
......@@ -1041,5 +1064,6 @@
/* read any JSON term and de-tuplefy the (rval, idx) */
tpl = scan_once_unicode(s, pystr, idx);
if (tpl == NULL) goto bail;
if (tpl == NULL)
goto bail;
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
......@@ -1045,6 +1069,8 @@
next_idx = PyInt_AsSsize_t(PyTuple_GET_ITEM(tpl, 1));
if (next_idx == -1 && PyErr_Occurred()) goto bail;
if (PyList_Append(rval, PyTuple_GET_ITEM(tpl, 0)) == -1) goto bail;
if (next_idx == -1 && PyErr_Occurred())
goto bail;
if (PyList_Append(rval, PyTuple_GET_ITEM(tpl, 0)) == -1)
goto bail;
Py_DECREF(tpl);
idx = next_idx;
tpl = NULL;
......@@ -1086,7 +1112,8 @@
PyObject *rval;
/* constant is "NaN", "Infinity", or "-Infinity" */
cstr = PyString_InternFromString(constant);
if (cstr == NULL) return NULL;
if (cstr == NULL)
return NULL;
/* rval = parse_constant(constant) */
rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL);
......@@ -1159,7 +1186,8 @@
/* copy the section we determined to be a number */
numstr = PyString_FromStringAndSize(&str[start], idx - start);
if (numstr == NULL) return NULL;
if (numstr == NULL)
return NULL;
if (is_float) {
/* parse as a float using a fast path if available, otherwise call user defined method */
if (s->parse_float != (PyObject *)&PyFloat_Type) {
......@@ -1244,7 +1272,8 @@
/* copy the section we determined to be a number */
numstr = PyUnicode_FromUnicode(&str[start], idx - start);
if (numstr == NULL) return NULL;
if (numstr == NULL)
return NULL;
if (is_float) {
/* parse as a float using a fast path if available, otherwise call user defined method */
if (s->parse_float != (PyObject *)&PyFloat_Type) {
......@@ -1457,7 +1486,8 @@
Py_DECREF(s->encoding);
s->encoding = tmp;
}
if (s->encoding == NULL || !PyString_Check(s->encoding)) goto bail;
if (s->encoding == NULL || !PyString_Check(s->encoding))
goto bail;
/* All of these will fail "gracefully" so we don't need to verify them */
s->strict = PyObject_GetAttrString(ctx, "strict");
......@@ -1461,5 +1491,6 @@
/* All of these will fail "gracefully" so we don't need to verify them */
s->strict = PyObject_GetAttrString(ctx, "strict");
if (s->strict == NULL) goto bail;
if (s->strict == NULL)
goto bail;
s->object_hook = PyObject_GetAttrString(ctx, "object_hook");
......@@ -1465,3 +1496,4 @@
s->object_hook = PyObject_GetAttrString(ctx, "object_hook");
if (s->object_hook == NULL) goto bail;
if (s->object_hook == NULL)
goto bail;
s->parse_float = PyObject_GetAttrString(ctx, "parse_float");
......@@ -1467,3 +1499,4 @@
s->parse_float = PyObject_GetAttrString(ctx, "parse_float");
if (s->parse_float == NULL) goto bail;
if (s->parse_float == NULL)
goto bail;
s->parse_int = PyObject_GetAttrString(ctx, "parse_int");
......@@ -1469,3 +1502,4 @@
s->parse_int = PyObject_GetAttrString(ctx, "parse_int");
if (s->parse_int == NULL) goto bail;
if (s->parse_int == NULL)
goto bail;
s->parse_constant = PyObject_GetAttrString(ctx, "parse_constant");
......@@ -1471,5 +1505,6 @@
s->parse_constant = PyObject_GetAttrString(ctx, "parse_constant");
if (s->parse_constant == NULL) goto bail;
if (s->parse_constant == NULL)
goto bail;
return 0;
......@@ -1592,7 +1627,8 @@
#endif
return NULL;
rval = PyList_New(0);
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
if (encoder_listencode_obj(s, rval, obj, indent_level)) {
Py_DECREF(rval);
return NULL;
......@@ -1621,7 +1657,8 @@
#endif
return NULL;
rval = PyList_New(0);
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
if (encoder_listencode_dict(s, rval, dct, indent_level)) {
Py_DECREF(rval);
return NULL;
......@@ -1650,7 +1687,8 @@
#endif
return NULL;
rval = PyList_New(0);
if (rval == NULL) return NULL;
if (rval == NULL)
return NULL;
if (encoder_listencode_list(s, rval, seq, indent_level)) {
Py_DECREF(rval);
return NULL;
......@@ -1702,9 +1740,10 @@
{
if (obj == Py_None || obj == Py_True || obj == Py_False) {
PyObject *cstr = _encoded_const(obj);
if (cstr == NULL) return -1;
if (cstr == NULL)
return -1;
return PyList_Append(rval, cstr);
}
else if (PyString_Check(obj) || PyUnicode_Check(obj))
{
PyObject *encoded = encoder_encode_string(s, obj);
......@@ -1706,10 +1745,11 @@
return PyList_Append(rval, cstr);
}
else if (PyString_Check(obj) || PyUnicode_Check(obj))
{
PyObject *encoded = encoder_encode_string(s, obj);
if (encoded == NULL) return -1;
if (encoded == NULL)
return -1;
return PyList_Append(rval, encoded);
}
else if (PyInt_Check(obj) || PyLong_Check(obj)) {
PyObject *encoded = PyObject_Repr(obj);
......@@ -1712,9 +1752,10 @@
return PyList_Append(rval, encoded);
}
else if (PyInt_Check(obj) || PyLong_Check(obj)) {
PyObject *encoded = PyObject_Repr(obj);
if (encoded == NULL) return -1;
if (encoded == NULL)
return -1;
return PyList_Append(rval, encoded);
}
else if (PyFloat_Check(obj)) {
PyObject *encoded = PyObject_CallFunctionObjArgs(s->floatstr, obj, NULL);
......@@ -1717,8 +1758,9 @@
return PyList_Append(rval, encoded);
}
else if (PyFloat_Check(obj)) {
PyObject *encoded = PyObject_CallFunctionObjArgs(s->floatstr, obj, NULL);
if (encoded == NULL) return -1;
if (encoded == NULL)
return -1;
return PyList_Append(rval, encoded);
}
else if (PyList_Check(obj) || PyTuple_Check(obj)) {
......@@ -1732,7 +1774,8 @@
if (s->markers != Py_None) {
ident = PyLong_FromVoidPtr(obj);
int has_key;
if (ident == NULL) return -1;
if (ident == NULL)
return -1;
has_key = PyDict_Contains(s->markers, ident);
if (has_key) {
if (has_key != -1)
......@@ -1790,7 +1833,8 @@
if (s->markers != Py_None) {
ident = PyLong_FromVoidPtr(dct);
int has_key;
if (ident == NULL) goto bail;
if (ident == NULL)
goto bail;
has_key = PyDict_Contains(s->markers, ident);
if (has_key) {
if (has_key != -1)
......@@ -1802,7 +1846,8 @@
}
}
if (PyList_Append(rval, open_dict)) goto bail;
if (PyList_Append(rval, open_dict))
goto bail;
if (s->indent != Py_None) {
/* TODO: DOES NOT RUN */
......@@ -1827,7 +1872,8 @@
}
else if (PyFloat_Check(key)) {
kstr = PyObject_CallFunctionObjArgs(s->floatstr, key, NULL);
if (kstr == NULL) goto bail;
if (kstr == NULL)
goto bail;
}
else if (PyInt_Check(key) || PyLong_Check(key)) {
kstr = PyObject_Repr(key);
......@@ -1831,7 +1877,8 @@
}
else if (PyInt_Check(key) || PyLong_Check(key)) {
kstr = PyObject_Repr(key);
if (kstr == NULL) goto bail;
if (kstr == NULL)
goto bail;
}
else if (key == Py_True || key == Py_False || key == Py_None) {
kstr = _encoded_const(key);
......@@ -1846,9 +1893,10 @@
}
if (idx) {
if (PyList_Append(rval, s->item_separator)) goto bail;
if (PyList_Append(rval, s->item_separator))
goto bail;
}
PyObject *encoded = encoder_encode_string(s, kstr);
Py_DECREF(kstr);
kstr = NULL;
......@@ -1850,12 +1898,16 @@
}
PyObject *encoded = encoder_encode_string(s, kstr);
Py_DECREF(kstr);
kstr = NULL;
if (encoded == NULL) goto bail;
if (PyList_Append(rval, encoded)) goto bail;
if (PyList_Append(rval, s->key_separator)) goto bail;
if (encoder_listencode_obj(s, rval, value, indent_level)) goto bail;
if (encoded == NULL)
goto bail;
if (PyList_Append(rval, encoded))
goto bail;
if (PyList_Append(rval, s->key_separator))
goto bail;
if (encoder_listencode_obj(s, rval, value, indent_level))
goto bail;
idx += 1;
}
if (ident != NULL) {
......@@ -1859,7 +1911,8 @@
idx += 1;
}
if (ident != NULL) {
if (PyDict_DelItem(s->markers, ident)) goto bail;
if (PyDict_DelItem(s->markers, ident))
goto bail;
Py_DECREF(ident);
ident = NULL;
}
......@@ -1870,7 +1923,8 @@
yield '\n' + (' ' * (_indent * _current_indent_level))
*/
}
if (PyList_Append(rval, close_dict)) goto bail;
if (PyList_Append(rval, close_dict))
goto bail;
return 0;
bail:
......@@ -1906,7 +1960,8 @@
if (s->markers != Py_None) {
ident = PyLong_FromVoidPtr(seq);
int has_key;
if (ident == NULL) goto bail;
if (ident == NULL)
goto bail;
has_key = PyDict_Contains(s->markers, ident);
if (has_key) {
if (has_key != -1)
......@@ -1919,7 +1974,8 @@
}
PyObject **seq_items = PySequence_Fast_ITEMS(s_fast);
if (PyList_Append(rval, open_array)) goto bail;
if (PyList_Append(rval, open_array))
goto bail;
Py_ssize_t i;
if (s->indent != Py_None) {
/* TODO: DOES NOT RUN */
......@@ -1933,5 +1989,6 @@
for (i = 0; i < num_items; i++) {
PyObject *obj = seq_items[i];
if (i) {
if (PyList_Append(rval, s->item_separator)) goto bail;
if (PyList_Append(rval, s->item_separator))
goto bail;
}
......@@ -1937,4 +1994,5 @@
}
if (encoder_listencode_obj(s, rval, obj, indent_level)) goto bail;
if (encoder_listencode_obj(s, rval, obj, indent_level))
goto bail;
}
if (ident != NULL) {
......@@ -1939,6 +1997,7 @@
}
if (ident != NULL) {
if (PyDict_DelItem(s->markers, ident)) goto bail;
if (PyDict_DelItem(s->markers, ident))
goto bail;
Py_DECREF(ident);
ident = NULL;
}
......@@ -1949,7 +2008,8 @@
yield '\n' + (' ' * (_indent * _current_indent_level))
*/
}
if (PyList_Append(rval, close_array)) goto bail;
if (PyList_Append(rval, close_array))
goto bail;
Py_DECREF(s_fast);
return 0;
......@@ -1964,15 +2024,24 @@
{
assert(PyEncoder_Check(self));
PyEncoderObject *s = (PyEncoderObject *)self;
Py_XDECREF(s->markers); s->markers = NULL;
Py_XDECREF(s->defaultfn); s->defaultfn = NULL;
Py_XDECREF(s->encoder); s->encoder = NULL;
Py_XDECREF(s->indent); s->indent = NULL;
Py_XDECREF(s->floatstr); s->floatstr = NULL;
Py_XDECREF(s->key_separator); s->key_separator = NULL;
Py_XDECREF(s->item_separator); s->item_separator = NULL;
Py_XDECREF(s->sort_keys); s->sort_keys = NULL;
Py_XDECREF(s->skipkeys); s->skipkeys = NULL;
Py_XDECREF(s->markers);
s->markers = NULL;
Py_XDECREF(s->defaultfn);
s->defaultfn = NULL;
Py_XDECREF(s->encoder);
s->encoder = NULL;
Py_XDECREF(s->indent);
s->indent = NULL;
Py_XDECREF(s->floatstr);
s->floatstr = NULL;
Py_XDECREF(s->key_separator);
s->key_separator = NULL;
Py_XDECREF(s->item_separator);
s->item_separator = NULL;
Py_XDECREF(s->sort_keys);
s->sort_keys = NULL;
Py_XDECREF(s->skipkeys);
s->skipkeys = NULL;
self->ob_type->tp_free(self);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment