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

Commit 70a7204

Browse files
authored
Merge pull request #3576 from MartinNowak/merge_stable
merge stable Signed-off-by: Petar Kirov <PetarKirov@users.noreply.github.com> Merged-on-behalf-of: Petar Kirov <PetarKirov@users.noreply.github.com>
2 parents 695ac5e + 1675e86 commit 70a7204

4 files changed

Lines changed: 81 additions & 40 deletions

File tree

src/core/exception.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,24 @@ extern (C)
835835
onArraySliceError(lower, upper, length, file[0 .. strlen(file)], line);
836836
}
837837

838+
/// ditto
839+
void _d_arraybounds_slice(string file, uint line, size_t lower, size_t upper, size_t length)
840+
{
841+
onArraySliceError(lower, upper, length, file, line);
842+
}
843+
838844
/// Called when an out of range array index is accessed
839845
void _d_arraybounds_indexp(immutable(char*) file, uint line, size_t index, size_t length)
840846
{
841847
import core.stdc.string : strlen;
842848
onArrayIndexError(index, length, file[0 .. strlen(file)], line);
843849
}
850+
851+
/// ditto
852+
void _d_arraybounds_index(string file, uint line, size_t index, size_t length)
853+
{
854+
onArrayIndexError(index, length, file, line);
855+
}
844856
}
845857

846858
// TLS storage shared for all errors, chaining might create circular reference

src/core/sys/linux/fs.d

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -154,39 +154,42 @@ enum {
154154
S_XFLAG_HASATTR = 0x80000000, /// no DIFLAG for this
155155
}
156156

157-
enum BLKROSET = _IO(0x12, 93); /// set device read-only
158-
enum BLKROGET = _IO(0x12, 94); /// get read-only status
159-
enum BLKRRPART = _IO(0x12, 95); /// re-read partition table
160-
enum BLKGETSIZE = _IO(0x12, 96); /// return device size
161-
enum BLKFLSBUF = _IO(0x12, 97); /// flush buffer cache
162-
enum BLKRASET = _IO(0x12, 98); /// set read ahead for block device
163-
enum BLKRAGET = _IO(0x12, 99); /// get current read ahead setting
164-
enum BLKFRASET = _IO(0x12, 100); /// set filesystem
165-
enum BLKFRAGET = _IO(0x12, 101); /// get filesystem
166-
enum BLKSECTSET = _IO(0x12, 102); /// set max sectors per request
167-
enum BLKSECTGET = _IO(0x12, 103); /// get max sectors per request
168-
enum BLKSSZGET = _IO(0x12, 104); /// get block device sector size
157+
static if (__traits(compiles, _IO(1, 2)))
158+
{
159+
enum BLKROSET = _IO(0x12, 93); /// set device read-only
160+
enum BLKROGET = _IO(0x12, 94); /// get read-only status
161+
enum BLKRRPART = _IO(0x12, 95); /// re-read partition table
162+
enum BLKGETSIZE = _IO(0x12, 96); /// return device size
163+
enum BLKFLSBUF = _IO(0x12, 97); /// flush buffer cache
164+
enum BLKRASET = _IO(0x12, 98); /// set read ahead for block device
165+
enum BLKRAGET = _IO(0x12, 99); /// get current read ahead setting
166+
enum BLKFRASET = _IO(0x12, 100); /// set filesystem
167+
enum BLKFRAGET = _IO(0x12, 101); /// get filesystem
168+
enum BLKSECTSET = _IO(0x12, 102); /// set max sectors per request
169+
enum BLKSECTGET = _IO(0x12, 103); /// get max sectors per request
170+
enum BLKSSZGET = _IO(0x12, 104); /// get block device sector size
169171

170172

171-
enum BLKBSZGET = _IOR!size_t(0x12, 112);
172-
enum BLKBSZSET = _IOW!size_t(0x12, 113);
173-
enum BLKGETSIZE64 = _IOR!size_t(0x12, 114);
174-
enum BLKTRACESTART = _IO(0x12, 116);
175-
enum BLKTRACESTOP = _IO(0x12, 117);
176-
enum BLKTRACETEARDOWN = _IO(0x12, 118);
177-
enum BLKDISCARD = _IO(0x12, 119);
178-
enum BLKIOMIN = _IO(0x12, 120);
179-
enum BLKIOOPT = _IO(0x12, 121);
180-
enum BLKALIGNOFF = _IO(0x12, 122);
181-
enum BLKPBSZGET = _IO(0x12, 123);
182-
enum BLKDISCARDZEROES = _IO(0x12, 124);
183-
enum BLKSECDISCARD = _IO(0x12, 125);
184-
enum BLKROTATIONAL = _IO(0x12, 126);
185-
enum BLKZEROOUT = _IO(0x12, 127);
173+
enum BLKBSZGET = _IOR!size_t(0x12, 112);
174+
enum BLKBSZSET = _IOW!size_t(0x12, 113);
175+
enum BLKGETSIZE64 = _IOR!size_t(0x12, 114);
176+
enum BLKTRACESTART = _IO(0x12, 116);
177+
enum BLKTRACESTOP = _IO(0x12, 117);
178+
enum BLKTRACETEARDOWN = _IO(0x12, 118);
179+
enum BLKDISCARD = _IO(0x12, 119);
180+
enum BLKIOMIN = _IO(0x12, 120);
181+
enum BLKIOOPT = _IO(0x12, 121);
182+
enum BLKALIGNOFF = _IO(0x12, 122);
183+
enum BLKPBSZGET = _IO(0x12, 123);
184+
enum BLKDISCARDZEROES = _IO(0x12, 124);
185+
enum BLKSECDISCARD = _IO(0x12, 125);
186+
enum BLKROTATIONAL = _IO(0x12, 126);
187+
enum BLKZEROOUT = _IO(0x12, 127);
186188

187-
enum BMAP_IOCTL = 1; /// obsolete - kept for compatibility
188-
enum FIBMAP = _IO(0x00, 1); /// bmap access
189-
enum FIGETBSZ = _IO(0x00, 2); /// get the block size used for bmap
189+
enum BMAP_IOCTL = 1; /// obsolete - kept for compatibility
190+
enum FIBMAP = _IO(0x00, 1); /// bmap access
191+
enum FIGETBSZ = _IO(0x00, 2); /// get the block size used for bmap
192+
}
190193

191194
enum FSLABEL_MAX = 256; /// Max chars for the interface; each fs may differ
192195

test/shared/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))
1313

1414
$(ROOT)/loadDR.done $(ROOT)/host.done: RUN_ARGS:=$(DRUNTIMESO)
1515

16-
$(ROOT)/dynamiccast.done: CLEANUP:=rm dynamiccast_endmain dynamiccast_endbar
16+
$(ROOT)/dynamiccast.done: CLEANUP:=rm $(ROOT)/dynamiccast_endmain $(ROOT)/dynamiccast_endbar
1717

1818
$(ROOT)/%.done: $(ROOT)/%
1919
@echo Testing $*

test/shared/src/dynamiccast.d

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ version (DLL)
3737
}
3838
else
3939
{
40-
T getFunc(T)(const(char)* sym, string thisExePath)
40+
T getFunc(T)(const(char)* sym)
4141
{
4242
import core.runtime : Runtime;
4343

@@ -50,29 +50,55 @@ else
5050
else version (Posix)
5151
{
5252
import core.sys.posix.dlfcn : dlsym;
53-
import core.stdc.string : strrchr;
54-
55-
auto name = thisExePath ~ '\0';
56-
const pathlen = strrchr(name.ptr, '/') - name.ptr + 1;
57-
name = name[0 .. pathlen] ~ "dynamiccast.so";
58-
return cast(T) Runtime.loadLibrary(name)
53+
return cast(T) Runtime.loadLibrary("./dynamiccast.so")
5954
.dlsym(sym);
6055
}
6156
else static assert(0);
6257
}
6358

59+
// Returns the path to the executable's directory (null-terminated).
60+
string getThisExeDir(string arg0)
61+
{
62+
char[] buffer = arg0.dup;
63+
assert(buffer.length);
64+
for (size_t i = buffer.length - 1; i > 0; --i)
65+
{
66+
if (buffer[i] == '/' || buffer[i] == '\\')
67+
{
68+
buffer[i] = 0;
69+
return cast(string) buffer[0 .. i];
70+
}
71+
}
72+
return null;
73+
}
74+
6475
version (DigitalMars) version (Win64) version = DMD_Win64;
6576

6677
void main(string[] args)
6778
{
6879
import core.stdc.stdio : fopen, fclose, remove;
6980

81+
const exeDir = getThisExeDir(args[0]);
82+
if (exeDir.length)
83+
{
84+
version (Windows)
85+
{
86+
import core.sys.windows.winbase : SetCurrentDirectoryA;
87+
SetCurrentDirectoryA(exeDir.ptr);
88+
}
89+
else
90+
{
91+
import core.sys.posix.unistd : chdir;
92+
chdir(exeDir.ptr);
93+
}
94+
}
95+
7096
remove("dynamiccast_endmain");
7197
remove("dynamiccast_endbar");
7298

7399
C c = new C;
74100

75-
auto o = getFunc!(Object function(Object))("foo", args[0])(c);
101+
auto o = getFunc!(Object function(Object))("foo")(c);
76102
assert(cast(C) o);
77103

78104
version (DMD_Win64)
@@ -84,7 +110,7 @@ else
84110
{
85111
bool caught;
86112
try
87-
getFunc!(void function(void function()))("bar", args[0])(
113+
getFunc!(void function(void function()))("bar")(
88114
{ throw new C; });
89115
catch (C e)
90116
caught = true;

0 commit comments

Comments
 (0)