diff options
author | Armin Rigo <arigo@tunes.org> | 2013-04-06 11:32:25 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2013-04-06 11:32:25 +0200 |
commit | 335d19f59213e0ac2e6129d0494addde12863659 (patch) | |
tree | 7badf437f3a25e2b90806cbfca0c5699746697f1 /cffi/backend_ctypes.py | |
parent | 310ba273925a522e718ee062c5867da2c0d1a517 (diff) | |
download | cffi-335d19f59213e0ac2e6129d0494addde12863659.tar.gz |
Test and fix in the ctypes backend for calling "void *" functions with a
Python string argument.
Diffstat (limited to 'cffi/backend_ctypes.py')
-rw-r--r-- | cffi/backend_ctypes.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py index 40a84ed..6975d9e 100644 --- a/cffi/backend_ctypes.py +++ b/cffi/backend_ctypes.py @@ -491,6 +491,8 @@ class CTypesBackend(object): elif BItem in (getbtype(model.PrimitiveType('signed char')), getbtype(model.PrimitiveType('unsigned char'))): kind = 'bytep' + elif BItem is getbtype(model.void_type): + kind = 'voidp' else: kind = 'generic' # @@ -546,13 +548,13 @@ class CTypesBackend(object): def __setitem__(self, index, value): self._as_ctype_ptr[index] = BItem._to_ctypes(value) - if kind == 'charp': + if kind == 'charp' or kind == 'voidp': @classmethod - def _arg_to_ctypes(cls, value): - if isinstance(value, bytes): - return ctypes.c_char_p(value) + def _arg_to_ctypes(cls, *value): + if value and isinstance(value[0], bytes): + return ctypes.c_char_p(value[0]) else: - return super(CTypesPtr, cls)._arg_to_ctypes(value) + return super(CTypesPtr, cls)._arg_to_ctypes(*value) if kind == 'charp' or kind == 'bytep': def _to_string(self, maxlen): |