Debian Codegraph @

Modules/_testinternalcapi/complex.c

raw
1 #include "parts.h"
2 #include "../_testcapi/util.h"
3
4 #define Py_BUILD_CORE
5 #include "pycore_complexobject.h"
6
7
8 #define _PY_CR_FUNC2(suffix) \
9 static PyObject * \
10 _py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
11 { \
12 Py_complex a, res; \
13 double b; \
14 \
15 if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
16 return NULL; \
17 } \
18 \
19 errno = 0; \
20 res = _Py_cr_##suffix(a, b); \
21 return Py_BuildValue("Di", &res, errno); \
22 };
23
24 #define _PY_RC_FUNC2(suffix) \
25 static PyObject * \
26 _py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
27 { \
28 Py_complex b, res; \
29 double a; \
30 \
31 if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
32 return NULL; \
33 } \
34 \
35 errno = 0; \
36 res = _Py_rc_##suffix(a, b); \
37 return Py_BuildValue("Di", &res, errno); \
38 };
39
40 _PY_CR_FUNC2(sum)
41 _PY_CR_FUNC2(diff)
42 _PY_RC_FUNC2(diff)
43 _PY_CR_FUNC2(prod)
44 _PY_CR_FUNC2(quot)
45 _PY_RC_FUNC2(quot)
46
47
48 static PyMethodDef test_methods[] = {
49 {"_py_cr_sum", _py_cr_sum, METH_VARARGS},
50 {"_py_cr_diff", _py_cr_diff, METH_VARARGS},
51 {"_py_rc_diff", _py_rc_diff, METH_VARARGS},
52 {"_py_cr_prod", _py_cr_prod, METH_VARARGS},
53 {"_py_cr_quot", _py_cr_quot, METH_VARARGS},
54 {"_py_rc_quot", _py_rc_quot, METH_VARARGS},
55 {NULL},
56 };
57
58 int
59 _PyTestInternalCapi_Init_Complex(PyObject *mod)
60 {
61 if (PyModule_AddFunctions(mod, test_methods) < 0) {
62 return -1;
63 }
64
65 return 0;
66 }