Skip to content

Commit

Permalink
Don't allocate front-end Strings on C++ heap
Browse files Browse the repository at this point in the history
If the GC is enabled (-lowmem), it must know about those Array instances,
so that the GC-allocated array of pointers and referenced GC-allocated
strings are kept alive.
  • Loading branch information
kinke committed Feb 5, 2020
1 parent 347b498 commit f22304a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dmd/ldcbindings.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

module dmd.ldcbindings;

import dmd.arraytypes : Strings;
import dmd.expression;
import dmd.globals;
import dmd.identifier;
Expand Down Expand Up @@ -72,3 +73,5 @@ mixin(factory!Expression);
mixin(factory!InlineAsmStatement);
mixin(factory!TypeDelegate);
mixin(factory!TypeIdentifier);

Strings* createStrings() { return new Strings(); }
2 changes: 2 additions & 0 deletions dmd/ldcbindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ InlineAsmStatement *createInlineAsmStatement(const Loc &loc, Token *tokens);
TypeDelegate *createTypeDelegate(Type *t);
TypeIdentifier *createTypeIdentifier(const Loc &loc, Identifier *ident);

Strings *createStrings();

// Structs
//Loc createLoc(const char * filename, uint linnum, uint charnum);

Expand Down
3 changes: 2 additions & 1 deletion driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "dmd/identifier.h"
#include "dmd/hdrgen.h"
#include "dmd/json.h"
#include "dmd/ldcbindings.h"
#include "dmd/mars.h"
#include "dmd/module.h"
#include "dmd/mtype.h"
Expand Down Expand Up @@ -159,7 +160,7 @@ void processVersions(std::vector<std::string> &list, const char *type,
char *cstr = mem.xstrdup(value);
if (Identifier::isValidIdentifier(cstr)) {
if (!globalIDs)
globalIDs = new Strings();
globalIDs = createStrings();
globalIDs->push(cstr);
continue;
} else {
Expand Down
3 changes: 2 additions & 1 deletion gen/cl_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "gen/cl_helpers.h"

#include "dmd/errors.h"
#include "dmd/ldcbindings.h"
#include "dmd/root/rmem.h"
#include "dmd/root/root.h"
#include <algorithm>
Expand Down Expand Up @@ -65,7 +66,7 @@ void StringsAdapter::push_back(const char *cstr) {
}

if (!*arrp) {
*arrp = new Strings;
*arrp = createStrings();
}
(*arrp)->push(mem.xstrdup(cstr));
}
Expand Down

0 comments on commit f22304a

Please sign in to comment.