Skip to content
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

Merged
merged 14 commits into from
Mar 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ for exceptions.
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Julia includes code from the following projects, which have their own licenses:
- [LDC](https://github.com/ldc-developers/ldc/blob/master/LICENSE) (for ccall/cfunction ABI definitions)
- [MUSL](http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT) (for getopt implementations on Windows)
- [NetBSD](http://www.netbsd.org/about/redistribution.html) (for setjmp/longjmp implementations on Windows)
Copy link
Member

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).

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the same as the rest of Julia

No it isn't. Musl is copyright Rich Felker, Julia isn't.

Copy link
Member

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.

Copy link
Member

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.


The Julia language links to the following external libraries, which have their
own licenses:
Expand All @@ -52,7 +56,6 @@ their own licenses:
- [GMP](http://gmplib.org/manual/Copying.html#Copying)
- [LIBGIT2](https://github.com/libgit2/libgit2/blob/development/COPYING)
- [MPFR](http://www.mpfr.org/mpfr-current/mpfr.html#Copying)
- [MUSL](http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT)
- [OPENBLAS](https://raw.github.com/xianyi/OpenBLAS/master/LICENSE)
- [LAPACK](http://netlib.org/lapack/LICENSE.txt)
- [PCRE](http://www.pcre.org/licence.txt)
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ julia-deps: git-submodules | $(DIRS) $(build_datarootdir)/julia/base $(build_da
julia-base: julia-deps
@$(MAKE) $(QUIET_MAKE) -C base

julia-libccalltest:
@$(MAKE) $(QUIET_MAKE) -C test libccalltest

julia-src-%: julia-deps
@$(MAKE) $(QUIET_MAKE) -C src libjulia-$*

Expand All @@ -78,7 +81,7 @@ julia-ui-%: julia-src-%
julia-sysimg-% : julia-ui-% julia-base
@$(MAKE) $(QUIET_MAKE) LD_LIBRARY_PATH=$(build_libdir):$(LD_LIBRARY_PATH) JULIA_EXECUTABLE="$(JULIA_EXECUTABLE_$*)" $(build_private_libdir)/sys.$(SHLIB_EXT)

julia-debug julia-release : julia-% : julia-symlink-% julia-sysimg-%
julia-debug julia-release : julia-% : julia-symlink-% julia-sysimg-% julia-libccalltest

debug release : % : julia-%

Expand Down Expand Up @@ -455,6 +458,7 @@ clean: | $(CLEAN_TARGETS)
@$(MAKE) -C doc clean
@$(MAKE) -C src clean
@$(MAKE) -C ui clean
@$(MAKE) -C test clean
@rm -f julia
@rm -f *~ *# *.tar.gz
@rm -f $(build_bindir)/stringreplace \
Expand Down
38 changes: 38 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).

Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be clearer. Does this mean "instead of writing &x, write Ref(x)"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either Ref(x) or Ref{T}

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
==========================

Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complex shouldn't be here; it's not in this module.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ for (fname, elty) in ((:cblas_zdotc_sub,:Complex128),
# DOUBLE PRECISION DX(*),DY(*)
function dotc(n::Integer, DX::Union(Ptr{$elty},DenseArray{$elty}), incx::Integer, DY::Union(Ptr{$elty},DenseArray{$elty}), incy::Integer)
result = Array($elty, 1)
ccall(($(blasfunc(fname)), libblas), $elty,
ccall(($(blasfunc(fname)), libblas), Void,
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
n, DX, incx, DY, incy, result)
result[1]
Expand All @@ -136,7 +136,7 @@ for (fname, elty) in ((:cblas_zdotu_sub,:Complex128),
# DOUBLE PRECISION DX(*),DY(*)
function dotu(n::Integer, DX::Union(Ptr{$elty},DenseArray{$elty}), incx::Integer, DY::Union(Ptr{$elty},DenseArray{$elty}), incy::Integer)
result = Array($elty, 1)
ccall(($(blasfunc(fname)), libblas), $elty,
ccall(($(blasfunc(fname)), libblas), Void,
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
n, DX, incx, DY, incy, result)
result[1]
Expand Down
5 changes: 5 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ function function_module(f, types)
end
m[1].func.code.module
end

#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[edit] ❌

Copy link
Member Author

Choose a reason for hiding this comment

The 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)
3 changes: 0 additions & 3 deletions base/special/erf.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@unix_only if WORD_SIZE == 64
# TODO: complex return only on 64-bit for now
for f in (:erf, :erfc, :erfcx, :erfi, :Dawson)
fname = (f === :Dawson) ? :dawson : f
@eval begin
Expand All @@ -8,7 +6,6 @@ for f in (:erf, :erfc, :erfcx, :erfi, :Dawson)
($fname)(z::Complex) = ($fname)(Complex128(z))
end
end
end
for f in (:erfcx, :erfi, :Dawson)
fname = (f === :Dawson) ? :dawson : f
@eval begin
Expand Down
7 changes: 3 additions & 4 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Makefile for Sphinx documentation
#

default: helpdb.jl html

# You can set these variables from the command line.
SPHINXOPTS =
Expand All @@ -17,10 +18,8 @@ JULIA_ENV = $(JULIAHOME)/deps/julia-env
ACTIVATE = $(JULIA_ENV)/bin/activate
SPHINX_BUILD = $(JULIA_ENV)/bin/sphinx-build

$(JULIA_ENV):
$(ACTIVATE):
$(MAKE) -C $(JULIAHOME)/deps install-virtualenv

$(ACTIVATE): $(JULIA_ENV)
touch -c $@

$(SPHINX_BUILD): $(ACTIVATE) requirements.txt
Expand Down
Loading