-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove unused Base.GMP.MPZ.import! and test Base.GMP.MPZ.export! #56903
Conversation
Thanks! AFAICT, This invokes pkgeval: @nanosoldier |
Oh, I wanted to run some kind of grep at least, if it is used somewhere, but I forgot. Sorry. However, this functionality is very handy for "interpreting memory as number". I am not sure if there is more use cases. However it would be nice for any serious RSA implementation (and ElGamal at least I think, possibly more cryptographic schemes), which needs to interpret memory as a number to sign it or encrypt/decrypt it. I would like to see movement in the opposite direction and would like to see more support for this. Otherwise, some iteration based construction for this use case would be needed, unless some Julia native BigInt type is present in Base. I also think, any big number serialization/deserialization would benefit from this. However, I can implement any proposed changes or feel free to close this, if it is not desired change |
No uses outside of Base according to https://juliahub.com/ui/Search?type=symbols&q=import! |
The package evaluation job you requested has completed - possible new issues were detected. |
Generally, I lean toward avoiding new public API unless there is a very compelling case. The fact that nobody has used this internal function all this time makes me doubt that it is valuable commonly enough to warrant including in the public API. For those reasons, I prefer deleting That said, it would be nice to hear other folks' opinions on whether we should keep/publicize/remove Let's talk about it at the next triage meeting Thursday at 1:15 ET. |
Triage talked about this and considered weather we want to provide a user facing wrapper of MPZ or if we just want to keep these internal and use only what we need to implement For |
Ok, fair. It makes sense since there is still much in MPZ that would be cool to have in Julia but does not have bindings. So, lets rebase it and keep only the test and argument rename? |
It would also be good to move the definition of |
6d71254
to
c1c49cc
Compare
Not sure, if this is how you meant to move the definition from base to tests. However I could not define |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, if this is how you meant to move the definition from base to tests.
Yes, that's it exactly. It would be bad to define Base.GMP.MPZ.import!
in tests because then someone could write tests for that function that appear to be testing a function defined in Base when that function actually does not exist in Base julia!
base/gmp.jl
Outdated
function export!(x::AbstractVector{T}, n::BigInt; order::Integer=-1, nails::Integer=0, endian::Integer=0) where {T<:Base.BitInteger} | ||
stride(x, 1) == 1 || throw(ArgumentError("x must have stride 1")) | ||
ndigits = cld(sizeinbase(n, 2), 8*sizeof(T) - nails) | ||
length(a) < ndigits && resize!(a, ndigits) | ||
length(x) < ndigits && resize!(x, ndigits) | ||
count = Ref{Csize_t}() | ||
ccall((:__gmpz_export, libgmp), Ptr{T}, (Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), | ||
a, count, order, sizeof(T), endian, nails, n) | ||
@assert count[] ≤ length(a) | ||
return a, Int(count[]) | ||
ccall((:__gmpz_export, libgmp), | ||
Ptr{T}, | ||
(Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), | ||
x, count, order, sizeof(T), endian, nails, n) | ||
@assert count[] ≤ length(x) | ||
return x, Int(count[]) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid committing formatting-only changes unless they are meaningful improvements and/or the old format was clearly bad. In this case, renaming this vector from a
to x
and changing line breaks just doesn't seem worth doing.
OTOH, I really don't care that much about this formatting so if you want to leave these changes in that's okay with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing it. It was either remove, or do separate commit and at that point it did not make sense anymore I think
test/gmp.jl
Outdated
@@ -445,6 +445,44 @@ end | |||
@test string(big(0), base = rand(2:62), pad = 0) == "" | |||
end | |||
|
|||
@testset "Base.GMP.MPZ.import!/export!" begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@testset "Base.GMP.MPZ.import!/export!" begin | |
@testset "Base.GMP.MPZ.export!" begin |
At this point, the testset is only testing export!
because import!
isn't a thing anymore (outside of the testset itself)
add tests, that numbers and vectors can be exported and imported correctly and composed import and export is identity
c1c49cc
to
dca8c16
Compare
Thanks, @NegaScout! |
rename Base.GMP.MPZ.export! "dynamic" variable from
a
tox
, since it is more in line with comment on L141 in base/gmp.jljulia/base/gmp.jl
Lines 141 to 146 in cab11bb
add tests, that numbers and vectors can be exported and imported correctly and composed import and export is identity