Skip to content
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
2 changes: 1 addition & 1 deletion base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ end

function isopen(x::Union{LibuvStream, LibuvServer})
if x.status == StatusUninit || x.status == StatusInit || x.handle === C_NULL
throw(ArgumentError("$x is not initialized"))
throw(ArgumentError("stream not initialized"))
end
return x.status != StatusClosed
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Sockets/src/PipeServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function connect!(sock::PipeEndpoint, path::AbstractString)
req = Libc.malloc(Base._sizeof_uv_connect)
uv_req_set_data(req, C_NULL)
ccall(:uv_pipe_connect, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), req, sock.handle, path,
@cfunction(uv_connectcb, Cvoid, (Ptr{Cvoid}, Cint)))
@cfunction(uv_connectcb_pipe, Cvoid, (Ptr{Cvoid}, Cint)))
sock.status = StatusConnecting
iolock_end()
return sock
Expand Down
18 changes: 14 additions & 4 deletions stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ function send(sock::UDPSocket, ipaddr::IPAddr, port::Integer, msg)
finally
Base.sigatomic_end()
iolock_begin()
q = ct.queue; q === nothing || Base.list_deletefirst!(q::IntrusiveLinkedList{Task}, ct)
q = ct.queue; q === nothing || Base.list_deletefirst!(q::Base.IntrusiveLinkedList{Task}, ct)
if uv_req_data(uvw) != C_NULL
# uvw is still alive,
# so make sure we won't get spurious notifications later
Expand All @@ -474,9 +474,19 @@ end


#from `connect`
function uv_connectcb(conn::Ptr{Cvoid}, status::Cint)
function uv_connectcb_tcp(conn::Ptr{Cvoid}, status::Cint)
hand = ccall(:jl_uv_connect_handle, Ptr{Cvoid}, (Ptr{Cvoid},), conn)
sock = @handle_as hand LibuvStream
sock = @handle_as hand TCPSocket
connectcb(conn, status, hand, sock)
end

function uv_connectcb_pipe(conn::Ptr{Cvoid}, status::Cint)
hand = ccall(:jl_uv_connect_handle, Ptr{Cvoid}, (Ptr{Cvoid},), conn)
sock = @handle_as hand PipeEndpoint
connectcb(conn, status, hand, sock)
end

function connectcb(conn::Ptr{Cvoid}, status::Cint, hand::Ptr{Cvoid}, sock::LibuvStream)
lock(sock.cond)
try
if status >= 0 # success
Expand Down Expand Up @@ -508,7 +518,7 @@ function connect!(sock::TCPSocket, host::Union{IPv4, IPv6}, port::Integer)
end
host_in = Ref(hton(host.host))
uv_error("connect", ccall(:jl_tcp_connect, Int32, (Ptr{Cvoid}, Ptr{Cvoid}, UInt16, Ptr{Cvoid}, Cint),
sock, host_in, hton(UInt16(port)), @cfunction(uv_connectcb, Cvoid, (Ptr{Cvoid}, Cint)),
sock, host_in, hton(UInt16(port)), @cfunction(uv_connectcb_tcp, Cvoid, (Ptr{Cvoid}, Cint)),
host isa IPv6))
sock.status = StatusConnecting
iolock_end()
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Sockets/src/addrinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function getalladdrinfo(host::String)
finally
Base.sigatomic_end()
iolock_begin()
q = ct.queue; q === nothing || Base.list_deletefirst!(q::IntrusiveLinkedList{Task}, ct)
q = ct.queue; q === nothing || Base.list_deletefirst!(q::Base.IntrusiveLinkedList{Task}, ct)
if uv_req_data(req) != C_NULL
# req is still alive,
# so make sure we don't get spurious notifications later
Expand Down Expand Up @@ -223,7 +223,7 @@ function getnameinfo(address::Union{IPv4, IPv6})
finally
Base.sigatomic_end()
iolock_begin()
q = ct.queue; q === nothing || Base.list_deletefirst!(q::IntrusiveLinkedList{Task}, ct)
q = ct.queue; q === nothing || Base.list_deletefirst!(q::Base.IntrusiveLinkedList{Task}, ct)
if uv_req_data(req) != C_NULL
# req is still alive,
# so make sure we don't get spurious notifications later
Expand Down
12 changes: 9 additions & 3 deletions test/trimming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@ JULIAC_BUILDSCRIPT := $(shell $(JULIA) -e 'print(joinpath(Sys.BINDIR, Base.DATAR

#=============================================================================

release: $(BIN)/hello$(EXE) $(BIN)/basic_jll$(EXE)
release: $(BIN)/hello$(EXE) $(BIN)/trimmability$(EXE) $(BIN)/basic_jll$(EXE)

$(BIN)/hello-o.a: $(SRCDIR)/hello.jl $(JULIAC_BUILDSCRIPT)
$(JULIA) -t 1 -J $(JULIA_LIBDIR)/julia/sys.$(SHLIB_EXT) --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(JULIAC_BUILDSCRIPT) $< --output-exe true

$(BIN)/trimmability-o.a: $(SRCDIR)/trimmability.jl $(JULIAC_BUILDSCRIPT)
$(JULIA) -t 1 -J $(JULIA_LIBDIR)/julia/sys.$(SHLIB_EXT) --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(JULIAC_BUILDSCRIPT) $< --output-exe true

$(BIN)/basic_jll-o.a: $(SRCDIR)/basic_jll.jl $(JULIAC_BUILDSCRIPT)
$(JULIA) -t 1 -J $(JULIA_LIBDIR)/julia/sys.$(SHLIB_EXT) --startup-file=no --history-file=no --project=$(SRCDIR) -e "using Pkg; Pkg.instantiate()"
$(JULIA) -t 1 -J $(JULIA_LIBDIR)/julia/sys.$(SHLIB_EXT) --startup-file=no --history-file=no --project=$(SRCDIR) --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(JULIAC_BUILDSCRIPT) $< --output-exe true

$(BIN)/hello$(EXE): $(BIN)/hello-o.a
$(CC) -o $@ $(WHOLE_ARCHIVE) $< $(NO_WHOLE_ARCHIVE) $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)

$(BIN)/trimmability$(EXE): $(BIN)/trimmability-o.a
$(CC) -o $@ $(WHOLE_ARCHIVE) $< $(NO_WHOLE_ARCHIVE) $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)

$(BIN)/basic_jll$(EXE): $(BIN)/basic_jll-o.a
$(CC) -o $@ $(WHOLE_ARCHIVE) $< $(NO_WHOLE_ARCHIVE) $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)

check: $(BIN)/hello$(EXE) $(BIN)/basic_jll$(EXE)
check: $(BIN)/hello$(EXE) $(BIN)/trimmability$(EXE) $(BIN)/basic_jll$(EXE)
$(JULIA) --depwarn=error $(SRCDIR)/trimming.jl $<

clean:
-rm -f $(BIN)/hello$(EXE) $(BIN)/basic_jll$(EXE) $(BIN)/hello-o.a $(BIN)/basic_jll-o.a
-rm -f $(BIN)/hello$(EXE) $(BIN)/trimmability$(EXE) $(BIN)/basic_jll$(EXE) $(BIN)/hello-o.a $(BIN)/trimmability-o.a $(BIN)/basic_jll-o.a

.PHONY: release clean check

Expand Down
35 changes: 2 additions & 33 deletions test/trimming/hello.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
world::String = "world!"
const str = OncePerProcess{String}() do
return "Hello, " * world
end

abstract type Shape end
struct Square <: Shape
side::Float64
end
struct Circle <: Shape
radius::Float64
end
area(s::Square) = s.side^2
area(c::Circle) = pi*c.radius^2

sum_areas(v::Vector{Shape}) = sum(area, v)
# Test that minimal executable size stays low

function @main(args::Vector{String})::Cint
println(Core.stdout, str())
println(Core.stdout, PROGRAM_FILE)
foreach(x->println(Core.stdout, x), args)

# test map/mapreduce; should work but relies on inlining and other optimizations
# test that you can dispatch to some number of concrete cases
println(Core.stdout, sum_areas(Shape[Circle(1), Square(2)]))

arr = rand(10)
sorted_arr = sort(arr)
tot = sum(sorted_arr)
tot = prod(sorted_arr)
a = any(x -> x > 0, sorted_arr)
b = all(x -> x >= 0, sorted_arr)
c = map(x -> x^2, sorted_arr)
d = mapreduce(x -> x^2, +, sorted_arr)
# e = reduce(xor, rand(Int, 10))
println(Core.stdout, "Hello, world!")
return 0
end
52 changes: 52 additions & 0 deletions test/trimming/trimmability.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Test that various constructs support trimming

using Sockets

world::String = "world!"
const str = OncePerProcess{String}() do
return "Hello, " * world
end

abstract type Shape end
struct Square <: Shape
side::Float64
end
struct Circle <: Shape
radius::Float64
end
area(s::Square) = s.side^2
area(c::Circle) = pi*c.radius^2

sum_areas(v::Vector{Shape}) = sum(area, v)

function @main(args::Vector{String})::Cint
println(Core.stdout, str())
println(Core.stdout, PROGRAM_FILE)
foreach(x->println(Core.stdout, x), args)

# test map/mapreduce; should work but relies on inlining and other optimizations
# test that you can dispatch to some number of concrete cases
println(Core.stdout, sum_areas(Shape[Circle(1), Square(2)]))

arr = rand(10)
sorted_arr = sort(arr)
tot = sum(sorted_arr)
tot = prod(sorted_arr)
a = any(x -> x > 0, sorted_arr)
b = all(x -> x >= 0, sorted_arr)
c = map(x -> x^2, sorted_arr)
d = mapreduce(x -> x^2, +, sorted_arr)
# e = reduce(xor, rand(Int, 10))

try
sock = connect("localhost", 4900)
Copy link
Member

Choose a reason for hiding this comment

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

CI for PR #59442 segfaults on this line:

[1246] signal 11 (1): Segmentation fault
in expression starting at none:0
speccache_eq at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:144 [inlined]
speccache_eq at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:136
jl_smallintset_lookup at /cache/build/tester-demeter6-13/julialang/julia-master/src/smallintset.c:137
jl_specializations_get_linfo_ at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:183
cache_method at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:1585
jl_mt_assoc_by_type at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:1867
jl_lookup_generic_ at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:4168 [inlined]
ijl_apply_generic at /cache/build/tester-demeter6-13/julialang/julia-master/src/gf.c:4194
jl_apply at /cache/build/tester-demeter6-13/julialang/julia-master/src/julia.h:2382 [inlined]
jl_uv_call_close_callback at /cache/build/tester-demeter6-13/julialang/julia-master/src/jl_uv.c:171
jl_uv_closeHandle at /cache/build/tester-demeter6-13/julialang/julia-master/src/jl_uv.c:191 [inlined]
jl_uv_closeHandle at /cache/build/tester-demeter6-13/julialang/julia-master/src/jl_uv.c:175
uv__finish_close at /workspace/srcdir/libuv/src/unix/core.c:342
uv__run_closing_handles at /workspace/srcdir/libuv/src/unix/core.c:356
uv_run at /workspace/srcdir/libuv/src/unix/core.c:445
ijl_process_events at /cache/build/tester-demeter6-13/julialang/julia-master/src/jl_uv.c:397
process_events; at ./libuv.jl:133 [inlined]
wait at ./task.jl:1188
#wait#401 at ./condition.jl:141
wait; at ./condition.jl:136 [inlined]
wait_connected at /cache/build/tester-demeter6-13/julialang/julia-master/usr/share/julia/stdlib/v1.13/Sockets/src/Sockets.jl:539
connect; at /cache/build/tester-demeter6-13/julialang/julia-master/usr/share/julia/stdlib/v1.13/Sockets/src/Sockets.jl:579 [inlined]
connect at /cache/build/tester-demeter6-13/julialang/julia-master/usr/share/julia/stdlib/v1.13/Sockets/src/Sockets.jl:564
main at /cache/build/builder-amdci4-5/julialang/julia-master/test/trimming/trimmability.jl:42
_main at /cache/build/builder-amdci4-5/julialang/julia-master/usr/share/julia/juliac/juliac-buildscript.jl:33
main at /cache/build/builder-amdci4-5/julialang/julia-master/usr/bin/trimmability (unknown line)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x402338) at /workspace/srcdir/glibc-2.17/csu/../sysdeps/x86_64/start.S
Allocations: 1 (Pool: 1; Big: 0); GC: 0

Perhaps this is flaky?

CI link:

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest reverting since this PR broke CI, but there isn't really anything to revert in the source, it is just adding a broken test. Perhaps we can just disable the test until Jeff can fix it?

if isopen(sock)
write(sock, "Hello")
flush(sock)
close(sock)
end
catch
end

return 0
end
7 changes: 5 additions & 2 deletions test/trimming/trimming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ bindir = dirname(ARGS[1])
let exe_suffix = splitext(Base.julia_exename())[2]

hello_exe = joinpath(bindir, "hello" * exe_suffix)
@test readchomp(`$hello_exe arg1 arg2`) == "Hello, world!\n$hello_exe\narg1\narg2\n$(4.0+pi)"
@test filesize(hello_exe) < 2_500_000
@test readchomp(`$hello_exe arg1 arg2`) == "Hello, world!"
@test filesize(hello_exe) < 1_900_000

trimmability_exe = joinpath(bindir, "trimmability" * exe_suffix)
@test readchomp(`$trimmability_exe arg1 arg2`) == "Hello, world!\n$trimmability_exe\narg1\narg2\n$(4.0+pi)"

basic_jll_exe = joinpath(bindir, "basic_jll" * exe_suffix)
lines = split(readchomp(`$basic_jll_exe`), "\n")
Expand Down