1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT license.
3
4 // SEALNet
5 #include "seal/c/memorypoolhandle.h"
6 #include "seal/c/utilities.h"
7
8 // SEAL
9 #include "seal/memorymanager.h"
10
11 using namespace std;
12 using namespace seal;
13 using namespace seal::c;
14
MemoryPoolHandle_Create1(void ** handle)15 SEAL_C_FUNC MemoryPoolHandle_Create1(void **handle)
16 {
17 IfNullRet(handle, E_POINTER);
18
19 MemoryPoolHandle *handleptr = new MemoryPoolHandle();
20 *handle = handleptr;
21 return S_OK;
22 }
23
MemoryPoolHandle_Create2(void * otherptr,void ** handle)24 SEAL_C_FUNC MemoryPoolHandle_Create2(void *otherptr, void **handle)
25 {
26 MemoryPoolHandle *other = FromVoid<MemoryPoolHandle>(otherptr);
27 IfNullRet(other, E_POINTER);
28 IfNullRet(handle, E_POINTER);
29
30 MemoryPoolHandle *handleptr = new MemoryPoolHandle(*other);
31 *handle = handleptr;
32 return S_OK;
33 }
34
MemoryPoolHandle_Destroy(void * thisptr)35 SEAL_C_FUNC MemoryPoolHandle_Destroy(void *thisptr)
36 {
37 MemoryPoolHandle *handle = FromVoid<MemoryPoolHandle>(thisptr);
38 IfNullRet(handle, E_POINTER);
39
40 delete handle;
41 return S_OK;
42 }
43
MemoryPoolHandle_Set(void * thisptr,void * assignptr)44 SEAL_C_FUNC MemoryPoolHandle_Set(void *thisptr, void *assignptr)
45 {
46 MemoryPoolHandle *handle = FromVoid<MemoryPoolHandle>(thisptr);
47 IfNullRet(handle, E_POINTER);
48 MemoryPoolHandle *assign = FromVoid<MemoryPoolHandle>(assignptr);
49 IfNullRet(assign, E_POINTER);
50
51 *handle = *assign;
52 return S_OK;
53 }
54
MemoryPoolHandle_Global(void ** handle)55 SEAL_C_FUNC MemoryPoolHandle_Global(void **handle)
56 {
57 IfNullRet(handle, E_POINTER);
58
59 MemoryPoolHandle global = MemoryPoolHandle::Global();
60 MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(global));
61 *handle = handleptr;
62 return S_OK;
63 }
64
MemoryPoolHandle_ThreadLocal(void ** handle)65 SEAL_C_FUNC MemoryPoolHandle_ThreadLocal(void **handle)
66 {
67 IfNullRet(handle, E_POINTER);
68
69 MemoryPoolHandle threadlocal = MemoryPoolHandle::ThreadLocal();
70 MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(threadlocal));
71 *handle = handleptr;
72 return S_OK;
73 }
74
MemoryPoolHandle_New(bool clear_on_destruction,void ** handle)75 SEAL_C_FUNC MemoryPoolHandle_New(bool clear_on_destruction, void **handle)
76 {
77 IfNullRet(handle, E_POINTER);
78
79 MemoryPoolHandle newhandle = MemoryPoolHandle::New(clear_on_destruction);
80 MemoryPoolHandle *handleptr = new MemoryPoolHandle(move(newhandle));
81 *handle = handleptr;
82 return S_OK;
83 }
84
MemoryPoolHandle_PoolCount(void * thisptr,uint64_t * count)85 SEAL_C_FUNC MemoryPoolHandle_PoolCount(void *thisptr, uint64_t *count)
86 {
87 MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
88 IfNullRet(pool, E_POINTER);
89 IfNullRet(count, E_POINTER);
90
91 *count = pool->pool_count();
92 return S_OK;
93 }
94
MemoryPoolHandle_AllocByteCount(void * thisptr,uint64_t * count)95 SEAL_C_FUNC MemoryPoolHandle_AllocByteCount(void *thisptr, uint64_t *count)
96 {
97 MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
98 IfNullRet(pool, E_POINTER);
99 IfNullRet(count, E_POINTER);
100
101 *count = pool->alloc_byte_count();
102 return S_OK;
103 }
104
MemoryPoolHandle_UseCount(void * thisptr,long * count)105 SEAL_C_FUNC MemoryPoolHandle_UseCount(void *thisptr, long *count)
106 {
107 MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
108 IfNullRet(pool, E_POINTER);
109 IfNullRet(count, E_POINTER);
110
111 *count = pool->use_count();
112 return S_OK;
113 }
114
MemoryPoolHandle_IsInitialized(void * thisptr,bool * result)115 SEAL_C_FUNC MemoryPoolHandle_IsInitialized(void *thisptr, bool *result)
116 {
117 MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
118 IfNullRet(pool, E_POINTER);
119 IfNullRet(result, E_POINTER);
120
121 *result = (bool)(*pool);
122 return S_OK;
123 }
124
MemoryPoolHandle_Equals(void * thisptr,void * otherptr,bool * result)125 SEAL_C_FUNC MemoryPoolHandle_Equals(void *thisptr, void *otherptr, bool *result)
126 {
127 MemoryPoolHandle *pool = FromVoid<MemoryPoolHandle>(thisptr);
128 IfNullRet(pool, E_POINTER);
129 MemoryPoolHandle *other = FromVoid<MemoryPoolHandle>(otherptr);
130 IfNullRet(other, E_POINTER);
131 IfNullRet(result, E_POINTER);
132
133 *result = (*pool == *other);
134 return S_OK;
135 }
136