You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/09/27 07:37:14 UTC

[GitHub] YorkShen closed pull request #1588: [core]fix opcode rax parser error

YorkShen closed pull request #1588: [core]fix opcode rax parser error
URL: https://github.com/apache/incubator-weex/pull/1588
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/weex_core/Source/core/data_render/binary_file.h b/weex_core/Source/core/data_render/binary_file.h
index c6764469e5..9689932554 100644
--- a/weex_core/Source/core/data_render/binary_file.h
+++ b/weex_core/Source/core/data_render/binary_file.h
@@ -33,6 +33,7 @@ namespace data_render {
         FUNCTION_SECTION,
         START_SECTION,
         GLOBAL_SECTION,
+        GLOBAL_VARIABLE_SECTION,
         STYLE_SECTION,
         ARRAY_SECTION,
         REF_SECTION,
diff --git a/weex_core/Source/core/data_render/exec_state.cc b/weex_core/Source/core/data_render/exec_state.cc
index b438575ae5..9ea9a045de 100644
--- a/weex_core/Source/core/data_render/exec_state.cc
+++ b/weex_core/Source/core/data_render/exec_state.cc
@@ -136,6 +136,7 @@ void ExecState::startEncode() {
     encodeFunctionSection();
     encodeStartSection();
     encodeGlobalSection();
+    encodeGlobalVariableSection();
     encodeStyleSection();
     encodeArraySection();
     encodeRefSection();
@@ -220,6 +221,10 @@ void ExecState::encodeFunctionSection() {
             super_index = static_cast<int>(it - func_states.begin());
         }
         file->write((char*)&super_index, sizeof(int));
+
+        bool is_class_func = func_state->is_class_func();
+        file->write((char*)&is_class_func, sizeof(int));
+
         unsigned opcodeSize = static_cast<unsigned>(func_state->instructions().size());
         file->write((char*)&opcodeSize, sizeof(unsigned));
         for (int i=0; i<opcodeSize; i++) {
@@ -261,6 +266,20 @@ void ExecState::encodeGlobalSection() {
     }
 }
 
+void ExecState::encodeGlobalVariableSection() {
+    BinaryFile* file = BinaryFile::instance();
+    unsigned id = Section::GLOBAL_VARIABLE_SECTION;
+    unsigned size = static_cast<unsigned>(global_variables_.size());
+
+    file->write((char*)&id, sizeof(unsigned));
+    file->write((char*)&size, sizeof(unsigned));
+    for (auto variable : global_variables_) {
+        unsigned length = static_cast<unsigned>(variable.first.length()) + 1;
+        file->write(variable.first.c_str(), static_cast<unsigned int>(sizeof(char) * length));
+        file->write((char*)&variable.second, sizeof(long));
+    }
+}
+
 void ExecState::encodeStyleSection() {
     unsigned id = Section::STYLE_SECTION;
     std::map<std::string, json11::Json>& styles = render_context_->style_json();
@@ -490,6 +509,9 @@ bool ExecState::startDecode() {
             case GLOBAL_SECTION:
                 decodeGlobalSection();
                 break;
+            case GLOBAL_VARIABLE_SECTION:
+                decodeGlobalVariableSection();
+                break;
             case STYLE_SECTION:
                 decodeStyleSection();
                 break;
@@ -580,6 +602,10 @@ void ExecState::decodeFunctionSection() {
         file->read((char*)&super_index, sizeof(int));
         func_state->set_super_index(super_index);
 
+        bool is_class_func = false;
+        file->read((char*)&is_class_func, sizeof(bool));
+        func_state->set_is_class_func(is_class_func);
+
         unsigned op_code_count = 0;
         file->read((char*)&op_code_count, sizeof(unsigned));
         for (int j=0; j<op_code_count; j++) {
@@ -639,6 +665,32 @@ void ExecState::decodeGlobalSection() {
     }
 }
 
+void ExecState::decodeGlobalVariableSection() {
+    BinaryFile* file = BinaryFile::instance();
+
+    unsigned count = 0;
+    file->read((char*)&count, sizeof(unsigned));
+    if (count == 0) {
+        return;
+    }
+
+    for (int i=0; i<count; i++) {
+        std::string key;
+        char c;
+        while (true) {
+            file->read(&c, sizeof(char));
+            if (c == 0) {
+                break;
+            }
+            key += c;
+        }
+
+        long value;
+        file->read((char*)&value, sizeof(long));
+        global_variables_.insert(std::pair<std::string, long>(key, value));
+    }
+}
+
 void ExecState::decodeStyleSection() {
     BinaryFile* file = BinaryFile::instance();
 
diff --git a/weex_core/Source/core/data_render/exec_state.h b/weex_core/Source/core/data_render/exec_state.h
index fbe6866bbe..a256572ac9 100644
--- a/weex_core/Source/core/data_render/exec_state.h
+++ b/weex_core/Source/core/data_render/exec_state.h
@@ -167,6 +167,7 @@ class ExecState {
   friend class CodeGenerator;
 
   void encodeGlobalSection();
+  void encodeGlobalVariableSection();
   void encodeFunctionSection();
   void encodeStartSection();
   void encodeTableSection();
@@ -183,6 +184,7 @@ class ExecState {
   void decodeFunctionSection();
   void decodeStartSection();
   void decodeGlobalSection();
+  void decodeGlobalVariableSection();
   void decodeStyleSection();
   void decodeArraySection();
   void decodeRefSection();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services