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

Commit 7438796

Browse files
authored
Merge pull request #2375 from CyberShadow/issue19433
Fix Issue 19433 - Don't consume --DRT-* options if rt_cmdline_enabled is false merged-on-behalf-of: Rainer Schuetze <rainers@users.noreply.github.com>
2 parents e798185 + c6b6803 commit 7438796

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

posix.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
253253
ifeq ($(HAS_ADDITIONAL_TESTS),1)
254254
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \
255255
test/aa test/hash \
256-
test/thread test/unittest test/imports test/betterc test/stdcpp
256+
test/thread test/unittest test/imports test/betterc test/stdcpp test/config
257257
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
258258
endif
259259

src/rt/config.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Configuration options for druntime.
44
The default way to configure the runtime is by passing command line arguments
55
starting with `--DRT-` and followed by the option name, e.g. `--DRT-gcopt` to
66
configure the GC.
7-
Command line options starting with `--DRT-` are filtered out before calling main,
8-
so the program will not see them. They are still available via `rt_args()`.
7+
When command line parsing is enabled, command line options starting
8+
with `--DRT-` are filtered out before calling main, so the program
9+
will not see them. They are still available via `rt_args()`.
910
1011
Configuration via the command line can be disabled by declaring a variable for the
1112
linker to pick up before using it's default from the runtime:

src/rt/dmain2.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
443443
size_t j = 0;
444444
foreach (arg; args)
445445
{
446-
if (arg.length < 6 || arg[0..6] != "--DRT-") // skip D runtime options
446+
import rt.config : rt_cmdline_enabled;
447+
448+
if (!rt_cmdline_enabled!() || arg.length < 6 || arg[0..6] != "--DRT-") // skip D runtime options
447449
{
448450
argsCopy[j++] = (argBuff[0 .. arg.length] = arg[]);
449451
argBuff += arg.length;

test/config/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include ../common.mak
2+
3+
TESTS:=test19433
4+
5+
.PHONY: all clean
6+
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))
7+
8+
$(ROOT)/%: $(SRC)/%.d
9+
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<
10+
11+
$(ROOT)/test19433.done: $(ROOT)/test19433
12+
@echo Testing test19433
13+
$(QUIET)$(ROOT)/test19433 --DRT-dont-eat-me
14+
@touch $@
15+
16+
clean:
17+
rm -rf $(ROOT)

test/config/src/test19433.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern(C) __gshared bool rt_cmdline_enabled = false;
2+
3+
void main(string[] args)
4+
{
5+
assert(args.length == 2);
6+
assert(args[1] == "--DRT-dont-eat-me");
7+
}

test/exceptions/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ $(ROOT)/rt_trap_exceptions.done: STDERR_EXP2="src/rt_trap_exceptions.d:8 main"
6363
$(ROOT)/%.done: $(ROOT)/%
6464
@echo Testing $*
6565
$(NEGATE) $(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>&1 1>/dev/null | grep -qF $(STDERR_EXP)
66-
if [ ! -z "$(STDERR_EXP2)" ] ; then \
66+
if [ ! -z $(STDERR_EXP2) ] ; then \
6767
$(NEGATE) $(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>&1 1>/dev/null | grep -qF $(STDERR_EXP2); \
6868
fi
6969
@touch $@
@@ -75,7 +75,7 @@ $(ROOT)/rt_trap_exceptions_drt.done: NEGATE=!
7575

7676
$(ROOT)/rt_trap_exceptions_drt_gdb.done: $(ROOT)/rt_trap_exceptions_drt
7777
@echo Testing rt_trap_exceptions_drt_gdb
78-
$(QUIET)$(TIMELIMIT) $(GDB) -ex run -ex 'bt full' -ex q --args $< --DRT-trapExceptions=0 \
78+
$(QUIET)$(TIMELIMIT) $(GDB) -ex 'set confirm off' -ex run -ex 'bt full' -ex q --args $< --DRT-trapExceptions=0 \
7979
> $(ROOT)/rt_trap_exceptions_drt_gdb.output 2>&1 || true
8080
cat $(ROOT)/rt_trap_exceptions_drt_gdb.output
8181
grep "in D main (args=...) at src/rt_trap_exceptions_drt.d:9" > /dev/null < $(ROOT)/rt_trap_exceptions_drt_gdb.output

0 commit comments

Comments
 (0)