[Python-checkins] r45269 - python/trunk/Objects/obmalloc.c python/trunk/Objects/stringobject.c python/trunk/Objects/tupleobject.c python/trunk/Objects/typeobject.c python/trunk/Objects/unicodeobject.c

anthony.baxter python-checkins at python.org
Tue Apr 11 09:42:39 CEST 2006


Author: anthony.baxter
Date: Tue Apr 11 09:42:36 2006
New Revision: 45269

Modified:
   python/trunk/Objects/obmalloc.c
   python/trunk/Objects/stringobject.c
   python/trunk/Objects/tupleobject.c
   python/trunk/Objects/typeobject.c
   python/trunk/Objects/unicodeobject.c
Log:
More low-hanging fruit. Still need to re-arrange some code (or find a better
solution) in the same way as listobject.c got changed. Hoping for a better
solution.


Modified: python/trunk/Objects/obmalloc.c
==============================================================================
--- python/trunk/Objects/obmalloc.c	(original)
+++ python/trunk/Objects/obmalloc.c	Tue Apr 11 09:42:36 2006
@@ -529,7 +529,7 @@
 		nbytes = numarenas * sizeof(*arenas);
 		if (nbytes / sizeof(*arenas) != numarenas)
 			return NULL;	/* overflow */
-		arenaobj = realloc(arenas, nbytes);
+		arenaobj = (arena_object *)realloc(arenas, nbytes);
 		if (arenaobj == NULL)
 			return NULL;
 		arenas = arenaobj;

Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c	(original)
+++ python/trunk/Objects/stringobject.c	Tue Apr 11 09:42:36 2006
@@ -1051,7 +1051,7 @@
 	lastchar = sub[shortsub];
 	last = s + PyString_GET_SIZE(a) - len_sub + 1;
 	while (s < last) {
-		s = memchr(s, firstchar, last-s);
+		s = (char *)memchr(s, firstchar, last-s);
 		if (s == NULL)
 			return 0;
 		assert(s < last);
@@ -1210,7 +1210,7 @@
 		}
 		else {
 			source_buf = PyString_AsString((PyObject*)self);
-			result_buf = PyMem_Malloc(slicelength);
+			result_buf = (char *)PyMem_Malloc(slicelength);
 			if (result_buf == NULL)
 				return PyErr_NoMemory();
 
@@ -2028,12 +2028,12 @@
 {
 	char *s = PyString_AS_STRING(self), *s_new;
 	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *new;
+	PyObject *newobj;
 
-	new = PyString_FromStringAndSize(NULL, n);
-	if (new == NULL)
+	newobj = PyString_FromStringAndSize(NULL, n);
+	if (newobj == NULL)
 		return NULL;
-	s_new = PyString_AsString(new);
+	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
 		if (isupper(c)) {
@@ -2042,7 +2042,7 @@
 			*s_new = c;
 		s_new++;
 	}
-	return new;
+	return newobj;
 }
 
 
@@ -2056,12 +2056,12 @@
 {
 	char *s = PyString_AS_STRING(self), *s_new;
 	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *new;
+	PyObject *newobj;
 
-	new = PyString_FromStringAndSize(NULL, n);
-	if (new == NULL)
+	newobj = PyString_FromStringAndSize(NULL, n);
+	if (newobj == NULL)
 		return NULL;
-	s_new = PyString_AsString(new);
+	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
 		if (islower(c)) {
@@ -2070,7 +2070,7 @@
 			*s_new = c;
 		s_new++;
 	}
-	return new;
+	return newobj;
 }
 
 
@@ -2086,12 +2086,12 @@
 	char *s = PyString_AS_STRING(self), *s_new;
 	Py_ssize_t i, n = PyString_GET_SIZE(self);
 	int previous_is_cased = 0;
-	PyObject *new;
+	PyObject *newobj;
 
-	new = PyString_FromStringAndSize(NULL, n);
-	if (new == NULL)
+	newobj = PyString_FromStringAndSize(NULL, n);
+	if (newobj == NULL)
 		return NULL;
-	s_new = PyString_AsString(new);
+	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
 		if (islower(c)) {
@@ -2106,7 +2106,7 @@
 			previous_is_cased = 0;
 		*s_new++ = c;
 	}
-	return new;
+	return newobj;
 }
 
 PyDoc_STRVAR(capitalize__doc__,
@@ -2120,12 +2120,12 @@
 {
 	char *s = PyString_AS_STRING(self), *s_new;
 	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *new;
+	PyObject *newobj;
 
-	new = PyString_FromStringAndSize(NULL, n);
-	if (new == NULL)
+	newobj = PyString_FromStringAndSize(NULL, n);
+	if (newobj == NULL)
 		return NULL;
-	s_new = PyString_AsString(new);
+	s_new = PyString_AsString(newobj);
 	if (0 < n) {
 		int c = Py_CHARMASK(*s++);
 		if (islower(c))
@@ -2142,7 +2142,7 @@
 			*s_new = c;
 		s_new++;
 	}
-	return new;
+	return newobj;
 }
 
 
@@ -2199,7 +2199,7 @@
 		}
 		if (i >= m)
 			break;
-		t = memchr(s+i, sub[0], m-i);
+		t = (const char *)memchr(s+i, sub[0], m-i);
 		if (t == NULL)
 			break;
 		i = t - s;
@@ -2218,12 +2218,12 @@
 {
 	char *s = PyString_AS_STRING(self), *s_new;
 	Py_ssize_t i, n = PyString_GET_SIZE(self);
-	PyObject *new;
+	PyObject *newobj;
 
-	new = PyString_FromStringAndSize(NULL, n);
-	if (new == NULL)
+	newobj = PyString_FromStringAndSize(NULL, n);
+	if (newobj == NULL)
 		return NULL;
-	s_new = PyString_AsString(new);
+	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
 		if (islower(c)) {
@@ -2236,7 +2236,7 @@
 			*s_new = c;
 		s_new++;
 	}
-	return new;
+	return newobj;
 }
 
 
@@ -2524,7 +2524,7 @@
 	const Py_ssize_t len = PyString_GET_SIZE(self);
 	Py_ssize_t sub_len, repl_len, out_len;
 	int count = -1;
-	PyObject *new;
+	PyObject *newobj;
 	PyObject *subobj, *replobj;
 
 	if (!PyArg_ParseTuple(args, "OO|i:replace",
@@ -2563,20 +2563,20 @@
 	if (out_len == -1) {
 		if (PyString_CheckExact(self)) {
 			/* we're returning another reference to self */
-			new = (PyObject*)self;
-			Py_INCREF(new);
+			newobj = (PyObject*)self;
+			Py_INCREF(newobj);
 		}
 		else {
-			new = PyString_FromStringAndSize(str, len);
-			if (new == NULL)
+			newobj = PyString_FromStringAndSize(str, len);
+			if (newobj == NULL)
 				return NULL;
 		}
 	}
 	else {
-		new = PyString_FromStringAndSize(new_s, out_len);
+		newobj = PyString_FromStringAndSize(new_s, out_len);
 		PyMem_FREE(new_s);
 	}
-	return new;
+	return newobj;
 }
 
 

Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c	(original)
+++ python/trunk/Objects/tupleobject.c	Tue Apr 11 09:42:36 2006
@@ -547,7 +547,7 @@
 static PyObject *
 tuple_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	PyObject *tmp, *new, *item;
+	PyObject *tmp, *newobj, *item;
 	Py_ssize_t i, n;
 
 	assert(PyType_IsSubtype(type, &PyTuple_Type));
@@ -555,16 +555,16 @@
 	if (tmp == NULL)
 		return NULL;
 	assert(PyTuple_Check(tmp));
-	new = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp));
-	if (new == NULL)
+	newobj = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp));
+	if (newobj == NULL)
 		return NULL;
 	for (i = 0; i < n; i++) {
 		item = PyTuple_GET_ITEM(tmp, i);
 		Py_INCREF(item);
-		PyTuple_SET_ITEM(new, i, item);
+		PyTuple_SET_ITEM(newobj, i, item);
 	}
 	Py_DECREF(tmp);
-	return new;
+	return newobj;
 }
 
 PyDoc_STRVAR(tuple_doc,

Modified: python/trunk/Objects/typeobject.c
==============================================================================
--- python/trunk/Objects/typeobject.c	(original)
+++ python/trunk/Objects/typeobject.c	Tue Apr 11 09:42:36 2006
@@ -453,7 +453,7 @@
 	if (PyType_IS_GC(type))
 		obj = _PyObject_GC_Malloc(size);
 	else
-		obj = PyObject_MALLOC(size);
+		obj = (PyObject *)PyObject_MALLOC(size);
 
 	if (obj == NULL)
 		return PyErr_NoMemory();
@@ -1150,7 +1150,7 @@
 	   remain[i] is the index of the next base in to_merge[i]
 	   that is not included in acc.
 	*/
-	remain = PyMem_MALLOC(SIZEOF_INT*to_merge_size);
+	remain = (int *)PyMem_MALLOC(SIZEOF_INT*to_merge_size);
 	if (remain == NULL)
 		return -1;
 	for (i = 0; i < to_merge_size; i++)
@@ -1896,7 +1896,7 @@
 		PyObject *doc = PyDict_GetItemString(dict, "__doc__");
 		if (doc != NULL && PyString_Check(doc)) {
 			const size_t n = (size_t)PyString_GET_SIZE(doc);
-                        char *tp_doc = PyObject_MALLOC(n+1);
+                        char *tp_doc = (char *)PyObject_MALLOC(n+1);
 			if (tp_doc == NULL) {
 				Py_DECREF(type);
 				return NULL;
@@ -2446,23 +2446,23 @@
 }
 
 static int
-compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
+compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, char* attr)
 {
 	PyTypeObject *newbase, *oldbase;
 
-	if (new->tp_dealloc != old->tp_dealloc ||
-	    new->tp_free != old->tp_free)
+	if (newto->tp_dealloc != oldto->tp_dealloc ||
+	    newto->tp_free != oldto->tp_free)
 	{
 		PyErr_Format(PyExc_TypeError,
 			     "%s assignment: "
 			     "'%s' deallocator differs from '%s'",
 			     attr,
-			     new->tp_name,
-			     old->tp_name);
+			     newto->tp_name,
+			     oldto->tp_name);
 		return 0;
 	}
-	newbase = new;
-	oldbase = old;
+	newbase = newto;
+	oldbase = oldto;
 	while (equiv_structs(newbase, newbase->tp_base))
 		newbase = newbase->tp_base;
 	while (equiv_structs(oldbase, oldbase->tp_base))
@@ -2474,8 +2474,8 @@
 			     "%s assignment: "
 			     "'%s' object layout differs from '%s'",
 			     attr,
-			     new->tp_name,
-			     old->tp_name);
+			     newto->tp_name,
+			     oldto->tp_name);
 		return 0;
 	}
 
@@ -2485,8 +2485,8 @@
 static int
 object_set_class(PyObject *self, PyObject *value, void *closure)
 {
-	PyTypeObject *old = self->ob_type;
-	PyTypeObject *new;
+	PyTypeObject *oldto = self->ob_type;
+	PyTypeObject *newto;
 
 	if (value == NULL) {
 		PyErr_SetString(PyExc_TypeError,
@@ -2499,18 +2499,18 @@
 		  value->ob_type->tp_name);
 		return -1;
 	}
-	new = (PyTypeObject *)value;
-	if (!(new->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
-	    !(old->tp_flags & Py_TPFLAGS_HEAPTYPE))
+	newto = (PyTypeObject *)value;
+	if (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
+	    !(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE))
 	{
 		PyErr_Format(PyExc_TypeError,
 			     "__class__ assignment: only for heap types");
 		return -1;
 	}
-	if (compatible_for_assignment(new, old, "__class__")) {
-		Py_INCREF(new);
-		self->ob_type = new;
-		Py_DECREF(old);
+	if (compatible_for_assignment(newto, oldto, "__class__")) {
+		Py_INCREF(newto);
+		self->ob_type = newto;
+		Py_DECREF(oldto);
 		return 0;
 	}
 	else {
@@ -3332,7 +3332,7 @@
 {
 	Py_ssize_t i;
 	int result;
-	PyObject *list, *ref, *new;
+	PyObject *list, *ref, *newobj;
 
 	list = base->tp_subclasses;
 	if (list == NULL) {
@@ -3341,16 +3341,16 @@
 			return -1;
 	}
 	assert(PyList_Check(list));
-	new = PyWeakref_NewRef((PyObject *)type, NULL);
+	newobj = PyWeakref_NewRef((PyObject *)type, NULL);
 	i = PyList_GET_SIZE(list);
 	while (--i >= 0) {
 		ref = PyList_GET_ITEM(list, i);
 		assert(PyWeakref_CheckRef(ref));
 		if (PyWeakref_GET_OBJECT(ref) == Py_None)
-			return PyList_SetItem(list, i, new);
+			return PyList_SetItem(list, i, newobj);
 	}
-	result = PyList_Append(list, new);
-	Py_DECREF(new);
+	result = PyList_Append(list, newobj);
+	Py_DECREF(newobj);
 	return result;
 }
 
@@ -5746,7 +5746,7 @@
 super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
 {
 	superobject *su = (superobject *)self;
-	superobject *new;
+	superobject *newobj;
 
 	if (obj == NULL || obj == Py_None || su->obj != NULL) {
 		/* Not binding to an object, or already bound */
@@ -5763,16 +5763,16 @@
 		PyTypeObject *obj_type = supercheck(su->type, obj);
 		if (obj_type == NULL)
 			return NULL;
-		new = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
+		newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
 							 NULL, NULL);
-		if (new == NULL)
+		if (newobj == NULL)
 			return NULL;
 		Py_INCREF(su->type);
 		Py_INCREF(obj);
-		new->type = su->type;
-		new->obj = obj;
-		new->obj_type = obj_type;
-		return (PyObject *)new;
+		newobj->type = su->type;
+		newobj->obj = obj;
+		newobj->obj_type = obj_type;
+		return (PyObject *)newobj;
 	}
 }
 

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Tue Apr 11 09:42:36 2006
@@ -149,7 +149,7 @@
     oldstr = unicode->str;
     PyMem_RESIZE(unicode->str, Py_UNICODE, length + 1);
     if (!unicode->str) {
-	unicode->str = oldstr;
+	unicode->str = (Py_UNICODE *)oldstr;
         PyErr_NoMemory();
         return -1;
     }
@@ -1884,7 +1884,7 @@
                 Py_DECREF(m);
                 if (api == NULL)
                     goto ucnhashError;
-                ucnhash_CAPI = PyCObject_AsVoidPtr(api);
+                ucnhash_CAPI = (_PyUnicode_Name_CAPI *)PyCObject_AsVoidPtr(api);
                 Py_DECREF(api);
                 if (ucnhash_CAPI == NULL)
                     goto ucnhashError;
@@ -2499,8 +2499,8 @@
     /* current output position */
     Py_ssize_t respos = 0;
     Py_ssize_t ressize;
-    char *encoding = (limit == 256) ? "latin-1" : "ascii";
-    char *reason = (limit == 256) ? "ordinal not in range(256)" : "ordinal not in range(128)";
+    const char *encoding = (limit == 256) ? "latin-1" : "ascii";
+    const char *reason = (limit == 256) ? "ordinal not in range(256)" : "ordinal not in range(128)";
     PyObject *errorHandler = NULL;
     PyObject *exc = NULL;
     /* the following variable is used for caching string comparisons
@@ -6488,7 +6488,8 @@
             return PyUnicode_FromUnicode(NULL, 0);
         } else {
             source_buf = PyUnicode_AS_UNICODE((PyObject*)self);
-            result_buf = PyMem_MALLOC(slicelength*sizeof(Py_UNICODE));
+            result_buf = (Py_UNICODE *)PyMem_MALLOC(slicelength*
+                                                    sizeof(Py_UNICODE));
 	    
 	    if (result_buf == NULL)
 		    return PyErr_NoMemory();


More information about the Python-checkins mailing list