mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
bug workaround on MacOS
Number::stoi may raise std::out_of_range but it cannot be caught via catch(std::exception&). We use catch(...) for now. Note that catch(...) may catch pkpy::Exception or any others.
This commit is contained in:
parent
e0c7b33434
commit
d4696d6931
2
.gitignore
vendored
2
.gitignore
vendored
@ -28,3 +28,5 @@ pocketpy.exp
|
||||
pocketpy.lib
|
||||
APPS
|
||||
build
|
||||
|
||||
pocketpy.dSYM
|
2
build.py
2
build.py
@ -15,7 +15,7 @@ main_src_arg = " ".join(src_file_list+["src2/main.cpp"])
|
||||
|
||||
print(main_src_arg)
|
||||
|
||||
linux_common = " -Wfatal-errors --std=c++17 -O2 -Wall -fno-rtti -stdlib=libc++ -Iinclude/ "
|
||||
linux_common = " -Wfatal-errors --std=c++17 -O1 -Wall -fno-rtti -stdlib=libc++ -Iinclude/ "
|
||||
linux_cmd = "clang++ -o pocketpy " + main_src_arg + linux_common
|
||||
|
||||
if "web" in sys.argv:
|
||||
|
@ -217,7 +217,7 @@ namespace pkpy{
|
||||
char code;
|
||||
try{
|
||||
code = (char)Number::stoi(hex, &parsed, 16);
|
||||
}catch(std::invalid_argument&){
|
||||
}catch(...){
|
||||
SyntaxError("invalid hex char");
|
||||
}
|
||||
if (parsed != 2) SyntaxError("invalid hex char");
|
||||
@ -259,19 +259,22 @@ namespace pkpy{
|
||||
return;
|
||||
}
|
||||
|
||||
if(m[1].matched && m[2].matched){
|
||||
SyntaxError("hex literal should not contain a dot");
|
||||
}
|
||||
|
||||
try{
|
||||
int base = 10;
|
||||
size_t size;
|
||||
if (m[1].matched) base = 16;
|
||||
if (m[2].matched) {
|
||||
if(base == 16) SyntaxError("hex literal should not contain a dot");
|
||||
PK_ASSERT(base == 10);
|
||||
add_token(TK("@num"), Number::stof(m[0], &size));
|
||||
} else {
|
||||
add_token(TK("@num"), Number::stoi(m[0], &size, base));
|
||||
}
|
||||
PK_ASSERT((int)size == (int)m.length());
|
||||
}catch(std::exception& e){
|
||||
PK_UNUSED(e);
|
||||
}catch(...){
|
||||
SyntaxError("invalid number literal");
|
||||
}
|
||||
}
|
||||
|
@ -308,9 +308,9 @@ void init_builtins(VM* _vm) {
|
||||
try{
|
||||
size_t parsed = 0;
|
||||
i64 val = Number::stoi(s.str(), &parsed, base);
|
||||
if(parsed != s.length()) throw std::invalid_argument("<?>");
|
||||
PK_ASSERT(parsed == s.length());
|
||||
return VAR(val);
|
||||
}catch(std::invalid_argument&){
|
||||
}catch(...){
|
||||
vm->ValueError("invalid literal for int(): " + s.escape());
|
||||
}
|
||||
}
|
||||
@ -368,7 +368,7 @@ void init_builtins(VM* _vm) {
|
||||
try{
|
||||
f64 val = Number::stof(s.str());
|
||||
return VAR(val);
|
||||
}catch(std::invalid_argument&){
|
||||
}catch(...){
|
||||
vm->ValueError("invalid literal for float(): " + s.escape());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user