[Python-checkins] python/dist/src/Objects classobject.c,2.154.8.3,2.154.8.4

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 08 Apr 2003 12:02:38 -0700


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

Modified Files:
      Tag: release22-maint
	classobject.c 
Log Message:
Added private API function _PyInstance_Lookup().  This is part of
backporting fixes so that garbage collection doesn't have to trigger
execution of arbitrary Python code just to figure out whether
an object has a __del__ method.


Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.154.8.3
retrieving revision 2.154.8.4
diff -C2 -d -r2.154.8.3 -r2.154.8.4
*** classobject.c	2 Feb 2003 19:37:32 -0000	2.154.8.3
--- classobject.c	8 Apr 2003 19:02:34 -0000	2.154.8.4
***************
*** 730,733 ****
--- 730,754 ----
  }
  
+ /* See classobject.h comments:  this only does dict lookups, and is always
+  * safe to call.
+  */
+ PyObject *
+ _PyInstance_Lookup(PyObject *pinst, PyObject *name)
+ {
+ 	PyObject *v;
+ 	PyClassObject *class;
+ 	PyInstanceObject *inst;	/* pinst cast to the right type */
+ 
+ 	assert(PyInstance_Check(pinst));
+ 	inst = (PyInstanceObject *)pinst;
+ 
+ 	assert(PyString_Check(name));
+ 
+  	v = PyDict_GetItem(inst->in_dict, name);
+ 	if (v == NULL)
+ 		v = class_lookup(inst->in_class, name, &class);
+ 	return v;
+ }
+ 
  static int
  instance_setattr1(PyInstanceObject *inst, PyObject *name, PyObject *v)
***************
*** 1057,1061 ****
  	if (!start)
  		return NULL;
! 	
  	end = PyInt_FromLong((long)j);
  	if (!end) {
--- 1078,1082 ----
  	if (!start)
  		return NULL;
! 
  	end = PyInt_FromLong((long)j);
  	if (!end) {
***************
*** 1089,1095 ****
  			return NULL;
  		arg = Py_BuildValue("(N)", sliceobj_from_intint(i, j));
! 	} else 
  		arg = Py_BuildValue("(ii)", i, j);
! 		
  	if (arg == NULL) {
  		Py_DECREF(func);
--- 1110,1116 ----
  			return NULL;
  		arg = Py_BuildValue("(N)", sliceobj_from_intint(i, j));
! 	} else
  		arg = Py_BuildValue("(ii)", i, j);
! 
  	if (arg == NULL) {
  		Py_DECREF(func);
***************
*** 1220,1224 ****
  		Py_DECREF(func);
  		Py_DECREF(arg);
! 		if(res == NULL) 
  			return -1;
  		ret = PyObject_IsTrue(res);
--- 1241,1245 ----
  		Py_DECREF(func);
  		Py_DECREF(arg);
! 		if(res == NULL)
  			return -1;
  		ret = PyObject_IsTrue(res);
***************
*** 1293,1297 ****
  /* Try one half of a binary operator involving a class instance. */
  static PyObject *
! half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc, 
  		int swapped)
  {
--- 1314,1318 ----
  /* Try one half of a binary operator involving a class instance. */
  static PyObject *
! half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc,
  		int swapped)
  {
***************
*** 1301,1305 ****
  	PyObject *v1;
  	PyObject *result;
! 	
  	if (!PyInstance_Check(v)) {
  		Py_INCREF(Py_NotImplemented);
--- 1322,1326 ----
  	PyObject *v1;
  	PyObject *result;
! 
  	if (!PyInstance_Check(v)) {
  		Py_INCREF(Py_NotImplemented);
***************
*** 1655,1659 ****
  static PyObject *
  instance_pow(PyObject *v, PyObject *w, PyObject *z)
! {	
  	if (z == Py_None) {
  		return do_binop(v, w, "__pow__", "__rpow__", bin_power);
--- 1676,1680 ----
  static PyObject *
  instance_pow(PyObject *v, PyObject *w, PyObject *z)
! {
  	if (z == Py_None) {
  		return do_binop(v, w, "__pow__", "__rpow__", bin_power);
***************
*** 1724,1728 ****
  static PyObject **name_op = NULL;
  
! static int 
  init_name_op(void)
  {
--- 1745,1749 ----
  static PyObject **name_op = NULL;
  
! static int
  init_name_op(void)
  {