Skip to content

Commit 3cac2af

Browse files
authored
gh-116417: Move limited C API long.c tests to _testlimitedcapi (#117001)
* Split long.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. * Move testcapi_long.h from Modules/_testcapi/ to Modules/_testlimitedcapi/. * Add MODULE__TESTLIMITEDCAPI_DEPS to Makefile.pre.in.
1 parent a114d08 commit 3cac2af

File tree

12 files changed

+962
-916
lines changed

12 files changed

+962
-916
lines changed

Lib/test/test_capi/test_long.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
from test.support import import_helper
66

7-
# Skip this test if the _testcapi module isn't available.
7+
# Skip this test if the _testcapi and _testlimitedcapi modules isn't available.
88
_testcapi = import_helper.import_module('_testcapi')
9+
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
910

1011
NULL = None
1112

@@ -56,7 +57,7 @@ def test_compact_known(self):
5657

5758
def test_long_check(self):
5859
# Test PyLong_Check()
59-
check = _testcapi.pylong_check
60+
check = _testlimitedcapi.pylong_check
6061
self.assertTrue(check(1))
6162
self.assertTrue(check(123456789012345678901234567890))
6263
self.assertTrue(check(-1))
@@ -68,7 +69,7 @@ def test_long_check(self):
6869

6970
def test_long_checkexact(self):
7071
# Test PyLong_CheckExact()
71-
check = _testcapi.pylong_checkexact
72+
check = _testlimitedcapi.pylong_checkexact
7273
self.assertTrue(check(1))
7374
self.assertTrue(check(123456789012345678901234567890))
7475
self.assertTrue(check(-1))
@@ -80,7 +81,7 @@ def test_long_checkexact(self):
8081

8182
def test_long_fromdouble(self):
8283
# Test PyLong_FromDouble()
83-
fromdouble = _testcapi.pylong_fromdouble
84+
fromdouble = _testlimitedcapi.pylong_fromdouble
8485
float_max = sys.float_info.max
8586
for value in (5.0, 5.1, 5.9, -5.1, -5.9, 0.0, -0.0, float_max, -float_max):
8687
with self.subTest(value=value):
@@ -91,7 +92,7 @@ def test_long_fromdouble(self):
9192

9293
def test_long_fromvoidptr(self):
9394
# Test PyLong_FromVoidPtr()
94-
fromvoidptr = _testcapi.pylong_fromvoidptr
95+
fromvoidptr = _testlimitedcapi.pylong_fromvoidptr
9596
obj = object()
9697
x = fromvoidptr(obj)
9798
y = fromvoidptr(NULL)
@@ -103,7 +104,7 @@ def test_long_fromvoidptr(self):
103104

104105
def test_long_fromstring(self):
105106
# Test PyLong_FromString()
106-
fromstring = _testcapi.pylong_fromstring
107+
fromstring = _testlimitedcapi.pylong_fromstring
107108
self.assertEqual(fromstring(b'123', 10), (123, 3))
108109
self.assertEqual(fromstring(b'cafe', 16), (0xcafe, 4))
109110
self.assertEqual(fromstring(b'xyz', 36), (44027, 3))
@@ -163,7 +164,7 @@ def test_long_fromunicodeobject(self):
163164

164165
def test_long_asint(self):
165166
# Test PyLong_AsInt()
166-
PyLong_AsInt = _testcapi.PyLong_AsInt
167+
PyLong_AsInt = _testlimitedcapi.PyLong_AsInt
167168
from _testcapi import INT_MIN, INT_MAX
168169

169170
# round trip (object -> int -> object)
@@ -186,7 +187,7 @@ def test_long_asint(self):
186187

187188
def test_long_aslong(self):
188189
# Test PyLong_AsLong() and PyLong_FromLong()
189-
aslong = _testcapi.pylong_aslong
190+
aslong = _testlimitedcapi.pylong_aslong
190191
from _testcapi import LONG_MIN, LONG_MAX
191192
# round trip (object -> long -> object)
192193
for value in (LONG_MIN, LONG_MAX, -1, 0, 1, 1234):
@@ -206,7 +207,7 @@ def test_long_aslong(self):
206207

207208
def test_long_aslongandoverflow(self):
208209
# Test PyLong_AsLongAndOverflow()
209-
aslongandoverflow = _testcapi.pylong_aslongandoverflow
210+
aslongandoverflow = _testlimitedcapi.pylong_aslongandoverflow
210211
from _testcapi import LONG_MIN, LONG_MAX
211212
# round trip (object -> long -> object)
212213
for value in (LONG_MIN, LONG_MAX, -1, 0, 1, 1234):
@@ -224,7 +225,7 @@ def test_long_aslongandoverflow(self):
224225

225226
def test_long_asunsignedlong(self):
226227
# Test PyLong_AsUnsignedLong() and PyLong_FromUnsignedLong()
227-
asunsignedlong = _testcapi.pylong_asunsignedlong
228+
asunsignedlong = _testlimitedcapi.pylong_asunsignedlong
228229
from _testcapi import ULONG_MAX
229230
# round trip (object -> unsigned long -> object)
230231
for value in (ULONG_MAX, 0, 1, 1234):
@@ -244,7 +245,7 @@ def test_long_asunsignedlong(self):
244245

245246
def test_long_asunsignedlongmask(self):
246247
# Test PyLong_AsUnsignedLongMask()
247-
asunsignedlongmask = _testcapi.pylong_asunsignedlongmask
248+
asunsignedlongmask = _testlimitedcapi.pylong_asunsignedlongmask
248249
from _testcapi import ULONG_MAX
249250
# round trip (object -> unsigned long -> object)
250251
for value in (ULONG_MAX, 0, 1, 1234):
@@ -264,7 +265,7 @@ def test_long_asunsignedlongmask(self):
264265

265266
def test_long_aslonglong(self):
266267
# Test PyLong_AsLongLong() and PyLong_FromLongLong()
267-
aslonglong = _testcapi.pylong_aslonglong
268+
aslonglong = _testlimitedcapi.pylong_aslonglong
268269
from _testcapi import LLONG_MIN, LLONG_MAX
269270
# round trip (object -> long long -> object)
270271
for value in (LLONG_MIN, LLONG_MAX, -1, 0, 1, 1234):
@@ -284,7 +285,7 @@ def test_long_aslonglong(self):
284285

285286
def test_long_aslonglongandoverflow(self):
286287
# Test PyLong_AsLongLongAndOverflow()
287-
aslonglongandoverflow = _testcapi.pylong_aslonglongandoverflow
288+
aslonglongandoverflow = _testlimitedcapi.pylong_aslonglongandoverflow
288289
from _testcapi import LLONG_MIN, LLONG_MAX
289290
# round trip (object -> long long -> object)
290291
for value in (LLONG_MIN, LLONG_MAX, -1, 0, 1, 1234):
@@ -302,7 +303,7 @@ def test_long_aslonglongandoverflow(self):
302303

303304
def test_long_asunsignedlonglong(self):
304305
# Test PyLong_AsUnsignedLongLong() and PyLong_FromUnsignedLongLong()
305-
asunsignedlonglong = _testcapi.pylong_asunsignedlonglong
306+
asunsignedlonglong = _testlimitedcapi.pylong_asunsignedlonglong
306307
from _testcapi import ULLONG_MAX
307308
# round trip (object -> unsigned long long -> object)
308309
for value in (ULLONG_MAX, 0, 1, 1234):
@@ -322,7 +323,7 @@ def test_long_asunsignedlonglong(self):
322323

323324
def test_long_asunsignedlonglongmask(self):
324325
# Test PyLong_AsUnsignedLongLongMask()
325-
asunsignedlonglongmask = _testcapi.pylong_asunsignedlonglongmask
326+
asunsignedlonglongmask = _testlimitedcapi.pylong_asunsignedlonglongmask
326327
from _testcapi import ULLONG_MAX
327328
# round trip (object -> unsigned long long -> object)
328329
for value in (ULLONG_MAX, 0, 1, 1234):
@@ -342,7 +343,7 @@ def test_long_asunsignedlonglongmask(self):
342343

343344
def test_long_as_ssize_t(self):
344345
# Test PyLong_AsSsize_t() and PyLong_FromSsize_t()
345-
as_ssize_t = _testcapi.pylong_as_ssize_t
346+
as_ssize_t = _testlimitedcapi.pylong_as_ssize_t
346347
from _testcapi import PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
347348
# round trip (object -> Py_ssize_t -> object)
348349
for value in (PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, -1, 0, 1, 1234):
@@ -362,7 +363,7 @@ def test_long_as_ssize_t(self):
362363

363364
def test_long_as_size_t(self):
364365
# Test PyLong_AsSize_t() and PyLong_FromSize_t()
365-
as_size_t = _testcapi.pylong_as_size_t
366+
as_size_t = _testlimitedcapi.pylong_as_size_t
366367
from _testcapi import SIZE_MAX
367368
# round trip (object -> size_t -> object)
368369
for value in (SIZE_MAX, 0, 1, 1234):
@@ -382,7 +383,7 @@ def test_long_as_size_t(self):
382383

383384
def test_long_asdouble(self):
384385
# Test PyLong_AsDouble()
385-
asdouble = _testcapi.pylong_asdouble
386+
asdouble = _testlimitedcapi.pylong_asdouble
386387
MAX = int(sys.float_info.max)
387388
for value in (-MAX, MAX, -1, 0, 1, 1234):
388389
with self.subTest(value=value):
@@ -402,8 +403,8 @@ def test_long_asdouble(self):
402403

403404
def test_long_asvoidptr(self):
404405
# Test PyLong_AsVoidPtr()
405-
fromvoidptr = _testcapi.pylong_fromvoidptr
406-
asvoidptr = _testcapi.pylong_asvoidptr
406+
fromvoidptr = _testlimitedcapi.pylong_fromvoidptr
407+
asvoidptr = _testlimitedcapi.pylong_asvoidptr
407408
obj = object()
408409
x = fromvoidptr(obj)
409410
y = fromvoidptr(NULL)

Makefile.pre.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,8 @@ MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_
30513051
MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HEADERS) Modules/_hacl/Hacl_Hash_SHA3.h Modules/_hacl/Hacl_Hash_SHA3.c
30523052
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c
30533053
MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
3054-
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/testcapi_long.h $(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
3054+
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
3055+
MODULE__TESTLIMITEDCAPI_DEPS=$(srcdir)/Modules/_testlimitedcapi/testcapi_long.h $(srcdir)/Modules/_testlimitedcapi/parts.h $(srcdir)/Modules/_testlimitedcapi/util.h
30553056
MODULE__TESTINTERNALCAPI_DEPS=$(srcdir)/Modules/_testinternalcapi/parts.h
30563057
MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h
30573058

Modules/Setup.stdlib.in

+1-1
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/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.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/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/clinic/long.c.h

+1-140
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)