]> granicus.if.org Git - python/commitdiff
Add PyDict_Copy() function to C API for dicts. It returns a new
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 30 Mar 2000 22:27:31 +0000 (22:27 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 30 Mar 2000 22:27:31 +0000 (22:27 +0000)
dictionary that contains the same key/value pairs as p.

Doc/api/api.tex
Doc/api/refcounts.dat
Include/dictobject.h
Objects/dictobject.c

index d2e6a44e522c91ffb0cabf6cc6599646b76f9f94..d67085abaf9046e8a51ceec1a378a84201c9d601 100644 (file)
@@ -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}
index 3114e96a5c20689c31233ff86438eed475eccbfa..53eb006e2c44f5a1ad2b41e5520b8240801b49a0 100644 (file)
@@ -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::
index 1f1fdde7c9dc2250b322af8a2fb05bd1d9fb4173..acffb41042483d82f8a2d81d697a1dd03b484d62 100644 (file)
@@ -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));
index ea32e235b496ba3bbceca9159e879ce6cd29b8e9..beab457462eed8bba93209be564efacd1c14596d 100644 (file)
@@ -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;