Skip to content

Commit

Permalink
New errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Oct 21, 1990
1 parent 4ab9b4c commit 2a9096b
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 126 deletions.
12 changes: 6 additions & 6 deletions Objects/classobject.c
Expand Up @@ -108,7 +108,7 @@ newclassmemberobject(class)
{
register classmemberobject *cm;
if (!is_classobject(class)) {
errno = EINVAL;
err_badcall();
return NULL;
}
cm = NEWOBJ(classmemberobject, &Classmembertype);
Expand Down Expand Up @@ -148,14 +148,14 @@ classmember_getattr(cm, name)
}
v = class_getattr(cm->cm_class, name);
if (v == NULL)
return v; /* class_getattr() has set errno */
return v; /* class_getattr() has set the error */
if (is_funcobject(v)) {
object *w = newclassmethodobject(v, (object *)cm);
DECREF(v);
return w;
}
DECREF(v);
errno = ESRCH;
err_setstr(NameError, name);
return NULL;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ newclassmethodobject(func, self)
{
register classmethodobject *cm;
if (!is_funcobject(func)) {
errno = EINVAL;
err_badcall();
return NULL;
}
cm = NEWOBJ(classmethodobject, &Classmethodtype);
Expand All @@ -223,7 +223,7 @@ classmethodgetfunc(cm)
register object *cm;
{
if (!is_classmethodobject(cm)) {
errno = EINVAL;
err_badcall();
return NULL;
}
return ((classmethodobject *)cm)->cm_func;
Expand All @@ -234,7 +234,7 @@ classmethodgetself(cm)
register object *cm;
{
if (!is_classmethodobject(cm)) {
errno = EINVAL;
err_badcall();
return NULL;
}
return ((classmethodobject *)cm)->cm_self;
Expand Down
45 changes: 25 additions & 20 deletions Objects/floatobject.c
@@ -1,5 +1,8 @@
/* 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 <math.h>
#include <ctype.h>
Expand All @@ -9,21 +12,19 @@
#include "floatobject.h"
#include "stringobject.h"
#include "objimpl.h"
#include "errors.h"

object *
newfloatobject(fval)
double fval;
{
/* For efficiency, this code is copied from newobject() */
register floatobject *op = (floatobject *) malloc(sizeof(floatobject));
if (op == NULL) {
errno = ENOMEM;
}
else {
NEWREF(op);
op->ob_type = &Floattype;
op->ob_fval = fval;
}
if (op == NULL)
return err_nomem();
NEWREF(op);
op->ob_type = &Floattype;
op->ob_fval = fval;
return (object *) op;
}

Expand All @@ -32,7 +33,7 @@ getfloatvalue(op)
object *op;
{
if (!is_floatobject(op)) {
errno = EBADF;
err_badarg();
return -1;
}
else
Expand Down Expand Up @@ -104,7 +105,7 @@ float_add(v, w)
object *w;
{
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
return newfloatobject(v->ob_fval + ((floatobject *)w) -> ob_fval);
Expand All @@ -116,7 +117,7 @@ float_sub(v, w)
object *w;
{
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
return newfloatobject(v->ob_fval - ((floatobject *)w) -> ob_fval);
Expand All @@ -128,7 +129,7 @@ float_mul(v, w)
object *w;
{
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
return newfloatobject(v->ob_fval * ((floatobject *)w) -> ob_fval);
Expand All @@ -140,11 +141,11 @@ float_div(v, w)
object *w;
{
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
if (((floatobject *)w) -> ob_fval == 0) {
errno = EDOM;
err_setstr(ZeroDivisionError, "float division by zero");
return NULL;
}
return newfloatobject(v->ob_fval / ((floatobject *)w) -> ob_fval);
Expand All @@ -158,12 +159,12 @@ float_rem(v, w)
double wx;
extern double fmod();
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
wx = ((floatobject *)w) -> ob_fval;
if (wx == 0.0) {
errno = EDOM;
err_setstr(ZeroDivisionError, "float division by zero");
return NULL;
}
return newfloatobject(fmod(v->ob_fval, wx));
Expand All @@ -177,17 +178,21 @@ float_pow(v, w)
double iv, iw, ix;
extern double pow();
if (!is_floatobject(w)) {
errno = EINVAL;
err_badarg();
return NULL;
}
iv = v->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;
ix = pow(iv, iw);
if (errno != 0)
if (errno != 0) {
/* XXX could it be another type of error? */
err_errno(OverflowError);
return NULL;
else
return newfloatobject(ix);
}
return newfloatobject(ix);
}

static object *
Expand Down
4 changes: 2 additions & 2 deletions Objects/funcobject.c
Expand Up @@ -36,7 +36,7 @@ getfuncnode(op)
object *op;
{
if (!is_funcobject(op)) {
errno = EBADF;
err_badcall();
return NULL;
}
return ((funcobject *) op) -> func_node;
Expand All @@ -47,7 +47,7 @@ getfuncglobals(op)
object *op;
{
if (!is_funcobject(op)) {
errno = EBADF;
err_badcall();
return NULL;
}
return ((funcobject *) op) -> func_globals;
Expand Down

0 comments on commit 2a9096b

Please sign in to comment.