[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.59,2.60

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 14 Sep 2001 09:58:10 -0700


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

Modified Files:
	typeobject.c 
Log Message:
call_method():

- Don't turn a non-tuple argument into a one-tuple.  Rather, the
  caller must pass a format that causes Py_VaBuildValue() to return a
  tuple.

- Speed things up by calling PyObject_Call (which is fairly low-level
  and straightforward) rather than PyObject_CallObject (which calls
  PyEval_CallObjectWithKeywords which calls PyObject_Call, and nothing
  is really done in the mean time except some tests for NULL args and
  valid types, which are already guaranteed).

- Cosmetics.

Other places:

- Make sure that the format argument to call_method() is surrounded by
  parentheses, so it will cause a tuple to be created.

- Replace a few calls to PyEval_CallObject() with a surefire tuple for
  args to calls to PyObject_Call().  (A few calls to
  PyEval_CallObject() remain that have NULL for args.)


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.59
retrieving revision 2.60
diff -C2 -d -r2.59 -r2.60
*** typeobject.c	2001/09/13 19:18:27	2.59
--- typeobject.c	2001/09/14 16:58:08	2.60
***************
*** 348,352 ****
  		va_end(va);
  		PyErr_SetString(PyExc_AttributeError, name);
! 		return 0;
  	}
  
--- 348,352 ----
  		va_end(va);
  		PyErr_SetString(PyExc_AttributeError, name);
! 		return NULL;
  	}
  
***************
*** 358,376 ****
  	va_end(va);
  
! 	if (!args)
  		return NULL;
- 
- 	if (!PyTuple_Check(args)) {
- 		PyObject *a;
- 
- 		a = PyTuple_New(1);
- 		if (a == NULL)
- 			return NULL;
- 		if (PyTuple_SetItem(a, 0, args) < 0)
- 			return NULL;
- 		args = a;
- 	}
  
! 	retval = PyObject_CallObject(func, args);
  
  	Py_DECREF(args);
--- 358,366 ----
  	va_end(va);
  
! 	if (args == NULL)
  		return NULL;
  
! 	assert(PyTuple_Check(args));
! 	retval = PyObject_Call(func, args, NULL);
  
  	Py_DECREF(args);
***************
*** 2438,2442 ****
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, ""); \
  }
  
--- 2428,2432 ----
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, "()"); \
  }
  
***************
*** 2446,2450 ****
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, ARGCODES, arg1); \
  }
  
--- 2436,2440 ----
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, "(" ARGCODES ")", arg1); \
  }
  
***************
*** 2459,2463 ****
  		PyObject *r; \
  		r = call_method( \
! 			self, OPSTR, &cache_str, "O", other); \
  		if (r != Py_NotImplemented || \
  		    other->ob_type == self->ob_type) \
--- 2449,2453 ----
  		PyObject *r; \
  		r = call_method( \
! 			self, OPSTR, &cache_str, "(O)", other); \
  		if (r != Py_NotImplemented || \
  		    other->ob_type == self->ob_type) \
***************
*** 2468,2472 ****
  	    other->ob_type->tp_as_number->SLOTNAME == TESTFUNC) { \
  		return call_method( \
! 			other, ROPSTR, &rcache_str, "O", self); \
  	} \
  	Py_INCREF(Py_NotImplemented); \
--- 2458,2462 ----
  	    other->ob_type->tp_as_number->SLOTNAME == TESTFUNC) { \
  		return call_method( \
! 			other, ROPSTR, &rcache_str, "(O)", self); \
  	} \
  	Py_INCREF(Py_NotImplemented); \
***************
*** 2482,2486 ****
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, ARGCODES, arg1, arg2); \
  }
  
--- 2472,2477 ----
  { \
  	static PyObject *cache_str; \
! 	return call_method(self, OPSTR, &cache_str, \
! 			   "(" ARGCODES ")", arg1, arg2); \
  }
  
***************
*** 2489,2493 ****
  {
  	static PyObject *len_str;
! 	PyObject *res = call_method(self, "__len__", &len_str, "");
  
  	if (res == NULL)
--- 2480,2484 ----
  {
  	static PyObject *len_str;
! 	PyObject *res = call_method(self, "__len__", &len_str, "()");
  
  	if (res == NULL)
***************
*** 2509,2516 ****
  	if (value == NULL)
  		res = call_method(self, "__delitem__", &delitem_str,
! 				  "i", index);
  	else
  		res = call_method(self, "__setitem__", &setitem_str,
! 				  "iO", index, value);
  	if (res == NULL)
  		return -1;
--- 2500,2507 ----
  	if (value == NULL)
  		res = call_method(self, "__delitem__", &delitem_str,
! 				  "(i)", index);
  	else
  		res = call_method(self, "__setitem__", &setitem_str,
! 				  "(iO)", index, value);
  	if (res == NULL)
  		return -1;
***************
*** 2527,2534 ****
  	if (value == NULL)
  		res = call_method(self, "__delslice__", &delslice_str,
! 				  "ii", i, j);
  	else
  		res = call_method(self, "__setslice__", &setslice_str,
! 				  "iiO", i, j, value);
  	if (res == NULL)
  		return -1;
--- 2518,2525 ----
  	if (value == NULL)
  		res = call_method(self, "__delslice__", &delslice_str,
! 				  "(ii)", i, j);
  	else
  		res = call_method(self, "__setslice__", &setslice_str,
! 				  "(iiO)", i, j, value);
  	if (res == NULL)
  		return -1;
***************
*** 2550,2554 ****
  			res = NULL;
  		else {
! 			res = PyEval_CallObject(func, args);
  			Py_DECREF(args);
  		}
--- 2541,2545 ----
  			res = NULL;
  		else {
! 			res = PyObject_Call(func, args, NULL);
  			Py_DECREF(args);
  		}
***************
*** 2580,2587 ****
  	if (value == NULL)
  		res = call_method(self, "__delitem__", &delitem_str,
! 				  "O", key);
  	else
  		res = call_method(self, "__setitem__", &setitem_str,
! 				 "OO", key, value);
  	if (res == NULL)
  		return -1;
--- 2571,2578 ----
  	if (value == NULL)
  		res = call_method(self, "__delitem__", &delitem_str,
! 				  "(O)", key);
  	else
  		res = call_method(self, "__setitem__", &setitem_str,
! 				 "(OO)", key, value);
  	if (res == NULL)
  		return -1;
***************
*** 2611,2615 ****
  	/* Three-arg power doesn't use __rpow__ */
  	return call_method(self, "__pow__", &pow_str,
! 			   "OO", other, modulus);
  }
  
--- 2602,2606 ----
  	/* Three-arg power doesn't use __rpow__ */
  	return call_method(self, "__pow__", &pow_str,
! 			   "(OO)", other, modulus);
  }
  
***************
*** 2631,2635 ****
  
  	if (func != NULL) {
! 		res = PyEval_CallObject(func, NULL);
  		Py_DECREF(func);
  		if (res == NULL)
--- 2622,2626 ----
  
  	if (func != NULL) {
! 		res = PyObject_CallObject(func, NULL);
  		Py_DECREF(func);
  		if (res == NULL)
***************
*** 2688,2692 ****
  			res = NULL;
  		else {
! 			res = PyObject_CallObject(func, args);
  			Py_DECREF(args);
  		}
--- 2679,2683 ----
  			res = NULL;
  		else {
! 			res = PyObject_Call(func, args, NULL);
  			Py_DECREF(args);
  		}
***************
*** 2842,2849 ****
  	if (value == NULL)
  		res = call_method(self, "__delattr__", &delattr_str,
! 				  "O", name);
  	else
  		res = call_method(self, "__setattr__", &setattr_str,
! 				  "OO", name, value);
  	if (res == NULL)
  		return -1;
--- 2833,2840 ----
  	if (value == NULL)
  		res = call_method(self, "__delattr__", &delattr_str,
! 				  "(O)", name);
  	else
  		res = call_method(self, "__setattr__", &setattr_str,
! 				  "(OO)", name, value);
  	if (res == NULL)
  		return -1;
***************
*** 2878,2882 ****
  		res = NULL;
  	else {
! 		res = PyObject_CallObject(func, args);
  		Py_DECREF(args);
  	}
--- 2869,2873 ----
  		res = NULL;
  	else {
! 		res = PyObject_Call(func, args, NULL);
  		Py_DECREF(args);
  	}
***************
*** 2936,2940 ****
  {
  	static PyObject *next_str;
! 	return call_method(self, "next", &next_str, "");
  }
  
--- 2927,2931 ----
  {
  	static PyObject *next_str;
! 	return call_method(self, "next", &next_str, "()");
  }
  
***************
*** 2974,2981 ****
  	if (value == NULL)
  		res = call_method(self, "__del__", &del_str,
! 				  "O", target);
  	else
  		res = call_method(self, "__set__", &set_str,
! 				  "OO", target, value);
  	if (res == NULL)
  		return -1;
--- 2965,2972 ----
  	if (value == NULL)
  		res = call_method(self, "__del__", &del_str,
! 				  "(O)", target);
  	else
  		res = call_method(self, "__set__", &set_str,
! 				  "(OO)", target, value);
  	if (res == NULL)
  		return -1;