Order of interfaces generated for %interface macros

Ensure the order of interfaces generated in proxy interfaces for the
%interface family of macros is the same as that parsed from the bases in C++.
This commit is contained in:
William S Fulton 2022-07-20 19:46:08 +01:00
parent ccccd6fc1f
commit 7592722e39
5 changed files with 23 additions and 25 deletions

View File

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress) Version 4.1.0 (in progress)
=========================== ===========================
2022-07-20: wsfulton
[C#, Java] Ensure the order of interfaces generated in proxy interfaces for the
%interface family of macros is the same as that parsed from the bases in C++.
2022-07-20: jicks, Ingener74, olly 2022-07-20: jicks, Ingener74, olly
#422 [Python] Fix mishandling of a Python class inheriting from #422 [Python] Fix mishandling of a Python class inheriting from
multiple SWIG-wrapped director classes. multiple SWIG-wrapped director classes.

View File

@ -46,17 +46,17 @@ public class multiple_inheritance_interfaces_runme {
checkBaseAndInterfaces(IC.class, true, "", new String[] {"IA", "IB"}); checkBaseAndInterfaces(IC.class, true, "", new String[] {"IA", "IB"});
checkBaseAndInterfaces(A.class, false, "", new String[] {"IA"}); checkBaseAndInterfaces(A.class, false, "", new String[] {"IA"});
checkBaseAndInterfaces(B.class, false, "", new String[] {"IB"}); checkBaseAndInterfaces(B.class, false, "", new String[] {"IB"});
checkBaseAndInterfaces(C.class, false, "", new String[] {"IA", "IB", "IC"}); checkBaseAndInterfaces(C.class, false, "", new String[] {"IC", "IA", "IB"});
checkBaseAndInterfaces(D.class, false, "", new String[] {"IA", "IB", "IC"}); checkBaseAndInterfaces(D.class, false, "", new String[] {"IC", "IA", "IB"});
checkBaseAndInterfaces(E.class, false, "D", new String[] {}); checkBaseAndInterfaces(E.class, false, "D", new String[] {});
checkBaseAndInterfaces(IJ.class, true, "", new String[] {}); checkBaseAndInterfaces(IJ.class, true, "", new String[] {});
checkBaseAndInterfaces(IK.class, true, "", new String[] {"IJ"}); checkBaseAndInterfaces(IK.class, true, "", new String[] {"IJ"});
checkBaseAndInterfaces(IL.class, true, "", new String[] {"IK"}); checkBaseAndInterfaces(IL.class, true, "", new String[] {"IK"});
checkBaseAndInterfaces(J.class, false, "", new String[] {"IJ"}); checkBaseAndInterfaces(J.class, false, "", new String[] {"IJ"});
checkBaseAndInterfaces(K.class, false, "", new String[] {"IJ", "IK"}); checkBaseAndInterfaces(K.class, false, "", new String[] {"IK", "IJ"});
checkBaseAndInterfaces(L.class, false, "", new String[] {"IJ", "IK", "IL"}); checkBaseAndInterfaces(L.class, false, "", new String[] {"IL", "IK", "IJ"});
checkBaseAndInterfaces(M.class, false, "", new String[] {"IJ", "IK", "IL"}); checkBaseAndInterfaces(M.class, false, "", new String[] {"IL", "IK", "IJ"});
checkBaseAndInterfaces(P.class, false, "", new String[] {}); checkBaseAndInterfaces(P.class, false, "", new String[] {});
checkBaseAndInterfaces(IQ.class, true, "", new String[] {}); checkBaseAndInterfaces(IQ.class, true, "", new String[] {});

View File

@ -1699,10 +1699,9 @@ public:
* addInterfaceNameAndUpcasts() * addInterfaceNameAndUpcasts()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, SwigType *c_classname) { void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, List *base_list, SwigType *c_classname) {
List *keys = Keys(base_list); for (Iterator it = First(base_list); it.item; it = Next(it)) {
for (Iterator it = First(keys); it.item; it = Next(it)) { Node *base = it.item;
Node *base = Getattr(base_list, it.item);
SwigType *c_baseclassname = Getattr(base, "name"); SwigType *c_baseclassname = Getattr(base, "name");
String *interface_name = Getattr(base, "interface:name"); String *interface_name = Getattr(base, "interface:name");
if (Len(interface_list)) if (Len(interface_list))
@ -1729,7 +1728,6 @@ public:
Delete(cptr_method_name); Delete(cptr_method_name);
Delete(interface_code); Delete(interface_code);
} }
Delete(keys);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -1825,7 +1823,7 @@ public:
} }
} }
} }
Hash *interface_bases = Getattr(n, "interface:bases"); List *interface_bases = Getattr(n, "interface:bases");
if (interface_bases) if (interface_bases)
addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname); addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname);

View File

@ -29,10 +29,9 @@ static bool interface_feature_enabled = false;
static List *collect_interface_methods(Node *n) { static List *collect_interface_methods(Node *n) {
List *methods = NewList(); List *methods = NewList();
if (Hash *bases = Getattr(n, "interface:bases")) { if (List *bases = Getattr(n, "interface:bases")) {
List *keys = Keys(bases); for (Iterator base = First(bases); base.item; base = Next(base)) {
for (Iterator base = First(keys); base.item; base = Next(base)) { Node *cls = base.item;
Node *cls = Getattr(bases, base.item);
if (cls == n) if (cls == n)
continue; continue;
for (Node *child = firstChild(cls); child; child = nextSibling(child)) { for (Node *child = firstChild(cls); child; child = nextSibling(child)) {
@ -55,7 +54,6 @@ static List *collect_interface_methods(Node *n) {
} }
} }
} }
Delete(keys);
} }
return methods; return methods;
} }
@ -64,11 +62,11 @@ static List *collect_interface_methods(Node *n) {
* collect_interface_bases * collect_interface_bases
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static void collect_interface_bases(Hash *bases, Node *n) { static void collect_interface_bases(List *bases, Node *n) {
if (GetFlag(n, "feature:interface")) { if (GetFlag(n, "feature:interface")) {
String *name = Getattr(n, "interface:name"); String *name = Getattr(n, "interface:name");
if (!Getattr(bases, name)) if (!Getattr(bases, name))
Setattr(bases, name, n); Append(bases, n);
} }
if (List *baselist = Getattr(n, "bases")) { if (List *baselist = Getattr(n, "bases")) {
@ -106,7 +104,7 @@ static void collect_interface_base_classes(Node *n) {
} }
} }
Hash *interface_bases = NewHash(); List *interface_bases = NewList();
collect_interface_bases(interface_bases, n); collect_interface_bases(interface_bases, n);
if (Len(interface_bases) == 0) if (Len(interface_bases) == 0)
Delete(interface_bases); Delete(interface_bases);

View File

@ -1840,10 +1840,9 @@ public:
* addInterfaceNameAndUpcasts() * addInterfaceNameAndUpcasts()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, Hash *base_list, SwigType *c_classname) { void addInterfaceNameAndUpcasts(SwigType *smart, String *interface_list, String *interface_upcasts, List *base_list, SwigType *c_classname) {
List *keys = Keys(base_list); for (Iterator it = First(base_list); it.item; it = Next(it)) {
for (Iterator it = First(keys); it.item; it = Next(it)) { Node *base = it.item;
Node *base = Getattr(base_list, it.item);
SwigType *c_baseclassname = Getattr(base, "name"); SwigType *c_baseclassname = Getattr(base, "name");
String *interface_name = Getattr(base, "interface:name"); String *interface_name = Getattr(base, "interface:name");
if (Len(interface_list)) if (Len(interface_list))
@ -1870,7 +1869,6 @@ public:
Delete(cptr_method_name); Delete(cptr_method_name);
Delete(interface_code); Delete(interface_code);
} }
Delete(keys);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -1976,7 +1974,7 @@ public:
} }
} }
Hash *interface_bases = Getattr(n, "interface:bases"); List *interface_bases = Getattr(n, "interface:bases");
if (interface_bases) if (interface_bases)
addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname); addInterfaceNameAndUpcasts(smart, interface_list, interface_upcasts, interface_bases, c_classname);