upgpkg: ocaml-topkg 1.0.5-2
[arch-packages.git] / icu / trunk / ICU-22356.patch
blob62cecb97f757c15b4eeb896b28415e00b142806c
1 From 4fd9d6ce9a951e66e727b296138f22cd05479de1 Mon Sep 17 00:00:00 2001
2 From: Fredrik Roubert <roubert@google.com>
3 Date: Tue, 18 Apr 2023 23:39:28 +0200
4 Subject: [PATCH] ICU-22356 Use ConstChar16Ptr to safely cast from UChar* to
5 char16_t*.
7 This is necessary for this header file to be usable by clients that
8 define UCHAR_TYPE as a type not compatible with char16_t, eg. uint16_t.
9 ---
10 icu4c/source/common/unicode/ures.h | 9 +++++----
11 icu4c/source/test/intltest/Makefile.in | 2 +-
12 icu4c/source/test/intltest/intltest.vcxproj | 1 +
13 icu4c/source/test/intltest/intltest.vcxproj.filters | 3 +++
14 icu4c/source/test/intltest/uchar_type_build_test.cpp | 7 +++++++
15 5 files changed, 17 insertions(+), 5 deletions(-)
16 create mode 100644 icu4c/source/test/intltest/uchar_type_build_test.cpp
18 diff --git a/icu4c/source/common/unicode/ures.h b/icu4c/source/common/unicode/ures.h
19 index cc25b6e49cd..babc01d426a 100644
20 --- a/icu4c/source/common/unicode/ures.h
21 +++ b/icu4c/source/common/unicode/ures.h
22 @@ -25,6 +25,7 @@
23 #ifndef URES_H
24 #define URES_H
26 +#include "unicode/char16ptr.h"
27 #include "unicode/utypes.h"
28 #include "unicode/uloc.h"
30 @@ -812,7 +813,7 @@ inline UnicodeString
31 ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) {
32 UnicodeString result;
33 int32_t len = 0;
34 - const char16_t *r = ures_getString(resB, &len, status);
35 + const char16_t *r = ConstChar16Ptr(ures_getString(resB, &len, status));
36 if(U_SUCCESS(*status)) {
37 result.setTo(true, r, len);
38 } else {
39 @@ -837,7 +838,7 @@ inline UnicodeString
40 ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) {
41 UnicodeString result;
42 int32_t len = 0;
43 - const char16_t* r = ures_getNextString(resB, &len, key, status);
44 + const char16_t* r = ConstChar16Ptr(ures_getNextString(resB, &len, key, status));
45 if(U_SUCCESS(*status)) {
46 result.setTo(true, r, len);
47 } else {
48 @@ -859,7 +860,7 @@ inline UnicodeString
49 ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) {
50 UnicodeString result;
51 int32_t len = 0;
52 - const char16_t* r = ures_getStringByIndex(resB, indexS, &len, status);
53 + const char16_t* r = ConstChar16Ptr(ures_getStringByIndex(resB, indexS, &len, status));
54 if(U_SUCCESS(*status)) {
55 result.setTo(true, r, len);
56 } else {
57 @@ -882,7 +883,7 @@ inline UnicodeString
58 ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) {
59 UnicodeString result;
60 int32_t len = 0;
61 - const char16_t* r = ures_getStringByKey(resB, key, &len, status);
62 + const char16_t* r = ConstChar16Ptr(ures_getStringByKey(resB, key, &len, status));
63 if(U_SUCCESS(*status)) {
64 result.setTo(true, r, len);
65 } else {
66 diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in
67 index 8007d3c1880..f57f8d995f4 100644
68 --- a/icu4c/source/test/intltest/Makefile.in
69 +++ b/icu4c/source/test/intltest/Makefile.in
70 @@ -70,7 +70,7 @@ numbertest_parse.o numbertest_doubleconversion.o numbertest_skeletons.o \
71 static_unisets_test.o numfmtdatadriventest.o numbertest_range.o erarulestest.o \
72 formattedvaluetest.o formatted_string_builder_test.o numbertest_permutation.o \
73 units_data_test.o units_router_test.o units_test.o displayoptions_test.o \
74 -numbertest_simple.o
75 +numbertest_simple.o uchar_type_build_test.o
77 DEPS = $(OBJECTS:.o=.d)
79 diff --git a/icu4c/source/test/intltest/intltest.vcxproj b/icu4c/source/test/intltest/intltest.vcxproj
80 index 0985ba1e808..71ce1254038 100644
81 --- a/icu4c/source/test/intltest/intltest.vcxproj
82 +++ b/icu4c/source/test/intltest/intltest.vcxproj
83 @@ -291,6 +291,7 @@
84 <ClCompile Include="units_data_test.cpp" />
85 <ClCompile Include="units_router_test.cpp" />
86 <ClCompile Include="units_test.cpp" />
87 + <ClCompile Include="uchar_type_build_test.cpp" />
88 </ItemGroup>
89 <ItemGroup>
90 <ClInclude Include="colldata.h" />
91 diff --git a/icu4c/source/test/intltest/intltest.vcxproj.filters b/icu4c/source/test/intltest/intltest.vcxproj.filters
92 index ffe9bc1467d..5d8777c5aaf 100644
93 --- a/icu4c/source/test/intltest/intltest.vcxproj.filters
94 +++ b/icu4c/source/test/intltest/intltest.vcxproj.filters
95 @@ -568,6 +568,9 @@
96 <ClCompile Include="units_test.cpp">
97 <Filter>formatting</Filter>
98 </ClCompile>
99 + <ClCompile Include="uchar_type_build_test.cpp">
100 + <Filter>configuration</Filter>
101 + </ClCompile>
102 </ItemGroup>
103 <ItemGroup>
104 <ClInclude Include="itrbbi.h">
105 diff --git a/icu4c/source/test/intltest/uchar_type_build_test.cpp b/icu4c/source/test/intltest/uchar_type_build_test.cpp
106 new file mode 100644
107 index 00000000000..ca9335441a3
108 --- /dev/null
109 +++ b/icu4c/source/test/intltest/uchar_type_build_test.cpp
110 @@ -0,0 +1,7 @@
111 +// © 2023 and later: Unicode, Inc. and others.
112 +// License & terms of use: http://www.unicode.org/copyright.html#License
114 +// ICU-22356 Test that client code can be built with UCHAR_TYPE redefined.
115 +#undef UCHAR_TYPE
116 +#define UCHAR_TYPE uint16_t
117 +#include "unicode/ures.h"