Skip to content

Commit 3a9672d

Browse files
committed
address review: move to Modules/_testinternalcapi/
1 parent 0439323 commit 3a9672d

File tree

8 files changed

+82
-54
lines changed

8 files changed

+82
-54
lines changed

Lib/test/test_capi/test_complex.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
_testcapi = import_helper.import_module('_testcapi')
1414
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
15+
_testinternalcapi = import_helper.import_module('_testinternalcapi')
1516

1617
NULL = None
1718
INF = float("inf")
@@ -174,7 +175,7 @@ def test_py_c_sum(self):
174175

175176
def test_py_cr_sum(self):
176177
# Test _Py_cr_sum()
177-
_py_cr_sum = _testcapi._py_cr_sum
178+
_py_cr_sum = _testinternalcapi._py_cr_sum
178179

179180
self.assertComplexesAreIdentical(_py_cr_sum(-0j, -0.0)[0],
180181
complex(-0.0, -0.0))
@@ -187,14 +188,14 @@ def test_py_c_diff(self):
187188

188189
def test_py_cr_diff(self):
189190
# Test _Py_cr_diff()
190-
_py_cr_diff = _testcapi._py_cr_diff
191+
_py_cr_diff = _testinternalcapi._py_cr_diff
191192

192193
self.assertComplexesAreIdentical(_py_cr_diff(-0j, 0.0)[0],
193194
complex(-0.0, -0.0))
194195

195196
def test_py_rc_diff(self):
196197
# Test _Py_rc_diff()
197-
_py_rc_diff = _testcapi._py_rc_diff
198+
_py_rc_diff = _testinternalcapi._py_rc_diff
198199

199200
self.assertComplexesAreIdentical(_py_rc_diff(-0.0, 0j)[0],
200201
complex(-0.0, -0.0))
@@ -213,7 +214,7 @@ def test_py_c_prod(self):
213214

214215
def test_py_cr_prod(self):
215216
# Test _Py_cr_prod()
216-
_py_cr_prod = _testcapi._py_cr_prod
217+
_py_cr_prod = _testinternalcapi._py_cr_prod
217218

218219
self.assertComplexesAreIdentical(_py_cr_prod(complex('inf+1j'), INF)[0],
219220
complex('inf+infj'))
@@ -242,14 +243,14 @@ def test_py_c_quot(self):
242243

243244
def test_py_cr_quot(self):
244245
# Test _Py_cr_quot()
245-
_py_cr_quot = _testcapi._py_cr_quot
246+
_py_cr_quot = _testinternalcapi._py_cr_quot
246247

247248
self.assertComplexesAreIdentical(_py_cr_quot(complex('inf+1j'), 2**1000)[0],
248249
INF + 2**-1000*1j)
249250

250251
def test_py_rc_quot(self):
251252
# Test _Py_rc_quot()
252-
_py_rc_quot = _testcapi._py_rc_quot
253+
_py_rc_quot = _testinternalcapi._py_rc_quot
253254

254255
self.assertComplexesAreIdentical(_py_rc_quot(1.0, complex('nan-infj'))[0],
255256
0j)

Modules/Setup.stdlib.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
@MODULE_XXSUBTYPE_TRUE@xxsubtype xxsubtype.c
162162
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
163163
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
164-
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
164+
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c _testinternalcapi/complex.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/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c _testcapi/type.c _testcapi/function.c
166166
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c
167167
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c

Modules/_testcapi/complex.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "parts.h"
22
#include "util.h"
33

4-
#define Py_BUILD_CORE
5-
#include "pycore_complexobject.h"
6-
74

85
static PyObject *
96
complex_fromccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
@@ -60,48 +57,10 @@ _py_c_neg(PyObject *Py_UNUSED(module), PyObject *num)
6057
return Py_BuildValue("Di", &res, errno); \
6158
};
6259

63-
#define _PY_CR_FUNC2(suffix) \
64-
static PyObject * \
65-
_py_cr_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
66-
{ \
67-
Py_complex a, res; \
68-
double b; \
69-
\
70-
if (!PyArg_ParseTuple(args, "Dd", &a, &b)) { \
71-
return NULL; \
72-
} \
73-
\
74-
errno = 0; \
75-
res = _Py_cr_##suffix(a, b); \
76-
return Py_BuildValue("Di", &res, errno); \
77-
};
78-
79-
#define _PY_RC_FUNC2(suffix) \
80-
static PyObject * \
81-
_py_rc_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
82-
{ \
83-
Py_complex b, res; \
84-
double a; \
85-
\
86-
if (!PyArg_ParseTuple(args, "dD", &a, &b)) { \
87-
return NULL; \
88-
} \
89-
\
90-
errno = 0; \
91-
res = _Py_rc_##suffix(a, b); \
92-
return Py_BuildValue("Di", &res, errno); \
93-
};
94-
9560
_PY_C_FUNC2(sum)
96-
_PY_CR_FUNC2(sum)
9761
_PY_C_FUNC2(diff)
98-
_PY_CR_FUNC2(diff)
99-
_PY_RC_FUNC2(diff)
10062
_PY_C_FUNC2(prod)
101-
_PY_CR_FUNC2(prod)
10263
_PY_C_FUNC2(quot)
103-
_PY_CR_FUNC2(quot)
104-
_PY_RC_FUNC2(quot)
10564
_PY_C_FUNC2(pow)
10665

10766
static PyObject*
@@ -127,16 +86,10 @@ static PyMethodDef test_methods[] = {
12786
{"complex_fromccomplex", complex_fromccomplex, METH_O},
12887
{"complex_asccomplex", complex_asccomplex, METH_O},
12988
{"_py_c_sum", _py_c_sum, METH_VARARGS},
130-
{"_py_cr_sum", _py_cr_sum, METH_VARARGS},
13189
{"_py_c_diff", _py_c_diff, METH_VARARGS},
132-
{"_py_cr_diff", _py_cr_diff, METH_VARARGS},
133-
{"_py_rc_diff", _py_rc_diff, METH_VARARGS},
13490
{"_py_c_neg", _py_c_neg, METH_O},
13591
{"_py_c_prod", _py_c_prod, METH_VARARGS},
136-
{"_py_cr_prod", _py_cr_prod, METH_VARARGS},
13792
{"_py_c_quot", _py_c_quot, METH_VARARGS},
138-
{"_py_cr_quot", _py_cr_quot, METH_VARARGS},
139-
{"_py_rc_quot", _py_rc_quot, METH_VARARGS},
14093
{"_py_c_pow", _py_c_pow, METH_VARARGS},
14194
{"_py_c_abs", _py_c_abs, METH_O},
14295
{NULL},

Modules/_testinternalcapi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,9 @@ module_exec(PyObject *module)
21182118
if (_PyTestInternalCapi_Init_Set(module) < 0) {
21192119
return 1;
21202120
}
2121+
if (_PyTestInternalCapi_Init_Complex(module) < 0) {
2122+
return 1;
2123+
}
21212124
if (_PyTestInternalCapi_Init_CriticalSection(module) < 0) {
21222125
return 1;
21232126
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}

Modules/_testinternalcapi/parts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
int _PyTestInternalCapi_Init_Lock(PyObject *module);
1414
int _PyTestInternalCapi_Init_PyTime(PyObject *module);
1515
int _PyTestInternalCapi_Init_Set(PyObject *module);
16+
int _PyTestInternalCapi_Init_Complex(PyObject *module);
1617
int _PyTestInternalCapi_Init_CriticalSection(PyObject *module);
1718

1819
#endif // Py_TESTINTERNALCAPI_PARTS_H

PCbuild/_testinternalcapi.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<ClCompile Include="..\Modules\_testinternalcapi\test_critical_sections.c" />
9999
<ClCompile Include="..\Modules\_testinternalcapi\test_lock.c" />
100100
<ClCompile Include="..\Modules\_testinternalcapi\set.c" />
101+
<ClCompile Include="..\Modules\_testinternalcapi\complex.c" />
101102
</ItemGroup>
102103
<ItemGroup>
103104
<ResourceCompile Include="..\PC\python_nt.rc" />

PCbuild/_testinternalcapi.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<ClCompile Include="..\Modules\_testinternalcapi\set.c">
2525
<Filter>Source Files</Filter>
2626
</ClCompile>
27+
<ClCompile Include="..\Modules\_testinternalcapi\complex.c">
28+
<Filter>Source Files</Filter>
29+
</ClCompile>
2730
</ItemGroup>
2831
<ItemGroup>
2932
<ResourceCompile Include="..\PC\python_nt.rc">

0 commit comments

Comments
 (0)