]> git.localhorst.tv Git - l2e.git/commitdiff
non-reference type array relocation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 17 Mar 2013 12:28:35 +0000 (13:28 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 17 Mar 2013 12:28:35 +0000 (13:28 +0100)
src/loader/Compiler.cpp
src/loader/Interpreter.cpp
src/loader/Interpreter.h
src/loader/Loader.cpp
src/loader/ObjectFile.h

index 95d41ccadceb3ab6a5dc3b558cb1ceaa2716463c..b583aabb298a46017fb87d23d1772e1e79fed12e 100644 (file)
@@ -141,6 +141,7 @@ void Compiler::WriteArrays(ostream &out) {
                        i(intp.Arrays().begin()), end(intp.Arrays().end());
                        i != end; ++i) {
                Array array;
+               array.typeId = i->typeId;
                array.size = i->size;
                array.ref = i->ref;
                Write(out, &array, sizeof(Array));
@@ -210,19 +211,23 @@ void Compiler::Relocate(iostream &out) {
        Array array;
        for (; out && out.tellg() < fileHeader.arraysEnd;) {
                out.read(reinterpret_cast<char *>(&array), sizeof(Array));
-               if (!array.ref) {
-                       out.seekg(array.size);
-                       continue;
+               if (array.ref) {
+                       buffer = new char[array.size];
+                       unsigned int pos = out.tellg();
+                       out.seekg(pos);
+                       out.read(buffer, array.size);
+                       RelocateArray(buffer, array.size);
+                       out.seekp(pos);
+                       out.write(buffer, array.size);
+                       out.seekg(out.tellp());
+                       delete[] buffer;
+               } else {
+                       const TypeDescription &td = TypeDescription::Get(array.typeId);
+                       for (char *i = array.Data(), *end = array.Data() + array.size;
+                                       i < end; i += td.Size()) {
+                               Relocate(i, td);
+                       }
                }
-               buffer = new char[array.size];
-               unsigned int pos = out.tellg();
-               out.seekg(pos);
-               out.read(buffer, array.size);
-               RelocateArray(buffer, array.size);
-               out.seekp(pos);
-               out.write(buffer, array.size);
-               out.seekg(out.tellp());
-               delete[] buffer;
        }
 }
 
index fc428cd8365e998ea37128ef23adf2ede9dbb716..51c6b9ce3b2648d23310f00f015126f2f394e2d7 100644 (file)
@@ -332,6 +332,7 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis
                                int arraySize(i->second->GetLiteral().ArraySize());
                                size_t memberSize = fd.IsReferenced() ? sizeof(char *) : fieldType.Size();
                                Array array;
+                               array.typeId = fd.TypeId();
                                array.size = arraySize * memberSize;
                                array.data = alloc.Alloc(array.size);
                                array.ref = fd.IsReferenced();
index 3e9f661e56ccb53da7f5637315c5b1f5e5b9e1a4..7eccab344bdc105cd50ddda63f65c80bb6c72690 100644 (file)
@@ -126,6 +126,7 @@ public:
        }
        struct Array {
                void *data;
+               unsigned int typeId;
                unsigned int size;
                bool ref;
        };
index 9c8739aabee00191584852973971f203fc8afa5e..1e0050dbc022a64c1d7896428caad0b152dac2f0 100644 (file)
@@ -120,13 +120,18 @@ void Loader::LoadObject(char *src, char *object, const TypeDescription &td) {
 
 void Loader::LoadArrays(char *src, Array *begin, Array *end) {
        for (Array *i = begin; i < end; i = i->Next()) {
-               if (!i->ref) {
-                       continue;
-               }
-               for (char *j = i->Data(), *end = i->Data() + i->size;
-                               j < end; j += sizeof(void *)) {
-                       *reinterpret_cast<char **>(j) =
-                                       src + *reinterpret_cast<unsigned int *>(j);
+               if (i->ref) {
+                       for (char *j = i->Data(), *end = i->Data() + i->size;
+                                       j < end; j += sizeof(void *)) {
+                               *reinterpret_cast<char **>(j) =
+                                               src + *reinterpret_cast<unsigned int *>(j);
+                       }
+               } else {
+                       const TypeDescription &td = TypeDescription::Get(i->typeId);
+                       for (char *j = i->Data(), *end = i->Data() + i->size;
+                                       j < end; j += td.Size()) {
+                               LoadObject(src, j, td);
+                       }
                }
        }
 }
index 178180a2f8c3eafe27926766cfe25b0c8546482c..b497e344b500ea45ba9fa4e80cbbbda1946c9629 100644 (file)
@@ -35,6 +35,7 @@ struct Object {
 };
 
 struct Array {
+       unsigned int typeId;
        unsigned int size;
        bool ref;
        char *Data();