From 03ed762bd5bad71b66939392b5437cc2216dc7cf Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Thu, 17 Jul 2025 15:26:36 +0100 Subject: [PATCH 1/2] Adds workaround for ARM macs --- compile/customWrapper/classHandle.hpp | 4 ++-- compile/customWrapper/wrapperMex.cpp | 7 ++++--- .../common/customModelFunctions/callCppFunction.m | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compile/customWrapper/classHandle.hpp b/compile/customWrapper/classHandle.hpp index a3728f28c..f83417425 100644 --- a/compile/customWrapper/classHandle.hpp +++ b/compile/customWrapper/classHandle.hpp @@ -60,9 +60,9 @@ template inline std::string convertPtr2String(base *ptr) return std::to_string(handle); } -template inline ClassHandle *convertString2HandlePtr(const char* in) +template inline ClassHandle *convertString2HandlePtr(const char* in, int size) { - uint64_t value = stoull(std::string(in)); + uint64_t value = stoull(std::string(in).substr(0, size)); ClassHandle *ptr = reinterpret_cast *>(value); if (!ptr->isValid()) throw std::invalid_argument("callback handle is not valid"); diff --git a/compile/customWrapper/wrapperMex.cpp b/compile/customWrapper/wrapperMex.cpp index 547406992..f78291e59 100644 --- a/compile/customWrapper/wrapperMex.cpp +++ b/compile/customWrapper/wrapperMex.cpp @@ -9,9 +9,9 @@ template inline mxArray *convertPtr2Mat(base *ptr) return mxCreateString(convertPtr2String(ptr).c_str()); } -template inline void destroyObject(const char* in) +template inline void destroyObject(const char* in, size_t size) { - delete convertString2HandlePtr(in); + delete convertString2HandlePtr(in, size); mexUnlock(); } @@ -51,7 +51,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (!strcmp("delete", cmd)) { if (nrhs != 2) mexErrMsgTxt("Second input for delete command should be a class instance handle."); - destroyObject(getStringFromMxArray(prhs[1], "class instance handle should a row vector char array")); + size_t size = mxGetNumberOfElements(prhs[1]); + destroyObject(getStringFromMxArray(prhs[1], "class instance handle should a row vector char array"), size); if (nlhs != 0 || nrhs != 2) mexWarnMsgTxt("Delete: Unexpected arguments ignored."); return; diff --git a/targetFunctions/common/customModelFunctions/callCppFunction.m b/targetFunctions/common/customModelFunctions/callCppFunction.m index 42d36a8bd..fbefd6e0e 100644 --- a/targetFunctions/common/customModelFunctions/callCppFunction.m +++ b/targetFunctions/common/customModelFunctions/callCppFunction.m @@ -8,7 +8,7 @@ coder.cinclude('classHandle.hpp') callbackHandle = coder.opaque('ClassHandle *','NULL'); - callbackHandle = coder.ceval('convertString2HandlePtr', pointer); + callbackHandle = coder.ceval('convertString2HandlePtr', pointer, numel(pointer)); callback = coder.opaque('CallbackInterface *','NULL'); callback = coder.ceval('std::mem_fn(&ClassHandle::ptr)', callbackHandle); From 6c36896b5120bf048cf48d2689e7b22a8cb6777c Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Wed, 23 Jul 2025 13:44:10 +0100 Subject: [PATCH 2/2] Addresses review comment --- compile/customWrapper/wrapperMex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compile/customWrapper/wrapperMex.cpp b/compile/customWrapper/wrapperMex.cpp index f78291e59..af0f3c76e 100644 --- a/compile/customWrapper/wrapperMex.cpp +++ b/compile/customWrapper/wrapperMex.cpp @@ -52,7 +52,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (nrhs != 2) mexErrMsgTxt("Second input for delete command should be a class instance handle."); size_t size = mxGetNumberOfElements(prhs[1]); - destroyObject(getStringFromMxArray(prhs[1], "class instance handle should a row vector char array"), size); + destroyObject(getStringFromMxArray(prhs[1], "class instance handle should be a row vector char array"), size); if (nlhs != 0 || nrhs != 2) mexWarnMsgTxt("Delete: Unexpected arguments ignored."); return;