diff --git a/Modules/_testcapi/clinic/dict.c.h b/Modules/_testcapi/clinic/dict.c.h new file mode 100644 index 00000000000000..d01db8759c8e4b --- /dev/null +++ b/Modules/_testcapi/clinic/dict.c.h @@ -0,0 +1,575 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) +# include "pycore_gc.h" // PyGC_Head +# include "pycore_runtime.h" // _Py_ID() +#endif + + +PyDoc_STRVAR(_testcapi_dict_check__doc__, +"dict_check($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_CHECK_METHODDEF \ + {"dict_check", (PyCFunction)_testcapi_dict_check, METH_O, _testcapi_dict_check__doc__}, + +PyDoc_STRVAR(_testcapi_dict_checkexact__doc__, +"dict_checkexact($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_CHECKEXACT_METHODDEF \ + {"dict_checkexact", (PyCFunction)_testcapi_dict_checkexact, METH_O, _testcapi_dict_checkexact__doc__}, + +PyDoc_STRVAR(_testcapi_dict_new__doc__, +"dict_new($module, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_NEW_METHODDEF \ + {"dict_new", (PyCFunction)_testcapi_dict_new, METH_NOARGS, _testcapi_dict_new__doc__}, + +static PyObject * +_testcapi_dict_new_impl(PyObject *module); + +static PyObject * +_testcapi_dict_new(PyObject *module, PyObject *Py_UNUSED(ignored)) +{ + return _testcapi_dict_new_impl(module); +} + +PyDoc_STRVAR(_testcapi_dictproxy_new__doc__, +"dictproxy_new($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICTPROXY_NEW_METHODDEF \ + {"dictproxy_new", (PyCFunction)_testcapi_dictproxy_new, METH_O, _testcapi_dictproxy_new__doc__}, + +PyDoc_STRVAR(_testcapi_dict_clear__doc__, +"dict_clear($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_CLEAR_METHODDEF \ + {"dict_clear", (PyCFunction)_testcapi_dict_clear, METH_O, _testcapi_dict_clear__doc__}, + +PyDoc_STRVAR(_testcapi_dict_copy__doc__, +"dict_copy($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_COPY_METHODDEF \ + {"dict_copy", (PyCFunction)_testcapi_dict_copy, METH_O, _testcapi_dict_copy__doc__}, + +PyDoc_STRVAR(_testcapi_dict_contains__doc__, +"dict_contains($module, obj, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_CONTAINS_METHODDEF \ + {"dict_contains", _PyCFunction_CAST(_testcapi_dict_contains), METH_FASTCALL, _testcapi_dict_contains__doc__}, + +static PyObject * +_testcapi_dict_contains_impl(PyObject *module, PyObject *obj, PyObject *key); + +static PyObject * +_testcapi_dict_contains(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *obj; + PyObject *key; + + if (!_PyArg_CheckPositional("dict_contains", nargs, 2, 2)) { + goto exit; + } + obj = args[0]; + key = args[1]; + return_value = _testcapi_dict_contains_impl(module, obj, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_size__doc__, +"dict_size($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_SIZE_METHODDEF \ + {"dict_size", (PyCFunction)_testcapi_dict_size, METH_O, _testcapi_dict_size__doc__}, + +PyDoc_STRVAR(_testcapi_dict_getitem__doc__, +"dict_getitem($module, mapping, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_GETITEM_METHODDEF \ + {"dict_getitem", _PyCFunction_CAST(_testcapi_dict_getitem), METH_FASTCALL, _testcapi_dict_getitem__doc__}, + +static PyObject * +_testcapi_dict_getitem_impl(PyObject *module, PyObject *mapping, + PyObject *key); + +static PyObject * +_testcapi_dict_getitem(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *key; + + if (!_PyArg_CheckPositional("dict_getitem", nargs, 2, 2)) { + goto exit; + } + mapping = args[0]; + key = args[1]; + return_value = _testcapi_dict_getitem_impl(module, mapping, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_getitemstring__doc__, +"dict_getitemstring($module, mapping, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_GETITEMSTRING_METHODDEF \ + {"dict_getitemstring", _PyCFunction_CAST(_testcapi_dict_getitemstring), METH_FASTCALL, _testcapi_dict_getitemstring__doc__}, + +static PyObject * +_testcapi_dict_getitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length); + +static PyObject * +_testcapi_dict_getitemstring(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + const char *key; + Py_ssize_t key_length; + + if (!_PyArg_ParseStack(args, nargs, "Oz#:dict_getitemstring", + &mapping, &key, &key_length)) { + goto exit; + } + return_value = _testcapi_dict_getitemstring_impl(module, mapping, key, key_length); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_getitemwitherror__doc__, +"dict_getitemwitherror($module, mapping, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_GETITEMWITHERROR_METHODDEF \ + {"dict_getitemwitherror", _PyCFunction_CAST(_testcapi_dict_getitemwitherror), METH_FASTCALL, _testcapi_dict_getitemwitherror__doc__}, + +static PyObject * +_testcapi_dict_getitemwitherror_impl(PyObject *module, PyObject *mapping, + PyObject *key); + +static PyObject * +_testcapi_dict_getitemwitherror(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *key; + + if (!_PyArg_CheckPositional("dict_getitemwitherror", nargs, 2, 2)) { + goto exit; + } + mapping = args[0]; + key = args[1]; + return_value = _testcapi_dict_getitemwitherror_impl(module, mapping, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_getitemref__doc__, +"dict_getitemref($module, obj, attr_name, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_GETITEMREF_METHODDEF \ + {"dict_getitemref", _PyCFunction_CAST(_testcapi_dict_getitemref), METH_FASTCALL, _testcapi_dict_getitemref__doc__}, + +static PyObject * +_testcapi_dict_getitemref_impl(PyObject *module, PyObject *obj, + PyObject *attr_name); + +static PyObject * +_testcapi_dict_getitemref(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *obj; + PyObject *attr_name; + + if (!_PyArg_CheckPositional("dict_getitemref", nargs, 2, 2)) { + goto exit; + } + obj = args[0]; + attr_name = args[1]; + return_value = _testcapi_dict_getitemref_impl(module, obj, attr_name); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_getitemstringref__doc__, +"dict_getitemstringref($module, obj, attr_name, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_GETITEMSTRINGREF_METHODDEF \ + {"dict_getitemstringref", _PyCFunction_CAST(_testcapi_dict_getitemstringref), METH_FASTCALL, _testcapi_dict_getitemstringref__doc__}, + +static PyObject * +_testcapi_dict_getitemstringref_impl(PyObject *module, PyObject *obj, + const char *attr_name, + Py_ssize_t attr_name_length); + +static PyObject * +_testcapi_dict_getitemstringref(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *obj; + const char *attr_name; + Py_ssize_t attr_name_length; + + if (!_PyArg_ParseStack(args, nargs, "Oz#:dict_getitemstringref", + &obj, &attr_name, &attr_name_length)) { + goto exit; + } + return_value = _testcapi_dict_getitemstringref_impl(module, obj, attr_name, attr_name_length); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_setitem__doc__, +"dict_setitem($module, mapping, key, value, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_SETITEM_METHODDEF \ + {"dict_setitem", _PyCFunction_CAST(_testcapi_dict_setitem), METH_FASTCALL, _testcapi_dict_setitem__doc__}, + +static PyObject * +_testcapi_dict_setitem_impl(PyObject *module, PyObject *mapping, + PyObject *key, PyObject *value); + +static PyObject * +_testcapi_dict_setitem(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *key; + PyObject *value; + + if (!_PyArg_CheckPositional("dict_setitem", nargs, 3, 3)) { + goto exit; + } + mapping = args[0]; + key = args[1]; + value = args[2]; + return_value = _testcapi_dict_setitem_impl(module, mapping, key, value); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_setitemstring__doc__, +"dict_setitemstring($module, mapping, key, value, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_SETITEMSTRING_METHODDEF \ + {"dict_setitemstring", _PyCFunction_CAST(_testcapi_dict_setitemstring), METH_FASTCALL, _testcapi_dict_setitemstring__doc__}, + +static PyObject * +_testcapi_dict_setitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length, + PyObject *value); + +static PyObject * +_testcapi_dict_setitemstring(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + const char *key; + Py_ssize_t key_length; + PyObject *value; + + if (!_PyArg_ParseStack(args, nargs, "Oz#O:dict_setitemstring", + &mapping, &key, &key_length, &value)) { + goto exit; + } + return_value = _testcapi_dict_setitemstring_impl(module, mapping, key, key_length, value); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_setdefault__doc__, +"dict_setdefault($module, mapping, key, defaultobj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_SETDEFAULT_METHODDEF \ + {"dict_setdefault", _PyCFunction_CAST(_testcapi_dict_setdefault), METH_FASTCALL, _testcapi_dict_setdefault__doc__}, + +static PyObject * +_testcapi_dict_setdefault_impl(PyObject *module, PyObject *mapping, + PyObject *key, PyObject *defaultobj); + +static PyObject * +_testcapi_dict_setdefault(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *key; + PyObject *defaultobj; + + if (!_PyArg_CheckPositional("dict_setdefault", nargs, 3, 3)) { + goto exit; + } + mapping = args[0]; + key = args[1]; + defaultobj = args[2]; + return_value = _testcapi_dict_setdefault_impl(module, mapping, key, defaultobj); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_delitem__doc__, +"dict_delitem($module, mapping, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_DELITEM_METHODDEF \ + {"dict_delitem", _PyCFunction_CAST(_testcapi_dict_delitem), METH_FASTCALL, _testcapi_dict_delitem__doc__}, + +static PyObject * +_testcapi_dict_delitem_impl(PyObject *module, PyObject *mapping, + PyObject *key); + +static PyObject * +_testcapi_dict_delitem(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *key; + + if (!_PyArg_CheckPositional("dict_delitem", nargs, 2, 2)) { + goto exit; + } + mapping = args[0]; + key = args[1]; + return_value = _testcapi_dict_delitem_impl(module, mapping, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_delitemstring__doc__, +"dict_delitemstring($module, mapping, key, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_DELITEMSTRING_METHODDEF \ + {"dict_delitemstring", _PyCFunction_CAST(_testcapi_dict_delitemstring), METH_FASTCALL, _testcapi_dict_delitemstring__doc__}, + +static PyObject * +_testcapi_dict_delitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length); + +static PyObject * +_testcapi_dict_delitemstring(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + const char *key; + Py_ssize_t key_length; + + if (!_PyArg_ParseStack(args, nargs, "Oz#:dict_delitemstring", + &mapping, &key, &key_length)) { + goto exit; + } + return_value = _testcapi_dict_delitemstring_impl(module, mapping, key, key_length); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_keys__doc__, +"dict_keys($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_KEYS_METHODDEF \ + {"dict_keys", (PyCFunction)_testcapi_dict_keys, METH_O, _testcapi_dict_keys__doc__}, + +PyDoc_STRVAR(_testcapi_dict_values__doc__, +"dict_values($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_VALUES_METHODDEF \ + {"dict_values", (PyCFunction)_testcapi_dict_values, METH_O, _testcapi_dict_values__doc__}, + +PyDoc_STRVAR(_testcapi_dict_items__doc__, +"dict_items($module, obj, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_ITEMS_METHODDEF \ + {"dict_items", (PyCFunction)_testcapi_dict_items, METH_O, _testcapi_dict_items__doc__}, + +PyDoc_STRVAR(_testcapi_dict_next__doc__, +"dict_next($module, mapping, pos, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_NEXT_METHODDEF \ + {"dict_next", _PyCFunction_CAST(_testcapi_dict_next), METH_FASTCALL, _testcapi_dict_next__doc__}, + +static PyObject * +_testcapi_dict_next_impl(PyObject *module, PyObject *mapping, Py_ssize_t pos); + +static PyObject * +_testcapi_dict_next(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + Py_ssize_t pos; + + if (!_PyArg_CheckPositional("dict_next", nargs, 2, 2)) { + goto exit; + } + mapping = args[0]; + { + Py_ssize_t ival = -1; + PyObject *iobj = _PyNumber_Index(args[1]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + pos = ival; + } + return_value = _testcapi_dict_next_impl(module, mapping, pos); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_merge__doc__, +"dict_merge($module, mapping, mapping2, override, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_MERGE_METHODDEF \ + {"dict_merge", _PyCFunction_CAST(_testcapi_dict_merge), METH_FASTCALL, _testcapi_dict_merge__doc__}, + +static PyObject * +_testcapi_dict_merge_impl(PyObject *module, PyObject *mapping, + PyObject *mapping2, int override); + +static PyObject * +_testcapi_dict_merge(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *mapping2; + int override; + + if (!_PyArg_CheckPositional("dict_merge", nargs, 3, 3)) { + goto exit; + } + mapping = args[0]; + mapping2 = args[1]; + override = _PyLong_AsInt(args[2]); + if (override == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _testcapi_dict_merge_impl(module, mapping, mapping2, override); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_update__doc__, +"dict_update($module, mapping, mapping2, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_UPDATE_METHODDEF \ + {"dict_update", _PyCFunction_CAST(_testcapi_dict_update), METH_FASTCALL, _testcapi_dict_update__doc__}, + +static PyObject * +_testcapi_dict_update_impl(PyObject *module, PyObject *mapping, + PyObject *mapping2); + +static PyObject * +_testcapi_dict_update(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *mapping2; + + if (!_PyArg_CheckPositional("dict_update", nargs, 2, 2)) { + goto exit; + } + mapping = args[0]; + mapping2 = args[1]; + return_value = _testcapi_dict_update_impl(module, mapping, mapping2); + +exit: + return return_value; +} + +PyDoc_STRVAR(_testcapi_dict_mergefromseq2__doc__, +"dict_mergefromseq2($module, mapping, seq, override, /)\n" +"--\n" +"\n"); + +#define _TESTCAPI_DICT_MERGEFROMSEQ2_METHODDEF \ + {"dict_mergefromseq2", _PyCFunction_CAST(_testcapi_dict_mergefromseq2), METH_FASTCALL, _testcapi_dict_mergefromseq2__doc__}, + +static PyObject * +_testcapi_dict_mergefromseq2_impl(PyObject *module, PyObject *mapping, + PyObject *seq, int override); + +static PyObject * +_testcapi_dict_mergefromseq2(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *seq; + int override; + + if (!_PyArg_CheckPositional("dict_mergefromseq2", nargs, 3, 3)) { + goto exit; + } + mapping = args[0]; + seq = args[1]; + override = _PyLong_AsInt(args[2]); + if (override == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _testcapi_dict_mergefromseq2_impl(module, mapping, seq, override); + +exit: + return return_value; +} +/*[clinic end generated code: output=e3085a44dfe3d4e7 input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/dict.c b/Modules/_testcapi/dict.c index b1dfcf4c707da7..878f079a743696 100644 --- a/Modules/_testcapi/dict.c +++ b/Modules/_testcapi/dict.c @@ -1,6 +1,13 @@ #include // ptrdiff_t #include "parts.h" +#include "clinic/dict.c.h" + + +/*[clinic input] +module _testcapi +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/ #define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0); @@ -21,73 +28,137 @@ } while (0) +/*[clinic input] +_testcapi.dict_check + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_check(PyObject *self, PyObject *obj) +_testcapi_dict_check(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=db5de1afc9b8e1e5 input=099d8ccf1c8e38b8]*/ { NULLABLE(obj); return PyLong_FromLong(PyDict_Check(obj)); } + +/*[clinic input] +_testcapi.dict_checkexact + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_checkexact(PyObject *self, PyObject *obj) +_testcapi_dict_checkexact(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=a53a2f2b969ce16c input=3b06ddc29bf6276f]*/ { NULLABLE(obj); return PyLong_FromLong(PyDict_CheckExact(obj)); } + +/*[clinic input] +_testcapi.dict_new +[clinic start generated code]*/ + static PyObject * -dict_new(PyObject *self, PyObject *Py_UNUSED(ignored)) +_testcapi_dict_new_impl(PyObject *module) +/*[clinic end generated code: output=22fafce00b067bd1 input=b4b463dfb073824f]*/ { return PyDict_New(); } + +/*[clinic input] +_testcapi.dictproxy_new + obj: object + / +[clinic start generated code]*/ + static PyObject * -dictproxy_new(PyObject *self, PyObject *obj) +_testcapi_dictproxy_new(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=f1cd75e4f9772ffb input=19b081e487df3067]*/ { NULLABLE(obj); return PyDictProxy_New(obj); } + +/*[clinic input] +_testcapi.dict_clear + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_clear(PyObject *self, PyObject *obj) +_testcapi_dict_clear(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=f3ae3c6547b16dad input=bb427bbf5d143860]*/ { PyDict_Clear(obj); Py_RETURN_NONE; } + +/*[clinic input] +_testcapi.dict_copy + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_copy(PyObject *self, PyObject *obj) +_testcapi_dict_copy(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=b6b7df7c11cb1a4c input=3e8300ceb63995f0]*/ { NULLABLE(obj); return PyDict_Copy(obj); } + +/*[clinic input] +_testcapi.dict_contains + obj: object + key: object + / +[clinic start generated code]*/ + static PyObject * -dict_contains(PyObject *self, PyObject *args) +_testcapi_dict_contains_impl(PyObject *module, PyObject *obj, PyObject *key) +/*[clinic end generated code: output=d29efe25b3d9cb07 input=581c486b6c9502a5]*/ { - PyObject *obj, *key; - if (!PyArg_ParseTuple(args, "OO", &obj, &key)) { - return NULL; - } NULLABLE(obj); NULLABLE(key); RETURN_INT(PyDict_Contains(obj, key)); } + +/*[clinic input] +_testcapi.dict_size + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_size(PyObject *self, PyObject *obj) +_testcapi_dict_size(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=3ef99b229e9c3b93 input=d1a87dff92a98060]*/ { NULLABLE(obj); RETURN_SIZE(PyDict_Size(obj)); } + +/*[clinic input] +_testcapi.dict_getitem + mapping: object + key: object + / +[clinic start generated code]*/ + static PyObject * -dict_getitem(PyObject *self, PyObject *args) +_testcapi_dict_getitem_impl(PyObject *module, PyObject *mapping, + PyObject *key) +/*[clinic end generated code: output=8656b2737d0ad225 input=c4b843cc6a837905]*/ { - PyObject *mapping, *key; - if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) { - return NULL; - } NULLABLE(mapping); NULLABLE(key); PyObject *value = PyDict_GetItem(mapping, key); @@ -100,15 +171,19 @@ dict_getitem(PyObject *self, PyObject *args) return Py_NewRef(value); } + +/*[clinic input] +_testcapi.dict_getitemstring + mapping: object + key: str(accept={robuffer, str, NoneType}, zeroes=True) + / +[clinic start generated code]*/ + static PyObject * -dict_getitemstring(PyObject *self, PyObject *args) +_testcapi_dict_getitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length) +/*[clinic end generated code: output=13ef172dc70898df input=fafe3be7e5953dcd]*/ { - 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) { @@ -120,13 +195,19 @@ dict_getitemstring(PyObject *self, PyObject *args) return Py_NewRef(value); } + +/*[clinic input] +_testcapi.dict_getitemwitherror + mapping: object + key: object + / +[clinic start generated code]*/ + static PyObject * -dict_getitemwitherror(PyObject *self, PyObject *args) +_testcapi_dict_getitemwitherror_impl(PyObject *module, PyObject *mapping, + PyObject *key) +/*[clinic end generated code: output=8673d9881daf90cf input=3967cd021c1c9445]*/ { - PyObject *mapping, *key; - if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) { - return NULL; - } NULLABLE(mapping); NULLABLE(key); PyObject *value = PyDict_GetItemWithError(mapping, key); @@ -140,13 +221,19 @@ dict_getitemwitherror(PyObject *self, PyObject *args) } +/*[clinic input] +_testcapi.dict_getitemref + obj: object + attr_name: object + / +[clinic start generated code]*/ + static PyObject * -dict_getitemref(PyObject *self, PyObject *args) +_testcapi_dict_getitemref_impl(PyObject *module, PyObject *obj, + PyObject *attr_name) +/*[clinic end generated code: output=b0a392407285a25f input=d7dff7f43142387d]*/ { - PyObject *obj, *attr_name, *value; - if (!PyArg_ParseTuple(args, "OO", &obj, &attr_name)) { - return NULL; - } + PyObject *value; NULLABLE(obj); NULLABLE(attr_name); @@ -165,15 +252,22 @@ dict_getitemref(PyObject *self, PyObject *args) } } + +/*[clinic input] +_testcapi.dict_getitemstringref + obj: object + attr_name: str(accept={robuffer, str, NoneType}, zeroes=True) + / +[clinic start generated code]*/ + static PyObject * -dict_getitemstringref(PyObject *self, PyObject *args) +_testcapi_dict_getitemstringref_impl(PyObject *module, PyObject *obj, + const char *attr_name, + Py_ssize_t attr_name_length) +/*[clinic end generated code: output=7b77e8da44d9d1dc input=103eee65f8f9841c]*/ { - PyObject *obj, *value; - const char *attr_name; + PyObject *value; Py_ssize_t size; - if (!PyArg_ParseTuple(args, "Oz#", &obj, &attr_name, &size)) { - return NULL; - } NULLABLE(obj); switch (PyDict_GetItemStringRef(obj, attr_name, &value)) { @@ -191,100 +285,159 @@ dict_getitemstringref(PyObject *self, PyObject *args) } } + +/*[clinic input] +_testcapi.dict_setitem + mapping: object + key: object + value: object + / +[clinic start generated code]*/ + static PyObject * -dict_setitem(PyObject *self, PyObject *args) +_testcapi_dict_setitem_impl(PyObject *module, PyObject *mapping, + PyObject *key, PyObject *value) +/*[clinic end generated code: output=0870405a87c747cf input=b99779c745fd9397]*/ { - 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)); } + +/*[clinic input] +_testcapi.dict_setitemstring + mapping: object + key: str(accept={robuffer, str, NoneType}, zeroes=True) + value: object + / +[clinic start generated code]*/ + static PyObject * -dict_setitemstring(PyObject *self, PyObject *args) +_testcapi_dict_setitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length, + PyObject *value) +/*[clinic end generated code: output=c684aeab1ee79d93 input=f5a6618dac763fba]*/ { - 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)); } + +/*[clinic input] +_testcapi.dict_setdefault + mapping: object + key: object + defaultobj: object + / +[clinic start generated code]*/ + static PyObject * -dict_setdefault(PyObject *self, PyObject *args) +_testcapi_dict_setdefault_impl(PyObject *module, PyObject *mapping, + PyObject *key, PyObject *defaultobj) +/*[clinic end generated code: output=59c54ee6f6b5fec6 input=17ec3f91916e0537]*/ { - PyObject *mapping, *key, *defaultobj; - if (!PyArg_ParseTuple(args, "OOO", &mapping, &key, &defaultobj)) { - return NULL; - } NULLABLE(mapping); NULLABLE(key); NULLABLE(defaultobj); return PyDict_SetDefault(mapping, key, defaultobj); } + +/*[clinic input] +_testcapi.dict_delitem + mapping: object + key: object + / +[clinic start generated code]*/ + static PyObject * -dict_delitem(PyObject *self, PyObject *args) +_testcapi_dict_delitem_impl(PyObject *module, PyObject *mapping, + PyObject *key) +/*[clinic end generated code: output=9fbff076cb508138 input=a55daafa5802bbb6]*/ { - PyObject *mapping, *key; - if (!PyArg_ParseTuple(args, "OO", &mapping, &key)) { - return NULL; - } NULLABLE(mapping); NULLABLE(key); RETURN_INT(PyDict_DelItem(mapping, key)); } + +/*[clinic input] +_testcapi.dict_delitemstring + mapping: object + key: str(accept={robuffer, str, NoneType}, zeroes=True) + / +[clinic start generated code]*/ + static PyObject * -dict_delitemstring(PyObject *self, PyObject *args) +_testcapi_dict_delitemstring_impl(PyObject *module, PyObject *mapping, + const char *key, Py_ssize_t key_length) +/*[clinic end generated code: output=9de0731724962620 input=296c0dab58190e6a]*/ { - 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)); } + +/*[clinic input] +_testcapi.dict_keys + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_keys(PyObject *self, PyObject *obj) +_testcapi_dict_keys(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=00e71422734d046c input=e5e245988a0269f1]*/ { NULLABLE(obj); return PyDict_Keys(obj); } + +/*[clinic input] +_testcapi.dict_values + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_values(PyObject *self, PyObject *obj) +_testcapi_dict_values(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=4914dc42ae946905 input=ae6cad73caa19486]*/ { NULLABLE(obj); return PyDict_Values(obj); } + +/*[clinic input] +_testcapi.dict_items + obj: object + / +[clinic start generated code]*/ + static PyObject * -dict_items(PyObject *self, PyObject *obj) +_testcapi_dict_items(PyObject *module, PyObject *obj) +/*[clinic end generated code: output=f9ddf49667eb4de7 input=d064428cb12cbbf6]*/ { NULLABLE(obj); return PyDict_Items(obj); } + +/*[clinic input] +_testcapi.dict_next + mapping: object + pos: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -dict_next(PyObject *self, PyObject *args) +_testcapi_dict_next_impl(PyObject *module, PyObject *mapping, Py_ssize_t pos) +/*[clinic end generated code: output=354ca34afaaf45d8 input=7decf2072b219a1d]*/ { - PyObject *mapping, *key, *value; - Py_ssize_t pos; - if (!PyArg_ParseTuple(args, "On", &mapping, &pos)) { - return NULL; - } + PyObject *key, *value; NULLABLE(mapping); int rc = PyDict_Next(mapping, &pos, &key, &value); if (rc != 0) { @@ -296,39 +449,57 @@ dict_next(PyObject *self, PyObject *args) Py_RETURN_NONE; } + +/*[clinic input] +_testcapi.dict_merge + mapping: object + mapping2: object + override: int + / +[clinic start generated code]*/ + static PyObject * -dict_merge(PyObject *self, PyObject *args) +_testcapi_dict_merge_impl(PyObject *module, PyObject *mapping, + PyObject *mapping2, int override) +/*[clinic end generated code: output=0ccb5ae3aa8a8439 input=aad455e20a680da0]*/ { - 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)); } + +/*[clinic input] +_testcapi.dict_update + mapping: object + mapping2: object + / +[clinic start generated code]*/ + static PyObject * -dict_update(PyObject *self, PyObject *args) +_testcapi_dict_update_impl(PyObject *module, PyObject *mapping, + PyObject *mapping2) +/*[clinic end generated code: output=03f5749b47b5a702 input=d9c80387e8370633]*/ { - PyObject *mapping, *mapping2; - if (!PyArg_ParseTuple(args, "OO", &mapping, &mapping2)) { - return NULL; - } NULLABLE(mapping); NULLABLE(mapping2); RETURN_INT(PyDict_Update(mapping, mapping2)); } + +/*[clinic input] +_testcapi.dict_mergefromseq2 + mapping: object + seq: object + override: int + / +[clinic start generated code]*/ + static PyObject * -dict_mergefromseq2(PyObject *self, PyObject *args) +_testcapi_dict_mergefromseq2_impl(PyObject *module, PyObject *mapping, + PyObject *seq, int override) +/*[clinic end generated code: output=ed47a724c1b40d8e input=ebd3ffc60eb3470c]*/ { - 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)); @@ -336,31 +507,31 @@ dict_mergefromseq2(PyObject *self, PyObject *args) 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_getitemref", dict_getitemref, METH_VARARGS}, - {"dict_getitemstringref", dict_getitemstringref, 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_setdefault", dict_setdefault, 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}, + _TESTCAPI_DICT_CHECK_METHODDEF + _TESTCAPI_DICT_CHECKEXACT_METHODDEF + _TESTCAPI_DICT_NEW_METHODDEF + _TESTCAPI_DICTPROXY_NEW_METHODDEF + _TESTCAPI_DICT_CLEAR_METHODDEF + _TESTCAPI_DICT_COPY_METHODDEF + _TESTCAPI_DICT_SIZE_METHODDEF + _TESTCAPI_DICT_GETITEM_METHODDEF + _TESTCAPI_DICT_GETITEMWITHERROR_METHODDEF + _TESTCAPI_DICT_GETITEMSTRING_METHODDEF + _TESTCAPI_DICT_GETITEMREF_METHODDEF + _TESTCAPI_DICT_GETITEMSTRINGREF_METHODDEF + _TESTCAPI_DICT_CONTAINS_METHODDEF + _TESTCAPI_DICT_SETITEM_METHODDEF + _TESTCAPI_DICT_SETITEMSTRING_METHODDEF + _TESTCAPI_DICT_DELITEM_METHODDEF + _TESTCAPI_DICT_DELITEMSTRING_METHODDEF + _TESTCAPI_DICT_SETDEFAULT_METHODDEF + _TESTCAPI_DICT_KEYS_METHODDEF + _TESTCAPI_DICT_VALUES_METHODDEF + _TESTCAPI_DICT_ITEMS_METHODDEF + _TESTCAPI_DICT_NEXT_METHODDEF + _TESTCAPI_DICT_MERGE_METHODDEF + _TESTCAPI_DICT_UPDATE_METHODDEF + _TESTCAPI_DICT_MERGEFROMSEQ2_METHODDEF {NULL}, };