Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c56ee6dc
Commit
c56ee6dc
authored
Oct 14, 1990
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New error handling.
parent
5122aee3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
36 deletions
+37
-36
Objects/intobject.c
Objects/intobject.c
+37
-36
No files found.
Objects/intobject.c
View file @
c56ee6dc
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include "intobject.h"
#include "intobject.h"
#include "stringobject.h"
#include "stringobject.h"
#include "objimpl.h"
#include "objimpl.h"
#include "errors.h"
/* Standard Booleans */
/* Standard Booleans */
intobject
FalseObject
=
{
intobject
FalseObject
=
{
...
@@ -18,6 +19,20 @@ intobject TrueObject = {
...
@@ -18,6 +19,20 @@ intobject TrueObject = {
1
1
};
};
static
object
*
err_ovf
()
{
err_setstr
(
RuntimeError
,
"integer overflow"
);
return
NULL
;
}
static
object
*
err_zdiv
()
{
err_setstr
(
RuntimeError
,
"division by zero"
);
return
NULL
;
}
object
*
object
*
newintobject
(
ival
)
newintobject
(
ival
)
long
ival
;
long
ival
;
...
@@ -25,7 +40,7 @@ newintobject(ival)
...
@@ -25,7 +40,7 @@ newintobject(ival)
/* For efficiency, this code is copied from newobject() */
/* For efficiency, this code is copied from newobject() */
register
intobject
*
op
=
(
intobject
*
)
malloc
(
sizeof
(
intobject
));
register
intobject
*
op
=
(
intobject
*
)
malloc
(
sizeof
(
intobject
));
if
(
op
==
NULL
)
{
if
(
op
==
NULL
)
{
err
no
=
ENOMEM
;
err
_nomem
()
;
}
}
else
{
else
{
NEWREF
(
op
);
NEWREF
(
op
);
...
@@ -40,7 +55,7 @@ getintvalue(op)
...
@@ -40,7 +55,7 @@ getintvalue(op)
register
object
*
op
;
register
object
*
op
;
{
{
if
(
!
is_intobject
(
op
))
{
if
(
!
is_intobject
(
op
))
{
err
no
=
EBADF
;
err
_badarg
()
;
return
-
1
;
return
-
1
;
}
}
else
else
...
@@ -83,16 +98,14 @@ intadd(v, w)
...
@@ -83,16 +98,14 @@ intadd(v, w)
{
{
register
long
a
,
b
,
x
;
register
long
a
,
b
,
x
;
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
a
=
v
->
ob_ival
;
a
=
v
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
x
=
a
+
b
;
x
=
a
+
b
;
if
((
x
^
a
)
<
0
&&
(
x
^
b
)
<
0
)
{
if
((
x
^
a
)
<
0
&&
(
x
^
b
)
<
0
)
errno
=
ERANGE
;
return
err_ovf
();
return
NULL
;
}
return
newintobject
(
x
);
return
newintobject
(
x
);
}
}
...
@@ -103,16 +116,14 @@ intsub(v, w)
...
@@ -103,16 +116,14 @@ intsub(v, w)
{
{
register
long
a
,
b
,
x
;
register
long
a
,
b
,
x
;
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
a
=
v
->
ob_ival
;
a
=
v
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
x
=
a
-
b
;
x
=
a
-
b
;
if
((
x
^
a
)
<
0
&&
(
x
^~
b
)
<
0
)
{
if
((
x
^
a
)
<
0
&&
(
x
^~
b
)
<
0
)
errno
=
ERANGE
;
return
err_ovf
();
return
NULL
;
}
return
newintobject
(
x
);
return
newintobject
(
x
);
}
}
...
@@ -124,16 +135,14 @@ intmul(v, w)
...
@@ -124,16 +135,14 @@ intmul(v, w)
register
long
a
,
b
;
register
long
a
,
b
;
double
x
;
double
x
;
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
a
=
v
->
ob_ival
;
a
=
v
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
b
=
((
intobject
*
)
w
)
->
ob_ival
;
x
=
(
double
)
a
*
(
double
)
b
;
x
=
(
double
)
a
*
(
double
)
b
;
if
(
x
>
0x7fffffff
||
x
<
(
double
)
(
long
)
0x80000000
)
{
if
(
x
>
0x7fffffff
||
x
<
(
double
)
(
long
)
0x80000000
)
errno
=
ERANGE
;
return
err_ovf
();
return
NULL
;
}
return
newintobject
(
a
*
b
);
return
newintobject
(
a
*
b
);
}
}
...
@@ -143,13 +152,11 @@ intdiv(v, w)
...
@@ -143,13 +152,11 @@ intdiv(v, w)
register
object
*
w
;
register
object
*
w
;
{
{
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
errno
=
EINVAL
;
err_badarg
();
return
NULL
;
}
if
(((
intobject
*
)
w
)
->
ob_ival
==
0
)
{
errno
=
EDOM
;
return
NULL
;
return
NULL
;
}
}
if
(((
intobject
*
)
w
)
->
ob_ival
==
0
)
err_zdiv
();
return
newintobject
(
v
->
ob_ival
/
((
intobject
*
)
w
)
->
ob_ival
);
return
newintobject
(
v
->
ob_ival
/
((
intobject
*
)
w
)
->
ob_ival
);
}
}
...
@@ -159,13 +166,11 @@ intrem(v, w)
...
@@ -159,13 +166,11 @@ intrem(v, w)
register
object
*
w
;
register
object
*
w
;
{
{
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
errno
=
EINVAL
;
err_badarg
();
return
NULL
;
}
if
(((
intobject
*
)
w
)
->
ob_ival
==
0
)
{
errno
=
EDOM
;
return
NULL
;
return
NULL
;
}
}
if
(((
intobject
*
)
w
)
->
ob_ival
==
0
)
err_zdiv
();
return
newintobject
(
v
->
ob_ival
%
((
intobject
*
)
w
)
->
ob_ival
);
return
newintobject
(
v
->
ob_ival
%
((
intobject
*
)
w
)
->
ob_ival
);
}
}
...
@@ -177,7 +182,7 @@ intpow(v, w)
...
@@ -177,7 +182,7 @@ intpow(v, w)
register
long
iv
,
iw
,
ix
;
register
long
iv
,
iw
,
ix
;
register
int
neg
;
register
int
neg
;
if
(
!
is_intobject
(
w
))
{
if
(
!
is_intobject
(
w
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
iv
=
v
->
ob_ival
;
iv
=
v
->
ob_ival
;
...
@@ -189,10 +194,8 @@ intpow(v, w)
...
@@ -189,10 +194,8 @@ intpow(v, w)
for
(;
iw
>
0
;
iw
--
)
for
(;
iw
>
0
;
iw
--
)
ix
=
ix
*
iv
;
ix
=
ix
*
iv
;
if
(
neg
)
{
if
(
neg
)
{
if
(
ix
==
0
)
{
if
(
ix
==
0
)
errno
=
EDOM
;
err_zdiv
();
return
NULL
;
}
ix
=
1
/
ix
;
ix
=
1
/
ix
;
}
}
/* XXX How to check for overflow? */
/* XXX How to check for overflow? */
...
@@ -206,10 +209,8 @@ intneg(v)
...
@@ -206,10 +209,8 @@ intneg(v)
register
long
a
,
x
;
register
long
a
,
x
;
a
=
v
->
ob_ival
;
a
=
v
->
ob_ival
;
x
=
-
a
;
x
=
-
a
;
if
(
a
<
0
&&
x
<
0
)
{
if
(
a
<
0
&&
x
<
0
)
errno
=
ERANGE
;
return
err_ovf
();
return
NULL
;
}
return
newintobject
(
x
);
return
newintobject
(
x
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment