summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2011-05-07 09:47:42 -0600
committerBob Ippolito <bob@redivi.com>2011-05-07 09:47:42 -0600
commitdc58b92571947568e67bb3e30ab6c891009e4c8b (patch)
tree1d33fe7a3b218e5e52044d9412d17034008a6e25
parent0c854c67b919ea768fa8aba0a5fa2e7e5449455b (diff)
downloadsimplejson-dc58b92571947568e67bb3e30ab6c891009e4c8b.tar.gz
scan_once_unicode recursion check
-rw-r--r--simplejson/_speedups.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index 156d41e..9db9068 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -1728,67 +1728,91 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
*/
Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
+ PyObject *rval = NULL;
+ int fallthrough = 0;
if (idx >= length) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
+ if (Py_EnterRecursiveCall(" while decoding a JSON document"))
+ return NULL;
switch (str[idx]) {
case '"':
/* string */
- return scanstring_unicode(pystr, idx + 1,
+ rval = scanstring_unicode(pystr, idx + 1,
PyObject_IsTrue(s->strict),
next_idx_ptr);
+ break;
case '{':
/* object */
- return _parse_object_unicode(s, pystr, idx + 1, next_idx_ptr);
+ rval = _parse_object_unicode(s, pystr, idx + 1, next_idx_ptr);
+ break;
case '[':
/* array */
- return _parse_array_unicode(s, pystr, idx + 1, next_idx_ptr);
+ rval = _parse_array_unicode(s, pystr, idx + 1, next_idx_ptr);
+ break;
case 'n':
/* null */
if ((idx + 3 < length) && str[idx + 1] == 'u' && str[idx + 2] == 'l' && str[idx + 3] == 'l') {
Py_INCREF(Py_None);
*next_idx_ptr = idx + 4;
- return Py_None;
+ rval = Py_None;
}
+ else
+ fallthrough = 1;
break;
case 't':
/* true */
if ((idx + 3 < length) && str[idx + 1] == 'r' && str[idx + 2] == 'u' && str[idx + 3] == 'e') {
Py_INCREF(Py_True);
*next_idx_ptr = idx + 4;
- return Py_True;
+ rval = Py_True;
}
+ else
+ fallthrough = 1;
break;
case 'f':
/* false */
if ((idx + 4 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'l' && str[idx + 3] == 's' && str[idx + 4] == 'e') {
Py_INCREF(Py_False);
*next_idx_ptr = idx + 5;
- return Py_False;
+ rval = Py_False;
}
+ else
+ fallthrough = 1;
break;
case 'N':
/* NaN */
if ((idx + 2 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'N') {
- return _parse_constant(s, "NaN", idx, next_idx_ptr);
+ rval = _parse_constant(s, "NaN", idx, next_idx_ptr);
}
+ else
+ fallthrough = 1;
break;
case 'I':
/* Infinity */
if ((idx + 7 < length) && str[idx + 1] == 'n' && str[idx + 2] == 'f' && str[idx + 3] == 'i' && str[idx + 4] == 'n' && str[idx + 5] == 'i' && str[idx + 6] == 't' && str[idx + 7] == 'y') {
- return _parse_constant(s, "Infinity", idx, next_idx_ptr);
+ rval = _parse_constant(s, "Infinity", idx, next_idx_ptr);
}
+ else
+ fallthrough = 1;
break;
case '-':
/* -Infinity */
if ((idx + 8 < length) && str[idx + 1] == 'I' && str[idx + 2] == 'n' && str[idx + 3] == 'f' && str[idx + 4] == 'i' && str[idx + 5] == 'n' && str[idx + 6] == 'i' && str[idx + 7] == 't' && str[idx + 8] == 'y') {
- return _parse_constant(s, "-Infinity", idx, next_idx_ptr);
+ rval = _parse_constant(s, "-Infinity", idx, next_idx_ptr);
}
+ else
+ fallthrough = 1;
break;
+ default:
+ fallthrough = 1;
}
/* Didn't find a string, object, array, or named constant. Look for a number. */
- return _match_number_unicode(s, pystr, idx, next_idx_ptr);
+ if (fallthrough)
+ rval = _match_number_unicode(s, pystr, idx, next_idx_ptr);
+ Py_LeaveRecursiveCall();
+ return rval;
}
static PyObject *