Skip to content

Commit 6cf2b14

Browse files
authored
remove unused Base.GMP.MPZ.import! and test Base.GMP.MPZ.export! (#56903)
1 parent ef04055 commit 6cf2b14

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

base/gmp.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ end
264264

265265
limbs_write!(x::BigInt, a) = ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a)
266266
limbs_finish!(x::BigInt, a) = ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a)
267-
import!(x::BigInt, a, b, c, d, e, f) = ccall((:__gmpz_import, libgmp), Cvoid,
268-
(mpz_t, Csize_t, Cint, Csize_t, Cint, Csize_t, Ptr{Cvoid}), x, a, b, c, d, e, f)
269267

270268
setbit!(x, a) = (ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a); x)
271269
tstbit(a::BigInt, b) = ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool

test/gmp.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,44 @@ end
445445
@test string(big(0), base = rand(2:62), pad = 0) == ""
446446
end
447447

448+
@testset "Base.GMP.MPZ.export!" begin
449+
450+
function Base_GMP_MPZ_import!(x::BigInt, n::AbstractVector{T}; order::Integer=-1, nails::Integer=0, endian::Integer=0) where {T<:Base.BitInteger}
451+
ccall((:__gmpz_import, Base.GMP.MPZ.libgmp),
452+
Cvoid,
453+
(Base.GMP.MPZ.mpz_t, Csize_t, Cint, Csize_t, Cint, Csize_t, Ptr{Cvoid}),
454+
x, length(n), order, sizeof(T), endian, nails, n)
455+
return x
456+
end
457+
# test import
458+
bytes_to_import_from = Vector{UInt8}([1, 0])
459+
int_to_import_to = BigInt()
460+
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_import_from, order=0)
461+
@test int_to_import_to == BigInt(256)
462+
463+
# test export
464+
int_to_export_from = BigInt(256)
465+
bytes_to_export_to = Vector{UInt8}(undef, 2)
466+
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
467+
@test all(bytes_to_export_to .== bytes_to_import_from)
468+
469+
# test both composed import(export) is identity
470+
int_to_export_from = BigInt(256)
471+
bytes_to_export_to = Vector{UInt8}(undef, 2)
472+
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
473+
int_to_import_to = BigInt()
474+
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_export_to, order=0)
475+
@test int_to_export_from == int_to_import_to
476+
477+
# test both composed export(import) is identity
478+
bytes_to_import_from = Vector{UInt8}([1, 0])
479+
int_to_import_to = BigInt()
480+
Base_GMP_MPZ_import!(int_to_import_to, bytes_to_import_from, order=0)
481+
bytes_to_export_to = Vector{UInt8}(undef, 2)
482+
Base.GMP.MPZ.export!(bytes_to_export_to, int_to_export_from, order=0)
483+
@test all(bytes_to_export_to .== bytes_to_import_from)
484+
end
485+
448486
@test isqrt(big(4)) == 2
449487
@test isqrt(big(5)) == 2
450488

0 commit comments

Comments
 (0)