summaryrefslogtreecommitdiff
path: root/cffi/backend_ctypes.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-08-12 19:33:49 +0200
committerArmin Rigo <arigo@tunes.org>2012-08-12 19:33:49 +0200
commitd7c947814dae58b3a9c81d8840be1e50f6a639ae (patch)
tree35237f81cb89776f69258d44345755e46b30dab7 /cffi/backend_ctypes.py
parent045b1df9f88e760608cc602b2a60641d346b1afa (diff)
downloadcffi-d7c947814dae58b3a9c81d8840be1e50f6a639ae.tar.gz
Fix
Diffstat (limited to 'cffi/backend_ctypes.py')
-rw-r--r--cffi/backend_ctypes.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
index 0ed0fda..b0e5c04 100644
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -469,6 +469,8 @@ class CTypesBackend(object):
#
class CTypesPtr(CTypesGenericPtr):
__slots__ = ['_own']
+ if kind == 'charp':
+ __slots__ += ['__as_strbuf']
_BItem = BItem
if hasattr(BItem, '_ctype'):
_ctype = ctypes.POINTER(BItem._ctype)
@@ -482,7 +484,13 @@ class CTypesBackend(object):
def __init__(self, init):
ctypeobj = BItem._create_ctype_obj(init)
- self._as_ctype_ptr = ctypes.pointer(ctypeobj)
+ if kind == 'charp':
+ self.__as_strbuf = ctypes.create_string_buffer(
+ ctypeobj.value + b'\x00')
+ self._as_ctype_ptr = ctypes.cast(
+ self.__as_strbuf, self._ctype)
+ else:
+ self._as_ctype_ptr = ctypes.pointer(ctypeobj)
self._address = ctypes.cast(self._as_ctype_ptr,
ctypes.c_void_p).value
self._own = True
@@ -526,9 +534,9 @@ class CTypesBackend(object):
p = ctypes.cast(self._as_ctype_ptr,
ctypes.POINTER(ctypes.c_char))
n = 0
- while n < maxlen and p[n] != '\x00':
+ while n < maxlen and p[n] != b'\x00':
n += 1
- return ''.join([p[i] for i in range(n)])
+ return b''.join([p[i] for i in range(n)])
def _get_own_repr(self):
if getattr(self, '_own', False):
@@ -619,9 +627,9 @@ class CTypesBackend(object):
p = ctypes.cast(self._blob,
ctypes.POINTER(ctypes.c_char))
n = 0
- while n < maxlen and p[n] != '\x00':
+ while n < maxlen and p[n] != b'\x00':
n += 1
- return ''.join([p[i] for i in range(n)])
+ return b''.join([p[i] for i in range(n)])
def _get_own_repr(self):
if getattr(self, '_own', False):