Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1609 from MartinNowak/fix_gc_config
Browse files Browse the repository at this point in the history
fix --DRT-gcopt string argument parsing
  • Loading branch information
rainers committed Jul 14, 2016
2 parents f74ee55 + eacf2ca commit 5b0ed71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
44 changes: 17 additions & 27 deletions src/gc/config.d
Expand Up @@ -74,7 +74,7 @@ struct Config
cast(long)maxPoolSize, cast(long)incPoolSize, heapSizeFactor);
}

bool parseOptions(const(char)[] opt)
bool parseOptions(string opt)
{
opt = skip!isspace(opt);
while (opt.length)
Expand Down Expand Up @@ -138,7 +138,7 @@ inout(char)[] find(alias pred)(inout(char)[] str)
return null;
}

bool parse(T:size_t)(const(char)[] optname, ref const(char)[] str, ref T res)
bool parse(T:size_t)(const(char)[] optname, ref inout(char)[] str, ref T res)
in { assert(str.length); }
body
{
Expand All @@ -155,7 +155,7 @@ body
return true;
}

bool parse(T:bool)(const(char)[] optname, ref const(char)[] str, ref T res)
bool parse(const(char)[] optname, ref inout(char)[] str, ref bool res)
in { assert(str.length); }
body
{
Expand All @@ -169,7 +169,7 @@ body
return true;
}

bool parse(T:float)(const(char)[] optname, ref const(char)[] str, ref T res)
bool parse(const(char)[] optname, ref inout(char)[] str, ref float res)
in { assert(str.length); }
body
{
Expand All @@ -186,32 +186,15 @@ body
return true;
}

bool parse(T:const(char)[])(const(char)[] optname, ref const(char)[] str, ref T res)
bool parse(const(char)[] optname, ref inout(char)[] str, ref inout(char)[] res)
in { assert(str.length); }
body
{
bool findNext(string next)
{
if(next.length>str.length)
return false;

return (next.length == str.length)? (next == str):(isspace(str[next.length+1])&&(next == str[0..next.length]));
}

if(findNext("manual"))
{
res = "manual";
}
else if(findNext("conservative"))
{
res = "conservative";
}
else
{
return parseError("conservative or manual", optname, str);
}

str = str[res.length .. $];
auto tail = str.find!(c => c == ':' || c == '=' || c == ' ');
res = str[0 .. $ - tail.length];
if (!res.length)
return parseError("an identifier", optname, str);
str = tail;
return true;
}

Expand Down Expand Up @@ -274,4 +257,11 @@ unittest
assert(conf.parseOptions("help"));
assert(conf.parseOptions("help profile:1"));
assert(conf.parseOptions("help profile:1 help"));

assert(conf.parseOptions("gc:manual") && conf.gc == "manual");
assert(conf.parseOptions("gc:my-gc~modified") && conf.gc == "my-gc~modified");
assert(conf.parseOptions("gc:conservative help profile:1") && conf.gc == "conservative" && conf.profile == 1);

// the config parse doesn't know all available GC names, so should accept unknown ones
assert(conf.parseOptions("gc:whatever"));
}
8 changes: 8 additions & 0 deletions src/gc/proxy.d
Expand Up @@ -42,6 +42,14 @@ extern (C)
config.initialize();
ManualGC.initialize(instance);
ConservativeGC.initialize(instance);
if (instance is null)
{
import core.stdc.stdio : fprintf, stderr;
import core.stdc.stdlib : exit;

fprintf(stderr, "No GC was initialized, please recheck the name of the selected GC ('%.*s').\n", cast(int)config.gc.length, config.gc.ptr);
exit(1);
}

// NOTE: The GC must initialize the thread library
// before its first collection.
Expand Down
3 changes: 2 additions & 1 deletion test/exceptions/Makefile
@@ -1,6 +1,6 @@
include ../common.mak

TESTS:=stderr_msg unittest_assert invalid_memory_operation
TESTS:=stderr_msg unittest_assert invalid_memory_operation unknown_gc
ifeq ($(OS)-$(BUILD),linux-debug)
TESTS:=$(TESTS) line_trace
endif
Expand All @@ -24,6 +24,7 @@ $(ROOT)/line_trace.done: $(ROOT)/line_trace
$(ROOT)/stderr_msg.done: STDERR_EXP="stderr_msg msg"
$(ROOT)/unittest_assert.done: STDERR_EXP="unittest_assert msg"
$(ROOT)/invalid_memory_operation.done: STDERR_EXP="InvalidMemoryOperationError"
$(ROOT)/unknown_gc.done: STDERR_EXP="'unknowngc'"
$(ROOT)/%.done: $(ROOT)/%
@echo Testing $*
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>&1 1>/dev/null | grep -qF $(STDERR_EXP)
Expand Down
5 changes: 5 additions & 0 deletions test/exceptions/src/unknown_gc.d
@@ -0,0 +1,5 @@
extern(C) __gshared string[] rt_options = [ "gcopt=gc:unknowngc" ];

void main()
{
}

0 comments on commit 5b0ed71

Please sign in to comment.