Skip to content

Commit d40a30c

Browse files
Made static_f a function pointer
1 parent cf89be2 commit d40a30c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/include/binfhe/binfhecontext_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::vector<uint64_t> GenerateLUTviaFunctionWrapper(BinFHEContext &self, py::fun
6363
NativeInteger StaticFunction(NativeInteger m, NativeInteger p);
6464

6565
// Define static variables to hold the state
66-
extern py::function static_f;
66+
// extern py::function static_f;
6767

6868
LWECiphertext EvalFuncWrapper(BinFHEContext &self, ConstLWECiphertext &ct, const std::vector<uint64_t> &LUT);
6969
#endif // BINFHE_CRYPTOCONTEXT_BINDINGS_H

src/lib/binfhe/binfhecontext_wrapper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,25 @@ const uint64_t GetLWECiphertextModulusWrapper(LWECiphertext &self)
7777
}
7878

7979
// Define static variables to hold the state
80-
py::function static_f;
80+
py::function* static_f = nullptr;
8181

8282
// Define a static function that uses the static variables
8383
NativeInteger StaticFunction(NativeInteger m, NativeInteger p) {
8484
// Convert the arguments to int
8585
uint64_t m_int = m.ConvertToInt<uint64_t>();
8686
uint64_t p_int = p.ConvertToInt<uint64_t>();
8787
// Call the Python function
88-
py::object result_py = static_f(m_int, p_int);
88+
py::object result_py = (*static_f)(m_int, p_int);
8989
// Convert the result to a NativeInteger
9090
return NativeInteger(py::cast<uint64_t>(result_py));
9191
}
9292

9393
std::vector<uint64_t> GenerateLUTviaFunctionWrapper(BinFHEContext &self, py::function f, uint64_t p)
9494
{
9595
NativeInteger p_native_int = NativeInteger(p);
96-
static_f = f;
96+
static_f = &f;
9797
std::vector<NativeInteger> result = self.GenerateLUTviaFunction(StaticFunction, p_native_int);
98+
static_f = nullptr;
9899
std::vector<uint64_t> result_uint64_t;
99100
// int size_int = static_cast<int>(result.size());
100101
for (const auto& value : result)

0 commit comments

Comments
 (0)