summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-03-30 22:27:31 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-03-30 22:27:31 (GMT)
commita12c7a762091805db6b6479108951dc2fcb95dde (patch)
tree15d23befe65d284484cb9549b49b8710b99ff225
parentc06653f56708084fc50bdad6c6301d9bc49c6af1 (diff)
downloadcpython-a12c7a762091805db6b6479108951dc2fcb95dde.zip
cpython-a12c7a762091805db6b6479108951dc2fcb95dde.tar.gz
cpython-a12c7a762091805db6b6479108951dc2fcb95dde.tar.bz2
Add PyDict_Copy() function to C API for dicts. It returns a new
dictionary that contains the same key/value pairs as p.
-rw-r--r--Doc/api/api.tex4
-rw-r--r--Doc/api/refcounts.dat5
-rw-r--r--Include/dictobject.h2
-rw-r--r--Objects/dictobject.c16
4 files changed, 25 insertions, 2 deletions
diff --git a/Doc/api/api.tex b/Doc/api/api.tex
index d2e6a44..d67085a 100644
--- a/Doc/api/api.tex
+++ b/Doc/api/api.tex
@@ -2081,6 +2081,10 @@ Returns true if its argument is a \ctype{PyDictObject}.
Returns a new empty dictionary.
\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}
Empties an existing dictionary of all key/value pairs.
\end{cfuncdesc}
diff --git a/Doc/api/refcounts.dat b/Doc/api/refcounts.dat
index 3114e96..53eb006 100644
--- a/Doc/api/refcounts.dat
+++ b/Doc/api/refcounts.dat
@@ -1,4 +1,4 @@
-# Created by kip Montanaro <skip@mojam.com>.
+# Created by Skip Montanaro <skip@mojam.com>.
# Format:
# function ':' type ':' [param name] ':' [refcount effect] ':' [comment]
@@ -88,6 +88,9 @@ PyDict_Keys:PyDictObject*:p:0:
PyDict_New:PyObject*::+1:
+PyDict_Copy:PyObject*::+1:
+PyDict_Copy:PyObject*:p:0:
+
PyDict_Next:int:::
PyDict_Next:PyDictObject*:p:0:
PyDict_Next:int:ppos::
diff --git a/Include/dictobject.h b/Include/dictobject.h
index 1f1fdde..acffb41 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -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_Items 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(int) PyDict_SetItemString Py_PROTO((PyObject *dp, char *key, PyObject *item));
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index ea32e23..beab457 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -738,11 +738,25 @@ dict_copy(mp, args)
register dictobject *mp;
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;
dictobject *copy;
dictentry *entry;
- if (!PyArg_Parse(args, ""))
+
+ if (o == NULL || !PyDict_Check(o)) {
+ PyErr_BadInternalCall();
return NULL;
+ }
+ mp = (dictobject *)o;
copy = (dictobject *)PyDict_New();
if (copy == NULL)
return NULL;