Fix C# delegate calling conventions
Summary: When using CSS-Layout in a C# UWP project in x86, by default the MSVC compiler defaults the delegate calling convention to cdecl, while .NET assumes that all delegates are declared using stdcall. This causes a problem when invoking such as this error: ``` Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. ``` This PR changes the calling convention in the C# code to reflect cdecl by using the `UnmanagedFunctionPointer` attribute and setting the calling convention to `CallingConvention.Cdecl`. ```csharp [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate CSSSize CSSMeasureFunc( IntPtr context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode); ``` I have updated all calls as well to other functions. I Closes https://github.com/facebook/css-layout/pull/231 Reviewed By: emilsjolander Differential Revision: D4063437 Pulled By: splhack fbshipit-source-id: b1069a1b9f675d2623a64a1c5f3189292a18a646
This commit is contained in:
committed by
Facebook Github Bot
parent
7673de823f
commit
1488f822c3
@@ -8,11 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Facebook.CSSLayout
|
namespace Facebook.CSSLayout
|
||||||
{
|
{
|
||||||
internal static class CSSAssert
|
internal static class CSSAssert
|
||||||
{
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void FailFunc(string message);
|
public delegate void FailFunc(string message);
|
||||||
|
|
||||||
private static bool _assertInitialized;
|
private static bool _assertInitialized;
|
||||||
|
@@ -8,11 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Facebook.CSSLayout
|
namespace Facebook.CSSLayout
|
||||||
{
|
{
|
||||||
internal static class CSSLogger
|
internal static class CSSLogger
|
||||||
{
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void Func(string message);
|
public delegate void Func(string message);
|
||||||
|
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
@@ -8,9 +8,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Facebook.CSSLayout
|
namespace Facebook.CSSLayout
|
||||||
{
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate CSSSize CSSMeasureFunc(
|
public delegate CSSSize CSSMeasureFunc(
|
||||||
IntPtr context,
|
IntPtr context,
|
||||||
float width,
|
float width,
|
||||||
|
@@ -21,10 +21,12 @@ namespace Facebook.CSSLayout
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSInteropSetLogger(CSSLogger.Func func);
|
public static extern void CSSInteropSetLogger(
|
||||||
|
[MarshalAs(UnmanagedType.FunctionPtr)] CSSLogger.Func func);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSAssertSetFailFunc(CSSAssert.FailFunc func);
|
public static extern void CSSAssertSetFailFunc(
|
||||||
|
[MarshalAs(UnmanagedType.FunctionPtr)] CSSAssert.FailFunc func);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern IntPtr CSSNodeNew();
|
public static extern IntPtr CSSNodeNew();
|
||||||
@@ -79,9 +81,12 @@ namespace Facebook.CSSLayout
|
|||||||
public static extern IntPtr CSSNodeGetContext(IntPtr node);
|
public static extern IntPtr CSSNodeGetContext(IntPtr node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSNodeSetMeasureFunc(IntPtr node, CSSMeasureFunc measureFunc);
|
public static extern void CSSNodeSetMeasureFunc(
|
||||||
|
IntPtr node,
|
||||||
|
[MarshalAs(UnmanagedType.FunctionPtr)] CSSMeasureFunc measureFunc);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
|
[return: MarshalAs(UnmanagedType.FunctionPtr)]
|
||||||
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
|
Reference in New Issue
Block a user