Fix crash on host/target word size mismatches
When compiling on a 64-bit host and using the QV4::CompileData on a 32-bit target, the size of QArrayData is different. Therefore we cannot use it in the QV4::CompiledData and have to resort to storing only the characters in there. We can at least still use fromRawData when extracting strings, but the QStringData will have to be allocated now. Change-Id: Ia9dab1722ed72186451b65ba74457051c6ce3155 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
18a96e8f49
commit
0640dce6cd
|
@ -151,7 +151,7 @@ struct JSClass
|
|||
struct String
|
||||
{
|
||||
quint32 flags; // isArrayIndex
|
||||
QArrayData str;
|
||||
qint32 size;
|
||||
// uint16 strdata[]
|
||||
|
||||
static int calculateSize(const QString &str) {
|
||||
|
@ -195,13 +195,12 @@ struct Unit
|
|||
const uint *offsetTable = reinterpret_cast<const uint*>((reinterpret_cast<const char *>(this)) + offsetToStringTable);
|
||||
const uint offset = offsetTable[idx];
|
||||
const String *str = reinterpret_cast<const String*>(reinterpret_cast<const char *>(this) + offset);
|
||||
if (str->str.size == 0)
|
||||
if (str->size == 0)
|
||||
return QString();
|
||||
QStringDataPtr holder = { const_cast<QStringData *>(static_cast<const QStringData*>(&str->str)) };
|
||||
QString qstr(holder);
|
||||
const QChar *characters = reinterpret_cast<const QChar *>(str + 1);
|
||||
if (flags & StaticData)
|
||||
return qstr;
|
||||
return QString(qstr.constData(), qstr.length());
|
||||
return QString::fromRawData(characters, str->size);
|
||||
return QString(characters, str->size);
|
||||
}
|
||||
|
||||
const uint *functionOffsetTable() const { return reinterpret_cast<const uint*>((reinterpret_cast<const char *>(this)) + offsetToFunctionTable); }
|
||||
|
|
|
@ -82,11 +82,7 @@ void QV4::Compiler::StringTableGenerator::serialize(uint *stringTable, char *dat
|
|||
|
||||
QV4::CompiledData::String *s = (QV4::CompiledData::String*)(stringData);
|
||||
s->flags = 0; // ###
|
||||
s->str.ref.atomic.store(-1);
|
||||
s->str.size = qstr.length();
|
||||
s->str.alloc = 0;
|
||||
s->str.capacityReserved = false;
|
||||
s->str.offset = sizeof(QArrayData);
|
||||
s->size = qstr.length();
|
||||
memcpy(s + 1, qstr.constData(), (qstr.length() + 1)*sizeof(ushort));
|
||||
|
||||
stringData += QV4::CompiledData::String::calculateSize(qstr);
|
||||
|
|
Loading…
Reference in New Issue