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

JuliaLang / julia / #37846

22 Jul 2024 01:06AM UTC coverage: 86.908% (+0.8%) from 86.098%
#37846

push

local

web-flow
Preserve Git objects from being garbage collected (#55142)

This issue has been discussed
[here](https://discourse.julialang.org/t/preserve-against-garbage-collection-in-libgit2/117095).

In most cases, thanks to the specialization of `Base.unsafe_convert`, it
is sufficient to replace `obj.ptr` by `obj` in `ccalls` to fix the
issue.

In other cases, for example when a pointer to an internal string is
returned, the code has to be wrapped in `GC.https://github.com/preserve
obj begin ... end` block.

All `LibGit2` tests run successfully. I have left a few `FIXME` comments
where I have doubts about the code, notably with `Ptr{Ptr{Cvoid}}`
arguments.

71 of 73 new or added lines in 15 files covered. (97.26%)

560 existing lines in 28 files now uncovered.

76034 of 87488 relevant lines covered (86.91%)

15443040.18 hits per line

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

86.0
/stdlib/Markdown/src/parse/parse.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
"""
4
    MD
5

6
`MD` represents a Markdown document. Note that the `MD` constructor should not generally be
7
used directly, since it constructs the internal data structures. Instead, you can construct
8
`MD` objects using the exported macros [`@md_str`](@ref) and [`@doc_str`](@ref).
9
"""
10
mutable struct MD
11
    content::Vector{Any}
12
    meta::Dict{Symbol, Any}
13

14
    MD(content::AbstractVector, meta::Dict = Dict()) =
33,448✔
15
        new(content, meta)
16
end
17

18
public MD
19

20
MD(xs...) = MD(vcat(xs...))
10,210✔
21

22
function MD(cfg::Config, xs...)
23
    md = MD(xs...)
9,947✔
24
    md.meta[:config] = cfg
9,947✔
25
    return md
9,947✔
26
end
27

28
config(md::MD) = md.meta[:config]::Config
42,955✔
29

30
# Forward some array methods
31

32
Base.push!(md::MD, x) = push!(md.content, x)
26,123✔
33
Base.getindex(md::MD, args...) = md.content[args...]
×
34
Base.setindex!(md::MD, args...) = setindex!(md.content, args...)
×
35
Base.lastindex(md::MD) = lastindex(md.content)
×
36
Base.firstindex(md::MD) = firstindex(md.content)
×
UNCOV
37
Base.length(md::MD) = length(md.content)
×
UNCOV
38
Base.isempty(md::MD) = isempty(md.content)
×
UNCOV
39
Base.copy(md::MD) = MD(copy(md.content), copy(md.meta))
×
40

41
==(a::MD, b::MD) = (html(a) == html(b))
9✔
42

43
# Parser functions:
44
#   md – should be modified appropriately
45
#   return – basically, true if parse was successful
46
#     false uses the next parser in the queue, true
47
#     goes back to the beginning
48
#
49
# Inner parsers:
50
#   return – element to use or nothing
51

52
# Inner parsing
53

54
function parseinline(stream::IO, md::MD, parsers::Vector{Function})
47,689✔
55
    for parser in parsers
47,689✔
56
        inner = parser(stream, md)
54,807✔
57
        inner ≡ nothing || return inner
98,719✔
58
    end
10,895✔
59
end
60

61
function parseinline(stream::IO, md::MD, config::Config)
25,271✔
62
    content = []
25,271✔
63
    buffer = IOBuffer()
25,271✔
64
    while !eof(stream)
1,718,847✔
65
        char = peek(stream, Char)
1,693,576✔
66
        if haskey(config.inner, char) &&
3,387,152✔
67
                (inner = parseinline(stream, md, config.inner[char])) !== nothing
68
            c = String(take!(buffer))
78,956✔
69
            !isempty(c) && push!(content, c)
43,912✔
70
            buffer = IOBuffer()
43,912✔
71
            push!(content, inner)
43,912✔
72
        else
73
            write(buffer, read(stream, Char))
1,649,664✔
74
        end
75
    end
1,693,576✔
76
    c = String(take!(buffer))
43,315✔
77
    !isempty(c) && push!(content, c)
25,271✔
78
    return content
25,271✔
79
end
80

81
parseinline(s::AbstractString, md::MD, c::Config) =
7,596✔
82
    parseinline(IOBuffer(s), md, c)
83

84
parseinline(s, md::MD) = parseinline(s, md, config(md))
25,271✔
85

86
# Block parsing
87

88
function parse(stream::IO, block::MD, config::Config; breaking = false)
109,286✔
89
    skipblank(stream)
54,643✔
90
    eof(stream) && return false
54,643✔
91
    for parser in (breaking ? config.breaking : [config.breaking; config.regular])
44,696✔
92
        parser(stream, block) && return true
344,625✔
93
    end
315,802✔
94
    return false
15,873✔
95
end
96

97
parse(stream::IO, block::MD; breaking = false) =
32,656✔
98
    parse(stream, block, config(block), breaking = breaking)
99

100
function parse(stream::IO; flavor = julia)
19,894✔
101
    isa(flavor, Symbol) && (flavor = flavors[flavor])
80✔
102
    markdown = MD(flavor)
9,947✔
103
    while parse(stream, markdown, flavor) end
38,315✔
104
    return markdown
9,947✔
105
end
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

© 2025 Coveralls, Inc