[Python-checkins] python/dist/src/Objects setobject.c,1.17,1.18

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat Dec 13 14:38:50 EST 2003


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

Modified Files:
	setobject.c 
Log Message:
* Refactor set.__contains__()
* Use Py_RETURN_NONE everywhere.
* Fix-up the firstpass check for the tp_print slot.



Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** setobject.c	13 Dec 2003 18:53:18 -0000	1.17
--- setobject.c	13 Dec 2003 19:38:47 -0000	1.18
***************
*** 159,174 ****
  set_direct_contains(PySetObject *so, PyObject *key)
  {
- 	PyObject *tmp;
  	long result;
  
! 	result = PyDict_Contains(so->data, key);
! 	if (result == -1 && PyAnySet_Check(key)) {
! 		PyErr_Clear();
! 		tmp = frozenset_dict_wrapper(((PySetObject *)(key))->data);
! 		if (tmp == NULL)
! 			return NULL;
! 		result = PyDict_Contains(so->data, tmp);
! 		Py_DECREF(tmp);
! 	}
  	if (result == -1)
  		return NULL;
--- 159,165 ----
  set_direct_contains(PySetObject *so, PyObject *key)
  {
  	long result;
  
! 	result = set_contains(so, key);
  	if (result == -1)
  		return NULL;
***************
*** 656,661 ****
  	PyObject *key, *value;
  	int pos = 0;
- 
  	long hash = 0;
  	if (so->hash != -1)
  		return so->hash;
--- 647,652 ----
  	PyObject *key, *value;
  	int pos = 0;
  	long hash = 0;
+ 
  	if (so->hash != -1)
  		return so->hash;
***************
*** 729,737 ****
  {
  	PyObject *key, *value;
! 	int pos = 0;
  
  	fprintf(fp, "%s([", so->ob_type->tp_name);
  	while (PyDict_Next(so->data, &pos, &key, &value)) {
! 		if (pos)
  			fprintf(fp, ", ");
  		if (PyObject_Print(key, fp, 0) != 0)
--- 720,730 ----
  {
  	PyObject *key, *value;
! 	int pos=0, firstpass=1;
  
  	fprintf(fp, "%s([", so->ob_type->tp_name);
  	while (PyDict_Next(so->data, &pos, &key, &value)) {
! 		if (firstpass)
! 			firstpass = 0;
! 		else
  			fprintf(fp, ", ");
  		if (PyObject_Print(key, fp, 0) != 0)
***************
*** 747,752 ****
  	PyDict_Clear(so->data);
  	so->hash = -1;
! 	Py_INCREF(Py_None);
! 	return Py_None;
  }
  
--- 740,744 ----
  	PyDict_Clear(so->data);
  	so->hash = -1;
! 	Py_RETURN_NONE;
  }
  
***************
*** 766,771 ****
  	if (PyDict_SetItem(so->data, item, Py_True) == -1)
  		return NULL;
! 	Py_INCREF(Py_None);
! 	return Py_None;
  }
  
--- 758,762 ----
  	if (PyDict_SetItem(so->data, item, Py_True) == -1)
  		return NULL;
! 	Py_RETURN_NONE;
  }
  
***************
*** 791,796 ****
  	if (PyDict_DelItem(so->data, item) == -1) 
  		return NULL;
! 	Py_INCREF(Py_None);
! 	return Py_None;
  }
  
--- 782,786 ----
  	if (PyDict_DelItem(so->data, item) == -1) 
  		return NULL;
! 	Py_RETURN_NONE;
  }
  
***************
*** 819,824 ****
  		PyErr_Clear();
  	}
! 	Py_INCREF(Py_None);
! 	return Py_None;
  }
  
--- 809,813 ----
  		PyErr_Clear();
  	}
! 	Py_RETURN_NONE;
  }
  





More information about the Python-checkins mailing list