Commits

Lenard Lindstrom committed 528255c

update capsule support and add desc/context access

Comments (0)

Files changed (1)

                 ('data', c_void_p), ('descr', py_object)]
 
 PAI_Ptr = POINTER(PyArrayInterface)
-PyCObject_AsVoidPtr = pythonapi.PyCObject_AsVoidPtr
-PyCObject_AsVoidPtr.restype = c_void_p
-PyCObject_AsVoidPtr.argtypes = [py_object]
+try:
+    PyCObject_AsVoidPtr = pythonapi.PyCObject_AsVoidPtr
+except AttributeError:
+    def PyCObject_AsVoidPtr(o):
+        raise TypeError("Not available")
+else:
+    PyCObject_AsVoidPtr.restype = c_void_p
+    PyCObject_AsVoidPtr.argtypes = [py_object]
+    PyCObject_GetDesc = pythonapi.PyCObject_GetDesc
+    PyCObject_GetDesc.restype = c_void_p
+    PyCObject_GetDesc.argtypes = [py_object]
 try:
     PyCapsule_IsValid = pythonapi.PyCapsule_IsValid
 except AttributeError:
     PyCapsule_GetPointer = pythonapi.PyCapsule_GetPointer
     PyCapsule_GetPointer.restype = c_void_p
     PyCapsule_GetPointer.argtypes = [py_object, c_char_p]
+    PyCapsule_GetContext = pythonapi.PyCapsule_GetContext
+    PyCapsule_GetContext.restype = c_void_p
+    PyCapsule_GetContext.argtypes = [py_object]
 
 PAI_CONTIGUOUS = 0x01
 PAI_FORTRAN = 0x02
                 vp = PyCapsule_GetPointer(self._cobj, None)
             else:
                 raise TypeError("The array object has an invalid array structure")
+            self.desc = PyCapsule_GetContext(self._cobj)
+        else:
+            self.desc = PyCObject_GetDesc(self._cobj)
         self._inter = cast(vp, PAI_Ptr)[0]
 
     def __getattr__(self, name):
         return getattr(self._inter, name)
 
     def __str__(self):
+        if isinstance(self.desc, tuple):
+            ver = self.desc[0]
+        else:
+            ver = "N/A"
         return ("nd: %i\n"
                 "typekind: %s\n"
                 "itemsize: %i\n"
                 "flags: %s\n"
                 "shape: %s\n"
-                "strides: %s\n" %
+                "strides: %s\n"
+                "ver: %s\n" %
                 (self.nd, self.typekind, self.itemsize,
                  format_flags(self.flags),
                  format_shape(self.nd, self.shape),
-                 format_strides(self.nd, self.strides)))
+                 format_strides(self.nd, self.strides), ver))
 
 def format_flags(flags):
     names = []
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 ProjectModifiedEvent.java.
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.