-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,21 @@ end | |
typealias CdoubleMax Union(Float16, Float32, Float64) | ||
|
||
const GMP_VERSION = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar})))) | ||
const GMP_BITS_PER_LIMB = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint))) | ||
|
||
if GMP_BITS_PER_LIMB == 32 | ||
typealias Limb UInt32 | ||
elseif GMP_BITS_PER_LIMB == 64 | ||
typealias Limb UInt64 | ||
else | ||
error("GMP: cannot determine the type mp_limb_t") | ||
end | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ViralBShah
Member
|
||
|
||
type BigInt <: Integer | ||
alloc::Cint | ||
size::Cint | ||
d::Ptr{Culong} | ||
d::Ptr{Limb} | ||
function BigInt() | ||
b = new(zero(Cint), zero(Cint), C_NULL) | ||
ccall((:__gmpz_init,:libgmp), Void, (Ptr{BigInt},), &b) | ||
|
5 comments
on commit 8b0921c
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.
Should Limb
types correspond to C types, instead of Julia types?
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 don't think so. The C types are just typealiases for Julia types to make it more convenient to write C interfaces without conditionals all over the code to have correct integer sizes on 32 and 64 bit systems. Here we know the number of bits in the type, and we can directly use Julia types with the correct number of bits.
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 agree with what @ivarne said. According to GMP sources, the Limb
could be unsigned
, unsigned long
or unsigned long long
. So I assumed here for simplicity that sizeof(unsigned) >= 32
and sizeof(unsigned long long) <= 64
.
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.
You have not just assumed, you have asserted and will crash the sysimg build with a (useful?) error if it is not true. (which is the right way to do it.)
I'm generally in favor of including the invalid value in errors like that. How about
error("GMP: cannot determine the type mp_limb_t (__gmp_bits_per_limb == $GMP_BITS_PER_LIMB)")
That typically saves us one roundtrip of questions when someone asks for help debugging when the error is triggered.
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.
Yes you are right, I will change this message when squashing.
This code will be executed at system image build time, not at runtime. I've seen discussions about distributing
sys.{dll,so,dylib}
. Should we just hope they distributelibgmp
(or do something make that required somehow), so that it will be compiled with the same options on the target system? If we can't assume that, we'll need to put these checks in a__init__
function, and somehow figure out to write the code without compile time knowledge of the length ofLimb
I don't expect @rfourquet to answer, but maybe others have some insight.