From acbe8ed49ce7ea9cb6bc9310557b433d646174bb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 23 Sep 2022 18:24:06 +0100 Subject: [PATCH] Runtime tables deterministic ordering (1) Many parts of the runtime tables are alphabetically sorted before for the generated code. This patch sorts the elements within the swig_cast_info lists. Order now is first the elements without a converter then the elements with a converter. For example: new: static swig_cast_info _swigc__p_Foo[] = { {&_swigt__p_Foo, 0, 0, 0}, {&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0}, {&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0}, {0, 0, 0, 0}}; old: static swig_cast_info _swigc__p_Foo[] = { {&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0}, {&_swigt__p_Foo, 0, 0, 0}, {&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0}, {0, 0, 0, 0}}; Previously the order was roughly in the order that the types were parsed, but not necessarily due to the use of internal hash tables which do not have an ordering guarantee. --- Source/Swig/typesys.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 464b89f28..860eafbcf 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -2170,8 +2170,10 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) { Hash *lthash; Iterator ltiter; Hash *nthash; + String *cast_temp_conv; cast_temp = NewStringEmpty(); + cast_temp_conv = NewStringEmpty(); Printv(types, "static swig_type_info _swigt_", ki.item, " = {", NIL); Append(table_list, ki.item); @@ -2227,13 +2229,14 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) { Printf(types, "\"%s\", \"%s\", 0, 0, (void*)%s, 0};\n", ki.item, nt, cd); el = SwigType_equivalent_mangle(ki.item, 0, 0); + SortList(el, SwigType_compare_mangled); for (ei = First(el); ei.item; ei = Next(ei)) { String *ckey; String *conv; ckey = NewStringf("%s+%s", ei.item, ki.item); conv = Getattr(conversions, ckey); if (conv) { - Printf(cast_temp, " {&_swigt_%s, %s, 0, 0},", ei.item, conv); + Printf(cast_temp_conv, " {&_swigt_%s, %s, 0, 0},", ei.item, conv); } else { Printf(cast_temp, " {&_swigt_%s, 0, 0, 0},", ei.item); } @@ -2250,7 +2253,8 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) { } } Delete(el); - Printf(cast, "%s{0, 0, 0, 0}};\n", cast_temp); + Printf(cast, "%s%s{0, 0, 0, 0}};\n", cast_temp, cast_temp_conv); + Delete(cast_temp_conv); Delete(cast_temp); Delete(nt); Delete(rt);