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
1=== modified file 'ijson/lib.py'
2--- ijson/lib.py 2010-12-03 13:48:18 +0000
3+++ ijson/lib.py 2010-12-04 11:51:13 +0000
4@@ -7,7 +7,7 @@
5 if name is None:
6 import os
7 hardy64_name = '/usr/lib/libyajl.so.1'
8- os.path.exists(hardy64_name):
9+ if os.path.exists(hardy64_name):
10 name = hardy64_name
11
12 if name is None:
13@@ -17,3 +17,4 @@
14 yajl.yajl_alloc.restype = POINTER(c_char)
15 yajl.yajl_gen_alloc.restype = POINTER(c_char)
16 yajl.yajl_gen_alloc2.restype = POINTER(c_char)
17+yajl.yajl_get_error.restype = POINTER(c_char)
18
19=== modified file 'ijson/parse.py'
20--- ijson/parse.py 2010-09-28 19:29:37 +0000
21+++ ijson/parse.py 2010-12-04 11:51:13 +0000
22@@ -1,5 +1,5 @@
23 from ctypes import Structure, c_uint, c_ubyte, c_int, c_long, c_double, \
24- c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at
25+ c_void_p, c_char_p, CFUNCTYPE, POINTER, byref, string_at, cast
26 from decimal import Decimal
27
28 from ijson.lib import yajl
29@@ -94,7 +94,6 @@
30 return 1
31 return func_type(c_callback)
32
33- yajl.yajl_get_error.restype = c_void_p
34 callbacks = Callbacks(*[callback(*data) for data in _callback_data])
35 config = Config(allow_comments, check_utf8)
36 handle = yajl.yajl_alloc(byref(callbacks), byref(config), None, None)
37@@ -107,7 +106,7 @@
38 result = yajl.yajl_parse_complete(handle)
39 if result == YAJL_ERROR:
40 perror = yajl.yajl_get_error(handle, 1, buffer, len(buffer))
41- error = c_char_p(perror).value
42+ error = cast(perror, c_char_p).value
43 yajl.yajl_free_error(handle, perror)
44 raise JSONError(error)
45 if not buffer and not events:
46
47=== modified file 'tests.py'
48--- tests.py 2010-09-28 09:30:05 +0000
49+++ tests.py 2010-12-04 11:51:13 +0000
50@@ -2,6 +2,7 @@
51 import unittest
52 from cStringIO import StringIO
53 from decimal import Decimal
54+import threading
55
56 from ijson import parse, basic_parse, JSONError, IncompleteJSONError, ObjectBuilder, items
57
58@@ -162,7 +163,50 @@
59 {'key': 'value'},
60 None,
61 ])
62-
63+
64+class FuncThread(threading.Thread):
65+ def __init__(self, func):
66+ super(FuncThread, self).__init__()
67+ self.func = func
68+
69+ def run(self):
70+ self.func()
71+
72+class ParseThreaded(Parse):
73+ def test_basic_parse(self):
74+ t = FuncThread(super(ParseThreaded, self).test_basic_parse)
75+ t.start()
76+ t.join()
77+
78+ def test_parse(self):
79+ t = FuncThread(super(ParseThreaded, self).test_parse)
80+ t.start()
81+ t.join()
82+
83+ def test_scalar(self):
84+ t = FuncThread(super(ParseThreaded, self).test_scalar)
85+ t.start()
86+ t.join()
87+
88+ def test_empty(self):
89+ t = FuncThread(super(ParseThreaded, self).test_empty)
90+ t.start()
91+ t.join()
92+
93+ def test_incomplete(self):
94+ t = FuncThread(super(ParseThreaded, self).test_incomplete)
95+ t.start()
96+ t.join()
97+
98+ def test_invalid(self):
99+ t = FuncThread(super(ParseThreaded, self).test_invalid)
100+ t.start()
101+ t.join()
102+
103+ def test_lazy(self):
104+ t = FuncThread(super(ParseThreaded, self).test_lazy)
105+ t.start()
106+ t.join()
107
108 if __name__ == '__main__':
109 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: