Permalink
Browse files

fix yajl.get_error return pointer trunction

add threaded test case which seem to trigger the truncation
fix lib hardy check
  • Loading branch information...
1 parent 824cf02 commit e95255b3563d15cf42832dd93a95c7f0e7204b1f andrewimam@hotmail.com committed Dec 4, 2010
Showing with 48 additions and 4 deletions.
  1. +2 −1 ijson/lib.py
  2. +2 −3 ijson/parse.py
  3. +44 −0 tests.py
View
@@ -7,7 +7,7 @@
if name is None:
import os
hardy64_name = '/usr/lib/libyajl.so.1'
- os.path.exists(hardy64_name):
+ if os.path.exists(hardy64_name):
name = hardy64_name
if name is None:
@@ -17,3 +17,4 @@
yajl.yajl_alloc.restype = POINTER(c_char)
yajl.yajl_gen_alloc.restype = POINTER(c_char)
yajl.yajl_gen_alloc2.restype = POINTER(c_char)
+yajl.yajl_get_error.restype = POINTER(c_char)
View
@@ -1,5 +1,5 @@
from ctypes import Structure, c_uint, c_ubyte, c_int, c_long, c_double, \
- c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at
+ c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at, cast
from decimal import Decimal
from ijson.lib import yajl
@@ -94,7 +94,6 @@ def c_callback(context, *args):
return 1
return func_type(c_callback)
- yajl.yajl_get_error.restype = c_void_p
callbacks = Callbacks(*[callback(*data) for data in _callback_data])
config = Config(allow_comments, check_utf8)
handle = yajl.yajl_alloc(byref(callbacks), byref(config), None, None)
@@ -107,7 +106,7 @@ def c_callback(context, *args):
result = yajl.yajl_parse_complete(handle)
if result == YAJL_ERROR:
perror = yajl.yajl_get_error(handle, 1, buffer, len(buffer))
- error = c_char_p(perror).value
+ error = cast(perror, c_char_p).value
yajl.yajl_free_error(handle, perror)
raise JSONError(error)
if not buffer and not events:
View
@@ -2,6 +2,7 @@
import unittest
from cStringIO import StringIO
from decimal import Decimal
+import threading
from ijson import parse, basic_parse, JSONError, IncompleteJSONError, ObjectBuilder, items
@@ -162,7 +163,50 @@ def test_items(self):
{'key': 'value'},
None,
])
+
+class FuncThread(threading.Thread):
+ def __init__(self, func):
+ super(FuncThread, self).__init__()
+ self.func = func
+
+ def run(self):
+ self.func()
+class ParseThreaded(Parse):
+ def test_basic_parse(self):
+ t = FuncThread(super(ParseThreaded, self).test_basic_parse)
+ t.start()
+ t.join()
+
+ def test_parse(self):
+ t = FuncThread(super(ParseThreaded, self).test_parse)
+ t.start()
+ t.join()
+
+ def test_scalar(self):
+ t = FuncThread(super(ParseThreaded, self).test_scalar)
+ t.start()
+ t.join()
+
+ def test_empty(self):
+ t = FuncThread(super(ParseThreaded, self).test_empty)
+ t.start()
+ t.join()
+
+ def test_incomplete(self):
+ t = FuncThread(super(ParseThreaded, self).test_incomplete)
+ t.start()
+ t.join()
+
+ def test_invalid(self):
+ t = FuncThread(super(ParseThreaded, self).test_invalid)
+ t.start()
+ t.join()
+
+ def test_lazy(self):
+ t = FuncThread(super(ParseThreaded, self).test_lazy)
+ t.start()
+ t.join()
if __name__ == '__main__':
unittest.main()

0 comments on commit e95255b

Please sign in to comment.