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

Commit 9c4d5b3

Browse files
committed
use pragma(crt_constructor) instead of registration via C
1 parent 7ea58b9 commit 9c4d5b3

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

src/gc/proxy.d

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
module gc.proxy;
1515

16-
import gc.impl.conservative.gc;
17-
import gc.impl.manual.gc;
1816
import gc.impl.proto.gc;
1917
import gc.config;
2018
import gc.gcinterface;
@@ -37,11 +35,27 @@ private
3735

3836
extern (C)
3937
{
38+
// do not import GC modules, they might add a dependency to this whole module
39+
void _d_register_conservative_gc();
40+
void _d_register_manual_gc();
41+
42+
// if you don't want to include the default GCs, replace during link by another implementation
43+
void* register_default_gcs()
44+
{
45+
pragma(inline, false);
46+
// do not call, they register implicitly through pragma(crt_constructor)
47+
// avoid being optimized away
48+
auto reg1 = &_d_register_conservative_gc;
49+
auto reg2 = &_d_register_manual_gc;
50+
return reg1 < reg2 ? reg1 : reg2;
51+
}
52+
4053
void gc_init()
4154
{
4255
instanceLock.lock();
4356
if (!isInstanceInit)
4457
{
58+
register_default_gcs();
4559
config.initialize();
4660
auto protoInstance = instance;
4761
auto newInstance = createGCInstance(config.gc);

src/gc/register.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/init_fini/Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ $(ROOT)/%.done: $(ROOT)/%
1010
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS)
1111
@touch $@
1212

13-
$(ROOT)/custom_gc: $(ROOT)/register_custom_gc.o
1413
$(ROOT)/%: $(SRC)/%.d
15-
$(QUIET)$(DMD) $(DFLAGS) -of$@ $^
16-
17-
$(ROOT)/register_custom_gc.o: $(SRC)/register_custom_gc.c
18-
$(QUIET)$(CC) -c $(CFLAGS) -o $@ $^
14+
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<
1915

2016
clean:
2117
rm -rf $(ROOT)

test/init_fini/src/custom_gc.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ static import core.memory;
66

77
extern (C) __gshared string[] rt_options = ["gcopt=gc:malloc"];
88

9-
extern (C) void register_mygc()
9+
extern (C) pragma(crt_constructor) void register_mygc()
1010
{
1111
registerGCFactory("malloc", &MallocGC.initialize);
1212
}
1313

14+
extern (C) void register_default_gcs()
15+
{
16+
// remove default GCs
17+
}
18+
1419
/** Simple GC that requires any pointers passed to it's API
1520
to point to start of the allocation.
1621
*/

test/init_fini/src/register_custom_gc.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/init_fini/win64.mak

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# built from the druntime top-level folder
2+
# to be overwritten by caller
3+
DMD=dmd
4+
MODEL=64
5+
DRUNTIMELIB=druntime64.lib
6+
7+
test: custom_gc
8+
9+
custom_gc:
10+
$(DMD) -m$(MODEL) -conf= -Isrc -defaultlib=$(DRUNTIMELIB) test\init_fini\src\custom_gc.d
11+
custom_gc.exe
12+
del custom_gc.exe custom_gc.obj
13+

win64.mak

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ test_hash:
105105
test_stdcpp:
106106
$(MAKE) -f test\stdcpp\win64.mak "DMD=$(DMD)" MODEL=$(MODEL) "VCDIR=$(VCDIR)" DRUNTIMELIB=$(DRUNTIME) "CC=$(CC)" test
107107

108-
test_all: test_uuid test_aa test_hash test_stdcpp
108+
custom_gc:
109+
$(MAKE) -f test\init_fini\win64.mak "DMD=$(DMD)" MODEL=$(MODEL) "VCDIR=$(VCDIR)" DRUNTIMELIB=$(DRUNTIME) "CC=$(CC)" test
110+
111+
test_all: test_uuid test_aa test_hash test_stdcpp custom_gc
109112

110113
################### zip/install/clean ##########################
111114

0 commit comments

Comments
 (0)