Skip to content

Commit b4f5ef4

Browse files
authored
Adds workaround for ARM macs (#403)
1 parent 92740db commit b4f5ef4

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

compile/customWrapper/classHandle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ template<class base> inline std::string convertPtr2String(base *ptr)
6060
return std::to_string(handle);
6161
}
6262

63-
template<class base> inline ClassHandle<base> *convertString2HandlePtr(const char* in)
63+
template<class base> inline ClassHandle<base> *convertString2HandlePtr(const char* in, int size)
6464
{
65-
uint64_t value = stoull(std::string(in));
65+
uint64_t value = stoull(std::string(in).substr(0, size));
6666
ClassHandle<base> *ptr = reinterpret_cast<ClassHandle<base> *>(value);
6767
if (!ptr->isValid())
6868
throw std::invalid_argument("callback handle is not valid");

compile/customWrapper/wrapperMex.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ template<class base> inline mxArray *convertPtr2Mat(base *ptr)
99
return mxCreateString(convertPtr2String<base>(ptr).c_str());
1010
}
1111

12-
template<class base> inline void destroyObject(const char* in)
12+
template<class base> inline void destroyObject(const char* in, size_t size)
1313
{
14-
delete convertString2HandlePtr<base>(in);
14+
delete convertString2HandlePtr<base>(in, size);
1515
mexUnlock();
1616
}
1717

@@ -51,7 +51,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
5151
if (!strcmp("delete", cmd)) {
5252
if (nrhs != 2)
5353
mexErrMsgTxt("Second input for delete command should be a class instance handle.");
54-
destroyObject<CallbackInterface>(getStringFromMxArray(prhs[1], "class instance handle should a row vector char array"));
54+
size_t size = mxGetNumberOfElements(prhs[1]);
55+
destroyObject<CallbackInterface>(getStringFromMxArray(prhs[1], "class instance handle should be a row vector char array"), size);
5556
if (nlhs != 0 || nrhs != 2)
5657
mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
5758
return;

targetFunctions/common/customModelFunctions/callCppFunction.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
coder.cinclude('classHandle.hpp')
99

1010
callbackHandle = coder.opaque('ClassHandle<CallbackInterface> *','NULL');
11-
callbackHandle = coder.ceval('convertString2HandlePtr<CallbackInterface>', pointer);
11+
callbackHandle = coder.ceval('convertString2HandlePtr<CallbackInterface>', pointer, numel(pointer));
1212

1313
callback = coder.opaque('CallbackInterface *','NULL');
1414
callback = coder.ceval('std::mem_fn(&ClassHandle<CallbackInterface>::ptr)', callbackHandle);

0 commit comments

Comments
 (0)