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

Update wrapper of xprs.h #257

Merged
merged 5 commits into from
Apr 2, 2024
Merged

Update wrapper of xprs.h #257

merged 5 commits into from
Apr 2, 2024

Conversation

odow
Copy link
Member

@odow odow commented Mar 26, 2024

I need to figure out a good way of handling the variety of Xpress versions that people might use.

I have headers for v33.01.12 and v42.01.05. Ideally, the Xpress.jl should use only functions defined in v33, but it should provide constants etc for v42.

@odow odow changed the title WIP: automatically wrap xors.h WIP: automatically wrap xprs.h Mar 26, 2024
Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.93%. Comparing base (5eb8119) to head (209c78b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #257      +/-   ##
==========================================
+ Coverage   67.91%   67.93%   +0.01%     
==========================================
  Files           6        6              
  Lines        3301     3303       +2     
==========================================
+ Hits         2242     2244       +2     
  Misses       1059     1059              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# For backwards compatibility, older versions of Xpress.jl used Cint
# instead of Clong.
# TODO(odow): this is wrong. Fix me in a separate PR.
contents = replace(contents, "Clong" => "Cint")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I found one super weird thing here. The xprs.jl uses Cint in places where it should use Clong. They are equivalent on windows, but not on Mac or Linux. I don't know if this causes any issues because we don't call the 64( API.

# with older versions of Xpress.jl
#
# We need to replace char* with Ptr{UInt8} and char[] with
# Cstring.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I've hacked around to get the right Cstring and Ptr{UInt8} in the right places. Focusing on minimal changes. We can reconsider in a different PR.

@odow
Copy link
Member Author

odow commented Mar 26, 2024

I think this really highlights that we should have some way of testing v8

@odow
Copy link
Member Author

odow commented Mar 26, 2024

x-ref JuliaRegistries/General#103626

setvals,
)
if get_version() >= v"41.01"
@checked Lib.XPRSgetmipentities(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bits were nasty:

Xpress.jl/src/Lib/xprs.jl

Lines 2366 to 2394 in ceb9df8

function _getversion()
buffer = Array{Cchar}(undef, 8 * 24)
buffer_p = pointer(buffer)
GC.@preserve buffer begin
out = Cstring(buffer_p)
r = Lib.XPRSgetversion(out)
if r != 0
throw(XpressError(r, "Unable to invoke XPRSgetversion"))
end
version = unsafe_string(out)::String
end
return VersionNumber(parse.(Int, split(version, "."))...)
end
function XPRSgetglobal(prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
if _getversion() >= v"41.0.0"
return ccall((:XPRSgetmipentities, libxprs), Cint, (XPRSprob, Ptr{Cint}, Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cdouble}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}), prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
else
return ccall((:XPRSgetglobal, libxprs), Cint, (XPRSprob, Ptr{Cint}, Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cdouble}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}), prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
end
end
function XPRSgetglobal64(prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
if _getversion() >= v"41.0.0"
return ccall((:XPRSgetmipentities64, libxprs), Cint, (XPRSprob, Ptr{Cint}, Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cdouble}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}), prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
else
return ccall((:XPRSgetglobal64, libxprs), Cint, (XPRSprob, Ptr{Cint}, Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cdouble}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}), prob, p_nentities, p_nsets, coltype, colind, limit, settype, start, setcols, refval)
end
end

@odow odow changed the title WIP: automatically wrap xprs.h Update wrapper of xprs.h Apr 2, 2024
@odow
Copy link
Member Author

odow commented Apr 2, 2024

Okay. I'm feeling a lot better about this now that we're testing on v8 and v9.

@odow
Copy link
Member Author

odow commented Apr 2, 2024

Merging because I want to open a couple of follow-ups.

@odow odow merged commit a6cddbe into master Apr 2, 2024
16 checks passed
@odow odow deleted the od/libxprs branch April 2, 2024 02:27
@odow odow mentioned this pull request Apr 9, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant