1
#ifndef NPY_CTYPES_H
2
#define NPY_CTYPES_H
3

4
#include <Python.h>
5

6
#include "npy_import.h"
7

8
/*
9
 * Check if a python type is a ctypes class.
10
 *
11
 * Works like the Py<type>_Check functions, returning true if the argument
12
 * looks like a ctypes object.
13
 *
14
 * This entire function is just a wrapper around the Python function of the
15
 * same name.
16
 */
17
NPY_INLINE static int
18 1
npy_ctypes_check(PyTypeObject *obj)
19
{
20
    static PyObject *py_func = NULL;
21
    PyObject *ret_obj;
22
    int ret;
23

24 1
    npy_cache_import("numpy.core._internal", "npy_ctypes_check", &py_func);
25 1
    if (py_func == NULL) {
26
        goto fail;
27
    }
28

29 1
    ret_obj = PyObject_CallFunctionObjArgs(py_func, (PyObject *)obj, NULL);
30 1
    if (ret_obj == NULL) {
31
        goto fail;
32
    }
33

34 1
    ret = PyObject_IsTrue(ret_obj);
35 1
    Py_DECREF(ret_obj);
36 1
    if (ret == -1) {
37
        goto fail;
38
    }
39

40
    return ret;
41

42 0
fail:
43
    /* If the above fails, then we should just assume that the type is not from
44
     * ctypes
45
     */
46 0
    PyErr_Clear();
47 0
    return 0;
48
}
49

50
#endif

Read our documentation on viewing source code .

Loading