Skip to content

Commit 39e2ce4

Browse files
Fix mapping for optional proxies in MATLAB (#2570)
1 parent 8570095 commit 39e2ce4

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

cpp/src/slice2matlab/Main.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ namespace
577577
}
578578
else if (m->optional())
579579
{
580-
return "IceInternal.UnsetI.Instance";
580+
return isProxyType(m->type()) ? "[]" : "IceInternal.UnsetI.Instance";
581581
}
582582
else
583583
{
@@ -1948,14 +1948,8 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
19481948
}
19491949
for (const auto& dm : optionalMembers)
19501950
{
1951-
if (dm->type()->isClassType())
1952-
{
1953-
unmarshal(out, "is", "@obj.iceSetMember_" + fixIdent(dm->name()), dm->type(), true, dm->tag());
1954-
}
1955-
else
1956-
{
1957-
unmarshal(out, "is", "obj." + fixIdent(dm->name()), dm->type(), true, dm->tag());
1958-
}
1951+
assert(!dm->type()->isClassType());
1952+
unmarshal(out, "is", "obj." + fixIdent(dm->name()), dm->type(), true, dm->tag());
19591953
}
19601954
out << nl << "is.endSlice();";
19611955
if (base)
@@ -4244,12 +4238,7 @@ CodeVisitor::unmarshal(
42444238
const string typeS = getAbsolute(prx, "", "Prx");
42454239
if (optional)
42464240
{
4247-
out << nl << "if " << stream << ".readOptional(" << tag << ", " << getOptionalFormat(type) << ")";
4248-
out.inc();
4249-
out << nl << stream << ".skip(4);";
4250-
out << nl << v << " = " << typeS << ".ice_read(" << stream << ");";
4251-
out.dec();
4252-
out << nl << "end";
4241+
out << nl << v << " = " << stream << ".readProxyOpt(" << tag << ", '" << typeS << "');";
42534242
}
42544243
else
42554244
{

matlab/lib/+Ice/InputStream.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,16 @@ function skipOptional(obj, format)
657657
r = Ice.ObjectPrx(obj.communicator, '', impl);
658658
end
659659
end
660-
function r = readProxyOpt(obj, tag)
660+
function r = readProxyOpt(obj, tag, cls)
661661
if obj.readOptional(tag, Ice.OptionalFormat.FSize)
662662
obj.skip(4);
663-
r = obj.readProxy();
663+
if nargin == 1
664+
r = obj.readProxy();
665+
else
666+
r = obj.readProxy(cls);
667+
end
664668
else
665-
r = IceInternal.UnsetI.Instance;
669+
r = [];
666670
end
667671
end
668672
function r = readEnum(obj, maxValue)

matlab/lib/+Ice/OutputStream.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function writeProxy(obj, v)
300300
end
301301
end
302302
function writeProxyOpt(obj, tag, v)
303-
if v ~= Ice.Unset && obj.writeOptional(tag, Ice.OptionalFormat.FSize)
303+
if ~isempty(v) && obj.writeOptional(tag, Ice.OptionalFormat.FSize)
304304
pos = obj.startSize();
305305
obj.writeProxy(v);
306306
obj.endSize(pos);

matlab/test/Ice/optional/AllTests.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
assert(mo1.g == Ice.Unset);
3232
assert(mo1.h == Ice.Unset);
3333
assert(mo1.i == Ice.Unset);
34-
assert(mo1.j == Ice.Unset);
34+
assert(isempty(mo1.j));
3535
assert(mo1.bs == Ice.Unset);
3636
assert(mo1.ss == Ice.Unset);
3737
assert(mo1.iid == Ice.Unset);
@@ -132,7 +132,7 @@
132132
assert(mo4.g == Ice.Unset);
133133
assert(mo4.h == Ice.Unset);
134134
assert(mo4.i == Ice.Unset);
135-
% assert(mo4.j == Ice.Unset);
135+
assert(isempty(mo4.j)); % we don't use Unset for optional proxies
136136
assert(mo4.bs == Ice.Unset);
137137
assert(mo4.ss == Ice.Unset);
138138
assert(mo4.iid == Ice.Unset);
@@ -258,12 +258,12 @@
258258
assert(mo9.g == mo1.g);
259259
assert(mo9.h == Ice.Unset);
260260
assert(mo9.i == mo1.i);
261-
% assert(mo9.j == Ice.Unset);
261+
assert(isempty(mo9.j)); % optional proxy
262262
assert(mo9.bs == Ice.Unset);
263263
assert(isequal(mo9.ss, mo1.ss));
264264
assert(mo9.iid == Ice.Unset);
265265
assert(mo9.sid('test') == 10);
266-
% assert(mo9.fs == Ice.Unset);
266+
assert(isempty(mo9.j)); % optional proxy
267267
assert(mo9.vs == mo1.vs);
268268

269269
assert(mo9.shs == Ice.Unset);
@@ -504,14 +504,14 @@
504504
[p2, p3] = f.fetchOutputs();
505505
assert(p2.a == p1.a && p3.a == p1.a);
506506

507-
% [p2, p3] = initial.opMyInterfaceProxy(Ice.Unset);
508-
% assert(p2 == Ice.Unset && p3 == Ice.Unset);
509-
% p1 = communicator.stringToProxy('test');
510-
% [p2, p3] = initial.opMyInterfaceProxy(p1);
511-
% assert(p2 == p1 && p3 == p1);
512-
% f = initial.opMyInterfaceProxyAsync(p1);
513-
% [p2, p3] = f.fetchOutputs();
514-
% assert(p2 == p1 && p3 == p1);
507+
[p2, p3] = initial.opMyInterfaceProxy([]);
508+
assert(isempty(p2) && isempty(p3));
509+
p1 = MyInterfacePrx(communicator, 'test');
510+
[p2, p3] = initial.opMyInterfaceProxy(p1);
511+
assert(p2 == p1 && p3 == p1);
512+
f = initial.opMyInterfaceProxyAsync(p1);
513+
[p2, p3] = f.fetchOutputs();
514+
assert(p2 == p1 && p3 == p1);
515515

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

0 commit comments

Comments
 (0)