0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 08:52:25 +01:00

gh-116417: Move limited C API abstract.c tests to _testlimitedcapi (#116986)

Split abstract.c and float.c tests of _testcapi into two parts:
limited C API tests in _testlimitedcapi and non-limited C API tests
in _testcapi.

Update test_bytes and test_class.
This commit is contained in:
Victor Stinner 2024-03-19 11:44:13 +01:00 committed by GitHub
parent b1bc37597f
commit 039d20ae54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 780 additions and 728 deletions

View File

@ -991,13 +991,13 @@ class BaseBytesTest:
self.assertEqual(c, b'hllo')
def test_sq_item(self):
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
obj = self.type2test((42,))
with self.assertRaises(IndexError):
_testcapi.sequence_getitem(obj, -2)
_testlimitedcapi.sequence_getitem(obj, -2)
with self.assertRaises(IndexError):
_testcapi.sequence_getitem(obj, 1)
self.assertEqual(_testcapi.sequence_getitem(obj, 0), 42)
_testlimitedcapi.sequence_getitem(obj, 1)
self.assertEqual(_testlimitedcapi.sequence_getitem(obj, 0), 42)
class BytesTest(BaseBytesTest, unittest.TestCase):
@ -1256,7 +1256,7 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
type2test = bytearray
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
def test_getitem_error(self):
b = bytearray(b'python')
@ -1354,7 +1354,7 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
b[i] = val
def setitem_as_sequence(b, i, val):
self._testcapi.sequence_setitem(b, i, val)
self._testlimitedcapi.sequence_setitem(b, i, val)
def do_tests(setitem):
b = bytearray([1, 2, 3])
@ -1401,7 +1401,7 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
del b[i]
def del_as_sequence(b, i):
self._testcapi.sequence_delitem(b, i)
self._testlimitedcapi.sequence_delitem(b, i)
def do_tests(delete):
b = bytearray(range(10))
@ -1810,7 +1810,7 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
with self.subTest("tp_as_sequence"):
b = bytearray(b'Now you see me...')
with self.assertRaises(IndexError):
self._testcapi.sequence_setitem(b, 0, Boom())
self._testlimitedcapi.sequence_setitem(b, 0, Boom())
class AssortedBytesTest(unittest.TestCase):

View File

@ -4,6 +4,7 @@ from test import support
from test.support import import_helper
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
from _testcapi import PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
NULL = None
@ -74,7 +75,7 @@ class CAPITest(unittest.TestCase):
def test_object_str(self):
# Test PyObject_Str()
object_str = _testcapi.object_str
object_str = _testlimitedcapi.object_str
self.assertTypedEqual(object_str(''), '')
self.assertTypedEqual(object_str('abc'), 'abc')
self.assertTypedEqual(object_str('\U0001f40d'), '\U0001f40d')
@ -87,7 +88,7 @@ class CAPITest(unittest.TestCase):
def test_object_repr(self):
# Test PyObject_Repr()
object_repr = _testcapi.object_repr
object_repr = _testlimitedcapi.object_repr
self.assertTypedEqual(object_repr(''), "''")
self.assertTypedEqual(object_repr('abc'), "'abc'")
self.assertTypedEqual(object_repr('\U0001f40d'), "'\U0001f40d'")
@ -100,7 +101,7 @@ class CAPITest(unittest.TestCase):
def test_object_ascii(self):
# Test PyObject_ASCII()
object_ascii = _testcapi.object_ascii
object_ascii = _testlimitedcapi.object_ascii
self.assertTypedEqual(object_ascii(''), "''")
self.assertTypedEqual(object_ascii('abc'), "'abc'")
self.assertTypedEqual(object_ascii('\U0001f40d'), r"'\U0001f40d'")
@ -113,7 +114,7 @@ class CAPITest(unittest.TestCase):
def test_object_bytes(self):
# Test PyObject_Bytes()
object_bytes = _testcapi.object_bytes
object_bytes = _testlimitedcapi.object_bytes
self.assertTypedEqual(object_bytes(b''), b'')
self.assertTypedEqual(object_bytes(b'abc'), b'abc')
self.assertTypedEqual(object_bytes(BytesSubclass(b'abc')), b'abc')
@ -132,7 +133,7 @@ class CAPITest(unittest.TestCase):
self.assertTypedEqual(object_bytes(NULL), b'<NULL>')
def test_object_getattr(self):
xgetattr = _testcapi.object_getattr
xgetattr = _testlimitedcapi.object_getattr
obj = TestObject()
obj.a = 11
setattr(obj, '\U0001f40d', 22)
@ -146,7 +147,7 @@ class CAPITest(unittest.TestCase):
# CRASHES xgetattr(NULL, 'a')
def test_object_getattrstring(self):
getattrstring = _testcapi.object_getattrstring
getattrstring = _testlimitedcapi.object_getattrstring
obj = TestObject()
obj.a = 11
setattr(obj, '\U0001f40d', 22)
@ -188,7 +189,7 @@ class CAPITest(unittest.TestCase):
# CRASHES getoptionalattrstring(NULL, b'a')
def test_object_hasattr(self):
xhasattr = _testcapi.object_hasattr
xhasattr = _testlimitedcapi.object_hasattr
obj = TestObject()
obj.a = 1
setattr(obj, '\U0001f40d', 2)
@ -212,7 +213,7 @@ class CAPITest(unittest.TestCase):
# CRASHES xhasattr(NULL, 'a')
def test_object_hasattrstring(self):
hasattrstring = _testcapi.object_hasattrstring
hasattrstring = _testlimitedcapi.object_hasattrstring
obj = TestObject()
obj.a = 1
setattr(obj, '\U0001f40d', 2)
@ -264,7 +265,7 @@ class CAPITest(unittest.TestCase):
# CRASHES hasattrstring(NULL, b'a')
def test_object_setattr(self):
xsetattr = _testcapi.object_setattr
xsetattr = _testlimitedcapi.object_setattr
obj = TestObject()
xsetattr(obj, 'a', 5)
self.assertEqual(obj.a, 5)
@ -284,7 +285,7 @@ class CAPITest(unittest.TestCase):
# CRASHES xsetattr(NULL, 'a', 5)
def test_object_setattrstring(self):
setattrstring = _testcapi.object_setattrstring
setattrstring = _testlimitedcapi.object_setattrstring
obj = TestObject()
setattrstring(obj, b'a', 5)
self.assertEqual(obj.a, 5)
@ -305,7 +306,7 @@ class CAPITest(unittest.TestCase):
# CRASHES setattrstring(NULL, b'a', 5)
def test_object_delattr(self):
xdelattr = _testcapi.object_delattr
xdelattr = _testlimitedcapi.object_delattr
obj = TestObject()
obj.a = 1
setattr(obj, '\U0001f40d', 2)
@ -322,7 +323,7 @@ class CAPITest(unittest.TestCase):
# CRASHES xdelattr(NULL, 'a')
def test_object_delattrstring(self):
delattrstring = _testcapi.object_delattrstring
delattrstring = _testlimitedcapi.object_delattrstring
obj = TestObject()
obj.a = 1
setattr(obj, '\U0001f40d', 2)
@ -340,7 +341,7 @@ class CAPITest(unittest.TestCase):
def test_mapping_check(self):
check = _testcapi.mapping_check
check = _testlimitedcapi.mapping_check
self.assertTrue(check({1: 2}))
self.assertTrue(check([1, 2]))
self.assertTrue(check((1, 2)))
@ -351,7 +352,7 @@ class CAPITest(unittest.TestCase):
self.assertFalse(check(NULL))
def test_mapping_size(self):
for size in _testcapi.mapping_size, _testcapi.mapping_length:
for size in _testlimitedcapi.mapping_size, _testlimitedcapi.mapping_length:
self.assertEqual(size({1: 2}), 1)
self.assertEqual(size([1, 2]), 2)
self.assertEqual(size((1, 2)), 2)
@ -363,7 +364,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, size, NULL)
def test_object_getitem(self):
getitem = _testcapi.object_getitem
getitem = _testlimitedcapi.object_getitem
dct = {'a': 1, '\U0001f40d': 2}
self.assertEqual(getitem(dct, 'a'), 1)
self.assertRaises(KeyError, getitem, dct, 'b')
@ -383,7 +384,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, getitem, NULL, 'a')
def test_mapping_getitemstring(self):
getitemstring = _testcapi.mapping_getitemstring
getitemstring = _testlimitedcapi.mapping_getitemstring
dct = {'a': 1, '\U0001f40d': 2}
self.assertEqual(getitemstring(dct, b'a'), 1)
self.assertRaises(KeyError, getitemstring, dct, b'b')
@ -437,7 +438,7 @@ class CAPITest(unittest.TestCase):
# CRASHES getitemstring(NULL, b'a')
def test_mapping_haskey(self):
haskey = _testcapi.mapping_haskey
haskey = _testlimitedcapi.mapping_haskey
dct = {'a': 1, '\U0001f40d': 2}
self.assertTrue(haskey(dct, 'a'))
self.assertFalse(haskey(dct, 'b'))
@ -486,7 +487,7 @@ class CAPITest(unittest.TestCase):
'null argument to internal routine')
def test_mapping_haskeystring(self):
haskeystring = _testcapi.mapping_haskeystring
haskeystring = _testlimitedcapi.mapping_haskeystring
dct = {'a': 1, '\U0001f40d': 2}
self.assertTrue(haskeystring(dct, b'a'))
self.assertFalse(haskeystring(dct, b'b'))
@ -527,7 +528,7 @@ class CAPITest(unittest.TestCase):
"null argument to internal routine")
def test_mapping_haskeywitherror(self):
haskey = _testcapi.mapping_haskeywitherror
haskey = _testlimitedcapi.mapping_haskeywitherror
dct = {'a': 1, '\U0001f40d': 2}
self.assertTrue(haskey(dct, 'a'))
self.assertFalse(haskey(dct, 'b'))
@ -548,7 +549,7 @@ class CAPITest(unittest.TestCase):
# CRASHES haskey(NULL, 'a'))
def test_mapping_haskeystringwitherror(self):
haskeystring = _testcapi.mapping_haskeystringwitherror
haskeystring = _testlimitedcapi.mapping_haskeystringwitherror
dct = {'a': 1, '\U0001f40d': 2}
self.assertTrue(haskeystring(dct, b'a'))
self.assertFalse(haskeystring(dct, b'b'))
@ -565,7 +566,7 @@ class CAPITest(unittest.TestCase):
# CRASHES haskeystring(NULL, b'a')
def test_object_setitem(self):
setitem = _testcapi.object_setitem
setitem = _testlimitedcapi.object_setitem
dct = {}
setitem(dct, 'a', 5)
self.assertEqual(dct, {'a': 5})
@ -591,7 +592,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, setitem, NULL, 'a', 5)
def test_mapping_setitemstring(self):
setitemstring = _testcapi.mapping_setitemstring
setitemstring = _testlimitedcapi.mapping_setitemstring
dct = {}
setitemstring(dct, b'a', 5)
self.assertEqual(dct, {'a': 5})
@ -611,7 +612,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, setitemstring, NULL, b'a', 5)
def test_object_delitem(self):
for delitem in _testcapi.object_delitem, _testcapi.mapping_delitem:
for delitem in _testlimitedcapi.object_delitem, _testlimitedcapi.mapping_delitem:
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
delitem(dct, 'a')
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
@ -637,7 +638,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, delitem, NULL, 'a')
def test_mapping_delitemstring(self):
delitemstring = _testcapi.mapping_delitemstring
delitemstring = _testlimitedcapi.mapping_delitemstring
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
delitemstring(dct, b'a')
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
@ -677,23 +678,23 @@ class CAPITest(unittest.TestCase):
for mapping in [{}, OrderedDict(), Mapping1(), Mapping2(),
dict_obj, OrderedDict(dict_obj),
Mapping1(dict_obj), Mapping2(dict_obj)]:
self.assertListEqual(_testcapi.mapping_keys(mapping),
self.assertListEqual(_testlimitedcapi.mapping_keys(mapping),
list(mapping.keys()))
self.assertListEqual(_testcapi.mapping_values(mapping),
self.assertListEqual(_testlimitedcapi.mapping_values(mapping),
list(mapping.values()))
self.assertListEqual(_testcapi.mapping_items(mapping),
self.assertListEqual(_testlimitedcapi.mapping_items(mapping),
list(mapping.items()))
def test_mapping_keys_valuesitems_bad_arg(self):
self.assertRaises(AttributeError, _testcapi.mapping_keys, object())
self.assertRaises(AttributeError, _testcapi.mapping_values, object())
self.assertRaises(AttributeError, _testcapi.mapping_items, object())
self.assertRaises(AttributeError, _testcapi.mapping_keys, [])
self.assertRaises(AttributeError, _testcapi.mapping_values, [])
self.assertRaises(AttributeError, _testcapi.mapping_items, [])
self.assertRaises(SystemError, _testcapi.mapping_keys, NULL)
self.assertRaises(SystemError, _testcapi.mapping_values, NULL)
self.assertRaises(SystemError, _testcapi.mapping_items, NULL)
self.assertRaises(AttributeError, _testlimitedcapi.mapping_keys, object())
self.assertRaises(AttributeError, _testlimitedcapi.mapping_values, object())
self.assertRaises(AttributeError, _testlimitedcapi.mapping_items, object())
self.assertRaises(AttributeError, _testlimitedcapi.mapping_keys, [])
self.assertRaises(AttributeError, _testlimitedcapi.mapping_values, [])
self.assertRaises(AttributeError, _testlimitedcapi.mapping_items, [])
self.assertRaises(SystemError, _testlimitedcapi.mapping_keys, NULL)
self.assertRaises(SystemError, _testlimitedcapi.mapping_values, NULL)
self.assertRaises(SystemError, _testlimitedcapi.mapping_items, NULL)
class BadMapping:
def keys(self):
@ -703,12 +704,12 @@ class CAPITest(unittest.TestCase):
def items(self):
return None
bad_mapping = BadMapping()
self.assertRaises(TypeError, _testcapi.mapping_keys, bad_mapping)
self.assertRaises(TypeError, _testcapi.mapping_values, bad_mapping)
self.assertRaises(TypeError, _testcapi.mapping_items, bad_mapping)
self.assertRaises(TypeError, _testlimitedcapi.mapping_keys, bad_mapping)
self.assertRaises(TypeError, _testlimitedcapi.mapping_values, bad_mapping)
self.assertRaises(TypeError, _testlimitedcapi.mapping_items, bad_mapping)
def test_sequence_check(self):
check = _testcapi.sequence_check
check = _testlimitedcapi.sequence_check
self.assertFalse(check({1: 2}))
self.assertTrue(check([1, 2]))
self.assertTrue(check((1, 2)))
@ -719,7 +720,7 @@ class CAPITest(unittest.TestCase):
# CRASHES check(NULL)
def test_sequence_size(self):
for size in _testcapi.sequence_size, _testcapi.sequence_length:
for size in _testlimitedcapi.sequence_size, _testlimitedcapi.sequence_length:
self.assertEqual(size([1, 2]), 2)
self.assertEqual(size((1, 2)), 2)
self.assertEqual(size('abc'), 3)
@ -731,7 +732,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, size, NULL)
def test_sequence_getitem(self):
getitem = _testcapi.sequence_getitem
getitem = _testlimitedcapi.sequence_getitem
lst = ['a', 'b', 'c']
self.assertEqual(getitem(lst, 1), 'b')
self.assertEqual(getitem(lst, -1), 'c')
@ -744,7 +745,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, getitem, NULL, 1)
def test_sequence_concat(self):
concat = _testcapi.sequence_concat
concat = _testlimitedcapi.sequence_concat
self.assertEqual(concat(['a', 'b'], [1, 2]), ['a', 'b', 1, 2])
self.assertEqual(concat(('a', 'b'), (1, 2)), ('a', 'b', 1, 2))
@ -757,7 +758,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, concat, NULL, [])
def test_sequence_repeat(self):
repeat = _testcapi.sequence_repeat
repeat = _testlimitedcapi.sequence_repeat
self.assertEqual(repeat(['a', 'b'], 2), ['a', 'b', 'a', 'b'])
self.assertEqual(repeat(('a', 'b'), 2), ('a', 'b', 'a', 'b'))
self.assertEqual(repeat(['a', 'b'], 0), [])
@ -771,7 +772,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, repeat, NULL, 2)
def test_sequence_inplaceconcat(self):
inplaceconcat = _testcapi.sequence_inplaceconcat
inplaceconcat = _testlimitedcapi.sequence_inplaceconcat
lst = ['a', 'b']
res = inplaceconcat(lst, [1, 2])
self.assertEqual(res, ['a', 'b', 1, 2])
@ -790,7 +791,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, inplaceconcat, NULL, [])
def test_sequence_inplacerepeat(self):
inplacerepeat = _testcapi.sequence_inplacerepeat
inplacerepeat = _testlimitedcapi.sequence_inplacerepeat
lst = ['a', 'b']
res = inplacerepeat(lst, 2)
self.assertEqual(res, ['a', 'b', 'a', 'b'])
@ -807,7 +808,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, inplacerepeat, NULL, 2)
def test_sequence_setitem(self):
setitem = _testcapi.sequence_setitem
setitem = _testlimitedcapi.sequence_setitem
lst = ['a', 'b', 'c']
setitem(lst, 1, 'x')
self.assertEqual(lst, ['a', 'x', 'c'])
@ -825,7 +826,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, setitem, NULL, 1, 'x')
def test_sequence_delitem(self):
delitem = _testcapi.sequence_delitem
delitem = _testlimitedcapi.sequence_delitem
lst = ['a', 'b', 'c']
delitem(lst, 1)
self.assertEqual(lst, ['a', 'c'])
@ -840,7 +841,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, delitem, NULL, 1)
def test_sequence_setslice(self):
setslice = _testcapi.sequence_setslice
setslice = _testlimitedcapi.sequence_setslice
# Correct case:
for start in [*range(-6, 7), PY_SSIZE_T_MIN, PY_SSIZE_T_MAX]:
@ -882,7 +883,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, setslice, NULL, 1, 3, 'xy')
def test_sequence_delslice(self):
delslice = _testcapi.sequence_delslice
delslice = _testlimitedcapi.sequence_delslice
# Correct case:
for start in [*range(-6, 7), PY_SSIZE_T_MIN, PY_SSIZE_T_MAX]:
@ -920,7 +921,7 @@ class CAPITest(unittest.TestCase):
self.assertEqual(mapping, {1: 'a', 2: 'b', 3: 'c'})
def test_sequence_count(self):
count = _testcapi.sequence_count
count = _testlimitedcapi.sequence_count
lst = ['a', 'b', 'a']
self.assertEqual(count(lst, 'a'), 2)
@ -935,7 +936,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, count, NULL, 'a')
def test_sequence_contains(self):
contains = _testcapi.sequence_contains
contains = _testlimitedcapi.sequence_contains
lst = ['a', 'b', 'a']
self.assertEqual(contains(lst, 'a'), 1)
@ -954,7 +955,7 @@ class CAPITest(unittest.TestCase):
# CRASHES contains(NULL, 'a')
def test_sequence_index(self):
index = _testcapi.sequence_index
index = _testlimitedcapi.sequence_index
lst = ['a', 'b', 'a']
self.assertEqual(index(lst, 'a'), 0)
@ -974,7 +975,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, index, NULL, 'a')
def test_sequence_list(self):
xlist = _testcapi.sequence_list
xlist = _testlimitedcapi.sequence_list
self.assertEqual(xlist(['a', 'b', 'c']), ['a', 'b', 'c'])
self.assertEqual(xlist(('a', 'b', 'c')), ['a', 'b', 'c'])
self.assertEqual(xlist(iter(['a', 'b', 'c'])), ['a', 'b', 'c'])
@ -984,7 +985,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, xlist, NULL)
def test_sequence_tuple(self):
xtuple = _testcapi.sequence_tuple
xtuple = _testlimitedcapi.sequence_tuple
self.assertEqual(xtuple(['a', 'b', 'c']), ('a', 'b', 'c'))
self.assertEqual(xtuple(('a', 'b', 'c')), ('a', 'b', 'c'))
self.assertEqual(xtuple(iter(['a', 'b', 'c'])), ('a', 'b', 'c'))
@ -994,7 +995,7 @@ class CAPITest(unittest.TestCase):
self.assertRaises(SystemError, xtuple, NULL)
def test_number_check(self):
number_check = _testcapi.number_check
number_check = _testlimitedcapi.number_check
self.assertTrue(number_check(1 + 1j))
self.assertTrue(number_check(1))
self.assertTrue(number_check(0.5))

View File

@ -9,6 +9,7 @@ from test.test_capi.test_getargs import (Float, FloatSubclass, FloatSubclass2,
from test.support import import_helper
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
NULL = None
@ -29,7 +30,7 @@ NAN = float("nan")
class CAPIFloatTest(unittest.TestCase):
def test_check(self):
# Test PyFloat_Check()
check = _testcapi.float_check
check = _testlimitedcapi.float_check
self.assertTrue(check(4.25))
self.assertTrue(check(FloatSubclass(4.25)))
@ -41,7 +42,7 @@ class CAPIFloatTest(unittest.TestCase):
def test_checkexact(self):
# Test PyFloat_CheckExact()
checkexact = _testcapi.float_checkexact
checkexact = _testlimitedcapi.float_checkexact
self.assertTrue(checkexact(4.25))
self.assertFalse(checkexact(FloatSubclass(4.25)))
@ -53,7 +54,7 @@ class CAPIFloatTest(unittest.TestCase):
def test_fromstring(self):
# Test PyFloat_FromString()
fromstring = _testcapi.float_fromstring
fromstring = _testlimitedcapi.float_fromstring
self.assertEqual(fromstring("4.25"), 4.25)
self.assertEqual(fromstring(b"4.25"), 4.25)
@ -72,13 +73,13 @@ class CAPIFloatTest(unittest.TestCase):
def test_fromdouble(self):
# Test PyFloat_FromDouble()
fromdouble = _testcapi.float_fromdouble
fromdouble = _testlimitedcapi.float_fromdouble
self.assertEqual(fromdouble(4.25), 4.25)
def test_asdouble(self):
# Test PyFloat_AsDouble()
asdouble = _testcapi.float_asdouble
asdouble = _testlimitedcapi.float_asdouble
class BadFloat3:
def __float__(self):
@ -109,19 +110,19 @@ class CAPIFloatTest(unittest.TestCase):
def test_getinfo(self):
# Test PyFloat_GetInfo()
getinfo = _testcapi.float_getinfo
getinfo = _testlimitedcapi.float_getinfo
self.assertEqual(getinfo(), sys.float_info)
def test_getmax(self):
# Test PyFloat_GetMax()
getmax = _testcapi.float_getmax
getmax = _testlimitedcapi.float_getmax
self.assertEqual(getmax(), sys.float_info.max)
def test_getmin(self):
# Test PyFloat_GetMax()
getmin = _testcapi.float_getmin
getmin = _testlimitedcapi.float_getmin
self.assertEqual(getmin(), sys.float_info.min)

View File

@ -448,15 +448,15 @@ class ClassTests(unittest.TestCase):
def testHasAttrString(self):
import sys
from test.support import import_helper
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
class A:
def __init__(self):
self.attr = 1
a = A()
self.assertEqual(_testcapi.object_hasattrstring(a, b"attr"), 1)
self.assertEqual(_testcapi.object_hasattrstring(a, b"noattr"), 0)
self.assertEqual(_testlimitedcapi.object_hasattrstring(a, b"attr"), 1)
self.assertEqual(_testlimitedcapi.object_hasattrstring(a, b"noattr"), 0)
self.assertIsNone(sys.exception())
def testDel(self):

View File

@ -163,7 +163,7 @@
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
@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
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/vectorcall_limited.c
@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/vectorcall_limited.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c

View File

@ -2,59 +2,6 @@
#include "util.h"
static PyObject *
object_repr(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Repr(arg);
}
static PyObject *
object_ascii(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_ASCII(arg);
}
static PyObject *
object_str(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Str(arg);
}
static PyObject *
object_bytes(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Bytes(arg);
}
static PyObject *
object_getattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
return PyObject_GetAttr(obj, attr_name);
}
static PyObject *
object_getattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
return PyObject_GetAttrString(obj, attr_name);
}
static PyObject *
object_getoptionalattr(PyObject *self, PyObject *args)
{
@ -106,31 +53,6 @@ object_getoptionalattrstring(PyObject *self, PyObject *args)
}
}
static PyObject *
object_hasattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
return PyLong_FromLong(PyObject_HasAttr(obj, attr_name));
}
static PyObject *
object_hasattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
return PyLong_FromLong(PyObject_HasAttrString(obj, attr_name));
}
static PyObject *
object_hasattrwitherror(PyObject *self, PyObject *args)
{
@ -156,136 +78,6 @@ object_hasattrstringwitherror(PyObject *self, PyObject *args)
RETURN_INT(PyObject_HasAttrStringWithError(obj, attr_name));
}
static PyObject *
object_setattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name, *value;
if (!PyArg_ParseTuple(args, "OOO", &obj, &attr_name, &value)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
NULLABLE(value);
RETURN_INT(PyObject_SetAttr(obj, attr_name, value));
}
static PyObject *
object_setattrstring(PyObject *self, PyObject *args)
{
PyObject *obj, *value;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#O", &obj, &attr_name, &size, &value)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(value);
RETURN_INT(PyObject_SetAttrString(obj, attr_name, value));
}
static PyObject *
object_delattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
RETURN_INT(PyObject_DelAttr(obj, attr_name));
}
static PyObject *
object_delattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
RETURN_INT(PyObject_DelAttrString(obj, attr_name));
}
static PyObject *
number_check(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyBool_FromLong(PyNumber_Check(obj));
}
static PyObject *
mapping_check(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyMapping_Check(obj));
}
static PyObject *
mapping_size(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PyMapping_Size(obj));
}
static PyObject *
mapping_length(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PyMapping_Length(obj));
}
static PyObject *
object_getitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
return PyObject_GetItem(mapping, key);
}
static PyObject *
mapping_getitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
return PyMapping_GetItemString(mapping, key);
}
static PyObject *
mapping_getoptionalitem(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name, *value = UNINITIALIZED_PTR;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
switch (PyMapping_GetOptionalItem(obj, attr_name, &value)) {
case -1:
assert(value == NULL);
return NULL;
case 0:
assert(value == NULL);
return Py_NewRef(PyExc_KeyError);
case 1:
return value;
default:
Py_FatalError("PyMapping_GetOptionalItem() returned invalid code");
Py_UNREACHABLE();
}
}
static PyObject *
mapping_getoptionalitemstring(PyObject *self, PyObject *args)
{
@ -313,393 +105,38 @@ mapping_getoptionalitemstring(PyObject *self, PyObject *args)
}
static PyObject *
mapping_haskey(PyObject *self, PyObject *args)
mapping_getoptionalitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
PyObject *obj, *attr_name, *value = UNINITIALIZED_PTR;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
return PyLong_FromLong(PyMapping_HasKey(mapping, key));
}
static PyObject *
mapping_haskeystring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
return PyLong_FromLong(PyMapping_HasKeyString(mapping, key));
}
static PyObject *
mapping_haskeywitherror(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyMapping_HasKeyWithError(mapping, key));
}
static PyObject *
mapping_haskeystringwitherror(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
RETURN_INT(PyMapping_HasKeyStringWithError(mapping, key));
}
static PyObject *
object_setitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key, *value;
if (!PyArg_ParseTuple(args, "OOO", &mapping, &key, &value)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
NULLABLE(value);
RETURN_INT(PyObject_SetItem(mapping, key, value));
}
static PyObject *
mapping_setitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping, *value;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#O", &mapping, &key, &size, &value)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(value);
RETURN_INT(PyMapping_SetItemString(mapping, key, value));
}
static PyObject *
object_delitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyObject_DelItem(mapping, key));
}
static PyObject *
mapping_delitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyMapping_DelItem(mapping, key));
}
static PyObject *
mapping_delitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
RETURN_INT(PyMapping_DelItemString(mapping, key));
}
static PyObject *
mapping_keys(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Keys(obj);
}
NULLABLE(attr_name);
static PyObject *
mapping_values(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Values(obj);
}
static PyObject *
mapping_items(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Items(obj);
}
static PyObject *
sequence_check(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PySequence_Check(obj));
}
static PyObject *
sequence_size(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PySequence_Size(obj));
}
static PyObject *
sequence_length(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PySequence_Length(obj));
}
static PyObject *
sequence_concat(PyObject *self, PyObject *args)
{
PyObject *seq1, *seq2;
if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
return NULL;
switch (PyMapping_GetOptionalItem(obj, attr_name, &value)) {
case -1:
assert(value == NULL);
return NULL;
case 0:
assert(value == NULL);
return Py_NewRef(PyExc_KeyError);
case 1:
return value;
default:
Py_FatalError("PyMapping_GetOptionalItem() returned invalid code");
Py_UNREACHABLE();
}
NULLABLE(seq1);
NULLABLE(seq2);
return PySequence_Concat(seq1, seq2);
}
static PyObject *
sequence_repeat(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t count;
if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
return NULL;
}
NULLABLE(seq);
return PySequence_Repeat(seq, count);
}
static PyObject *
sequence_inplaceconcat(PyObject *self, PyObject *args)
{
PyObject *seq1, *seq2;
if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
return NULL;
}
NULLABLE(seq1);
NULLABLE(seq2);
return PySequence_InPlaceConcat(seq1, seq2);
}
static PyObject *
sequence_inplacerepeat(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t count;
if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
return NULL;
}
NULLABLE(seq);
return PySequence_InPlaceRepeat(seq, count);
}
static PyObject *
sequence_getitem(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t i;
if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
return NULL;
}
NULLABLE(seq);
return PySequence_GetItem(seq, i);
}
static PyObject *
sequence_setitem(PyObject *self, PyObject *args)
{
Py_ssize_t i;
PyObject *seq, *val;
if (!PyArg_ParseTuple(args, "OnO", &seq, &i, &val)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(val);
RETURN_INT(PySequence_SetItem(seq, i, val));
}
static PyObject *
sequence_delitem(PyObject *self, PyObject *args)
{
Py_ssize_t i;
PyObject *seq;
if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
return NULL;
}
NULLABLE(seq);
RETURN_INT(PySequence_DelItem(seq, i));
}
static PyObject *
sequence_setslice(PyObject* self, PyObject *args)
{
PyObject *sequence, *obj;
Py_ssize_t i1, i2;
if (!PyArg_ParseTuple(args, "OnnO", &sequence, &i1, &i2, &obj)) {
return NULL;
}
NULLABLE(sequence);
NULLABLE(obj);
RETURN_INT(PySequence_SetSlice(sequence, i1, i2, obj));
}
static PyObject *
sequence_delslice(PyObject *self, PyObject *args)
{
PyObject *sequence;
Py_ssize_t i1, i2;
if (!PyArg_ParseTuple(args, "Onn", &sequence, &i1, &i2)) {
return NULL;
}
NULLABLE(sequence);
RETURN_INT(PySequence_DelSlice(sequence, i1, i2));
}
static PyObject *
sequence_count(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_SIZE(PySequence_Count(seq, value));
}
static PyObject *
sequence_contains(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_INT(PySequence_Contains(seq, value));
}
static PyObject *
sequence_index(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_SIZE(PySequence_Index(seq, value));
}
static PyObject *
sequence_list(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PySequence_List(obj);
}
static PyObject *
sequence_tuple(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PySequence_Tuple(obj);
}
static PyMethodDef test_methods[] = {
{"object_repr", object_repr, METH_O},
{"object_ascii", object_ascii, METH_O},
{"object_str", object_str, METH_O},
{"object_bytes", object_bytes, METH_O},
{"object_getattr", object_getattr, METH_VARARGS},
{"object_getattrstring", object_getattrstring, METH_VARARGS},
{"object_getoptionalattr", object_getoptionalattr, METH_VARARGS},
{"object_getoptionalattrstring", object_getoptionalattrstring, METH_VARARGS},
{"object_hasattr", object_hasattr, METH_VARARGS},
{"object_hasattrstring", object_hasattrstring, METH_VARARGS},
{"object_hasattrwitherror", object_hasattrwitherror, METH_VARARGS},
{"object_hasattrstringwitherror", object_hasattrstringwitherror, METH_VARARGS},
{"object_setattr", object_setattr, METH_VARARGS},
{"object_setattrstring", object_setattrstring, METH_VARARGS},
{"object_delattr", object_delattr, METH_VARARGS},
{"object_delattrstring", object_delattrstring, METH_VARARGS},
{"number_check", number_check, METH_O},
{"mapping_check", mapping_check, METH_O},
{"mapping_size", mapping_size, METH_O},
{"mapping_length", mapping_length, METH_O},
{"object_getitem", object_getitem, METH_VARARGS},
{"mapping_getitemstring", mapping_getitemstring, METH_VARARGS},
{"mapping_getoptionalitem", mapping_getoptionalitem, METH_VARARGS},
{"mapping_getoptionalitemstring", mapping_getoptionalitemstring, METH_VARARGS},
{"mapping_haskey", mapping_haskey, METH_VARARGS},
{"mapping_haskeystring", mapping_haskeystring, METH_VARARGS},
{"mapping_haskeywitherror", mapping_haskeywitherror, METH_VARARGS},
{"mapping_haskeystringwitherror", mapping_haskeystringwitherror, METH_VARARGS},
{"object_setitem", object_setitem, METH_VARARGS},
{"mapping_setitemstring", mapping_setitemstring, METH_VARARGS},
{"object_delitem", object_delitem, METH_VARARGS},
{"mapping_delitem", mapping_delitem, METH_VARARGS},
{"mapping_delitemstring", mapping_delitemstring, METH_VARARGS},
{"mapping_keys", mapping_keys, METH_O},
{"mapping_values", mapping_values, METH_O},
{"mapping_items", mapping_items, METH_O},
{"sequence_check", sequence_check, METH_O},
{"sequence_size", sequence_size, METH_O},
{"sequence_length", sequence_length, METH_O},
{"sequence_concat", sequence_concat, METH_VARARGS},
{"sequence_repeat", sequence_repeat, METH_VARARGS},
{"sequence_inplaceconcat", sequence_inplaceconcat, METH_VARARGS},
{"sequence_inplacerepeat", sequence_inplacerepeat, METH_VARARGS},
{"sequence_getitem", sequence_getitem, METH_VARARGS},
{"sequence_setitem", sequence_setitem, METH_VARARGS},
{"sequence_delitem", sequence_delitem, METH_VARARGS},
{"sequence_setslice", sequence_setslice, METH_VARARGS},
{"sequence_delslice", sequence_delslice, METH_VARARGS},
{"sequence_count", sequence_count, METH_VARARGS},
{"sequence_contains", sequence_contains, METH_VARARGS},
{"sequence_index", sequence_index, METH_VARARGS},
{"sequence_list", sequence_list, METH_O},
{"sequence_tuple", sequence_tuple, METH_O},
{NULL},
};

View File

@ -6,71 +6,6 @@
#include "clinic/float.c.h"
static PyObject *
float_check(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyFloat_Check(obj));
}
static PyObject *
float_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyFloat_CheckExact(obj));
}
static PyObject *
float_fromstring(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyFloat_FromString(obj);
}
static PyObject *
float_fromdouble(PyObject *Py_UNUSED(module), PyObject *obj)
{
double d;
if (!PyArg_Parse(obj, "d", &d)) {
return NULL;
}
return PyFloat_FromDouble(d);
}
static PyObject *
float_asdouble(PyObject *Py_UNUSED(module), PyObject *obj)
{
double d;
NULLABLE(obj);
d = PyFloat_AsDouble(obj);
if (d == -1. && PyErr_Occurred()) {
return NULL;
}
return PyFloat_FromDouble(d);
}
static PyObject *
float_getinfo(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_GetInfo();
}
static PyObject *
float_getmax(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_FromDouble(PyFloat_GetMax());
}
static PyObject *
float_getmin(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_FromDouble(PyFloat_GetMin());
}
/*[clinic input]
module _testcapi
[clinic start generated code]*/
@ -165,14 +100,6 @@ _testcapi_float_unpack_impl(PyObject *module, const char *data,
}
static PyMethodDef test_methods[] = {
{"float_check", float_check, METH_O},
{"float_checkexact", float_checkexact, METH_O},
{"float_fromstring", float_fromstring, METH_O},
{"float_fromdouble", float_fromdouble, METH_O},
{"float_asdouble", float_asdouble, METH_O},
{"float_getinfo", float_getinfo, METH_NOARGS},
{"float_getmax", float_getmax, METH_NOARGS},
{"float_getmin", float_getmin, METH_NOARGS},
_TESTCAPI_FLOAT_PACK_METHODDEF
_TESTCAPI_FLOAT_UNPACK_METHODDEF
{NULL},

View File

@ -26,12 +26,18 @@ PyInit__testlimitedcapi(void)
return NULL;
}
if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
return NULL;
}

View File

@ -0,0 +1,582 @@
#include "parts.h"
#include "util.h"
static PyObject *
object_repr(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Repr(arg);
}
static PyObject *
object_ascii(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_ASCII(arg);
}
static PyObject *
object_str(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Str(arg);
}
static PyObject *
object_bytes(PyObject *self, PyObject *arg)
{
NULLABLE(arg);
return PyObject_Bytes(arg);
}
static PyObject *
object_getattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
return PyObject_GetAttr(obj, attr_name);
}
static PyObject *
object_getattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
return PyObject_GetAttrString(obj, attr_name);
}
static PyObject *
object_hasattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
return PyLong_FromLong(PyObject_HasAttr(obj, attr_name));
}
static PyObject *
object_hasattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
return PyLong_FromLong(PyObject_HasAttrString(obj, attr_name));
}
static PyObject *
object_setattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name, *value;
if (!PyArg_ParseTuple(args, "OOO", &obj, &attr_name, &value)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
NULLABLE(value);
RETURN_INT(PyObject_SetAttr(obj, attr_name, value));
}
static PyObject *
object_setattrstring(PyObject *self, PyObject *args)
{
PyObject *obj, *value;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#O", &obj, &attr_name, &size, &value)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(value);
RETURN_INT(PyObject_SetAttrString(obj, attr_name, value));
}
static PyObject *
object_delattr(PyObject *self, PyObject *args)
{
PyObject *obj, *attr_name;
if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) {
return NULL;
}
NULLABLE(obj);
NULLABLE(attr_name);
RETURN_INT(PyObject_DelAttr(obj, attr_name));
}
static PyObject *
object_delattrstring(PyObject *self, PyObject *args)
{
PyObject *obj;
const char *attr_name;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) {
return NULL;
}
NULLABLE(obj);
RETURN_INT(PyObject_DelAttrString(obj, attr_name));
}
static PyObject *
number_check(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyBool_FromLong(PyNumber_Check(obj));
}
static PyObject *
mapping_check(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyMapping_Check(obj));
}
static PyObject *
mapping_size(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PyMapping_Size(obj));
}
static PyObject *
mapping_length(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PyMapping_Length(obj));
}
static PyObject *
object_getitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
return PyObject_GetItem(mapping, key);
}
static PyObject *
mapping_getitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
return PyMapping_GetItemString(mapping, key);
}
static PyObject *
mapping_haskey(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
return PyLong_FromLong(PyMapping_HasKey(mapping, key));
}
static PyObject *
mapping_haskeystring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
return PyLong_FromLong(PyMapping_HasKeyString(mapping, key));
}
static PyObject *
mapping_haskeywitherror(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyMapping_HasKeyWithError(mapping, key));
}
static PyObject *
mapping_haskeystringwitherror(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
RETURN_INT(PyMapping_HasKeyStringWithError(mapping, key));
}
static PyObject *
object_setitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key, *value;
if (!PyArg_ParseTuple(args, "OOO", &mapping, &key, &value)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
NULLABLE(value);
RETURN_INT(PyObject_SetItem(mapping, key, value));
}
static PyObject *
mapping_setitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping, *value;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#O", &mapping, &key, &size, &value)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(value);
RETURN_INT(PyMapping_SetItemString(mapping, key, value));
}
static PyObject *
object_delitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyObject_DelItem(mapping, key));
}
static PyObject *
mapping_delitem(PyObject *self, PyObject *args)
{
PyObject *mapping, *key;
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
return NULL;
}
NULLABLE(mapping);
NULLABLE(key);
RETURN_INT(PyMapping_DelItem(mapping, key));
}
static PyObject *
mapping_delitemstring(PyObject *self, PyObject *args)
{
PyObject *mapping;
const char *key;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Oz#", &mapping, &key, &size)) {
return NULL;
}
NULLABLE(mapping);
RETURN_INT(PyMapping_DelItemString(mapping, key));
}
static PyObject *
mapping_keys(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Keys(obj);
}
static PyObject *
mapping_values(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Values(obj);
}
static PyObject *
mapping_items(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PyMapping_Items(obj);
}
static PyObject *
sequence_check(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PySequence_Check(obj));
}
static PyObject *
sequence_size(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PySequence_Size(obj));
}
static PyObject *
sequence_length(PyObject* self, PyObject *obj)
{
NULLABLE(obj);
RETURN_SIZE(PySequence_Length(obj));
}
static PyObject *
sequence_concat(PyObject *self, PyObject *args)
{
PyObject *seq1, *seq2;
if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
return NULL;
}
NULLABLE(seq1);
NULLABLE(seq2);
return PySequence_Concat(seq1, seq2);
}
static PyObject *
sequence_repeat(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t count;
if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
return NULL;
}
NULLABLE(seq);
return PySequence_Repeat(seq, count);
}
static PyObject *
sequence_inplaceconcat(PyObject *self, PyObject *args)
{
PyObject *seq1, *seq2;
if (!PyArg_ParseTuple(args, "OO", &seq1, &seq2)) {
return NULL;
}
NULLABLE(seq1);
NULLABLE(seq2);
return PySequence_InPlaceConcat(seq1, seq2);
}
static PyObject *
sequence_inplacerepeat(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t count;
if (!PyArg_ParseTuple(args, "On", &seq, &count)) {
return NULL;
}
NULLABLE(seq);
return PySequence_InPlaceRepeat(seq, count);
}
static PyObject *
sequence_getitem(PyObject *self, PyObject *args)
{
PyObject *seq;
Py_ssize_t i;
if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
return NULL;
}
NULLABLE(seq);
return PySequence_GetItem(seq, i);
}
static PyObject *
sequence_setitem(PyObject *self, PyObject *args)
{
Py_ssize_t i;
PyObject *seq, *val;
if (!PyArg_ParseTuple(args, "OnO", &seq, &i, &val)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(val);
RETURN_INT(PySequence_SetItem(seq, i, val));
}
static PyObject *
sequence_delitem(PyObject *self, PyObject *args)
{
Py_ssize_t i;
PyObject *seq;
if (!PyArg_ParseTuple(args, "On", &seq, &i)) {
return NULL;
}
NULLABLE(seq);
RETURN_INT(PySequence_DelItem(seq, i));
}
static PyObject *
sequence_setslice(PyObject* self, PyObject *args)
{
PyObject *sequence, *obj;
Py_ssize_t i1, i2;
if (!PyArg_ParseTuple(args, "OnnO", &sequence, &i1, &i2, &obj)) {
return NULL;
}
NULLABLE(sequence);
NULLABLE(obj);
RETURN_INT(PySequence_SetSlice(sequence, i1, i2, obj));
}
static PyObject *
sequence_delslice(PyObject *self, PyObject *args)
{
PyObject *sequence;
Py_ssize_t i1, i2;
if (!PyArg_ParseTuple(args, "Onn", &sequence, &i1, &i2)) {
return NULL;
}
NULLABLE(sequence);
RETURN_INT(PySequence_DelSlice(sequence, i1, i2));
}
static PyObject *
sequence_count(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_SIZE(PySequence_Count(seq, value));
}
static PyObject *
sequence_contains(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_INT(PySequence_Contains(seq, value));
}
static PyObject *
sequence_index(PyObject *self, PyObject *args)
{
PyObject *seq, *value;
if (!PyArg_ParseTuple(args, "OO", &seq, &value)) {
return NULL;
}
NULLABLE(seq);
NULLABLE(value);
RETURN_SIZE(PySequence_Index(seq, value));
}
static PyObject *
sequence_list(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PySequence_List(obj);
}
static PyObject *
sequence_tuple(PyObject *self, PyObject *obj)
{
NULLABLE(obj);
return PySequence_Tuple(obj);
}
static PyMethodDef test_methods[] = {
{"object_repr", object_repr, METH_O},
{"object_ascii", object_ascii, METH_O},
{"object_str", object_str, METH_O},
{"object_bytes", object_bytes, METH_O},
{"object_getattr", object_getattr, METH_VARARGS},
{"object_getattrstring", object_getattrstring, METH_VARARGS},
{"object_hasattr", object_hasattr, METH_VARARGS},
{"object_hasattrstring", object_hasattrstring, METH_VARARGS},
{"object_setattr", object_setattr, METH_VARARGS},
{"object_setattrstring", object_setattrstring, METH_VARARGS},
{"object_delattr", object_delattr, METH_VARARGS},
{"object_delattrstring", object_delattrstring, METH_VARARGS},
{"number_check", number_check, METH_O},
{"mapping_check", mapping_check, METH_O},
{"mapping_size", mapping_size, METH_O},
{"mapping_length", mapping_length, METH_O},
{"object_getitem", object_getitem, METH_VARARGS},
{"mapping_getitemstring", mapping_getitemstring, METH_VARARGS},
{"mapping_haskey", mapping_haskey, METH_VARARGS},
{"mapping_haskeystring", mapping_haskeystring, METH_VARARGS},
{"mapping_haskeywitherror", mapping_haskeywitherror, METH_VARARGS},
{"mapping_haskeystringwitherror", mapping_haskeystringwitherror, METH_VARARGS},
{"object_setitem", object_setitem, METH_VARARGS},
{"mapping_setitemstring", mapping_setitemstring, METH_VARARGS},
{"object_delitem", object_delitem, METH_VARARGS},
{"mapping_delitem", mapping_delitem, METH_VARARGS},
{"mapping_delitemstring", mapping_delitemstring, METH_VARARGS},
{"mapping_keys", mapping_keys, METH_O},
{"mapping_values", mapping_values, METH_O},
{"mapping_items", mapping_items, METH_O},
{"sequence_check", sequence_check, METH_O},
{"sequence_size", sequence_size, METH_O},
{"sequence_length", sequence_length, METH_O},
{"sequence_concat", sequence_concat, METH_VARARGS},
{"sequence_repeat", sequence_repeat, METH_VARARGS},
{"sequence_inplaceconcat", sequence_inplaceconcat, METH_VARARGS},
{"sequence_inplacerepeat", sequence_inplacerepeat, METH_VARARGS},
{"sequence_getitem", sequence_getitem, METH_VARARGS},
{"sequence_setitem", sequence_setitem, METH_VARARGS},
{"sequence_delitem", sequence_delitem, METH_VARARGS},
{"sequence_setslice", sequence_setslice, METH_VARARGS},
{"sequence_delslice", sequence_delslice, METH_VARARGS},
{"sequence_count", sequence_count, METH_VARARGS},
{"sequence_contains", sequence_contains, METH_VARARGS},
{"sequence_index", sequence_index, METH_VARARGS},
{"sequence_list", sequence_list, METH_O},
{"sequence_tuple", sequence_tuple, METH_O},
{NULL},
};
int
_PyTestLimitedCAPI_Init_Abstract(PyObject *m)
{
if (PyModule_AddFunctions(m, test_methods) < 0) {
return -1;
}
return 0;
}

View File

@ -0,0 +1,92 @@
#include "parts.h"
#include "util.h"
static PyObject *
float_check(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyFloat_Check(obj));
}
static PyObject *
float_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyLong_FromLong(PyFloat_CheckExact(obj));
}
static PyObject *
float_fromstring(PyObject *Py_UNUSED(module), PyObject *obj)
{
NULLABLE(obj);
return PyFloat_FromString(obj);
}
static PyObject *
float_fromdouble(PyObject *Py_UNUSED(module), PyObject *obj)
{
double d;
if (!PyArg_Parse(obj, "d", &d)) {
return NULL;
}
return PyFloat_FromDouble(d);
}
static PyObject *
float_asdouble(PyObject *Py_UNUSED(module), PyObject *obj)
{
double d;
NULLABLE(obj);
d = PyFloat_AsDouble(obj);
if (d == -1. && PyErr_Occurred()) {
return NULL;
}
return PyFloat_FromDouble(d);
}
static PyObject *
float_getinfo(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_GetInfo();
}
static PyObject *
float_getmax(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_FromDouble(PyFloat_GetMax());
}
static PyObject *
float_getmin(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(arg))
{
return PyFloat_FromDouble(PyFloat_GetMin());
}
static PyMethodDef test_methods[] = {
{"float_check", float_check, METH_O},
{"float_checkexact", float_checkexact, METH_O},
{"float_fromstring", float_fromstring, METH_O},
{"float_fromdouble", float_fromdouble, METH_O},
{"float_asdouble", float_asdouble, METH_O},
{"float_getinfo", float_getinfo, METH_NOARGS},
{"float_getmax", float_getmax, METH_NOARGS},
{"float_getmin", float_getmin, METH_NOARGS},
{NULL},
};
int
_PyTestLimitedCAPI_Init_Float(PyObject *mod)
{
if (PyModule_AddFunctions(mod, test_methods) < 0) {
return -1;
}
return 0;
}

View File

@ -22,8 +22,10 @@
# error "Py_BUILD_CORE macro must not be defined"
#endif
int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
int _PyTestLimitedCAPI_Init_List(PyObject *module);
int _PyTestLimitedCAPI_Init_PyOS(PyObject *module);

View File

@ -94,8 +94,10 @@
</PropertyGroup>
<ItemGroup>
<ClCompile Include="..\Modules\_testlimitedcapi.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\pyos.c" />

View File

@ -9,8 +9,10 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\pyos.c" />