Skip to content

Commit 6ef31d6

Browse files
Override the error mode and level and remove the duplicate exceptions
1 parent 128a3b6 commit 6ef31d6

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM debian:bullseye
2+
3+
# Install build dependencies
4+
RUN apt-get update && apt-get install -y \
5+
build-essential \
6+
wget \
7+
tar \
8+
pkg-config \
9+
libtool \
10+
automake \
11+
autoconf \
12+
unzip \
13+
bison \
14+
re2c \
15+
libxml2-dev \
16+
libsqlite3-dev \
17+
libonig-dev \
18+
libzip-dev \
19+
g++ \
20+
locales \
21+
libiconv-hook-dev || true \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
RUN apt-get install -y pkg-config build-essential autoconf bison re2c libxml2-dev libsqlite3-dev
25+
26+
WORKDIR /tmp
27+
RUN wget https://github.com/unicode-org/icu/releases/download/release-62-2/icu4c-62_2-src.tgz && \
28+
tar -xzf icu4c-62_2-src.tgz && \
29+
cd icu/source && \
30+
./configure --prefix=/usr/local && \
31+
make -j$(nproc) && \
32+
make install && \
33+
ldconfig
34+
35+
WORKDIR /app
36+
COPY . /app
37+
RUN ./buildconf --force
38+
RUN ./configure --enable-debug --enable-intl CFLAGS="-g -O0"
39+
RUN make -j4

ext/intl/rangeformatter/rangeformatter_class.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, createFromSkeleton)
121121
UnlocalizedNumberFormatter nf = NumberFormatter::forSkeleton(skeleton_ustr, status);
122122

123123
if (U_FAILURE(status)) {
124+
// override error level and use exceptions
125+
const bool old_use_exception = INTL_G(use_exceptions);
126+
const zend_long old_error_level = INTL_G(error_level);
127+
INTL_G(use_exceptions) = true;
128+
INTL_G(error_level) = 0;
129+
124130
intl_error_set(NULL, status, "Failed to create the number skeleton");
125-
zend_throw_exception(IntlException_ce_ptr, "Failed to create the number skeleton", 0);
126-
RETURN_THROWS();
131+
132+
INTL_G(use_exceptions) = old_use_exception;
133+
INTL_G(error_level) = old_error_level;
127134
}
128135

129136
LocalizedNumberRangeFormatter* nrf = new LocalizedNumberRangeFormatter(
@@ -165,20 +172,25 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, format)
165172

166173
UnicodeString result = RANGEFORMATTER_OBJECT(obj)->formatFormattableRange(start_formattable, end_formattable, error).toString(error);
167174

175+
// override error level and use exceptions
176+
const bool old_use_exception = INTL_G(use_exceptions);
177+
const zend_long old_error_level = INTL_G(error_level);
178+
INTL_G(use_exceptions) = true;
179+
INTL_G(error_level) = 0;
180+
168181
if (U_FAILURE(error)) {
169182
intl_error_set(NULL, error, "Failed to format number range");
170-
zend_throw_exception(IntlException_ce_ptr, "Failed to format number range", 0);
171-
RETURN_THROWS();
172183
}
173184

174185
zend_string *ret = intl_charFromString(result, &error);
175186

176187
if (U_FAILURE(error)) {
177188
intl_error_set(NULL, error, "Failed to convert result to UTF-8");
178-
zend_throw_exception(IntlException_ce_ptr, "Failed to convert result to UTF-8", 0);
179-
RETURN_THROWS();
180189
}
181190

191+
INTL_G(use_exceptions) = old_use_exception;
192+
INTL_G(error_level) = old_error_level;
193+
182194
RETVAL_NEW_STR(ret);
183195
#endif
184196
}

ext/intl/tests/rangeformatter/rangeformatter_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ try {
7777

7878
?>
7979
--EXPECT--
80-
Failed to create the number skeleton
80+
IntlNumberRangeFormatter::createFromSkeleton(): Failed to create the number skeleton
8181
65811
8282
IntlNumberRangeFormatter::createFromSkeleton(): Failed to create the number skeleton: U_NUMBER_SKELETON_SYNTAX_ERROR
8383
Call to private IntlNumberRangeFormatter::__construct() from global scope

0 commit comments

Comments
 (0)