Skip to content

Commit 12cbf4a

Browse files
linter: fix readability-use-concise-preprocessor-directives issues
Signed-off-by: Martin Olivier <martin.olivier@live.fr>
1 parent 0a8573a commit 12cbf4a

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

example/lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <string>
22
#include <vector>
33

4-
#if defined(_WIN32)
4+
#ifdef _WIN32
55
#define LIB_EXPORT __declspec(dllexport)
66
#else
77
#define LIB_EXPORT

include/dylib.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <filesystem>
2323
#endif
2424

25-
#if defined(_WIN32)
25+
#ifdef _WIN32
2626
#ifndef WIN32_LEAN_AND_MEAN
2727
#define WIN32_LEAN_AND_MEAN
2828
#define DYLIB_UNDEFINE_LEAN_AND_MEAN
@@ -42,7 +42,7 @@
4242
#endif
4343
#endif
4444

45-
#if defined(_WIN32)
45+
#ifdef _WIN32
4646
#define DYLIB_WIN_MAC_OTHER(win_def, mac_def, other_def) win_def
4747
#define DYLIB_WIN_OTHER(win_def, other_def) win_def
4848
#elif defined(__APPLE__)
@@ -224,14 +224,14 @@ class library {
224224
#pragma GCC diagnostic push
225225
#pragma GCC diagnostic ignored "-Wcast-function-type"
226226
#endif
227-
#if defined __clang__
227+
#ifdef __clang__
228228
#if __has_warning("-Wcast-function-type-mismatch")
229229
#pragma clang diagnostic push
230230
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
231231
#endif
232232
#endif
233233
return reinterpret_cast<T *>(get_symbol(symbol_name));
234-
#if defined __clang__
234+
#ifdef __clang__
235235
#if __has_warning("-Wcast-function-type-mismatch")
236236
#pragma clang diagnostic pop
237237
#endif
@@ -286,7 +286,7 @@ class library {
286286

287287
protected:
288288
native_handle_type m_handle{nullptr};
289-
#if defined(__APPLE__)
289+
#ifdef __APPLE__
290290
int m_fd{-1};
291291
#endif
292292
};

src/dylib.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* This library is released under MIT license
88
*/
99

10-
#if !defined(_WIN32)
10+
#ifndef _WIN32
1111
#include <dlfcn.h>
1212
#include <unistd.h>
1313
#endif
@@ -44,31 +44,31 @@ std::vector<internal_symbol_info> get_symbols(native_handle_type handle, int fd)
4444
std::string demangle_symbol(const char *symbol);
4545

4646
static native_handle_type open_lib(const char *path) noexcept {
47-
#if defined(_WIN32)
47+
#ifdef _WIN32
4848
return LoadLibraryA(path);
4949
#else
5050
return dlopen(path, RTLD_NOW | RTLD_LOCAL);
5151
#endif
5252
}
5353

5454
static native_symbol_type locate_symbol(native_handle_type lib, const char *name) noexcept {
55-
#if defined(_WIN32)
55+
#ifdef _WIN32
5656
return GetProcAddress(lib, name);
5757
#else
5858
return dlsym(lib, name);
5959
#endif
6060
}
6161

6262
static void close_lib(native_handle_type lib) noexcept {
63-
#if defined(_WIN32)
63+
#ifdef _WIN32
6464
FreeLibrary(lib);
6565
#else
6666
dlclose(lib);
6767
#endif
6868
}
6969

7070
static std::string get_error_description() noexcept {
71-
#if defined(_WIN32)
71+
#ifdef _WIN32
7272
WORD lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
7373
char description[512];
7474
DWORD error_code;
@@ -91,15 +91,15 @@ static std::string get_error_description() noexcept {
9191

9292
library::library(library &&other) noexcept {
9393
std::swap(m_handle, other.m_handle);
94-
#if defined(__APPLE__)
94+
#ifdef __APPLE__
9595
std::swap(m_fd, other.m_fd);
9696
#endif
9797
}
9898

9999
library &library::operator=(library &&other) noexcept {
100100
if (this != &other) {
101101
std::swap(m_handle, other.m_handle);
102-
#if defined(__APPLE__)
102+
#ifdef __APPLE__
103103
std::swap(m_fd, other.m_fd);
104104
#endif
105105
}
@@ -116,7 +116,7 @@ library::library(const char *lib_path, dylib::decorations decorations) {
116116

117117
lib = lib_path;
118118

119-
#if defined(_WIN32)
119+
#ifdef _WIN32
120120
while (lib.find('\\') != std::string::npos)
121121
lib.replace(lib.find('\\'), 1, "/");
122122
#endif
@@ -139,7 +139,7 @@ library::library(const char *lib_path, dylib::decorations decorations) {
139139
if (!m_handle)
140140
throw load_error("Could not load library '" + lib + "':\n" + get_error_description());
141141

142-
#if defined(__APPLE__)
142+
#ifdef __APPLE__
143143
m_fd = open(lib.c_str(), O_RDONLY);
144144
if (m_fd < 0)
145145
throw load_error("Could not open file '" + lib + "':\n" + strerror(errno));
@@ -157,7 +157,7 @@ library::library(const std::filesystem::path &lib_path, decorations decorations)
157157
library::~library() {
158158
if (m_handle)
159159
close_lib(m_handle);
160-
#if defined(__APPLE__)
160+
#ifdef __APPLE__
161161
if (m_fd > -1)
162162
close(m_fd);
163163
#endif

src/symbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void add_symbol(std::vector<internal_symbol_info> &result, const char *sy
5858
}
5959

6060
/************************ Windows ************************/
61-
#if defined(_WIN32)
61+
#ifdef _WIN32
6262

6363
#include <windows.h>
6464
#include <tchar.h>

tests/tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "dylib.hpp"
1717
#include "lib.hpp"
1818

19-
#if !defined(_WIN32)
19+
#ifndef _WIN32
2020
#include <dlfcn.h>
2121
#endif
2222

@@ -85,14 +85,14 @@ TEST(library, handle_management) {
8585
#pragma GCC diagnostic push
8686
#pragma GCC diagnostic ignored "-Wcast-function-type"
8787
#endif
88-
#if defined __clang__
88+
#ifdef __clang__
8989
#if __has_warning("-Wcast-function-type-mismatch")
9090
#pragma clang diagnostic push
9191
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
9292
#endif
9393
#endif
9494
auto res = ((double (*)(double, double))(sym))(10, 10);
95-
#if defined __clang__
95+
#ifdef __clang__
9696
#if __has_warning("-Wcast-function-type-mismatch")
9797
#pragma clang diagnostic pop
9898
#endif

0 commit comments

Comments
 (0)