diff --git a/packages/react-native/ReactCommon/callinvoker/React/CallInvoker.h b/packages/react-native/ReactCommon/callinvoker/React/CallInvoker.h index e8bf92e95da..f77c0725d1e 100644 --- a/packages/react-native/ReactCommon/callinvoker/React/CallInvoker.h +++ b/packages/react-native/ReactCommon/callinvoker/React/CallInvoker.h @@ -18,10 +18,16 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/cxxstableapi/UmbrellaGuard.h b/packages/react-native/ReactCommon/react/cxxstableapi/UmbrellaGuard.h index fa925805f1e..a0b08eec4dd 100644 --- a/packages/react-native/ReactCommon/react/cxxstableapi/UmbrellaGuard.h +++ b/packages/react-native/ReactCommon/react/cxxstableapi/UmbrellaGuard.h @@ -29,15 +29,25 @@ // defining RN_STRICT_API. // // RN_UMBRELLA_CONTEXT Internal marker (implementation detail; consumers never -// set it). A module umbrella defines it around its own -// `#include`s to signal the blessed inclusion path: -// #define RN_UMBRELLA_CONTEXT +// set it). A module umbrella brackets its own `#include`s +// with it to signal the blessed inclusion path: +// #pragma push_macro("RN_UMBRELLA_CONTEXT") +// #undef RN_UMBRELLA_CONTEXT +// #define RN_UMBRELLA_CONTEXT 1 // #include // #include // #undef RN_UMBRELLA_CONTEXT -// The `#undef` matters: it keeps the marker scoped to the -// umbrella's includes so later *direct* includes in the -// same translation unit are still caught. +// #pragma pop_macro("RN_UMBRELLA_CONTEXT") +// Saving and restoring, rather than a bare +// `#define`/`#undef` pair, is what makes the scope both +// end at the umbrella -- later *direct* includes in the +// same translation unit are still caught -- and nest: an +// umbrella reached from inside another umbrella's +// context leaves the outer one armed. A bare `#undef` +// would disarm it, and every public header the outer +// umbrella included afterwards would hard-error. +// `scripts/add-cxxstableapi-guard.js --tier=public` +// emits this block; do not hand-write or "simplify" it. // // RN_BUILDING Defined by React Native's own build targets so internal // sources may keep including the fine-grained headers diff --git a/packages/react-native/ReactCommon/react/debug/React/Debug.h b/packages/react-native/ReactCommon/react/debug/React/Debug.h index 8ba388a6e3a..4957eaa6a66 100644 --- a/packages/react-native/ReactCommon/react/debug/React/Debug.h +++ b/packages/react-native/ReactCommon/react/debug/React/Debug.h @@ -21,11 +21,17 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/bridging/React/RendererBridging.h b/packages/react-native/ReactCommon/react/renderer/bridging/React/RendererBridging.h index cc15bb5bae3..7f711c8b3c1 100644 --- a/packages/react-native/ReactCommon/react/renderer/bridging/React/RendererBridging.h +++ b/packages/react-native/ReactCommon/react/renderer/bridging/React/RendererBridging.h @@ -23,11 +23,15 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. Scoped to -// this block so later *direct* includes in the same translation unit are still -// caught. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/image/React/Image.h b/packages/react-native/ReactCommon/react/renderer/components/image/React/Image.h index de6e2a47c36..11fd0c2dca5 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/image/React/Image.h +++ b/packages/react-native/ReactCommon/react/renderer/components/image/React/Image.h @@ -18,8 +18,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include @@ -29,3 +34,4 @@ #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/modal/React/Modal.h b/packages/react-native/ReactCommon/react/renderer/components/modal/React/Modal.h index 71518feb1c4..c763e4d9ffb 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/modal/React/Modal.h +++ b/packages/react-native/ReactCommon/react/renderer/components/modal/React/Modal.h @@ -19,8 +19,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include @@ -28,3 +33,4 @@ #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/root/React/Root.h b/packages/react-native/ReactCommon/react/renderer/components/root/React/Root.h index 96f08af7caf..c81a6d62346 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/root/React/Root.h +++ b/packages/react-native/ReactCommon/react/renderer/components/root/React/Root.h @@ -19,11 +19,17 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/React/ScrollView.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/React/ScrollView.h index 96bf19f107d..d382ee45a3d 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/React/ScrollView.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/React/ScrollView.h @@ -20,8 +20,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include @@ -40,3 +45,4 @@ #endif #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/React/Text.h b/packages/react-native/ReactCommon/react/renderer/components/text/React/Text.h index 6670d8a7b36..183a9e55789 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/React/Text.h +++ b/packages/react-native/ReactCommon/react/renderer/components/text/React/Text.h @@ -19,8 +19,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include @@ -51,3 +56,4 @@ #endif #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/React/View.h b/packages/react-native/ReactCommon/react/renderer/components/view/React/View.h index 11325cb2223..de36f85ecdd 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/React/View.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/React/View.h @@ -19,9 +19,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. Scoped to -// this block so later *direct* includes in the same TU are still caught. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #if defined(__APPLE__) #include @@ -76,3 +80,4 @@ #endif #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/mapbuffer/React/MapBuffer.h b/packages/react-native/ReactCommon/react/renderer/mapbuffer/React/MapBuffer.h index 898a7befe37..aed8b6dc821 100644 --- a/packages/react-native/ReactCommon/react/renderer/mapbuffer/React/MapBuffer.h +++ b/packages/react-native/ReactCommon/react/renderer/mapbuffer/React/MapBuffer.h @@ -18,10 +18,16 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/React/UIManager.h b/packages/react-native/ReactCommon/react/renderer/uimanager/React/UIManager.h index 0eb6cedb315..aeb126a87d0 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/React/UIManager.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/React/UIManager.h @@ -19,8 +19,13 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #include @@ -39,3 +44,4 @@ #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT") diff --git a/packages/react-native/ReactCommon/react/timing/React/Timing.h b/packages/react-native/ReactCommon/react/timing/React/Timing.h index 56a676dc92d..bfac6c96fcb 100644 --- a/packages/react-native/ReactCommon/react/timing/React/Timing.h +++ b/packages/react-native/ReactCommon/react/timing/React/Timing.h @@ -18,10 +18,15 @@ // ============================================================================= // Marks that the following headers are pulled in through the umbrella, so their -// shared guard () accepts them. Scoped to -// this block so later *direct* includes in the same TU are still caught. -#define RN_UMBRELLA_CONTEXT +// shared guard () accepts them. The marker +// is saved and restored rather than defined and undefined: the scope ends at +// this block, so later *direct* includes in the same TU are still caught, and +// it nests inside an enclosing umbrella rather than disarming it. +#pragma push_macro("RN_UMBRELLA_CONTEXT") +#undef RN_UMBRELLA_CONTEXT +#define RN_UMBRELLA_CONTEXT 1 #include #undef RN_UMBRELLA_CONTEXT +#pragma pop_macro("RN_UMBRELLA_CONTEXT")