Skip to content

Commit be2c14b

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Make the umbrella context nest (#58261)
Summary: Pull Request resolved: #58261 Umbrellas bracketed their includes with a bare `#define`/`#undef` of `RN_UMBRELLA_CONTEXT`. That does not nest: an umbrella reached from inside another umbrella's context cleared it on the way out, so every public header the outer umbrella included afterwards hit `UmbrellaGuard.h`. Switch the bracket to `#pragma push_macro`/`pop_macro` so the inner umbrella restores the outer context instead of clearing it. Nothing nests today, it starts once a for-frameworks header reaches a public module through its umbrella. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D118114589 fbshipit-source-id: beccd3233adcc18ea3a47be9e9eb91d7cc3dc388
1 parent 92cd588 commit be2c14b

12 files changed

Lines changed: 104 additions & 32 deletions

File tree

packages/react-native/ReactCommon/callinvoker/React/CallInvoker.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
// =============================================================================
1919

2020
// Marks that the following headers are pulled in through the umbrella, so their
21-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
22-
#define RN_UMBRELLA_CONTEXT
21+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
22+
// is saved and restored rather than defined and undefined: the scope ends at
23+
// this block, so later *direct* includes in the same TU are still caught, and
24+
// it nests inside an enclosing umbrella rather than disarming it.
25+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
26+
#undef RN_UMBRELLA_CONTEXT
27+
#define RN_UMBRELLA_CONTEXT 1
2328

2429
#include <ReactCommon/CallInvoker.h>
2530
#include <ReactCommon/SchedulerPriority.h>
2631

2732
#undef RN_UMBRELLA_CONTEXT
33+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/cxxstableapi/UmbrellaGuard.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@
2929
// defining RN_STRICT_API.
3030
//
3131
// RN_UMBRELLA_CONTEXT Internal marker (implementation detail; consumers never
32-
// set it). A module umbrella defines it around its own
33-
// `#include`s to signal the blessed inclusion path:
34-
// #define RN_UMBRELLA_CONTEXT
32+
// set it). A module umbrella brackets its own `#include`s
33+
// with it to signal the blessed inclusion path:
34+
// #pragma push_macro("RN_UMBRELLA_CONTEXT")
35+
// #undef RN_UMBRELLA_CONTEXT
36+
// #define RN_UMBRELLA_CONTEXT 1
3537
// #include <react/.../PublicHeaderA.h>
3638
// #include <react/.../PublicHeaderB.h>
3739
// #undef RN_UMBRELLA_CONTEXT
38-
// The `#undef` matters: it keeps the marker scoped to the
39-
// umbrella's includes so later *direct* includes in the
40-
// same translation unit are still caught.
40+
// #pragma pop_macro("RN_UMBRELLA_CONTEXT")
41+
// Saving and restoring, rather than a bare
42+
// `#define`/`#undef` pair, is what makes the scope both
43+
// end at the umbrella -- later *direct* includes in the
44+
// same translation unit are still caught -- and nest: an
45+
// umbrella reached from inside another umbrella's
46+
// context leaves the outer one armed. A bare `#undef`
47+
// would disarm it, and every public header the outer
48+
// umbrella included afterwards would hard-error.
49+
// `scripts/add-cxxstableapi-guard.js --tier=public`
50+
// emits this block; do not hand-write or "simplify" it.
4151
//
4252
// RN_BUILDING Defined by React Native's own build targets so internal
4353
// sources may keep including the fine-grained headers

packages/react-native/ReactCommon/react/debug/React/Debug.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121
// =============================================================================
2222

2323
// Marks that the following headers are pulled in through the umbrella, so their
24-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
25-
#define RN_UMBRELLA_CONTEXT
24+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
25+
// is saved and restored rather than defined and undefined: the scope ends at
26+
// this block, so later *direct* includes in the same TU are still caught, and
27+
// it nests inside an enclosing umbrella rather than disarming it.
28+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
29+
#undef RN_UMBRELLA_CONTEXT
30+
#define RN_UMBRELLA_CONTEXT 1
2631

2732
#include <react/debug/flags.h>
2833
#include <react/debug/react_native_assert.h>
2934
#include <react/debug/react_native_expect.h>
3035

3136
#undef RN_UMBRELLA_CONTEXT
37+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/bridging/React/RendererBridging.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
// =============================================================================
2424

2525
// Marks that the following headers are pulled in through the umbrella, so their
26-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. Scoped to
27-
// this block so later *direct* includes in the same translation unit are still
28-
// caught.
29-
#define RN_UMBRELLA_CONTEXT
26+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
27+
// is saved and restored rather than defined and undefined: the scope ends at
28+
// this block, so later *direct* includes in the same TU are still caught, and
29+
// it nests inside an enclosing umbrella rather than disarming it.
30+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
31+
#undef RN_UMBRELLA_CONTEXT
32+
#define RN_UMBRELLA_CONTEXT 1
3033

3134
#include <react/renderer/bridging/bridging.h>
3235

3336
#undef RN_UMBRELLA_CONTEXT
37+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/image/React/Image.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
// =============================================================================
1919

2020
// Marks that the following headers are pulled in through the umbrella, so their
21-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
22-
#define RN_UMBRELLA_CONTEXT
21+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
22+
// is saved and restored rather than defined and undefined: the scope ends at
23+
// this block, so later *direct* includes in the same TU are still caught, and
24+
// it nests inside an enclosing umbrella rather than disarming it.
25+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
26+
#undef RN_UMBRELLA_CONTEXT
27+
#define RN_UMBRELLA_CONTEXT 1
2328

2429
#include <react/renderer/components/image/ImageComponentDescriptor.h>
2530
#include <react/renderer/components/image/ImageEventEmitter.h>
@@ -29,3 +34,4 @@
2934
#include <react/renderer/components/image/conversions.h>
3035

3136
#undef RN_UMBRELLA_CONTEXT
37+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/modal/React/Modal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
// =============================================================================
2020

2121
// Marks that the following headers are pulled in through the umbrella, so their
22-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
23-
#define RN_UMBRELLA_CONTEXT
22+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
23+
// is saved and restored rather than defined and undefined: the scope ends at
24+
// this block, so later *direct* includes in the same TU are still caught, and
25+
// it nests inside an enclosing umbrella rather than disarming it.
26+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
27+
#undef RN_UMBRELLA_CONTEXT
28+
#define RN_UMBRELLA_CONTEXT 1
2429

2530
#include <react/renderer/components/modal/ModalHostViewComponentDescriptor.h>
2631
#include <react/renderer/components/modal/ModalHostViewShadowNode.h>
2732
#include <react/renderer/components/modal/ModalHostViewState.h>
2833
#include <react/renderer/components/modal/ModalHostViewUtils.h>
2934

3035
#undef RN_UMBRELLA_CONTEXT
36+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/root/React/Root.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
// =============================================================================
2020

2121
// Marks that the following headers are pulled in through the umbrella, so their
22-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
23-
#define RN_UMBRELLA_CONTEXT
22+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
23+
// is saved and restored rather than defined and undefined: the scope ends at
24+
// this block, so later *direct* includes in the same TU are still caught, and
25+
// it nests inside an enclosing umbrella rather than disarming it.
26+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
27+
#undef RN_UMBRELLA_CONTEXT
28+
#define RN_UMBRELLA_CONTEXT 1
2429

2530
#include <react/renderer/components/root/RootComponentDescriptor.h>
2631
#include <react/renderer/components/root/RootProps.h>
2732
#include <react/renderer/components/root/RootShadowNode.h>
2833

2934
#undef RN_UMBRELLA_CONTEXT
35+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/scrollview/React/ScrollView.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@
2020
// =============================================================================
2121

2222
// Marks that the following headers are pulled in through the umbrella, so their
23-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
24-
#define RN_UMBRELLA_CONTEXT
23+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
24+
// is saved and restored rather than defined and undefined: the scope ends at
25+
// this block, so later *direct* includes in the same TU are still caught, and
26+
// it nests inside an enclosing umbrella rather than disarming it.
27+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
28+
#undef RN_UMBRELLA_CONTEXT
29+
#define RN_UMBRELLA_CONTEXT 1
2530

2631
#include <react/renderer/components/scrollview/BaseScrollViewProps.h>
2732
#include <react/renderer/components/scrollview/HostPlatformScrollViewProps.h>
@@ -40,3 +45,4 @@
4045
#endif
4146

4247
#undef RN_UMBRELLA_CONTEXT
48+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/text/React/Text.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919
// =============================================================================
2020

2121
// Marks that the following headers are pulled in through the umbrella, so their
22-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them.
23-
#define RN_UMBRELLA_CONTEXT
22+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
23+
// is saved and restored rather than defined and undefined: the scope ends at
24+
// this block, so later *direct* includes in the same TU are still caught, and
25+
// it nests inside an enclosing umbrella rather than disarming it.
26+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
27+
#undef RN_UMBRELLA_CONTEXT
28+
#define RN_UMBRELLA_CONTEXT 1
2429

2530
#include <react/renderer/components/text/BaseParagraphComponentDescriptor.h>
2631
#include <react/renderer/components/text/BaseParagraphProps.h>
@@ -51,3 +56,4 @@
5156
#endif
5257

5358
#undef RN_UMBRELLA_CONTEXT
59+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

packages/react-native/ReactCommon/react/renderer/components/view/React/View.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
// =============================================================================
2020

2121
// Marks that the following headers are pulled in through the umbrella, so their
22-
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. Scoped to
23-
// this block so later *direct* includes in the same TU are still caught.
24-
#define RN_UMBRELLA_CONTEXT
22+
// shared guard (<react/cxxstableapi/UmbrellaGuard.h>) accepts them. The marker
23+
// is saved and restored rather than defined and undefined: the scope ends at
24+
// this block, so later *direct* includes in the same TU are still caught, and
25+
// it nests inside an enclosing umbrella rather than disarming it.
26+
#pragma push_macro("RN_UMBRELLA_CONTEXT")
27+
#undef RN_UMBRELLA_CONTEXT
28+
#define RN_UMBRELLA_CONTEXT 1
2529

2630
#if defined(__APPLE__)
2731
#include <TargetConditionals.h>
@@ -76,3 +80,4 @@
7680
#endif
7781

7882
#undef RN_UMBRELLA_CONTEXT
83+
#pragma pop_macro("RN_UMBRELLA_CONTEXT")

0 commit comments

Comments
 (0)