mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
1cf3964fd1
commit
a62862120d
|
@ -529,7 +529,7 @@ new_arena(void)
|
|||
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;
|
||||
|
|
|
@ -1051,7 +1051,7 @@ string_contains(PyObject *a, PyObject *el)
|
|||
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 @@ string_subscript(PyStringObject* self, PyObject* item)
|
|||
}
|
||||
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 @@ string_lower(PyStringObject *self)
|
|||
{
|
||||
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 @@ string_lower(PyStringObject *self)
|
|||
*s_new = c;
|
||||
s_new++;
|
||||
}
|
||||
return new;
|
||||
return newobj;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2056,12 +2056,12 @@ string_upper(PyStringObject *self)
|
|||
{
|
||||
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 @@ string_upper(PyStringObject *self)
|
|||
*s_new = c;
|
||||
s_new++;
|
||||
}
|
||||
return new;
|
||||
return newobj;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2086,12 +2086,12 @@ string_title(PyStringObject *self)
|
|||
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 @@ string_title(PyStringObject *self)
|
|||
previous_is_cased = 0;
|
||||
*s_new++ = c;
|
||||
}
|
||||
return new;
|
||||
return newobj;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(capitalize__doc__,
|
||||
|
@ -2120,12 +2120,12 @@ string_capitalize(PyStringObject *self)
|
|||
{
|
||||
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 @@ string_capitalize(PyStringObject *self)
|
|||
*s_new = c;
|
||||
s_new++;
|
||||
}
|
||||
return new;
|
||||
return newobj;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2199,7 +2199,7 @@ string_count(PyStringObject *self, PyObject *args)
|
|||
}
|
||||
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 @@ string_swapcase(PyStringObject *self)
|
|||
{
|
||||
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 @@ string_swapcase(PyStringObject *self)
|
|||
*s_new = c;
|
||||
s_new++;
|
||||
}
|
||||
return new;
|
||||
return newobj;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2524,7 +2524,7 @@ string_replace(PyStringObject *self, PyObject *args)
|
|||
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 @@ string_replace(PyStringObject *self, PyObject *args)
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -547,7 +547,7 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
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 @@ tuple_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
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,
|
||||
|
|
|
@ -453,7 +453,7 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
|
|||
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 @@ pmerge(PyObject *acc, PyObject* to_merge) {
|
|||
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 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
|||
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 @@ same_slots_added(PyTypeObject *a, PyTypeObject *b)
|
|||
}
|
||||
|
||||
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 @@ compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
|
|||
"%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 @@ compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
|
|||
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 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
|
|||
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 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
|
|||
{
|
||||
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 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
|
|||
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 @@ static PyObject *
|
|||
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 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ int unicode_resize(register PyUnicodeObject *unicode,
|
|||
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 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
|
|||
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 @@ static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
|
|||
/* 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 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item)
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue