Use const char* const* over const char** (#1005)

The FFI difference becomes significant in languages like Rust where you
can't necessarily just cast a const pointer.
This commit is contained in:
LoganDark 2023-08-07 13:45:04 -07:00 committed by GitHub
parent 0b2755f964
commit 2b03c8f72a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 6 deletions

View file

@ -39,7 +39,7 @@ struct CompileOptions
const char* vectorType = nullptr; const char* vectorType = nullptr;
// null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these // null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these
const char** mutableGlobals = nullptr; const char* const* mutableGlobals = nullptr;
}; };
class CompileError : public std::exception class CompileError : public std::exception

View file

@ -35,7 +35,7 @@ struct lua_CompileOptions
const char* vectorType; const char* vectorType;
// null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these // null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these
const char** mutableGlobals; const char* const* mutableGlobals;
}; };
// compile source to bytecode; when source compilation fails, the resulting bytecode contains the encoded error. use free() to destroy // compile source to bytecode; when source compilation fails, the resulting bytecode contains the encoded error. use free() to destroy

View file

@ -82,13 +82,13 @@ struct ValueVisitor : AstVisitor
} }
}; };
void assignMutable(DenseHashMap<AstName, Global>& globals, const AstNameTable& names, const char** mutableGlobals) void assignMutable(DenseHashMap<AstName, Global>& globals, const AstNameTable& names, const char* const* mutableGlobals)
{ {
if (AstName name = names.get("_G"); name.value) if (AstName name = names.get("_G"); name.value)
globals[name] = Global::Mutable; globals[name] = Global::Mutable;
if (mutableGlobals) if (mutableGlobals)
for (const char** ptr = mutableGlobals; *ptr; ++ptr) for (const char* const* ptr = mutableGlobals; *ptr; ++ptr)
if (AstName name = names.get(*ptr); name.value) if (AstName name = names.get(*ptr); name.value)
globals[name] = Global::Mutable; globals[name] = Global::Mutable;
} }

View file

@ -28,7 +28,7 @@ struct Variable
bool constant = false; // is the variable's value a compile-time constant? filled by constantFold bool constant = false; // is the variable's value a compile-time constant? filled by constantFold
}; };
void assignMutable(DenseHashMap<AstName, Global>& globals, const AstNameTable& names, const char** mutableGlobals); void assignMutable(DenseHashMap<AstName, Global>& globals, const AstNameTable& names, const char* const* mutableGlobals);
void trackValues(DenseHashMap<AstName, Global>& globals, DenseHashMap<AstLocal*, Variable>& variables, AstNode* root); void trackValues(DenseHashMap<AstName, Global>& globals, DenseHashMap<AstLocal*, Variable>& variables, AstNode* root);
inline Global getGlobalState(const DenseHashMap<AstName, Global>& globals, AstName name) inline Global getGlobalState(const DenseHashMap<AstName, Global>& globals, AstName name)

View file

@ -4213,7 +4213,7 @@ RETURN R0 0
bcb.setDumpFlags(Luau::BytecodeBuilder::Dump_Code); bcb.setDumpFlags(Luau::BytecodeBuilder::Dump_Code);
Luau::CompileOptions options; Luau::CompileOptions options;
const char* mutableGlobals[] = {"Game", "Workspace", "game", "plugin", "script", "shared", "workspace", NULL}; const char* mutableGlobals[] = {"Game", "Workspace", "game", "plugin", "script", "shared", "workspace", NULL};
options.mutableGlobals = &mutableGlobals[0]; options.mutableGlobals = mutableGlobals;
Luau::compileOrThrow(bcb, source, options); Luau::compileOrThrow(bcb, source, options);
CHECK_EQ("\n" + bcb.dumpFunction(0), R"( CHECK_EQ("\n" + bcb.dumpFunction(0), R"(