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
042eb9a9
Commit
042eb9a9
authored
Aug 29, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Found the issue: don't handle imports in try blocks correctly
parent
5003059e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
117 additions
and
7 deletions
+117
-7
include/Python.h
include/Python.h
+3
-0
include/pyctype.h
include/pyctype.h
+33
-0
src/jit.cpp
src/jit.cpp
+1
-1
src/runtime/stacktrace.cpp
src/runtime/stacktrace.cpp
+24
-0
test/tests/import_failure_test.py
test/tests/import_failure_test.py
+56
-6
No files found.
include/Python.h
View file @
042eb9a9
...
...
@@ -16,6 +16,7 @@
#define PYSTON_EXTINCLUDE_PYTHON_H
#include <assert.h>
#include <ctype.h> // it looks like this gets included via unicodeobject.h in CPython
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
...
...
@@ -62,6 +63,8 @@
#include "abstract.h"
#include "pyctype.h"
// directly from CPython:
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
...
...
include/pyctype.h
0 → 100644
View file @
042eb9a9
// This file is originally from CPython 2.7, with modifications for Pyston
#ifndef PYCTYPE_H
#define PYCTYPE_H
#define PY_CTF_LOWER 0x01
#define PY_CTF_UPPER 0x02
#define PY_CTF_ALPHA (PY_CTF_LOWER|PY_CTF_UPPER)
#define PY_CTF_DIGIT 0x04
#define PY_CTF_ALNUM (PY_CTF_ALPHA|PY_CTF_DIGIT)
#define PY_CTF_SPACE 0x08
#define PY_CTF_XDIGIT 0x10
PyAPI_DATA
(
const
unsigned
int
)
_Py_ctype_table
[
256
];
/* Unlike their C counterparts, the following macros are not meant to
* handle an int with any of the values [EOF, 0-UCHAR_MAX]. The argument
* must be a signed/unsigned char. */
#define Py_ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_LOWER)
#define Py_ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_UPPER)
#define Py_ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALPHA)
#define Py_ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_DIGIT)
#define Py_ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_XDIGIT)
#define Py_ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALNUM)
#define Py_ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_SPACE)
PyAPI_DATA
(
const
unsigned
char
)
_Py_ctype_tolower
[
256
];
PyAPI_DATA
(
const
unsigned
char
)
_Py_ctype_toupper
[
256
];
#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
#endif
/* !PYCTYPE_H */
src/jit.cpp
View file @
042eb9a9
...
...
@@ -152,7 +152,7 @@ int main(int argc, char** argv) {
printLastTraceback
();
fprintf
(
stderr
,
"%s
\n
"
,
msg
.
c_str
());
exit
(
1
)
;
return
1
;
}
}
}
...
...
src/runtime/stacktrace.cpp
View file @
042eb9a9
...
...
@@ -188,6 +188,8 @@ extern "C" void abort() {
if
(
!
recursive
)
{
recursive
=
true
;
fprintf
(
stderr
,
"Someone called abort!
\n
"
);
_printStacktrace
();
}
...
...
@@ -195,6 +197,28 @@ extern "C" void abort() {
__builtin_unreachable
();
}
extern
"C"
void
exit
(
int
code
)
{
static
void
(
*
libc_exit
)(
int
)
=
(
void
(
*
)(
int
))
dlsym
(
RTLD_NEXT
,
"exit"
);
if
(
code
==
0
)
{
libc_exit
(
0
);
__builtin_unreachable
();
}
fprintf
(
stderr
,
"Someone called exit with code=%d!
\n
"
,
code
);
// In case something calls exit down the line:
static
bool
recursive
=
false
;
if
(
!
recursive
)
{
recursive
=
true
;
_printStacktrace
();
}
libc_exit
(
code
);
__builtin_unreachable
();
}
static
std
::
vector
<
const
LineInfo
*>
getTracebackEntries
()
{
std
::
vector
<
const
LineInfo
*>
entries
;
...
...
test/tests/import_failure_test.py
View file @
042eb9a9
# expected: fail
# - wip
try
:
import
non_existent_module
assert
0
,
"shouldn't get here"
except
ImportError
:
p
ass
except
ImportError
,
e
:
p
rint
e
try
:
from
non_existent_module
import
a
assert
0
,
"shouldn't get here"
except
ImportError
:
p
ass
except
ImportError
,
e
:
p
rint
e
try
:
from
sys
import
non_existent_attribute
assert
0
,
"shouldn't get here"
except
ImportError
:
pass
except
ImportError
,
e
:
print
e
# Run it all again inside a funtion scope:
def
f
():
try
:
import
non_existent_module
assert
0
,
"shouldn't get here"
except
ImportError
,
e
:
print
e
try
:
from
non_existent_module
import
a
assert
0
,
"shouldn't get here"
except
ImportError
,
e
:
print
e
try
:
from
sys
import
non_existent_attribute
assert
0
,
"shouldn't get here"
except
ImportError
,
e
:
print
e
try
:
print
os
1
/
0
except
NameError
,
e
:
print
e
try
:
import
os
,
aoeu
except
ImportError
,
e
:
print
e
print
type
(
os
)
f
()
def
f2
():
try
:
from
os
import
path
,
doesnt_exist
except
ImportError
,
e
:
print
e
print
path
try
:
print
doesnt_exist
except
NameError
,
e
:
print
e
f2
()
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