Skip to content

Commit ae9f94c

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 e80ce4b commit ae9f94c

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
@@ -647,7 +647,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '.' in "123456789123.4"
647647
[...]
648648
```
649649
"""
650-
macro int128_str(s)
650+
macro int128_str(s::String)
651651
return parse(Int128, s)
652652
end
653653

@@ -667,7 +667,7 @@ ERROR: LoadError: ArgumentError: invalid base 10 digit '-' in "-123456789123"
667667
[...]
668668
```
669669
"""
670-
macro uint128_str(s)
670+
macro uint128_str(s::String)
671671
return parse(UInt128, s)
672672
end
673673

@@ -700,7 +700,7 @@ ERROR: ArgumentError: invalid number format _ for BigInt or BigFloat
700700
depends on the value of the precision at the point when the function is
701701
defined, **not** at the precision at the time when the function is called.
702702
"""
703-
macro big_str(s)
703+
macro big_str(s::String)
704704
message = "invalid number format $s for BigInt or BigFloat"
705705
throw_error = :(throw(ArgumentError($message)))
706706
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
@@ -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)