-
Notifications
You must be signed in to change notification settings - Fork 31
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
Proper handling of some callbacks and create some wrapper objects with automatic memory management #132
Conversation
Some functions are explicitly forbidden from using these since they store the reference of gsl_function across multiple calls.
I took a look at GSL.jl's dependents and observed the following usage of types and routines: Package usage of GSL.jl
which is almost entirely special functions, so this api wouldn't immediately affect the package ecosystem. I think a great benefit of this work is that wrapping these routines in higher-level interfaces such as Integrals.jl and NonlinearSolve.jl becomes greatly simplified. I also went through the package to identify as many of the callback types and unsafe interfaces as I could find. Callback wrapper typesAll of these types can have helper macros to convert user callbacks into
Types storing callback pointersIn order to be safe, helper routines for these wrappers, i.e. all except for the
Other typesAny routine that allocates a gsl type can be found with Ctrl+F "alloc" and "calloc" in I will mention the following types that use callback functions in particular routines in a context where a
Is it correct that only the types in "Types storing callback pointers" will need to store a reference to the callback data? In particular I don't think Procedure to create safe api
I got carried away with writing this comment and I'll submit a pr to this pr later today adding tests for |
This only cover a few of the functions (the ones that have macros created for them) and all of their uses. There are still many other callback types and objects that are not covered.
All the new interfaces should be restricted to when it is actually safe to do so. The old interface remains in place for backward compatibility (it may be broken for a few cases if the user have defined their own
cconvert
/unsafe_convert
methods on the GSL pointer type but I think those usecases can be safely ignored.)The auto generation script has not been updated. There are some changes to the code that can't easily be done automatically though most of those should not be exported function anymore (there's method explicitly defined in GSL module that hides the C module reexport) so that could be fixed reasonably easily.
The implementation for some functions (the "managed" ones, e.g.
cheb_init
are not fully optimum) and there are some cases where another one allocation could be shaved off. Since these are mainly set-once-use-multiple time allocations I didn't feel like optimizing it while making the code a bit more ugly at the moment....