Skip to content

Commit c67e3d9

Browse files
committed
add UMF_EXPORT for windows dll
1 parent c62f898 commit c67e3d9

File tree

4 files changed

+55
-44
lines changed

4 files changed

+55
-44
lines changed

include/umf/base.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
extern "C" {
1818
#endif
1919

20+
#ifdef _WIN32
21+
#define UMF_EXPORT __declspec(dllexport)
22+
#else
23+
#define UMF_EXPORT
24+
#endif
25+
2026
/// @brief Generates generic 'UMF' API versions
2127
#define UMF_MAKE_VERSION(_major, _minor) \
2228
((_major << 16) | (_minor & 0x0000ffff))

include/umf/memory_pool.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,24 @@ typedef struct umf_memory_pool_ops_t umf_memory_pool_ops_t;
3838
/// @param hPool [out] handle to the newly created memory pool
3939
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
4040
///
41-
umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
42-
umf_memory_provider_handle_t provider, void *params,
43-
umf_memory_pool_handle_t *hPool);
41+
UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
42+
umf_memory_provider_handle_t provider,
43+
void *params,
44+
umf_memory_pool_handle_t *hPool);
4445

4546
///
4647
/// @brief Destroys memory pool.
4748
/// @param hPool handle to the pool
4849
///
49-
void umfPoolDestroy(umf_memory_pool_handle_t hPool);
50+
UMF_EXPORT void umfPoolDestroy(umf_memory_pool_handle_t hPool);
5051

5152
///
5253
/// @brief Allocates \p size bytes of uninitialized storage from \p hPool
5354
/// @param hPool specified memory hPool
5455
/// @param size number of bytes to allocate
5556
/// @return Pointer to the allocated memory.
5657
///
57-
void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
58+
UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
5859

5960
///
6061
/// @brief Allocates \p size bytes of uninitialized storage from the specified \p hPool
@@ -64,8 +65,8 @@ void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
6465
/// @param alignment alignment of the allocation in bytes
6566
/// @return Pointer to the allocated memory
6667
///
67-
void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
68-
size_t alignment);
68+
UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
69+
size_t size, size_t alignment);
6970

7071
///
7172
/// @brief Allocates memory from \p hPool for an array of \p num elements
@@ -76,7 +77,8 @@ void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
7677
/// @param size number of bytes to allocate for each object
7778
/// @return Pointer to the allocated memory
7879
///
79-
void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);
80+
UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
81+
size_t size);
8082

8183
///
8284
/// @brief Reallocates memory from \p hPool
@@ -85,15 +87,17 @@ void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);
8587
/// @param size new size for the memory block in bytes
8688
/// @return Pointer to the allocated memory
8789
///
88-
void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size);
90+
UMF_EXPORT void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr,
91+
size_t size);
8992

9093
///
9194
/// @brief Obtains size of block of memory allocated from the \p hPool for a given \p ptr
9295
/// @param hPool specified memory hPool
9396
/// @param ptr pointer to the allocated memory
9497
/// @return size of the memory block allocated from the \p hPool
9598
///
96-
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
99+
UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
100+
void *ptr);
97101

98102
///
99103
/// @brief Frees the memory space of the specified \p hPool pointed by \p ptr
@@ -103,7 +107,7 @@ size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
103107
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
104108
/// depends on the memory provider used by the \p hPool.
105109
///
106-
umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
110+
UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
107111

108112
///
109113
/// @brief Frees the memory space pointed by ptr if it belongs to UMF pool, does nothing otherwise.
@@ -112,7 +116,7 @@ umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
112116
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
113117
/// depends on the memory provider used by the pool.
114118
///
115-
umf_result_t umfFree(void *ptr);
119+
UMF_EXPORT umf_result_t umfFree(void *ptr);
116120

117121
///
118122
/// @brief Retrieve \p umf_result_t representing the error of the last failed allocation
@@ -132,15 +136,16 @@ umf_result_t umfFree(void *ptr);
132136
/// @return Error code desciribng the failure of the last failed allocation operation.
133137
/// The value is undefined if the previous allocation was successful.
134138
///
135-
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
139+
UMF_EXPORT umf_result_t
140+
umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
136141

137142
///
138143
/// @brief Retrieve memory pool associated with a given ptr. Only memory allocated
139144
/// with the usage of a memory provider is being tracked.
140145
/// @param ptr pointer to memory belonging to a memory pool
141146
/// @return Handle to a memory pool that contains ptr or NULL if pointer does not belong to any UMF pool.
142147
///
143-
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
148+
UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
144149

145150
///
146151
/// @brief Retrieve memory provider associated with a given pool.
@@ -149,8 +154,8 @@ umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
149154
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
150155
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if hProvider is NULL
151156
///
152-
umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool,
153-
umf_memory_provider_handle_t *hProvider);
157+
UMF_EXPORT umf_result_t umfPoolGetMemoryProvider(
158+
umf_memory_pool_handle_t hPool, umf_memory_provider_handle_t *hProvider);
154159

155160
#ifdef __cplusplus
156161
}

include/umf/memory_provider.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
2727
/// @param hProvider [out] pointer to the newly created memory provider
2828
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
2929
///
30-
umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
31-
void *params,
32-
umf_memory_provider_handle_t *hProvider);
30+
UMF_EXPORT umf_result_t
31+
umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, void *params,
32+
umf_memory_provider_handle_t *hProvider);
3333

3434
///
3535
/// @brief Destroys memory provider.
3636
/// @param hProvider handle to the memory provider
3737
///
38-
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
38+
UMF_EXPORT void
39+
umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
3940

4041
///
4142
/// @brief Allocates \p size bytes of uninitialized storage from memory \p hProvider
@@ -46,8 +47,9 @@ void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
4647
/// @param ptr [out] pointer to the allocated memory
4748
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
4849
///
49-
umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
50-
size_t size, size_t alignment, void **ptr);
50+
UMF_EXPORT umf_result_t
51+
umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
52+
size_t alignment, void **ptr);
5153

5254
///
5355
/// @brief Frees the memory space pointed by \p ptr from the memory \p hProvider
@@ -56,8 +58,8 @@ umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
5658
/// @param size size of the allocation
5759
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
5860
///
59-
umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
60-
void *ptr, size_t size);
61+
UMF_EXPORT umf_result_t umfMemoryProviderFree(
62+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
6163

6264
///
6365
/// @brief Retrieve string representation of the underlying provider specific
@@ -83,9 +85,9 @@ umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
8385
/// result in string representation
8486
/// @param pError [out] pointer to an integer where the adapter specific error code will be stored
8587
///
86-
void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
87-
const char **ppMessage,
88-
int32_t *pError);
88+
UMF_EXPORT void
89+
umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
90+
const char **ppMessage, int32_t *pError);
8991

9092
///
9193
/// @brief Retrieve recommended page size for a given allocation size.
@@ -94,9 +96,8 @@ void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
9496
/// @param pageSize [out] pointer to the recommended page size
9597
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
9698
///
97-
umf_result_t
98-
umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
99-
size_t size, size_t *pageSize);
99+
UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
100+
umf_memory_provider_handle_t hProvider, size_t size, size_t *pageSize);
100101

101102
///
102103
/// @brief Retrieve minimum possible page size used by memory region referenced by a given \p ptr
@@ -106,9 +107,8 @@ umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
106107
/// @param pageSize [out] pointer to the minimum possible page size
107108
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
108109
///
109-
umf_result_t
110-
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
111-
void *ptr, size_t *pageSize);
110+
UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
111+
umf_memory_provider_handle_t hProvider, void *ptr, size_t *pageSize);
112112

113113
///
114114
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
@@ -120,8 +120,8 @@ umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
120120
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
121121
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
122122
///
123-
umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
124-
void *ptr, size_t size);
123+
UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
124+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
125125

126126
///
127127
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
@@ -133,15 +133,16 @@ umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
133133
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
134134
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
135135
///
136-
umf_result_t umfMemoryProviderPurgeForce(umf_memory_provider_handle_t hProvider,
137-
void *ptr, size_t size);
136+
UMF_EXPORT umf_result_t umfMemoryProviderPurgeForce(
137+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
138138

139139
///
140140
/// @brief Retrieve name of a given memory \p hProvider.
141141
/// @param hProvider handle to the memory provider
142142
/// @return pointer to a string containing the name of the \p hProvider
143143
///
144-
const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
144+
UMF_EXPORT const char *
145+
umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
145146

146147
///
147148
/// @brief Retrieve handle to the last memory provider that returned status other
@@ -153,7 +154,7 @@ const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
153154
///
154155
/// @return Handle to the memory provider
155156
///
156-
umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
157+
UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
157158

158159
#ifdef __cplusplus
159160
}

src/memory_pool.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
#include <assert.h>
1616
#include <stdlib.h>
1717

18-
umf_result_t umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops,
19-
void *pool_params,
20-
const umf_memory_provider_ops_t *provider_ops,
21-
void *provider_params,
22-
umf_memory_pool_handle_t *hPool) {
18+
UMF_EXPORT umf_result_t
19+
umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops, void *pool_params,
20+
const umf_memory_provider_ops_t *provider_ops,
21+
void *provider_params, umf_memory_pool_handle_t *hPool) {
2322
if (!pool_ops || !provider_ops || !hPool) {
2423
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
2524
}

0 commit comments

Comments
 (0)