summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi/modsupport.c
blob: 6746eb9eb1e94a61897ef80f02b5e356de226000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "parts.h"



static PyObject *
pyabiinfo_check(PyObject *Py_UNUSED(module), PyObject *args)
{
    const char *modname;
    unsigned long maj, min, flags, buildver, abiver;

    if (!PyArg_ParseTuple(args, "zkkkkk",
        &modname, &maj, &min, &flags, &buildver, &abiver))
    {
        return NULL;
    }
    PyABIInfo info = {
        .abiinfo_major_version = (uint8_t)maj,
        .abiinfo_minor_version = (uint8_t)min,
        .flags = (uint16_t)flags,
        .build_version = (uint32_t)buildver,
        .abi_version = (uint32_t)abiver};
    if (PyABIInfo_Check(&info, modname) < 0) {
        return NULL;
    }
    Py_RETURN_NONE;
}

static PyMethodDef TestMethods[] = {
    {"pyabiinfo_check", pyabiinfo_check, METH_VARARGS},
    {NULL},
};

int
_PyTestCapi_Init_Modsupport(PyObject *m)
{
    if (PyModule_AddIntMacro(m, PyABIInfo_STABLE) < 0) {
        return -1;
    }
    if (PyModule_AddIntMacro(m, PyABIInfo_INTERNAL) < 0) {
        return -1;
    }
    if (PyModule_AddIntMacro(m, PyABIInfo_GIL) < 0) {
        return -1;
    }
    if (PyModule_AddIntMacro(m, PyABIInfo_FREETHREADED) < 0) {
        return -1;
    }
    if (PyModule_AddIntMacro(m, PyABIInfo_FREETHREADING_AGNOSTIC) < 0) {
        return -1;
    }
    if (PyModule_AddFunctions(m, TestMethods) < 0) {
        return -1;
    }
    return 0;
}