From: Daniel Karbach Date: Sun, 17 Mar 2013 12:28:35 +0000 (+0100) Subject: non-reference type array relocation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7b3710c47f24e64e0d01378a4564730bcb2f6ef2;p=l2e.git non-reference type array relocation --- diff --git a/src/loader/Compiler.cpp b/src/loader/Compiler.cpp index 95d41cc..b583aab 100644 --- a/src/loader/Compiler.cpp +++ b/src/loader/Compiler.cpp @@ -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(&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; } } diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index fc428cd..51c6b9c 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -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(); diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 3e9f661..7eccab3 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -126,6 +126,7 @@ public: } struct Array { void *data; + unsigned int typeId; unsigned int size; bool ref; }; diff --git a/src/loader/Loader.cpp b/src/loader/Loader.cpp index 9c8739a..1e0050d 100644 --- a/src/loader/Loader.cpp +++ b/src/loader/Loader.cpp @@ -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(j) = - src + *reinterpret_cast(j); + if (i->ref) { + for (char *j = i->Data(), *end = i->Data() + i->size; + j < end; j += sizeof(void *)) { + *reinterpret_cast(j) = + src + *reinterpret_cast(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); + } } } } diff --git a/src/loader/ObjectFile.h b/src/loader/ObjectFile.h index 178180a..b497e34 100644 --- a/src/loader/ObjectFile.h +++ b/src/loader/ObjectFile.h @@ -35,6 +35,7 @@ struct Object { }; struct Array { + unsigned int typeId; unsigned int size; bool ref; char *Data();