Skip to content

Commit 96870de

Browse files
authored
Fix signature for mpfr's set_emin/_emax calls (#32743)
These functions can error and thus return a Cint error code. Most architectures aren't particularly picky about a mismatched signature for the return value (particularly something like Cint that is often ignored), but it is both wrong and can cause problems on architectures that have strict checking (e.g. wasm).
1 parent b9cb5f4 commit 96870de

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

base/mpfr.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,9 @@ get_emin() = ccall((:mpfr_get_emin, :libmpfr), Clong, ())
10311031
get_emin_min() = ccall((:mpfr_get_emin_min, :libmpfr), Clong, ())
10321032
get_emin_max() = ccall((:mpfr_get_emin_max, :libmpfr), Clong, ())
10331033

1034-
set_emax!(x) = ccall((:mpfr_set_emax, :libmpfr), Cvoid, (Clong,), x)
1035-
set_emin!(x) = ccall((:mpfr_set_emin, :libmpfr), Cvoid, (Clong,), x)
1034+
check_exponent_err(ret) = ret == 0 || throw(ArgumentError("Invalid MPFR exponent range"))
1035+
set_emax!(x) = check_exponent_err(ccall((:mpfr_set_emax, :libmpfr), Cint, (Clong,), x))
1036+
set_emin!(x) = check_exponent_err(ccall((:mpfr_set_emin, :libmpfr), Cint, (Clong,), x))
10361037

10371038
function Base.deepcopy_internal(x::BigFloat, stackdict::IdDict)
10381039
haskey(stackdict, x) && return stackdict[x]

0 commit comments

Comments
 (0)