From ed6384edc6858c7932aa301aee66ce33aa426b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Fri, 20 Jan 2023 00:06:38 -0300 Subject: [PATCH] Add `internal` variable support to files outside gzdoom.pk3 --- src/common/scripting/backend/codegen.cpp | 10 +++++----- src/common/scripting/backend/codegen.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index bfcf83e53b..ac49b3a154 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -177,9 +177,9 @@ void FCompileContext::CheckReturn(PPrototype *proto, FScriptPosition &pos) } } -bool FCompileContext::IsWritable(int flags) +bool FCompileContext::IsWritable(int flags, int checkFileNo) { - return !(flags & VARF_ReadOnly) || ((flags & VARF_InternalAccess) && fileSystem.GetFileContainer(Lump) == 0); + return !(flags & VARF_ReadOnly) || ((flags & VARF_InternalAccess) && fileSystem.GetFileContainer(Lump) == checkFileNo); } FxLocalVariableDeclaration *FCompileContext::FindLocalVariable(FName name) @@ -6882,7 +6882,7 @@ FxGlobalVariable::FxGlobalVariable(PField* mem, const FScriptPosition &pos) bool FxGlobalVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo); return true; } @@ -7075,7 +7075,7 @@ FxStackVariable::~FxStackVariable() bool FxStackVariable::RequestAddress(FCompileContext &ctx, bool *writable) { AddressRequested = true; - if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags); + if (writable != nullptr) *writable = AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo); return true; } @@ -7177,7 +7177,7 @@ bool FxStructMember::RequestAddress(FCompileContext &ctx, bool *writable) else if (writable != nullptr) { // [ZZ] original check. - bool bWritable = (AddressWritable && ctx.IsWritable(membervar->Flags) && + bool bWritable = (AddressWritable && ctx.IsWritable(membervar->Flags, membervar->mDefFileNo) && (!classx->ValueType->isPointer() || !classx->ValueType->toPointer()->IsConst)); // [ZZ] implement write barrier between different scopes if (bWritable) diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index a52b546aeb..c12e33d3f3 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -101,7 +101,7 @@ struct FCompileContext void HandleJumps(int token, FxExpression *handler); void CheckReturn(PPrototype *proto, FScriptPosition &pos); - bool IsWritable(int flags); + bool IsWritable(int flags, int checkFileNo = 0); FxLocalVariableDeclaration *FindLocalVariable(FName name); };