Breaking: YGConfigRef related const-correctness fixes (#1371)

Summary:
X-link: https://github.com/facebook/react-native/pull/39374

Pull Request resolved: https://github.com/facebook/yoga/pull/1371

Right now `YGConfigGetDefault` and `YGNodeGetConfig` both return mutable, freeable, configs, which is bad, since the former points to a global singleton config, and the latter usually does too. Mutating this is not thread safe, and it should never be freed.

This change makes these functions return `YGConfigConstRef` to prevent mutation, and also lets us allow `YGConfigNewWithConfig` to accept a const config. If a caller does want to mutate a config (such as to free it), it must be tracked manually.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D49132476

fbshipit-source-id: ac9ce61149e69c6c25cadb99711435b0a5b9f38a
This commit is contained in:
Nick Gerleman
2023-09-11 19:51:40 -07:00
committed by Facebook GitHub Bot
parent a003c09a4c
commit 0720e0b22a
8 changed files with 42 additions and 33 deletions

View File

@@ -71,7 +71,7 @@ private:
size_t lineIndex_ = 0;
Node* owner_ = nullptr;
std::vector<Node*> children_ = {};
Config* config_;
const Config* config_;
std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}};
@@ -95,10 +95,8 @@ private:
Node& operator=(Node&&) = default;
public:
Node() : Node{static_cast<Config*>(YGConfigGetDefault())} {
flags_.hasNewLayout = true;
}
explicit Node(Config* config);
Node();
explicit Node(const Config* config);
~Node() = default; // cleanup of owner/children relationships in YGNodeFree
Node(Node&&);
@@ -165,7 +163,7 @@ public:
size_t getChildCount() const { return children_.size(); }
Config* getConfig() const { return config_; }
const Config* getConfig() const { return config_; }
bool isDirty() const { return flags_.isDirty; }