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
780c42f7
Commit
780c42f7
authored
Apr 24, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the module from sys.modules if importing failed
parent
03ac7b78
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
20 deletions
+54
-20
from_cpython/Lib/modulefinder.py
from_cpython/Lib/modulefinder.py
+0
-5
src/runtime/import.cpp
src/runtime/import.cpp
+37
-15
test/tests/import_failure_target.py
test/tests/import_failure_target.py
+5
-0
test/tests/import_failure_test.py
test/tests/import_failure_test.py
+12
-0
No files found.
from_cpython/Lib/modulefinder.py
View file @
780c42f7
...
@@ -3,11 +3,6 @@
...
@@ -3,11 +3,6 @@
from
__future__
import
generators
from
__future__
import
generators
# Pyston change:
import
sys
del
sys
.
modules
[
'modulefinder'
]
raise
ImportError
(
"This isn't really supported in Pyston yet"
)
import
dis
import
dis
import
imp
import
imp
import
marshal
import
marshal
...
...
src/runtime/import.cpp
View file @
780c42f7
...
@@ -32,11 +32,22 @@ static const std::string path_str("__path__");
...
@@ -32,11 +32,22 @@ static const std::string path_str("__path__");
static
const
std
::
string
package_str
(
"__package__"
);
static
const
std
::
string
package_str
(
"__package__"
);
static
BoxedClass
*
null_importer_cls
;
static
BoxedClass
*
null_importer_cls
;
static
void
removeModule
(
const
std
::
string
&
name
)
{
BoxedDict
*
d
=
getSysModulesDict
();
Box
*
b_name
=
boxString
(
name
);
d
->
d
.
erase
(
b_name
);
}
BoxedModule
*
createAndRunModule
(
const
std
::
string
&
name
,
const
std
::
string
&
fn
)
{
BoxedModule
*
createAndRunModule
(
const
std
::
string
&
name
,
const
std
::
string
&
fn
)
{
BoxedModule
*
module
=
createModule
(
name
,
fn
);
BoxedModule
*
module
=
createModule
(
name
,
fn
);
AST_Module
*
ast
=
caching_parse_file
(
fn
.
c_str
());
AST_Module
*
ast
=
caching_parse_file
(
fn
.
c_str
());
try
{
compileAndRunModule
(
ast
,
module
);
compileAndRunModule
(
ast
,
module
);
}
catch
(
ExcInfo
e
)
{
removeModule
(
name
);
raiseRaw
(
e
);
}
return
module
;
return
module
;
}
}
...
@@ -51,7 +62,12 @@ static BoxedModule* createAndRunModule(const std::string& name, const std::strin
...
@@ -51,7 +62,12 @@ static BoxedModule* createAndRunModule(const std::string& name, const std::strin
module
->
setattr
(
path_str
,
path_list
,
NULL
);
module
->
setattr
(
path_str
,
path_list
,
NULL
);
AST_Module
*
ast
=
caching_parse_file
(
fn
.
c_str
());
AST_Module
*
ast
=
caching_parse_file
(
fn
.
c_str
());
try
{
compileAndRunModule
(
ast
,
module
);
compileAndRunModule
(
ast
,
module
);
}
catch
(
ExcInfo
e
)
{
removeModule
(
name
);
raiseRaw
(
e
);
}
return
module
;
return
module
;
}
}
...
@@ -363,6 +379,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
...
@@ -363,6 +379,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
if
(
sr
.
type
!=
SearchResult
::
SEARCH_ERROR
)
{
if
(
sr
.
type
!=
SearchResult
::
SEARCH_ERROR
)
{
Box
*
module
;
Box
*
module
;
try
{
if
(
sr
.
type
==
SearchResult
::
PY_SOURCE
)
if
(
sr
.
type
==
SearchResult
::
PY_SOURCE
)
module
=
createAndRunModule
(
full_name
,
sr
.
path
);
module
=
createAndRunModule
(
full_name
,
sr
.
path
);
else
if
(
sr
.
type
==
SearchResult
::
PKG_DIRECTORY
)
else
if
(
sr
.
type
==
SearchResult
::
PKG_DIRECTORY
)
...
@@ -376,6 +393,10 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
...
@@ -376,6 +393,10 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
boxString
(
full_name
),
NULL
,
NULL
,
NULL
,
NULL
);
boxString
(
full_name
),
NULL
,
NULL
,
NULL
,
NULL
);
}
else
}
else
RELEASE_ASSERT
(
0
,
"%d"
,
sr
.
type
);
RELEASE_ASSERT
(
0
,
"%d"
,
sr
.
type
);
}
catch
(
ExcInfo
e
)
{
removeModule
(
name
);
raiseRaw
(
e
);
}
if
(
parent_module
&&
parent_module
!=
None
)
if
(
parent_module
&&
parent_module
!=
None
)
parent_module
->
setattr
(
name
,
module
,
NULL
);
parent_module
->
setattr
(
name
,
module
,
NULL
);
...
@@ -609,6 +630,7 @@ extern "C" PyObject* PyImport_ExecCodeModuleEx(char* name, PyObject* co, char* p
...
@@ -609,6 +630,7 @@ extern "C" PyObject* PyImport_ExecCodeModuleEx(char* name, PyObject* co, char* p
module
->
setattr
(
"__file__"
,
boxString
(
pathname
),
NULL
);
module
->
setattr
(
"__file__"
,
boxString
(
pathname
),
NULL
);
return
module
;
return
module
;
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
removeModule
(
name
);
setCAPIException
(
e
);
setCAPIException
(
e
);
return
NULL
;
return
NULL
;
}
}
...
...
test/tests/import_failure_target.py
0 → 100644
View file @
780c42f7
# skip-if: True
import
sys
print
"import_failure_target"
in
sys
.
modules
raise
Exception
(
"pretending submodule didn't import"
)
test/tests/import_failure_test.py
View file @
780c42f7
...
@@ -62,3 +62,15 @@ def f2():
...
@@ -62,3 +62,15 @@ def f2():
except
NameError
,
e
:
except
NameError
,
e
:
print
e
print
e
f2
()
f2
()
try
:
import
import_failure_target
raise
Exception
(
"This should not be importable"
)
except
Exception
,
e
:
print
type
(
e
),
e
try
:
import
import_failure_target
raise
Exception
(
"This should not be importable if we tried it again"
)
except
Exception
,
e
:
print
type
(
e
),
e
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