From af776bb4aa293c11f378d1db1da31354c2df9de5 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 7 Dec 2022 14:07:44 +0800 Subject: [PATCH] disable rtti Update main.yml up --- .github/workflows/main.yml | 4 ++-- build_cpp.sh | 2 +- build_wasm.sh | 2 +- plugins/flutter/lib/jsonrpc.dart | 4 ++-- plugins/flutter/src/CMakeLists.txt | 6 +++++- src/compiler.h | 12 +++++------- src/pocketpy.h | 4 ++-- src/vm.h | 14 ++++++-------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25fe6f1d..aefc3ad4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,9 +9,9 @@ jobs: - name: Compiling shell: bash run: | - CL -std:c++17 -utf-8 -O2 -EHsc -Fe:pocketpy src/main.cpp + CL -std:c++17 -GR- -EHsc -O2 -Fe:pocketpy src/main.cpp mv src/pocketpy.h src/pocketpy.cpp - CL -std:c++17 -utf-8 -O2 -EHsc -LD -Fe:pocketpy src/pocketpy.cpp + CL -std:c++17 -GR- -EHsc -O2 -LD -Fe:pocketpy src/pocketpy.cpp mkdir -p output/windows/x86_64 mv pocketpy.exe output/windows/x86_64 mv pocketpy.dll output/windows/x86_64 diff --git a/build_cpp.sh b/build_cpp.sh index c49ffc67..a4d1a5ff 100644 --- a/build_cpp.sh +++ b/build_cpp.sh @@ -1 +1 @@ -g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable \ No newline at end of file +g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable -fno-rtti \ No newline at end of file diff --git a/build_wasm.sh b/build_wasm.sh index f3e6790f..c8043f80 100644 --- a/build_wasm.sh +++ b/build_wasm.sh @@ -1,3 +1,3 @@ rm -rf web/lib/ mkdir -p web/lib/ -em++ src/main.cpp -fexceptions -sEXIT_RUNTIME -O3 -sEXPORTED_FUNCTIONS=_repl_input,_repl_start -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js \ No newline at end of file +em++ src/main.cpp -fno-rtti -fexceptions -sEXIT_RUNTIME -O3 -sEXPORTED_FUNCTIONS=_repl_input,_repl_start -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js \ No newline at end of file diff --git a/plugins/flutter/lib/jsonrpc.dart b/plugins/flutter/lib/jsonrpc.dart index a2e57f8c..d8e1e5ad 100644 --- a/plugins/flutter/lib/jsonrpc.dart +++ b/plugins/flutter/lib/jsonrpc.dart @@ -30,7 +30,7 @@ class JsonRpcServer { this.onPostDispatch, this.enableFileAccess = false}) { if (!enableFileAccess) return; - registerOS(this); + _registerOS(this); } /// Register a JSONRPC handler. @@ -87,7 +87,7 @@ class JsonRpcServer { int _fileId = 0; final Map _files = {}; - void registerOS(JsonRpcServer rpcServer) { + void _registerOS(JsonRpcServer rpcServer) { rpcServer.register("fopen", (params) { var path = params[0]; //var mode = params[1]; diff --git a/plugins/flutter/src/CMakeLists.txt b/plugins/flutter/src/CMakeLists.txt index f56285be..3f2faf3d 100644 --- a/plugins/flutter/src/CMakeLists.txt +++ b/plugins/flutter/src/CMakeLists.txt @@ -13,7 +13,11 @@ add_library(pocketpy SHARED "pocketpy.cpp" ) -add_compile_options("$<$:/utf-8>") +if (NOT MSVC) + target_compile_options(pocketpy PRIVATE -fno-rtti) +else() + target_compile_options(pocketpy PRIVATE /GR- /EHsc) +endif() set_target_properties(pocketpy PROPERTIES PUBLIC_HEADER pocketpy.h diff --git a/src/compiler.h b/src/compiler.h index 7de2944f..c0d9f328 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -1027,13 +1027,11 @@ _Code compile(VM* vm, const char* source, _Str filename, CompileMode mode=EXEC_M if(!noThrow) return compiler.__fillCode(); try{ return compiler.__fillCode(); + }catch(_Error& e){ + (*vm->_stderr) << e.what() << '\n'; }catch(std::exception& e){ - if(dynamic_cast(&e)){ - (*vm->_stderr) << e.what() << '\n'; - }else{ - auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot()); - (*vm->_stderr) << ce.what() << '\n'; - } - return nullptr; + auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot()); + (*vm->_stderr) << ce.what() << '\n'; } + return nullptr; } \ No newline at end of file diff --git a/src/pocketpy.h b/src/pocketpy.h index 5a2b1324..1b5144ee 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -852,8 +852,8 @@ extern "C" { /// Return a json representing the result. char* pkpy_vm_read_output(VM* vm){ if(vm->use_stdio) return nullptr; - _StrStream* s_out = dynamic_cast<_StrStream*>(vm->_stdout); - _StrStream* s_err = dynamic_cast<_StrStream*>(vm->_stderr); + _StrStream* s_out = (_StrStream*)(vm->_stdout); + _StrStream* s_err = (_StrStream*)(vm->_stderr); _Str _stdout = s_out->str(); _Str _stderr = s_err->str(); _StrStream ss; diff --git a/src/vm.h b/src/vm.h index da88cfdd..feefd072 100644 --- a/src/vm.h +++ b/src/vm.h @@ -547,15 +547,13 @@ public: if(_module == nullptr) _module = _main; try { return _exec(code, _module, {}); - } catch (const std::exception& e) { - if(dynamic_cast(&e)){ - *_stderr << e.what() << '\n'; - }else{ - auto re = RuntimeError("UnexpectedError", e.what(), _cleanErrorAndGetSnapshots()); - *_stderr << re.what() << '\n'; - } - return nullptr; + }catch (const _Error& e){ + *_stderr << e.what() << '\n'; + }catch (const std::exception& e) { + auto re = RuntimeError("UnexpectedError", e.what(), _cleanErrorAndGetSnapshots()); + *_stderr << re.what() << '\n'; } + return nullptr; } virtual void execAsync(const _Code& code) {