Skip to content

Commit dd9bf83

Browse files
committed
druntime: Refactor common isDcloseNoop logic in 'shared' integration tests
1 parent f89fc19 commit dd9bf83

File tree

4 files changed

+25
-38
lines changed

4 files changed

+25
-38
lines changed

runtime/druntime/test/shared/src/finalize.d

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern (C) alias SetFinalizeCounter = void function(shared(size_t*));
3333

3434
void main(string[] args)
3535
{
36-
import utils : dllExt, loadSym;
36+
import utils : dllExt, isDlcloseNoop, loadSym;
3737

3838
auto name = args[0] ~ '\0';
3939
const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
@@ -45,7 +45,7 @@ void main(string[] args)
4545
auto nf1 = new NoFinalize;
4646
auto nf2 = new NoFinalizeBig;
4747

48-
shared static size_t finalizeCounter;
48+
static shared size_t finalizeCounter;
4949
SetFinalizeCounter setFinalizeCounter;
5050
loadSym(h, setFinalizeCounter, "setFinalizeCounter");
5151
setFinalizeCounter(&finalizeCounter);
@@ -58,16 +58,7 @@ void main(string[] args)
5858
auto r = Runtime.unloadLibrary(h);
5959
if (!r)
6060
assert(0);
61-
version (darwin)
62-
{
63-
// Fails starting with macOS 10.13, as .dylibs with TLS can't be
64-
// unloaded anymore (https://github.com/ldc-developers/ldc/issues/3002).
65-
}
66-
else version (CRuntime_Musl)
67-
{
68-
// On Musl, dlclose is a no-op
69-
}
70-
else
61+
static if (!isDlcloseNoop)
7162
{
7263
if (finalizeCounter != 4)
7364
assert(0);

runtime/druntime/test/shared/src/load.d

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,16 @@ void runTests(string libName)
127127
assert(findModuleInfo("lib") is null);
128128
}
129129

130-
version (LDC)
131-
{
132-
version (CRuntime_Musl) enum unloadIsNoop = true;
133-
else version (darwin) enum unloadIsNoop = true;
134-
else enum unloadIsNoop = false;
135-
}
136-
137130
void main(string[] args)
138131
{
139132
auto name = args[0] ~ '\0';
140133
const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
141-
import utils : dllExt;
134+
import utils : dllExt, isDlcloseNoop;
142135
name = name[0 .. pathlen] ~ "lib." ~ dllExt;
143136

144137
runTests(name);
145138

146-
static if (unloadIsNoop)
147-
{
148-
// https://github.com/ldc-developers/ldc/issues/3002
149-
}
150-
else
139+
static if (!isDlcloseNoop)
151140
{
152141
// lib is no longer resident
153142
name ~= '\0';

runtime/druntime/test/shared/src/load_13414.d

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ shared uint tlsDtor, dtor;
66
void staticDtorHook() { atomicOp!"+="(tlsDtor, 1); }
77
void sharedStaticDtorHook() { atomicOp!"+="(dtor, 1); }
88

9-
version (LDC) version (darwin) version = LDC_darwin;
10-
119
void runTest(string name)
1210
{
1311
auto h = Runtime.loadLibrary(name);
1412
assert(h !is null);
1513

16-
import utils : loadSym;
14+
import utils : isDlcloseNoop, loadSym;
1715
void function()* pLibStaticDtorHook, pLibSharedStaticDtorHook;
1816
loadSym(h, pLibStaticDtorHook, "_D9lib_1341414staticDtorHookOPFZv");
1917
loadSym(h, pLibSharedStaticDtorHook, "_D9lib_1341420sharedStaticDtorHookOPFZv");
@@ -24,16 +22,8 @@ void runTest(string name)
2422
const unloaded = Runtime.unloadLibrary(h);
2523
assert(unloaded);
2624
assert(tlsDtor == 1);
27-
version (LDC_darwin)
28-
{
29-
// Since 10.13: https://github.com/ldc-developers/ldc/issues/3002
30-
assert(dtor == 0);
31-
}
32-
else version (CRuntime_Musl)
33-
{
34-
// On Musl, dlclose is a no-op
25+
static if (isDlcloseNoop)
3526
assert(dtor == 0);
36-
}
3727
else
3828
assert(dtor == 1);
3929
}

runtime/druntime/test/shared/src/utils.di

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
module utils;
22

3+
version (OSX)
4+
version = Darwin;
5+
else version (iOS)
6+
version = Darwin;
7+
else version (TVOS)
8+
version = Darwin;
9+
else version (WatchOS)
10+
version = Darwin;
11+
312
version (Windows)
413
enum dllExt = "dll";
5-
else version (darwin)
14+
else version (Darwin)
615
enum dllExt = "dylib";
716
else
817
enum dllExt = "so";
918

19+
// on some platforms, dlclose() is a no-op
20+
version (Darwin)
21+
enum isDlcloseNoop = true; // since macOS ~10.12.6 if shared lib uses TLS: https://github.com/rust-lang/rust/issues/28794#issuecomment-368693049
22+
else version (CRuntime_Musl)
23+
enum isDlcloseNoop = true; // https://wiki.musl-libc.org/functional-differences-from-glibc.html
24+
else
25+
enum isDlcloseNoop = false;
26+
1027
void loadSym(T)(void* handle, ref T val, const char* mangle)
1128
{
1229
version (Windows)

0 commit comments

Comments
 (0)