Skip to content

Commit e966167

Browse files
committed
Fixed redundand internal constructor behavior (they shouldn't return NULL anymore)
1 parent dd0b602 commit e966167

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
4242
&rules, &rules_len, &compiled) == FAILURE) {
4343
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
4444
"rbbi_create_instance: bad arguments", 0);
45-
Z_OBJ_P(return_value) = NULL;
4645
return;
4746
}
4847

@@ -72,7 +71,6 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
7271
intl_error_set_custom_msg(NULL, msg, 1);
7372
efree(msg);
7473
delete rbbi;
75-
Z_OBJ_P(return_value) = NULL;
7674
return;
7775
}
7876
} else { // compiled
@@ -81,13 +79,11 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
8179
if (U_FAILURE(status)) {
8280
intl_error_set(NULL, status, "rbbi_create_instance: unable to "
8381
"create instance from compiled rules", 0);
84-
Z_OBJ_P(return_value) = NULL;
8582
return;
8683
}
8784
#else
8885
intl_error_set(NULL, U_UNSUPPORTED_ERROR, "rbbi_create_instance: "
8986
"compiled rules require ICU >= 4.8", 0);
90-
Z_OBJ_P(return_value) = NULL;
9187
return;
9288
#endif
9389
}
@@ -102,11 +98,6 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
10298
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
10399
return_value = getThis();
104100
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
105-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
106-
if (!EG(exception)) {
107-
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
108-
}
109-
}
110101
zend_restore_error_handling(&error_handling);
111102
}
112103

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ static void _php_intlgregcal_constructor_body(
5757
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
5858
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
5959
"intlgregcal_create_instance: too many arguments", 0);
60-
Z_OBJ_P(return_value) = NULL;
60+
if (!is_constructor) {
61+
zval_dtor(return_value);
62+
RETVAL_NULL();
63+
}
6164
return;
6265
}
6366
for (variant = ZEND_NUM_ARGS();
@@ -67,7 +70,10 @@ static void _php_intlgregcal_constructor_body(
6770
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
6871
"intlgregcal_create_instance: no variant with 4 arguments "
6972
"(excluding trailing NULLs)", 0);
70-
Z_OBJ_P(return_value) = NULL;
73+
if (!is_constructor) {
74+
zval_dtor(return_value);
75+
RETVAL_NULL();
76+
}
7177
return;
7278
}
7379

@@ -77,7 +83,10 @@ static void _php_intlgregcal_constructor_body(
7783
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
7884
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
7985
"intlgregcal_create_instance: bad arguments", 0);
80-
Z_OBJ_P(return_value) = NULL;
86+
if (!is_constructor) {
87+
zval_dtor(return_value);
88+
RETVAL_NULL();
89+
}
8190
return;
8291
}
8392
}
@@ -86,7 +95,10 @@ static void _php_intlgregcal_constructor_body(
8695
&largs[5]) == FAILURE) {
8796
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
8897
"intlgregcal_create_instance: bad arguments", 0);
89-
Z_OBJ_P(return_value) = NULL;
98+
if (!is_constructor) {
99+
zval_dtor(return_value);
100+
RETVAL_NULL();
101+
}
90102
return;
91103
}
92104

@@ -98,7 +110,13 @@ static void _php_intlgregcal_constructor_body(
98110
TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL,
99111
"intlgregcal_create_instance");
100112
if (tz == NULL) {
101-
Z_OBJ_P(return_value) = NULL;
113+
if (!EG(exception)) {
114+
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
115+
}
116+
if (!is_constructor) {
117+
zval_dtor(return_value);
118+
RETVAL_NULL();
119+
}
102120
return;
103121
}
104122
if (!locale) {
@@ -114,7 +132,10 @@ static void _php_intlgregcal_constructor_body(
114132
delete gcal;
115133
}
116134
delete tz;
117-
Z_OBJ_P(return_value) = NULL;
135+
if (!is_constructor) {
136+
zval_dtor(return_value);
137+
RETVAL_NULL();
138+
}
118139
return;
119140
}
120141
} else {
@@ -124,7 +145,10 @@ static void _php_intlgregcal_constructor_body(
124145
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
125146
"intlgregcal_create_instance: at least one of the arguments"
126147
" has an absolute value that is too large", 0);
127-
Z_OBJ_P(return_value) = NULL;
148+
if (!is_constructor) {
149+
zval_dtor(return_value);
150+
RETVAL_NULL();
151+
}
128152
return;
129153
}
130154
}
@@ -146,7 +170,10 @@ static void _php_intlgregcal_constructor_body(
146170
if (gcal) {
147171
delete gcal;
148172
}
149-
Z_OBJ_P(return_value) = NULL;
173+
if (!is_constructor) {
174+
zval_dtor(return_value);
175+
RETVAL_NULL();
176+
}
150177
return;
151178
}
152179

@@ -163,7 +190,10 @@ static void _php_intlgregcal_constructor_body(
163190
"from PHP's default timezone name (see date_default_timezone_get())",
164191
0);
165192
delete gcal;
166-
Z_OBJ_P(return_value) = NULL;
193+
if (!is_constructor) {
194+
zval_dtor(return_value);
195+
RETVAL_NULL();
196+
}
167197
return;
168198
}
169199

@@ -177,18 +207,10 @@ static void _php_intlgregcal_constructor_body(
177207

178208
U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
179209
{
180-
zval orig;
181210
intl_error_reset(NULL);
182211

183212
object_init_ex(return_value, GregorianCalendar_ce_ptr);
184-
ZVAL_COPY_VALUE(&orig, return_value);
185-
186213
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
187-
188-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
189-
zval_dtor(&orig);
190-
RETURN_NULL();
191-
}
192214
}
193215

194216
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
@@ -198,11 +220,6 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
198220
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
199221
return_value = getThis();
200222
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
201-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
202-
if (!EG(exception)) {
203-
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
204-
}
205-
}
206223
zend_restore_error_handling(&error_handling);
207224
}
208225

0 commit comments

Comments
 (0)