This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree 1 file changed +30
-2
lines changed
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
1884
1884
if (! p1 || ! p2)
1885
1885
return false ;
1886
1886
else if (xopEquals)
1887
- return (* xopEquals)(p1, p2);
1887
+ {
1888
+ const dg = _memberFunc(p2, xopEquals);
1889
+ return dg.xopEquals(p1);
1890
+ }
1888
1891
else if (p1 == p2)
1889
1892
return true ;
1890
1893
else
@@ -1904,7 +1907,10 @@ class TypeInfo_Struct : TypeInfo
1904
1907
if (! p2)
1905
1908
return true ;
1906
1909
else if (xopCmp)
1907
- return (* xopCmp)(p2, p1);
1910
+ {
1911
+ const dg = _memberFunc(p1, xopCmp);
1912
+ return dg.xopCmp(p2);
1913
+ }
1908
1914
else
1909
1915
// BUG: relies on the GC not moving objects
1910
1916
return memcmp (p1, p2, initializer().length);
@@ -2008,6 +2014,28 @@ class TypeInfo_Struct : TypeInfo
2008
2014
TypeInfo m_arg2;
2009
2015
}
2010
2016
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
+ }
2011
2039
}
2012
2040
2013
2041
@system unittest
You can’t perform that action at this time.
0 commit comments