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

ska-sa / spead2 / 5991859444

27 Aug 2023 02:11PM UTC coverage: 75.031% (+0.03%) from 75.0%
5991859444

Pull #239

github

bmerry
Remove an unneeded lambda capture

It was giving a warning on Clang and hence failing CI.
Pull Request #239: Update to require at least C++17

152 of 152 new or added lines in 39 files covered. (100.0%)

5427 of 7233 relevant lines covered (75.03%)

52706.23 hits per line

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

0.0
/src/common_loader_utils.cpp
1
/* Copyright 2019-2020 National Research Foundation (SARAO)
2
 *
3
 * This program is free software: you can redistribute it and/or modify it under
4
 * the terms of the GNU Lesser General Public License as published by the Free
5
 * Software Foundation, either version 3 of the License, or (at your option) any
6
 * later version.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
11
 * details.
12
 *
13
 * You should have received a copy of the GNU Lesser General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16

17
/**
18
 * @file
19
 */
20

21
#ifndef _GNU_SOURCE
22
# define _GNU_SOURCE
23
#endif
24
#include <spead2/common_features.h>
25

26
#include <string>
27
#include <exception>
28
#include <system_error>
29
#include <dlfcn.h>
30
#include <spead2/common_loader_utils.h>
31
#include <spead2/common_logging.h>
32

33
using namespace std::literals;
34

35
namespace spead2
36
{
37

38
const char *loader_error_category::name() const noexcept
×
39
{
40
    return "loader";
×
41
}
42

43
std::string loader_error_category::message(int condition) const
×
44
{
45
    switch (loader_error(condition))
×
46
    {
47
        case loader_error::LIBRARY_ERROR:
×
48
            return "library could not be loaded";
×
49
        case loader_error::SYMBOL_ERROR:
×
50
            return "symbol could not be loaded";
×
51
        case loader_error::NO_INIT:
×
52
            return "loader_init was not called";
×
53
        default:
×
54
            return "unknown error";  // unreachable
×
55
    }
56
}
57

58
std::error_condition loader_error_category::default_error_condition(int condition) const noexcept
×
59
{
60
    switch (loader_error(condition))
×
61
    {
62
        case loader_error::LIBRARY_ERROR:
×
63
            return std::errc::no_such_file_or_directory;
×
64
        case loader_error::SYMBOL_ERROR:
×
65
            return std::errc::not_supported;
×
66
        case loader_error::NO_INIT:
×
67
            return std::errc::state_not_recoverable;
×
68
        default:
×
69
            return std::errc::not_supported;  // unreachable
×
70
    }
71
}
72

73
std::error_category &loader_category()
×
74
{
75
    static loader_error_category category;
×
76
    return category;
×
77
}
78

79
dl_handle::dl_handle(const char *filename)
×
80
{
81
    handle = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
×
82
    if (!handle)
×
83
    {
84
        std::error_code code((int) loader_error::LIBRARY_ERROR, loader_category());
×
85
        throw std::system_error(code, "Could not open "s + filename + ": " + dlerror());
×
86
    }
87
}
×
88

89
dl_handle::~dl_handle()
×
90
{
91
    if (handle)
×
92
    {
93
        int ret = dlclose(handle);
×
94
        if (ret != 0)
×
95
            log_warning("dlclose failed: %s", dlerror());
×
96
    }
97
}
×
98

99
void *dl_handle::release()
×
100
{
101
    void *ret = handle;
×
102
    handle = nullptr;
×
103
    return ret;
×
104
}
105

106
void *dl_handle::sym(const char *name)
×
107
{
108
    void *ret = dlsym(handle, name);
×
109
    if (!ret)
×
110
    {
111
        std::error_code code((int) loader_error::SYMBOL_ERROR, loader_category());
×
112
        throw std::system_error(code, "Symbol "s + name + " not found: " + dlerror());
×
113
    }
114
    return ret;
×
115
}
116

117
}  // namespace spead2
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