summaryrefslogtreecommitdiffstats
path: root/Modules/_testlimitedcapi
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-19 16:23:12 (GMT)
committerGitHub <noreply@github.com>2024-03-19 16:23:12 (GMT)
commit61c659e2dcc073dda6d9a88f735af21622b1c844 (patch)
tree49b0b78bf0948c4acc307a6bd8b6e5be95293527 /Modules/_testlimitedcapi
parent7f64ae30ddc22577ce4101ce0b6601b3548b036f (diff)
downloadcpython-61c659e2dcc073dda6d9a88f735af21622b1c844.zip
cpython-61c659e2dcc073dda6d9a88f735af21622b1c844.tar.gz
cpython-61c659e2dcc073dda6d9a88f735af21622b1c844.tar.bz2
gh-116417: Move limited C API complex.c tests to _testlimitedcapi (#117014)
Split complex.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
Diffstat (limited to 'Modules/_testlimitedcapi')
-rw-r--r--Modules/_testlimitedcapi/complex.c79
-rw-r--r--Modules/_testlimitedcapi/parts.h1
2 files changed, 80 insertions, 0 deletions
diff --git a/Modules/_testlimitedcapi/complex.c b/Modules/_testlimitedcapi/complex.c
new file mode 100644
index 0000000..e4c244e
--- /dev/null
+++ b/Modules/_testlimitedcapi/complex.c
@@ -0,0 +1,79 @@
+#include "parts.h"
+#include "util.h"
+
+
+static PyObject *
+complex_check(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+ NULLABLE(obj);
+ return PyLong_FromLong(PyComplex_Check(obj));
+}
+
+static PyObject *
+complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+ NULLABLE(obj);
+ return PyLong_FromLong(PyComplex_CheckExact(obj));
+}
+
+static PyObject *
+complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ double real, imag;
+
+ if (!PyArg_ParseTuple(args, "dd", &real, &imag)) {
+ return NULL;
+ }
+
+ return PyComplex_FromDoubles(real, imag);
+}
+
+static PyObject *
+complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+ double real;
+
+ NULLABLE(obj);
+ real = PyComplex_RealAsDouble(obj);
+
+ if (real == -1. && PyErr_Occurred()) {
+ return NULL;
+ }
+
+ return PyFloat_FromDouble(real);
+}
+
+static PyObject *
+complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+ double imag;
+
+ NULLABLE(obj);
+ imag = PyComplex_ImagAsDouble(obj);
+
+ if (imag == -1. && PyErr_Occurred()) {
+ return NULL;
+ }
+
+ return PyFloat_FromDouble(imag);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"complex_check", complex_check, METH_O},
+ {"complex_checkexact", complex_checkexact, METH_O},
+ {"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
+ {"complex_realasdouble", complex_realasdouble, METH_O},
+ {"complex_imagasdouble", complex_imagasdouble, METH_O},
+ {NULL},
+};
+
+int
+_PyTestLimitedCAPI_Init_Complex(PyObject *mod)
+{
+ if (PyModule_AddFunctions(mod, test_methods) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h
index 4de9f89..4b65912 100644
--- a/Modules/_testlimitedcapi/parts.h
+++ b/Modules/_testlimitedcapi/parts.h
@@ -25,6 +25,7 @@
int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
+int _PyTestLimitedCAPI_Init_Complex(PyObject *module);
int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);