-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Make by-value struct passing work properly #7906
Changes from all commits
468cb71
9053bff
1d6c898
99899a0
892b3d6
67a845b
dd34fa5
851c0df
db70626
b7bdfc0
e3d9f85
0e9704e
c26bccf
22490c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,12 @@ New language features | |
Language changes | ||
---------------- | ||
|
||
* cfunction breaking syntax changes, ccall improved generalized argument conversion, | ||
and Ref type addition. See the section below on [Improvements to ccall and cfunction, and Ref] | ||
|
||
* `convert(Ptr, x::Any)` is now generally deprecated, replaced by `unsafe_convert`. | ||
(You can still explicitly `convert` one pointer type into another if needed.) | ||
|
||
* `[x,y]` constructs a vector of `x` and `y` instead of concatenating them | ||
([#3737], [#2488], [#8599]). | ||
|
||
|
@@ -247,6 +253,36 @@ Deprecated or removed | |
* `flipud(A)` and `fliplr(A)` have been deprecated in favor of `flipdim(A, 1)` and | ||
`flipdim(A, 2)`, respectively ([#10446]). | ||
|
||
Improvements to ccall and cfunction, and Ref | ||
-------------------------------------------- | ||
|
||
* a `Ref` abstract type was added, as a general replacement for the `&` special-syntax. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be clearer. Does this mean "instead of writing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either |
||
when converting arguments to `Ref`, the result will be a pointer to a Julia gc-managed | ||
memory location of the appropriate type. | ||
Create a `Ref` object wrapper around a value to create a gc-stable reference to it. | ||
|
||
* cfunction syntax has been altered to be exactly the reverse of ccall | ||
- all types are passed by-value (no implied `*` on the argument), and will be | ||
copied to a new Julia object to match the calling convention of the Julia function | ||
- wrapping a type in `Ref{T}` will look up the method applicable to `T`, | ||
but pass it by-reference to a `jl_value_t*`-typed argument. however, | ||
note that it should only be used on memory allocated in Julia and known isbits types | ||
- isbits types are unaffected by this change, however other types need to be wrapped | ||
in ``Ref{...}`` to retain the old behavior | ||
|
||
* ccall now respects the platform ABI. | ||
For portability, it is essential that your ccall/cfunction argument and return | ||
types are declared correctly. | ||
For example, if the type is one of the native C numeric types (such as `int`), | ||
you must pass it exactly as a 32-bit integer type (for example: `bitstype 32 Int32`). | ||
A Float32 or a `[immutable] type` struct with a size of 32-bits is not equivalent. | ||
|
||
* Lowering of ccall arguments now calls ``unsafe_convert(T, cconvert(T, x))``, | ||
instead of just ``cconvert(T,x)``. Accordingly, "unsafe" operations, like Array-to-Ptr, | ||
have been moved from methods of ``convert`` to methods of ``unsafe_convert``. | ||
|
||
* Updated documentation at [ccall chapter] in the manual | ||
|
||
Julia v0.3.0 Release Notes | ||
========================== | ||
|
||
|
@@ -957,10 +993,12 @@ Bugfixes and performance updates | |
Too numerous to mention. | ||
|
||
[packages chapter]: http://docs.julialang.org/en/latest/manual/packages/ | ||
[ccall chapter]: http://docs.julialang.org/en/latest/manual/calling-c-and-fortran-code/ | ||
[sorting functions]: http://docs.julialang.org/en/latest/stdlib/sort/ | ||
[pairwise summation]: https://en.wikipedia.org/wiki/Pairwise_summation | ||
[a448e080]: https://github.com/JuliaLang/julia/commit/a448e080dc736c7fb326426dfcb2528be36973d3 | ||
[5e3f074b]: https://github.com/JuliaLang/julia/commit/5e3f074b9173044a0a4219f9b285879ff7cec041 | ||
[Improvements to ccall and cfunction, and Ref]: #improvements-to-ccall-and-cfunction-and-ref | ||
<!--- generated by NEWS-update.jl: --> | ||
[#13]: https://github.com/JuliaLang/julia/issues/13 | ||
[#69]: https://github.com/JuliaLang/julia/issues/69 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,9 +125,10 @@ export | |
Box, Function, IntrinsicFunction, LambdaStaticData, Method, MethodTable, | ||
Module, Symbol, Task, Array, GenSym, | ||
# numeric types | ||
Bool, FloatingPoint, Float16, Float32, Float64, Number, Integer, Int, Int8, Int16, | ||
Int32, Int64, Int128, Ref, Ptr, Real, Signed, UInt, UInt8, UInt16, UInt32, | ||
UInt64, UInt128, Unsigned, | ||
Real, Complex, Number, Integer, Bool, Ref, Ptr, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wonder if it should move here (or had at some points in the life of this PR), since it is now an influential type on ccall ABI generation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal; the run time system already refers to some stuff in Base. |
||
FloatingPoint, Float16, Float32, Float64, | ||
Signed, Int, Int8, Int16, Int32, Int64, Int128, | ||
Unsigned, UInt, UInt8, UInt16, UInt32, UInt64, UInt128, | ||
# string types | ||
Char, ASCIIString, ByteString, DirectIndexString, AbstractString, UTF8String, | ||
# errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,3 +215,8 @@ function function_module(f, types) | |
end | ||
m[1].func.code.module | ||
end | ||
|
||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [edit] ❌ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a green X? but yes, that's a good reminder that we need to scan through this and remove any debug code |
||
|
||
type_alignment(x::DataType) = ccall(:jl_get_alignment,Csize_t,(Any,),x) | ||
field_offset(x::DataType,idx) = ccall(:jl_get_field_offset,Csize_t,(Any,Int32),x,idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LDC license concerns me a bit. It's not a common license and it's not simple either. The main MUSL license is MIT, same as Julia; is the getopt implementation under that license or a different one? Similarly, is the NetBSD setjmp/longjmp code on Windows under the 2 or 3 clause BSD license? The 2-clause is MIT-equivalent, while the 3-clause is slightly more restrictive (but not much).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The applicable license from LDC is 3-clause BSD since it's part of LDC, but not DMD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's good. We should probably note these things here. We may want to go through all of the code we use from other projects at some point and check what the specific license of the code we're using is (as opposed to the whole project). I think we're actually already in pretty good shape regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's already there at the top of each file that we've taken from another project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getopt implementation in musl doesn't have a specific license header, so it's under the main musl license. I copied that main musl license into the file: https://github.com/JuliaLang/julia/blob/master/ui/getopt.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the MUSL/getopt.c license is MIT, then please don't list it here: it's the same as the rest of Julia. Things are already complex enough regarding files which have a different license.
Not sure for NetBSD, but if that's exactly equivalent to MIT, maybe do not list it here either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it isn't. Musl is copyright Rich Felker, Julia isn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that information isn't very useful, except for people owning the copyright for most of the rest of the Julia codebase and who may want to relicense it (which likely isn't going to happen). Is it really needed here, rather than in the file header?
Anyway, if it's equivalent to MIT, it should be written explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2-clause BSD is equivalent to MIT but not identical; it should be listed as a separate license.