Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
a1e85219
Commit
a1e85219
authored
Dec 16, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support OSError(arg1, arg2, arg3)
parent
94b020e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
15 deletions
+69
-15
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+1
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+53
-13
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+11
-1
src/runtime/types.h
src/runtime/types.h
+2
-1
test/tests/os_test.py
test/tests/os_test.py
+2
-0
No files found.
src/capi/typeobject.cpp
View file @
a1e85219
...
...
@@ -877,6 +877,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
}
cls
->
gc_visit
=
&
conservativeGCHandler
;
cls
->
is_user_defined
=
true
;
// TODO not sure how we can handle extension types that manually
// specify a dict...
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
a1e85219
...
...
@@ -482,7 +482,7 @@ BoxedClass* BaseException, *Exception, *StandardError, *AssertionError, *Attribu
}
Box
*
exceptionNew1
(
BoxedClass
*
cls
)
{
return
exceptionNew
2
(
cls
,
boxStrConstant
(
""
)
);
return
exceptionNew
(
cls
,
EmptyTuple
);
}
class
BoxedException
:
public
Box
{
...
...
@@ -492,11 +492,29 @@ public:
};
Box
*
exceptionNew2
(
BoxedClass
*
cls
,
Box
*
message
)
{
assert
(
cls
->
tp_basicsize
==
sizeof
(
BoxedException
));
Box
*
r
=
new
BoxedException
(
cls
);
// TODO: maybe this should be a MemberDescriptor?
r
->
giveAttr
(
"message"
,
message
);
return
r
;
return
exceptionNew
(
cls
,
new
BoxedTuple
({
message
}));
}
Box
*
exceptionNew
(
BoxedClass
*
cls
,
BoxedTuple
*
args
)
{
if
(
!
isSubclass
(
cls
->
cls
,
type_cls
))
raiseExcHelper
(
TypeError
,
"exceptions.__new__(X): X is not a type object (%s)"
,
getTypeName
(
cls
)
->
c_str
());
if
(
!
isSubclass
(
cls
,
BaseException
))
raiseExcHelper
(
TypeError
,
"BaseException.__new__(%s): %s is not a subtype of BaseException"
,
getNameOfClass
(
cls
)
->
c_str
(),
getNameOfClass
(
cls
)
->
c_str
());
assert
(
cls
->
tp_basicsize
>=
sizeof
(
BoxedException
));
void
*
mem
=
gc_alloc
(
cls
->
tp_basicsize
,
gc
::
GCKind
::
PYTHON
);
memset
((
char
*
)
mem
+
sizeof
(
BoxedException
),
0
,
cls
->
tp_basicsize
-
sizeof
(
BoxedException
));
BoxedException
*
rtn
=
::
new
(
mem
)
BoxedException
(
cls
);
initUserAttrs
(
rtn
,
cls
);
// TODO: this should be a MemberDescriptor and set during init
if
(
args
->
elts
.
size
()
==
1
)
rtn
->
giveAttr
(
"message"
,
args
->
elts
[
0
]);
else
rtn
->
giveAttr
(
"message"
,
boxStrConstant
(
""
));
return
rtn
;
}
Box
*
exceptionStr
(
Box
*
b
)
{
...
...
@@ -520,15 +538,16 @@ Box* exceptionRepr(Box* b) {
return
boxString
(
*
getTypeName
(
b
)
+
"("
+
message_s
->
s
+
",)"
);
}
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
)
{
BoxedClass
*
cls
=
new
BoxedHeapClass
(
type_cls
,
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
sizeof
(
BoxedException
),
false
);
static
BoxedClass
*
makeBuiltinException
(
BoxedClass
*
base
,
const
char
*
name
,
int
size
=
0
)
{
if
(
size
==
0
)
size
=
base
->
tp_basicsize
;
BoxedClass
*
cls
=
new
BoxedHeapClass
(
type_cls
,
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
size
,
false
);
cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
name
));
cls
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"exceptions"
));
if
(
base
==
object_cls
)
{
cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionNew2
,
UNKNOWN
,
2
,
1
,
false
,
false
),
{
boxStrConstant
(
""
)
}));
cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
cls
->
giveAttr
(
"__str__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionStr
,
STR
,
1
)));
cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
exceptionRepr
,
STR
,
1
)));
}
...
...
@@ -720,6 +739,23 @@ Box* pydump(void* p) {
return
None
;
}
class
BoxedEnvironmentError
:
public
BoxedException
{
public:
// Box* args, *message, *myerrno, *strerror, *filename;
Box
*
myerrno
,
*
strerror
,
*
filename
;
static
Box
*
__init__
(
BoxedEnvironmentError
*
self
,
Box
*
errno_
,
Box
*
strerror
,
Box
**
_args
)
{
Box
*
filename
=
_args
[
0
];
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
EnvironmentError
),
""
);
self
->
myerrno
=
errno_
;
self
->
strerror
=
strerror
;
self
->
filename
=
filename
;
return
None
;
}
};
void
setupBuiltins
()
{
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
);
...
...
@@ -740,7 +776,7 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"all"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
)));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
)));
BaseException
=
makeBuiltinException
(
object_cls
,
"BaseException"
);
BaseException
=
makeBuiltinException
(
object_cls
,
"BaseException"
,
sizeof
(
BoxedException
)
);
Exception
=
makeBuiltinException
(
BaseException
,
"Exception"
);
StandardError
=
makeBuiltinException
(
Exception
,
"StandardError"
);
AssertionError
=
makeBuiltinException
(
StandardError
,
"AssertionError"
);
...
...
@@ -751,7 +787,7 @@ void setupBuiltins() {
LookupError
=
makeBuiltinException
(
StandardError
,
"LookupError"
);
KeyError
=
makeBuiltinException
(
LookupError
,
"KeyError"
);
IndexError
=
makeBuiltinException
(
LookupError
,
"IndexError"
);
EnvironmentError
=
makeBuiltinException
(
StandardError
,
"EnvironmentError"
);
EnvironmentError
=
makeBuiltinException
(
StandardError
,
"EnvironmentError"
,
sizeof
(
BoxedEnvironmentError
)
);
IOError
=
makeBuiltinException
(
EnvironmentError
,
"IOError"
);
OSError
=
makeBuiltinException
(
EnvironmentError
,
"OSError"
);
ArithmeticError
=
makeBuiltinException
(
StandardError
,
"ArithmeticError"
);
...
...
@@ -775,6 +811,10 @@ void setupBuiltins() {
SystemError
=
makeBuiltinException
(
StandardError
,
"SystemError"
);
NotImplementedError
=
makeBuiltinException
(
RuntimeError
,
"NotImplementedError"
);
EnvironmentError
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnvironmentError
::
__init__
,
NONE
,
4
,
1
,
false
,
false
),
{
None
}));
repr_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
));
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
len_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
len
,
UNKNOWN
,
1
));
...
...
src/runtime/objmodel.cpp
View file @
a1e85219
...
...
@@ -19,6 +19,7 @@
#include <cstdlib>
#include <cstring>
#include <memory>
#include <sstream>
#include <stdint.h>
#include "asm_writing/icinfo.h"
...
...
@@ -2313,7 +2314,16 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
Box
*
ovarargs
=
new
BoxedTuple
(
unused_positional
);
getArg
(
varargs_idx
,
oarg1
,
oarg2
,
oarg3
,
oargs
)
=
ovarargs
;
}
else
if
(
unused_positional
.
size
())
{
raiseExcHelper
(
TypeError
,
"<function>() takes at most %d argument%s (%d given)"
,
f
->
num_args
,
std
::
string
name
=
"<unknown function>"
;
if
(
f
->
source
)
name
=
f
->
source
->
getName
();
else
if
(
f
->
versions
.
size
())
{
std
::
ostringstream
oss
;
oss
<<
"<function at "
<<
f
->
versions
[
0
]
->
code
<<
">"
;
name
=
oss
.
str
();
}
raiseExcHelper
(
TypeError
,
"%s() takes at most %d argument%s (%d given)"
,
name
.
c_str
(),
f
->
num_args
,
(
f
->
num_args
==
1
?
""
:
"s"
),
argspec
.
num_args
+
argspec
.
num_keywords
+
varargs
.
size
());
}
...
...
src/runtime/types.h
View file @
a1e85219
...
...
@@ -217,7 +217,7 @@ public:
// Whether this class was defined by the user or is a builtin type.
// this is used mostly for debugging.
const
bool
is_user_defined
;
bool
is_user_defined
;
// will need to update this once we support tp_getattr-style overriding:
bool
hasGenericGetattr
()
{
return
true
;
}
...
...
@@ -539,6 +539,7 @@ extern "C" void boxGCHandler(GCVisitor* v, Box* b);
Box
*
exceptionNew1
(
BoxedClass
*
cls
);
Box
*
exceptionNew2
(
BoxedClass
*
cls
,
Box
*
message
);
Box
*
exceptionNew
(
BoxedClass
*
cls
,
BoxedTuple
*
args
);
extern
"C"
BoxedClass
*
Exception
,
*
AssertionError
,
*
AttributeError
,
*
TypeError
,
*
NameError
,
*
KeyError
,
*
IndexError
,
*
IOError
,
*
OSError
,
*
ZeroDivisionError
,
*
ValueError
,
*
UnboundLocalError
,
*
RuntimeError
,
*
ImportError
,
...
...
test/tests/os_test.py
View file @
a1e85219
...
...
@@ -12,3 +12,5 @@ print len(r1), len(r2), type(r1), type(r2), r1 == r2
print
type
(
os
.
stat
(
"/dev/null"
))
print
os
.
path
.
expanduser
(
"~"
)
==
os
.
environ
[
"HOME"
]
OSError
(
1
,
2
,
3
)
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