Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
goulart-paul committed May 28, 2024
1 parent ec6b723 commit 6734765
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/julia/ClarabelRs/src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ function write_to_file(solver::Solver, filename::String)

end

function read_from_file(filename::String)

solver_read_from_file_jlrs(filename::String)

end


# -------------------------------------
# Wrappers for rust-side interface
Expand Down Expand Up @@ -117,6 +123,22 @@ function solver_write_to_file_jlrs(solver::Solver, filename::String)

end

function solver_read_from_file_jlrs(filename::String)

ptr = ccall(Libdl.dlsym(librust,:solver_read_from_file_jlrs),Ptr{Cvoid},
(
Cstring,
),
filename,
)

if ptr == C_NULL
error("Error reading from file $filename")
end
return Solver{Float64}(ptr)

end

function solver_drop_jlrs(solver::Solver)
ccall(Libdl.dlsym(librust,:solver_drop_jlrs),Cvoid,
(Ptr{Cvoid},), solver.ptr)
Expand Down
30 changes: 30 additions & 0 deletions src/julia/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ pub(crate) extern "C" fn solver_write_to_file_jlrs(
return status;
}

// dump problem data to a file
// returns NULL on failure, pointer to solver on success
#[no_mangle]
pub(crate) extern "C" fn solver_read_from_file_jlrs(
filename: *const std::os::raw::c_char,
) -> *const c_void {
let slice = unsafe { CStr::from_ptr(filename) };

let filename = match slice.to_str() {
Ok(s) => s,
Err(_) => {
return std::ptr::null();
}
};

let mut file = match File::open(&filename) {
Ok(f) => f,
Err(_) => {
return std::ptr::null();
}
};

let solver = DefaultSolver::read_from_file(&mut file);

match solver {
Ok(solver) => to_ptr(Box::new(solver)),
Err(_) => std::ptr::null(),
}
}

// safely drop a solver object through its pointer.
// called by the Julia side finalizer when a solver
// is out of scope
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/solver/implementations/default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ pub use solver::*;
pub use variables::*;

#[cfg(feature = "serde")]
mod fileio;
mod json;

0 comments on commit 6734765

Please sign in to comment.