Skip to content

Commit f9365a5

Browse files
authored
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.
1 parent c89b1ff commit f9365a5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

base/int.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '.' in "123456789123.4"
642642
[...]
643643
```
644644
"""
645-
macro int128_str(s)
645+
macro int128_str(s::String)
646646
return parse(Int128, s)
647647
end
648648

@@ -662,7 +662,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '-' in "-123456789123"
662662
[...]
663663
```
664664
"""
665-
macro uint128_str(s)
665+
macro uint128_str(s::String)
666666
return parse(UInt128, s)
667667
end
668668

@@ -695,7 +695,7 @@ ERROR: ArgumentError: invalid number format _ for BigInt or BigFloat
695695
depends on the value of the precision at the point when the function is
696696
defined, **not** at the precision at the time when the function is called.
697697
"""
698-
macro big_str(s)
698+
macro big_str(s::String)
699699
message = "invalid number format $s for BigInt or BigFloat"
700700
throw_error = :(throw(ArgumentError($message)))
701701
if '_' in s

stdlib/Dates/src/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ but creates the DateFormat object once during macro expansion.
478478
479479
See [`DateFormat`](@ref) for details about format specifiers.
480480
"""
481-
macro dateformat_str(str)
481+
macro dateformat_str(str::String)
482482
DateFormat(str)
483483
end
484484

stdlib/Sockets/src/IPAddr.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ julia> @ip_str "2001:db8:0:0:0:0:2:1"
286286
ip"2001:db8::2:1"
287287
```
288288
"""
289-
macro ip_str(str)
289+
macro ip_str(str::String)
290290
return parse(IPAddr, str)
291291
end
292292

0 commit comments

Comments
 (0)