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
39859d79
Commit
39859d79
authored
Mar 03, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'multiple_inheritance'
parents
53dc9612
fee6818c
Changes
28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
1080 additions
and
196 deletions
+1080
-196
Makefile
Makefile
+12
-12
src/asm_writing/rewriter.cpp
src/asm_writing/rewriter.cpp
+13
-2
src/capi/abstract.cpp
src/capi/abstract.cpp
+5
-4
src/capi/modsupport.cpp
src/capi/modsupport.cpp
+39
-2
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+531
-11
src/capi/typeobject.h
src/capi/typeobject.h
+8
-1
src/gc/heap.cpp
src/gc/heap.cpp
+1
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+7
-5
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+2
-1
src/runtime/builtin_modules/thread.cpp
src/runtime/builtin_modules/thread.cpp
+4
-4
src/runtime/capi.cpp
src/runtime/capi.cpp
+8
-5
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+4
-4
src/runtime/dict.cpp
src/runtime/dict.cpp
+9
-7
src/runtime/generator.cpp
src/runtime/generator.cpp
+2
-2
src/runtime/inline/xrange.cpp
src/runtime/inline/xrange.cpp
+3
-3
src/runtime/iterobject.cpp
src/runtime/iterobject.cpp
+5
-4
src/runtime/list.cpp
src/runtime/list.cpp
+17
-4
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+130
-59
src/runtime/set.cpp
src/runtime/set.cpp
+2
-1
src/runtime/str.cpp
src/runtime/str.cpp
+2
-2
src/runtime/super.cpp
src/runtime/super.cpp
+61
-6
src/runtime/traceback.cpp
src/runtime/traceback.cpp
+2
-2
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+2
-1
src/runtime/types.cpp
src/runtime/types.cpp
+85
-42
src/runtime/types.h
src/runtime/types.h
+19
-6
test/tests/multiple_inheritance.py
test/tests/multiple_inheritance.py
+94
-0
test/tests/super.py
test/tests/super.py
+8
-0
tools/tester.py
tools/tester.py
+5
-5
No files found.
Makefile
View file @
39859d79
...
...
@@ -404,26 +404,26 @@ check:
@# jit_prof forces the use of GCC as the compiler, which can expose other errors, so just build it and see what happens
:
$(MAKE)
pyston_prof
@
# and run some basic tests to make sure it works:
$(
call
checksha,./pyston_prof
-
c
q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-
c
qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-
c
qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(MAKE)
check_release
echo
"All tests passed"
quick_check
:
$(MAKE)
pyston_dbg
$(
call
checksha,./pyston_dbg
-
c
q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_dbg
-
c
qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_dbg
-
c
qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_dbg
-q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_dbg
-qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_dbg
-qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(MAKE)
pyston
$(
call
checksha,./pyston
-
c
q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston
-
c
qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston
-
c
qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston
-q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston
-qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston
-qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(MAKE)
pyston_prof
$(
call
checksha,./pyston_prof
-
c
q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-
c
qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-
c
qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-q
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-qn
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
$(
call
checksha,./pyston_prof
-qO
$(TESTS_DIR)
/raytrace_small.py,0544f4621dd45fe94205219488a2576b84dc044d
)
Makefile.local
:
echo
"Creating default Makefile.local"
...
...
src/asm_writing/rewriter.cpp
View file @
39859d79
...
...
@@ -180,7 +180,13 @@ void RewriterVar::addAttrGuard(int offset, uint64_t val, bool negate) {
}
void
Rewriter
::
_addAttrGuard
(
RewriterVar
*
var
,
int
offset
,
uint64_t
val
,
bool
negate
)
{
assembler
::
Register
var_reg
=
var
->
getInReg
();
// TODO if var is a constant, we will end up emitting something like
// mov $0x123, %rax
// cmp $0x10(%rax), %rdi
// when we could just do
// cmp ($0x133), %rdi
assembler
::
Register
var_reg
=
var
->
getInReg
(
Location
::
any
(),
/* allow_constant_in_reg */
true
);
if
(
isLargeConstant
(
val
))
{
assembler
::
Register
reg
=
allocReg
(
Location
::
any
(),
/* otherThan */
var_reg
);
assert
(
reg
!=
var_reg
);
...
...
@@ -206,7 +212,12 @@ RewriterVar* RewriterVar::getAttr(int offset, Location dest, assembler::MovType
}
void
Rewriter
::
_getAttr
(
RewriterVar
*
result
,
RewriterVar
*
ptr
,
int
offset
,
Location
dest
,
assembler
::
MovType
type
)
{
assembler
::
Register
ptr_reg
=
ptr
->
getInReg
();
// TODO if var is a constant, we will end up emitting something like
// mov $0x123, %rax
// mov $0x10(%rax), %rdi
// when we could just do
// mov ($0x133), %rdi
assembler
::
Register
ptr_reg
=
ptr
->
getInReg
(
Location
::
any
(),
/* allow_constant_in_reg */
true
);
// It's okay to bump the use now, since it's fine to allocate the result
// in the same register as ptr
...
...
src/capi/abstract.cpp
View file @
39859d79
...
...
@@ -293,15 +293,16 @@ extern "C" PyObject* PyObject_CallFunctionObjArgs(PyObject* callable, ...) noexc
}
extern
"C"
PyObject
*
PyObject_CallObject
(
PyObject
*
obj
,
PyObject
*
args
)
noexcept
{
RELEASE_ASSERT
(
args
,
""
);
// actually it looks like this is allowed to be NULL
RELEASE_ASSERT
(
args
->
cls
==
tuple_cls
,
""
);
// TODO do something like this? not sure if this is safe; will people expect that calling into a known function
// won't end up doing a GIL check?
// threading::GLDemoteRegion _gil_demote;
try
{
Box
*
r
=
runtimeCall
(
obj
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
args
,
NULL
,
NULL
,
NULL
,
NULL
);
Box
*
r
;
if
(
args
)
r
=
runtimeCall
(
obj
,
ArgPassSpec
(
0
,
0
,
true
,
false
),
args
,
NULL
,
NULL
,
NULL
,
NULL
);
else
r
=
runtimeCall
(
obj
,
ArgPassSpec
(
0
,
0
,
false
,
false
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
return
r
;
}
catch
(
ExcInfo
e
)
{
Py_FatalError
(
"unimplemented"
);
...
...
src/capi/modsupport.cpp
View file @
39859d79
...
...
@@ -82,7 +82,7 @@ static int _ustrlen(Py_UNICODE* u) {
#endif
static
PyObject
*
do_mktuple
(
const
char
**
,
va_list
*
,
int
,
int
,
int
)
noexcept
;
// static PyObject *do_mklist(const char**, va_list
*, int, int, int) noexcept;
static
PyObject
*
do_mklist
(
const
char
**
,
va_list
*
,
int
,
int
,
int
)
noexcept
;
// static PyObject *do_mkdict(const char**, va_list *, int, int, int) noexcept;
static
PyObject
*
do_mkvalue
(
const
char
**
,
va_list
*
,
int
)
noexcept
;
...
...
@@ -92,10 +92,10 @@ static PyObject* do_mkvalue(const char** p_format, va_list* p_va, int flags) noe
case
'('
:
return
do_mktuple
(
p_format
,
p_va
,
')'
,
countformat
(
*
p_format
,
')'
),
flags
);
#if 0
case
'['
:
return
do_mklist
(
p_format
,
p_va
,
']'
,
countformat
(
*
p_format
,
']'
),
flags
);
#if 0
case '{':
return do_mkdict(p_format, p_va, '}', countformat(*p_format, '}'), flags);
#endif
...
...
@@ -239,6 +239,43 @@ static PyObject* do_mktuple(const char** p_format, va_list* p_va, int endchar, i
return
v
;
}
static
PyObject
*
do_mklist
(
const
char
**
p_format
,
va_list
*
p_va
,
int
endchar
,
int
n
,
int
flags
)
noexcept
{
PyObject
*
v
;
int
i
;
int
itemfailed
=
0
;
if
(
n
<
0
)
return
NULL
;
v
=
PyList_New
(
n
);
if
(
v
==
NULL
)
return
NULL
;
/* Note that we can't bail immediately on error as this will leak
refcounts on any 'N' arguments. */
for
(
i
=
0
;
i
<
n
;
i
++
)
{
PyObject
*
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
if
(
w
==
NULL
)
{
itemfailed
=
1
;
Py_INCREF
(
Py_None
);
w
=
Py_None
;
}
PyList_SET_ITEM
(
v
,
i
,
w
);
}
if
(
itemfailed
)
{
/* do_mkvalue() should have already set an error */
Py_DECREF
(
v
);
return
NULL
;
}
if
(
**
p_format
!=
endchar
)
{
Py_DECREF
(
v
);
PyErr_SetString
(
PyExc_SystemError
,
"Unmatched paren in format"
);
return
NULL
;
}
if
(
endchar
)
++*
p_format
;
return
v
;
}
static
PyObject
*
va_build_value
(
const
char
*
fmt
,
va_list
va
,
int
flags
)
noexcept
{
int
n
=
countformat
(
fmt
,
'\0'
);
...
...
src/capi/typeobject.cpp
View file @
39859d79
This diff is collapsed.
Click to expand it.
src/capi/typeobject.h
View file @
39859d79
...
...
@@ -23,7 +23,14 @@ namespace pyston {
bool
update_slot
(
BoxedClass
*
self
,
const
std
::
string
&
attr
)
noexcept
;
void
fixup_slot_dispatchers
(
BoxedClass
*
self
)
noexcept
;
void
PystonType_Ready
(
BoxedClass
*
cls
);
void
commonClassSetup
(
BoxedClass
*
cls
);
// We need to expose these due to our different file organization (they
// are defined as part of the CPython copied into typeobject.c, but used
// from Pyston code).
// We could probably unify things more but that's for later.
PyTypeObject
*
best_base
(
PyObject
*
bases
)
noexcept
;
PyObject
*
mro_external
(
PyObject
*
self
)
noexcept
;
}
#endif
src/gc/heap.cpp
View file @
39859d79
...
...
@@ -630,8 +630,8 @@ LargeArena::LargeFreeChunk* LargeArena::get_from_size_list(LargeFreeChunk** list
section
->
free_chunk_map
[
i
]
=
0
;
}
assert
(
section
->
num_free_chunks
>=
size
>>
CHUNK_BITS
);
section
->
num_free_chunks
-=
size
>>
CHUNK_BITS
;
assert
(
section
->
num_free_chunks
>=
0
);
return
free_chunks
;
}
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
39859d79
...
...
@@ -730,7 +730,7 @@ static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int
if
(
size
==
0
)
size
=
base
->
tp_basicsize
;
BoxedClass
*
cls
=
new
BoxedHeapClass
(
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
size
,
false
,
name
);
BoxedClass
*
cls
=
BoxedHeapClass
::
create
(
type_cls
,
base
,
NULL
,
offsetof
(
BoxedException
,
attrs
),
size
,
false
,
name
);
cls
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"exceptions"
));
if
(
base
==
object_cls
)
{
...
...
@@ -954,7 +954,8 @@ Box* pydumpAddr(Box* p) {
void
setupBuiltins
()
{
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
);
BoxedHeapClass
*
ellipsis_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
);
BoxedHeapClass
*
ellipsis_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
);
Box
*
Ellipsis
=
new
(
ellipsis_cls
)
Box
();
assert
(
Ellipsis
->
cls
);
gc
::
registerPermanentRoot
(
Ellipsis
);
...
...
@@ -967,7 +968,8 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"print"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
print
,
NONE
,
0
,
0
,
true
,
true
),
"print"
));
notimplemented_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
Box
),
false
,
"NotImplementedType"
);
notimplemented_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
Box
),
false
,
"NotImplementedType"
);
notimplemented_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
notimplementedRepr
,
STR
,
1
)));
notimplemented_cls
->
freeze
();
NotImplemented
=
new
(
notimplemented_cls
)
Box
();
...
...
@@ -1046,8 +1048,8 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"__import__"
,
new
BoxedBuiltinFunctionOrMethod
(
import_func
,
"__import__"
,
{
None
,
None
,
None
,
new
BoxedInt
(
-
1
)
}));
enumerate_cls
=
new
BoxedHeapClass
(
object_cls
,
&
BoxedEnumerate
::
gcHandler
,
0
,
sizeof
(
BoxedEnumerate
),
false
,
"enumerate"
);
enumerate_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedEnumerate
::
gcHandler
,
0
,
sizeof
(
BoxedEnumerate
),
false
,
"enumerate"
);
enumerate_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedEnumerate
::
new_
,
UNKNOWN
,
3
,
1
,
false
,
false
),
{
boxInt
(
0
)
}));
...
...
src/runtime/builtin_modules/sys.cpp
View file @
39859d79
...
...
@@ -294,7 +294,8 @@ void setupSys() {
sys_module
->
giveAttr
(
"maxint"
,
boxInt
(
PYSTON_INT_MAX
));
sys_flags_cls
=
new
BoxedHeapClass
(
object_cls
,
BoxedSysFlags
::
gcHandler
,
0
,
sizeof
(
BoxedSysFlags
),
false
,
"flags"
);
sys_flags_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
BoxedSysFlags
::
gcHandler
,
0
,
sizeof
(
BoxedSysFlags
),
false
,
"flags"
);
sys_flags_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedSysFlags
::
__new__
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
#define ADD(name) \
...
...
src/runtime/builtin_modules/thread.cpp
View file @
39859d79
...
...
@@ -179,7 +179,7 @@ void setupThread() {
thread_module
->
giveAttr
(
"stack_size"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
stackSize
,
BOXED_INT
,
0
),
"stack_size"
));
thread_lock_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedThreadLock
),
false
,
"lock"
);
thread_lock_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedThreadLock
),
false
,
"lock"
);
thread_lock_cls
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"thread"
));
thread_lock_cls
->
giveAttr
(
"acquire"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedThreadLock
::
acquire
,
BOXED_BOOL
,
2
,
1
,
false
,
false
),
...
...
@@ -191,13 +191,13 @@ void setupThread() {
thread_lock_cls
->
giveAttr
(
"__exit__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedThreadLock
::
exit
,
NONE
,
4
)));
thread_lock_cls
->
freeze
();
thread_local_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedThreadLocal
),
false
,
"_local"
);
thread_local_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedThreadLocal
),
false
,
"_local"
);
thread_local_cls
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"thread"
));
thread_local_cls
->
freeze
();
thread_module
->
giveAttr
(
"_local"
,
thread_local_cls
);
BoxedClass
*
ThreadError
=
new
BoxedHeapClass
(
Exception
,
NULL
,
Exception
->
attrs_offset
,
Exception
->
tp_basicsize
,
false
,
"error"
);
BoxedClass
*
ThreadError
=
BoxedHeapClass
::
create
(
type_cls
,
Exception
,
NULL
,
Exception
->
attrs_offset
,
Exception
->
tp_basicsize
,
false
,
"error"
);
ThreadError
->
giveAttr
(
"__module__"
,
boxStrConstant
(
"thread"
));
ThreadError
->
freeze
();
...
...
src/runtime/capi.cpp
View file @
39859d79
...
...
@@ -501,6 +501,8 @@ extern "C" Py_ssize_t PySequence_Index(PyObject* o, PyObject* value) noexcept {
extern
"C"
PyObject
*
PySequence_Tuple
(
PyObject
*
o
)
noexcept
{
if
(
o
->
cls
==
tuple_cls
)
return
o
;
if
(
PyList_Check
(
o
))
return
PyList_AsTuple
(
o
);
Py_FatalError
(
"unimplemented"
);
}
...
...
@@ -1543,7 +1545,7 @@ static Box* methodGetDoc(Box* b, void*) {
}
void
setupCAPI
()
{
capifunc_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedCApiFunction
),
false
,
"capifunc"
);
capifunc_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedCApiFunction
),
false
,
"capifunc"
);
capifunc_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedCApiFunction
::
__repr__
,
UNKNOWN
,
1
)));
...
...
@@ -1554,7 +1556,7 @@ void setupCAPI() {
capifunc_cls
->
freeze
();
method_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedMethodDescriptor
),
false
,
"method"
);
method_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedMethodDescriptor
),
false
,
"method"
);
method_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedMethodDescriptor
::
__get__
,
UNKNOWN
,
3
)));
method_cls
->
giveAttr
(
"__call__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedMethodDescriptor
::
__call__
,
UNKNOWN
,
2
,
...
...
@@ -1562,13 +1564,14 @@ void setupCAPI() {
method_cls
->
giveAttr
(
"__doc__"
,
new
(
pyston_getset_cls
)
BoxedGetsetDescriptor
(
methodGetDoc
,
NULL
,
NULL
));
method_cls
->
freeze
();
wrapperdescr_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedWrapperDescriptor
),
false
,
"wrapper_descriptor"
);
wrapperdescr_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedWrapperDescriptor
),
false
,
"wrapper_descriptor"
);
wrapperdescr_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedWrapperDescriptor
::
__get__
,
UNKNOWN
,
3
)));
wrapperdescr_cls
->
freeze
();
wrapperobject_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedWrapperObject
),
false
,
"method-wrapper"
);
wrapperobject_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedWrapperObject
),
false
,
"method-wrapper"
);
wrapperobject_cls
->
giveAttr
(
"__call__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedWrapperObject
::
__call__
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
wrapperobject_cls
->
freeze
();
...
...
src/runtime/classobj.cpp
View file @
39859d79
...
...
@@ -270,10 +270,10 @@ Box* instanceSetitem(Box* _inst, Box* key, Box* value) {
}
void
setupClassobj
()
{
classobj_cls
=
new
BoxedHeapClass
(
object_cls
,
&
BoxedClassobj
::
gcHandler
,
offsetof
(
BoxedClassobj
,
attrs
)
,
sizeof
(
BoxedClassobj
),
false
,
"classobj"
);
instance_cls
=
new
BoxedHeapClass
(
object_cls
,
&
BoxedInstance
::
gcHandler
,
offsetof
(
BoxedInstance
,
attrs
)
,
sizeof
(
BoxedInstance
),
false
,
"instance"
);
classobj_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedClassobj
::
gcHandler
,
offsetof
(
BoxedClassobj
,
attrs
),
sizeof
(
BoxedClassobj
),
false
,
"classobj"
);
instance_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedInstance
::
gcHandler
,
offsetof
(
BoxedInstance
,
attrs
),
sizeof
(
BoxedInstance
),
false
,
"instance"
);
classobj_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
classobjNew
,
UNKNOWN
,
4
,
0
,
false
,
false
)));
...
...
src/runtime/dict.cpp
View file @
39859d79
...
...
@@ -572,13 +572,15 @@ static Box* dict_repr(PyObject* self) noexcept {
}
void
setupDict
()
{
dict_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
dictIteratorGCHandler
,
0
,
sizeof
(
BoxedDict
),
false
,
"dictionary-itemiterator"
);
dict_keys_cls
=
new
BoxedHeapClass
(
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_keys"
);
dict_values_cls
=
new
BoxedHeapClass
(
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_values"
);
dict_items_cls
=
new
BoxedHeapClass
(
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_items"
);
dict_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
dictIteratorGCHandler
,
0
,
sizeof
(
BoxedDict
),
false
,
"dictionary-itemiterator"
);
dict_keys_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_keys"
);
dict_values_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_values"
);
dict_items_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
dictViewGCHandler
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_items"
);
dict_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictLen
,
BOXED_INT
,
1
)));
dict_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
...
...
src/runtime/generator.cpp
View file @
39859d79
...
...
@@ -298,8 +298,8 @@ void generatorDestructor(Box* b) {
}
void
setupGenerator
()
{
generator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
generatorGCHandler
,
offsetof
(
BoxedGenerator
,
attrs
),
sizeof
(
BoxedGenerator
),
false
,
"generator"
);
generator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
generatorGCHandler
,
offsetof
(
BoxedGenerator
,
attrs
),
sizeof
(
BoxedGenerator
),
false
,
"generator"
);
generator_cls
->
simple_destructor
=
generatorDestructor
;
generator_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
generatorIter
,
typeFromClass
(
generator_cls
),
1
)));
...
...
src/runtime/inline/xrange.cpp
View file @
39859d79
...
...
@@ -178,9 +178,9 @@ Box* xrangeReversed(Box* self) {
}
void
setupXrange
()
{
xrange_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedXrange
),
false
,
"xrange"
);
xrange_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
BoxedXrangeIterator
::
xrangeIteratorGCHandler
,
0
,
sizeof
(
BoxedXrangeIterator
),
false
,
"rangeiterator"
);
xrange_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedXrange
),
false
,
"xrange"
);
xrange_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedXrangeIterator
::
xrangeIteratorGCHandler
,
0
,
sizeof
(
BoxedXrangeIterator
),
false
,
"rangeiterator"
);
xrange_cls
->
giveAttr
(
"__new__"
,
...
...
src/runtime/iterobject.cpp
View file @
39859d79
...
...
@@ -141,7 +141,8 @@ extern "C" PyObject* PySeqIter_New(PyObject* seq) noexcept {
}
void
setupIter
()
{
seqiter_cls
=
new
BoxedHeapClass
(
object_cls
,
seqiterGCVisit
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
);
seqiter_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
seqiterGCVisit
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
);
seqiter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqiter_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterHasnext
,
BOXED_BOOL
,
1
)));
...
...
@@ -149,7 +150,7 @@ void setupIter() {
seqiter_cls
->
freeze
();
seqreviter_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"reversed"
);
seqreviter_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
NULL
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"reversed"
);
seqreviter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqreviter_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqreviterHasnext
,
BOXED_BOOL
,
1
)));
...
...
@@ -157,8 +158,8 @@ void setupIter() {
seqreviter_cls
->
freeze
();
iterwrapper_cls
=
new
BoxedHeapClass
(
object_cls
,
iterwrapperGCVisit
,
0
,
sizeof
(
BoxedIterWrapper
),
false
,
"iterwrapper"
);
iterwrapper_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
iterwrapperGCVisit
,
0
,
sizeof
(
BoxedIterWrapper
),
false
,
"iterwrapper"
);
iterwrapper_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
iterwrapperNext
,
UNKNOWN
,
1
)));
iterwrapper_cls
->
giveAttr
(
"__hasnext__"
,
...
...
src/runtime/list.cpp
View file @
39859d79
...
...
@@ -49,6 +49,19 @@ extern "C" PyObject** PyList_Items(PyObject* op) noexcept {
return
&
static_cast
<
BoxedList
*>
(
op
)
->
elts
->
elts
[
0
];
}
extern
"C"
PyObject
*
PyList_AsTuple
(
PyObject
*
v
)
noexcept
{
PyObject
*
w
;
PyObject
**
p
,
**
q
;
Py_ssize_t
n
;
if
(
v
==
NULL
||
!
PyList_Check
(
v
))
{
PyErr_BadInternalCall
();
return
NULL
;
}
auto
l
=
static_cast
<
BoxedList
*>
(
v
);
return
new
BoxedTuple
(
BoxedTuple
::
GCVector
(
l
->
elts
->
elts
,
l
->
elts
->
elts
+
l
->
size
));
}
extern
"C"
Box
*
listRepr
(
BoxedList
*
self
)
{
LOCK_REGION
(
self
->
lock
.
asRead
());
...
...
@@ -751,10 +764,10 @@ extern "C" int PyList_SetSlice(PyObject* a, Py_ssize_t ilow, Py_ssize_t ihigh, P
}
void
setupList
()
{
list_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
listIteratorGCHandler
,
0
,
sizeof
(
BoxedList
),
false
,
"listiterator"
);
list_reverse_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
listIteratorGCHandler
,
0
,
sizeof
(
BoxedListIterator
)
,
false
,
"listreverseiterator"
);
list_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
listIteratorGCHandler
,
0
,
sizeof
(
BoxedList
),
false
,
"listiterator"
);
list_reverse_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
listIteratorGCHandler
,
0
,
sizeof
(
BoxedListIterator
),
false
,
"listreverseiterator"
);
list_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listLen
,
BOXED_INT
,
1
)));
...
...
src/runtime/objmodel.cpp
View file @
39859d79
This diff is collapsed.
Click to expand it.
src/runtime/set.cpp
View file @
39859d79
...
...
@@ -246,7 +246,8 @@ Box* setNonzero(BoxedSet* self) {
using
namespace
pyston
::
set
;
void
setupSet
()
{
set_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
setIteratorGCHandler
,
0
,
sizeof
(
BoxedSet
),
false
,
"setiterator"
);
set_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
setIteratorGCHandler
,
0
,
sizeof
(
BoxedSet
),
false
,
"setiterator"
);
set_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorHasnext
,
BOXED_BOOL
,
1
)));
set_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setiteratorNext
,
UNKNOWN
,
1
)));
...
...
src/runtime/str.cpp
View file @
39859d79
...
...
@@ -2208,8 +2208,8 @@ void setupStr() {
str_cls
->
simple_destructor
=
strDestructor
;
str_cls
->
tp_flags
|=
Py_TPFLAGS_HAVE_NEWBUFFER
;
str_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
strIteratorGCHandler
,
0
,
sizeof
(
BoxedStringIterator
),
false
,
"striterator"
);
str_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
strIteratorGCHandler
,
0
,
sizeof
(
BoxedStringIterator
),
false
,
"striterator"
);
str_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedStringIterator
::
hasnext
,
BOXED_BOOL
,
1
)));
str_iterator_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedStringIterator
::
next
,
STR
,
1
)));
...
...
src/runtime/super.cpp
View file @
39859d79
...
...
@@ -16,6 +16,7 @@
#include <sstream>
#include "capi/types.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/objmodel.h"
...
...
@@ -66,15 +67,68 @@ Box* superGetattribute(Box* _s, Box* _attr) {
}
if
(
!
skip
)
{
// We don't support multiple inheritance yet, so the lookup order is simple:
Box
*
r
=
typeLookup
(
s
->
type
->
tp_base
,
attr
->
s
,
NULL
);
if
(
r
)
{
return
processDescriptor
(
r
,
(
s
->
obj
==
s
->
obj_type
?
None
:
s
->
obj
),
s
->
obj_type
);
PyObject
*
mro
,
*
res
,
*
tmp
,
*
dict
;
PyTypeObject
*
starttype
;
descrgetfunc
f
;
Py_ssize_t
i
,
n
;
starttype
=
s
->
obj_type
;
mro
=
starttype
->
tp_mro
;
if
(
mro
==
NULL
)
n
=
0
;
else
{
assert
(
PyTuple_Check
(
mro
));
n
=
PyTuple_GET_SIZE
(
mro
);
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
((
PyObject
*
)(
s
->
type
)
==
PyTuple_GET_ITEM
(
mro
,
i
))
break
;
}
i
++
;
res
=
NULL
;
for
(;
i
<
n
;
i
++
)
{
tmp
=
PyTuple_GET_ITEM
(
mro
,
i
);
// Pyston change:
#if 0
if (PyType_Check(tmp))
dict = ((PyTypeObject *)tmp)->tp_dict;
else if (PyClass_Check(tmp))
dict = ((PyClassObject *)tmp)->cl_dict;
else
continue;
res = PyDict_GetItem(dict, name);
#endif
res
=
tmp
->
getattr
(
attr
->
s
);
if
(
res
!=
NULL
)
{
// Pyston change:
#if 0
Py_INCREF(res);
f = Py_TYPE(res)->tp_descr_get;
if (f != NULL) {
tmp = f(res,
/* Only pass 'obj' param if
this is instance-mode sper
(See SF ID #743627)
*/
(s->obj == (PyObject *)
s->obj_type
? (PyObject *)NULL
: s->obj),
(PyObject *)starttype);
Py_DECREF(res);
res = tmp;
}
#endif
return
processDescriptor
(
res
,
(
s
->
obj
==
s
->
obj_type
?
None
:
s
->
obj
),
s
->
obj_type
);
}
}
}
Box
*
r
=
typeLookup
(
s
->
cls
,
attr
->
s
,
NULL
);
// TODO implement this
RELEASE_ASSERT
(
r
,
"should call the equivalent of objectGetattr here"
);
return
processDescriptor
(
r
,
s
,
s
->
cls
);
}
...
...
@@ -132,7 +186,8 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
}
void
setupSuper
()
{
super_cls
=
new
BoxedHeapClass
(
object_cls
,
&
BoxedSuper
::
gcHandler
,
0
,
sizeof
(
BoxedSuper
),
false
,
"super"
);
super_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
BoxedSuper
::
gcHandler
,
0
,
sizeof
(
BoxedSuper
),
false
,
"super"
);
super_cls
->
giveAttr
(
"__getattribute__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
superGetattribute
,
UNKNOWN
,
2
)));
super_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
superRepr
,
STR
,
1
)));
...
...
src/runtime/traceback.cpp
View file @
39859d79
...
...
@@ -107,8 +107,8 @@ Box* BoxedTraceback::getLines(Box* b) {
}
void
setupTraceback
()
{
traceback_cls
=
new
BoxedHeapClass
(
object_cls
,
BoxedTraceback
::
gcHandler
,
0
,
sizeof
(
BoxedTraceback
),
false
,
"traceback"
);
traceback_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
BoxedTraceback
::
gcHandler
,
0
,
sizeof
(
BoxedTraceback
),
false
,
"traceback"
);
traceback_cls
->
giveAttr
(
"getLines"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
BoxedTraceback
::
getLines
,
UNKNOWN
,
1
)));
...
...
src/runtime/tuple.cpp
View file @
39859d79
...
...
@@ -386,7 +386,8 @@ extern "C" void tupleIteratorGCHandler(GCVisitor* v, Box* b) {
void
setupTuple
()
{
tuple_iterator_cls
=
new
BoxedHeapClass
(
object_cls
,
&
tupleIteratorGCHandler
,
0
,
sizeof
(
BoxedTuple
),
false
,
"tuple"
);
tuple_iterator_cls
=
BoxedHeapClass
::
create
(
type_cls
,
object_cls
,
&
tupleIteratorGCHandler
,
0
,
sizeof
(
BoxedTuple
),
false
,
"tuple"
);
tuple_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
tupleNew
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
CLFunction
*
getitem
=
createRTFunction
(
2
,
0
,
0
,
0
);
...
...
src/runtime/types.cpp
View file @
39859d79
This diff is collapsed.
Click to expand it.
src/runtime/types.h
View file @
39859d79
...
...
@@ -192,9 +192,15 @@ public:
void
freeze
();
protected:
// These functions are not meant for external callers and will mostly just be called
// by BoxedHeapClass::create(), but setupRuntime() also needs to do some manual class
// creation due to bootstrapping issues.
void
finishInitialization
();
BoxedClass
(
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
);
DEFAULT_CLASS
(
type_cls
);
friend
void
setupRuntime
(
);
};
class
BoxedHeapClass
:
public
BoxedClass
{
...
...
@@ -207,15 +213,22 @@ public:
BoxedString
*
ht_name
;
PyObject
**
ht_slots
;
BoxedHeapClass
(
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
,
const
std
::
string
&
name
);
// These functions are the preferred way to construct new types:
static
BoxedHeapClass
*
create
(
BoxedClass
*
metatype
,
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
,
BoxedString
*
name
,
BoxedTuple
*
bases
);
static
BoxedHeapClass
*
create
(
BoxedClass
*
metatype
,
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
,
const
std
::
string
&
name
);
private:
// These functions are not meant for external callers and will mostly just be called
// by BoxedHeapClass::create(), but setupRuntime() also needs to do some manual class
// creation due to bootstrapping issues.
BoxedHeapClass
(
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
,
BoxedString
*
name
);
// This constructor is only used for bootstrapping purposes to be called for types that
// are initialized before str_cls.
BoxedHeapClass
(
BoxedClass
*
base
,
gcvisit_func
gc_visit
,
int
attrs_offset
,
int
instance_size
,
bool
is_user_defined
);
friend
void
setupRuntime
();
DEFAULT_CLASS
(
type_cls
);
};
static_assert
(
sizeof
(
pyston
::
Box
)
==
sizeof
(
struct
_object
),
""
);
...
...
test/tests/multiple_inheritance.py
0 → 100644
View file @
39859d79
# Testing the basic multiple-inheritance rules and functionality:
class
C
(
object
):
n
=
1
def
c
(
self
):
print
"C.c()"
def
f
(
self
):
print
"C.f()"
,
self
.
n
class
D
(
object
):
n
=
2
def
d
(
self
):
print
"D.d()"
def
f
(
self
):
print
"D.f()"
,
self
.
n
class
E
(
C
,
D
):
pass
class
F
(
D
,
C
):
pass
class
G
(
E
,
D
):
pass
for
o
in
[
C
(),
D
(),
E
(),
F
()]:
print
type
(
o
),
type
(
o
).
mro
(),
type
(
o
).
__mro__
o
.
f
()
try
:
o
.
c
()
except
Exception
,
e
:
print
e
try
:
o
.
d
()
except
Exception
,
e
:
print
e
# Testing invalid multiple inheritance hierarchies:
# Conflicting MRO:
try
:
class
G
(
E
,
F
):
pass
except
TypeError
,
e
:
# This is silly but I think actually reasonable: the error message for this case is implementation-specific,
# since it depends on dict ordering rules (says either "for bases E, F" or "for bases F, E", depending on ordering).
# Canonicalize the error message by sorting the characters in it:
print
''
.
join
(
sorted
(
e
.
message
)).
strip
()
# Conflicting MRO:
try
:
class
H
(
C
,
F
):
pass
except
TypeError
,
e
:
print
''
.
join
(
sorted
(
e
.
message
)).
strip
()
# "instance lay-out conflict"
try
:
class
I
(
str
,
int
):
pass
except
TypeError
,
e
:
print
e
# Testing the way super() behaves with multiple inheritance:
class
S
(
C
,
D
):
n
=
3
def
c
(
self
):
print
"S.c()"
super
(
S
,
self
).
c
()
def
d
(
self
):
print
"S.d()"
super
(
S
,
self
).
d
()
def
f
(
self
):
print
"S.f()"
print
self
.
n
,
super
(
S
,
self
).
n
,
super
(
C
,
self
).
n
# TODO: Pyston doesn't support the full super.__getattribute__, so this will abort
# rather than throw an exception:
# try:
# print super(D, self).n
# except Exception as e:
# print e
super
(
S
,
self
).
f
()
super
(
C
,
self
).
f
()
s
=
S
()
s
.
c
()
s
.
d
()
s
.
f
()
for
cls
in
[
object
,
tuple
,
list
,
type
,
int
,
bool
]:
print
cls
.
__mro__
test/tests/super.py
View file @
39859d79
...
...
@@ -5,6 +5,9 @@ class B(object):
o
.
arg1
=
arg1
return
o
def
f
(
self
):
print
"B.f()"
class
C
(
B
):
def
__new__
(
cls
,
arg1
,
arg2
):
print
"C.__new__"
,
arg2
...
...
@@ -13,9 +16,14 @@ class C(B):
print
super
(
C
,
cls
),
super
(
C
,
o
)
return
o
def
f
(
self
):
print
"C.f()"
super
(
C
,
self
).
f
()
c
=
C
(
1
,
2
)
print
c
.
arg1
print
c
.
arg2
c
.
f
()
try
:
super
(
1
)
...
...
tools/tester.py
View file @
39859d79
...
...
@@ -413,16 +413,16 @@ if __name__ == "__main__":
]
tests += big_tests
LIB_DIR = os.path.join(sys.prefix, "lib/python2.7")
for t in tests:
bn = os.path.basename(t)
assert bn.endswith(".py")
module_name = bn[:-3]
try:
__import__(module_name)
if os.path.exists(os.path.join(LIB_DIR, module_name)) or
\
os.path.exists(os.path.join(LIB_DIR, module_name + ".py")) or
\
module_name in sys.builtin_module_names:
raise Exception("Error: %s hides builtin module '%s'" % (t, module_name))
except ImportError:
pass
# good
for t in TOSKIP:
assert t in ("%s/t.py" % TEST_DIR, "%s/t2.py" % TEST_DIR) or t in tests, t
...
...
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