mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
Correct problems found by THINK C 6.0
This commit is contained in:
parent
f4b1a64a21
commit
6cd2fe043b
1 changed files with 67 additions and 44 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||||
Amsterdam, The Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
@ -27,6 +27,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
|
#ifdef STDC_HEADERS
|
||||||
|
#include <stddef.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h> /* For size_t */
|
||||||
|
#endif
|
||||||
|
|
||||||
object *
|
object *
|
||||||
newlistobject(size)
|
newlistobject(size)
|
||||||
|
|
@ -34,7 +39,7 @@ newlistobject(size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
listobject *op;
|
listobject *op;
|
||||||
MALLARG nbytes;
|
size_t nbytes;
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
err_badcall();
|
err_badcall();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -211,21 +216,17 @@ static object *
|
||||||
list_repr(v)
|
list_repr(v)
|
||||||
listobject *v;
|
listobject *v;
|
||||||
{
|
{
|
||||||
object *s, *t, *comma;
|
object *s, *comma;
|
||||||
int i;
|
int i;
|
||||||
s = newstringobject("[");
|
s = newstringobject("[");
|
||||||
comma = newstringobject(", ");
|
comma = newstringobject(", ");
|
||||||
for (i = 0; i < v->ob_size && s != NULL; i++) {
|
for (i = 0; i < v->ob_size && s != NULL; i++) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
joinstring(&s, comma);
|
joinstring(&s, comma);
|
||||||
t = reprobject(v->ob_item[i]);
|
joinstring_decref(&s, reprobject(v->ob_item[i]));
|
||||||
joinstring(&s, t);
|
|
||||||
DECREF(t);
|
|
||||||
}
|
}
|
||||||
DECREF(comma);
|
XDECREF(comma);
|
||||||
t = newstringobject("]");
|
joinstring_decref(&s, newstringobject("]"));
|
||||||
joinstring(&s, t);
|
|
||||||
DECREF(t);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -500,15 +501,11 @@ listappend(self, args)
|
||||||
return ins(self, (int) self->ob_size, v);
|
return ins(self, (int) self->ob_size, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *cmpfunc;
|
static object *comparefunc;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmp(v, w)
|
cmp(v, w)
|
||||||
#ifdef __STDC__
|
const ANY *v, *w;
|
||||||
void *v, *w;
|
|
||||||
#else
|
|
||||||
char *v, *w;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
object *t, *res;
|
object *t, *res;
|
||||||
long i;
|
long i;
|
||||||
|
|
@ -516,14 +513,14 @@ cmp(v, w)
|
||||||
if (err_occurred())
|
if (err_occurred())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (cmpfunc == NULL)
|
if (comparefunc == NULL)
|
||||||
return cmpobject(* (object **) v, * (object **) w);
|
return cmpobject(* (object **) v, * (object **) w);
|
||||||
|
|
||||||
/* Call the user-supplied comparison function */
|
/* Call the user-supplied comparison function */
|
||||||
t = mkvalue("OO", * (object **) v, * (object **) w);
|
t = mkvalue("OO", * (object **) v, * (object **) w);
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
res = call_object(cmpfunc, t);
|
res = call_object(comparefunc, t);
|
||||||
DECREF(t);
|
DECREF(t);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -547,24 +544,24 @@ listsort(self, args)
|
||||||
listobject *self;
|
listobject *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *save_cmpfunc;
|
object *save_comparefunc;
|
||||||
if (self->ob_size <= 1) {
|
if (self->ob_size <= 1) {
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
save_cmpfunc = cmpfunc;
|
save_comparefunc = comparefunc;
|
||||||
cmpfunc = args;
|
comparefunc = args;
|
||||||
if (cmpfunc != NULL) {
|
if (comparefunc != NULL) {
|
||||||
/* Test the comparison function for obvious errors */
|
/* Test the comparison function for obvious errors */
|
||||||
(void) cmp(&self->ob_item[0], &self->ob_item[1]);
|
(void) cmp((ANY *)&self->ob_item[0], (ANY *)&self->ob_item[1]);
|
||||||
if (err_occurred()) {
|
if (err_occurred()) {
|
||||||
cmpfunc = save_cmpfunc;
|
comparefunc = save_comparefunc;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qsort((char *)self->ob_item,
|
qsort((char *)self->ob_item,
|
||||||
(int) self->ob_size, sizeof(object *), cmp);
|
(int) self->ob_size, sizeof(object *), cmp);
|
||||||
cmpfunc = save_cmpfunc;
|
comparefunc = save_comparefunc;
|
||||||
if (err_occurred())
|
if (err_occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
|
|
@ -612,6 +609,32 @@ sortlist(v)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object *
|
||||||
|
listtuple(v)
|
||||||
|
object *v;
|
||||||
|
{
|
||||||
|
object *w;
|
||||||
|
object **p;
|
||||||
|
int n;
|
||||||
|
if (v == NULL || !is_listobject(v)) {
|
||||||
|
err_badcall();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
n = ((listobject *)v)->ob_size;
|
||||||
|
w = newtupleobject(n);
|
||||||
|
if (w == NULL)
|
||||||
|
return NULL;
|
||||||
|
p = ((tupleobject *)w)->ob_item;
|
||||||
|
memcpy((ANY *)p,
|
||||||
|
(ANY *)((listobject *)v)->ob_item,
|
||||||
|
n*sizeof(object *));
|
||||||
|
while (--n >= 0) {
|
||||||
|
INCREF(*p);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
listindex(self, args)
|
listindex(self, args)
|
||||||
listobject *self;
|
listobject *self;
|
||||||
|
|
@ -675,13 +698,13 @@ listremove(self, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist list_methods[] = {
|
static struct methodlist list_methods[] = {
|
||||||
{"append", listappend},
|
{"append", (method)listappend},
|
||||||
{"count", listcount},
|
{"count", (method)listcount},
|
||||||
{"index", listindex},
|
{"index", (method)listindex},
|
||||||
{"insert", listinsert},
|
{"insert", (method)listinsert},
|
||||||
{"sort", listsort},
|
{"sort", (method)listsort},
|
||||||
{"remove", listremove},
|
{"remove", (method)listremove},
|
||||||
{"reverse", listreverse},
|
{"reverse", (method)listreverse},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -694,13 +717,13 @@ list_getattr(f, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
static sequence_methods list_as_sequence = {
|
static sequence_methods list_as_sequence = {
|
||||||
list_length, /*sq_length*/
|
(inquiry)list_length, /*sq_length*/
|
||||||
list_concat, /*sq_concat*/
|
(binaryfunc)list_concat, /*sq_concat*/
|
||||||
list_repeat, /*sq_repeat*/
|
(intargfunc)list_repeat, /*sq_repeat*/
|
||||||
list_item, /*sq_item*/
|
(intargfunc)list_item, /*sq_item*/
|
||||||
list_slice, /*sq_slice*/
|
(intintargfunc)list_slice, /*sq_slice*/
|
||||||
list_ass_item, /*sq_ass_item*/
|
(intobjargproc)list_ass_item, /*sq_ass_item*/
|
||||||
list_ass_slice, /*sq_ass_slice*/
|
(intintobjargproc)list_ass_slice, /*sq_ass_slice*/
|
||||||
};
|
};
|
||||||
|
|
||||||
typeobject Listtype = {
|
typeobject Listtype = {
|
||||||
|
|
@ -709,12 +732,12 @@ typeobject Listtype = {
|
||||||
"list",
|
"list",
|
||||||
sizeof(listobject),
|
sizeof(listobject),
|
||||||
0,
|
0,
|
||||||
list_dealloc, /*tp_dealloc*/
|
(destructor)list_dealloc, /*tp_dealloc*/
|
||||||
list_print, /*tp_print*/
|
(printfunc)list_print, /*tp_print*/
|
||||||
list_getattr, /*tp_getattr*/
|
(getattrfunc)list_getattr, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
list_compare, /*tp_compare*/
|
(cmpfunc)list_compare, /*tp_compare*/
|
||||||
list_repr, /*tp_repr*/
|
(reprfunc)list_repr, /*tp_repr*/
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
&list_as_sequence, /*tp_as_sequence*/
|
&list_as_sequence, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue