@@ -62,9 +62,6 @@ def pointer(self, struct):
62
62
## simple value converters
63
63
# will fail if fed wrong arguments
64
64
65
- def as_is (value ):
66
- return value
67
-
68
65
def to_bytes (value ):
69
66
if type (value ) is bytes : return value
70
67
else : return value .encode ('utf-8' , 'ignore' )
@@ -88,7 +85,7 @@ def makeFunc(c_func):
88
85
elif c_arg_type .kind == 'pointer' :
89
86
converters .append (to_pointer )
90
87
else :
91
- converters .append (as_is )
88
+ converters .append (None ) # None = leave as is
92
89
93
90
# not sure if this would bring any speedup
94
91
#converters = tuple(converters)
@@ -98,17 +95,19 @@ def makeFunc(c_func):
98
95
if c_result_type is ffi .typeof ('char *' ):
99
96
resultConverter = to_str
100
97
elif c_result_type :
101
- resultConverter = as_is
98
+ resultConverter = None # None = leave as is
102
99
103
100
# use a closure to bring converters into c function call
104
101
def func (* args ):
105
102
nonlocal converters , resultConverter
106
103
107
- result = c_func (* (convert (arg ) for (arg , convert ) in zip (args , converters ) ) )
104
+ result = c_func (* (convert (arg ) if convert else arg for (arg , convert ) in zip (args , converters ) ) )
108
105
109
- if result is None or resultConverter is None :
106
+ if result is None :
110
107
return
111
- return resultConverter (result )
108
+ if resultConverter :
109
+ return resultConverter (result )
110
+ return result
112
111
113
112
return func
114
113
0 commit comments