This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -1884,7 +1884,10 @@ class TypeInfo_Struct : TypeInfo
18841884 if (! p1 || ! p2)
18851885 return false ;
18861886 else if (xopEquals)
1887- return (* xopEquals)(p1, p2);
1887+ {
1888+ const dg = _memberFunc(p2, xopEquals);
1889+ return dg.xopEquals(p1);
1890+ }
18881891 else if (p1 == p2)
18891892 return true ;
18901893 else
@@ -1904,7 +1907,10 @@ class TypeInfo_Struct : TypeInfo
19041907 if (! p2)
19051908 return true ;
19061909 else if (xopCmp)
1907- return (* xopCmp)(p2, p1);
1910+ {
1911+ const dg = _memberFunc(p1, xopCmp);
1912+ return dg.xopCmp(p2);
1913+ }
19081914 else
19091915 // BUG: relies on the GC not moving objects
19101916 return memcmp (p1, p2, initializer().length);
@@ -2008,6 +2014,28 @@ class TypeInfo_Struct : TypeInfo
20082014 TypeInfo m_arg2;
20092015 }
20102016 immutable (void )* m_RTInfo; // data for precise GC
2017+
2018+ // The xopEquals and xopCmp members are function pointers to member
2019+ // functions, which is not guaranteed to share the same ABI, as it is not
2020+ // known whether the `this` parameter is the first or second argument.
2021+ // This wrapper is to convert it to a delegate which will always pass the
2022+ // `this` parameter in the correct way.
2023+ private struct _memberFunc
2024+ {
2025+ union
2026+ {
2027+ struct // delegate
2028+ {
2029+ const void * ptr;
2030+ const void * funcptr;
2031+ }
2032+ @safe pure nothrow
2033+ {
2034+ bool delegate (in void * ) xopEquals;
2035+ int delegate (in void * ) xopCmp;
2036+ }
2037+ }
2038+ }
20112039}
20122040
20132041@system unittest
You can’t perform that action at this time.
0 commit comments