2015-04-03 17:53:51 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2024-02-06 18:03:43 -04:00
|
|
|
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
|
|
|
|
|
2015-04-03 17:53:51 -03:00
|
|
|
PyDoc_STRVAR(dict_fromkeys__doc__,
|
|
|
|
"fromkeys($type, iterable, value=None, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
2017-01-24 18:30:04 -04:00
|
|
|
"Create a new dictionary with keys from iterable and values set to value.");
|
2015-04-03 17:53:51 -03:00
|
|
|
|
|
|
|
#define DICT_FROMKEYS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"fromkeys", _PyCFunction_CAST(dict_fromkeys), METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__},
|
2015-04-03 17:53:51 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value);
|
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
|
2015-04-03 17:53:51 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *iterable;
|
|
|
|
PyObject *value = Py_None;
|
|
|
|
|
2019-01-11 12:01:42 -04:00
|
|
|
if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) {
|
2017-01-16 21:21:47 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 12:01:42 -04:00
|
|
|
iterable = args[0];
|
|
|
|
if (nargs < 2) {
|
|
|
|
goto skip_optional;
|
|
|
|
}
|
|
|
|
value = args[1];
|
|
|
|
skip_optional:
|
2015-04-03 17:53:51 -03:00
|
|
|
return_value = dict_fromkeys_impl(type, iterable, value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-01-23 18:10:04 -04:00
|
|
|
PyDoc_STRVAR(dict_copy__doc__,
|
|
|
|
"copy($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a shallow copy of the dict.");
|
|
|
|
|
|
|
|
#define DICT_COPY_METHODDEF \
|
|
|
|
{"copy", (PyCFunction)dict_copy, METH_NOARGS, dict_copy__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_copy_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_copy(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict_copy_impl(self);
|
|
|
|
}
|
|
|
|
|
2015-04-03 17:53:51 -03:00
|
|
|
PyDoc_STRVAR(dict___contains____doc__,
|
|
|
|
"__contains__($self, key, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
2017-02-04 02:05:07 -04:00
|
|
|
"True if the dictionary has the specified key, else False.");
|
2015-04-03 17:53:51 -03:00
|
|
|
|
|
|
|
#define DICT___CONTAINS___METHODDEF \
|
|
|
|
{"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_get__doc__,
|
|
|
|
"get($self, key, default=None, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
2017-01-24 18:30:04 -04:00
|
|
|
"Return the value for key if key is in the dictionary, else default.");
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
#define DICT_GET_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"get", _PyCFunction_CAST(dict_get), METH_FASTCALL, dict_get__doc__},
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-01-19 13:00:30 -04:00
|
|
|
dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
|
2017-01-19 07:37:13 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *key;
|
2017-01-19 13:00:30 -04:00
|
|
|
PyObject *default_value = Py_None;
|
2017-01-19 07:37:13 -04:00
|
|
|
|
2019-01-11 12:01:42 -04:00
|
|
|
if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
|
2017-01-19 07:37:13 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 12:01:42 -04:00
|
|
|
key = args[0];
|
|
|
|
if (nargs < 2) {
|
|
|
|
goto skip_optional;
|
|
|
|
}
|
|
|
|
default_value = args[1];
|
|
|
|
skip_optional:
|
2024-02-06 18:03:43 -04:00
|
|
|
Py_BEGIN_CRITICAL_SECTION(self);
|
2017-01-19 13:00:30 -04:00
|
|
|
return_value = dict_get_impl(self, key, default_value);
|
2024-02-06 18:03:43 -04:00
|
|
|
Py_END_CRITICAL_SECTION();
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_setdefault__doc__,
|
|
|
|
"setdefault($self, key, default=None, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
2017-01-24 18:30:04 -04:00
|
|
|
"Insert key with a value of default if key is not in the dictionary.\n"
|
|
|
|
"\n"
|
|
|
|
"Return the value for key if key is in the dictionary, else default.");
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
#define DICT_SETDEFAULT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"setdefault", _PyCFunction_CAST(dict_setdefault), METH_FASTCALL, dict_setdefault__doc__},
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-01-19 13:00:30 -04:00
|
|
|
dict_setdefault_impl(PyDictObject *self, PyObject *key,
|
|
|
|
PyObject *default_value);
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
|
2017-01-19 07:37:13 -04:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *key;
|
2017-01-19 13:00:30 -04:00
|
|
|
PyObject *default_value = Py_None;
|
2017-01-19 07:37:13 -04:00
|
|
|
|
2019-01-11 12:01:42 -04:00
|
|
|
if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
|
2017-01-19 07:37:13 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 12:01:42 -04:00
|
|
|
key = args[0];
|
|
|
|
if (nargs < 2) {
|
|
|
|
goto skip_optional;
|
|
|
|
}
|
|
|
|
default_value = args[1];
|
|
|
|
skip_optional:
|
2024-02-06 18:03:43 -04:00
|
|
|
Py_BEGIN_CRITICAL_SECTION(self);
|
2017-01-19 13:00:30 -04:00
|
|
|
return_value = dict_setdefault_impl(self, key, default_value);
|
2024-02-06 18:03:43 -04:00
|
|
|
Py_END_CRITICAL_SECTION();
|
2017-01-19 07:37:13 -04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2018-11-05 20:38:54 -04:00
|
|
|
|
2024-01-23 18:10:04 -04:00
|
|
|
PyDoc_STRVAR(dict_clear__doc__,
|
|
|
|
"clear($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Remove all items from the dict.");
|
|
|
|
|
|
|
|
#define DICT_CLEAR_METHODDEF \
|
|
|
|
{"clear", (PyCFunction)dict_clear, METH_NOARGS, dict_clear__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_clear_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_clear(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict_clear_impl(self);
|
|
|
|
}
|
|
|
|
|
2019-04-12 04:11:28 -03:00
|
|
|
PyDoc_STRVAR(dict_pop__doc__,
|
2019-09-14 06:24:05 -03:00
|
|
|
"pop($self, key, default=<unrepresentable>, /)\n"
|
2019-04-12 04:11:28 -03:00
|
|
|
"--\n"
|
|
|
|
"\n"
|
2019-09-14 06:24:05 -03:00
|
|
|
"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n"
|
2019-04-12 04:11:28 -03:00
|
|
|
"\n"
|
2020-07-19 03:18:55 -03:00
|
|
|
"If the key is not found, return the default if given; otherwise,\n"
|
|
|
|
"raise a KeyError.");
|
2019-04-12 04:11:28 -03:00
|
|
|
|
|
|
|
#define DICT_POP_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"pop", _PyCFunction_CAST(dict_pop), METH_FASTCALL, dict_pop__doc__},
|
2019-04-12 04:11:28 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *key;
|
|
|
|
PyObject *default_value = NULL;
|
|
|
|
|
|
|
|
if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
key = args[0];
|
|
|
|
if (nargs < 2) {
|
|
|
|
goto skip_optional;
|
|
|
|
}
|
|
|
|
default_value = args[1];
|
|
|
|
skip_optional:
|
|
|
|
return_value = dict_pop_impl(self, key, default_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_popitem__doc__,
|
|
|
|
"popitem($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Remove and return a (key, value) pair as a 2-tuple.\n"
|
|
|
|
"\n"
|
|
|
|
"Pairs are returned in LIFO (last-in, first-out) order.\n"
|
|
|
|
"Raises KeyError if the dict is empty.");
|
|
|
|
|
|
|
|
#define DICT_POPITEM_METHODDEF \
|
|
|
|
{"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_popitem_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
2024-02-06 18:03:43 -04:00
|
|
|
PyObject *return_value = NULL;
|
|
|
|
|
|
|
|
Py_BEGIN_CRITICAL_SECTION(self);
|
|
|
|
return_value = dict_popitem_impl(self);
|
|
|
|
Py_END_CRITICAL_SECTION();
|
|
|
|
|
|
|
|
return return_value;
|
2019-04-12 04:11:28 -03:00
|
|
|
}
|
|
|
|
|
2024-01-23 18:10:04 -04:00
|
|
|
PyDoc_STRVAR(dict___sizeof____doc__,
|
|
|
|
"__sizeof__($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the size of the dict in memory, in bytes.");
|
|
|
|
|
|
|
|
#define DICT___SIZEOF___METHODDEF \
|
|
|
|
{"__sizeof__", (PyCFunction)dict___sizeof__, METH_NOARGS, dict___sizeof____doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict___sizeof___impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict___sizeof__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict___sizeof___impl(self);
|
|
|
|
}
|
|
|
|
|
2018-11-05 20:38:54 -04:00
|
|
|
PyDoc_STRVAR(dict___reversed____doc__,
|
|
|
|
"__reversed__($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a reverse iterator over the dict keys.");
|
|
|
|
|
|
|
|
#define DICT___REVERSED___METHODDEF \
|
|
|
|
{"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict___reversed___impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict___reversed___impl(self);
|
|
|
|
}
|
2024-01-23 18:10:04 -04:00
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_keys__doc__,
|
|
|
|
"keys($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a set-like object providing a view on the dict\'s keys.");
|
|
|
|
|
|
|
|
#define DICT_KEYS_METHODDEF \
|
|
|
|
{"keys", (PyCFunction)dict_keys, METH_NOARGS, dict_keys__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_keys_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_keys(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict_keys_impl(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_items__doc__,
|
|
|
|
"items($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a set-like object providing a view on the dict\'s items.");
|
|
|
|
|
|
|
|
#define DICT_ITEMS_METHODDEF \
|
|
|
|
{"items", (PyCFunction)dict_items, METH_NOARGS, dict_items__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_items_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_items(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict_items_impl(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(dict_values__doc__,
|
|
|
|
"values($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return an object providing a view on the dict\'s values.");
|
|
|
|
|
|
|
|
#define DICT_VALUES_METHODDEF \
|
|
|
|
{"values", (PyCFunction)dict_values, METH_NOARGS, dict_values__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_values_impl(PyDictObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
dict_values(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return dict_values_impl(self);
|
|
|
|
}
|
2024-02-20 21:08:14 -04:00
|
|
|
/*[clinic end generated code: output=f3dd5f3fb8122aef input=a9049054013a1b77]*/
|