Skip to content

Commit ebcbc07

Browse files
authored
Merge pull request #1257 from lplewa/const_api
add missing const in external umf api
2 parents a92aa12 + d79e219 commit ebcbc07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+213
-199
lines changed

benchmark/benchmark_umf.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct provider_interface {
7171
}
7272
}
7373

74-
virtual umf_memory_provider_ops_t *
74+
virtual const umf_memory_provider_ops_t *
7575
getOps([[maybe_unused]] ::benchmark::State &state) = 0;
7676

7777
virtual params_ptr getParams([[maybe_unused]] ::benchmark::State &state) {
@@ -129,7 +129,7 @@ struct pool_interface {
129129
provider.TearDown(state);
130130
};
131131

132-
virtual umf_memory_pool_ops_t *
132+
virtual const umf_memory_pool_ops_t *
133133
getOps([[maybe_unused]] ::benchmark::State &state) = 0;
134134

135135
virtual params_ptr getParams([[maybe_unused]] ::benchmark::State &state) {
@@ -189,7 +189,7 @@ struct os_provider : public provider_interface {
189189
deleter};
190190
}
191191

192-
umf_memory_provider_ops_t *
192+
const umf_memory_provider_ops_t *
193193
getOps([[maybe_unused]] ::benchmark::State &state) override {
194194
return umfOsMemoryProviderOps();
195195
}
@@ -245,7 +245,7 @@ struct fixed_provider : public provider_interface {
245245
deleter};
246246
}
247247

248-
umf_memory_provider_ops_t *
248+
const umf_memory_provider_ops_t *
249249
getOps([[maybe_unused]] ::benchmark::State &state) override {
250250
return umfFixedMemoryProviderOps();
251251
}
@@ -254,7 +254,7 @@ struct fixed_provider : public provider_interface {
254254

255255
template <typename Provider>
256256
struct proxy_pool : public pool_interface<Provider> {
257-
umf_memory_pool_ops_t *
257+
const umf_memory_pool_ops_t *
258258
getOps([[maybe_unused]] ::benchmark::State &state) override {
259259
return umfProxyPoolOps();
260260
}
@@ -264,7 +264,7 @@ struct proxy_pool : public pool_interface<Provider> {
264264

265265
template <typename Provider>
266266
struct disjoint_pool : public pool_interface<Provider> {
267-
umf_memory_pool_ops_t *
267+
const umf_memory_pool_ops_t *
268268
getOps([[maybe_unused]] ::benchmark::State &state) override {
269269
return umfDisjointPoolOps();
270270
}
@@ -319,7 +319,7 @@ struct disjoint_pool : public pool_interface<Provider> {
319319
#ifdef UMF_POOL_JEMALLOC_ENABLED
320320
template <typename Provider>
321321
struct jemalloc_pool : public pool_interface<Provider> {
322-
umf_memory_pool_ops_t *
322+
const umf_memory_pool_ops_t *
323323
getOps([[maybe_unused]] ::benchmark::State &state) override {
324324
return umfJemallocPoolOps();
325325
}
@@ -333,7 +333,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
333333
#ifdef UMF_POOL_SCALABLE_ENABLED
334334
template <typename Provider>
335335
struct scalable_pool : public pool_interface<Provider> {
336-
umf_memory_pool_ops_t *
336+
const umf_memory_pool_ops_t *
337337
getOps([[maybe_unused]] ::benchmark::State &state) override {
338338
return umfScalablePoolOps();
339339
}

benchmark/multithread.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ struct bench_params {
2727
size_t alloc_size = 64;
2828
};
2929

30-
using poolCreateExtParams = std::tuple<umf_memory_pool_ops_t *, void *,
31-
umf_memory_provider_ops_t *, void *>;
30+
using poolCreateExtParams =
31+
std::tuple<const umf_memory_pool_ops_t *, const void *,
32+
const umf_memory_provider_ops_t *, const void *>;
3233

3334
static auto poolCreateExtUnique(poolCreateExtParams params) {
3435
umf_memory_pool_handle_t hPool;

examples/basic/basic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main(void) {
2222
// Allocations are made with mmap. The default values of params result
2323
// in an mmap call like this:
2424
// mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)
25-
umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps();
25+
const umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps();
2626
umf_os_memory_provider_params_handle_t params = NULL;
2727
umf_memory_provider_handle_t provider;
2828

@@ -69,7 +69,7 @@ int main(void) {
6969
printf("Freed memory at %p\n", ptr_provider);
7070

7171
// Create a memory pool
72-
umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps();
72+
const umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps();
7373
void *pool_params = NULL;
7474
umf_pool_create_flags_t flags = 0;
7575
umf_memory_pool_handle_t pool;

examples/custom_file_provider/custom_file_provider.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ typedef struct file_params_t {
4040
} file_params_t;
4141

4242
// Function to initialize the file provider
43-
static umf_result_t file_init(void *params, void **provider) {
43+
static umf_result_t file_init(const void *params, void **provider) {
4444
file_provider_t *file_provider = NULL;
4545

4646
if (params == NULL || provider == NULL) {
4747
fprintf(stderr, "Params or provider cannot be null\n");
4848
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
4949
}
5050

51-
file_params_t *file_params = (file_params_t *)params;
51+
const file_params_t *file_params = params;
5252
int page_size = 0;
5353
umf_result_t ret = UMF_RESULT_SUCCESS;
5454

@@ -224,7 +224,7 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size,
224224
}
225225

226226
// Function to get the minimum page size of the file provider
227-
static umf_result_t file_get_min_page_size(void *provider, void *ptr,
227+
static umf_result_t file_get_min_page_size(void *provider, const void *ptr,
228228
size_t *pageSize) {
229229
(void)ptr; // Unused parameter
230230
file_provider_t *file_provider = (file_provider_t *)provider;
@@ -291,7 +291,7 @@ int main(void) {
291291
printf("Freed memory at %p\n", ptr_provider);
292292

293293
// Create a memory pool
294-
umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps();
294+
const umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps();
295295
void *pool_params = NULL;
296296
umf_pool_create_flags_t flags = 0;
297297
umf_memory_pool_handle_t pool;

include/umf/memory_pool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ typedef uint32_t umf_pool_create_flags_t;
5151
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
5252
///
5353
umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
54-
umf_memory_provider_handle_t provider, void *params,
55-
umf_pool_create_flags_t flags,
54+
umf_memory_provider_handle_t provider,
55+
const void *params, umf_pool_create_flags_t flags,
5656
umf_memory_pool_handle_t *hPool);
5757

5858
///
@@ -106,7 +106,7 @@ void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size);
106106
/// @param ptr pointer to the allocated memory
107107
/// @return size of the memory block allocated from the \p hPool
108108
///
109-
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
109+
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, const void *ptr);
110110

111111
///
112112
/// @brief Frees the memory space of the specified \p hPool pointed by \p ptr

include/umf/memory_pool_ops.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
/// @brief Version of the Memory Pool ops structure.
2121
/// NOTE: This is equal to the latest UMF version, in which the ops structure
2222
/// has been modified.
23-
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
23+
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)
2424

2525
///
2626
/// @brief This structure comprises function pointers used by corresponding umfPool*
@@ -42,7 +42,7 @@ typedef struct umf_memory_pool_ops_t {
4242
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
4343
///
4444
umf_result_t (*initialize)(umf_memory_provider_handle_t provider,
45-
void *params, void **pool);
45+
const void *params, void **pool);
4646

4747
///
4848
/// @brief Finalizes memory pool
@@ -94,7 +94,7 @@ typedef struct umf_memory_pool_ops_t {
9494
/// @param ptr pointer to the allocated memory
9595
/// @return size of the memory block allocated from the \p pool
9696
///
97-
size_t (*malloc_usable_size)(void *pool, void *ptr);
97+
size_t (*malloc_usable_size)(void *pool, const void *ptr);
9898

9999
///
100100
/// @brief Frees the memory space of the specified \p pool pointed by \p ptr

include/umf/memory_provider.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -45,7 +45,7 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
4545
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
4646
///
4747
umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
48-
void *params,
48+
const void *params,
4949
umf_memory_provider_handle_t *hProvider);
5050

5151
///
@@ -125,7 +125,7 @@ umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
125125
///
126126
umf_result_t
127127
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
128-
void *ptr, size_t *pageSize);
128+
const void *ptr, size_t *pageSize);
129129

130130
///
131131
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr

include/umf/memory_provider_ops.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
/// @brief Version of the Memory Provider ops structure.
2020
/// NOTE: This is equal to the latest UMF version, in which the ops structure
2121
/// has been modified.
22-
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
22+
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)
2323

2424
///
2525
/// @brief This structure comprises optional function pointers used
@@ -156,7 +156,7 @@ typedef struct umf_memory_provider_ops_t {
156156
/// @param provider returns pointer to the provider
157157
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
158158
///
159-
umf_result_t (*initialize)(void *params, void **provider);
159+
umf_result_t (*initialize)(const void *params, void **provider);
160160

161161
///
162162
/// @brief Finalizes memory provider.
@@ -230,7 +230,7 @@ typedef struct umf_memory_provider_ops_t {
230230
/// @param pageSize [out] pointer to the minimum possible page size
231231
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
232232
///
233-
umf_result_t (*get_min_page_size)(void *provider, void *ptr,
233+
umf_result_t (*get_min_page_size)(void *provider, const void *ptr,
234234
size_t *pageSize);
235235

236236
///

include/umf/pools/pool_disjoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ umf_result_t
106106
umfDisjointPoolParamsSetName(umf_disjoint_pool_params_handle_t hParams,
107107
const char *name);
108108

109-
umf_memory_pool_ops_t *umfDisjointPoolOps(void);
109+
const umf_memory_pool_ops_t *umfDisjointPoolOps(void);
110110

111111
#ifdef __cplusplus
112112
}

include/umf/pools/pool_jemalloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ umf_result_t
4343
umfJemallocPoolParamsSetNumArenas(umf_jemalloc_pool_params_handle_t hParams,
4444
size_t numArenas);
4545

46-
umf_memory_pool_ops_t *umfJemallocPoolOps(void);
46+
const umf_memory_pool_ops_t *umfJemallocPoolOps(void);
4747

4848
#ifdef __cplusplus
4949
}

include/umf/pools/pool_proxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -18,7 +18,7 @@
1818
extern "C" {
1919
#endif
2020

21-
umf_memory_pool_ops_t *umfProxyPoolOps(void);
21+
const umf_memory_pool_ops_t *umfProxyPoolOps(void);
2222

2323
#ifdef __cplusplus
2424
}

include/umf/pools/pool_scalable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ umfScalablePoolParamsSetKeepAllMemory(umf_scalable_pool_params_handle_t hParams,
5555

5656
/// @brief Return \p ops structure containing pointers to the scalable pool implementation.
5757
/// @return pointer to the \p umf_memory_pool_ops_t struct.
58-
umf_memory_pool_ops_t *umfScalablePoolOps(void);
58+
const umf_memory_pool_ops_t *umfScalablePoolOps(void);
5959

6060
#ifdef __cplusplus
6161
}

include/umf/providers/provider_cuda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ umf_result_t umfCUDAMemoryProviderParamsSetMemoryType(
6161
umf_result_t umfCUDAMemoryProviderParamsSetAllocFlags(
6262
umf_cuda_memory_provider_params_handle_t hParams, unsigned int flags);
6363

64-
umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void);
64+
const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void);
6565

6666
#ifdef __cplusplus
6767
}

include/umf/providers/provider_devdax_memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -65,7 +65,7 @@ typedef enum umf_devdax_memory_provider_native_error {
6565
UMF_DEVDAX_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed
6666
} umf_devdax_memory_provider_native_error_t;
6767

68-
umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void);
68+
const umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void);
6969

7070
#ifdef __cplusplus
7171
}

include/umf/providers/provider_file_memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -66,7 +66,7 @@ typedef enum umf_file_memory_provider_native_error {
6666
UMF_FILE_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed
6767
} umf_file_memory_provider_native_error_t;
6868

69-
umf_memory_provider_ops_t *umfFileMemoryProviderOps(void);
69+
const umf_memory_provider_ops_t *umfFileMemoryProviderOps(void);
7070

7171
#ifdef __cplusplus
7272
}

include/umf/providers/provider_fixed_memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -49,7 +49,7 @@ umf_result_t umfFixedMemoryProviderParamsDestroy(
4949

5050
/// @brief Retrieve the operations structure for the Fixed Memory Provider.
5151
/// @return Pointer to the umf_memory_provider_ops_t structure.
52-
umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void);
52+
const umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void);
5353

5454
/// @brief Fixed Memory Provider operation results
5555
typedef enum umf_fixed_memory_provider_native_error {

include/umf/providers/provider_level_zero.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetDeviceOrdinal(
9191
umf_level_zero_memory_provider_params_handle_t hParams,
9292
uint32_t deviceOrdinal);
9393

94-
umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);
94+
const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);
9595

9696
#ifdef __cplusplus
9797
}

include/umf/providers/provider_os_memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ typedef enum umf_os_memory_provider_native_error {
146146
UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED, ///< HWLOC topology discovery failed
147147
} umf_os_memory_provider_native_error_t;
148148

149-
umf_memory_provider_ops_t *umfOsMemoryProviderOps(void);
149+
const umf_memory_provider_ops_t *umfOsMemoryProviderOps(void);
150150

151151
#ifdef __cplusplus
152152
}

src/base_alloc/base_alloc_global.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void *add_metadata_and_align(void *ptr, size_t size, size_t alignment) {
130130
// return original ptr (the one that has been passed to add_metadata_and_align)
131131
// along with total allocation size (needed to find proper alloc class
132132
// in free) and usable size
133-
static void *get_original_alloc(void *user_ptr, size_t *total_size,
133+
static void *get_original_alloc(const void *user_ptr, size_t *total_size,
134134
size_t *usable_size) {
135135
assert(user_ptr);
136136

@@ -233,7 +233,7 @@ void umf_ba_global_free(void *ptr) {
233233
umf_ba_free(BASE_ALLOC.ac[ac_index], ptr);
234234
}
235235

236-
size_t umf_ba_global_malloc_usable_size(void *ptr) {
236+
size_t umf_ba_global_malloc_usable_size(const void *ptr) {
237237
if (!ptr) {
238238
return 0;
239239
}

src/base_alloc/base_alloc_global.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -20,7 +20,7 @@ void *umf_ba_global_alloc(size_t size);
2020
void umf_ba_global_free(void *ptr);
2121
void umf_ba_destroy_global(void);
2222
bool umf_ba_global_is_destroyed(void);
23-
size_t umf_ba_global_malloc_usable_size(void *ptr);
23+
size_t umf_ba_global_malloc_usable_size(const void *ptr);
2424
void *umf_ba_global_aligned_alloc(size_t size, size_t alignment);
2525

2626
#ifdef __cplusplus

0 commit comments

Comments
 (0)