Просмотр исходного кода

disable rtti

Update main.yml

up
blueloveTH 3 лет назад
Родитель
Сommit
af776bb4aa

+ 2 - 2
.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

+ 1 - 1
build_cpp.sh

@@ -1 +1 @@
-g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable
+g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable -fno-rtti

+ 1 - 1
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
+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

+ 2 - 2
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<int, File> _files = {};
 
-  void registerOS(JsonRpcServer rpcServer) {
+  void _registerOS(JsonRpcServer rpcServer) {
     rpcServer.register("fopen", (params) {
       var path = params[0];
       //var mode = params[1];

+ 5 - 1
plugins/flutter/src/CMakeLists.txt

@@ -13,7 +13,11 @@ add_library(pocketpy SHARED
   "pocketpy.cpp"
 )
 
-add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/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

+ 5 - 7
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<const _Error*>(&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;
 }

+ 2 - 2
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;

+ 6 - 8
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<const _Error*>(&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) {