Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a9096b

Browse files
committed
New errors.
1 parent 4ab9b4c commit 2a9096b

7 files changed

Lines changed: 137 additions & 126 deletions

File tree

Objects/classobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ newclassmemberobject(class)
108108
{
109109
register classmemberobject *cm;
110110
if (!is_classobject(class)) {
111-
errno = EINVAL;
111+
err_badcall();
112112
return NULL;
113113
}
114114
cm = NEWOBJ(classmemberobject, &Classmembertype);
@@ -148,14 +148,14 @@ classmember_getattr(cm, name)
148148
}
149149
v = class_getattr(cm->cm_class, name);
150150
if (v == NULL)
151-
return v; /* class_getattr() has set errno */
151+
return v; /* class_getattr() has set the error */
152152
if (is_funcobject(v)) {
153153
object *w = newclassmethodobject(v, (object *)cm);
154154
DECREF(v);
155155
return w;
156156
}
157157
DECREF(v);
158-
errno = ESRCH;
158+
err_setstr(NameError, name);
159159
return NULL;
160160
}
161161

@@ -205,7 +205,7 @@ newclassmethodobject(func, self)
205205
{
206206
register classmethodobject *cm;
207207
if (!is_funcobject(func)) {
208-
errno = EINVAL;
208+
err_badcall();
209209
return NULL;
210210
}
211211
cm = NEWOBJ(classmethodobject, &Classmethodtype);
@@ -223,7 +223,7 @@ classmethodgetfunc(cm)
223223
register object *cm;
224224
{
225225
if (!is_classmethodobject(cm)) {
226-
errno = EINVAL;
226+
err_badcall();
227227
return NULL;
228228
}
229229
return ((classmethodobject *)cm)->cm_func;
@@ -234,7 +234,7 @@ classmethodgetself(cm)
234234
register object *cm;
235235
{
236236
if (!is_classmethodobject(cm)) {
237-
errno = EINVAL;
237+
err_badcall();
238238
return NULL;
239239
}
240240
return ((classmethodobject *)cm)->cm_self;

Objects/floatobject.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* Float object implementation */
22

3+
/* XXX There should be overflow checks here, but it's hard to check
4+
for any kind of float exception without losing portability. */
5+
36
#include <stdio.h>
47
#include <math.h>
58
#include <ctype.h>
@@ -9,21 +12,19 @@
912
#include "floatobject.h"
1013
#include "stringobject.h"
1114
#include "objimpl.h"
15+
#include "errors.h"
1216

1317
object *
1418
newfloatobject(fval)
1519
double fval;
1620
{
1721
/* For efficiency, this code is copied from newobject() */
1822
register floatobject *op = (floatobject *) malloc(sizeof(floatobject));
19-
if (op == NULL) {
20-
errno = ENOMEM;
21-
}
22-
else {
23-
NEWREF(op);
24-
op->ob_type = &Floattype;
25-
op->ob_fval = fval;
26-
}
23+
if (op == NULL)
24+
return err_nomem();
25+
NEWREF(op);
26+
op->ob_type = &Floattype;
27+
op->ob_fval = fval;
2728
return (object *) op;
2829
}
2930

@@ -32,7 +33,7 @@ getfloatvalue(op)
3233
object *op;
3334
{
3435
if (!is_floatobject(op)) {
35-
errno = EBADF;
36+
err_badarg();
3637
return -1;
3738
}
3839
else
@@ -104,7 +105,7 @@ float_add(v, w)
104105
object *w;
105106
{
106107
if (!is_floatobject(w)) {
107-
errno = EINVAL;
108+
err_badarg();
108109
return NULL;
109110
}
110111
return newfloatobject(v->ob_fval + ((floatobject *)w) -> ob_fval);
@@ -116,7 +117,7 @@ float_sub(v, w)
116117
object *w;
117118
{
118119
if (!is_floatobject(w)) {
119-
errno = EINVAL;
120+
err_badarg();
120121
return NULL;
121122
}
122123
return newfloatobject(v->ob_fval - ((floatobject *)w) -> ob_fval);
@@ -128,7 +129,7 @@ float_mul(v, w)
128129
object *w;
129130
{
130131
if (!is_floatobject(w)) {
131-
errno = EINVAL;
132+
err_badarg();
132133
return NULL;
133134
}
134135
return newfloatobject(v->ob_fval * ((floatobject *)w) -> ob_fval);
@@ -140,11 +141,11 @@ float_div(v, w)
140141
object *w;
141142
{
142143
if (!is_floatobject(w)) {
143-
errno = EINVAL;
144+
err_badarg();
144145
return NULL;
145146
}
146147
if (((floatobject *)w) -> ob_fval == 0) {
147-
errno = EDOM;
148+
err_setstr(ZeroDivisionError, "float division by zero");
148149
return NULL;
149150
}
150151
return newfloatobject(v->ob_fval / ((floatobject *)w) -> ob_fval);
@@ -158,12 +159,12 @@ float_rem(v, w)
158159
double wx;
159160
extern double fmod();
160161
if (!is_floatobject(w)) {
161-
errno = EINVAL;
162+
err_badarg();
162163
return NULL;
163164
}
164165
wx = ((floatobject *)w) -> ob_fval;
165166
if (wx == 0.0) {
166-
errno = EDOM;
167+
err_setstr(ZeroDivisionError, "float division by zero");
167168
return NULL;
168169
}
169170
return newfloatobject(fmod(v->ob_fval, wx));
@@ -177,17 +178,21 @@ float_pow(v, w)
177178
double iv, iw, ix;
178179
extern double pow();
179180
if (!is_floatobject(w)) {
180-
errno = EINVAL;
181+
err_badarg();
181182
return NULL;
182183
}
183184
iv = v->ob_fval;
184185
iw = ((floatobject *)w)->ob_fval;
186+
if (iw == 0.0)
187+
return newfloatobject(1.0); /* x**0 is always 1, even 0**0 */
185188
errno = 0;
186189
ix = pow(iv, iw);
187-
if (errno != 0)
190+
if (errno != 0) {
191+
/* XXX could it be another type of error? */
192+
err_errno(OverflowError);
188193
return NULL;
189-
else
190-
return newfloatobject(ix);
194+
}
195+
return newfloatobject(ix);
191196
}
192197

193198
static object *

Objects/funcobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ getfuncnode(op)
3636
object *op;
3737
{
3838
if (!is_funcobject(op)) {
39-
errno = EBADF;
39+
err_badcall();
4040
return NULL;
4141
}
4242
return ((funcobject *) op) -> func_node;
@@ -47,7 +47,7 @@ getfuncglobals(op)
4747
object *op;
4848
{
4949
if (!is_funcobject(op)) {
50-
errno = EBADF;
50+
err_badcall();
5151
return NULL;
5252
}
5353
return ((funcobject *) op) -> func_globals;

0 commit comments

Comments
 (0)