Summary: The issue is on ARM builds for Windows UWP. For the C# P/Invoke API wrapper, any native method that returns the YogaValue struct throws the AccessViolationException. The issue is not with structs in general, as returning the YogaSize / YGSize struct works fine. The issue seems to be limited to structs that have an enum member. I tried a number of things to resolve the issue without changing the underlying native API for Windows. I read the ARM documentation and saw reference to variable enum sizes based on the number of enum members, so I tried to use a number of different UnmanagedType values in a [MarsalAs()] attribute on the enum member of the C# struct declaration. What ultimately worked was to return a pointer to the location of the struct, and use the System.Runtime.InteropServices.PtrToStructure API to read the struct data from that pointer. I added a few new macros that will return the struct address on Windows only, other builds are not affected. Note, I have not tested the impact of this ch Closes https://github.com/facebook/yoga/pull/459 Reviewed By: emilsjolander Differential Revision: D4652278 Pulled By: splhack fbshipit-source-id: bf7ada4da1781e3f813b3ba331974b7bded476d9
62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
#define YG_EXTERN_C_BEGIN extern "C" {
|
|
#define YG_EXTERN_C_END }
|
|
#else
|
|
#define YG_EXTERN_C_BEGIN
|
|
#define YG_EXTERN_C_END
|
|
#endif
|
|
|
|
#ifdef _WINDLL
|
|
#define WIN_EXPORT __declspec(dllexport)
|
|
#else
|
|
#define WIN_EXPORT
|
|
#endif
|
|
|
|
#ifdef WINARMDLL
|
|
#define WIN_STRUCT(type) type*
|
|
#define WIN_STRUCT_REF(value) &value
|
|
#else
|
|
#define WIN_STRUCT(type) type
|
|
#define WIN_STRUCT_REF(value) value
|
|
#endif
|
|
|
|
#ifndef FB_ASSERTIONS_ENABLED
|
|
#define FB_ASSERTIONS_ENABLED 1
|
|
#endif
|
|
|
|
#if FB_ASSERTIONS_ENABLED
|
|
#define YG_ABORT() abort()
|
|
#else
|
|
#define YG_ABORT()
|
|
#endif
|
|
|
|
#ifndef YG_ASSERT
|
|
#define YG_ASSERT(X, message) \
|
|
if (!(X)) { \
|
|
YGLog(YGLogLevelError, "%s", message); \
|
|
YG_ABORT(); \
|
|
}
|
|
#endif
|
|
|
|
#ifdef NS_ENUM
|
|
// Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a
|
|
// enum).
|
|
// Therefor when linking the Yoga C library into obj-c the header is a missmatch for the Yoga ABI.
|
|
#define YG_ENUM_BEGIN(name) NS_ENUM(int, name)
|
|
#define YG_ENUM_END(name)
|
|
#else
|
|
#define YG_ENUM_BEGIN(name) enum name
|
|
#define YG_ENUM_END(name) name
|
|
#endif
|