Add YGConfigGetInstanceCount

- For memory leak unit test
- Expose the API for C#
This commit is contained in:
Kazuki Sakamoto
2017-03-29 10:47:17 -07:00
parent 8eed68e34b
commit a50e567c8a
3 changed files with 17 additions and 1 deletions

View File

@@ -138,6 +138,9 @@ namespace Facebook.Yoga
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int YGNodeGetInstanceCount();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int YGConfigGetInstanceCount();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetExperimentalFeatureEnabled(
YGConfigHandle config,

View File

@@ -63,5 +63,10 @@ namespace Facebook.Yoga
Native.YGConfigSetPointScaleFactor(_ygConfig, value);
}
}
public static int GetInstanceCount()
{
return Native.YGConfigGetInstanceCount();
}
}
}

View File

@@ -308,6 +308,7 @@ static inline float YGResolveValueMargin(const YGValue *const value, const float
}
int32_t gNodeInstanceCount = 0;
int32_t gConfigInstanceCount = 0;
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
@@ -373,15 +374,21 @@ int32_t YGNodeGetInstanceCount(void) {
return gNodeInstanceCount;
}
int32_t YGConfigGetInstanceCount(void) {
return gConfigInstanceCount;
}
YGConfigRef YGConfigNew(void) {
const YGConfigRef config = gYGMalloc(sizeof(YGConfig));
YG_ASSERT(config, "Could not allocate memory for config");
gConfigInstanceCount++;
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
return config;
}
void YGConfigFree(const YGConfigRef config) {
gYGFree(config);
gConfigInstanceCount--;
}
static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
@@ -3468,7 +3475,8 @@ bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
}
void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) {
YG_ASSERT(gNodeInstanceCount == 0, "Cannot set memory functions: all node must be freed first");
YG_ASSERT(gNodeInstanceCount == 0 && gConfigInstanceCount == 0,
"Cannot set memory functions: all node must be freed first");
YG_ASSERT((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) ||
(ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL),
"Cannot set memory functions: functions must be all NULL or Non-NULL");