Add YGConfigGetInstanceCount

Summary:
- depends on #496
- For memory leak unit test
- Expose the API for C#
Closes https://github.com/facebook/yoga/pull/497

Reviewed By: emilsjolander

Differential Revision: D4796190

Pulled By: splhack

fbshipit-source-id: 99e4e78e8dfb3d459cf6cd7103ab252c3748e5a6
This commit is contained in:
Kazuki Sakamoto 2017-04-10 14:22:23 -07:00 committed by Facebook Github Bot
parent ca6e0b37cf
commit ecd0df01af
2 changed files with 10 additions and 1 deletions

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) {
@ -3426,7 +3433,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");

View File

@ -228,6 +228,7 @@ WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const floa
// YGConfig
WIN_EXPORT YGConfigRef YGConfigNew(void);
WIN_EXPORT void YGConfigFree(const YGConfigRef config);
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
const YGExperimentalFeature feature,