mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use std::string_view for macro bodies (#1326)
This removes the last use of `strdup` This required making a lot of related pointers be `const`. That in turn conflicted with the need to `munmap()` a pointer eventually, which was similar to the need to eventually `free()` an `Expansion`'s contents, so I used the same solution of a `union`. That lets us normally use the `const` pointer for `const` correctness, and the non-`const` one for the not-really- mutating destruction cases.
This commit is contained in:
@@ -396,14 +396,14 @@ void fstk_RunMacro(char const *macroName, MacroArgs *args)
|
||||
|
||||
Context &context = newContext(fileInfo);
|
||||
|
||||
lexer_OpenFileView(context.lexerState, "MACRO", macro->macro.value, macro->macro.size,
|
||||
lexer_OpenFileView(context.lexerState, "MACRO", macro->macro->data(), macro->macro->size(),
|
||||
macro->fileLine);
|
||||
lexer_SetStateAtEOL(&context.lexerState);
|
||||
context.uniqueID = macro_UseNewUniqueID();
|
||||
macro_UseNewArgs(args);
|
||||
}
|
||||
|
||||
static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
||||
static bool newReptContext(int32_t reptLineNo, char const *body, size_t size)
|
||||
{
|
||||
uint32_t reptDepth = contextStack.top().fileInfo->type == NODE_REPT
|
||||
? contextStack.top().fileInfo->iters().size()
|
||||
@@ -432,7 +432,7 @@ static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char const *body, size_t size)
|
||||
{
|
||||
if (count == 0)
|
||||
return;
|
||||
@@ -443,7 +443,7 @@ void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
||||
}
|
||||
|
||||
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||
int32_t reptLineNo, char *body, size_t size)
|
||||
int32_t reptLineNo, char const *body, size_t size)
|
||||
{
|
||||
Symbol *sym = sym_AddVar(symName, start);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user