# HG changeset patch # User Bob Ippolito <bob@redivi.com> # Date 1226907940 0 # Mon Nov 17 07:45:40 2008 +0000 # Node ID f8a3477931fe9db40299597ebc1cc320225745a3 # Parent a46f9b3387ed23c7cc9ef29c4497d138b98c1f31 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 diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -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 diff --git a/simplejson/__init__.py b/simplejson/__init__.py --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -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', diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -1778,21 +1778,21 @@ } 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) { - Py_DECREF(ident); + Py_XDECREF(ident); return -1; } if (ident != NULL) { if (PyDict_DelItem(s->markers, ident)) { - Py_DECREF(ident); + Py_XDECREF(ident); return -1; } - Py_DECREF(ident); + Py_XDECREF(ident); } return rv; } diff --git a/simplejson/tests/test_check_circular.py b/simplejson/tests/test_check_circular.py new file mode 100644 --- /dev/null +++ b/simplejson/tests/test_check_circular.py @@ -0,0 +1,30 @@ +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)