Skip to content

apply patch from issue 166 #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ def __init__(self, name, type_index, size, signed, allenums):
self.allenums = allenums

def as_c_expr(self):
return (' { "%s", %d, _cffi_prim_int(%s, %s),\n'
' "%s" },' % (self.name, self.type_index,
self.size, self.signed, self.allenums))
lines = [' { "%s", %d, _cffi_prim_int(%s, %s),' % (self.name, self.type_index,
self.size, self.signed,)]
pending = 0
while len(self.allenums) > pending + 110:
j = self.allenums.find(',', pending + 100)
if j < 0:
break
j += 1
lines.append(' "%s"' % (self.allenums[pending:j],))
pending = j
lines.append(' "%s" },' % (self.allenums[pending:],))
return '\n'.join(lines)

def as_python_expr(self):
prim_index = {
Expand Down
19 changes: 19 additions & 0 deletions testing/cffi1/test_recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2575,3 +2575,22 @@ def test_convert_api_mode_builtin_function_to_cdata():
my_array_2 = ffi.new("void *[]", [lib.add1, lib.add2])
assert ffi.cast("struct s(*)(struct s)", my_array_2[1])(s).x == 302
assert ffi.typeof(lib.add1) == ffi.typeof("struct s(*)(struct s)")

def test_large_enum():
ffi = FFI()
biglist = ['nn%d' % i for i in range(6000)]
ffi.cdef(
"""enum foo_s { %s };""" % ','.join(biglist))
lib = verify(ffi, "test_large_enum", """
enum foo_s { %s };""" % ','.join(biglist))
assert lib.nn0 == 0
assert lib.nn1234 == 1234
assert lib.nn5999 == 5999
e = ffi.typeof("enum foo_s")
elements = {}
relements = {}
for i in range(6000):
elements[i] = biglist[i]
relements[biglist[i]] = i
assert e.elements == elements
assert e.relements == relements
Loading