Skip to content
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

Segmentation fault with julia v0.6 #13

Closed
rdeits opened this issue May 30, 2017 · 3 comments
Closed

Segmentation fault with julia v0.6 #13

rdeits opened this issue May 30, 2017 · 3 comments

Comments

@rdeits
Copy link
Contributor

rdeits commented May 30, 2017

The CDDLib.jl and Polyhedra.jl unit tests fail with segfaults on Julia v0.6. The smallest reproducible example I can find so far is this:

using CDDLib
import CDDLib: Cdd_ErrorType, Cdd_boolean, @dd_ccall, Cdd_MatrixData, Cdd_rowrange,
    fulldim, myerror, myfree, CDDInequalityMatrix
using Polyhedra

A = eye(Int, 2)
b = [1, 1]
h = Polyhedra.SimpleHRepresentation(A, b)
matrix = CDDInequalityMatrix(h)
i = Cdd_rowrange(1)
len = fulldim(matrix) + 1
err = Ref{Cdd_ErrorType}(0)
certificateGMPRat = zeros(GMPRational, len)
found = (@dd_ccall Redundant Cdd_boolean (Ptr{Cdd_MatrixData{GMPRational}}, Cdd_rowrange, Ptr{GMPRational}, Ref{Cdd_ErrorType}) matrix.matrix i certificateGMPRat err)
myerror(err[])
certificate = Array{Rational{BigInt}}(certificateGMPRat)
myfree(certificateGMPRat)

which is distilled from the call to redundant(matrix, i) in test/board.jl.

Removing the final call to myfree(certificateGMPRat) prevents the segfault, but I don't understand enough about GMP to know if that's actually a good idea.

This may be related to the issue alluded to here: https://discourse.julialang.org/t/bindings-to-external-lib-work-with-0-5-but-fail-with-0-6-rc1/3734/2 . Apparently in julia v0.5, some finalizers were not actually being run, so it's possible that there's been a double-free somewhere in this code which was hidden by that v0.5 bug but revealed on v0.6.

rdeits added a commit to rdeits/CDDLib.jl that referenced this issue May 30, 2017
@blegat
Copy link
Member

blegat commented May 31, 2017

Thanks for identifying this bug. It it weird because GMPRational has no finalizer. The only possible reason would be that it is freed by Rational{BigInt} which would mean that __gmp_get_num here does not copy.
Let's have the workwaround of #14 for now :)

blegat pushed a commit that referenced this issue Jun 4, 2017
@odow
Copy link
Contributor

odow commented Feb 21, 2024

This should be closed as out-dated.

@odow
Copy link
Contributor

odow commented Feb 22, 2024

julia> using CDDLib

julia> import CDDLib: Cdd_ErrorType, Cdd_boolean, @dd_ccall, Cdd_MatrixData, Cdd_rowrange,
           fulldim, myerror, myfree, CDDInequalityMatrix

julia> using Polyhedra

julia> import LinearAlgebra

julia> eye(T, n) = LinearAlgebra.I(n) * one(T)
eye (generic function with 1 method)

julia> A = eye(Int, 2)
2×2 Diagonal{Int64, Vector{Int64}}:
 1  
   1

julia> b = [1, 1]
2-element Vector{Int64}:
 1
 1

julia> h = Polyhedra.hrep(A, b)
H-representation MixedMatHRep{Int64, Diagonal{Int64, Vector{Int64}}}:
2-element iterator of HalfSpace{Int64, Vector{Int64}}:
 HalfSpace([1, 0], 1)
 HalfSpace([0, 1], 1)

julia> matrix = CDDInequalityMatrix(h)
H-representation CDDInequalityMatrix{Rational{BigInt}, GMPRational}:
2-element iterator of HalfSpace{Rational{BigInt}, Vector{Rational{BigInt}}}:
 HalfSpace(Rational{BigInt}[1, 0], 1//1)
 HalfSpace(Rational{BigInt}[0, 1], 1//1)

julia> i = Cdd_rowrange(1)
1

julia> len = fulldim(matrix) + 1
3

julia> err = Ref{Cdd_ErrorType}(0)
Base.RefValue{Int32}(0)

julia> certificateGMPRat = zeros(GMPRational, len)
3-element Vector{GMPRational}:
 0//1
 0//1
 0//1

julia> found = (@dd_ccall Redundant Cdd_boolean (Ptr{Cdd_MatrixData{GMPRational}}, Cdd_rowrange, Ptr{GMPRational}, Ref{Cdd_ErrorType}) matrix.matrix i certificateGMPRat err)
0

julia> myerror("foo", err[])

julia> certificate = Array{Rational{BigInt}}(certificateGMPRat)
3-element Vector{Rational{BigInt}}:
 1
 2
 1

julia> myfree(certificateGMPRat)

julia>

@odow odow closed this as completed Feb 22, 2024
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

No branches or pull requests

3 participants