Skip to content

Commit b0fa13f

Browse files
nsajkoKristofferC
authored andcommitted
restrict dispatch of some custrom string macros to String (#57781)
Restricts the dispatch for these macros so that only `String` (literal) arguments are accepted: * `int128_str` * `uint128_str` * `big_str` * `ip_str` from the Sockets stdlib * `dateformat_str` from the Dates stdlib Some of these changes make the code in the sysimage less vulnerable to invalidation. (cherry picked from commit f9365a5)
1 parent 6f6fa6b commit b0fa13f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

base/int.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '.' in "123456789123.4"
711711
[...]
712712
```
713713
"""
714-
macro int128_str(s)
714+
macro int128_str(s::String)
715715
return parse(Int128, s)
716716
end
717717

@@ -731,7 +731,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '-' in "-123456789123"
731731
[...]
732732
```
733733
"""
734-
macro uint128_str(s)
734+
macro uint128_str(s::String)
735735
return parse(UInt128, s)
736736
end
737737

@@ -755,7 +755,7 @@ ERROR: ArgumentError: invalid number format _ for BigInt or BigFloat
755755
[...]
756756
```
757757
"""
758-
macro big_str(s)
758+
macro big_str(s::String)
759759
message = "invalid number format $s for BigInt or BigFloat"
760760
throw_error = :(throw(ArgumentError($message)))
761761
if '_' in s

stdlib/Dates/src/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ but creates the DateFormat object once during macro expansion.
460460
461461
See [`DateFormat`](@ref) for details about format specifiers.
462462
"""
463-
macro dateformat_str(str)
463+
macro dateformat_str(str::String)
464464
DateFormat(str)
465465
end
466466

stdlib/Sockets/src/IPAddr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ julia> @ip_str "2001:db8:0:0:0:0:2:1"
265265
ip"2001:db8::2:1"
266266
```
267267
"""
268-
macro ip_str(str)
268+
macro ip_str(str::String)
269269
return parse(IPAddr, str)
270270
end
271271

0 commit comments

Comments
 (0)