Debian Codegraph @

mypyc/lib-rt/vecs/librt_vecs_api.c

raw
1 #include "librt_vecs_api.h"
2
3 VecCapsule *VecApi = NULL;
4 VecI64API VecI64Api = {0};
5 VecI32API VecI32Api = {0};
6 VecI16API VecI16Api = {0};
7 VecU8API VecU8Api = {0};
8 VecFloatAPI VecFloatApi = {0};
9 VecBoolAPI VecBoolApi = {0};
10 VecTAPI VecTApi = {0};
11 VecNestedAPI VecNestedApi = {0};
12
13 int
14 import_librt_vecs(void)
15 {
16 PyObject *mod = PyImport_ImportModule("librt.vecs");
17 if (mod == NULL)
18 return -1;
19 Py_DECREF(mod); // we import just for the side effect of making the below work.
20 VecCapsule *capsule = PyCapsule_Import("librt.vecs._C_API", 0);
21 if (!capsule)
22 return -1;
23 if (capsule->abi_version() != LIBRT_VECS_ABI_VERSION) {
24 char err[128];
25 snprintf(err, sizeof(err),
26 "ABI version conflict for librt.vecs, expected %d, found %d",
27 LIBRT_VECS_ABI_VERSION,
28 capsule->abi_version());
29 PyErr_SetString(PyExc_ValueError, err);
30 return -1;
31 }
32 if (capsule->api_version() < LIBRT_VECS_API_VERSION) {
33 char err[128];
34 snprintf(err, sizeof(err),
35 "API version conflict for librt.vecs, expected %d or newer, found %d (hint: upgrade librt)",
36 LIBRT_VECS_API_VERSION,
37 capsule->api_version());
38 PyErr_SetString(PyExc_ValueError, err);
39 return -1;
40 }
41 VecApi = capsule;
42 VecI64Api = *VecApi->i64;
43 VecI32Api = *VecApi->i32;
44 VecI16Api = *VecApi->i16;
45 VecU8Api = *VecApi->u8;
46 VecFloatApi = *VecApi->float_;
47 VecBoolApi = *VecApi->bool_;
48 VecTApi = *VecApi->t;
49 VecNestedApi = *VecApi->nested;
50 return 0;
51 }