Skip to content

Commit

Permalink
common: fix clang '-Wcast-function-type-strict' issue
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <[email protected]>
  • Loading branch information
grom72 committed Jan 29, 2025
1 parent e9ddf7d commit 5e9dbc3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
12 changes: 12 additions & 0 deletions src/core/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright 2014-2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */
/*
* Copyright (c) 2016-2020, Microsoft Corporation. All rights reserved.
*
Expand Down Expand Up @@ -331,6 +332,17 @@ char *util_concat_str(const char *s1, const char *s2);
#define SUPPRESS_ARG_8(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_7(__VA_ARGS__)
#define SUPPRESS_ARG_9(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_8(__VA_ARGS__)

/* tell clang to ignore the "cast-function-type-strict" warning */
#if __clang__
#define CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(exp) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wcast-function-type-strict\"") \
exp; \
_Pragma("clang diagnostic pop")
#else
#define CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(exp) exp
#endif

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/libpmem/libpmem.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* libpmem.c -- pmem entry points for libpmem
Expand Down Expand Up @@ -128,6 +129,8 @@ pmem_log_get_threshold(enum pmem_log_threshold threshold,
int
pmem_log_set_function(pmem_log_function *log_function)
{
int ret = core_log_set_function((core_log_function *)log_function);
int ret = EFAULT;
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
ret = core_log_set_function((core_log_function *)log_function));
return core_log_error_translate(ret);
}
17 changes: 9 additions & 8 deletions src/libpmemobj/lane.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* lane.c -- lane implementation
Expand Down Expand Up @@ -215,17 +216,17 @@ lane_init(PMEMobjpool *pop, struct lane *lane, struct lane_layout *layout)
if (lane->internal == NULL)
goto error_internal_new;

lane->external = operation_new((struct ulog *)&layout->external,
LANE_REDO_EXTERNAL_SIZE,
lane_redo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_REDO);
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
lane->external = operation_new((struct ulog *)&layout->external,
LANE_REDO_EXTERNAL_SIZE, lane_redo_extend,
(ulog_free_fn)pfree, &pop->p_ops, LOG_TYPE_REDO));
if (lane->external == NULL)
goto error_external_new;

lane->undo = operation_new((struct ulog *)&layout->undo,
LANE_UNDO_SIZE,
lane_undo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_UNDO);
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
lane->undo = operation_new((struct ulog *)&layout->undo,
LANE_UNDO_SIZE, lane_undo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_UNDO));
if (lane->undo == NULL)
goto error_undo_new;

Expand Down
5 changes: 4 additions & 1 deletion src/libpmemobj/obj_log.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* obj_log.c -- the public interface to control the logging output
Expand Down Expand Up @@ -40,6 +41,8 @@ pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold,
int
pmemobj_log_set_function(pmemobj_log_function *log_function)
{
int ret = core_log_set_function((core_log_function *)log_function);
int ret = EFAULT;
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
ret = core_log_set_function((core_log_function *)log_function));
return core_log_error_translate(ret);
}
5 changes: 4 additions & 1 deletion src/test/ctl_prefault/ctl_prefault.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2023, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* ctl_prefault.c -- tests for the ctl entry points: prefault
Expand Down Expand Up @@ -119,7 +120,9 @@ main(int argc, char *argv[])
int prefault = atoi(argv[2]);
int open = atoi(argv[3]);

prefault_fun(prefault, (fun)pmemobj_ctl_get, (fun)pmemobj_ctl_set);
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
prefault_fun(prefault, (fun)pmemobj_ctl_get,
(fun)pmemobj_ctl_set));
test_obj(path, open);

DONE(NULL);
Expand Down
28 changes: 16 additions & 12 deletions src/test/obj_memops/obj_memops.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2023, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* obj_memops.c -- basic memory operations tests
Expand Down Expand Up @@ -161,10 +162,11 @@ test_same_twice(struct operation_context *ctx, struct test_object *object)
static void
test_redo(PMEMobjpool *pop, struct test_object *object)
{
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
struct operation_context *ctx = NULL;
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
ctx = operation_new((struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_REDO));

/*
* Keep this test first.
Expand Down Expand Up @@ -620,10 +622,11 @@ static void
test_redo_cleanup_same_size(PMEMobjpool *pop, struct test_object *object)
{
#define ULOG_SIZE 1024
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_REDO);
struct operation_context *ctx = NULL;
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
ctx = operation_new((struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_REDO));

int ret = pmalloc(pop, &object->redo.next, ULOG_SIZE, 0, 0);
UT_ASSERTeq(ret, 0);
Expand All @@ -648,10 +651,11 @@ test_redo_cleanup_same_size(PMEMobjpool *pop, struct test_object *object)
static void
test_undo(PMEMobjpool *pop, struct test_object *object)
{
struct operation_context *ctx = operation_new(
(struct ulog *)&object->undo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_UNDO);
struct operation_context *ctx = NULL;
CLANG_IGNORE_CAST_FUNCTION_TYPE_STRICT_WARNING(
ctx = operation_new((struct ulog *)&object->undo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree, &pop->p_ops,
LOG_TYPE_UNDO));

test_undo_small_single_copy(ctx, object);
test_undo_small_single_set(ctx, object);
Expand Down
1 change: 1 addition & 0 deletions utils/style_check.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2023, Intel Corporation
# Copyright 2025, Hewlett Packard Enterprise Development LP
#
# utils/style_check.sh -- common style checking script
#
Expand Down

0 comments on commit 5e9dbc3

Please sign in to comment.