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
1da4cefb
Commit
1da4cefb
authored
Dec 16, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sys.copyright, better old-style __nonzero__
parent
0d2c9b6e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
3 deletions
+31
-3
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+7
-0
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+15
-3
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+4
-0
src/runtime/objmodel.h
src/runtime/objmodel.h
+1
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+3
-0
test/tests/sys_test.py
test/tests/sys_test.py
+1
-0
No files found.
src/runtime/builtin_modules/sys.cpp
View file @
1da4cefb
...
...
@@ -143,6 +143,13 @@ void setupSys() {
sys_module
->
giveAttr
(
"prefix"
,
boxStrConstant
(
"/usr"
));
sys_module
->
giveAttr
(
"exec_prefix"
,
boxStrConstant
(
"/usr"
));
sys_module
->
giveAttr
(
"copyright"
,
boxStrConstant
(
"Copyright 2014 Dropbox.
\n
All Rights Reserved.
\n\n
Copyright (c) 2001-2014 "
"Python Software Foundation.
\n
All Rights Reserved.
\n\n
Copyright (c) 2000 "
"BeOpen.com.
\n
All Rights Reserved.
\n\n
Copyright (c) 1995-2001 Corporation for "
"National Research Initiatives.
\n
All Rights Reserved.
\n\n
Copyright (c) "
"1991-1995 Stichting Mathematisch Centrum, Amsterdam.
\n
All Rights Reserved."
));
sys_module
->
giveAttr
(
"version"
,
boxString
(
generateVersionString
()));
sys_module
->
giveAttr
(
"hexversion"
,
boxInt
(
PY_VERSION_HEX
));
...
...
src/runtime/classobj.cpp
View file @
1da4cefb
...
...
@@ -215,10 +215,22 @@ Box* instanceNonzero(Box* _inst) {
RELEASE_ASSERT
(
_inst
->
cls
==
instance_cls
,
""
);
BoxedInstance
*
inst
=
static_cast
<
BoxedInstance
*>
(
_inst
);
Box
*
nonzero_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__nonzero__"
),
false
);
Box
*
nonzero_func
=
NULL
;
try
{
nonzero_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__nonzero__"
),
false
);
}
catch
(
Box
*
b
)
{
if
(
!
isInstance
(
b
,
AttributeError
))
throw
;
}
if
(
nonzero_func
==
NULL
)
nonzero_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__len__"
),
false
);
if
(
nonzero_func
==
NULL
)
{
try
{
nonzero_func
=
_instanceGetattribute
(
inst
,
boxStrConstant
(
"__len__"
),
false
);
}
catch
(
Box
*
b
)
{
if
(
!
isInstance
(
b
,
AttributeError
))
throw
;
}
}
if
(
nonzero_func
)
{
return
runtimeCall
(
nonzero_func
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
...
...
src/runtime/objmodel.cpp
View file @
1da4cefb
...
...
@@ -248,6 +248,10 @@ extern "C" void my_assert(bool b) {
assert
(
b
);
}
bool
isInstance
(
Box
*
obj
,
BoxedClass
*
cls
)
{
return
isSubclass
(
obj
->
cls
,
cls
);
}
extern
"C"
bool
isSubclass
(
BoxedClass
*
child
,
BoxedClass
*
parent
)
{
// TODO the class is allowed to override this using __subclasscheck__
while
(
child
)
{
...
...
src/runtime/objmodel.h
View file @
1da4cefb
...
...
@@ -81,6 +81,7 @@ extern "C" Box* importStar(Box* from_module, BoxedModule* to_module);
extern
"C"
Box
**
unpackIntoArray
(
Box
*
obj
,
int64_t
expected_size
);
extern
"C"
void
assertNameDefined
(
bool
b
,
const
char
*
name
,
BoxedClass
*
exc_cls
,
bool
local_var_msg
);
extern
"C"
void
assertFail
(
BoxedModule
*
inModule
,
Box
*
msg
);
extern
"C"
bool
isInstance
(
Box
*
obj
,
BoxedClass
*
parent
);
extern
"C"
bool
isSubclass
(
BoxedClass
*
child
,
BoxedClass
*
parent
);
extern
"C"
BoxedClosure
*
createClosure
(
BoxedClosure
*
parent_closure
);
extern
"C"
Box
*
getiter
(
Box
*
o
);
...
...
test/tests/oldstyle_classes.py
View file @
1da4cefb
...
...
@@ -115,6 +115,8 @@ print issubclass(OldStyleClass, OldStyleClass)
class
GetattrTest
:
def
__getattr__
(
self
,
attr
):
print
"getattr"
,
attr
if
attr
.
startswith
(
"__"
):
raise
AttributeError
(
attr
)
return
1
g
=
GetattrTest
()
...
...
@@ -123,3 +125,4 @@ print g.a
print
g
.
b
print
g
.
__class__
print
g
.
__dict__
.
items
()
print
bool
(
g
)
test/tests/sys_test.py
View file @
1da4cefb
...
...
@@ -6,3 +6,4 @@ import os.path
print
sys
.
version
[:
3
]
print
os
.
path
.
exists
(
sys
.
executable
)
print
sys
.
prefix
,
sys
.
exec_prefix
print
sys
.
copyright
[
-
200
:]
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