Skip to content

Commit c677d81

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Breaking: Fix callback const-correctness (react#1369)
Summary: Pull Request resolved: react#1369 X-link: react/react-native#39370 This fixes const-correctness of callbacks (e.g. not letting a logger function modify nodes during layout). This helps us to continue to fix const-correctness issues inside of Yoga. This change is breaking to the public API, since it requires a change in signature passed to Yoga. Changelog: [Internal] Differential Revision: https://internalfb.com/D49130714 fbshipit-source-id: 880f3debf7dfea41ff6580a9579b5cd3ed77841f
1 parent f62b2d2 commit c677d81

22 files changed

Lines changed: 111 additions & 111 deletions

benchmark/YGBenchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void __printBenchmarkResult(
7676
}
7777

7878
static YGSize _measure(
79-
YGNodeRef node,
79+
YGNodeConstRef node,
8080
float width,
8181
YGMeasureMode widthMode,
8282
float height,

java/jni/YGJNIVanilla.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace facebook::yoga;
2727
using namespace facebook::yoga::vanillajni;
2828

2929
static inline ScopedLocalRef<jobject> YGNodeJobject(
30-
YGNodeRef node,
30+
YGNodeConstRef node,
3131
void* layoutContext) {
3232
return reinterpret_cast<PtrJNodeMapVanilla*>(layoutContext)->ref(node);
3333
}
@@ -138,8 +138,8 @@ static jlong jni_YGNodeNewWithConfigJNI(
138138
}
139139

140140
static int YGJNILogFunc(
141-
const YGConfigRef config,
142-
const YGNodeRef /*node*/,
141+
const YGConfigConstRef config,
142+
const YGNodeConstRef /*node*/,
143143
YGLogLevel level,
144144
void* /*layoutContext*/,
145145
const char* format,
@@ -639,7 +639,7 @@ static void jni_YGNodeStyleSetBorderJNI(
639639
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
640640
}
641641

642-
static void YGTransferLayoutDirection(YGNodeRef node, jobject javaNode) {
642+
static void YGTransferLayoutDirection(YGNodeConstRef node, jobject javaNode) {
643643
// Don't change this field name without changing the name of the field in
644644
// Database.java
645645
JNIEnv* env = getCurrentEnv();
@@ -655,7 +655,7 @@ static void YGTransferLayoutDirection(YGNodeRef node, jobject javaNode) {
655655
}
656656

657657
static YGSize YGJNIMeasureFunc(
658-
YGNodeRef node,
658+
YGNodeConstRef node,
659659
float width,
660660
YGMeasureMode widthMode,
661661
float height,
@@ -700,7 +700,7 @@ static void jni_YGNodeSetHasMeasureFuncJNI(
700700
}
701701

702702
static float YGJNIBaselineFunc(
703-
YGNodeRef node,
703+
YGNodeConstRef node,
704704
float width,
705705
float height,
706706
void* layoutContext) {

javascript/src/Node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "./Config.h"
1616

1717
static YGSize globalMeasureFunc(
18-
YGNodeRef nodeRef,
18+
YGNodeConstRef nodeRef,
1919
float width,
2020
YGMeasureMode widthMode,
2121
float height,
@@ -29,7 +29,7 @@ static YGSize globalMeasureFunc(
2929
return ygSize;
3030
}
3131

32-
static void globalDirtiedFunc(YGNodeRef nodeRef) {
32+
static void globalDirtiedFunc(YGNodeConstRef nodeRef) {
3333
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
3434

3535
node.callDirtiedFunc();

tests/EventsTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
249249
TEST_F(EventTest, measure_functions_get_wrapped) {
250250
auto root = YGNodeNew();
251251
YGNodeSetMeasureFunc(
252-
root, [](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
252+
root, [](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode) {
253253
return YGSize{};
254254
});
255255

@@ -267,7 +267,8 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
267267
auto child = YGNodeNew();
268268
YGNodeInsertChild(root, child, 0);
269269

270-
YGNodeSetBaselineFunc(child, [](YGNodeRef, float, float) { return 0.0f; });
270+
YGNodeSetBaselineFunc(
271+
child, [](YGNodeConstRef, float, float) { return 0.0f; });
271272
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
272273
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
273274

tests/YGAlignBaselineTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#include <yoga/Yoga.h>
1010

1111
static float _baselineFunc(
12-
YGNodeRef /*node*/,
12+
YGNodeConstRef /*node*/,
1313
const float /*width*/,
1414
const float height) {
1515
return height / 2;
1616
}
1717

1818
static YGSize _measure1(
19-
YGNodeRef /*node*/,
19+
YGNodeConstRef /*node*/,
2020
float /*width*/,
2121
YGMeasureMode /*widthMode*/,
2222
float /*height*/,
@@ -25,7 +25,7 @@ static YGSize _measure1(
2525
}
2626

2727
static YGSize _measure2(
28-
YGNodeRef /*node*/,
28+
YGNodeConstRef /*node*/,
2929
float /*width*/,
3030
YGMeasureMode /*widthMode*/,
3131
float /*height*/,

tests/YGAspectRatioTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <yoga/Yoga.h>
1010

1111
static YGSize _measure(
12-
YGNodeRef /*node*/,
12+
YGNodeConstRef /*node*/,
1313
float width,
1414
YGMeasureMode widthMode,
1515
float height,

tests/YGBaselineFuncTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <yoga/Yoga.h>
1010

1111
static float _baseline(
12-
YGNodeRef node,
12+
YGNodeConstRef node,
1313
const float /*width*/,
1414
const float /*height*/) {
1515
float* baseline = (float*) YGNodeGetContext(node);

tests/YGDirtiedTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using namespace facebook;
1313

14-
static void _dirtied(YGNodeRef node) {
14+
static void _dirtied(YGNodeConstRef node) {
1515
int* dirtiedCount = (int*) YGNodeGetContext(node);
1616
(*dirtiedCount)++;
1717
}

tests/YGDirtyMarkingTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
147147
YGConfigRef newConfig = YGConfigNew();
148148
YGConfigSetLogger(
149149
newConfig,
150-
[](const YGConfigRef, const YGNodeRef, YGLogLevel, const char*, va_list) {
150+
[](YGConfigConstRef, YGNodeConstRef, YGLogLevel, const char*, va_list) {
151151
return 0;
152152
});
153153
YGNodeSetConfig(root_child0, newConfig);

tests/YGLoggerTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace {
1515
char writeBuffer[4096];
1616
int _unmanagedLogger(
17-
const YGConfigRef /*config*/,
18-
const YGNodeRef /*node*/,
17+
const YGConfigConstRef /*config*/,
18+
const YGNodeConstRef /*node*/,
1919
YGLogLevel /*level*/,
2020
const char* format,
2121
va_list args) {

0 commit comments

Comments
 (0)