-
Notifications
You must be signed in to change notification settings - Fork 30
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
remove use of Ref{Void}
as a struct field type
#43
Comments
true, this may be worth a special case for Ref. In C, the |
I don't fully agree with that; This problem would occur with any type; assigning a |
If you declare the field type wrong, the code will be wrong. There's nothing unique to Ref there, since the same applies to any other error in field declaration. otoh, if you declare the fields correctly, then you can't substitute Ref for Ptr (since that requires an unsafe_convert), which is the intended direction for usage-safety.
|
I think this problem reflects some unclarity about when to use Ref instead of Ptr. The docs basically say "use Ref". Maybe all we need to do is update the docs to say "never use Ref as a struct field"? However this is a bit complicated by the fact that if you use |
As I understood from discussion with @JeffBezanson and @vtjnash offline, the general rule of thumb is to use |
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Other minor formatting change Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Other minor formatting change Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl - Fix description of `cconvert` in the Auto-conversion section - Better cross-referencing to the standard library - Other minor formatting changes Ref: JuliaMath/GSL.jl#43
- Remove references to #2818 - Explain when to use `Ptr{T}` and when to use `Ref{T}` correctly. `Ptr` is generally used for return types and fields of types mirroring C structs. `Ref` is generally used for input types, allowing memory managed by either C or Julia to be referenced by `ccall`. - Provide some examples of C wrappers simplified from GSL.jl, with comments delineating the various parts of the `ccall`. - Fix description of `cconvert` in the Auto-conversion section - Better cross-referencing to the standard library - Other minor formatting changes Ref: JuliaMath/GSL.jl#43
I think all reasonable actions pertaining to this issue have been taken. The Julia manual has been updated and |
I believe we need more changes of the kind made in #40. For example _35_3_Providing_the_function_to_solve.jl still has a use of
Ref{Void}
in a struct. This is only correct if you want the struct to contain exactly a pointer to the objectnothing
. @vtjnash am I right about that?Problems arise when storing a
Ptr{Void}
to such a field, becausePtr{Void}
is no-op convertible toRef{Void}
, so the field ends up pointing to a boxed pointer. This strikes me as a bug in the type safety ofRef
.The text was updated successfully, but these errors were encountered: