• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / 1285

25 Sep 2025 09:41PM UTC coverage: 70.929% (-6.0%) from 76.923%
1285

push

buildkite

web-flow
Fix gcdx and lcm with mixed signed/unsigned arguments (#59628)

Add `gcdx(a::Signed, b::Unsigned)` and `gcdx(a::Unsigned, b::Signed)`
methods to fix #58025:
```julia
julia> gcdx(UInt16(100), Int8(-101))  # pr
(0x0001, 0xffff, 0xffff)

julia> gcdx(UInt16(100), Int8(-101))  # master, incorrect result
(0x0005, 0xf855, 0x0003)
```

Also add the equivalent methods for `lcm` to fix the systematic
`InexactError` when one argument is a negative `Signed` and the other is
any `Unsigned`:
```julia
julia> lcm(UInt16(100), Int8(-101))  # pr
0x2774

julia> lcm(UInt16(100), Int8(-101))  # master, error
ERROR: InexactError: trunc(UInt16, -101)
Stacktrace:
 [1] throw_inexacterror(func::Symbol, to::Type, val::Int8)
   @ Core ./boot.jl:866
 [2] check_sign_bit
   @ ./boot.jl:872 [inlined]
 [3] toUInt16
   @ ./boot.jl:958 [inlined]
 [4] UInt16
   @ ./boot.jl:1011 [inlined]
 [5] convert
   @ ./number.jl:7 [inlined]
 [6] _promote
   @ ./promotion.jl:379 [inlined]
 [7] promote
   @ ./promotion.jl:404 [inlined]
 [8] lcm(a::UInt16, b::Int8)
   @ Base ./intfuncs.jl:152
 [9] top-level scope
   @ REPL[62]:1
```

Inspired by
https://github.com/JuliaLang/julia/pull/59487#issuecomment-3258209203.
The difference is that the solution proposed in this PR keeps the
current correct result type for inputs such as `(::Int16, ::UInt8)`.

10 of 10 new or added lines in 1 file covered. (100.0%)

4780 existing lines in 122 files now uncovered.

50633 of 71385 relevant lines covered (70.93%)

7422080.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.94
/stdlib/Sockets/src/PipeServer.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
mutable struct PipeServer <: LibuvServer
4
    handle::Ptr{Cvoid}
5
    status::Int
6
    cond::Base.ThreadSynchronizer
UNCOV
7
    function PipeServer(handle::Ptr{Cvoid}, status)
×
UNCOV
8
        p = new(handle,
×
9
                status,
10
                Base.ThreadSynchronizer())
UNCOV
11
        associate_julia_struct(p.handle, p)
×
UNCOV
12
        finalizer(uvfinalize, p)
×
UNCOV
13
        return p
×
14
    end
15
end
16

UNCOV
17
function PipeServer()
×
UNCOV
18
    pipe = PipeServer(Libc.malloc(Base._sizeof_uv_named_pipe), StatusUninit)
×
UNCOV
19
    iolock_begin()
×
UNCOV
20
    err = ccall(:uv_pipe_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cint), eventloop(), pipe.handle, 0)
×
UNCOV
21
    uv_error("failed to create pipe server", err)
×
UNCOV
22
    pipe.status = StatusInit
×
UNCOV
23
    iolock_end()
×
UNCOV
24
    return pipe
×
25
end
26

UNCOV
27
function PipeServer(handle::OS_HANDLE)
×
UNCOV
28
    pipe = PipeServer()
×
UNCOV
29
    return Base.open_pipe!(pipe, handle)
×
30
end
31

UNCOV
32
function Base.open_pipe!(p::PipeServer, handle::OS_HANDLE)
×
UNCOV
33
    iolock_begin()
×
UNCOV
34
    if p.status != StatusInit
×
35
        error("pipe is already in use or has been closed")
×
36
    end
UNCOV
37
    err = ccall(:uv_pipe_open, Int32, (Ptr{Cvoid}, OS_HANDLE), p.handle, handle)
×
UNCOV
38
    uv_error("pipe_open", err)
×
UNCOV
39
    p.status = StatusOpen
×
UNCOV
40
    iolock_end()
×
UNCOV
41
    return p
×
42
end
43

44
## server functions ##
45

46
accept(server::PipeServer) = accept(server, PipeEndpoint())
631✔
47

48
function accept_nonblock(server::PipeServer, client::PipeEndpoint)
UNCOV
49
    iolock_begin()
×
UNCOV
50
    if client.status != StatusInit
×
51
        error("client is already in use or has been closed")
×
52
    end
UNCOV
53
    err = ccall(:uv_accept, Int32, (Ptr{Cvoid}, Ptr{Cvoid}), server.handle, client.handle)
×
UNCOV
54
    if err == 0
×
UNCOV
55
        client.status = StatusOpen
×
56
    end
UNCOV
57
    iolock_end()
×
UNCOV
58
    return err
×
59
end
60

61
function accept_nonblock(server::PipeServer)
×
62
    client = PipeEndpoint()
×
63
    uv_error("accept", accept_nonblock(server, client) != 0)
×
64
    return client
×
65
end
66

67
function bind(server::PipeServer, name::AbstractString)
628✔
68
    iolock_begin()
628✔
69
    @assert server.status == StatusInit
628✔
70
    err = ccall(:uv_pipe_bind, Int32, (Ptr{Cvoid}, Cstring),
628✔
71
                server, name)
72
    if err != 0
628✔
73
        iolock_end()
×
74
        if err != UV_EADDRINUSE && err != UV_EACCES
×
75
            #TODO: this codepath is currently not tested
76
            throw(_UVError("bind", err))
×
77
        else
78
            return false
×
79
        end
80
    end
81
    server.status = StatusOpen
628✔
82
    iolock_end()
628✔
83
    return true
628✔
84
end
85

86
"""
87
    listen(path::AbstractString) -> PipeServer
88

89
Create and listen on a named pipe / UNIX domain socket.
90

91
!!! note
92
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
93
"""
94
function listen(path::AbstractString)
628✔
95
    sock = PipeServer()
628✔
96
    bind(sock, path) || throw(ArgumentError("could not listen on path $path"))
628✔
97
    return listen(sock)
628✔
98
end
99

100
function connect!(sock::PipeEndpoint, path::AbstractString)
631✔
101
    iolock_begin()
631✔
102
    @assert sock.status == StatusInit
631✔
103
    req = Libc.malloc(Base._sizeof_uv_connect)
631✔
104
    uv_req_set_data(req, C_NULL)
631✔
105
    ccall(:uv_pipe_connect, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), req, sock.handle, path,
631✔
106
          @cfunction(uv_connectcb_pipe, Cvoid, (Ptr{Cvoid}, Cint)))
107
    sock.status = StatusConnecting
631✔
108
    iolock_end()
631✔
109
    return sock
631✔
110
end
111

112
"""
113
    connect(path::AbstractString) -> PipeEndpoint
114

115
Connect to the named pipe / UNIX domain socket at `path`.
116

117
!!! note
118
    Path length on Unix is limited to somewhere between 92 and 108 bytes (cf. `man unix`).
119
"""
120
connect(path::AbstractString) = connect(PipeEndpoint(), path)
631✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc