Skip to content

Commit

Permalink
Remove Yoga-internal.h (facebook#1452)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#41346


This removes the last remnant from `Yoga-interna.h`, `YGNodeDellocate()`. The API is renamed to `YGNodeFinalize` to give it the explicit purpose of freeing the node from a garbage collector, and made public with that documented contract.

With that, every top-level header is now a public API, and Yoga's JNI bindings do not need to rely on private headers anymore.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D51014340
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Nov 7, 2023
1 parent e6236bf commit 1802d7f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Pod::Spec.new do |spec|
spec.source_files = 'yoga/**/*.{h,cpp}'
spec.header_mappings_dir = 'yoga'

public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGValue}.h'
public_header_files = 'yoga/*.h'
spec.public_header_files = public_header_files

all_header_files = 'yoga/**/*.h'
Expand Down
2 changes: 1 addition & 1 deletion java/com/facebook/yoga/YogaNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class YogaNative {
// YGNode related
static native long jni_YGNodeNewJNI();
static native long jni_YGNodeNewWithConfigJNI(long configPointer);
static native void jni_YGNodeDeallocateJNI(long nativePointer);
static native void jni_YGNodeFinalizeJNI(long nativePointer);
static native void jni_YGNodeResetJNI(long nativePointer);
static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index);
static native void jni_YGNodeSwapChildJNI(long nativePointer, long childPointer, int index);
Expand Down
2 changes: 1 addition & 1 deletion java/com/facebook/yoga/YogaNodeJNIFinalizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void freeNatives() {
if (mNativePointer != 0) {
long nativePointer = mNativePointer;
mNativePointer = 0;
YogaNative.jni_YGNodeDeallocateJNI(nativePointer);
YogaNative.jni_YGNodeFinalizeJNI(nativePointer);
}
}
}
15 changes: 6 additions & 9 deletions java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "YGJNIVanilla.h"
#include <bit>
#include <cstring>
#include <iostream>
#include <memory>
Expand All @@ -16,9 +17,6 @@
#include "common.h"
#include "jni.h"

#include <yoga/Yoga-internal.h>
#include <yoga/bits/BitCast.h>

using namespace facebook;
using namespace facebook::yoga;
using namespace facebook::yoga::vanillajni;
Expand Down Expand Up @@ -190,12 +188,12 @@ static void jni_YGConfigSetLoggerJNI(
}

static void
jni_YGNodeDeallocateJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) {
jni_YGNodeFinalizeJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) {
if (nativePointer == 0) {
return;
}
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodeDeallocate(node);
YGNodeFinalize(node);
}

static void
Expand Down Expand Up @@ -637,9 +635,8 @@ static YGSize YGJNIMeasureFunc(

uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
uint32_t hBits = 0xFFFFFFFF & measureResult;

const float measuredWidth = yoga::bit_cast<float>(wBits);
const float measuredHeight = yoga::bit_cast<float>(hBits);
float measuredWidth = std::bit_cast<float>(wBits);
float measuredHeight = std::bit_cast<float>(hBits);

return YGSize{measuredWidth, measuredHeight};
} else {
Expand Down Expand Up @@ -751,7 +748,7 @@ static JNINativeMethod methods[] = {
(void*)jni_YGConfigSetLoggerJNI},
{"jni_YGNodeNewJNI", "()J", (void*)jni_YGNodeNewJNI},
{"jni_YGNodeNewWithConfigJNI", "(J)J", (void*)jni_YGNodeNewWithConfigJNI},
{"jni_YGNodeDeallocateJNI", "(J)V", (void*)jni_YGNodeDeallocateJNI},
{"jni_YGNodeFinalizeJNI", "(J)V", (void*)jni_YGNodeFinalizeJNI},
{"jni_YGNodeResetJNI", "(J)V", (void*)jni_YGNodeResetJNI},
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*)jni_YGNodeInsertChildJNI},
{"jni_YGNodeSwapChildJNI", "(JJI)V", (void*)jni_YGNodeSwapChildJNI},
Expand Down
1 change: 0 additions & 1 deletion tests/YGRoundingFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#include <gtest/gtest.h>
#include <yoga/Yoga-internal.h>
#include <yoga/Yoga.h>

TEST(YogaTest, rounding_value) {
Expand Down
22 changes: 0 additions & 22 deletions yoga/Yoga-internal.h

This file was deleted.

7 changes: 4 additions & 3 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

#include <yoga/Yoga-internal.h>
#include <yoga/Yoga.h>

#include <yoga/algorithm/Cache.h>
Expand Down Expand Up @@ -136,10 +135,12 @@ void YGNodeFree(const YGNodeRef nodeRef) {
}

node->clearChildren();
YGNodeDeallocate(node);

Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
delete resolveRef(node);
}

void YGNodeDeallocate(const YGNodeRef node) {
void YGNodeFinalize(const YGNodeRef node) {
Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
delete resolveRef(node);
}
Expand Down
6 changes: 6 additions & 0 deletions yoga/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ YG_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
YGNodeRef node,
YGNodeCleanupFunc cleanup);
YG_EXPORT void YGNodeFreeRecursive(YGNodeRef node);

// Frees the Yoga node without disconnecting it from its owner or children.
// Allows garbage collecting Yoga nodes in parallel when the entire tree is
// unrechable.
YG_EXPORT void YGNodeFinalize(YGNodeRef node);

YG_EXPORT void YGNodeReset(YGNodeRef node);

YG_EXPORT void YGNodeInsertChild(YGNodeRef node, YGNodeRef child, size_t index);
Expand Down

0 comments on commit 1802d7f

Please sign in to comment.