1. Maciej Fijalkowski
  2. hack2

Source

hack2 / pypyembed / inner.py

Diff from to

File pypyembed/inner.py

  • Ignore whitespace
     PyTuple_SetItem = declare('PyTuple_SetItem', [PY_OBJECT, ctypes.c_long,
                                                   PY_OBJECT], ctypes.c_long,
                               errcond=-1)
+    PyTuple_GetItem = declare('PyTuple_GetItem', [PY_OBJECT, ctypes.c_long],
+                              PY_OBJECT)
+    PyTuple_Check = declare_extra('_PyTuple_Check', [PY_OBJECT],
+                                  ctypes.c_bool)
+    PyTuple_Size = declare('PyTuple_Size', [PY_OBJECT], ctypes.c_long)
     Py_CompileStringFlags = declare('Py_CompileStringFlags',
          [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, PY_OBJECT], PY_OBJECT)
     PyObject_GetItem = declare('PyObject_GetItem', [PY_OBJECT, PY_OBJECT],
             res = PyString_AsString(py_x)
         elif PyFloat_Check(py_x):
             res = PyFloat_AsDouble(py_x)
+        elif PyTuple_Check(py_x):
+            buf = PyInt_AsLong(PyTuple_GetItem(py_x, 0))
+            dtype = PyString_AsString(PyTuple_GetItem(py_x, 1))
+            py_shape = PyTuple_GetItem(py_x, 2)
+            shape = [PyInt_AsLong(PyTuple_GetItem(py_shape, i)) for i in range(PyTuple_Size(py_shape))]
+            return numpypy.ndarray(shape, dtype, buffer=buf)
         else:
             raise NotImplementedError("unknown type")
         return res