Commit 042eb9a9 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Found the issue: don't handle imports in try blocks correctly

parent 5003059e
......@@ -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))
......
// 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 */
......@@ -152,7 +152,7 @@ int main(int argc, char** argv) {
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
exit(1);
return 1;
}
}
}
......
......@@ -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;
......
# expected: fail
# - wip
try:
import non_existent_module
assert 0, "shouldn't get here"
except ImportError:
pass
except ImportError, e:
print e
try:
from non_existent_module import a
assert 0, "shouldn't get here"
except ImportError:
pass
except ImportError, e:
print 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()
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