gh-116417: Move limited C API complex.c tests to _testlimitedcapi (#1… · python/cpython@61c659e · GitHub
Skip to content

Commit 61c659e

Browse files
authored
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.
1 parent 7f64ae3 commit 61c659e

8 files changed

Lines changed: 92 additions & 67 deletions

File tree

‎Lib/test/test_capi/test_complex.py‎

Lines changed: 6 additions & 5 deletions

‎Modules/Setup.stdlib.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
164164
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
165165
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c
166-
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
166+
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
167167
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
168168
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
169169

‎Modules/_testcapi/complex.c‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
#include "util.h"
33

44

5-
static PyObject *
6-
complex_check(PyObject *Py_UNUSED(module), PyObject *obj)
7-
{
8-
NULLABLE(obj);
9-
return PyLong_FromLong(PyComplex_Check(obj));
10-
}
11-
12-
static PyObject *
13-
complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
14-
{
15-
NULLABLE(obj);
16-
return PyLong_FromLong(PyComplex_CheckExact(obj));
17-
}
18-
195
static PyObject *
206
complex_fromccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
217
{
@@ -28,48 +14,6 @@ complex_fromccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
2814
return PyComplex_FromCComplex(complex);
2915
}
3016

31-
static PyObject *
32-
complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args)
33-
{
34-
double real, imag;
35-
36-
if (!PyArg_ParseTuple(args, "dd", &real, &imag)) {
37-
return NULL;
38-
}
39-
40-
return PyComplex_FromDoubles(real, imag);
41-
}
42-
43-
static PyObject *
44-
complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
45-
{
46-
double real;
47-
48-
NULLABLE(obj);
49-
real = PyComplex_RealAsDouble(obj);
50-
51-
if (real == -1. && PyErr_Occurred()) {
52-
return NULL;
53-
}
54-
55-
return PyFloat_FromDouble(real);
56-
}
57-
58-
static PyObject *
59-
complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
60-
{
61-
double imag;
62-
63-
NULLABLE(obj);
64-
imag = PyComplex_ImagAsDouble(obj);
65-
66-
if (imag == -1. && PyErr_Occurred()) {
67-
return NULL;
68-
}
69-
70-
return PyFloat_FromDouble(imag);
71-
}
72-
7317
static PyObject *
7418
complex_asccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
7519
{
@@ -139,12 +83,7 @@ _py_c_abs(PyObject *Py_UNUSED(module), PyObject* obj)
13983

14084

14185
static PyMethodDef test_methods[] = {
142-
{"complex_check", complex_check, METH_O},
143-
{"complex_checkexact", complex_checkexact, METH_O},
14486
{"complex_fromccomplex", complex_fromccomplex, METH_O},
145-
{"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
146-
{"complex_realasdouble", complex_realasdouble, METH_O},
147-
{"complex_imagasdouble", complex_imagasdouble, METH_O},
14887
{"complex_asccomplex", complex_asccomplex, METH_O},
14988
{"_py_c_sum", _py_c_sum, METH_VARARGS},
15089
{"_py_c_diff", _py_c_diff, METH_VARARGS},

‎Modules/_testlimitedcapi.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ PyInit__testlimitedcapi(void)
3535
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
3636
return NULL;
3737
}
38+
if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) {
39+
return NULL;
40+
}
3841
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
3942
return NULL;
4043
}

‎Modules/_testlimitedcapi/complex.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "parts.h"
2+
#include "util.h"
3+
4+
5+
static PyObject *
6+
complex_check(PyObject *Py_UNUSED(module), PyObject *obj)
7+
{
8+
NULLABLE(obj);
9+
return PyLong_FromLong(PyComplex_Check(obj));
10+
}
11+
12+
static PyObject *
13+
complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
14+
{
15+
NULLABLE(obj);
16+
return PyLong_FromLong(PyComplex_CheckExact(obj));
17+
}
18+
19+
static PyObject *
20+
complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args)
21+
{
22+
double real, imag;
23+
24+
if (!PyArg_ParseTuple(args, "dd", &real, &imag)) {
25+
return NULL;
26+
}
27+
28+
return PyComplex_FromDoubles(real, imag);
29+
}
30+
31+
static PyObject *
32+
complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
33+
{
34+
double real;
35+
36+
NULLABLE(obj);
37+
real = PyComplex_RealAsDouble(obj);
38+
39+
if (real == -1. && PyErr_Occurred()) {
40+
return NULL;
41+
}
42+
43+
return PyFloat_FromDouble(real);
44+
}
45+
46+
static PyObject *
47+
complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
48+
{
49+
double imag;
50+
51+
NULLABLE(obj);
52+
imag = PyComplex_ImagAsDouble(obj);
53+
54+
if (imag == -1. && PyErr_Occurred()) {
55+
return NULL;
56+
}
57+
58+
return PyFloat_FromDouble(imag);
59+
}
60+
61+
62+
static PyMethodDef test_methods[] = {
63+
{"complex_check", complex_check, METH_O},
64+
{"complex_checkexact", complex_checkexact, METH_O},
65+
{"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
66+
{"complex_realasdouble", complex_realasdouble, METH_O},
67+
{"complex_imagasdouble", complex_imagasdouble, METH_O},
68+
{NULL},
69+
};
70+
71+
int
72+
_PyTestLimitedCAPI_Init_Complex(PyObject *mod)
73+
{
74+
if (PyModule_AddFunctions(mod, test_methods) < 0) {
75+
return -1;
76+
}
77+
78+
return 0;
79+
}

‎Modules/_testlimitedcapi/parts.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
2626
int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
2727
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
28+
int _PyTestLimitedCAPI_Init_Complex(PyObject *module);
2829
int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
2930
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
3031
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);

‎PCbuild/_testlimitedcapi.vcxproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
9898
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
9999
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
100+
<ClCompile Include="..\Modules\_testlimitedcapi\complex.c" />
100101
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
101102
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
102103
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />

‎PCbuild/_testlimitedcapi.vcxproj.filters‎

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)