Add PyDict_Copy() function to C API for dicts. It returns a new
dictionary that contains the same key/value pairs as p.
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 @@
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;