Skip to content

Commit 813885f

Browse files
committed
Code review - another round
1 parent 036fc11 commit 813885f

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

Zend/zend_API.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code,
221221
case ZPP_ERROR_WRONG_CLASS_OR_NULL:
222222
zend_wrong_parameter_class_or_null_error(num, name, arg);
223223
break;
224+
case ZPP_ERROR_WRONG_CLASS_OR_STRING:
225+
zend_wrong_parameter_class_or_string_error(num, name, arg);
226+
break;
227+
case ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL:
228+
zend_wrong_parameter_class_or_string_or_null_error(num, name, arg);
229+
break;
224230
case ZPP_ERROR_WRONG_CLASS_OR_LONG:
225231
zend_wrong_parameter_class_or_long_error(num, name, arg);
226232
break;
@@ -230,12 +236,6 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code,
230236
case ZPP_ERROR_WRONG_ARG:
231237
zend_wrong_parameter_type_error(num, expected_type, arg);
232238
break;
233-
case ZPP_ERROR_WRONG_CLASS_OR_STRING:
234-
zend_wrong_parameter_class_or_string_error(num, name, arg);
235-
break;
236-
case ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL:
237-
zend_wrong_parameter_class_or_string_or_null_error(num, name, arg);
238-
break;
239239
case ZPP_ERROR_UNEXPECTED_EXTRA_NAMED:
240240
zend_unexpected_extra_named_error();
241241
break;

Zend/zend_API.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,12 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
12651265
#define ZPP_ERROR_WRONG_CALLBACK 2
12661266
#define ZPP_ERROR_WRONG_CLASS 3
12671267
#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1268-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG 5
1269-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 6
1270-
#define ZPP_ERROR_WRONG_ARG 7
1271-
#define ZPP_ERROR_WRONG_COUNT 8
1272-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING 9
1273-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 10
1268+
#define ZPP_ERROR_WRONG_CLASS_OR_STRING 5
1269+
#define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
1270+
#define ZPP_ERROR_WRONG_CLASS_OR_LONG 7
1271+
#define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 8
1272+
#define ZPP_ERROR_WRONG_ARG 9
1273+
#define ZPP_ERROR_WRONG_COUNT 10
12741274
#define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11
12751275

12761276
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \

ext/date/php_date.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,15 +4139,21 @@ PHP_METHOD(DatePeriod, __construct)
41394139
}
41404140

41414141
if (dpobj->start == NULL) {
4142-
zend_argument_error(zend_ce_exception, 1, "must contain a start date, \"%s\" given", isostr);
4142+
zend_string *func = get_active_function_or_method_name();
4143+
zend_throw_error(NULL, "%s(): Argument #1 must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
4144+
zend_string_release(func);
41434145
RETURN_THROWS();
41444146
}
41454147
if (dpobj->interval == NULL) {
4146-
zend_argument_error(zend_ce_exception, 1, "must contain an interval, \"%s\" given", isostr);
4148+
zend_string *func = get_active_function_or_method_name();
4149+
zend_throw_error(NULL, "%s(): Argument #1 must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
4150+
zend_string_release(func);
41474151
RETURN_THROWS();
41484152
}
41494153
if (dpobj->end == NULL && recurrences == 0) {
4150-
zend_argument_error(zend_ce_exception, 1, "must contain an end date or a recurrence count, \"%s\" given", isostr);
4154+
zend_string *func = get_active_function_or_method_name();
4155+
zend_throw_error(NULL, "%s(): Argument #1 must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
4156+
zend_string_release(func);
41514157
RETURN_THROWS();
41524158
}
41534159

ext/date/php_date.stub.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,13 @@ public static function __set_state(array $array) {}
393393

394394
class DatePeriod implements IteratorAggregate
395395
{
396-
public function __construct(DateTimeInterface|string $start, DateInterval|int|null $interval = null, DateTimeInterface|int|null $end = null, int $options = 0) {}
396+
/**
397+
* @param DateTimeInterface|string $start
398+
* @param DateInterval|int $interval
399+
* @param DateTimeInterface|int $end
400+
* @param int $options
401+
*/
402+
public function __construct($start, $interval = UNKNOWN, $end = UNKNOWN, $options = UNKNOWN) {}
397403

398404
/** @return DateTimeInterface */
399405
public function getStartDate() {}

ext/date/php_date_arginfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 67182d27266e8618e555e7617882166661f803b8 */
2+
* Stub hash: fee95924adec03c89fdd677ec26bb6eea34d4b3c */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
@@ -409,10 +409,10 @@ ZEND_END_ARG_INFO()
409409
#define arginfo_class_DateInterval___set_state arginfo_class_DateTime___set_state
410410

411411
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DatePeriod___construct, 0, 0, 1)
412-
ZEND_ARG_OBJ_TYPE_MASK(0, start, DateTimeInterface, MAY_BE_STRING, NULL)
413-
ZEND_ARG_OBJ_TYPE_MASK(0, interval, DateInterval, MAY_BE_LONG|MAY_BE_NULL, "null")
414-
ZEND_ARG_OBJ_TYPE_MASK(0, end, DateTimeInterface, MAY_BE_LONG|MAY_BE_NULL, "null")
415-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
412+
ZEND_ARG_INFO(0, start)
413+
ZEND_ARG_INFO(0, interval)
414+
ZEND_ARG_INFO(0, end)
415+
ZEND_ARG_INFO(0, options)
416416
ZEND_END_ARG_INFO()
417417

418418
#define arginfo_class_DatePeriod_getStartDate arginfo_class_DateTimeInterface_getTimezone

ext/intl/dateformat/dateformat_attrcpp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extern "C" {
2525
#include "../timezone/timezone_class.h"
2626
#define USE_CALENDAR_POINTER 1
2727
#include "../calendar/calendar_class.h"
28-
#include "../calendar/calendar_ce.h"
2928
}
3029

3130
#include "../intl_convertcpp.h"

ext/intl/dateformat/dateformat_create.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
#include "php_intl.h"
2727
#include "dateformat_create.h"
2828
#include "dateformat_class.h"
29-
#include "../calendar/calendar_ce.h"
29+
#include "../calendar/calendar_class.h"
3030
#define USE_TIMEZONE_POINTER 1
3131
#include "../timezone/timezone_class.h"
3232
#include "../intl_convert.h"
@@ -44,7 +44,7 @@ extern "C" {
4444
UDAT_PATTERN == (i))
4545

4646
/* {{{ */
47-
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
47+
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4848
{
4949
zval *object;
5050
char *locale_str;
@@ -78,28 +78,25 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
7878
Z_PARAM_ZVAL(timezone_zv)
7979
Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(calendar_obj, Calendar_ce_ptr, calendar_long, calendar_is_null)
8080
Z_PARAM_STRING_OR_NULL(pattern_str, pattern_str_len)
81-
ZEND_PARSE_PARAMETERS_END();
81+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
8282

8383
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
8484

8585
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
8686
intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0);
87-
zval_ptr_dtor(return_value);
88-
RETURN_NULL();
87+
return FAILURE;
8988
}
9089

9190
if (!INTL_UDATE_FMT_OK(date_type)) {
9291
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid date format style", 0);
93-
zval_ptr_dtor(return_value);
94-
RETURN_NULL();
92+
return FAILURE;
9593
}
9694
if (!INTL_UDATE_FMT_OK(time_type)) {
9795
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid time format style", 0);
98-
zval_ptr_dtor(return_value);
99-
RETURN_NULL();
96+
return FAILURE;
10097
}
10198

102-
INTL_CHECK_LOCALE_LEN(locale_len);
99+
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
103100
if (locale_len == 0) {
104101
locale_str = (char *) intl_locale_get_default();
105102
}
@@ -183,20 +180,15 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
183180
delete cal;
184181
}
185182

186-
if (U_FAILURE(intl_error_get_code(NULL))) {
187-
zval_ptr_dtor(return_value);
188-
RETURN_NULL();
189-
}
183+
return U_FAILURE(intl_error_get_code(NULL)) ? FAILURE : SUCCESS;
190184
}
191185
/* }}} */
192186

193187
/* {{{ Create formatter. */
194188
U_CFUNC PHP_FUNCTION( datefmt_create )
195189
{
196190
object_init_ex( return_value, IntlDateFormatter_ce_ptr );
197-
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
198-
199-
if (Z_TYPE_P(return_value) == IS_NULL) {
191+
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
200192
zval_ptr_dtor(return_value);
201193
RETURN_NULL();
202194
}
@@ -212,8 +204,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
212204
/* return_value param is being changed, therefore we will always return
213205
* NULL here */
214206
return_value = ZEND_THIS;
215-
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
216-
if (Z_TYPE_P(return_value) == IS_NULL) {
207+
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
217208
if (!EG(exception)) {
218209
zend_string *err = intl_error_get_message(NULL);
219210
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));

0 commit comments

Comments
 (0)