Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/amplitude_experiment/local/evaluation/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .libevaluation_interop import libevaluation_interop_symbols
from ctypes import cast, c_char_p

def evaluate(rules: str, user: str) -> str:
"""
Expand All @@ -11,4 +12,6 @@ def evaluate(rules: str, user: str) -> str:
Evaluation results with variants in JSON
"""
result = libevaluation_interop_symbols().contents.kotlin.root.evaluate(rules, user)
return str(result, 'utf-8')
py_result = cast(result, c_char_p).value
libevaluation_interop_symbols().contents.DisposeString(result)
return str(py_result, 'utf-8')
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,11 @@ class struct_anon_14(Structure):
'evaluate',
]
struct_anon_14._fields_ = [
('evaluate', CFUNCTYPE(UNCHECKED(c_char_p), String, String)),
# NOTE(bgiori): Changed this line from `UNCHECKED(c_char_p)` to `UNCHECKED(c_void_p)`
# to help fix a memory leak. Strings returned from kotlin/native must
# be freed using the DisposeString function, but c_char_p converts the
# c value making it incompatible with the dispose function.
('evaluate', CFUNCTYPE(UNCHECKED(c_void_p), String, String)),
]

# src/amplitude_experiment/local/evaluation/lib/macosX64/libevaluation_interop_api.h: 100
Expand Down