Skip to content

Commit

Permalink
Fix mapping for optional proxies in MATLAB (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jul 26, 2024
1 parent 8570095 commit 39e2ce4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
19 changes: 4 additions & 15 deletions cpp/src/slice2matlab/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ namespace
}
else if (m->optional())
{
return "IceInternal.UnsetI.Instance";
return isProxyType(m->type()) ? "[]" : "IceInternal.UnsetI.Instance";
}
else
{
Expand Down Expand Up @@ -1948,14 +1948,8 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
}
for (const auto& dm : optionalMembers)
{
if (dm->type()->isClassType())
{
unmarshal(out, "is", "@obj.iceSetMember_" + fixIdent(dm->name()), dm->type(), true, dm->tag());
}
else
{
unmarshal(out, "is", "obj." + fixIdent(dm->name()), dm->type(), true, dm->tag());
}
assert(!dm->type()->isClassType());
unmarshal(out, "is", "obj." + fixIdent(dm->name()), dm->type(), true, dm->tag());
}
out << nl << "is.endSlice();";
if (base)
Expand Down Expand Up @@ -4244,12 +4238,7 @@ CodeVisitor::unmarshal(
const string typeS = getAbsolute(prx, "", "Prx");
if (optional)
{
out << nl << "if " << stream << ".readOptional(" << tag << ", " << getOptionalFormat(type) << ")";
out.inc();
out << nl << stream << ".skip(4);";
out << nl << v << " = " << typeS << ".ice_read(" << stream << ");";
out.dec();
out << nl << "end";
out << nl << v << " = " << stream << ".readProxyOpt(" << tag << ", '" << typeS << "');";
}
else
{
Expand Down
10 changes: 7 additions & 3 deletions matlab/lib/+Ice/InputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,16 @@ function skipOptional(obj, format)
r = Ice.ObjectPrx(obj.communicator, '', impl);
end
end
function r = readProxyOpt(obj, tag)
function r = readProxyOpt(obj, tag, cls)
if obj.readOptional(tag, Ice.OptionalFormat.FSize)
obj.skip(4);
r = obj.readProxy();
if nargin == 1
r = obj.readProxy();
else
r = obj.readProxy(cls);
end
else
r = IceInternal.UnsetI.Instance;
r = [];
end
end
function r = readEnum(obj, maxValue)
Expand Down
2 changes: 1 addition & 1 deletion matlab/lib/+Ice/OutputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function writeProxy(obj, v)
end
end
function writeProxyOpt(obj, tag, v)
if v ~= Ice.Unset && obj.writeOptional(tag, Ice.OptionalFormat.FSize)
if ~isempty(v) && obj.writeOptional(tag, Ice.OptionalFormat.FSize)
pos = obj.startSize();
obj.writeProxy(v);
obj.endSize(pos);
Expand Down
24 changes: 12 additions & 12 deletions matlab/test/Ice/optional/AllTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
assert(mo1.g == Ice.Unset);
assert(mo1.h == Ice.Unset);
assert(mo1.i == Ice.Unset);
assert(mo1.j == Ice.Unset);
assert(isempty(mo1.j));
assert(mo1.bs == Ice.Unset);
assert(mo1.ss == Ice.Unset);
assert(mo1.iid == Ice.Unset);
Expand Down Expand Up @@ -132,7 +132,7 @@
assert(mo4.g == Ice.Unset);
assert(mo4.h == Ice.Unset);
assert(mo4.i == Ice.Unset);
% assert(mo4.j == Ice.Unset);
assert(isempty(mo4.j)); % we don't use Unset for optional proxies
assert(mo4.bs == Ice.Unset);
assert(mo4.ss == Ice.Unset);
assert(mo4.iid == Ice.Unset);
Expand Down Expand Up @@ -258,12 +258,12 @@
assert(mo9.g == mo1.g);
assert(mo9.h == Ice.Unset);
assert(mo9.i == mo1.i);
% assert(mo9.j == Ice.Unset);
assert(isempty(mo9.j)); % optional proxy
assert(mo9.bs == Ice.Unset);
assert(isequal(mo9.ss, mo1.ss));
assert(mo9.iid == Ice.Unset);
assert(mo9.sid('test') == 10);
% assert(mo9.fs == Ice.Unset);
assert(isempty(mo9.j)); % optional proxy
assert(mo9.vs == mo1.vs);

assert(mo9.shs == Ice.Unset);
Expand Down Expand Up @@ -504,14 +504,14 @@
[p2, p3] = f.fetchOutputs();
assert(p2.a == p1.a && p3.a == p1.a);

% [p2, p3] = initial.opMyInterfaceProxy(Ice.Unset);
% assert(p2 == Ice.Unset && p3 == Ice.Unset);
% p1 = communicator.stringToProxy('test');
% [p2, p3] = initial.opMyInterfaceProxy(p1);
% assert(p2 == p1 && p3 == p1);
% f = initial.opMyInterfaceProxyAsync(p1);
% [p2, p3] = f.fetchOutputs();
% assert(p2 == p1 && p3 == p1);
[p2, p3] = initial.opMyInterfaceProxy([]);
assert(isempty(p2) && isempty(p3));
p1 = MyInterfacePrx(communicator, 'test');
[p2, p3] = initial.opMyInterfaceProxy(p1);
assert(p2 == p1 && p3 == p1);
f = initial.opMyInterfaceProxyAsync(p1);
[p2, p3] = f.fetchOutputs();
assert(p2 == p1 && p3 == p1);

[p2, p3] = initial.opByteSeq(Ice.Unset);
assert(p2 == Ice.Unset && p3 == Ice.Unset);
Expand Down

0 comments on commit 39e2ce4

Please sign in to comment.