Skip to content

Commit ecd0df0

Browse files
splhackfacebook-github-bot
authored andcommitted
Add YGConfigGetInstanceCount
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
1 parent ca6e0b3 commit ecd0df0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ReactCommon/yoga/yoga/Yoga.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ static inline float YGResolveValueMargin(const YGValue *const value, const float
308308
}
309309

310310
int32_t gNodeInstanceCount = 0;
311+
int32_t gConfigInstanceCount = 0;
311312

312313
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
313314
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
@@ -373,15 +374,21 @@ int32_t YGNodeGetInstanceCount(void) {
373374
return gNodeInstanceCount;
374375
}
375376

377+
int32_t YGConfigGetInstanceCount(void) {
378+
return gConfigInstanceCount;
379+
}
380+
376381
YGConfigRef YGConfigNew(void) {
377382
const YGConfigRef config = gYGMalloc(sizeof(YGConfig));
378383
YG_ASSERT(config, "Could not allocate memory for config");
384+
gConfigInstanceCount++;
379385
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
380386
return config;
381387
}
382388

383389
void YGConfigFree(const YGConfigRef config) {
384390
gYGFree(config);
391+
gConfigInstanceCount--;
385392
}
386393

387394
static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
@@ -3426,7 +3433,8 @@ bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
34263433
}
34273434

34283435
void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) {
3429-
YG_ASSERT(gNodeInstanceCount == 0, "Cannot set memory functions: all node must be freed first");
3436+
YG_ASSERT(gNodeInstanceCount == 0 && gConfigInstanceCount == 0,
3437+
"Cannot set memory functions: all node must be freed first");
34303438
YG_ASSERT((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) ||
34313439
(ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL),
34323440
"Cannot set memory functions: functions must be all NULL or Non-NULL");

ReactCommon/yoga/yoga/Yoga.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const floa
228228
// YGConfig
229229
WIN_EXPORT YGConfigRef YGConfigNew(void);
230230
WIN_EXPORT void YGConfigFree(const YGConfigRef config);
231+
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
231232

232233
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
233234
const YGExperimentalFeature feature,

0 commit comments

Comments
 (0)