From a52d3e787fba1ce5da5390d288f580604ad29070 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 30 Oct 2024 11:48:58 -0400 Subject: [PATCH] Fix MATLAB --- matlab/src/ImplicitContext.cpp | 6 +++--- matlab/src/ObjectPrx.cpp | 8 ++++---- matlab/src/Util.cpp | 33 ++++++++++++++++++++++++++++++++- matlab/src/Util.h | 2 ++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/matlab/src/ImplicitContext.cpp b/matlab/src/ImplicitContext.cpp index 057b3d1b3ca..441613ab13e 100644 --- a/matlab/src/ImplicitContext.cpp +++ b/matlab/src/ImplicitContext.cpp @@ -21,7 +21,7 @@ extern "C" { try { - return createResultValue(createStringMap(deref(self)->getContext())); + return createResultValue(createContext(deref(self)->getContext())); } catch (...) { @@ -33,8 +33,8 @@ extern "C" { try { - map ctx; - getStringMap(newContext, ctx); + Ice::Context ctx; + getContext(newContext, ctx); deref(self)->setContext(ctx); } catch (...) diff --git a/matlab/src/ObjectPrx.cpp b/matlab/src/ObjectPrx.cpp index b908234b785..f5636063470 100644 --- a/matlab/src/ObjectPrx.cpp +++ b/matlab/src/ObjectPrx.cpp @@ -239,7 +239,7 @@ extern "C" try { Ice::Context ctx; - getStringMap(context, ctx); + getContext(context, ctx); auto ok = restoreProxy(self)->ice_invoke(op, mode, params, v, ctx); mxArray* results = 0; if (!v.empty()) @@ -309,7 +309,7 @@ extern "C" try { Ice::Context ctx; - getStringMap(context, ctx); + getContext(context, ctx); function token = proxy->ice_invokeAsync( op, mode, @@ -400,7 +400,7 @@ extern "C" mxArray* Ice_ObjectPrx_ice_getContext(void* self) { - return createResultValue(createStringMap(restoreProxy(self)->ice_getContext())); + return createResultValue(createContext(restoreProxy(self)->ice_getContext())); } mxArray* Ice_ObjectPrx_ice_context(void* self, void** r, mxArray* c) @@ -408,7 +408,7 @@ extern "C" try { Ice::Context ctx; - getStringMap(c, ctx); + getContext(c, ctx); auto proxy = restoreProxy(self); auto newProxy = proxy->ice_context(ctx); *r = newProxy == proxy ? nullptr : new Ice::ObjectPrx(std::move(newProxy)); diff --git a/matlab/src/Util.cpp b/matlab/src/Util.cpp index a51daab03e0..e6274456c64 100644 --- a/matlab/src/Util.cpp +++ b/matlab/src/Util.cpp @@ -166,8 +166,39 @@ IceMatlab::createStringMap(const map& m) return r; } +// TODO: reduce duplication with code above + +mxArray* +IceMatlab::createContext(const Ice::Context& m) +{ + mxArray* r; + if (m.empty()) + { + mexCallMATLAB(1, &r, 0, 0, "containers.Map"); + } + else + { + mwSize dims[2] = {1, 0}; + dims[1] = static_cast(m.size()); + auto keys = mxCreateCellArray(2, dims); + auto values = mxCreateCellArray(2, dims); + int idx = 0; + for (auto p : m) + { + mxSetCell(keys, idx, createStringFromUTF8(p.first)); + mxSetCell(values, idx, createStringFromUTF8(p.second)); + idx++; + } + mxArray* params[2]; + params[0] = keys; + params[1] = values; + mexCallMATLAB(1, &r, 2, params, "containers.Map"); + } + return r; +} + void -IceMatlab::getStringMap(mxArray* p, map& m) +IceMatlab::getContext(mxArray* p, Ice::Context& m) { if (mxIsEmpty(p)) { diff --git a/matlab/src/Util.h b/matlab/src/Util.h index 4431a641f01..e5fdcc77e24 100644 --- a/matlab/src/Util.h +++ b/matlab/src/Util.h @@ -17,6 +17,8 @@ namespace IceMatlab void getIdentity(mxArray*, Ice::Identity&); mxArray* createStringMap(const std::map&); void getStringMap(mxArray*, std::map&); + mxArray* createContext(const Ice::Context&); + void getContext(mxArray*, Ice::Context&); mxArray* createProtocolVersion(const Ice::ProtocolVersion&); mxArray* createEncodingVersion(const Ice::EncodingVersion&); void getEncodingVersion(mxArray*, Ice::EncodingVersion&);