Skip to content

Commit 0a73edf

Browse files
committed
Slightly simplify python3 function wrapper
1 parent 80248fc commit 0a73edf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/parse/cffi/please_parser.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,14 @@ def _get_globals(c_package, c_package_name):
465465
@ffi.def_extern('RegisterCallback')
466466
def register_callback(name, c_type, callback):
467467
"""Called at initialisation time to register a single callback."""
468+
f = ffi.cast(ffi_to_string(c_type), callback)
468469
if is_py3:
469470
# Wrap the function up to auto-encode to bytes (ffi requires this in py3)
470471
# TODO(pebers): this is not exactly beautiful, can we find a better way of handling it?
471-
t = ffi_to_string(c_type)
472-
argdefs = [arg == 'char*' for arg in t[t.find('(*)')+4:].rstrip(')').split(', ')]
473-
f = ffi.cast(t, callback)
474-
globals()[ffi_to_string(name)] = lambda *args: f(*[ffi_from_string(arg) if argdef and isinstance(arg, str) else arg
475-
for arg, argdef in zip(args, argdefs)])
472+
globals()[ffi_to_string(name)] = lambda *args: f(
473+
*[ffi_from_string(arg) if isinstance(arg, str) else arg for arg in args])
476474
else:
477-
globals()[ffi_to_string(name)] = ffi.cast(ffi_to_string(c_type), callback)
475+
globals()[ffi_to_string(name)] = f
478476
return 1 # used to detect success (must be nonzero)
479477

480478

0 commit comments

Comments
 (0)