Comments (6)
This strikes me as a bug in the type safety of Ref.
true, this may be worth a special case for Ref. In C, the void
type is more nearly Union{}
in Julia. The common mapping in Julia to Void
has some slightly different behaviors (such as this one).
from gsl.jl.
I don't fully agree with that; Union{}
is closer to a noreturn
declaration. void
in C is pretty close to being a normal observable value.
This problem would occur with any type; assigning a Ptr{Int}
to a Ref{Int}
field would do the same thing. The only fix I can think of so far is to throw an error for converting a Ptr to a Ref. Ptr could still be a subtype of Ref. That seems to handle the contexts where Ptr can vs. can't be substituted as a Ref.
from gsl.jl.
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.
void
is not constructible, cannot be used as a field, and is convertible to/from all other types but cannot itself be constructed: http://programmers.stackexchange.com/a/254191
In C++, void &x
would be an error because void
cannot be constructed, which is more similar to how Union{}
behaves in Julia. In particular, the C standard specifies that the presence of the void
type is special in that it does not have a value (usage of it would be an error), but the code must still be executed for side-effects.
from gsl.jl.
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 Ref{Int}
as a field type, assigning an Int
to it will actually work. Assigning a Ptr to a Ref field may be wrong, but it's wrong in a very confusing way that could benefit from an error message.
from gsl.jl.
As I understood from discussion with @JeffBezanson and @vtjnash offline, the general rule of thumb is to use Ref{T}
only in covariant context to replace the x = Array(T, 1); ccall(... &x)
idiom in old Julia. In other scenarios like the return value of a ccall and a Julia type mimicking a C struct
, Ptr{T}
should be used instead as the proper representation of a C pointer (an integer representing a potentially useful address, lacking the address validation and GC rooting created by Ref
to a Julia object).
from gsl.jl.
I think all reasonable actions pertaining to this issue have been taken. The Julia manual has been updated and Ref
s excised.
from gsl.jl.
Related Issues (20)
- Upgrade to GSL 2.6
- Register a new version of the package that uses GSL_jll artifacts HOT 1
- install failure on Ubuntu HOT 3
- Cannot construct a parameters object HOT 14
- TagBot trigger issue HOT 7
- drone.io pipeline failing HOT 2
- upgrade to GSL 2.7 HOT 2
- Include slightly higher-level interface, for example manage rng allocation HOT 2
- How to use multilarge_nlinear? HOT 1
- Build error: MethodError: no method matching installed(::String) HOT 1
- hypergeom doesn't work for complex arguments HOT 2
- Package compatibility caps
- Incorrect values in hypergeometric_2F1 HOT 5
- Planning upgrade to GSL 2 HOT 5
- `custom_error_handler` needs redesign
- More Examples HOT 1
- `cglobal: could not find symbol gsl_movstat_accum_mad` HOT 1
- Release new version HOT 1
- Stack overflow from hypergeometric 1F1 HOT 6
- segfault upon "using GSL" on Julia master HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gsl.jl.