summaryrefslogtreecommitdiff
path: root/cffi/backend_ctypes.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-09-18 16:54:42 +0200
committerArmin Rigo <arigo@tunes.org>2012-09-18 16:54:42 +0200
commit0d04c39c2303e58cd097e47944914c06f19aec8b (patch)
tree9e79be8a272aeae977efe7698a0efc952888b388 /cffi/backend_ctypes.py
parent3c363d642f266cfa1636f8510d51774205ac0788 (diff)
downloadcffi-0d04c39c2303e58cd097e47944914c06f19aec8b.tar.gz
Remove a special case from _cffi_backend, and replace it with a general
solution: ffi.addressof(), only for structs or unions.
Diffstat (limited to 'cffi/backend_ctypes.py')
-rw-r--r--cffi/backend_ctypes.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
index 3f54869..17b9c36 100644
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -1044,6 +1044,12 @@ class CTypesBackend(object):
def getcname(self, BType, replace_with):
return BType._get_c_name(replace_with)
+ def addressof(self, BTypePtr, cdata):
+ if not isinstance(cdata, CTypesBaseStructOrUnion):
+ raise TypeError("expected a <cdata 'struct-or-union'>")
+ ptr = ctypes.pointer(type(cdata)._to_ctypes(cdata))
+ return BTypePtr._from_ctypes(ptr)
+
class CTypesLibrary(object):