Lenard Lindstrom committed 12ebe54

add svn properties and add capsule support to for Python 3.x

Comments (0)

Files changed (1)

+import sys
 from ctypes import *
+PY3 = 0
+if sys.version_info >= (3,):
+    PY3 = 1
 class PyArrayInterface(Structure):
     _fields_ = [('two', c_int), ('nd', c_int), ('typekind', c_char),
                 ('itemsize', c_int), ('flags', c_int),
 PyCObject_AsVoidPtr = pythonapi.PyCObject_AsVoidPtr
 PyCObject_AsVoidPtr.restype = c_void_p
 PyCObject_AsVoidPtr.argtypes = [py_object]
+    PyCapsule_IsValid = pythonapi.PyCapsule_IsValid
+except AttributeError:
+    def PyCapsule_IsValid(capsule, name):
+        return 0
+    PyCapsule_IsValid.restype = c_int
+    PyCapsule_IsValid.argtypes = [py_object, c_char_p]
+    PyCapsule_GetPointer = pythonapi.PyCapsule_GetPointer
+    PyCapsule_GetPointer.restype = c_void_p
+    PyCapsule_GetPointer.argtypes = [py_object, c_char_p]
 class Inter(object):
     def __init__(self, arr):
-        self._cobj = arr.__array_struct__
-        vp = PyCObject_AsVoidPtr(self._cobj)
+        try:
+            self._cobj = arr.__array_struct__
+        except AttributeError:
+            raise TypeError("The array object lacks an array structure")
+        if not self._cobj:
+            raise TypeError("The array object has a NULL array structure value")
+        try:
+            vp = PyCObject_AsVoidPtr(self._cobj)
+        except TypeError:
+            if PyCapsule_IsValid(self._cobj, None):
+                vp = PyCapsule_GetPointer(self._cobj, None)
+            else:
+                raise TypeError("The array object has an invalid array structure")
         self._inter = cast(vp, PAI_Ptr)[0]
     def __getattr__(self, name):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.