forked from python/cpython
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-116417: Move limited C API complex.c tests to _testlimitedca…
…pi (python#117014) Split complex.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
- Loading branch information
1 parent
b30f7e6
commit 34fac11
Showing
8 changed files
with
92 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters