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

JuliaLang / julia / #38162

06 Aug 2025 08:25PM UTC coverage: 25.688% (-43.6%) from 69.336%
#38162

push

local

web-flow
fix runtime cglobal builtin function implementation (#59210)

This had failed to be updated for the LazyLibrary changes to codegen.

12976 of 50513 relevant lines covered (25.69%)

676965.51 hits per line

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

70.59
/base/refvalue.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
### Methods for a Ref object that can store a single value of any type
4

5
mutable struct RefValue{T} <: Ref{T}
6
    x::T
7
    RefValue{T}() where {T} = new()
891,408✔
8
    RefValue{T}(x) where {T} = new(x)
2,007,172✔
9
end
10
RefValue(x::T) where {T} = RefValue{T}(x)
10,905✔
11
"""
12
    isassigned(ref::RefValue)::Bool
13

14
Test whether the given [`Ref`](@ref) is associated with a value.
15
This is always true for a [`Ref`](@ref) of a bitstype object.
16
Return `false` if the reference is undefined.
17

18
# Examples
19
```jldoctest
20
julia> ref = Ref{Function}()
21
Base.RefValue{Function}(#undef)
22

23
julia> isassigned(ref)
24
false
25

26
julia> ref[] = (foobar(x) = x)
27
foobar (generic function with 1 method)
28

29
julia> isassigned(ref)
30
true
31

32
julia> isassigned(Ref{Int}())
33
true
34
```
35
"""
36
isassigned(x::RefValue) = isdefined(x, :x)
2,068,684✔
37

38
function unsafe_convert(P::Union{Type{Ptr{T}},Type{Ptr{Cvoid}}}, b::RefValue{T})::P where T
282,217✔
39
    if allocatedinline(T)
335,688✔
40
        p = pointer_from_objref(b)
2,010,118✔
41
    elseif isconcretetype(T) && ismutabletype(T)
9✔
42
        p = pointer_from_objref(b.x)
9✔
43
    else
44
        # If the slot is not leaf type, it could be either immutable or not.
45
        # If it is actually an immutable, then we can't take it's pointer directly
46
        # Instead, explicitly load the pointer from the `RefValue`,
47
        # which also ensures this returns same pointer as the one rooted in the `RefValue` object.
48
        p = atomic_pointerref(Ptr{Ptr{Cvoid}}(pointer_from_objref(b)), :monotonic)
×
49
        if p == C_NULL
×
50
            throw(UndefRefError())
×
51
        end
52
    end
53
    return p
2,010,123✔
54
end
55
function unsafe_convert(::Type{Ptr{Any}}, b::RefValue{Any})::Ptr{Any}
×
56
    return pointer_from_objref(b)
×
57
end
58

59
getindex(b::RefValue) = b.x
2,634,313✔
60
setindex!(b::RefValue, x) = (b.x = x; b)
883,392✔
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