Skip to content

Commit cd89fe6

Browse files
committed
1 parent 66474ec commit cd89fe6

1 file changed

Lines changed: 37 additions & 11 deletions

File tree

‎src/objects/js-temporal-zoneinfo64.cc‎

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,30 @@
1111
#include "temporal_rs/TimeZone.hpp"
1212

1313
#ifdef V8_INTL_SUPPORT
14-
#include "udatamem.h"
14+
/**
15+
* Shadow definition of UDataMemory
16+
* This is functionally identical to the definition in udatamem.h
17+
* Irrelevant fields are marked 'ignored' and should not be used.
18+
*
19+
* This definition is copied here so that the result of udata_open()
20+
* can be used and length-checked without needing to resort to
21+
* calling internal ICU functions.
22+
*
23+
* Note, there is an ICU ticket,
24+
* https://unicode-org.atlassian.net/browse/ICU-23400
25+
* to consider whether the API surface should be changed
26+
* here. If and when this is done, such an API could be used.
27+
*/
28+
struct UDataMemoryShadow {
29+
const void* ignored1;
30+
const void* data; //< pointer to header of data object
31+
const void* ignored2;
32+
UBool ignored3;
33+
void* ignored4;
34+
void* ignored5;
35+
int32_t
36+
length; //< length of entire region pointed to by data if known, else -1
37+
};
1538
#else
1639
// Defined in builtins-temporal-zoneinfo64-data.cc, generated by
1740
// include-file-as-bytes.py
@@ -30,26 +53,29 @@ ZoneInfo64Provider::ZoneInfo64Provider() {
3053
provider = temporal_rs::Provider::empty();
3154
return;
3255
}
33-
// NOT udata_getLength: this ignores the header,
34-
// and we're parsing resb files with the header
35-
auto length = memory->length;
36-
const void* data = udata_getRawMemory(memory);
37-
DCHECK_WITH_MSG(length % 4 == 0, "ICU4C should align udata to uint32_t");
38-
if (length % 4 != 0) {
39-
// This really shouldn't happen: ICU4C aligns these files
40-
// to 4 when baking them in
56+
// reinterpret with a local struct
57+
const UDataMemoryShadow* shadowMemory =
58+
reinterpret_cast<const UDataMemoryShadow*>(memory);
59+
// just need the length and data
60+
auto length = shadowMemory->length;
61+
// This really shouldn't happen: ICU4C pads these files
62+
// to 4 when baking them in
63+
DCHECK_WITH_MSG(length % 4 == 0, "ICU4C should pad udata to uint32_t");
64+
// Length may not be known. If we're not OK with that, don't proceed.
65+
DCHECK_WITH_MSG(length != -1, "ICU4C usually knows the length");
66+
if (length % 4 != 0 || length == -1) {
4167
provider = temporal_rs::Provider::empty();
4268
return;
4369
}
70+
auto data = shadowMemory->data;
71+
DCHECK_WITH_MSG(data != nullptr, "ICU4C returned nullptr");
4472

4573
const uint32_t* data_32 = static_cast<const uint32_t*>(data);
4674
std::span<const uint32_t> data_span(data_32, length / 4);
47-
4875
#else
4976
std::span<const uint32_t> data_span(zoneinfo64_static_data,
5077
zoneinfo64_static_data_len);
5178
#endif
52-
5379
auto result = temporal_rs::Provider::new_zoneinfo64(data_span);
5480
DCHECK_WITH_MSG(result.is_ok(), "Baked-in zoneinfo64 file must parse");
5581
if (result.is_ok()) {

0 commit comments

Comments
 (0)