Commit 919e8d25 authored by Kevin Modzelewski's avatar Kevin Modzelewski

exec and eval of unicode

parent db9e052a
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "core/stats.h" #include "core/stats.h"
#include "core/types.h" #include "core/types.h"
#include "core/util.h" #include "core/util.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h" #include "runtime/objmodel.h"
#include "runtime/types.h" #include "runtime/types.h"
...@@ -371,6 +372,13 @@ Box* eval(Box* boxedCode) { ...@@ -371,6 +372,13 @@ Box* eval(Box* boxedCode) {
if (globals && globals->cls == attrwrapper_cls && unwrapAttrWrapper(globals) == module) if (globals && globals->cls == attrwrapper_cls && unwrapAttrWrapper(globals) == module)
globals = NULL; globals = NULL;
if (boxedCode->cls == unicode_cls) {
boxedCode = PyUnicode_AsUTF8String(boxedCode);
if (!boxedCode)
throwCAPIException();
// cf.cf_flags |= PyCF_SOURCE_IS_UTF8
}
// TODO error message if parse fails or if it isn't an expr // TODO error message if parse fails or if it isn't an expr
// TODO should have a cleaner interface that can parse the Expression directly // TODO should have a cleaner interface that can parse the Expression directly
// TODO this memory leaks // TODO this memory leaks
...@@ -428,6 +436,13 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) { ...@@ -428,6 +436,13 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
PyDict_SetItemString(globals, "__builtins__", builtins_module); PyDict_SetItemString(globals, "__builtins__", builtins_module);
} }
if (boxedCode->cls == unicode_cls) {
boxedCode = PyUnicode_AsUTF8String(boxedCode);
if (!boxedCode)
throwCAPIException();
// cf.cf_flags |= PyCF_SOURCE_IS_UTF8
}
// TODO same issues as in `eval` // TODO same issues as in `eval`
RELEASE_ASSERT(boxedCode->cls == str_cls, ""); RELEASE_ASSERT(boxedCode->cls == str_cls, "");
const char* code = static_cast<BoxedString*>(boxedCode)->s.data(); const char* code = static_cast<BoxedString*>(boxedCode)->s.data();
......
...@@ -16,7 +16,7 @@ print "Running", args ...@@ -16,7 +16,7 @@ print "Running", args
subprocess.check_call(args) subprocess.check_call(args)
sh_script = """ sh_script = """
set -e set -ex
python -c 'import __future__' python -c 'import __future__'
python -c 'import sys; print sys.executable' python -c 'import sys; print sys.executable'
. test_env/bin/activate . test_env/bin/activate
...@@ -24,6 +24,6 @@ pip install bcrypt==1.1.0 ...@@ -24,6 +24,6 @@ pip install bcrypt==1.1.0
python -c 'import bcrypt; assert bcrypt.__version__ == "1.1.0"; assert bcrypt.hashpw("password1", "$2a$12$0123456789012345678901").endswith("I1hdtg4K"); print "bcrypt seems to work"' python -c 'import bcrypt; assert bcrypt.__version__ == "1.1.0"; assert bcrypt.hashpw("password1", "$2a$12$0123456789012345678901").endswith("I1hdtg4K"); print "bcrypt seems to work"'
""".strip() """.strip()
print sh_script # print sh_script
subprocess.check_call(["sh", "-c", sh_script]) subprocess.check_call(["sh", "-c", sh_script])
...@@ -3,3 +3,7 @@ a = 5 ...@@ -3,3 +3,7 @@ a = 5
print a""" print a"""
exec "" exec ""
# Exec of a unicode encodes as utf8:
exec u"print repr('\u0180')"
print repr(eval(u"'\u0180'"))
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