Commit 3bedca63 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge commit 'e70d720a' into refcounting

parents f9205898 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;
......
......@@ -3384,6 +3384,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;
}
_Py_INC_REFTOTAL;
classes.push_back(cls);
......
......@@ -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;
......
......@@ -168,10 +168,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 {
......
......@@ -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 = getStaticString("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 = getStaticString("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 = getStaticString("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;
......@@ -732,7 +739,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());
......
......@@ -3046,7 +3046,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()) {
......
......@@ -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:
......
......@@ -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
......@@ -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
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment