mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-116417: Move limited C API dict.c tests to _testlimitedcapi (#117006)
Split dict.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
This commit is contained in:
parent
75935746be
commit
f55e1880c1
8 changed files with 325 additions and 304 deletions
|
|
@ -3,6 +3,7 @@ from collections import OrderedDict, UserDict
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from test import support
|
from test import support
|
||||||
import _testcapi
|
import _testcapi
|
||||||
|
import _testlimitedcapi
|
||||||
|
|
||||||
|
|
||||||
NULL = None
|
NULL = None
|
||||||
|
|
@ -25,7 +26,7 @@ def gen():
|
||||||
class CAPITest(unittest.TestCase):
|
class CAPITest(unittest.TestCase):
|
||||||
|
|
||||||
def test_dict_check(self):
|
def test_dict_check(self):
|
||||||
check = _testcapi.dict_check
|
check = _testlimitedcapi.dict_check
|
||||||
self.assertTrue(check({1: 2}))
|
self.assertTrue(check({1: 2}))
|
||||||
self.assertTrue(check(OrderedDict({1: 2})))
|
self.assertTrue(check(OrderedDict({1: 2})))
|
||||||
self.assertFalse(check(UserDict({1: 2})))
|
self.assertFalse(check(UserDict({1: 2})))
|
||||||
|
|
@ -34,7 +35,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES check(NULL)
|
# CRASHES check(NULL)
|
||||||
|
|
||||||
def test_dict_checkexact(self):
|
def test_dict_checkexact(self):
|
||||||
check = _testcapi.dict_checkexact
|
check = _testlimitedcapi.dict_checkexact
|
||||||
self.assertTrue(check({1: 2}))
|
self.assertTrue(check({1: 2}))
|
||||||
self.assertFalse(check(OrderedDict({1: 2})))
|
self.assertFalse(check(OrderedDict({1: 2})))
|
||||||
self.assertFalse(check(UserDict({1: 2})))
|
self.assertFalse(check(UserDict({1: 2})))
|
||||||
|
|
@ -43,7 +44,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES check(NULL)
|
# CRASHES check(NULL)
|
||||||
|
|
||||||
def test_dict_new(self):
|
def test_dict_new(self):
|
||||||
dict_new = _testcapi.dict_new
|
dict_new = _testlimitedcapi.dict_new
|
||||||
dct = dict_new()
|
dct = dict_new()
|
||||||
self.assertEqual(dct, {})
|
self.assertEqual(dct, {})
|
||||||
self.assertIs(type(dct), dict)
|
self.assertIs(type(dct), dict)
|
||||||
|
|
@ -51,7 +52,7 @@ class CAPITest(unittest.TestCase):
|
||||||
self.assertIsNot(dct2, dct)
|
self.assertIsNot(dct2, dct)
|
||||||
|
|
||||||
def test_dictproxy_new(self):
|
def test_dictproxy_new(self):
|
||||||
dictproxy_new = _testcapi.dictproxy_new
|
dictproxy_new = _testlimitedcapi.dictproxy_new
|
||||||
for dct in {1: 2}, OrderedDict({1: 2}), UserDict({1: 2}):
|
for dct in {1: 2}, OrderedDict({1: 2}), UserDict({1: 2}):
|
||||||
proxy = dictproxy_new(dct)
|
proxy = dictproxy_new(dct)
|
||||||
self.assertIs(type(proxy), MappingProxyType)
|
self.assertIs(type(proxy), MappingProxyType)
|
||||||
|
|
@ -67,7 +68,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES dictproxy_new(NULL)
|
# CRASHES dictproxy_new(NULL)
|
||||||
|
|
||||||
def test_dict_copy(self):
|
def test_dict_copy(self):
|
||||||
copy = _testcapi.dict_copy
|
copy = _testlimitedcapi.dict_copy
|
||||||
for dct in {1: 2}, OrderedDict({1: 2}):
|
for dct in {1: 2}, OrderedDict({1: 2}):
|
||||||
dct_copy = copy(dct)
|
dct_copy = copy(dct)
|
||||||
self.assertIs(type(dct_copy), dict)
|
self.assertIs(type(dct_copy), dict)
|
||||||
|
|
@ -79,7 +80,7 @@ class CAPITest(unittest.TestCase):
|
||||||
self.assertRaises(SystemError, copy, NULL)
|
self.assertRaises(SystemError, copy, NULL)
|
||||||
|
|
||||||
def test_dict_clear(self):
|
def test_dict_clear(self):
|
||||||
clear = _testcapi.dict_clear
|
clear = _testlimitedcapi.dict_clear
|
||||||
dct = {1: 2}
|
dct = {1: 2}
|
||||||
clear(dct)
|
clear(dct)
|
||||||
self.assertEqual(dct, {})
|
self.assertEqual(dct, {})
|
||||||
|
|
@ -98,7 +99,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES? clear(NULL)
|
# CRASHES? clear(NULL)
|
||||||
|
|
||||||
def test_dict_size(self):
|
def test_dict_size(self):
|
||||||
size = _testcapi.dict_size
|
size = _testlimitedcapi.dict_size
|
||||||
self.assertEqual(size({1: 2}), 1)
|
self.assertEqual(size({1: 2}), 1)
|
||||||
self.assertEqual(size(OrderedDict({1: 2})), 1)
|
self.assertEqual(size(OrderedDict({1: 2})), 1)
|
||||||
|
|
||||||
|
|
@ -109,7 +110,7 @@ class CAPITest(unittest.TestCase):
|
||||||
self.assertRaises(SystemError, size, NULL)
|
self.assertRaises(SystemError, size, NULL)
|
||||||
|
|
||||||
def test_dict_getitem(self):
|
def test_dict_getitem(self):
|
||||||
getitem = _testcapi.dict_getitem
|
getitem = _testlimitedcapi.dict_getitem
|
||||||
dct = {'a': 1, '\U0001f40d': 2}
|
dct = {'a': 1, '\U0001f40d': 2}
|
||||||
self.assertEqual(getitem(dct, 'a'), 1)
|
self.assertEqual(getitem(dct, 'a'), 1)
|
||||||
self.assertIs(getitem(dct, 'b'), KeyError)
|
self.assertIs(getitem(dct, 'b'), KeyError)
|
||||||
|
|
@ -131,7 +132,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES getitem(NULL, 'a')
|
# CRASHES getitem(NULL, 'a')
|
||||||
|
|
||||||
def test_dict_getitemstring(self):
|
def test_dict_getitemstring(self):
|
||||||
getitemstring = _testcapi.dict_getitemstring
|
getitemstring = _testlimitedcapi.dict_getitemstring
|
||||||
dct = {'a': 1, '\U0001f40d': 2}
|
dct = {'a': 1, '\U0001f40d': 2}
|
||||||
self.assertEqual(getitemstring(dct, b'a'), 1)
|
self.assertEqual(getitemstring(dct, b'a'), 1)
|
||||||
self.assertIs(getitemstring(dct, b'b'), KeyError)
|
self.assertIs(getitemstring(dct, b'b'), KeyError)
|
||||||
|
|
@ -188,7 +189,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES getitemstring(NULL, b'a')
|
# CRASHES getitemstring(NULL, b'a')
|
||||||
|
|
||||||
def test_dict_getitemwitherror(self):
|
def test_dict_getitemwitherror(self):
|
||||||
getitem = _testcapi.dict_getitemwitherror
|
getitem = _testlimitedcapi.dict_getitemwitherror
|
||||||
dct = {'a': 1, '\U0001f40d': 2}
|
dct = {'a': 1, '\U0001f40d': 2}
|
||||||
self.assertEqual(getitem(dct, 'a'), 1)
|
self.assertEqual(getitem(dct, 'a'), 1)
|
||||||
self.assertIs(getitem(dct, 'b'), KeyError)
|
self.assertIs(getitem(dct, 'b'), KeyError)
|
||||||
|
|
@ -206,7 +207,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES getitem(NULL, 'a')
|
# CRASHES getitem(NULL, 'a')
|
||||||
|
|
||||||
def test_dict_contains(self):
|
def test_dict_contains(self):
|
||||||
contains = _testcapi.dict_contains
|
contains = _testlimitedcapi.dict_contains
|
||||||
dct = {'a': 1, '\U0001f40d': 2}
|
dct = {'a': 1, '\U0001f40d': 2}
|
||||||
self.assertTrue(contains(dct, 'a'))
|
self.assertTrue(contains(dct, 'a'))
|
||||||
self.assertFalse(contains(dct, 'b'))
|
self.assertFalse(contains(dct, 'b'))
|
||||||
|
|
@ -238,7 +239,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES contains(NULL, b'a')
|
# CRASHES contains(NULL, b'a')
|
||||||
|
|
||||||
def test_dict_setitem(self):
|
def test_dict_setitem(self):
|
||||||
setitem = _testcapi.dict_setitem
|
setitem = _testlimitedcapi.dict_setitem
|
||||||
dct = {}
|
dct = {}
|
||||||
setitem(dct, 'a', 5)
|
setitem(dct, 'a', 5)
|
||||||
self.assertEqual(dct, {'a': 5})
|
self.assertEqual(dct, {'a': 5})
|
||||||
|
|
@ -258,7 +259,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES setitem(NULL, 'a', 5)
|
# CRASHES setitem(NULL, 'a', 5)
|
||||||
|
|
||||||
def test_dict_setitemstring(self):
|
def test_dict_setitemstring(self):
|
||||||
setitemstring = _testcapi.dict_setitemstring
|
setitemstring = _testlimitedcapi.dict_setitemstring
|
||||||
dct = {}
|
dct = {}
|
||||||
setitemstring(dct, b'a', 5)
|
setitemstring(dct, b'a', 5)
|
||||||
self.assertEqual(dct, {'a': 5})
|
self.assertEqual(dct, {'a': 5})
|
||||||
|
|
@ -277,7 +278,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES setitemstring(NULL, b'a', 5)
|
# CRASHES setitemstring(NULL, b'a', 5)
|
||||||
|
|
||||||
def test_dict_delitem(self):
|
def test_dict_delitem(self):
|
||||||
delitem = _testcapi.dict_delitem
|
delitem = _testlimitedcapi.dict_delitem
|
||||||
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
||||||
delitem(dct, 'a')
|
delitem(dct, 'a')
|
||||||
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
||||||
|
|
@ -298,7 +299,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES delitem(NULL, 'a')
|
# CRASHES delitem(NULL, 'a')
|
||||||
|
|
||||||
def test_dict_delitemstring(self):
|
def test_dict_delitemstring(self):
|
||||||
delitemstring = _testcapi.dict_delitemstring
|
delitemstring = _testlimitedcapi.dict_delitemstring
|
||||||
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
|
||||||
delitemstring(dct, b'a')
|
delitemstring(dct, b'a')
|
||||||
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
|
||||||
|
|
@ -371,21 +372,21 @@ class CAPITest(unittest.TestCase):
|
||||||
return None
|
return None
|
||||||
dict_obj = {'foo': 1, 'bar': 2, 'spam': 3}
|
dict_obj = {'foo': 1, 'bar': 2, 'spam': 3}
|
||||||
for mapping in [dict_obj, DictSubclass(dict_obj), BadMapping(dict_obj)]:
|
for mapping in [dict_obj, DictSubclass(dict_obj), BadMapping(dict_obj)]:
|
||||||
self.assertListEqual(_testcapi.dict_keys(mapping),
|
self.assertListEqual(_testlimitedcapi.dict_keys(mapping),
|
||||||
list(dict_obj.keys()))
|
list(dict_obj.keys()))
|
||||||
self.assertListEqual(_testcapi.dict_values(mapping),
|
self.assertListEqual(_testlimitedcapi.dict_values(mapping),
|
||||||
list(dict_obj.values()))
|
list(dict_obj.values()))
|
||||||
self.assertListEqual(_testcapi.dict_items(mapping),
|
self.assertListEqual(_testlimitedcapi.dict_items(mapping),
|
||||||
list(dict_obj.items()))
|
list(dict_obj.items()))
|
||||||
|
|
||||||
def test_dict_keys_valuesitems_bad_arg(self):
|
def test_dict_keys_valuesitems_bad_arg(self):
|
||||||
for mapping in UserDict(), [], object():
|
for mapping in UserDict(), [], object():
|
||||||
self.assertRaises(SystemError, _testcapi.dict_keys, mapping)
|
self.assertRaises(SystemError, _testlimitedcapi.dict_keys, mapping)
|
||||||
self.assertRaises(SystemError, _testcapi.dict_values, mapping)
|
self.assertRaises(SystemError, _testlimitedcapi.dict_values, mapping)
|
||||||
self.assertRaises(SystemError, _testcapi.dict_items, mapping)
|
self.assertRaises(SystemError, _testlimitedcapi.dict_items, mapping)
|
||||||
|
|
||||||
def test_dict_next(self):
|
def test_dict_next(self):
|
||||||
dict_next = _testcapi.dict_next
|
dict_next = _testlimitedcapi.dict_next
|
||||||
self.assertIsNone(dict_next({}, 0))
|
self.assertIsNone(dict_next({}, 0))
|
||||||
dct = {'a': 1, 'b': 2, 'c': 3}
|
dct = {'a': 1, 'b': 2, 'c': 3}
|
||||||
pos = 0
|
pos = 0
|
||||||
|
|
@ -402,7 +403,7 @@ class CAPITest(unittest.TestCase):
|
||||||
# CRASHES dict_next(NULL, 0)
|
# CRASHES dict_next(NULL, 0)
|
||||||
|
|
||||||
def test_dict_update(self):
|
def test_dict_update(self):
|
||||||
update = _testcapi.dict_update
|
update = _testlimitedcapi.dict_update
|
||||||
for cls1 in dict, DictSubclass:
|
for cls1 in dict, DictSubclass:
|
||||||
for cls2 in dict, DictSubclass, UserDict:
|
for cls2 in dict, DictSubclass, UserDict:
|
||||||
dct = cls1({'a': 1, 'b': 2})
|
dct = cls1({'a': 1, 'b': 2})
|
||||||
|
|
@ -417,7 +418,7 @@ class CAPITest(unittest.TestCase):
|
||||||
self.assertRaises(SystemError, update, NULL, {})
|
self.assertRaises(SystemError, update, NULL, {})
|
||||||
|
|
||||||
def test_dict_merge(self):
|
def test_dict_merge(self):
|
||||||
merge = _testcapi.dict_merge
|
merge = _testlimitedcapi.dict_merge
|
||||||
for cls1 in dict, DictSubclass:
|
for cls1 in dict, DictSubclass:
|
||||||
for cls2 in dict, DictSubclass, UserDict:
|
for cls2 in dict, DictSubclass, UserDict:
|
||||||
dct = cls1({'a': 1, 'b': 2})
|
dct = cls1({'a': 1, 'b': 2})
|
||||||
|
|
@ -435,7 +436,7 @@ class CAPITest(unittest.TestCase):
|
||||||
self.assertRaises(SystemError, merge, NULL, {}, 0)
|
self.assertRaises(SystemError, merge, NULL, {}, 0)
|
||||||
|
|
||||||
def test_dict_mergefromseq2(self):
|
def test_dict_mergefromseq2(self):
|
||||||
mergefromseq2 = _testcapi.dict_mergefromseq2
|
mergefromseq2 = _testlimitedcapi.dict_mergefromseq2
|
||||||
for cls1 in dict, DictSubclass:
|
for cls1 in dict, DictSubclass:
|
||||||
for cls2 in list, iter:
|
for cls2 in list, iter:
|
||||||
dct = cls1({'a': 1, 'b': 2})
|
dct = cls1({'a': 1, 'b': 2})
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@
|
||||||
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
|
@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__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__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/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
|
@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
|
||||||
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
|
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
|
||||||
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
|
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,59 +2,6 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_check(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyLong_FromLong(PyDict_Check(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_checkexact(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyLong_FromLong(PyDict_CheckExact(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_new(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|
||||||
{
|
|
||||||
return PyDict_New();
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dictproxy_new(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyDictProxy_New(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_clear(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
PyDict_Clear(obj);
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_copy(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyDict_Copy(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_contains(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *obj, *key;
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &obj, &key)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(obj);
|
|
||||||
NULLABLE(key);
|
|
||||||
RETURN_INT(PyDict_Contains(obj, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_containsstring(PyObject *self, PyObject *args)
|
dict_containsstring(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -68,72 +15,6 @@ dict_containsstring(PyObject *self, PyObject *args)
|
||||||
RETURN_INT(PyDict_ContainsString(obj, key));
|
RETURN_INT(PyDict_ContainsString(obj, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_size(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
RETURN_SIZE(PyDict_Size(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_getitem(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *key;
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(key);
|
|
||||||
PyObject *value = PyDict_GetItem(mapping, key);
|
|
||||||
if (value == NULL) {
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return Py_NewRef(PyExc_KeyError);
|
|
||||||
}
|
|
||||||
return Py_NewRef(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_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);
|
|
||||||
PyObject *value = PyDict_GetItemString(mapping, key);
|
|
||||||
if (value == NULL) {
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return Py_NewRef(PyExc_KeyError);
|
|
||||||
}
|
|
||||||
return Py_NewRef(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_getitemwitherror(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *key;
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(key);
|
|
||||||
PyObject *value = PyDict_GetItemWithError(mapping, key);
|
|
||||||
if (value == NULL) {
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return Py_NewRef(PyExc_KeyError);
|
|
||||||
}
|
|
||||||
return Py_NewRef(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_getitemref(PyObject *self, PyObject *args)
|
dict_getitemref(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -185,33 +66,6 @@ dict_getitemstringref(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_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(PyDict_SetItem(mapping, key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_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(PyDict_SetItemString(mapping, key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_setdefault(PyObject *self, PyObject *args)
|
dict_setdefault(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -250,112 +104,6 @@ dict_setdefaultref(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_delitem(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *key;
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(key);
|
|
||||||
RETURN_INT(PyDict_DelItem(mapping, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_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(PyDict_DelItemString(mapping, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_keys(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyDict_Keys(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_values(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyDict_Values(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_items(PyObject *self, PyObject *obj)
|
|
||||||
{
|
|
||||||
NULLABLE(obj);
|
|
||||||
return PyDict_Items(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_next(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *key = UNINITIALIZED_PTR, *value = UNINITIALIZED_PTR;
|
|
||||||
Py_ssize_t pos;
|
|
||||||
if (!PyArg_ParseTuple(args, "On", &mapping, &pos)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
int rc = PyDict_Next(mapping, &pos, &key, &value);
|
|
||||||
if (rc != 0) {
|
|
||||||
return Py_BuildValue("inOO", rc, pos, key, value);
|
|
||||||
}
|
|
||||||
assert(key == UNINITIALIZED_PTR);
|
|
||||||
assert(value == UNINITIALIZED_PTR);
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_merge(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *mapping2;
|
|
||||||
int override;
|
|
||||||
if (!PyArg_ParseTuple(args, "OOi", &mapping, &mapping2, &override)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(mapping2);
|
|
||||||
RETURN_INT(PyDict_Merge(mapping, mapping2, override));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_update(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *mapping2;
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &mapping, &mapping2)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(mapping2);
|
|
||||||
RETURN_INT(PyDict_Update(mapping, mapping2));
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
dict_mergefromseq2(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *mapping, *seq;
|
|
||||||
int override;
|
|
||||||
if (!PyArg_ParseTuple(args, "OOi", &mapping, &seq, &override)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
NULLABLE(mapping);
|
|
||||||
NULLABLE(seq);
|
|
||||||
RETURN_INT(PyDict_MergeFromSeq2(mapping, seq, override));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_pop(PyObject *self, PyObject *args)
|
dict_pop(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -382,7 +130,6 @@ dict_pop(PyObject *self, PyObject *args)
|
||||||
return Py_BuildValue("iN", res, result);
|
return Py_BuildValue("iN", res, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_pop_null(PyObject *self, PyObject *args)
|
dict_pop_null(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -396,7 +143,6 @@ dict_pop_null(PyObject *self, PyObject *args)
|
||||||
RETURN_INT(PyDict_Pop(dict, key, NULL));
|
RETURN_INT(PyDict_Pop(dict, key, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_popstring(PyObject *self, PyObject *args)
|
dict_popstring(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -423,7 +169,6 @@ dict_popstring(PyObject *self, PyObject *args)
|
||||||
return Py_BuildValue("iN", res, result);
|
return Py_BuildValue("iN", res, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_popstring_null(PyObject *self, PyObject *args)
|
dict_popstring_null(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
|
@ -439,33 +184,11 @@ dict_popstring_null(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef test_methods[] = {
|
static PyMethodDef test_methods[] = {
|
||||||
{"dict_check", dict_check, METH_O},
|
{"dict_containsstring", dict_containsstring, METH_VARARGS},
|
||||||
{"dict_checkexact", dict_checkexact, METH_O},
|
|
||||||
{"dict_new", dict_new, METH_NOARGS},
|
|
||||||
{"dictproxy_new", dictproxy_new, METH_O},
|
|
||||||
{"dict_clear", dict_clear, METH_O},
|
|
||||||
{"dict_copy", dict_copy, METH_O},
|
|
||||||
{"dict_size", dict_size, METH_O},
|
|
||||||
{"dict_getitem", dict_getitem, METH_VARARGS},
|
|
||||||
{"dict_getitemwitherror", dict_getitemwitherror, METH_VARARGS},
|
|
||||||
{"dict_getitemstring", dict_getitemstring, METH_VARARGS},
|
|
||||||
{"dict_getitemref", dict_getitemref, METH_VARARGS},
|
{"dict_getitemref", dict_getitemref, METH_VARARGS},
|
||||||
{"dict_getitemstringref", dict_getitemstringref, METH_VARARGS},
|
{"dict_getitemstringref", dict_getitemstringref, METH_VARARGS},
|
||||||
{"dict_contains", dict_contains, METH_VARARGS},
|
|
||||||
{"dict_containsstring", dict_containsstring, METH_VARARGS},
|
|
||||||
{"dict_setitem", dict_setitem, METH_VARARGS},
|
|
||||||
{"dict_setitemstring", dict_setitemstring, METH_VARARGS},
|
|
||||||
{"dict_delitem", dict_delitem, METH_VARARGS},
|
|
||||||
{"dict_delitemstring", dict_delitemstring, METH_VARARGS},
|
|
||||||
{"dict_setdefault", dict_setdefault, METH_VARARGS},
|
{"dict_setdefault", dict_setdefault, METH_VARARGS},
|
||||||
{"dict_setdefaultref", dict_setdefaultref, METH_VARARGS},
|
{"dict_setdefaultref", dict_setdefaultref, METH_VARARGS},
|
||||||
{"dict_keys", dict_keys, METH_O},
|
|
||||||
{"dict_values", dict_values, METH_O},
|
|
||||||
{"dict_items", dict_items, METH_O},
|
|
||||||
{"dict_next", dict_next, METH_VARARGS},
|
|
||||||
{"dict_merge", dict_merge, METH_VARARGS},
|
|
||||||
{"dict_update", dict_update, METH_VARARGS},
|
|
||||||
{"dict_mergefromseq2", dict_mergefromseq2, METH_VARARGS},
|
|
||||||
{"dict_pop", dict_pop, METH_VARARGS},
|
{"dict_pop", dict_pop, METH_VARARGS},
|
||||||
{"dict_pop_null", dict_pop_null, METH_VARARGS},
|
{"dict_pop_null", dict_pop_null, METH_VARARGS},
|
||||||
{"dict_popstring", dict_popstring, METH_VARARGS},
|
{"dict_popstring", dict_popstring, METH_VARARGS},
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ PyInit__testlimitedcapi(void)
|
||||||
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
|
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
|
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
291
Modules/_testlimitedcapi/dict.c
Normal file
291
Modules/_testlimitedcapi/dict.c
Normal file
|
|
@ -0,0 +1,291 @@
|
||||||
|
#include "parts.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_check(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyLong_FromLong(PyDict_Check(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_checkexact(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyLong_FromLong(PyDict_CheckExact(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_new(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return PyDict_New();
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dictproxy_new(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyDictProxy_New(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_clear(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
PyDict_Clear(obj);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_copy(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyDict_Copy(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_contains(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *obj, *key;
|
||||||
|
if (!PyArg_ParseTuple(args, "OO", &obj, &key)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(obj);
|
||||||
|
NULLABLE(key);
|
||||||
|
RETURN_INT(PyDict_Contains(obj, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_size(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
RETURN_SIZE(PyDict_Size(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_getitem(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *key;
|
||||||
|
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(key);
|
||||||
|
PyObject *value = PyDict_GetItem(mapping, key);
|
||||||
|
if (value == NULL) {
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return Py_NewRef(PyExc_KeyError);
|
||||||
|
}
|
||||||
|
return Py_NewRef(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_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);
|
||||||
|
PyObject *value = PyDict_GetItemString(mapping, key);
|
||||||
|
if (value == NULL) {
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return Py_NewRef(PyExc_KeyError);
|
||||||
|
}
|
||||||
|
return Py_NewRef(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_getitemwitherror(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *key;
|
||||||
|
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(key);
|
||||||
|
PyObject *value = PyDict_GetItemWithError(mapping, key);
|
||||||
|
if (value == NULL) {
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return Py_NewRef(PyExc_KeyError);
|
||||||
|
}
|
||||||
|
return Py_NewRef(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_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(PyDict_SetItem(mapping, key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_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(PyDict_SetItemString(mapping, key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_delitem(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *key;
|
||||||
|
if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(key);
|
||||||
|
RETURN_INT(PyDict_DelItem(mapping, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_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(PyDict_DelItemString(mapping, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_keys(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyDict_Keys(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_values(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyDict_Values(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_items(PyObject *self, PyObject *obj)
|
||||||
|
{
|
||||||
|
NULLABLE(obj);
|
||||||
|
return PyDict_Items(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_next(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *key = UNINITIALIZED_PTR, *value = UNINITIALIZED_PTR;
|
||||||
|
Py_ssize_t pos;
|
||||||
|
if (!PyArg_ParseTuple(args, "On", &mapping, &pos)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
int rc = PyDict_Next(mapping, &pos, &key, &value);
|
||||||
|
if (rc != 0) {
|
||||||
|
return Py_BuildValue("inOO", rc, pos, key, value);
|
||||||
|
}
|
||||||
|
assert(key == UNINITIALIZED_PTR);
|
||||||
|
assert(value == UNINITIALIZED_PTR);
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_merge(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *mapping2;
|
||||||
|
int override;
|
||||||
|
if (!PyArg_ParseTuple(args, "OOi", &mapping, &mapping2, &override)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(mapping2);
|
||||||
|
RETURN_INT(PyDict_Merge(mapping, mapping2, override));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_update(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *mapping2;
|
||||||
|
if (!PyArg_ParseTuple(args, "OO", &mapping, &mapping2)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(mapping2);
|
||||||
|
RETURN_INT(PyDict_Update(mapping, mapping2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
dict_mergefromseq2(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *mapping, *seq;
|
||||||
|
int override;
|
||||||
|
if (!PyArg_ParseTuple(args, "OOi", &mapping, &seq, &override)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
NULLABLE(mapping);
|
||||||
|
NULLABLE(seq);
|
||||||
|
RETURN_INT(PyDict_MergeFromSeq2(mapping, seq, override));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyMethodDef test_methods[] = {
|
||||||
|
{"dict_check", dict_check, METH_O},
|
||||||
|
{"dict_checkexact", dict_checkexact, METH_O},
|
||||||
|
{"dict_new", dict_new, METH_NOARGS},
|
||||||
|
{"dictproxy_new", dictproxy_new, METH_O},
|
||||||
|
{"dict_clear", dict_clear, METH_O},
|
||||||
|
{"dict_copy", dict_copy, METH_O},
|
||||||
|
{"dict_size", dict_size, METH_O},
|
||||||
|
{"dict_getitem", dict_getitem, METH_VARARGS},
|
||||||
|
{"dict_getitemwitherror", dict_getitemwitherror, METH_VARARGS},
|
||||||
|
{"dict_getitemstring", dict_getitemstring, METH_VARARGS},
|
||||||
|
{"dict_contains", dict_contains, METH_VARARGS},
|
||||||
|
{"dict_setitem", dict_setitem, METH_VARARGS},
|
||||||
|
{"dict_setitemstring", dict_setitemstring, METH_VARARGS},
|
||||||
|
{"dict_delitem", dict_delitem, METH_VARARGS},
|
||||||
|
{"dict_delitemstring", dict_delitemstring, METH_VARARGS},
|
||||||
|
{"dict_keys", dict_keys, METH_O},
|
||||||
|
{"dict_values", dict_values, METH_O},
|
||||||
|
{"dict_items", dict_items, METH_O},
|
||||||
|
{"dict_next", dict_next, METH_VARARGS},
|
||||||
|
{"dict_merge", dict_merge, METH_VARARGS},
|
||||||
|
{"dict_update", dict_update, METH_VARARGS},
|
||||||
|
{"dict_mergefromseq2", dict_mergefromseq2, METH_VARARGS},
|
||||||
|
{NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
_PyTestLimitedCAPI_Init_Dict(PyObject *m)
|
||||||
|
{
|
||||||
|
if (PyModule_AddFunctions(m, test_methods) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
|
int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
|
||||||
int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
|
int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
|
||||||
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
|
int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
|
||||||
|
int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
|
||||||
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
|
int _PyTestLimitedCAPI_Init_Float(PyObject *module);
|
||||||
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
|
int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
|
||||||
int _PyTestLimitedCAPI_Init_List(PyObject *module);
|
int _PyTestLimitedCAPI_Init_List(PyObject *module);
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
|
||||||
|
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
|
||||||
|
<ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
|
||||||
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
|
<ClCompile Include="..\Modules\_testlimitedcapi\list.c" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue