Skip to content

Commit 42b3917

Browse files
chiaramooneyfacebook-github-bot
authored andcommitted
Fix ReactCommon Break for Windows (#33047)
Summary: Changes to MapBuffer code in aaff15c...d287598 broke build for Windows. Errors included incompatible type conversions, the use of `__attribute__(__packed__)` which is only supported by GCC and Clang, and the usage of designated initializers which are only supported on C++20. Changes here restore build on Windows. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - Fix build break on Windows with ReactCommon Pull Request resolved: #33047 Test Plan: React Native project built on Windows and passes react-native-windows repository pipeline. These edits are currently merged into the main branch of react-native-windows. Reviewed By: ShikaSD Differential Revision: D34101367 Pulled By: philIip fbshipit-source-id: 1596365c2e92f377c6375805b33de5e1c7b78e66
1 parent 216ac27 commit 42b3917

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

ReactCommon/react/renderer/mapbuffer/MapBuffer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ MapBuffer::MapBuffer(std::vector<uint8_t> data) : bytes_(std::move(data)) {
3333
}
3434
}
3535

36-
uint32_t MapBuffer::getKeyBucket(Key key) const {
37-
uint32_t lo = 0;
38-
uint32_t hi = count_ - 1;
36+
int32_t MapBuffer::getKeyBucket(Key key) const {
37+
int32_t lo = 0;
38+
int32_t hi = count_ - 1;
3939
while (lo <= hi) {
40-
uint32_t mid = (lo + hi) >> 1;
40+
int32_t mid = (lo + hi) >> 1;
4141

4242
Key midVal =
4343
*reinterpret_cast<Key const *>(bytes_.data() + bucketOffset(mid));
@@ -112,7 +112,7 @@ MapBuffer MapBuffer::getMapBuffer(Key key) const {
112112
return MapBuffer(std::move(value));
113113
}
114114

115-
uint32_t MapBuffer::size() const {
115+
size_t MapBuffer::size() const {
116116
return bytes_.size();
117117
}
118118

ReactCommon/react/renderer/mapbuffer/MapBuffer.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ class MapBuffer {
8080
uint32_t bufferSize; // Amount of bytes used to store the map in memory
8181
};
8282

83-
struct __attribute__((__packed__)) Bucket {
83+
#pragma pack(push, 1)
84+
struct Bucket {
8485
Key key;
8586
uint16_t type;
8687
uint64_t data;
8788

8889
Bucket(Key key, uint16_t type, uint64_t data)
8990
: key(key), type(type), data(data) {}
9091
};
92+
#pragma pack(pop)
9193

9294
static_assert(sizeof(Header) == 8, "MapBuffer header size is incorrect.");
9395
static_assert(sizeof(Bucket) == 12, "MapBuffer bucket size is incorrect.");
@@ -124,7 +126,7 @@ class MapBuffer {
124126
// TODO T83483191: review this declaration
125127
MapBuffer getMapBuffer(MapBuffer::Key key) const;
126128

127-
uint32_t size() const;
129+
size_t size() const;
128130

129131
uint8_t const *data() const;
130132

@@ -140,7 +142,7 @@ class MapBuffer {
140142
// returns the relative offset of the first byte of dynamic data
141143
int32_t getDynamicDataOffset() const;
142144

143-
uint32_t getKeyBucket(MapBuffer::Key key) const;
145+
int32_t getKeyBucket(MapBuffer::Key key) const;
144146

145147
friend ReadableMapBuffer;
146148
};

ReactCommon/react/renderer/mapbuffer/MapBufferBuilder.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace facebook {
1414
namespace react {
1515

1616
constexpr uint32_t INT_SIZE = sizeof(uint32_t);
17-
constexpr double DOUBLE_SIZE = sizeof(double);
17+
constexpr uint32_t DOUBLE_SIZE = sizeof(double);
1818
constexpr uint32_t MAX_BUCKET_VALUE_SIZE = sizeof(uint64_t);
1919

2020
MapBuffer MapBufferBuilder::EMPTY() {
@@ -23,6 +23,8 @@ MapBuffer MapBufferBuilder::EMPTY() {
2323

2424
MapBufferBuilder::MapBufferBuilder(uint32_t initialSize) {
2525
buckets_.reserve(initialSize);
26+
header_.count = 0;
27+
header_.bufferSize = 0;
2628
}
2729

2830
void MapBufferBuilder::storeKeyValue(
@@ -76,7 +78,7 @@ void MapBufferBuilder::putInt(MapBuffer::Key key, int32_t value) {
7678
}
7779

7880
void MapBufferBuilder::putString(MapBuffer::Key key, std::string const &value) {
79-
int32_t strSize = value.size();
81+
auto strSize = value.size();
8082
const char *strData = value.data();
8183

8284
// format [length of string (int)] + [Array of Characters in the string]
@@ -94,7 +96,7 @@ void MapBufferBuilder::putString(MapBuffer::Key key, std::string const &value) {
9496
}
9597

9698
void MapBufferBuilder::putMapBuffer(MapBuffer::Key key, MapBuffer const &map) {
97-
int32_t mapBufferSize = map.size();
99+
auto mapBufferSize = map.size();
98100

99101
auto offset = dynamicData_.size();
100102

@@ -122,9 +124,9 @@ MapBuffer MapBufferBuilder::build() {
122124
// Create buffer: [header] + [key, values] + [dynamic data]
123125
auto bucketSize = buckets_.size() * sizeof(MapBuffer::Bucket);
124126
auto headerSize = sizeof(MapBuffer::Header);
125-
uint32_t bufferSize = headerSize + bucketSize + dynamicData_.size();
127+
auto bufferSize = headerSize + bucketSize + dynamicData_.size();
126128

127-
header_.bufferSize = bufferSize;
129+
header_.bufferSize = static_cast<uint32_t>(bufferSize);
128130

129131
if (needsSort_) {
130132
std::sort(buckets_.begin(), buckets_.end(), compareBuckets);

ReactCommon/react/renderer/mapbuffer/MapBufferBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MapBufferBuilder {
3838
MapBuffer build();
3939

4040
private:
41-
MapBuffer::Header header_ = {.count = 0, .bufferSize = 0};
41+
MapBuffer::Header header_;
4242

4343
std::vector<MapBuffer::Bucket> buckets_{};
4444

0 commit comments

Comments
 (0)