Merge lp:~ai-2/ijson/more-ptr-trunc into lp:~isagalaev/ijson/trunk

Proposed by a
Status: Merged
Merged at revision: 28
Proposed branch: lp:~ai-2/ijson/more-ptr-trunc
Merge into: lp:~isagalaev/ijson/trunk
Diff against target: 109 lines (+49/-5)
3 files modified
ijson/lib.py (+2/-1)
ijson/parse.py (+2/-3)
tests.py (+45/-1)
To merge this branch: bzr merge lp:~ai-2/ijson/more-ptr-trunc
Reviewer Review Type Date Requested Status
Ivan Sagalaev Pending
Review via email: mp+42728@code.launchpad.net

Description of the change

return pointer truncation issue for yajl.get_error (ctype.c_void_p is int?).

added a threading test case that seem to triggers this problem.

all test cases pass w/ fedora 13 x86_64, python 2.6

To post a comment you must log in.
Revision history for this message
Ivan Sagalaev (isagalaev) wrote :

> --- ijson/lib.py 2010-12-03 13:48:18 +0000
> +++ ijson/lib.py 2010-12-04 11:51:13 +0000
>
> @@ -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

Doh... Sorry for this, I was in a hurry :-(

Thanks for the fix!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ijson/lib.py'
--- ijson/lib.py 2010-12-03 13:48:18 +0000
+++ ijson/lib.py 2010-12-04 11:51:13 +0000
@@ -7,7 +7,7 @@
7if name is None:7if name is None:
8 import os8 import os
9 hardy64_name = '/usr/lib/libyajl.so.1'9 hardy64_name = '/usr/lib/libyajl.so.1'
10 os.path.exists(hardy64_name):10 if os.path.exists(hardy64_name):
11 name = hardy64_name11 name = hardy64_name
1212
13if name is None:13if name is None:
@@ -17,3 +17,4 @@
17yajl.yajl_alloc.restype = POINTER(c_char)17yajl.yajl_alloc.restype = POINTER(c_char)
18yajl.yajl_gen_alloc.restype = POINTER(c_char)18yajl.yajl_gen_alloc.restype = POINTER(c_char)
19yajl.yajl_gen_alloc2.restype = POINTER(c_char)19yajl.yajl_gen_alloc2.restype = POINTER(c_char)
20yajl.yajl_get_error.restype = POINTER(c_char)
2021
=== modified file 'ijson/parse.py'
--- ijson/parse.py 2010-09-28 19:29:37 +0000
+++ ijson/parse.py 2010-12-04 11:51:13 +0000
@@ -1,5 +1,5 @@
1from ctypes import Structure, c_uint, c_ubyte, c_int, c_long, c_double, \1from ctypes import Structure, c_uint, c_ubyte, c_int, c_long, c_double, \
2 c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at2 c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at, cast
3from decimal import Decimal3from decimal import Decimal
44
5from ijson.lib import yajl5from ijson.lib import yajl
@@ -94,7 +94,6 @@
94 return 194 return 1
95 return func_type(c_callback)95 return func_type(c_callback)
9696
97 yajl.yajl_get_error.restype = c_void_p
98 callbacks = Callbacks(*[callback(*data) for data in _callback_data])97 callbacks = Callbacks(*[callback(*data) for data in _callback_data])
99 config = Config(allow_comments, check_utf8)98 config = Config(allow_comments, check_utf8)
100 handle = yajl.yajl_alloc(byref(callbacks), byref(config), None, None)99 handle = yajl.yajl_alloc(byref(callbacks), byref(config), None, None)
@@ -107,7 +106,7 @@
107 result = yajl.yajl_parse_complete(handle)106 result = yajl.yajl_parse_complete(handle)
108 if result == YAJL_ERROR:107 if result == YAJL_ERROR:
109 perror = yajl.yajl_get_error(handle, 1, buffer, len(buffer))108 perror = yajl.yajl_get_error(handle, 1, buffer, len(buffer))
110 error = c_char_p(perror).value109 error = cast(perror, c_char_p).value
111 yajl.yajl_free_error(handle, perror)110 yajl.yajl_free_error(handle, perror)
112 raise JSONError(error)111 raise JSONError(error)
113 if not buffer and not events:112 if not buffer and not events:
114113
=== modified file 'tests.py'
--- tests.py 2010-09-28 09:30:05 +0000
+++ tests.py 2010-12-04 11:51:13 +0000
@@ -2,6 +2,7 @@
2import unittest2import unittest
3from cStringIO import StringIO3from cStringIO import StringIO
4from decimal import Decimal4from decimal import Decimal
5import threading
56
6from ijson import parse, basic_parse, JSONError, IncompleteJSONError, ObjectBuilder, items7from ijson import parse, basic_parse, JSONError, IncompleteJSONError, ObjectBuilder, items
78
@@ -162,7 +163,50 @@
162 {'key': 'value'},163 {'key': 'value'},
163 None,164 None,
164 ])165 ])
165166
167class FuncThread(threading.Thread):
168 def __init__(self, func):
169 super(FuncThread, self).__init__()
170 self.func = func
171
172 def run(self):
173 self.func()
174
175class ParseThreaded(Parse):
176 def test_basic_parse(self):
177 t = FuncThread(super(ParseThreaded, self).test_basic_parse)
178 t.start()
179 t.join()
180
181 def test_parse(self):
182 t = FuncThread(super(ParseThreaded, self).test_parse)
183 t.start()
184 t.join()
185
186 def test_scalar(self):
187 t = FuncThread(super(ParseThreaded, self).test_scalar)
188 t.start()
189 t.join()
190
191 def test_empty(self):
192 t = FuncThread(super(ParseThreaded, self).test_empty)
193 t.start()
194 t.join()
195
196 def test_incomplete(self):
197 t = FuncThread(super(ParseThreaded, self).test_incomplete)
198 t.start()
199 t.join()
200
201 def test_invalid(self):
202 t = FuncThread(super(ParseThreaded, self).test_invalid)
203 t.start()
204 t.join()
205
206 def test_lazy(self):
207 t = FuncThread(super(ParseThreaded, self).test_lazy)
208 t.start()
209 t.join()
166210
167if __name__ == '__main__':211if __name__ == '__main__':
168 unittest.main()212 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: