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
4d90cb9c
Commit
4d90cb9c
authored
Oct 21, 1990
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New errors.
parent
08263057
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
126 deletions
+137
-126
Objects/classobject.c
Objects/classobject.c
+6
-6
Objects/floatobject.c
Objects/floatobject.c
+25
-20
Objects/funcobject.c
Objects/funcobject.c
+2
-2
Objects/listobject.c
Objects/listobject.c
+46
-32
Objects/methodobject.c
Objects/methodobject.c
+3
-2
Objects/stringobject.c
Objects/stringobject.c
+41
-50
Objects/tupleobject.c
Objects/tupleobject.c
+14
-14
No files found.
Objects/classobject.c
View file @
4d90cb9c
...
@@ -108,7 +108,7 @@ newclassmemberobject(class)
...
@@ -108,7 +108,7 @@ newclassmemberobject(class)
{
{
register
classmemberobject
*
cm
;
register
classmemberobject
*
cm
;
if
(
!
is_classobject
(
class
))
{
if
(
!
is_classobject
(
class
))
{
err
no
=
EINVAL
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
cm
=
NEWOBJ
(
classmemberobject
,
&
Classmembertype
);
cm
=
NEWOBJ
(
classmemberobject
,
&
Classmembertype
);
...
@@ -148,14 +148,14 @@ classmember_getattr(cm, name)
...
@@ -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
);
err
no
=
ESRCH
;
err
_setstr
(
NameError
,
name
)
;
return
NULL
;
return
NULL
;
}
}
...
@@ -205,7 +205,7 @@ newclassmethodobject(func, self)
...
@@ -205,7 +205,7 @@ newclassmethodobject(func, self)
{
{
register
classmethodobject
*
cm
;
register
classmethodobject
*
cm
;
if
(
!
is_funcobject
(
func
))
{
if
(
!
is_funcobject
(
func
))
{
err
no
=
EINVAL
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
cm
=
NEWOBJ
(
classmethodobject
,
&
Classmethodtype
);
cm
=
NEWOBJ
(
classmethodobject
,
&
Classmethodtype
);
...
@@ -223,7 +223,7 @@ classmethodgetfunc(cm)
...
@@ -223,7 +223,7 @@ classmethodgetfunc(cm)
register
object
*
cm
;
register
object
*
cm
;
{
{
if
(
!
is_classmethodobject
(
cm
))
{
if
(
!
is_classmethodobject
(
cm
))
{
err
no
=
EINVAL
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
classmethodobject
*
)
cm
)
->
cm_func
;
return
((
classmethodobject
*
)
cm
)
->
cm_func
;
...
@@ -234,7 +234,7 @@ classmethodgetself(cm)
...
@@ -234,7 +234,7 @@ classmethodgetself(cm)
register
object
*
cm
;
register
object
*
cm
;
{
{
if
(
!
is_classmethodobject
(
cm
))
{
if
(
!
is_classmethodobject
(
cm
))
{
err
no
=
EINVAL
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
classmethodobject
*
)
cm
)
->
cm_self
;
return
((
classmethodobject
*
)
cm
)
->
cm_self
;
...
...
Objects/floatobject.c
View file @
4d90cb9c
/* 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 @@
...
@@ -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)
...
@@ -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
();
}
NEWREF
(
op
);
else
{
op
->
ob_type
=
&
Floattype
;
NEWREF
(
op
);
op
->
ob_fval
=
fval
;
op
->
ob_type
=
&
Floattype
;
op
->
ob_fval
=
fval
;
}
return
(
object
*
)
op
;
return
(
object
*
)
op
;
}
}
...
@@ -32,7 +33,7 @@ getfloatvalue(op)
...
@@ -32,7 +33,7 @@ getfloatvalue(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_floatobject
(
op
))
{
if
(
!
is_floatobject
(
op
))
{
err
no
=
EBADF
;
err
_badarg
()
;
return
-
1
;
return
-
1
;
}
}
else
else
...
@@ -104,7 +105,7 @@ float_add(v, w)
...
@@ -104,7 +105,7 @@ float_add(v, w)
object
*
w
;
object
*
w
;
{
{
if
(
!
is_floatobject
(
w
))
{
if
(
!
is_floatobject
(
w
))
{
err
no
=
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)
...
@@ -116,7 +117,7 @@ float_sub(v, w)
object
*
w
;
object
*
w
;
{
{
if
(
!
is_floatobject
(
w
))
{
if
(
!
is_floatobject
(
w
))
{
err
no
=
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)
...
@@ -128,7 +129,7 @@ float_mul(v, w)
object
*
w
;
object
*
w
;
{
{
if
(
!
is_floatobject
(
w
))
{
if
(
!
is_floatobject
(
w
))
{
err
no
=
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)
...
@@ -140,11 +141,11 @@ float_div(v, w)
object
*
w
;
object
*
w
;
{
{
if
(
!
is_floatobject
(
w
))
{
if
(
!
is_floatobject
(
w
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
if
(((
floatobject
*
)
w
)
->
ob_fval
==
0
)
{
if
(((
floatobject
*
)
w
)
->
ob_fval
==
0
)
{
err
no
=
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)
...
@@ -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
))
{
err
no
=
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
)
{
err
no
=
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,17 +178,21 @@ float_pow(v, w)
...
@@ -177,17 +178,21 @@ 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
))
{
err
no
=
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
);
}
}
static
object
*
static
object
*
...
...
Objects/funcobject.c
View file @
4d90cb9c
...
@@ -36,7 +36,7 @@ getfuncnode(op)
...
@@ -36,7 +36,7 @@ getfuncnode(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_funcobject
(
op
))
{
if
(
!
is_funcobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
funcobject
*
)
op
)
->
func_node
;
return
((
funcobject
*
)
op
)
->
func_node
;
...
@@ -47,7 +47,7 @@ getfuncglobals(op)
...
@@ -47,7 +47,7 @@ getfuncglobals(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_funcobject
(
op
))
{
if
(
!
is_funcobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
funcobject
*
)
op
)
->
func_globals
;
return
((
funcobject
*
)
op
)
->
func_globals
;
...
...
Objects/listobject.c
View file @
4d90cb9c
...
@@ -11,6 +11,7 @@
...
@@ -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)
...
@@ -24,13 +25,12 @@ newlistobject(size)
int
i
;
int
i
;
listobject
*
op
;
listobject
*
op
;
if
(
size
<
0
)
{
if
(
size
<
0
)
{
err
no
=
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)
...
@@ -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)
...
@@ -56,7 +55,7 @@ getlistsize(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_listobject
(
op
))
{
if
(
!
is_listobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
-
1
;
return
-
1
;
}
}
else
else
...
@@ -69,11 +68,11 @@ getlistitem(op, i)
...
@@ -69,11 +68,11 @@ getlistitem(op, i)
int
i
;
int
i
;
{
{
if
(
!
is_listobject
(
op
))
{
if
(
!
is_listobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
if
(
i
<
0
||
i
>=
((
listobject
*
)
op
)
->
ob_size
)
{
if
(
i
<
0
||
i
>=
((
listobject
*
)
op
)
->
ob_size
)
{
err
no
=
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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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
)
{
err
no
=
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)
...
@@ -278,15 +287,14 @@ list_concat(a, bb)
int
i
;
int
i
;
listobject
*
np
;
listobject
*
np
;
if
(
!
is_listobject
(
bb
))
{
if
(
!
is_listobject
(
bb
))
{
err
no
=
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)
...
@@ -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)
...
@@ -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)
...
@@ -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)
...
@@ -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
)
{
err
no
=
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)
...
@@ -426,14 +440,14 @@ listsort(self, args)
object
*
args
;
object
*
args
;
{
{
if
(
args
!=
NULL
)
{
if
(
args
!=
NULL
)
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
err
no
=
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
(
err
no
!=
0
)
if
(
err
_occurred
()
)
return
NULL
;
return
NULL
;
INCREF
(
None
);
INCREF
(
None
);
return
None
;
return
None
;
...
...
Objects/methodobject.c
View file @
4d90cb9c
...
@@ -9,6 +9,7 @@
...
@@ -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)
...
@@ -39,7 +40,7 @@ getmethod(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_methodobject
(
op
))
{
if
(
!
is_methodobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
methodobject
*
)
op
)
->
m_meth
;
return
((
methodobject
*
)
op
)
->
m_meth
;
...
@@ -50,7 +51,7 @@ getself(op)
...
@@ -50,7 +51,7 @@ getself(op)
object
*
op
;
object
*
op
;
{
{
if
(
!
is_methodobject
(
op
))
{
if
(
!
is_methodobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
methodobject
*
)
op
)
->
m_self
;
return
((
methodobject
*
)
op
)
->
m_self
;
...
...
Objects/stringobject.c
View file @
4d90cb9c
...
@@ -7,6 +7,7 @@
...
@@ -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)
...
@@ -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
();
}
NEWREF
(
op
);
else
{
op
->
ob_type
=
&
Stringtype
;
NEWREF
(
op
);
op
->
ob_size
=
size
;
op
->
ob_type
=
&
Stringtype
;
if
(
str
!=
NULL
)
op
->
ob_size
=
size
;
memcpy
(
op
->
ob_sval
,
str
,
size
);
if
(
str
!=
NULL
)
op
->
ob_sval
[
size
]
=
'\0'
;
memcpy
(
op
->
ob_sval
,
str
,
size
);
op
->
ob_sval
[
size
]
=
'\0'
;
}
return
(
object
*
)
op
;
return
(
object
*
)
op
;
}
}
...
@@ -36,15 +34,12 @@ newstringobject(str)
...
@@ -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
();
}
NEWREF
(
op
);
else
{
op
->
ob_type
=
&
Stringtype
;
NEWREF
(
op
);
op
->
ob_size
=
size
;
op
->
ob_type
=
&
Stringtype
;
strcpy
(
op
->
ob_sval
,
str
);
op
->
ob_size
=
size
;
strcpy
(
op
->
ob_sval
,
str
);
}
return
(
object
*
)
op
;
return
(
object
*
)
op
;
}
}
...
@@ -53,7 +48,7 @@ getstringsize(op)
...
@@ -53,7 +48,7 @@ getstringsize(op)
register
object
*
op
;
register
object
*
op
;
{
{
if
(
!
is_stringobject
(
op
))
{
if
(
!
is_stringobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
-
1
;
return
-
1
;
}
}
return
((
stringobject
*
)
op
)
->
ob_size
;
return
((
stringobject
*
)
op
)
->
ob_size
;
...
@@ -64,7 +59,7 @@ getstringvalue(op)
...
@@ -64,7 +59,7 @@ getstringvalue(op)
register
object
*
op
;
register
object
*
op
;
{
{
if
(
!
is_stringobject
(
op
))
{
if
(
!
is_stringobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
return
((
stringobject
*
)
op
)
->
ob_sval
;
return
((
stringobject
*
)
op
)
->
ob_sval
;
...
@@ -105,7 +100,7 @@ stringrepr(op)
...
@@ -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,8 +127,8 @@ stringrepr(op)
...
@@ -132,8 +127,8 @@ 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
...
@@ -151,7 +146,7 @@ stringconcat(a, bb)
...
@@ -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
))
{
err
no
=
EINVAL
;
err
_badarg
()
;
return
NULL
;
return
NULL
;
}
}
#define b ((stringobject *)bb)
#define b ((stringobject *)bb)
...
@@ -167,17 +162,14 @@ stringconcat(a, 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
();
}
NEWREF
(
op
);
else
{
op
->
ob_type
=
&
Stringtype
;
NEWREF
(
op
);
op
->
ob_size
=
size
;
op
->
ob_type
=
&
Stringtype
;
memcpy
(
op
->
ob_sval
,
a
->
ob_sval
,
(
int
)
a
->
ob_size
);
op
->
ob_size
=
size
;
memcpy
(
op
->
ob_sval
+
a
->
ob_size
,
b
->
ob_sval
,
(
int
)
b
->
ob_size
);
memcpy
(
op
->
ob_sval
,
a
->
ob_sval
,
(
int
)
a
->
ob_size
);
op
->
ob_sval
[
size
]
=
'\0'
;
memcpy
(
op
->
ob_sval
+
a
->
ob_size
,
b
->
ob_sval
,
(
int
)
b
->
ob_size
);
op
->
ob_sval
[
size
]
=
'\0'
;
}
return
(
object
*
)
op
;
return
(
object
*
)
op
;
#undef b
#undef b
}
}
...
@@ -199,17 +191,14 @@ stringrepeat(a, n)
...
@@ -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
();
}
NEWREF
(
op
);
else
{
op
->
ob_type
=
&
Stringtype
;
NEWREF
(
op
);
op
->
ob_size
=
size
;
op
->
ob_type
=
&
Stringtype
;
for
(
i
=
0
;
i
<
size
;
i
+=
a
->
ob_size
)
op
->
ob_size
=
size
;
memcpy
(
op
->
ob_sval
+
i
,
a
->
ob_sval
,
(
int
)
a
->
ob_size
);
for
(
i
=
0
;
i
<
size
;
i
+=
a
->
ob_size
)
op
->
ob_sval
[
size
]
=
'\0'
;
memcpy
(
op
->
ob_sval
+
i
,
a
->
ob_sval
,
(
int
)
a
->
ob_size
);
op
->
ob_sval
[
size
]
=
'\0'
;
}
return
(
object
*
)
op
;
return
(
object
*
)
op
;
}
}
...
@@ -241,7 +230,7 @@ stringitem(a, i)
...
@@ -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
)
{
err
no
=
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)
...
@@ -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
;
...
...
Objects/tupleobject.c
View file @
4d90cb9c
...
@@ -8,6 +8,7 @@
...
@@ -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)
...
@@ -21,15 +22,13 @@ newtupleobject(size)
register
int
i
;
register
int
i
;
register
tupleobject
*
op
;
register
tupleobject
*
op
;
if
(
size
<
0
)
{
if
(
size
<
0
)
{
err
no
=
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)
...
@@ -43,7 +42,7 @@ gettuplesize(op)
register
object
*
op
;
register
object
*
op
;
{
{
if
(
!
is_tupleobject
(
op
))
{
if
(
!
is_tupleobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
-
1
;
return
-
1
;
}
}
else
else
...
@@ -56,11 +55,11 @@ gettupleitem(op, i)
...
@@ -56,11 +55,11 @@ gettupleitem(op, i)
register
int
i
;
register
int
i
;
{
{
if
(
!
is_tupleobject
(
op
))
{
if
(
!
is_tupleobject
(
op
))
{
err
no
=
EBADF
;
err
_badcall
()
;
return
NULL
;
return
NULL
;
}
}
if
(
i
<
0
||
i
>=
((
tupleobject
*
)
op
)
->
ob_size
)
{
if
(
i
<
0
||
i
>=
((
tupleobject
*
)
op
)
->
ob_size
)
{
err
no
=
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)
...
@@ -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)
...
@@ -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
)
{
err
no
=
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)
...
@@ -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
))
{
err
no
=
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
];
...
...
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