Skip to content
Snippets Groups Projects
Commit f8a3477931fe authored by Bob Ippolito's avatar Bob Ippolito
Browse files

add test coverage for check_circular and fix a Py_DECREF(NULL) but when check_circular=False

git-svn-id: http://simplejson.googlecode.com/svn/trunk@152 a4795897-2c25-0410-b006-0d3caba88fa1
parent a46f9b3387ed
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@
from distutils.errors import CCompilerError, DistutilsExecError, \
DistutilsPlatformError
VERSION = '2.0.4'
VERSION = '2.0.5'
DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
LONG_DESCRIPTION = """
simplejson is a simple, fast, complete, correct and extensible
......
......@@ -94,7 +94,7 @@
$ echo '{ 1.2:3.4}' | python -msimplejson.tool
Expecting property name: line 1 column 2 (char 2)
"""
__version__ = '2.0.4'
__version__ = '2.0.5'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONEncoder',
......
......@@ -1778,9 +1778,9 @@
}
newobj = PyObject_CallFunctionObjArgs(s->defaultfn, obj, NULL);
if (newobj == NULL) {
Py_DECREF(ident);
Py_XDECREF(ident);
return -1;
}
rv = encoder_listencode_obj(s, rval, newobj, indent_level);
Py_DECREF(newobj);
if (rv) {
......@@ -1782,10 +1782,10 @@
return -1;
}
rv = encoder_listencode_obj(s, rval, newobj, indent_level);
Py_DECREF(newobj);
if (rv) {
Py_DECREF(ident);
Py_XDECREF(ident);
return -1;
}
if (ident != NULL) {
if (PyDict_DelItem(s->markers, ident)) {
......@@ -1788,7 +1788,7 @@
return -1;
}
if (ident != NULL) {
if (PyDict_DelItem(s->markers, ident)) {
Py_DECREF(ident);
Py_XDECREF(ident);
return -1;
}
......@@ -1793,6 +1793,6 @@
return -1;
}
Py_DECREF(ident);
Py_XDECREF(ident);
}
return rv;
}
......
from unittest import TestCase
import simplejson as json
def default_iterable(obj):
return list(obj)
class TestCheckCircular(TestCase):
def test_circular_dict(self):
dct = {}
dct['a'] = dct
self.assertRaises(ValueError, json.dumps, dct)
def test_circular_list(self):
lst = []
lst.append(lst)
self.assertRaises(ValueError, json.dumps, lst)
def test_circular_composite(self):
dct2 = {}
dct2['a'] = []
dct2['a'].append(dct2)
self.assertRaises(ValueError, json.dumps, dct2)
def test_circular_default(self):
json.dumps([set()], default=default_iterable)
self.assertRaises(TypeError, json.dumps, [set()])
def test_circular_off_default(self):
json.dumps([set()], default=default_iterable, check_circular=False)
self.assertRaises(TypeError, json.dumps, [set()], check_circular=False)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment