diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2024-01-17 23:49:05 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2024-02-03 00:16:55 +0100 |
commit | 5470a9b176c2b3030ff3891c7e9403db2b0685b8 (patch) | |
tree | 6f8227718a03c22ea6a2ca1a78b7c8c18838c3c4 /libphobos/src/std | |
parent | 838e706fa55b1798fb5f0242dbd90cd4d9817bbe (diff) | |
download | gcc-5470a9b176c2b3030ff3891c7e9403db2b0685b8.zip gcc-5470a9b176c2b3030ff3891c7e9403db2b0685b8.tar.gz gcc-5470a9b176c2b3030ff3891c7e9403db2b0685b8.tar.bz2 |
d: Merge dmd, druntime d8e3976a58, phobos 7a6e95688
D front-end changes:
- Import dmd v2.107.0-beta.1.
- A string literal as an assert condition is deprecated.
- Added `@standalone` for module constructors.
D runtime changes:
- Import druntime v2.107.0-beta.1.
Phobos changes:
- Import phobos v2.107.0-beta.1.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd d8e3976a58.
* dmd/VERSION: Bump version to v2.107.0-beta.1.
* d-lang.cc (d_parse_file): Update for new front-end interface.
* modules.cc (struct module_info): Add standalonectors.
(build_module_tree): Implement @standalone.
(register_module_decl): Likewise.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime d8e3976a58.
* src/MERGE: Merge upstream phobos 7a6e95688.
Diffstat (limited to 'libphobos/src/std')
-rw-r--r-- | libphobos/src/std/conv.d | 29 | ||||
-rw-r--r-- | libphobos/src/std/datetime/package.d | 10 | ||||
-rw-r--r-- | libphobos/src/std/datetime/systime.d | 72 | ||||
-rw-r--r-- | libphobos/src/std/math/algebraic.d | 37 | ||||
-rw-r--r-- | libphobos/src/std/net/curl.d | 58 |
5 files changed, 135 insertions, 71 deletions
diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d index 3a53381..23b33c4 100644 --- a/libphobos/src/std/conv.d +++ b/libphobos/src/std/conv.d @@ -5712,8 +5712,8 @@ private auto hexStrLiteral(String)(scope String hexData) * radix = 2, 8, 10, 16 * Char = character type for output * letterCase = lower for deadbeef, upper for DEADBEEF - * value = integer to convert. Can be uint or ulong. If radix is 10, can also be - * int or long. + * value = integer to convert. Can be ubyte, ushort, uint or ulong. If radix + * is 10, can also be byte, short, int or long. * Returns: * Random access range with slicing and everything */ @@ -5721,8 +5721,7 @@ private auto hexStrLiteral(String)(scope String hexData) auto toChars(ubyte radix = 10, Char = char, LetterCase letterCase = LetterCase.lower, T)(T value) pure nothrow @nogc @safe if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && - (is(immutable T == immutable uint) || is(immutable T == immutable ulong) || - radix == 10 && (is(immutable T == immutable int) || is(immutable T == immutable long)))) + isIntegral!T && (radix == 10 || isUnsigned!T)) { alias UT = Unqual!T; @@ -5870,8 +5869,12 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && assert(toChars(123) == toChars(123)); { + assert(toChars!2(ubyte(0)).array == "0"); + assert(toChars!2(ushort(0)).array == "0"); assert(toChars!2(0u).array == "0"); assert(toChars!2(0Lu).array == "0"); + assert(toChars!2(ubyte(1)).array == "1"); + assert(toChars!2(ushort(1)).array == "1"); assert(toChars!2(1u).array == "1"); assert(toChars!2(1Lu).array == "1"); @@ -5884,10 +5887,14 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && assert(s.retro.array == "01"); } { + assert(toChars!8(ubyte(0)).array == "0"); + assert(toChars!8(ushort(0)).array == "0"); assert(toChars!8(0u).array == "0"); assert(toChars!8(0Lu).array == "0"); assert(toChars!8(1u).array == "1"); assert(toChars!8(1234567Lu).array == "4553207"); + assert(toChars!8(ubyte.max).array == "377"); + assert(toChars!8(ushort.max).array == "177777"); auto r = toChars!8(8u); assert(r.length == 2); @@ -5898,10 +5905,14 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && assert(s.retro.array == "01"); } { + assert(toChars!10(ubyte(0)).array == "0"); + assert(toChars!10(ushort(0)).array == "0"); assert(toChars!10(0u).array == "0"); assert(toChars!10(0Lu).array == "0"); assert(toChars!10(1u).array == "1"); assert(toChars!10(1234567Lu).array == "1234567"); + assert(toChars!10(ubyte.max).array == "255"); + assert(toChars!10(ushort.max).array == "65535"); assert(toChars!10(uint.max).array == "4294967295"); assert(toChars!10(ulong.max).array == "18446744073709551615"); @@ -5918,10 +5929,16 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && assert(toChars!10(0L).array == "0"); assert(toChars!10(1).array == "1"); assert(toChars!10(1234567L).array == "1234567"); + assert(toChars!10(byte.max).array == "127"); + assert(toChars!10(short.max).array == "32767"); assert(toChars!10(int.max).array == "2147483647"); assert(toChars!10(long.max).array == "9223372036854775807"); + assert(toChars!10(-byte.max).array == "-127"); + assert(toChars!10(-short.max).array == "-32767"); assert(toChars!10(-int.max).array == "-2147483647"); assert(toChars!10(-long.max).array == "-9223372036854775807"); + assert(toChars!10(byte.min).array == "-128"); + assert(toChars!10(short.min).array == "-32768"); assert(toChars!10(int.min).array == "-2147483648"); assert(toChars!10(long.min).array == "-9223372036854775808"); @@ -5938,6 +5955,10 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && assert(toChars!(16)(0Lu).array == "0"); assert(toChars!(16)(10u).array == "a"); assert(toChars!(16, char, LetterCase.upper)(0x12AF34567Lu).array == "12AF34567"); + assert(toChars!(16)(ubyte(0)).array == "0"); + assert(toChars!(16)(ushort(0)).array == "0"); + assert(toChars!(16)(ubyte.max).array == "ff"); + assert(toChars!(16)(ushort.max).array == "ffff"); auto r = toChars!(16)(16u); assert(r.length == 2); diff --git a/libphobos/src/std/datetime/package.d b/libphobos/src/std/datetime/package.d index 8e9f5ae..58e71e5 100644 --- a/libphobos/src/std/datetime/package.d +++ b/libphobos/src/std/datetime/package.d @@ -12,6 +12,7 @@ $(TR $(TD Points in Time) $(TD + $(REF_ALTTEXT Clock, Clock, std, datetime, systime)$(NBSP) $(REF_ALTTEXT Date, Date, std, datetime, date)$(NBSP) $(REF_ALTTEXT TimeOfDay, TimeOfDay, std, datetime, date)$(NBSP) $(REF_ALTTEXT DateTime, DateTime, std, datetime, date)$(NBSP) @@ -19,7 +20,7 @@ ) ) $(TR - $(TD Timezones) + $(TD $(MREF_ALTTEXT Timezones, std, datetime, timezone)) $(TD $(REF_ALTTEXT TimeZone, TimeZone, std, datetime, timezone)$(NBSP) $(REF_ALTTEXT UTC, UTC, std, datetime, timezone)$(NBSP) @@ -38,7 +39,7 @@ ) ) $(TR - $(TD Durations of Time) + $(TD $(MREF_ALTTEXT Durations of Time, core, time)) $(TD $(REF_ALTTEXT Duration, Duration, core, time)$(NBSP) $(REF_ALTTEXT weeks, weeks, core, time)$(NBSP) @@ -62,7 +63,7 @@ ) )) - This functionality is separated into the following modules + This functionality is separated into the following modules: $(UL $(LI $(MREF std, datetime, date) for points in time without timezones.) @@ -73,6 +74,7 @@ ) See_Also: + $(MREF core, time)$(BR) $(DDLINK intro-to-datetime, Introduction to std.datetime, Introduction to std.datetime)<br> $(HTTP en.wikipedia.org/wiki/ISO_8601, ISO 8601)<br> @@ -87,7 +89,7 @@ +/ module std.datetime; -/// Get the current time from the system clock +/// Get the current time from the system clock. @safe unittest { import std.datetime.systime : SysTime, Clock; diff --git a/libphobos/src/std/datetime/systime.d b/libphobos/src/std/datetime/systime.d index 6898934..a1d8ef3 100644 --- a/libphobos/src/std/datetime/systime.d +++ b/libphobos/src/std/datetime/systime.d @@ -2,7 +2,6 @@ /++ -$(SCRIPT inhibitQuickIndex = 1;) $(DIVC quickindex, $(BOOKTABLE, $(TR $(TH Category) $(TH Functions)) @@ -468,30 +467,38 @@ private: `SysTime` (though for local time applications, time zones can be ignored and it will work, since it defaults to using the local time zone). It holds its internal time in std time (hnsecs since midnight, January 1st, 1 A.D. - UTC), so it interfaces well with the system time. However, that means that, - unlike $(REF DateTime,std,datetime,date), it is not optimized for - calendar-based operations, and getting individual units from it such as - years or days is going to involve conversions and be less efficient. + UTC), so it interfaces well with the system time. An $(I hnsec) (hecto-nanosecond) is 100 nanoseconds. There are 10,000,000 hnsecs in a second. +$(PANEL + Unlike $(REF_SHORT DateTime,std,datetime,date), `SysTime` is not optimized for + calendar-based operations, and getting individual units from it such as + years or days is going to involve conversions and be less efficient. + For calendar-based operations that don't - care about time zones, then $(REF DateTime,std,datetime,date) would be + care about time zones, then $(REF_SHORT DateTime,std,datetime,date) would be the type to use. For system time, use `SysTime`. - - $(LREF Clock.currTime) will return the current time as a `SysTime`. - To convert a `SysTime` to a $(REF Date,std,datetime,date) or - $(REF DateTime,std,datetime,date), simply cast it. To convert a - $(REF Date,std,datetime,date) or $(REF DateTime,std,datetime,date) to a +) +$(P + Casting a `SysTime` to one of the following types will perform a conversion: +) + * $(REF Date,std,datetime,date) + * $(REF_SHORT DateTime,std,datetime,date) + * $(REF_SHORT TimeOfDay,std,datetime,date) +$(P + To convert a + $(REF_SHORT Date,std,datetime,date) or $(REF_SHORT DateTime,std,datetime,date) to a `SysTime`, use `SysTime`'s constructor, and pass in the intended time zone with it (or don't pass in a $(REF TimeZone,std,datetime,timezone), and the local time zone will be used). Be aware, however, that converting from a - $(REF DateTime,std,datetime,date) to a `SysTime` will not necessarily + $(REF_SHORT DateTime,std,datetime,date) to a `SysTime` will not necessarily be 100% accurate due to DST (one hour of the year doesn't exist and another occurs twice). To not risk any conversion errors, keep times as `SysTime`s. Aside from DST though, there shouldn't be any conversion problems. - +) +$(PANEL For using time zones other than local time or UTC, use $(REF PosixTimeZone,std,datetime,timezone) on Posix systems (or on Windows, if providing the TZ Database files), and use @@ -499,16 +506,20 @@ private: `SysTime` is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC. Conversion error cannot happen when changing the time zone of a `SysTime`. $(REF LocalTime,std,datetime,timezone) is the - $(REF TimeZone,std,datetime,timezone) class which represents the local time, - and `UTC` is the $(REF TimeZone,std,datetime,timezone) class which - represents UTC. `SysTime` uses $(REF LocalTime,std,datetime,timezone) if - no $(REF TimeZone,std,datetime,timezone) is provided. For more details on - time zones, see the documentation for $(REF TimeZone,std,datetime,timezone), - $(REF PosixTimeZone,std,datetime,timezone), and - $(REF WindowsTimeZone,std,datetime,timezone). - + $(REF_SHORT TimeZone,std,datetime,timezone) class which represents the local time, + and `UTC` is the $(REF_SHORT TimeZone,std,datetime,timezone) class which + represents UTC. `SysTime` uses $(REF_SHORT LocalTime,std,datetime,timezone) if + no $(REF_SHORT TimeZone,std,datetime,timezone) is provided. For more details on + time zones, see the documentation for $(REF_SHORT TimeZone,std,datetime,timezone), + $(REF_SHORT PosixTimeZone,std,datetime,timezone), and + $(REF_SHORT WindowsTimeZone,std,datetime,timezone). +) +$(P `SysTime`'s range is from approximately 29,000 B.C. to approximately 29,000 A.D. +) +See_Also: + $(RELATIVE_LINK2 .Clock.currTime, `Clock.currTime`) will return the current time as a `SysTime`. +/ struct SysTime { @@ -9674,16 +9685,25 @@ private: @safe unittest { import core.time : days, hours, seconds; - import std.datetime.date : DateTime; + import std.datetime.date : Date, DateTime; import std.datetime.timezone : SimpleTimeZone, UTC; + const dt = DateTime(2018, 1, 1, 10, 30, 0); // make a specific point in time in the UTC timezone - auto st = SysTime(DateTime(2018, 1, 1, 10, 30, 0), UTC()); + auto st = SysTime(dt, UTC()); + assert(st.year == 2018); + assert(st.hour == 10); + + // cast to convert + assert(cast(DateTime) st == dt); + assert(cast(Date) st == Date(2018, 1, 1)); + // make a specific point in time in the New York timezone - auto ny = SysTime( - DateTime(2018, 1, 1, 10, 30, 0), + const ny = SysTime(dt, new immutable SimpleTimeZone(-5.hours, "America/New_York") ); + assert(ny != st); + assert(ny.hour == 10); // ISO standard time strings assert(st.toISOString() == "20180101T103000Z"); @@ -9775,7 +9795,7 @@ long unixTimeToStdTime(long unixTime) @safe pure nothrow @nogc "std time"'s epoch is based on the Proleptic Gregorian Calendar per ISO 8601 and is what $(LREF SysTime) uses internally. However, holding the time - as an integer in hnescs since that epoch technically isn't actually part of + as an integer in hnsecs since that epoch technically isn't actually part of the standard, much as it's based on it, so the name "std time" isn't particularly good, but there isn't an official name for it. C# uses "ticks" for the same thing, but they aren't actually clock ticks, and the term diff --git a/libphobos/src/std/math/algebraic.d b/libphobos/src/std/math/algebraic.d index 4791766..9999071 100644 --- a/libphobos/src/std/math/algebraic.d +++ b/libphobos/src/std/math/algebraic.d @@ -43,24 +43,24 @@ import std.traits : CommonType, isFloatingPoint, isIntegral, isSigned, Unqual; * the return type will be the same as the input. * * Limitations: - * Does not work correctly for signed intergal types and value `Num`.min. + * When x is a signed integral equal to `Num.min` the value of x will be returned instead. + * Note for 2's complement; `-Num.min` (= `Num.max + 1`) is not representable due to overflow. */ -auto abs(Num)(Num x) @nogc pure nothrow -if ((is(immutable Num == immutable short) || is(immutable Num == immutable byte)) || - (is(typeof(Num.init >= 0)) && is(typeof(-Num.init)))) +auto abs(Num)(Num x) @nogc nothrow pure +if (isIntegral!Num || (is(typeof(Num.init >= 0)) && is(typeof(-Num.init)))) { static if (isFloatingPoint!(Num)) return fabs(x); else { - static if (is(immutable Num == immutable short) || is(immutable Num == immutable byte)) - return x >= 0 ? x : cast(Num) -int(x); + static if (isIntegral!Num) + return x >= 0 ? x : cast(Num) -x; else return x >= 0 ? x : -x; } } -/// ditto +/// @safe pure nothrow @nogc unittest { import std.math.traits : isIdentical, isNaN; @@ -70,16 +70,27 @@ if ((is(immutable Num == immutable short) || is(immutable Num == immutable byte) assert(abs(-real.infinity) == real.infinity); assert(abs(-56) == 56); assert(abs(2321312L) == 2321312L); + assert(abs(23u) == 23u); } @safe pure nothrow @nogc unittest { - short s = -8; - byte b = -8; - assert(abs(s) == 8); - assert(abs(b) == 8); - immutable(byte) c = -8; - assert(abs(c) == 8); + assert(abs(byte(-8)) == 8); + assert(abs(ubyte(8u)) == 8); + assert(abs(short(-8)) == 8); + assert(abs(ushort(8u)) == 8); + assert(abs(int(-8)) == 8); + assert(abs(uint(8u)) == 8); + assert(abs(long(-8)) == 8); + assert(abs(ulong(8u)) == 8); + assert(is(typeof(abs(byte(-8))) == byte)); + assert(is(typeof(abs(ubyte(8u))) == ubyte)); + assert(is(typeof(abs(short(-8))) == short)); + assert(is(typeof(abs(ushort(8u))) == ushort)); + assert(is(typeof(abs(int(-8))) == int)); + assert(is(typeof(abs(uint(8u))) == uint)); + assert(is(typeof(abs(long(-8))) == long)); + assert(is(typeof(abs(ulong(8u))) == ulong)); } @safe pure nothrow @nogc unittest diff --git a/libphobos/src/std/net/curl.d b/libphobos/src/std/net/curl.d index 2fcbf94..6aec366c 100644 --- a/libphobos/src/std/net/curl.d +++ b/libphobos/src/std/net/curl.d @@ -2419,8 +2419,8 @@ struct HTTP @system @property void onReceiveHeader(void delegate(in char[] key, in char[] value) callback) { - import std.algorithm.searching : startsWith; - import std.regex : regex, match; + import std.algorithm.searching : findSplit, startsWith; + import std.string : indexOf, chomp; import std.uni : toLower; // Wrap incoming callback in order to separate http status line from @@ -2447,21 +2447,18 @@ struct HTTP return; } - // Normal http header - auto m = match(cast(char[]) header, regex("(.*?): (.*)$")); - - auto fieldName = m.captures[1].toLower().idup; + auto m = header.findSplit(": "); + auto fieldName = m[0].toLower(); + auto fieldContent = m[2].chomp; if (fieldName == "content-type") { - auto mct = match(cast(char[]) m.captures[2], - regex("charset=([^;]*)", "i")); - if (!mct.empty && mct.captures.length > 1) - charset = mct.captures[1].idup; + auto io = indexOf(fieldContent, "charset=", No.caseSensitive); + if (io != -1) + charset = fieldContent[io + "charset=".length .. $].findSplit(";")[0].idup; } - - if (!m.empty && callback !is null) - callback(fieldName, m.captures[2]); - headersIn[fieldName] = m.captures[2].idup; + if (!m[1].empty && callback !is null) + callback(fieldName, fieldContent); + headersIn[fieldName] = fieldContent.idup; } catch (UTFException e) { @@ -2479,20 +2476,27 @@ struct HTTP /// Parse status line, as received from / generated by cURL. private static bool parseStatusLine(const char[] header, out StatusLine status) @safe { - import std.conv : to; - import std.regex : regex, match; + import std.algorithm.searching : findSplit, startsWith; + import std.conv : to, ConvException; - const m = match(header, regex(r"^HTTP/(\d+)(?:\.(\d+))? (\d+)(?: (.*))?$")); - if (m.empty) - return false; // Invalid status line - else + if (!header.startsWith("HTTP/")) + return false; + + try { - status.majorVersion = to!ushort(m.captures[1]); - status.minorVersion = m.captures[2].length ? to!ushort(m.captures[2]) : 0; - status.code = to!ushort(m.captures[3]); - status.reason = m.captures[4].idup; + const m = header["HTTP/".length .. $].findSplit(" "); + const v = m[0].findSplit("."); + status.majorVersion = to!ushort(v[0]); + status.minorVersion = v[1].length ? to!ushort(v[2]) : 0; + const s2 = m[2].findSplit(" "); + status.code = to!ushort(s2[0]); + status.reason = s2[2].idup; return true; } + catch (ConvException e) + { + return false; + } } @safe unittest @@ -2505,6 +2509,12 @@ struct HTTP // The HTTP2 protocol is binary; cURL generates this fake text header. assert(parseStatusLine("HTTP/2 200", status) && status == StatusLine(2, 0, 200, null)); + + assert(!parseStatusLine("HTTP/2", status)); + assert(!parseStatusLine("HTTP/2 -1", status)); + assert(!parseStatusLine("HTTP/2 200", status)); + assert(!parseStatusLine("HTTP/2.X 200", status)); + assert(!parseStatusLine("HTTP|2 200", status)); } /** Time condition enumeration as an alias of $(REF CurlTimeCond, etc,c,curl) |