mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Add PyDict_Copy() function to C API for dicts. It returns a new
dictionary that contains the same key/value pairs as p.
This commit is contained in:
parent
c06653f567
commit
a12c7a7620
4 changed files with 25 additions and 2 deletions
|
@ -2081,6 +2081,10 @@ Returns true if its argument is a \ctype{PyDictObject}.
|
||||||
Returns a new empty dictionary.
|
Returns a new empty dictionary.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{PyObject*}{PyDict_Copy}{PyObject *p}
|
||||||
|
Returns a new dictionary that contains the same key/value pairs as p.
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{void}{PyDict_Clear}{PyDictObject *p}
|
\begin{cfuncdesc}{void}{PyDict_Clear}{PyDictObject *p}
|
||||||
Empties an existing dictionary of all key/value pairs.
|
Empties an existing dictionary of all key/value pairs.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Created by kip Montanaro <skip@mojam.com>.
|
# Created by Skip Montanaro <skip@mojam.com>.
|
||||||
|
|
||||||
# Format:
|
# Format:
|
||||||
# function ':' type ':' [param name] ':' [refcount effect] ':' [comment]
|
# function ':' type ':' [param name] ':' [refcount effect] ':' [comment]
|
||||||
|
@ -88,6 +88,9 @@ PyDict_Keys:PyDictObject*:p:0:
|
||||||
|
|
||||||
PyDict_New:PyObject*::+1:
|
PyDict_New:PyObject*::+1:
|
||||||
|
|
||||||
|
PyDict_Copy:PyObject*::+1:
|
||||||
|
PyDict_Copy:PyObject*:p:0:
|
||||||
|
|
||||||
PyDict_Next:int:::
|
PyDict_Next:int:::
|
||||||
PyDict_Next:PyDictObject*:p:0:
|
PyDict_Next:PyDictObject*:p:0:
|
||||||
PyDict_Next:int:ppos::
|
PyDict_Next:int:ppos::
|
||||||
|
|
|
@ -52,6 +52,8 @@ extern DL_IMPORT(PyObject *) PyDict_Keys Py_PROTO((PyObject *mp));
|
||||||
extern DL_IMPORT(PyObject *) PyDict_Values Py_PROTO((PyObject *mp));
|
extern DL_IMPORT(PyObject *) PyDict_Values Py_PROTO((PyObject *mp));
|
||||||
extern DL_IMPORT(PyObject *) PyDict_Items Py_PROTO((PyObject *mp));
|
extern DL_IMPORT(PyObject *) PyDict_Items Py_PROTO((PyObject *mp));
|
||||||
extern DL_IMPORT(int) PyDict_Size Py_PROTO((PyObject *mp));
|
extern DL_IMPORT(int) PyDict_Size Py_PROTO((PyObject *mp));
|
||||||
|
extern DL_IMPORT(PyObject *) PyDict_Copy Py_PROTO((PyObject *mp));
|
||||||
|
|
||||||
|
|
||||||
extern DL_IMPORT(PyObject *) PyDict_GetItemString Py_PROTO((PyObject *dp, char *key));
|
extern DL_IMPORT(PyObject *) PyDict_GetItemString Py_PROTO((PyObject *dp, char *key));
|
||||||
extern DL_IMPORT(int) PyDict_SetItemString Py_PROTO((PyObject *dp, char *key, PyObject *item));
|
extern DL_IMPORT(int) PyDict_SetItemString Py_PROTO((PyObject *dp, char *key, PyObject *item));
|
||||||
|
|
|
@ -738,11 +738,25 @@ dict_copy(mp, args)
|
||||||
register dictobject *mp;
|
register dictobject *mp;
|
||||||
PyObject *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
|
if (!PyArg_Parse(args, ""))
|
||||||
|
return NULL;
|
||||||
|
return PyDict_Copy((PyObject*)mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
PyDict_Copy(o)
|
||||||
|
PyObject *o;
|
||||||
|
{
|
||||||
|
register dictobject *mp;
|
||||||
register int i;
|
register int i;
|
||||||
dictobject *copy;
|
dictobject *copy;
|
||||||
dictentry *entry;
|
dictentry *entry;
|
||||||
if (!PyArg_Parse(args, ""))
|
|
||||||
|
if (o == NULL || !PyDict_Check(o)) {
|
||||||
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
mp = (dictobject *)o;
|
||||||
copy = (dictobject *)PyDict_New();
|
copy = (dictobject *)PyDict_New();
|
||||||
if (copy == NULL)
|
if (copy == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue