Skip to content

cleanup C - Julia BigFloat interop #104

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

Merged
merged 2 commits into from
May 15, 2020
Merged

cleanup C - Julia BigFloat interop #104

merged 2 commits into from
May 15, 2020

Conversation

MikaelSlevinsky
Copy link
Member

C controls mpfr_t memory, Julia controls BigFloat memory.

  • Since BigFloats have an extra field, sizeof(BigFloat) == 40, an array is passed as mpfr_t **, and implicitly the only datum in the second level of addressing is dereferenced by [0].
  • Since BigFloat is a mutable struct, there is no guarantee that each entry in
    an Array{BigFloat} has a unique pointer. For example, looking at the Limbs,
julia> Id = Matrix{BigFloat}(I, 3, 3)
3×3 Array{BigFloat,2}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0

julia> map(x->x.d, Id)
3×3 Array{Ptr{UInt64},2}:
 Ptr{UInt64} @0x000000010f22f958  Ptr{UInt64} @0x000000010f22f918  Ptr{UInt64} @0x000000010f22f918
 Ptr{UInt64} @0x000000010f22f918  Ptr{UInt64} @0x000000010f22f958  Ptr{UInt64} @0x000000010f22f918
 Ptr{UInt64} @0x000000010f22f918  Ptr{UInt64} @0x000000010f22f918  Ptr{UInt64} @0x000000010f22f958

shows that the ones and the zeros all share the same pointers. If a C function
assumes unicity of each datum, then the array must be renewed with a deepcopy.

Before this PR, some of the BigFloat tests were skipped because BigFloat was unsafely converted to mpfr_t before passing to C. I suspect this was unsafe because the garbage collector could free some BigFloat data after the conversion to mpfr_t but before functions were done executing.

@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #104 into master will decrease coverage by 0.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #104      +/-   ##
==========================================
- Coverage   78.65%   78.32%   -0.34%     
==========================================
  Files          12       12              
  Lines        1373     1352      -21     
==========================================
- Hits         1080     1059      -21     
  Misses        293      293              
Impacted Files Coverage Δ
src/FastTransforms.jl 100.00% <ø> (ø)
src/libfasttransforms.jl 86.55% <100.00%> (-0.91%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc78aad...f0b7ff3. Read the comment docs.

@MikaelSlevinsky MikaelSlevinsky merged commit 3b70c23 into master May 15, 2020
@MikaelSlevinsky MikaelSlevinsky deleted the better-BigFloat branch May 15, 2020 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant