Skip to content

Commit ff612b8

Browse files
authored
Merge pull request #10732 from dlang/stable
Merge stable
2 parents 8233866 + 60034b5 commit ff612b8

File tree

16 files changed

+119
-261
lines changed

16 files changed

+119
-261
lines changed

changelog/bit-cast.dd

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

changelog/formatted_read_tuple_return.dd

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

changelog/fromhexstring.dd

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

changelog/odbc-4.dd

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

changelog/pop-grapheme.dd

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

changelog/readfln.dd

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

changelog/shared-allocator-list.dd

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

changelog/sumtype_procedural_api.dd

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

changelog/unicode-16.dd

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

std/experimental/allocator/building_blocks/allocator_list.d

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ template SharedAllocatorList(alias factoryFunction,
11401140
import std.algorithm.comparison : max;
11411141
import std.typecons : Ternary;
11421142

1143-
enum pageSize = 4096;
11441143
enum numPages = 2;
11451144

11461145
static void testrw(void[] b)
@@ -1269,8 +1268,6 @@ template SharedAllocatorList(alias factoryFunction,
12691268
import std.algorithm.comparison : max;
12701269
import std.typecons : Ternary;
12711270

1272-
enum pageSize = 4096;
1273-
12741271
static void testrw(void[] b)
12751272
{
12761273
ubyte* buf = cast(ubyte*) b.ptr;
@@ -1283,17 +1280,17 @@ template SharedAllocatorList(alias factoryFunction,
12831280

12841281
enum numPages = 5;
12851282
AllocatorList!((n) => AscendingPageAllocator(max(n, numPages * pageSize)), NullAllocator) a;
1286-
auto b = a.alignedAllocate(1, pageSize * 2);
1283+
auto b = a.alignedAllocate(1, cast(uint) (pageSize * 2));
12871284
assert(b.length == 1);
1288-
assert(a.expand(b, 4095));
1289-
assert(b.ptr.alignedAt(2 * 4096));
1290-
assert(b.length == 4096);
1285+
assert(a.expand(b, pageSize - 1));
1286+
assert(b.ptr.alignedAt(cast(uint) (pageSize * 2)));
1287+
assert(b.length == pageSize);
12911288

1292-
b = a.allocate(4096);
1293-
assert(b.length == 4096);
1289+
b = a.allocate(pageSize);
1290+
assert(b.length == pageSize);
12941291
assert(a.allocators.length == 1);
12951292

1296-
assert(a.allocate(4096 * 5).length == 4096 * 5);
1293+
assert(a.allocate(pageSize * 5).length == pageSize * 5);
12971294
assert(a.allocators.length == 2);
12981295

12991296
assert(a.deallocateAll());
@@ -1339,7 +1336,6 @@ template SharedAllocatorList(alias factoryFunction,
13391336
import std.algorithm.comparison : max;
13401337

13411338
enum numThreads = 100;
1342-
enum pageSize = 4096;
13431339
enum numPages = 10;
13441340
SharedAllocatorList!((n) => SharedAscendingPageAllocator(max(n, pageSize * numPages)), Mallocator) a;
13451341

std/experimental/allocator/common.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ unittest
6363
class C2 { char c; }
6464
static assert(stateSize!C2 == 4 * size_t.sizeof);
6565
static class C3 { char c; }
66-
static assert(stateSize!C3 == 2 * size_t.sizeof + char.sizeof);
66+
// Uncomment test after dmd issue closed https://github.com/dlang/dmd/issues/21065
67+
//static assert(stateSize!C3 == 3 * size_t.sizeof);
6768
}
6869

6970
/**

std/format/spec.d

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ if (is(Unqual!Char == Char))
127127
128128
Counting starts with `1`. Set to `0` if not used. Default: `0`.
129129
*/
130-
ubyte indexStart;
130+
ushort indexStart;
131131

132132
/**
133133
Index of the last argument for positional parameter ranges.
134134
135135
Counting starts with `1`. Set to `0` if not used. Default: `0`.
136+
137+
The maximum value of this field is used as a sentinel to indicate the arguments' length.
136138
*/
137-
ubyte indexEnd;
139+
ushort indexEnd;
138140

139141
version (StdDdoc)
140142
{
@@ -296,6 +298,8 @@ if (is(Unqual!Char == Char))
296298
}
297299

298300
width = 0;
301+
indexStart = 0;
302+
indexEnd = 0;
299303
precision = UNSPECIFIED;
300304
nested = null;
301305
// Parse the spec (we assume we're past '%' already)
@@ -834,6 +838,33 @@ if (is(Unqual!Char == Char))
834838
== "$ expected after '*10' in format string");
835839
}
836840

841+
// https://github.com/dlang/phobos/issues/10713
842+
@safe pure unittest
843+
{
844+
import std.array : appender;
845+
auto f = FormatSpec!char("%3$d%d");
846+
847+
auto w = appender!(char[])();
848+
f.writeUpToNextSpec(w);
849+
assert(f.indexStart == 3);
850+
851+
f.writeUpToNextSpec(w);
852+
assert(w.data.length == 0);
853+
assert(f.indexStart == 0);
854+
}
855+
856+
// https://github.com/dlang/phobos/issues/10699
857+
@safe pure unittest
858+
{
859+
import std.array : appender;
860+
auto f = FormatSpec!char("%1:$d");
861+
auto w = appender!(char[])();
862+
863+
f.writeUpToNextSpec(w);
864+
assert(f.indexStart == 1);
865+
assert(f.indexEnd == ushort.max);
866+
}
867+
837868
/**
838869
Helper function that returns a `FormatSpec` for a single format specifier.
839870

std/format/write.d

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,16 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[]
648648
break SWITCH;
649649
}
650650
default:
651-
throw new FormatException(
652-
text("Positional specifier %", spec.indexStart, '$', spec.spec,
653-
" index exceeds ", Args.length));
651+
if (spec.indexEnd == spec.indexEnd.max)
652+
break;
653+
else if (spec.indexEnd == spec.indexStart)
654+
throw new FormatException(
655+
text("Positional specifier %", spec.indexStart, '$', spec.spec,
656+
" index exceeds ", Args.length));
657+
else
658+
throw new FormatException(
659+
text("Positional specifier %", spec.indexStart, ":", spec.indexEnd, '$', spec.spec,
660+
" index exceeds ", Args.length));
654661
}
655662
}
656663
return currentArg;
@@ -1199,6 +1206,16 @@ if (isSomeString!(typeof(fmt)))
11991206
formattedWrite(stream, "%s", aa);
12001207
}
12011208

1209+
// https://github.com/dlang/phobos/issues/10699
1210+
@safe pure unittest
1211+
{
1212+
import std.array : appender;
1213+
auto w = appender!(char[])();
1214+
1215+
formattedWrite(w, "%1:$d", 1, 2, 3);
1216+
assert(w.data == "123");
1217+
}
1218+
12021219
/**
12031220
Formats a value of any type according to a format specifier and
12041221
writes the result to an output range.

0 commit comments

Comments
 (0)