Skip to content

Commit f8a2a54

Browse files
committed
auto wrapper
1 parent af3ca7b commit f8a2a54

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/gen/gsl_types.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ defined in `gsl_math.h`.
876876
"""
877877
mutable struct gsl_function
878878
function_::Ptr{Cvoid}
879-
params::Ptr{Cvoid}
879+
params
880880
end
881881

882882
@doc md"""

src/manual_wrappers.jl

+19
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ end
3030

3131

3232
## Root finding
33+
34+
# wrapper function
35+
function gsl_function_helper(x::Cdouble, @nospecialize(fn::Any))::Cdouble
36+
try
37+
return Cdouble(fn(x))
38+
catch
39+
return NaN
40+
end
41+
end
42+
43+
function Base.cconvert(::Type{Ref{gsl_function}}, fn)
44+
fptr = @cfunction(gsl_function_helper, Cdouble, (Cdouble, Any))
45+
convert(Ref{gsl_function}, gsl_function(fptr, fn))
46+
end
47+
48+
Base.cconvert(::Type{Ref{gsl_function}}, gslf::gsl_function) =
49+
convert(Ref{gsl_function}, gslf)
50+
51+
3352
# Macros for easier creation of gsl_function and gsl_function_fdf structs
3453
export @gsl_function, @gsl_function_fdf
3554

0 commit comments

Comments
 (0)