Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile: avoid min macro pollution #942

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/time.h>

#include <ccan/build_assert/build_assert.h>
#include <ccan/ccan/minmax/minmax.h>
#include <ccan/endian/endian.h>

#include "ioctl.h"
Expand Down Expand Up @@ -503,7 +504,7 @@ static int read_ana_chunk(int fd, enum nvme_log_ana_lsp lsp, bool rae,
}

while (*read < to_read) {
__u32 len = min(log_end - *read, NVME_LOG_PAGE_PDU_SIZE);
__u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE);
int ret;

ret = nvme_get_log_ana(fd, lsp, rae, *read - log, len, *read);
Expand Down
3 changes: 2 additions & 1 deletion src/nvme/mi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <unistd.h>

#include <ccan/array_size/array_size.h>
#include <ccan/ccan/minmax/minmax.h>
#include <ccan/endian/endian.h>

#include "log.h"
Expand Down Expand Up @@ -1021,7 +1022,7 @@ static int read_ana_chunk(nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool r
}

while (*read < to_read) {
__u32 len = min(log_end - *read, NVME_LOG_PAGE_PDU_SIZE);
__u32 len = min_t(__u32, log_end - *read, NVME_LOG_PAGE_PDU_SIZE);
int ret;

ret = nvme_mi_admin_get_log_ana(ctrl, lsp, rae,
Expand Down
1 change: 1 addition & 0 deletions src/nvme/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <netdb.h>
#include <unistd.h>

#include <ccan/ccan/minmax/minmax.h>
#include <ccan/endian/endian.h>

#include "cleanup.h"
Expand Down
2 changes: 0 additions & 2 deletions src/nvme/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ char *kv_keymatch(const char *kv, const char *key);
*/
char *startswith(const char *s, const char *prefix);

#define min(x, y) ((x) > (y) ? (y) : (x))

#define __round_mask(val, mult) ((__typeof__(val))((mult)-1))

/**
Expand Down
11 changes: 11 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ if cxx_available
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)

test('cpp-dump', cpp)

misc = executable(
'test-misc',
['misc.cc'],
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)
test('cpp-misc', misc)

endif

register = executable(
Expand Down
22 changes: 22 additions & 0 deletions test/misc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
* This file is part of libnvme.
* Copyright (c) 2025 Daniel Wagner, SUSE LLC
*/

#include <algorithm>
#include <libnvme.h>

static int minmax_test()
{
/*
* Ensure libnvme doesn't spoil the namespace, e.g. by exposing a
* min/max macro.
*/
return !(std::min(1, 2) == 1 && std::max(1, 2) == 2);
}

int main(int argc, char *argv[])
{
return minmax_test();
}