New errors.

This commit is contained in:
Guido van Rossum 1990-10-21 22:15:08 +00:00
parent 4ab9b4c9ad
commit 2a9096b5f9
7 changed files with 137 additions and 126 deletions

View File

@ -108,7 +108,7 @@ newclassmemberobject(class)
{ {
register classmemberobject *cm; register classmemberobject *cm;
if (!is_classobject(class)) { if (!is_classobject(class)) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
cm = NEWOBJ(classmemberobject, &Classmembertype); cm = NEWOBJ(classmemberobject, &Classmembertype);
@ -148,14 +148,14 @@ classmember_getattr(cm, name)
} }
v = class_getattr(cm->cm_class, name); v = class_getattr(cm->cm_class, name);
if (v == NULL) if (v == NULL)
return v; /* class_getattr() has set errno */ return v; /* class_getattr() has set the error */
if (is_funcobject(v)) { if (is_funcobject(v)) {
object *w = newclassmethodobject(v, (object *)cm); object *w = newclassmethodobject(v, (object *)cm);
DECREF(v); DECREF(v);
return w; return w;
} }
DECREF(v); DECREF(v);
errno = ESRCH; err_setstr(NameError, name);
return NULL; return NULL;
} }
@ -205,7 +205,7 @@ newclassmethodobject(func, self)
{ {
register classmethodobject *cm; register classmethodobject *cm;
if (!is_funcobject(func)) { if (!is_funcobject(func)) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
cm = NEWOBJ(classmethodobject, &Classmethodtype); cm = NEWOBJ(classmethodobject, &Classmethodtype);
@ -223,7 +223,7 @@ classmethodgetfunc(cm)
register object *cm; register object *cm;
{ {
if (!is_classmethodobject(cm)) { if (!is_classmethodobject(cm)) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
return ((classmethodobject *)cm)->cm_func; return ((classmethodobject *)cm)->cm_func;
@ -234,7 +234,7 @@ classmethodgetself(cm)
register object *cm; register object *cm;
{ {
if (!is_classmethodobject(cm)) { if (!is_classmethodobject(cm)) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
return ((classmethodobject *)cm)->cm_self; return ((classmethodobject *)cm)->cm_self;

View File

@ -1,5 +1,8 @@
/* Float object implementation */ /* Float object implementation */
/* XXX There should be overflow checks here, but it's hard to check
for any kind of float exception without losing portability. */
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
@ -9,6 +12,7 @@
#include "floatobject.h" #include "floatobject.h"
#include "stringobject.h" #include "stringobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "errors.h"
object * object *
newfloatobject(fval) newfloatobject(fval)
@ -16,14 +20,11 @@ newfloatobject(fval)
{ {
/* For efficiency, this code is copied from newobject() */ /* For efficiency, this code is copied from newobject() */
register floatobject *op = (floatobject *) malloc(sizeof(floatobject)); register floatobject *op = (floatobject *) malloc(sizeof(floatobject));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
}
else {
NEWREF(op); NEWREF(op);
op->ob_type = &Floattype; op->ob_type = &Floattype;
op->ob_fval = fval; op->ob_fval = fval;
}
return (object *) op; return (object *) op;
} }
@ -32,7 +33,7 @@ getfloatvalue(op)
object *op; object *op;
{ {
if (!is_floatobject(op)) { if (!is_floatobject(op)) {
errno = EBADF; err_badarg();
return -1; return -1;
} }
else else
@ -104,7 +105,7 @@ float_add(v, w)
object *w; object *w;
{ {
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
return newfloatobject(v->ob_fval + ((floatobject *)w) -> ob_fval); return newfloatobject(v->ob_fval + ((floatobject *)w) -> ob_fval);
@ -116,7 +117,7 @@ float_sub(v, w)
object *w; object *w;
{ {
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
return newfloatobject(v->ob_fval - ((floatobject *)w) -> ob_fval); return newfloatobject(v->ob_fval - ((floatobject *)w) -> ob_fval);
@ -128,7 +129,7 @@ float_mul(v, w)
object *w; object *w;
{ {
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
return newfloatobject(v->ob_fval * ((floatobject *)w) -> ob_fval); return newfloatobject(v->ob_fval * ((floatobject *)w) -> ob_fval);
@ -140,11 +141,11 @@ float_div(v, w)
object *w; object *w;
{ {
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
if (((floatobject *)w) -> ob_fval == 0) { if (((floatobject *)w) -> ob_fval == 0) {
errno = EDOM; err_setstr(ZeroDivisionError, "float division by zero");
return NULL; return NULL;
} }
return newfloatobject(v->ob_fval / ((floatobject *)w) -> ob_fval); return newfloatobject(v->ob_fval / ((floatobject *)w) -> ob_fval);
@ -158,12 +159,12 @@ float_rem(v, w)
double wx; double wx;
extern double fmod(); extern double fmod();
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
wx = ((floatobject *)w) -> ob_fval; wx = ((floatobject *)w) -> ob_fval;
if (wx == 0.0) { if (wx == 0.0) {
errno = EDOM; err_setstr(ZeroDivisionError, "float division by zero");
return NULL; return NULL;
} }
return newfloatobject(fmod(v->ob_fval, wx)); return newfloatobject(fmod(v->ob_fval, wx));
@ -177,16 +178,20 @@ float_pow(v, w)
double iv, iw, ix; double iv, iw, ix;
extern double pow(); extern double pow();
if (!is_floatobject(w)) { if (!is_floatobject(w)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
iv = v->ob_fval; iv = v->ob_fval;
iw = ((floatobject *)w)->ob_fval; iw = ((floatobject *)w)->ob_fval;
if (iw == 0.0)
return newfloatobject(1.0); /* x**0 is always 1, even 0**0 */
errno = 0; errno = 0;
ix = pow(iv, iw); ix = pow(iv, iw);
if (errno != 0) if (errno != 0) {
/* XXX could it be another type of error? */
err_errno(OverflowError);
return NULL; return NULL;
else }
return newfloatobject(ix); return newfloatobject(ix);
} }

View File

@ -36,7 +36,7 @@ getfuncnode(op)
object *op; object *op;
{ {
if (!is_funcobject(op)) { if (!is_funcobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
return ((funcobject *) op) -> func_node; return ((funcobject *) op) -> func_node;
@ -47,7 +47,7 @@ getfuncglobals(op)
object *op; object *op;
{ {
if (!is_funcobject(op)) { if (!is_funcobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
return ((funcobject *) op) -> func_globals; return ((funcobject *) op) -> func_globals;

View File

@ -11,6 +11,7 @@
#include "listobject.h" #include "listobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "modsupport.h" #include "modsupport.h"
#include "errors.h"
typedef struct { typedef struct {
OB_VARHEAD OB_VARHEAD
@ -24,13 +25,12 @@ newlistobject(size)
int i; int i;
listobject *op; listobject *op;
if (size < 0) { if (size < 0) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
op = (listobject *) malloc(sizeof(listobject)); op = (listobject *) malloc(sizeof(listobject));
if (op == NULL) { if (op == NULL) {
errno = ENOMEM; return err_nomem();
return NULL;
} }
if (size <= 0) { if (size <= 0) {
op->ob_item = NULL; op->ob_item = NULL;
@ -39,8 +39,7 @@ newlistobject(size)
op->ob_item = (object **) malloc(size * sizeof(object *)); op->ob_item = (object **) malloc(size * sizeof(object *));
if (op->ob_item == NULL) { if (op->ob_item == NULL) {
free((ANY *)op); free((ANY *)op);
errno = ENOMEM; return err_nomem();
return NULL;
} }
} }
NEWREF(op); NEWREF(op);
@ -56,7 +55,7 @@ getlistsize(op)
object *op; object *op;
{ {
if (!is_listobject(op)) { if (!is_listobject(op)) {
errno = EBADF; err_badcall();
return -1; return -1;
} }
else else
@ -69,11 +68,11 @@ getlistitem(op, i)
int i; int i;
{ {
if (!is_listobject(op)) { if (!is_listobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
if (i < 0 || i >= ((listobject *)op) -> ob_size) { if (i < 0 || i >= ((listobject *)op) -> ob_size) {
errno = EDOM; err_setstr(IndexError, "list index out of range");
return NULL; return NULL;
} }
return ((listobject *)op) -> ob_item[i]; return ((listobject *)op) -> ob_item[i];
@ -89,12 +88,14 @@ setlistitem(op, i, newitem)
if (!is_listobject(op)) { if (!is_listobject(op)) {
if (newitem != NULL) if (newitem != NULL)
DECREF(newitem); DECREF(newitem);
return errno = EBADF; err_badcall();
return -1;
} }
if (i < 0 || i >= ((listobject *)op) -> ob_size) { if (i < 0 || i >= ((listobject *)op) -> ob_size) {
if (newitem != NULL) if (newitem != NULL)
DECREF(newitem); DECREF(newitem);
return errno = EDOM; err_setstr(IndexError, "list assignment index out of range");
return -1;
} }
olditem = ((listobject *)op) -> ob_item[i]; olditem = ((listobject *)op) -> ob_item[i];
((listobject *)op) -> ob_item[i] = newitem; ((listobject *)op) -> ob_item[i] = newitem;
@ -111,12 +112,16 @@ ins1(self, where, v)
{ {
int i; int i;
object **items; object **items;
if (v == NULL) if (v == NULL) {
return errno = EINVAL; err_badcall();
return -1;
}
items = self->ob_item; items = self->ob_item;
RESIZE(items, object *, self->ob_size+1); RESIZE(items, object *, self->ob_size+1);
if (items == NULL) if (items == NULL) {
return errno = ENOMEM; err_nomem();
return -1;
}
if (where < 0) if (where < 0)
where = 0; where = 0;
if (where > self->ob_size) if (where > self->ob_size)
@ -136,8 +141,10 @@ inslistitem(op, where, newitem)
int where; int where;
object *newitem; object *newitem;
{ {
if (!is_listobject(op)) if (!is_listobject(op)) {
return errno = EBADF; err_badcall();
return -1;
}
return ins1((listobject *)op, where, newitem); return ins1((listobject *)op, where, newitem);
} }
@ -146,8 +153,10 @@ addlistitem(op, newitem)
object *op; object *op;
object *newitem; object *newitem;
{ {
if (!is_listobject(op)) if (!is_listobject(op)) {
return errno = EBADF; err_badcall();
return -1;
}
return ins1((listobject *)op, return ins1((listobject *)op,
(int) ((listobject *)op)->ob_size, newitem); (int) ((listobject *)op)->ob_size, newitem);
} }
@ -234,7 +243,7 @@ list_item(a, i)
int i; int i;
{ {
if (i < 0 || i >= a->ob_size) { if (i < 0 || i >= a->ob_size) {
errno = EDOM; err_setstr(IndexError, "list index out of range");
return NULL; return NULL;
} }
INCREF(a->ob_item[i]); INCREF(a->ob_item[i]);
@ -278,15 +287,14 @@ list_concat(a, bb)
int i; int i;
listobject *np; listobject *np;
if (!is_listobject(bb)) { if (!is_listobject(bb)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
#define b ((listobject *)bb) #define b ((listobject *)bb)
size = a->ob_size + b->ob_size; size = a->ob_size + b->ob_size;
np = (listobject *) newlistobject(size); np = (listobject *) newlistobject(size);
if (np == NULL) { if (np == NULL) {
errno = ENOMEM; return err_nomem();
return NULL;
} }
for (i = 0; i < a->ob_size; i++) { for (i = 0; i < a->ob_size; i++) {
object *v = a->ob_item[i]; object *v = a->ob_item[i];
@ -308,8 +316,10 @@ list_ass_item(a, i, v)
int i; int i;
object *v; object *v;
{ {
if (i < 0 || i >= a->ob_size) if (i < 0 || i >= a->ob_size) {
return errno = EDOM; err_setstr(IndexError, "list assignment index out of range");
return -1;
}
if (v == NULL) if (v == NULL)
return list_ass_slice(a, i, i+1, v); return list_ass_slice(a, i, i+1, v);
INCREF(v); INCREF(v);
@ -333,8 +343,10 @@ list_ass_slice(a, ilow, ihigh, v)
n = 0; n = 0;
else if (is_listobject(v)) else if (is_listobject(v))
n = b->ob_size; n = b->ob_size;
else else {
return errno = EINVAL; err_badarg();
return -1;
}
if (ilow < 0) if (ilow < 0)
ilow = 0; ilow = 0;
else if (ilow > a->ob_size) else if (ilow > a->ob_size)
@ -360,8 +372,10 @@ list_ass_slice(a, ilow, ihigh, v)
} }
else { /* Insert d items; DECREF ihigh-ilow items */ else { /* Insert d items; DECREF ihigh-ilow items */
RESIZE(item, object *, a->ob_size + d); RESIZE(item, object *, a->ob_size + d);
if (item == NULL) if (item == NULL) {
return errno = ENOMEM; err_nomem();
return -1;
}
for (k = a->ob_size; --k >= ihigh; ) for (k = a->ob_size; --k >= ihigh; )
item[k+d] = item[k]; item[k+d] = item[k];
for (/*k = ihigh-1*/; k >= ilow; --k) for (/*k = ihigh-1*/; k >= ilow; --k)
@ -397,7 +411,7 @@ listinsert(self, args)
{ {
int i; int i;
if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) { if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
if (!getintarg(gettupleitem(args, 0), &i)) if (!getintarg(gettupleitem(args, 0), &i))
@ -426,14 +440,14 @@ listsort(self, args)
object *args; object *args;
{ {
if (args != NULL) { if (args != NULL) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
errno = 0; err_clear();
if (self->ob_size > 1) if (self->ob_size > 1)
qsort((char *)self->ob_item, qsort((char *)self->ob_item,
(int) self->ob_size, sizeof(object *), cmp); (int) self->ob_size, sizeof(object *), cmp);
if (errno != 0) if (err_occurred())
return NULL; return NULL;
INCREF(None); INCREF(None);
return None; return None;

View File

@ -9,6 +9,7 @@
#include "methodobject.h" #include "methodobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "token.h" #include "token.h"
#include "errors.h"
typedef struct { typedef struct {
OB_HEAD OB_HEAD
@ -39,7 +40,7 @@ getmethod(op)
object *op; object *op;
{ {
if (!is_methodobject(op)) { if (!is_methodobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
return ((methodobject *)op) -> m_meth; return ((methodobject *)op) -> m_meth;
@ -50,7 +51,7 @@ getself(op)
object *op; object *op;
{ {
if (!is_methodobject(op)) { if (!is_methodobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
return ((methodobject *)op) -> m_self; return ((methodobject *)op) -> m_self;

View File

@ -7,6 +7,7 @@
#include "stringobject.h" #include "stringobject.h"
#include "intobject.h" #include "intobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "errors.h"
object * object *
newsizedstringobject(str, size) newsizedstringobject(str, size)
@ -15,17 +16,14 @@ newsizedstringobject(str, size)
{ {
register stringobject *op = (stringobject *) register stringobject *op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char)); malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
}
else {
NEWREF(op); NEWREF(op);
op->ob_type = &Stringtype; op->ob_type = &Stringtype;
op->ob_size = size; op->ob_size = size;
if (str != NULL) if (str != NULL)
memcpy(op->ob_sval, str, size); memcpy(op->ob_sval, str, size);
op->ob_sval[size] = '\0'; op->ob_sval[size] = '\0';
}
return (object *) op; return (object *) op;
} }
@ -36,15 +34,12 @@ newstringobject(str)
register unsigned int size = strlen(str); register unsigned int size = strlen(str);
register stringobject *op = (stringobject *) register stringobject *op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char)); malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
}
else {
NEWREF(op); NEWREF(op);
op->ob_type = &Stringtype; op->ob_type = &Stringtype;
op->ob_size = size; op->ob_size = size;
strcpy(op->ob_sval, str); strcpy(op->ob_sval, str);
}
return (object *) op; return (object *) op;
} }
@ -53,7 +48,7 @@ getstringsize(op)
register object *op; register object *op;
{ {
if (!is_stringobject(op)) { if (!is_stringobject(op)) {
errno = EBADF; err_badcall();
return -1; return -1;
} }
return ((stringobject *)op) -> ob_size; return ((stringobject *)op) -> ob_size;
@ -64,7 +59,7 @@ getstringvalue(op)
register object *op; register object *op;
{ {
if (!is_stringobject(op)) { if (!is_stringobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
return ((stringobject *)op) -> ob_sval; return ((stringobject *)op) -> ob_sval;
@ -105,7 +100,7 @@ stringrepr(op)
int newsize = 2 + 4 * op->ob_size * sizeof(char); int newsize = 2 + 4 * op->ob_size * sizeof(char);
object *v = newsizedstringobject((char *)NULL, newsize); object *v = newsizedstringobject((char *)NULL, newsize);
if (v == NULL) { if (v == NULL) {
errno = ENOMEM; return err_nomem();
} }
else { else {
register int i; register int i;
@ -132,9 +127,9 @@ stringrepr(op)
*p++ = '\''; *p++ = '\'';
*p = '\0'; *p = '\0';
resizestring(&v, (int) (p - ((stringobject *)v)->ob_sval)); resizestring(&v, (int) (p - ((stringobject *)v)->ob_sval));
}
return v; return v;
} }
}
static int static int
stringlength(a) stringlength(a)
@ -151,7 +146,7 @@ stringconcat(a, bb)
register unsigned int size; register unsigned int size;
register stringobject *op; register stringobject *op;
if (!is_stringobject(bb)) { if (!is_stringobject(bb)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
#define b ((stringobject *)bb) #define b ((stringobject *)bb)
@ -167,17 +162,14 @@ stringconcat(a, bb)
size = a->ob_size + b->ob_size; size = a->ob_size + b->ob_size;
op = (stringobject *) op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char)); malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
}
else {
NEWREF(op); NEWREF(op);
op->ob_type = &Stringtype; op->ob_type = &Stringtype;
op->ob_size = size; op->ob_size = size;
memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size); memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size); memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size);
op->ob_sval[size] = '\0'; op->ob_sval[size] = '\0';
}
return (object *) op; return (object *) op;
#undef b #undef b
} }
@ -199,17 +191,14 @@ stringrepeat(a, n)
} }
op = (stringobject *) op = (stringobject *)
malloc(sizeof(stringobject) + size * sizeof(char)); malloc(sizeof(stringobject) + size * sizeof(char));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
}
else {
NEWREF(op); NEWREF(op);
op->ob_type = &Stringtype; op->ob_type = &Stringtype;
op->ob_size = size; op->ob_size = size;
for (i = 0; i < size; i += a->ob_size) for (i = 0; i < size; i += a->ob_size)
memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size); memcpy(op->ob_sval+i, a->ob_sval, (int) a->ob_size);
op->ob_sval[size] = '\0'; op->ob_sval[size] = '\0';
}
return (object *) op; return (object *) op;
} }
@ -241,7 +230,7 @@ stringitem(a, i)
register int i; register int i;
{ {
if (i < 0 || i >= a->ob_size) { if (i < 0 || i >= a->ob_size) {
errno = EDOM; err_setstr(IndexError, "string index out of range");
return NULL; return NULL;
} }
return stringslice(a, i, i+1); return stringslice(a, i, i+1);
@ -312,14 +301,16 @@ resizestring(pv, newsize)
if (!is_stringobject(v) || v->ob_refcnt != 1) { if (!is_stringobject(v) || v->ob_refcnt != 1) {
*pv = 0; *pv = 0;
DECREF(v); DECREF(v);
return errno = EBADF; err_badcall();
return -1;
} }
*pv = (object *) *pv = (object *)
realloc((char *)v, realloc((char *)v,
sizeof(stringobject) + newsize * sizeof(char)); sizeof(stringobject) + newsize * sizeof(char));
if (*pv == NULL) { if (*pv == NULL) {
DECREF(v); DECREF(v);
return errno = ENOMEM; err_nomem();
return -1;
} }
v = (stringobject *) *pv; v = (stringobject *) *pv;
v->ob_size = newsize; v->ob_size = newsize;

View File

@ -8,6 +8,7 @@
#include "tupleobject.h" #include "tupleobject.h"
#include "intobject.h" #include "intobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "errors.h"
typedef struct { typedef struct {
OB_VARHEAD OB_VARHEAD
@ -21,15 +22,13 @@ newtupleobject(size)
register int i; register int i;
register tupleobject *op; register tupleobject *op;
if (size < 0) { if (size < 0) {
errno = EINVAL; err_badcall();
return NULL; return NULL;
} }
op = (tupleobject *) op = (tupleobject *)
malloc(sizeof(tupleobject) + size * sizeof(object *)); malloc(sizeof(tupleobject) + size * sizeof(object *));
if (op == NULL) { if (op == NULL)
errno = ENOMEM; return err_nomem();
return NULL;
}
NEWREF(op); NEWREF(op);
op->ob_type = &Tupletype; op->ob_type = &Tupletype;
op->ob_size = size; op->ob_size = size;
@ -43,7 +42,7 @@ gettuplesize(op)
register object *op; register object *op;
{ {
if (!is_tupleobject(op)) { if (!is_tupleobject(op)) {
errno = EBADF; err_badcall();
return -1; return -1;
} }
else else
@ -56,11 +55,11 @@ gettupleitem(op, i)
register int i; register int i;
{ {
if (!is_tupleobject(op)) { if (!is_tupleobject(op)) {
errno = EBADF; err_badcall();
return NULL; return NULL;
} }
if (i < 0 || i >= ((tupleobject *)op) -> ob_size) { if (i < 0 || i >= ((tupleobject *)op) -> ob_size) {
errno = EDOM; err_setstr(IndexError, "tuple index out of range");
return NULL; return NULL;
} }
return ((tupleobject *)op) -> ob_item[i]; return ((tupleobject *)op) -> ob_item[i];
@ -76,12 +75,14 @@ settupleitem(op, i, newitem)
if (!is_tupleobject(op)) { if (!is_tupleobject(op)) {
if (newitem != NULL) if (newitem != NULL)
DECREF(newitem); DECREF(newitem);
return errno = EBADF; err_badcall();
return -1;
} }
if (i < 0 || i >= ((tupleobject *)op) -> ob_size) { if (i < 0 || i >= ((tupleobject *)op) -> ob_size) {
if (newitem != NULL) if (newitem != NULL)
DECREF(newitem); DECREF(newitem);
return errno = EDOM; err_setstr(IndexError, "tuple assignment index out of range");
return -1;
} }
olditem = ((tupleobject *)op) -> ob_item[i]; olditem = ((tupleobject *)op) -> ob_item[i];
((tupleobject *)op) -> ob_item[i] = newitem; ((tupleobject *)op) -> ob_item[i] = newitem;
@ -179,7 +180,7 @@ tupleitem(a, i)
register int i; register int i;
{ {
if (i < 0 || i >= a->ob_size) { if (i < 0 || i >= a->ob_size) {
errno = EDOM; err_setstr(IndexError, "tuple index out of range");
return NULL; return NULL;
} }
INCREF(a->ob_item[i]); INCREF(a->ob_item[i]);
@ -224,15 +225,14 @@ tupleconcat(a, bb)
register int i; register int i;
tupleobject *np; tupleobject *np;
if (!is_tupleobject(bb)) { if (!is_tupleobject(bb)) {
errno = EINVAL; err_badarg();
return NULL; return NULL;
} }
#define b ((tupleobject *)bb) #define b ((tupleobject *)bb)
size = a->ob_size + b->ob_size; size = a->ob_size + b->ob_size;
np = (tupleobject *) newtupleobject(size); np = (tupleobject *) newtupleobject(size);
if (np == NULL) { if (np == NULL) {
errno = ENOMEM; return err_nomem();
return NULL;
} }
for (i = 0; i < a->ob_size; i++) { for (i = 0; i < a->ob_size; i++) {
object *v = a->ob_item[i]; object *v = a->ob_item[i];