# HG changeset patch
# User Bob Ippolito <bob@redivi.com>
# Date 1261954451 0
#      Sun Dec 27 22:54:11 2009 +0000
# Node ID f6f1a23db6fb76dca8232a41c5dde07f0227c865
# Parent  e23b4ce931c7a5de67ae8de6b6a28779dc8dc9f3
fix Py_ssize_t converter

git-svn-id: http://simplejson.googlecode.com/svn/trunk@215 a4795897-2c25-0410-b006-0d3caba88fa1

diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -161,9 +161,9 @@
 {
     /* PyObject to Py_ssize_t converter */
     *size_ptr = PyInt_AsSsize_t(o);
-    if (*size_ptr == -1 && PyErr_Occurred());
-        return 1;
-    return 0;
+    if (*size_ptr == -1 && PyErr_Occurred())
+        return 0;
+    return 1;
 }
 
 static PyObject *
@@ -476,6 +476,7 @@
     char *buf = PyString_AS_STRING(pystr);
     PyObject *chunks = NULL;
     PyObject *chunk = NULL;
+
     if (end < 0 || len <= end) {
         PyErr_SetString(PyExc_ValueError, "end is out of bounds");
         goto bail;
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -42,6 +42,7 @@
         'simplejson.tests.test_recursion',
         'simplejson.tests.test_scanstring',
         'simplejson.tests.test_separators',
+        'simplejson.tests.test_speedups',
         'simplejson.tests.test_unicode',
     ])
     suite = additional_tests(suite)
diff --git a/simplejson/tests/test_decode.py b/simplejson/tests/test_decode.py
--- a/simplejson/tests/test_decode.py
+++ b/simplejson/tests/test_decode.py
@@ -8,16 +8,16 @@
 class TestDecode(TestCase):
     if not hasattr(TestCase, 'assertIs'):
         def assertIs(self, a, b):
-            self.assert_(a is b, '%r is %r' % (a, b))
+            self.assertTrue(a is b, '%r is %r' % (a, b))
 
     def test_decimal(self):
         rval = json.loads('1.1', parse_float=decimal.Decimal)
-        self.assert_(isinstance(rval, decimal.Decimal))
+        self.assertTrue(isinstance(rval, decimal.Decimal))
         self.assertEquals(rval, decimal.Decimal('1.1'))
 
     def test_float(self):
         rval = json.loads('1', parse_int=float)
-        self.assert_(isinstance(rval, float))
+        self.assertTrue(isinstance(rval, float))
         self.assertEquals(rval, 1.0)
 
     def test_decoder_optimizations(self):
diff --git a/simplejson/tests/test_indent.py b/simplejson/tests/test_indent.py
--- a/simplejson/tests/test_indent.py
+++ b/simplejson/tests/test_indent.py
@@ -5,7 +5,8 @@
 
 class TestIndent(TestCase):
     def test_indent(self):
-        h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
+        h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh',
+             'i-vhbjkhnth',
              {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
 
         expect = textwrap.dedent("""\
@@ -44,6 +45,9 @@
         self.assertEquals(h2, h)
         self.assertEquals(h3, h)
         self.assertEquals(h4, h)
-        self.assertEquals(d2, expect)
         self.assertEquals(d3, expect.replace('\t', '  '))
         self.assertEquals(d4, expect.replace('\t', '  '))
+        # NOTE: Python 2.4 textwrap.dedent converts tabs to spaces,
+        #       so the following is expected to fail. Python 2.4 is not a
+        #       supported platform in simplejson 2.1.0+.
+        self.assertEquals(d2, expect)
diff --git a/simplejson/tests/test_scanstring.py b/simplejson/tests/test_scanstring.py
--- a/simplejson/tests/test_scanstring.py
+++ b/simplejson/tests/test_scanstring.py
@@ -1,5 +1,4 @@
 import sys
-import decimal
 from unittest import TestCase
 
 import simplejson as json
@@ -109,3 +108,8 @@
                           "xxx")
         self.assertRaises(UnicodeDecodeError,
                           json.encoder.encode_basestring_ascii, "xx\xff")
+
+    def test_overflow(self):
+        self.assertRaises(OverflowError, json.decoder.scanstring, "xxx",
+                          sys.maxsize + 1)
+
diff --git a/simplejson/tests/test_speedups.py b/simplejson/tests/test_speedups.py
new file mode 100644
--- /dev/null
+++ b/simplejson/tests/test_speedups.py
@@ -0,0 +1,14 @@
+import decimal
+from unittest import TestCase
+
+from simplejson import decoder, encoder, scanner
+
+class TestDecode(TestCase):
+    def test_make_scanner(self):
+        self.assertRaises(AttributeError, scanner.c_make_scanner, 1)
+
+    def test_make_encoder(self):
+        self.assertRaises(TypeError, encoder.c_make_encoder,
+            None,
+            "\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
+            None)