Index: dictobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v retrieving revision 2.151 diff -c -r2.151 dictobject.c *** dictobject.c 17 Feb 2004 20:10:11 -0000 2.151 --- dictobject.c 29 Feb 2004 22:30:53 -0000 *************** *** 1029,1038 **** return NULL; } static PyObject * ! dict_update(PyObject *mp, PyObject *other) { ! if (PyDict_Update(mp, other) < 0) return NULL; Py_INCREF(Py_None); return Py_None; --- 1029,1058 ---- return NULL; } + static int + dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methname) + { + PyObject *arg = NULL; + int result = 0; + + if (!PyArg_UnpackTuple(args, methname, 0, 1, &arg)) + result = -1; + + else if (arg != NULL) { + if (PyObject_HasAttrString(arg, "keys")) + result = PyDict_Merge(self, arg, 1); + else + result = PyDict_MergeFromSeq2(self, arg, 1); + } + if (result == 0 && kwds != NULL) + result = PyDict_Merge(self, kwds, 1); + return result; + } + static PyObject * ! dict_update(PyObject *self, PyObject *args, PyObject *kwds) { ! if (dict_update_common(self, args, kwds, "update") == -1) return NULL; Py_INCREF(Py_None); return Py_None; *************** *** 1806,1812 **** items__doc__}, {"values", (PyCFunction)dict_values, METH_NOARGS, values__doc__}, ! {"update", (PyCFunction)dict_update, METH_O, update__doc__}, {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS | METH_CLASS, fromkeys__doc__}, --- 1826,1832 ---- items__doc__}, {"values", (PyCFunction)dict_values, METH_NOARGS, values__doc__}, ! {"update", (PyCFunction)dict_update, METH_VARARGS | METH_KEYWORDS, update__doc__}, {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS | METH_CLASS, fromkeys__doc__}, *************** *** 1875,1895 **** static int dict_init(PyObject *self, PyObject *args, PyObject *kwds) { ! PyObject *arg = NULL; ! int result = 0; ! ! if (!PyArg_UnpackTuple(args, "dict", 0, 1, &arg)) ! result = -1; ! ! else if (arg != NULL) { ! if (PyObject_HasAttrString(arg, "keys")) ! result = PyDict_Merge(self, arg, 1); ! else ! result = PyDict_MergeFromSeq2(self, arg, 1); ! } ! if (result == 0 && kwds != NULL) ! result = PyDict_Merge(self, kwds, 1); ! return result; } static long --- 1895,1901 ---- static int dict_init(PyObject *self, PyObject *args, PyObject *kwds) { ! return dict_update_common(self, args, kwds, "dict"); } static long