[Python-checkins] CVS: python/dist/src/Python ceval.c,2.214,2.215

Fred L. Drake python-dev@python.org
Thu, 04 Jan 2001 14:33:04 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv5906/Python

Modified Files:
	ceval.c 
Log Message:

When a PyCFunction that takes only positional parameters is called with
an empty keywords dictionary (via apply() or the extended call syntax),
the keywords dict should be ignored.  If the keywords dict is not empty,
TypeError should be raised.  (Between the restructuring of the call
machinery and this patch, an empty dict in this situation would trigger
a SystemError via PyErr_BadInternalCall().)

Added regression tests to detect errors for this.


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.214
retrieving revision 2.215
diff -C2 -r2.214 -r2.215
*** ceval.c	2001/01/03 23:52:36	2.214
--- ceval.c	2001/01/04 22:33:01	2.215
***************
*** 2608,2628 ****
  	int flags = PyCFunction_GET_FLAGS(func);
  
! 	if (flags & METH_KEYWORDS && kw == NULL) {
! 		static PyObject *dict = NULL;
! 		if (dict == NULL) {
! 			dict = PyDict_New();
! 			if (dict == NULL)
! 				return NULL;
  		}
! 		kw = dict;
! 		Py_INCREF(dict);
  	}
! 	if (flags & METH_VARARGS && kw == NULL) {
! 		return (*meth)(self, arg);
  	}
! 	if (flags & METH_KEYWORDS) {
! 		return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
  	}
  	if (!(flags & METH_VARARGS)) {
  		int size = PyTuple_GET_SIZE(arg);
  		if (size == 1)
--- 2608,2635 ----
  	int flags = PyCFunction_GET_FLAGS(func);
  
! 	if (flags & METH_KEYWORDS) {
! 		if (kw == NULL) {
! 			static PyObject *dict = NULL;
! 			if (dict == NULL) {
! 				dict = PyDict_New();
! 				if (dict == NULL)
! 					return NULL;
! 			}
! 			kw = dict;
! 			Py_INCREF(dict);
  		}
! 		return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
  	}
! 	if (kw != NULL && PyDict_Size(kw) != 0) {
! 		PyErr_Format(PyExc_TypeError,
! 			     "%.200s() takes no keyword arguments",
! 			     f->m_ml->ml_name);
! 		return NULL;
  	}
! 	if (flags & METH_VARARGS) {
! 		return (*meth)(self, arg);
  	}
  	if (!(flags & METH_VARARGS)) {
+ 		/* the really old style */
  		int size = PyTuple_GET_SIZE(arg);
  		if (size == 1)
***************
*** 2631,2640 ****
  			arg = NULL;
  		return (*meth)(self, arg);
- 	}
- 	if (kw != NULL && PyDict_Size(kw) != 0) {
- 		PyErr_Format(PyExc_TypeError,
- 			     "%.200s() takes no keyword arguments",
- 			     f->m_ml->ml_name);
- 		return NULL;
  	}
  	/* should never get here ??? */
--- 2638,2641 ----