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
e70d720a
Commit
e70d720a
authored
Jan 13, 2016
by
Marius Wachtler
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1052 from undingen/pytest_fixes
fixes for py.test
parents
3a81033b
ca40452b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
74 additions
and
31 deletions
+74
-31
from_cpython/Python/_warnings.c
from_cpython/Python/_warnings.c
+2
-1
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+6
-0
src/codegen/codegen.cpp
src/codegen/codegen.cpp
+1
-1
src/runtime/frame.cpp
src/runtime/frame.cpp
+1
-4
src/runtime/import.cpp
src/runtime/import.cpp
+30
-23
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+1
-1
test/tests/compile_test.py
test/tests/compile_test.py
+3
-0
test/tests/import_test.py
test/tests/import_test.py
+6
-0
test/tests/sys_meta_path.py
test/tests/sys_meta_path.py
+20
-1
test/tests/warnings_test.py
test/tests/warnings_test.py
+4
-0
No files found.
from_cpython/Python/_warnings.c
View file @
e70d720a
...
...
@@ -472,7 +472,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup registry. */
assert
(
globals
!=
NULL
);
assert
(
PyDict_Check
(
globals
));
// Pyston change: PyFrame_GetGlobals returns a attrwrapper object not a real dict
// assert(PyDict_Check(globals));
*
registry
=
PyDict_GetItemString
(
globals
,
"__warningregistry__"
);
if
(
*
registry
==
NULL
)
{
int
rc
;
...
...
src/capi/typeobject.cpp
View file @
e70d720a
...
...
@@ -3404,6 +3404,12 @@ extern "C" void PyType_GiveHcAttrsDictDescr(PyTypeObject* cls) noexcept {
extern
"C"
int
PyType_Ready
(
PyTypeObject
*
cls
)
noexcept
{
ASSERT
(
!
cls
->
is_pyston_class
,
"should not call this on Pyston classes"
);
// if this type is already in ready state we are finished.
if
(
cls
->
tp_flags
&
Py_TPFLAGS_READY
)
{
assert
(
cls
->
tp_dict
!=
NULL
);
return
0
;
}
gc
::
registerNonheapRootObject
(
cls
,
sizeof
(
PyTypeObject
));
// unhandled fields:
...
...
src/codegen/codegen.cpp
View file @
e70d720a
...
...
@@ -116,7 +116,7 @@ SourceInfo::SourceInfo(BoxedModule* m, ScopingAnalysis* scoping, FutureFlags fut
ast
(
ast
),
cfg
(
NULL
),
body
(
std
::
move
(
body
))
{
assert
(
fn
->
size
()
);
assert
(
fn
);
// TODO: we should track this reference correctly rather than making it a root
gc
::
registerPermanentRoot
(
fn
,
true
);
this
->
fn
=
fn
;
...
...
src/runtime/frame.cpp
View file @
e70d720a
...
...
@@ -163,10 +163,7 @@ extern "C" int PyFrame_GetLineNumber(PyFrameObject* _f) noexcept {
}
extern
"C"
PyObject
*
PyFrame_GetGlobals
(
PyFrameObject
*
f
)
noexcept
{
Box
*
globals
=
BoxedFrame
::
globals
((
Box
*
)
f
,
NULL
);
if
(
globals
->
cls
==
attrwrapper_cls
)
return
attrwrapperToDict
(
globals
);
return
globals
;
return
BoxedFrame
::
globals
((
Box
*
)
f
,
NULL
);
}
extern
"C"
PyFrameObject
*
PyFrame_ForStackLevel
(
int
stack_level
)
noexcept
{
...
...
src/runtime/import.cpp
View file @
e70d720a
...
...
@@ -184,22 +184,25 @@ struct SearchResult {
SearchResult
(
Box
*
loader
)
:
loader
(
loader
),
type
(
IMP_HOOK
)
{}
};
SearchResult
findModule
(
const
std
::
string
&
name
,
BoxedString
*
full_name
,
BoxedList
*
path_list
)
{
static
BoxedString
*
meta_path_str
=
internStringImmortal
(
"meta_path"
);
BoxedList
*
meta_path
=
static_cast
<
BoxedList
*>
(
sys_module
->
getattr
(
meta_path_str
));
if
(
!
meta_path
||
meta_path
->
cls
!=
list_cls
)
raiseExcHelper
(
RuntimeError
,
"sys.meta_path must be a list of import hooks"
);
SearchResult
findModule
(
const
std
::
string
&
name
,
BoxedString
*
full_name
,
BoxedList
*
path_list
,
bool
call_import_hooks
)
{
static
BoxedString
*
findmodule_str
=
internStringImmortal
(
"find_module"
);
for
(
int
i
=
0
;
i
<
meta_path
->
size
;
i
++
)
{
Box
*
finder
=
meta_path
->
elts
->
elts
[
i
];
auto
path_pass
=
path_list
?
path_list
:
None
;
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
false
,
.
argspec
=
ArgPassSpec
(
2
)
};
Box
*
loader
=
callattr
(
finder
,
findmodule_str
,
callattr_flags
,
full_name
,
path_pass
,
NULL
,
NULL
,
NULL
);
if
(
call_import_hooks
)
{
static
BoxedString
*
meta_path_str
=
internStringImmortal
(
"meta_path"
);
BoxedList
*
meta_path
=
static_cast
<
BoxedList
*>
(
sys_module
->
getattr
(
meta_path_str
));
if
(
!
meta_path
||
meta_path
->
cls
!=
list_cls
)
raiseExcHelper
(
RuntimeError
,
"sys.meta_path must be a list of import hooks"
);
for
(
int
i
=
0
;
i
<
meta_path
->
size
;
i
++
)
{
Box
*
finder
=
meta_path
->
elts
->
elts
[
i
];
auto
path_pass
=
path_list
?
path_list
:
None
;
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
false
,
.
argspec
=
ArgPassSpec
(
2
)
};
Box
*
loader
=
callattr
(
finder
,
findmodule_str
,
callattr_flags
,
full_name
,
path_pass
,
NULL
,
NULL
,
NULL
);
if
(
loader
!=
None
)
return
SearchResult
(
loader
);
if
(
loader
!=
None
)
return
SearchResult
(
loader
);
}
}
if
(
!
path_list
)
...
...
@@ -240,15 +243,19 @@ SearchResult findModule(const std::string& name, BoxedString* full_name, BoxedLi
llvm
::
sys
::
path
::
append
(
joined_path
,
"__init__.py"
);
std
::
string
fn
(
joined_path
.
str
());
PyObject
*
importer
=
get_path_importer
(
path_importer_cache
,
path_hooks
,
_p
);
if
(
importer
==
NULL
)
throwCAPIException
();
if
(
call_import_hooks
)
{
PyObject
*
importer
=
get_path_importer
(
path_importer_cache
,
path_hooks
,
_p
);
if
(
importer
==
NULL
)
throwCAPIException
();
if
(
importer
!=
None
)
{
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
false
,
.
argspec
=
ArgPassSpec
(
1
)
};
Box
*
loader
=
callattr
(
importer
,
findmodule_str
,
callattr_flags
,
full_name
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
loader
!=
None
)
return
SearchResult
(
loader
);
if
(
importer
!=
None
)
{
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
false
,
.
argspec
=
ArgPassSpec
(
1
)
};
Box
*
loader
=
callattr
(
importer
,
findmodule_str
,
callattr_flags
,
full_name
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
loader
!=
None
)
return
SearchResult
(
loader
);
}
}
if
(
pathExists
(
fn
))
...
...
@@ -405,7 +412,7 @@ static Box* importSub(const std::string& name, BoxedString* full_name, Box* pare
}
}
SearchResult
sr
=
findModule
(
name
,
full_name
,
path_list
);
SearchResult
sr
=
findModule
(
name
,
full_name
,
path_list
,
true
/* call_import_hooks */
);
if
(
sr
.
type
!=
SearchResult
::
SEARCH_ERROR
)
{
Box
*
module
;
...
...
@@ -721,7 +728,7 @@ Box* impFindModule(Box* _name, BoxedList* path) {
BoxedString
*
name
=
static_cast
<
BoxedString
*>
(
_name
);
BoxedList
*
path_list
=
path
&&
path
!=
None
?
path
:
getSysPath
();
SearchResult
sr
=
findModule
(
name
->
s
(),
name
,
path_list
);
SearchResult
sr
=
findModule
(
name
->
s
(),
name
,
path_list
,
false
/* call_import_hooks */
);
if
(
sr
.
type
==
SearchResult
::
SEARCH_ERROR
)
raiseExcHelper
(
ImportError
,
"%s"
,
name
->
data
());
...
...
src/runtime/objmodel.cpp
View file @
e70d720a
...
...
@@ -2642,7 +2642,7 @@ extern "C" bool nonzero(Box* obj) {
||
obj
->
cls
==
capifunc_cls
||
obj
->
cls
==
builtin_function_or_method_cls
||
obj
->
cls
==
method_cls
||
obj
->
cls
==
frame_cls
||
obj
->
cls
==
generator_cls
||
obj
->
cls
==
capi_getset_cls
||
obj
->
cls
==
pyston_getset_cls
||
obj
->
cls
==
wrapperdescr_cls
||
obj
->
cls
==
wrapperobject_cls
,
||
obj
->
cls
==
wrapperobject_cls
||
obj
->
cls
==
code_cls
,
"%s.__nonzero__"
,
getTypeName
(
obj
));
// TODO
if
(
rewriter
.
get
())
{
...
...
test/tests/compile_test.py
View file @
e70d720a
...
...
@@ -20,6 +20,9 @@ exec compile('print(1, 2)', 'test.py', 'exec')
tree
=
compile
(
'print(1, 2)'
,
'test.py'
,
'exec'
,
_ast
.
PyCF_ONLY_AST
)
exec
compile
(
tree
,
'<tree>'
,
'exec'
)
c
=
compile
(
'print(1, 2)'
,
''
,
'exec'
)
exec
c
print
(
c
.
co_name
,
c
.
co_filename
)
# test bad syntax which should not raise in compile time:
try
:
...
...
test/tests/import_test.py
View file @
e70d720a
...
...
@@ -29,3 +29,9 @@ print y
print
__name__
print
__import__
(
"import_target"
)
is
import_target
import
sys
import
_multiprocessing
del
_multiprocessing
del
sys
.
modules
[
"_multiprocessing"
]
import
_multiprocessing
test/tests/sys_meta_path.py
View file @
e70d720a
...
...
@@ -42,18 +42,29 @@ except ImportError, e:
# So unfortunately we can't print out the error message.
print
"caught import error 1"
def
ImportErrorPathHook
(
a
):
print
"ImportErrorPathHook"
,
a
raise
ImportError
sys
.
path_hooks
.
insert
(
0
,
ImportErrorPathHook
)
sys
.
path_hooks
.
append
(
Finder2
)
try
:
import
a.b.test
except
ImportError
,
e
:
print
"caught import error 2"
# this should not call into ImportErrorPathHook
try
:
imp
.
find_module
(
"foobar"
,
[
"/"
])
except
ImportError
,
e
:
print
"caught import error 3"
sys
.
path
.
append
(
"/my_magic_directory"
)
try
:
import
a.b.test
except
ImportError
,
e
:
print
"caught import error
3
"
print
"caught import error
4
"
sys
.
meta_path
.
append
(
Finder
())
import
a
...
...
@@ -62,3 +73,11 @@ import a.b.test as test
print
test
import
a.b
as
b
print
b
class
RecursiveLoader
(
object
):
def
find_module
(
self
,
name
,
path
=
None
):
print
"RecursiveLoader"
,
name
,
path
imp
.
find_module
(
name
,
path
)
return
Loader
()
sys
.
meta_path
.
insert
(
0
,
RecursiveLoader
())
import
subprocess
test/tests/warnings_test.py
View file @
e70d720a
import
warnings
import
_warnings
print
"__warningregistry__"
in
globals
()
warnings
.
filterwarnings
(
'error'
)
try
:
...
...
@@ -12,3 +14,5 @@ try:
_warnings
.
warn
(
"deperecated"
,
Warning
)
except
Warning
as
w
:
print
(
w
.
args
[
0
])
print
"__warningregistry__"
in
globals
()
Boxiang Sun
@Daetalus
mentioned in commit
3bedca63
·
Sep 08, 2016
mentioned in commit
3bedca63
mentioned in commit 3bedca63eb287ba3a7bd933693b469f7e9b9c5a1
Toggle commit list
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