Skip to content

Commit

Permalink
Add YGConfigGetInstanceCount
Browse files Browse the repository at this point in the history
Summary:
- depends on #496
- For memory leak unit test
- Expose the API for C#
Closes facebook/yoga#497

Reviewed By: emilsjolander

Differential Revision: D4796190

Pulled By: splhack

fbshipit-source-id: 99e4e78e8dfb3d459cf6cd7103ab252c3748e5a6
  • Loading branch information
splhack authored and facebook-github-bot committed Apr 10, 2017
1 parent 5d59dc1 commit e70a608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e70a608

Please sign in to comment.