[Python-checkins] python/dist/src/Objects object.c,2.206.2.1,2.206.2.2 typeobject.c,2.220.2.2,2.220.2.3

ping@users.sourceforge.net ping@users.sourceforge.net
Tue, 25 Mar 2003 15:04:53 -0800


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

Modified Files:
      Tag: cache-attr-branch
	object.c typeobject.c 
Log Message:
Change cache from (isdata, where) pairs to (where, descr, isdata) triples.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.206.2.1
retrieving revision 2.206.2.2
diff -C2 -d -r2.206.2.1 -r2.206.2.2
*** object.c	25 Mar 2003 20:15:15 -0000	2.206.2.1
--- object.c	25 Mar 2003 23:04:43 -0000	2.206.2.2
***************
*** 1357,1376 ****
  		(descr)->ob_type->field : NULL)
  
! /* Find the dict where an attribute resides, and remember whether its value */
! /* is a data descriptor.  The dict is returned un-INCREFed. */
  PyObject *_PyObject_FindAttr(PyTypeObject *tp, PyObject *name,
! 			     int *is_data_descr)
  {
! 	PyObject *pair = NULL;
! 	PyObject *flag = NULL;
! 	PyObject *where = NULL;
! 	PyObject *descr = NULL;
  
  	if (tp->tp_cache != NULL) {
! 		pair = PyDict_GetItem(tp->tp_cache, name);
  		/* pair is not owned by this func */
! 		if (pair) {
! 			flag = PyTuple_GET_ITEM(pair, 0);
! 			where = PyTuple_GET_ITEM(pair, 1);
  			goto done;
  		}
--- 1357,1379 ----
  		(descr)->ob_type->field : NULL)
  
! /* Find the dict where an attribute resides, and return it un-INCREFed.  */
! /* In addition, cache/return whether the value is a descriptor-with-set; and */
! /* cache/return the value itself if the value is a descriptor-with-get. */
  PyObject *_PyObject_FindAttr(PyTypeObject *tp, PyObject *name,
! 			     PyObject **descr, int *isdata)
  {
! 	PyObject *triple = NULL;
! 	PyObject *value;
! 	PyObject *cache_where = Py_None;
! 	PyObject *cache_descr = Py_None;
! 	PyObject *cache_isdata = Py_False;
  
  	if (tp->tp_cache != NULL) {
! 		triple = PyDict_GetItem(tp->tp_cache, name);
  		/* pair is not owned by this func */
! 		if (triple) {
! 			cache_where = PyTuple_GET_ITEM(triple, 0);
! 			cache_descr = PyTuple_GET_ITEM(triple, 1);
! 			cache_isdata = PyTuple_GET_ITEM(triple, 2);
  			goto done;
  		}
***************
*** 1396,1408 ****
  			}
  			assert(dict && PyDict_Check(dict));
! 			descr = PyDict_GetItem(dict, name);
! 			if (descr != NULL) {
! 				if (GET_DESCR_FIELD(descr, tp_descr_set)) {
! 					/* It's a data descriptor. */
! 					flag = Py_True;
! 				} else {
! 					flag = Py_False;
! 				}
! 				where = dict;
  				break;
  			}
--- 1399,1409 ----
  			}
  			assert(dict && PyDict_Check(dict));
! 			value = PyDict_GetItem(dict, name);
! 			if (value != NULL) {
! 				cache_where = dict;
! 				if (GET_DESCR_FIELD(value, tp_descr_get))
! 					cache_descr = value;
! 				if (GET_DESCR_FIELD(value, tp_descr_set))
! 					cache_isdata = Py_True;
  				break;
  			}
***************
*** 1410,1435 ****
  	}
  
- 	if (flag == NULL) {
- 		flag = Py_False;
- 		where = Py_None;
- 	}
- 
  	if (tp->tp_cache != NULL) {
! 		pair = PyTuple_New(2);
! 		Py_INCREF(flag);
! 		PyTuple_SetItem(pair, 0, flag);
! 		Py_INCREF(where);
! 		PyTuple_SetItem(pair, 1, where);
! 		PyDict_SetItem(tp->tp_cache, name, pair);
! 		Py_DECREF(pair);
  	}
  
    done:
! 	*is_data_descr = (flag == Py_True);
! 	if (where == Py_None) {
  		return NULL;
! 	} else {
! 		return where;
! 	}
  }
  
--- 1411,1436 ----
  	}
  
  	if (tp->tp_cache != NULL) {
! 		triple = PyTuple_New(3);
! 		Py_INCREF(cache_where);
! 		PyTuple_SetItem(triple, 0, cache_where);
! 		Py_INCREF(cache_descr);
! 		PyTuple_SetItem(triple, 1, cache_descr);
! 		Py_INCREF(cache_isdata);
! 		PyTuple_SetItem(triple, 2, cache_isdata);
! 		PyDict_SetItem(tp->tp_cache, name, triple);
! 		Py_DECREF(triple);
  	}
  
    done:
! 	if (cache_descr == Py_None)
! 		*descr = NULL;
! 	else
! 		*descr = cache_descr;
! 	*isdata = (cache_isdata == Py_True);
! 	if (cache_where == Py_None)
  		return NULL;
! 	else
! 		return cache_where;
  }
  
***************
*** 1439,1444 ****
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
- 	int is_data_descr = 0;
  	PyObject *descr = NULL;
  	PyObject *res = NULL;
  	descrgetfunc descr_get;
--- 1440,1445 ----
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
  	PyObject *descr = NULL;
+ 	int isdata = 0;
  	PyObject *res = NULL;
  	descrgetfunc descr_get;
***************
*** 1473,1480 ****
  
  	/* Locate the attribute among the base classes. */
! 	where = _PyObject_FindAttr(tp, name, &is_data_descr);
  
  	/* Data descriptor takes priority over instance attribute. */
! 	if (!is_data_descr) {
  
  		/* Inline _PyObject_GetDictPtr */
--- 1474,1481 ----
  
  	/* Locate the attribute among the base classes. */
! 	where = _PyObject_FindAttr(tp, name, &descr, &isdata);
  
  	/* Data descriptor takes priority over instance attribute. */
! 	if (!isdata) {
  
  		/* Inline _PyObject_GetDictPtr */
***************
*** 1507,1522 ****
  	}
  
! 	if (where != NULL) {
! 		descr = PyDict_GetItem(where, name);
! 		assert(descr != NULL);
  		descr_get = GET_DESCR_FIELD(descr, tp_descr_get);
  
! 		if (descr_get != NULL) {
! 			res = descr_get(descr, obj, (PyObject *) tp);
! 			goto done;
! 		}
! 
! 		Py_INCREF(descr);
! 		res = descr;
  		goto done;
  	}
--- 1508,1522 ----
  	}
  
! 	if (descr != NULL) {
  		descr_get = GET_DESCR_FIELD(descr, tp_descr_get);
+ 		assert(descr_get != NULL);
+ 		res = descr_get(descr, obj, (PyObject *)tp);
+ 		goto done;
+ 	}
  
! 	if (where != NULL) {
! 		res = PyDict_GetItem(where, name);
! 		assert(res != NULL);
! 		Py_INCREF(res);
  		goto done;
  	}
***************
*** 1536,1541 ****
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
! 	int is_data_descr = 0;
! 	PyObject *descr = NULL;
  	descrsetfunc descr_set;
  	PyObject **dictptr;
--- 1536,1541 ----
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
! 	PyObject *descr;
! 	int isdata = 0;
  	descrsetfunc descr_set;
  	PyObject **dictptr;
***************
*** 1569,1581 ****
  
  	/* Locate the attribute among the base classes. */
! 	where = _PyObject_FindAttr(tp, name, &is_data_descr);
! 	if (where != NULL) {
! 		descr = PyDict_GetItem(where, name);
! 	}
! 	if (is_data_descr) {
  		/* Data descriptor takes priority over instance attribute. */
! 		assert(descr != NULL);
  		descr_set = GET_DESCR_FIELD(descr, tp_descr_set);
! 		assert(descr_set != NULL && PyDescr_IsData(descr));
  		res = descr_set(descr, obj, value);
  		goto done;
--- 1569,1578 ----
  
  	/* Locate the attribute among the base classes. */
! 	where = _PyObject_FindAttr(tp, name, &descr, &isdata);
! 	if (isdata) {
  		/* Data descriptor takes priority over instance attribute. */
! 		assert(descr != NULL); /* XXX Will fail if set but no get! */
  		descr_set = GET_DESCR_FIELD(descr, tp_descr_set);
! 		assert(descr_set != NULL);
  		res = descr_set(descr, obj, value);
  		goto done;

Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.220.2.2
retrieving revision 2.220.2.3
diff -C2 -d -r2.220.2.2 -r2.220.2.3
*** typeobject.c	25 Mar 2003 21:19:02 -0000	2.220.2.2
--- typeobject.c	25 Mar 2003 23:04:48 -0000	2.220.2.3
***************
*** 2104,2108 ****
  {
  	PyObject *old;
! 	int was_data_descr, is_data_descr;
  
  	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
--- 2104,2108 ----
  {
  	PyObject *old;
! 	int wasdata, isdata, wasdescr, isdescr, wasnull, isnull;
  
  	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
***************
*** 2116,2125 ****
  	/* If this change affects attribute lookup, invalidate cache entries. */
  	old = PyDict_GetItem(type->tp_dict, name);
! 	was_data_descr = (old != NULL) && GET_DESCR_FIELD(old, tp_descr_set);
! 	is_data_descr = (value != NULL) && GET_DESCR_FIELD(value, tp_descr_set);
! 	if (was_data_descr != is_data_descr ||
! 	    (old == NULL) != (value == NULL)) {
  		update_subclasses(type, name, invalidate_cache, name);
- 	}
  
  	if (PyObject_GenericSetAttr((PyObject *)type, name, value) < 0)
--- 2116,2127 ----
  	/* If this change affects attribute lookup, invalidate cache entries. */
  	old = PyDict_GetItem(type->tp_dict, name);
! 	wasnull = (old == NULL);
! 	isnull = (value == NULL);
! 	wasdescr = (GET_DESCR_FIELD(old, tp_descr_get) != NULL);
! 	isdescr = (GET_DESCR_FIELD(value, tp_descr_get) != NULL);
! 	wasdata = (GET_DESCR_FIELD(old, tp_descr_set) != NULL);
! 	isdata = (GET_DESCR_FIELD(value, tp_descr_set) != NULL);
! 	if (wasnull != isnull || wasdescr != isdescr || wasdata != isdata)
  		update_subclasses(type, name, invalidate_cache, name);
  
  	if (PyObject_GenericSetAttr((PyObject *)type, name, value) < 0)