Skip to content

Commit 812c152

Browse files
author
anthony.baxter
committed
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. git-svn-id: http://svn.python.org/projects/python/trunk@45269 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5ebd285 commit 812c152

5 files changed

Lines changed: 80 additions & 79 deletions

File tree

Objects/obmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ new_arena(void)
529529
nbytes = numarenas * sizeof(*arenas);
530530
if (nbytes / sizeof(*arenas) != numarenas)
531531
return NULL; /* overflow */
532-
arenaobj = realloc(arenas, nbytes);
532+
arenaobj = (arena_object *)realloc(arenas, nbytes);
533533
if (arenaobj == NULL)
534534
return NULL;
535535
arenas = arenaobj;

Objects/stringobject.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ string_contains(PyObject *a, PyObject *el)
10511051
lastchar = sub[shortsub];
10521052
last = s + PyString_GET_SIZE(a) - len_sub + 1;
10531053
while (s < last) {
1054-
s = memchr(s, firstchar, last-s);
1054+
s = (char *)memchr(s, firstchar, last-s);
10551055
if (s == NULL)
10561056
return 0;
10571057
assert(s < last);
@@ -1210,7 +1210,7 @@ string_subscript(PyStringObject* self, PyObject* item)
12101210
}
12111211
else {
12121212
source_buf = PyString_AsString((PyObject*)self);
1213-
result_buf = PyMem_Malloc(slicelength);
1213+
result_buf = (char *)PyMem_Malloc(slicelength);
12141214
if (result_buf == NULL)
12151215
return PyErr_NoMemory();
12161216

@@ -2028,12 +2028,12 @@ string_lower(PyStringObject *self)
20282028
{
20292029
char *s = PyString_AS_STRING(self), *s_new;
20302030
Py_ssize_t i, n = PyString_GET_SIZE(self);
2031-
PyObject *new;
2031+
PyObject *newobj;
20322032

2033-
new = PyString_FromStringAndSize(NULL, n);
2034-
if (new == NULL)
2033+
newobj = PyString_FromStringAndSize(NULL, n);
2034+
if (newobj == NULL)
20352035
return NULL;
2036-
s_new = PyString_AsString(new);
2036+
s_new = PyString_AsString(newobj);
20372037
for (i = 0; i < n; i++) {
20382038
int c = Py_CHARMASK(*s++);
20392039
if (isupper(c)) {
@@ -2042,7 +2042,7 @@ string_lower(PyStringObject *self)
20422042
*s_new = c;
20432043
s_new++;
20442044
}
2045-
return new;
2045+
return newobj;
20462046
}
20472047

20482048

@@ -2056,12 +2056,12 @@ string_upper(PyStringObject *self)
20562056
{
20572057
char *s = PyString_AS_STRING(self), *s_new;
20582058
Py_ssize_t i, n = PyString_GET_SIZE(self);
2059-
PyObject *new;
2059+
PyObject *newobj;
20602060

2061-
new = PyString_FromStringAndSize(NULL, n);
2062-
if (new == NULL)
2061+
newobj = PyString_FromStringAndSize(NULL, n);
2062+
if (newobj == NULL)
20632063
return NULL;
2064-
s_new = PyString_AsString(new);
2064+
s_new = PyString_AsString(newobj);
20652065
for (i = 0; i < n; i++) {
20662066
int c = Py_CHARMASK(*s++);
20672067
if (islower(c)) {
@@ -2070,7 +2070,7 @@ string_upper(PyStringObject *self)
20702070
*s_new = c;
20712071
s_new++;
20722072
}
2073-
return new;
2073+
return newobj;
20742074
}
20752075

20762076

@@ -2086,12 +2086,12 @@ string_title(PyStringObject *self)
20862086
char *s = PyString_AS_STRING(self), *s_new;
20872087
Py_ssize_t i, n = PyString_GET_SIZE(self);
20882088
int previous_is_cased = 0;
2089-
PyObject *new;
2089+
PyObject *newobj;
20902090

2091-
new = PyString_FromStringAndSize(NULL, n);
2092-
if (new == NULL)
2091+
newobj = PyString_FromStringAndSize(NULL, n);
2092+
if (newobj == NULL)
20932093
return NULL;
2094-
s_new = PyString_AsString(new);
2094+
s_new = PyString_AsString(newobj);
20952095
for (i = 0; i < n; i++) {
20962096
int c = Py_CHARMASK(*s++);
20972097
if (islower(c)) {
@@ -2106,7 +2106,7 @@ string_title(PyStringObject *self)
21062106
previous_is_cased = 0;
21072107
*s_new++ = c;
21082108
}
2109-
return new;
2109+
return newobj;
21102110
}
21112111

21122112
PyDoc_STRVAR(capitalize__doc__,
@@ -2120,12 +2120,12 @@ string_capitalize(PyStringObject *self)
21202120
{
21212121
char *s = PyString_AS_STRING(self), *s_new;
21222122
Py_ssize_t i, n = PyString_GET_SIZE(self);
2123-
PyObject *new;
2123+
PyObject *newobj;
21242124

2125-
new = PyString_FromStringAndSize(NULL, n);
2126-
if (new == NULL)
2125+
newobj = PyString_FromStringAndSize(NULL, n);
2126+
if (newobj == NULL)
21272127
return NULL;
2128-
s_new = PyString_AsString(new);
2128+
s_new = PyString_AsString(newobj);
21292129
if (0 < n) {
21302130
int c = Py_CHARMASK(*s++);
21312131
if (islower(c))
@@ -2142,7 +2142,7 @@ string_capitalize(PyStringObject *self)
21422142
*s_new = c;
21432143
s_new++;
21442144
}
2145-
return new;
2145+
return newobj;
21462146
}
21472147

21482148

@@ -2199,7 +2199,7 @@ string_count(PyStringObject *self, PyObject *args)
21992199
}
22002200
if (i >= m)
22012201
break;
2202-
t = memchr(s+i, sub[0], m-i);
2202+
t = (const char *)memchr(s+i, sub[0], m-i);
22032203
if (t == NULL)
22042204
break;
22052205
i = t - s;
@@ -2218,12 +2218,12 @@ string_swapcase(PyStringObject *self)
22182218
{
22192219
char *s = PyString_AS_STRING(self), *s_new;
22202220
Py_ssize_t i, n = PyString_GET_SIZE(self);
2221-
PyObject *new;
2221+
PyObject *newobj;
22222222

2223-
new = PyString_FromStringAndSize(NULL, n);
2224-
if (new == NULL)
2223+
newobj = PyString_FromStringAndSize(NULL, n);
2224+
if (newobj == NULL)
22252225
return NULL;
2226-
s_new = PyString_AsString(new);
2226+
s_new = PyString_AsString(newobj);
22272227
for (i = 0; i < n; i++) {
22282228
int c = Py_CHARMASK(*s++);
22292229
if (islower(c)) {
@@ -2236,7 +2236,7 @@ string_swapcase(PyStringObject *self)
22362236
*s_new = c;
22372237
s_new++;
22382238
}
2239-
return new;
2239+
return newobj;
22402240
}
22412241

22422242

@@ -2524,7 +2524,7 @@ string_replace(PyStringObject *self, PyObject *args)
25242524
const Py_ssize_t len = PyString_GET_SIZE(self);
25252525
Py_ssize_t sub_len, repl_len, out_len;
25262526
int count = -1;
2527-
PyObject *new;
2527+
PyObject *newobj;
25282528
PyObject *subobj, *replobj;
25292529

25302530
if (!PyArg_ParseTuple(args, "OO|i:replace",
@@ -2563,20 +2563,20 @@ string_replace(PyStringObject *self, PyObject *args)
25632563
if (out_len == -1) {
25642564
if (PyString_CheckExact(self)) {
25652565
/* we're returning another reference to self */
2566-
new = (PyObject*)self;
2567-
Py_INCREF(new);
2566+
newobj = (PyObject*)self;
2567+
Py_INCREF(newobj);
25682568
}
25692569
else {
2570-
new = PyString_FromStringAndSize(str, len);
2571-
if (new == NULL)
2570+
newobj = PyString_FromStringAndSize(str, len);
2571+
if (newobj == NULL)
25722572
return NULL;
25732573
}
25742574
}
25752575
else {
2576-
new = PyString_FromStringAndSize(new_s, out_len);
2576+
newobj = PyString_FromStringAndSize(new_s, out_len);
25772577
PyMem_FREE(new_s);
25782578
}
2579-
return new;
2579+
return newobj;
25802580
}
25812581

25822582

Objects/tupleobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,24 +547,24 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
547547
static PyObject *
548548
tuple_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
549549
{
550-
PyObject *tmp, *new, *item;
550+
PyObject *tmp, *newobj, *item;
551551
Py_ssize_t i, n;
552552

553553
assert(PyType_IsSubtype(type, &PyTuple_Type));
554554
tmp = tuple_new(&PyTuple_Type, args, kwds);
555555
if (tmp == NULL)
556556
return NULL;
557557
assert(PyTuple_Check(tmp));
558-
new = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp));
559-
if (new == NULL)
558+
newobj = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp));
559+
if (newobj == NULL)
560560
return NULL;
561561
for (i = 0; i < n; i++) {
562562
item = PyTuple_GET_ITEM(tmp, i);
563563
Py_INCREF(item);
564-
PyTuple_SET_ITEM(new, i, item);
564+
PyTuple_SET_ITEM(newobj, i, item);
565565
}
566566
Py_DECREF(tmp);
567-
return new;
567+
return newobj;
568568
}
569569

570570
PyDoc_STRVAR(tuple_doc,

Objects/typeobject.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
453453
if (PyType_IS_GC(type))
454454
obj = _PyObject_GC_Malloc(size);
455455
else
456-
obj = PyObject_MALLOC(size);
456+
obj = (PyObject *)PyObject_MALLOC(size);
457457

458458
if (obj == NULL)
459459
return PyErr_NoMemory();
@@ -1150,7 +1150,7 @@ pmerge(PyObject *acc, PyObject* to_merge) {
11501150
remain[i] is the index of the next base in to_merge[i]
11511151
that is not included in acc.
11521152
*/
1153-
remain = PyMem_MALLOC(SIZEOF_INT*to_merge_size);
1153+
remain = (int *)PyMem_MALLOC(SIZEOF_INT*to_merge_size);
11541154
if (remain == NULL)
11551155
return -1;
11561156
for (i = 0; i < to_merge_size; i++)
@@ -1896,7 +1896,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
18961896
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
18971897
if (doc != NULL && PyString_Check(doc)) {
18981898
const size_t n = (size_t)PyString_GET_SIZE(doc);
1899-
char *tp_doc = PyObject_MALLOC(n+1);
1899+
char *tp_doc = (char *)PyObject_MALLOC(n+1);
19001900
if (tp_doc == NULL) {
19011901
Py_DECREF(type);
19021902
return NULL;
@@ -2446,23 +2446,23 @@ same_slots_added(PyTypeObject *a, PyTypeObject *b)
24462446
}
24472447

24482448
static int
2449-
compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
2449+
compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, char* attr)
24502450
{
24512451
PyTypeObject *newbase, *oldbase;
24522452

2453-
if (new->tp_dealloc != old->tp_dealloc ||
2454-
new->tp_free != old->tp_free)
2453+
if (newto->tp_dealloc != oldto->tp_dealloc ||
2454+
newto->tp_free != oldto->tp_free)
24552455
{
24562456
PyErr_Format(PyExc_TypeError,
24572457
"%s assignment: "
24582458
"'%s' deallocator differs from '%s'",
24592459
attr,
2460-
new->tp_name,
2461-
old->tp_name);
2460+
newto->tp_name,
2461+
oldto->tp_name);
24622462
return 0;
24632463
}
2464-
newbase = new;
2465-
oldbase = old;
2464+
newbase = newto;
2465+
oldbase = oldto;
24662466
while (equiv_structs(newbase, newbase->tp_base))
24672467
newbase = newbase->tp_base;
24682468
while (equiv_structs(oldbase, oldbase->tp_base))
@@ -2474,8 +2474,8 @@ compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
24742474
"%s assignment: "
24752475
"'%s' object layout differs from '%s'",
24762476
attr,
2477-
new->tp_name,
2478-
old->tp_name);
2477+
newto->tp_name,
2478+
oldto->tp_name);
24792479
return 0;
24802480
}
24812481

@@ -2485,8 +2485,8 @@ compatible_for_assignment(PyTypeObject* old, PyTypeObject* new, char* attr)
24852485
static int
24862486
object_set_class(PyObject *self, PyObject *value, void *closure)
24872487
{
2488-
PyTypeObject *old = self->ob_type;
2489-
PyTypeObject *new;
2488+
PyTypeObject *oldto = self->ob_type;
2489+
PyTypeObject *newto;
24902490

24912491
if (value == NULL) {
24922492
PyErr_SetString(PyExc_TypeError,
@@ -2499,18 +2499,18 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
24992499
value->ob_type->tp_name);
25002500
return -1;
25012501
}
2502-
new = (PyTypeObject *)value;
2503-
if (!(new->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
2504-
!(old->tp_flags & Py_TPFLAGS_HEAPTYPE))
2502+
newto = (PyTypeObject *)value;
2503+
if (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
2504+
!(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE))
25052505
{
25062506
PyErr_Format(PyExc_TypeError,
25072507
"__class__ assignment: only for heap types");
25082508
return -1;
25092509
}
2510-
if (compatible_for_assignment(new, old, "__class__")) {
2511-
Py_INCREF(new);
2512-
self->ob_type = new;
2513-
Py_DECREF(old);
2510+
if (compatible_for_assignment(newto, oldto, "__class__")) {
2511+
Py_INCREF(newto);
2512+
self->ob_type = newto;
2513+
Py_DECREF(oldto);
25142514
return 0;
25152515
}
25162516
else {
@@ -3332,7 +3332,7 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
33323332
{
33333333
Py_ssize_t i;
33343334
int result;
3335-
PyObject *list, *ref, *new;
3335+
PyObject *list, *ref, *newobj;
33363336

33373337
list = base->tp_subclasses;
33383338
if (list == NULL) {
@@ -3341,16 +3341,16 @@ add_subclass(PyTypeObject *base, PyTypeObject *type)
33413341
return -1;
33423342
}
33433343
assert(PyList_Check(list));
3344-
new = PyWeakref_NewRef((PyObject *)type, NULL);
3344+
newobj = PyWeakref_NewRef((PyObject *)type, NULL);
33453345
i = PyList_GET_SIZE(list);
33463346
while (--i >= 0) {
33473347
ref = PyList_GET_ITEM(list, i);
33483348
assert(PyWeakref_CheckRef(ref));
33493349
if (PyWeakref_GET_OBJECT(ref) == Py_None)
3350-
return PyList_SetItem(list, i, new);
3350+
return PyList_SetItem(list, i, newobj);
33513351
}
3352-
result = PyList_Append(list, new);
3353-
Py_DECREF(new);
3352+
result = PyList_Append(list, newobj);
3353+
Py_DECREF(newobj);
33543354
return result;
33553355
}
33563356

@@ -5746,7 +5746,7 @@ static PyObject *
57465746
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
57475747
{
57485748
superobject *su = (superobject *)self;
5749-
superobject *new;
5749+
superobject *newobj;
57505750

57515751
if (obj == NULL || obj == Py_None || su->obj != NULL) {
57525752
/* Not binding to an object, or already bound */
@@ -5763,16 +5763,16 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
57635763
PyTypeObject *obj_type = supercheck(su->type, obj);
57645764
if (obj_type == NULL)
57655765
return NULL;
5766-
new = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
5766+
newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
57675767
NULL, NULL);
5768-
if (new == NULL)
5768+
if (newobj == NULL)
57695769
return NULL;
57705770
Py_INCREF(su->type);
57715771
Py_INCREF(obj);
5772-
new->type = su->type;
5773-
new->obj = obj;
5774-
new->obj_type = obj_type;
5775-
return (PyObject *)new;
5772+
newobj->type = su->type;
5773+
newobj->obj = obj;
5774+
newobj->obj_type = obj_type;
5775+
return (PyObject *)newobj;
57765776
}
57775777
}
57785778

0 commit comments

Comments
 (0)