Debian Codegraph @

tests/integration/testdependencies/testdependencies.c

raw
1 #ifdef WITH_DEPENDENCY
2 #include "dependency.h"
3 #else
4 #include <errno.h>
5 #include <malloc.h>
6 #include <math.h>
7 #include <pthread.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <time.h>
11 #include <unistd.h>
12 #if defined(__GLIBC_PREREQ)
13 #if __GLIBC_PREREQ(2, 39)
14 #include <sys/pidfd.h>
15 #endif
16 #if __GLIBC_PREREQ(2, 35)
17 #include <sys/epoll.h>
18 #endif
19 #if __GLIBC_PREREQ(2, 28)
20 #include <threads.h>
21 #endif
22 #endif
23 #endif
24 #include <Python.h>
25
26 static __thread int tres = 0;
27
28 static PyObject *
29 run(PyObject *self, PyObject *args)
30 {
31 int res;
32
33 (void)self;
34 (void)args;
35
36 #ifdef WITH_DEPENDENCY
37 res = dep_run();
38 #elif defined(__GLIBC_PREREQ)
39 #if __GLIBC_PREREQ(2, 39)
40 res = (pidfd_getpid(0) == pidfd_getpid(0)) ? 0 : 1;
41 #elif __GLIBC_PREREQ(2, 35)
42 res = (epoll_pwait2(0, NULL, 0, NULL, NULL) == epoll_pwait2(0, NULL, 0, NULL, NULL)) ? 0 : 1;
43 #elif __GLIBC_PREREQ(2, 34)
44 // pthread_mutexattr_init was moved to libc.so.6 in manylinux_2_34+
45 pthread_mutexattr_t attr;
46 res = pthread_mutexattr_init(&attr);
47 if (res == 0) {
48 pthread_mutexattr_destroy(&attr);
49 }
50 #elif __GLIBC_PREREQ(2, 30)
51 res = gettid() == getpid() ? 0 : 1;
52 #elif __GLIBC_PREREQ(2, 28)
53 res = thrd_equal(thrd_current(), thrd_current()) ? 0 : 1;
54 #elif __GLIBC_PREREQ(2, 24)
55 res = (int)nextupf(0.0F);
56 #elif __GLIBC_PREREQ(2, 17)
57 res = (int)(intptr_t)secure_getenv("NON_EXISTING_ENV_VARIABLE");
58 #elif __GLIBC_PREREQ(2, 10)
59 res = malloc_info(0, stdout);
60 #else
61 res = 0;
62 #endif
63 #else // !defined(__GLIBC_PREREQ)
64 res = 0;
65 #endif
66 return PyLong_FromLong(res + tres);
67 }
68
69 static PyObject *
70 set_tres(PyObject *self, PyObject *args)
71 {
72 (void)self;
73 (void)args;
74 tres = 1;
75 return PyLong_FromLong(tres);
76 }
77
78 /* Module initialization */
79 PyMODINIT_FUNC PyInit_testdependencies(void)
80 {
81 static PyMethodDef module_methods[] = {
82 {"run", (PyCFunction)run, METH_NOARGS, "run."},
83 {"set_tres", (PyCFunction)set_tres, METH_NOARGS, "set_tres."},
84 {NULL} /* Sentinel */
85 };
86 static struct PyModuleDef moduledef = {
87 PyModuleDef_HEAD_INIT,
88 "testdependencies",
89 "testdependencies module",
90 -1,
91 module_methods,
92 };
93 return PyModule_Create(&moduledef);
94 }