Skip to content

Commit

Permalink
auto wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Dec 31, 2023
1 parent af3ca7b commit f8a2a54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gen/gsl_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ defined in `gsl_math.h`.
"""
mutable struct gsl_function
function_::Ptr{Cvoid}
params::Ptr{Cvoid}
params
end

@doc md"""
Expand Down
19 changes: 19 additions & 0 deletions src/manual_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ end


## Root finding

# wrapper function
function gsl_function_helper(x::Cdouble, @nospecialize(fn::Any))::Cdouble
try
return Cdouble(fn(x))
catch
return NaN
end
end

function Base.cconvert(::Type{Ref{gsl_function}}, fn)
fptr = @cfunction(gsl_function_helper, Cdouble, (Cdouble, Any))
convert(Ref{gsl_function}, gsl_function(fptr, fn))
end

Base.cconvert(::Type{Ref{gsl_function}}, gslf::gsl_function) =
convert(Ref{gsl_function}, gslf)


# Macros for easier creation of gsl_function and gsl_function_fdf structs
export @gsl_function, @gsl_function_fdf

Expand Down

0 comments on commit f8a2a54

Please sign in to comment.