Skip to content

Commit 4bde898

Browse files
committed
Address code review
1 parent 3c831a0 commit 4bde898

25 files changed

+118
-120
lines changed

ext/com_dotnet/com_com.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -684,34 +684,35 @@ PHP_FUNCTION(com_create_guid)
684684
/* {{{ Connect events from a COM object to a PHP object */
685685
PHP_FUNCTION(com_event_sink)
686686
{
687-
zval *object, *sinkobject, *sink=NULL;
687+
zval *object, *sinkobject;
688+
zend_string *sink_str = NULL;
689+
HashTable *sink_ht = NULL;
688690
char *dispname = NULL, *typelibname = NULL;
689691
php_com_dotnet_object *obj;
690692
ITypeInfo *typeinfo = NULL;
691693

692-
RETVAL_FALSE;
694+
ZEND_PARSE_PARAMETERS_START(2, 3)
695+
Z_PARAM_OBJECT_OF_CLASS(object, php_com_variant_class_entry)
696+
Z_PARAM_OBJECT(sinkobject)
697+
Z_PARAM_OPTIONAL
698+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(sink_str, sink_ht)
699+
ZEND_PARSE_PARAMETERS_END();
693700

694-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "Oo|z!/",
695-
&object, php_com_variant_class_entry, &sinkobject, &sink)) {
696-
RETURN_THROWS();
697-
}
701+
RETVAL_FALSE;
698702

699703
php_com_initialize();
700704
obj = CDNO_FETCH(object);
701705

702-
if (sink && Z_TYPE_P(sink) == IS_ARRAY) {
706+
if (sink_ht) {
703707
/* 0 => typelibname, 1 => dispname */
704708
zval *tmp;
705709

706-
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
710+
if ((tmp = zend_hash_index_find(sink_ht, 0)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
707711
typelibname = Z_STRVAL_P(tmp);
708-
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
712+
if ((tmp = zend_hash_index_find(sink_ht, 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
709713
dispname = Z_STRVAL_P(tmp);
710-
} else if (sink != NULL) {
711-
if (!try_convert_to_string(sink)) {
712-
RETURN_THROWS();
713-
}
714-
dispname = Z_STRVAL_P(sink);
714+
} else if (sink_str) {
715+
dispname = ZSTR_VAL(sink_str);
715716
}
716717

717718
typeinfo = php_com_locate_typeinfo(typelibname, obj, dispname, 1);

ext/com_dotnet/com_extension.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ function com_get_active_object(string $progid, ?int $code_page = null): variant
5858

5959
function com_create_guid(): string|false {}
6060

61-
/** @param array|string|null $sinkinterface */
62-
function com_event_sink(variant $comobject, object $sinkobject, $sinkinterface = UNKNOWN): bool {}
61+
function com_event_sink(variant $comobject, object $sinkobject, array|string|null $sinkinterface = null): bool {}
6362

6463
/** @param com|dotnet|variant|string $comobject */
6564
function com_print_typeinfo($comobject, ?string $dispinterface = null, bool $wantsink = false): bool {}

ext/com_dotnet/com_extension_arginfo.h

Lines changed: 2 additions & 2 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: 9c7d872d61142127560453283a1ca9f07bfdc207 */
2+
* Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
55
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
@@ -92,7 +92,7 @@ ZEND_END_ARG_INFO()
9292
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_event_sink, 0, 2, _IS_BOOL, 0)
9393
ZEND_ARG_OBJ_INFO(0, comobject, variant, 0)
9494
ZEND_ARG_TYPE_INFO(0, sinkobject, IS_OBJECT, 0)
95-
ZEND_ARG_INFO(0, sinkinterface)
95+
ZEND_ARG_TYPE_MASK(0, sinkinterface, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
9696
ZEND_END_ARG_INFO()
9797

9898
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_com_print_typeinfo, 0, 1, _IS_BOOL, 0)

ext/intl/calendar/calendar_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time)
10201020
calendar_object_create(return_value, cal);
10211021

10221022
error:
1023-
if (date_obj && date_str) {
1023+
if (date_str) {
10241024
OBJ_RELEASE(date_obj);
10251025
}
10261026
}

ext/intl/intl_data.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ typedef struct _intl_data {
7171
RETURN_FALSE; \
7272
}
7373

74+
/* Check status in object, if error goto a label */
75+
#define INTL_METHOD_CHECK_STATUS_OR_GOTO(obj, msg, label) \
76+
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
77+
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
78+
{ \
79+
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
80+
RETVAL_FALSE; \
81+
goto label; \
82+
}
83+
7484
/* Check status in object, if error return null */
7585
#define INTL_METHOD_CHECK_STATUS_OR_NULL(obj, msg) \
7686
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \

ext/intl/transliterator/transliterator_methods.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ PHP_FUNCTION( transliterator_transliterate )
280280
TRANSLITERATOR_METHOD_INIT_VARS;
281281

282282
object = getThis();
283+
283284
ZVAL_UNDEF(&tmp_object);
284285

285286
if (object == NULL) {
@@ -310,12 +311,10 @@ PHP_FUNCTION( transliterator_transliterate )
310311
goto cleanup;
311312
}
312313
} else {
313-
ZVAL_OBJ(&tmp_object, arg1_obj);
314+
ZVAL_OBJ_COPY(&tmp_object, arg1_obj);
314315
object = &tmp_object;
315316
}
316-
} else if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|ll",
317-
&str, &str_len, &start, &limit ) == FAILURE )
318-
{
317+
} else if(zend_parse_parameters( ZEND_NUM_ARGS(), "s|ll", &str, &str_len, &start, &limit) == FAILURE) {
319318
RETURN_THROWS();
320319
}
321320

@@ -324,24 +323,25 @@ PHP_FUNCTION( transliterator_transliterate )
324323
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
325324
"transliterator_transliterate: \"end\" argument should be "
326325
"either non-negative or -1", 0 );
327-
RETURN_FALSE;
326+
RETVAL_FALSE;
327+
goto cleanup_object;
328328
}
329329

330330
if( start < 0 || ((limit != -1 ) && (start > limit )) )
331331
{
332332
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
333333
"transliterator_transliterate: \"start\" argument should be "
334334
"non-negative and not bigger than \"end\" (if defined)", 0 );
335-
RETURN_FALSE;
335+
RETVAL_FALSE;
336+
goto cleanup_object;
336337
}
337338

338339
/* end argument parsing/validation */
339340

340341
TRANSLITERATOR_METHOD_FETCH_OBJECT;
341342

342-
intl_convert_utf8_to_utf16( &ustr, &ustr_len, str, str_len,
343-
TRANSLITERATOR_ERROR_CODE_P( to ) );
344-
INTL_METHOD_CHECK_STATUS( to, "String conversion of string to UTF-16 failed" );
343+
intl_convert_utf8_to_utf16(&ustr, &ustr_len, str, str_len, TRANSLITERATOR_ERROR_CODE_P(to));
344+
INTL_METHOD_CHECK_STATUS_OR_GOTO(to, "String conversion of string to UTF-16 failed", cleanup_object);
345345

346346
/* we've started allocating resources, goto from now on */
347347

@@ -419,9 +419,8 @@ PHP_FUNCTION( transliterator_transliterate )
419419
RETVAL_FALSE;
420420
}
421421

422-
if (object != &tmp_object) {
423-
zval_ptr_dtor( &tmp_object );
424-
}
422+
cleanup_object:
423+
zval_ptr_dtor( &tmp_object );
425424
}
426425
/* }}} */
427426

ext/spl/spl_array.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,9 @@ PHP_METHOD(ArrayObject, __construct)
11741174
return; /* nothing to do */
11751175
}
11761176

1177-
ZEND_PARSE_PARAMETERS_START(0, 3)
1178-
Z_PARAM_OPTIONAL
1179-
Z_PARAM_ARRAY_OR_OBJECT(array)
1180-
Z_PARAM_LONG(ar_flags)
1181-
Z_PARAM_CLASS(ce_get_iterator)
1182-
ZEND_PARSE_PARAMETERS_END();
1177+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|AlC", &array, &ar_flags, &ce_get_iterator) == FAILURE) {
1178+
RETURN_THROWS();
1179+
}
11831180

11841181
intern = Z_SPLARRAY_P(object);
11851182

@@ -1205,11 +1202,9 @@ PHP_METHOD(ArrayIterator, __construct)
12051202
return; /* nothing to do */
12061203
}
12071204

1208-
ZEND_PARSE_PARAMETERS_START(0, 2)
1209-
Z_PARAM_OPTIONAL
1210-
Z_PARAM_ARRAY_OR_OBJECT(array)
1211-
Z_PARAM_LONG(ar_flags)
1212-
ZEND_PARSE_PARAMETERS_END();
1205+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|Al", &array, &ar_flags) == FAILURE) {
1206+
RETURN_THROWS();
1207+
}
12131208

12141209
intern = Z_SPLARRAY_P(object);
12151210

@@ -1284,9 +1279,9 @@ PHP_METHOD(ArrayObject, exchangeArray)
12841279
zval *object = ZEND_THIS, *array;
12851280
spl_array_object *intern = Z_SPLARRAY_P(object);
12861281

1287-
ZEND_PARSE_PARAMETERS_START(1, 1)
1288-
Z_PARAM_ARRAY_OR_OBJECT(array)
1289-
ZEND_PARSE_PARAMETERS_END();
1282+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &array) == FAILURE) {
1283+
RETURN_THROWS();
1284+
}
12901285

12911286
if (intern->nApplyCount > 0) {
12921287
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");

ext/spl/spl_array.stub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
77
public function __construct(array|object $input = [], int $flags = 0, string $iterator_class = ArrayIterator::class) {}
88

99
/**
10-
* @param array|string|float|int|bool|null $index
10+
* @param string|int $index
1111
* @return bool
1212
*/
1313
public function offsetExists($index) {}
1414

1515
/**
16-
* @param array|string|float|int|bool|null $index
16+
* @param string|int $index
1717
* @return mixed
1818
*/
1919
public function offsetGet($index) {}
2020

2121
/**
22-
* @param array|string|float|int|bool|null $index
22+
* @param string|int $index
2323
* @return void
2424
*/
2525
public function offsetSet($index, mixed $value) {}
2626

2727
/**
28-
* @param array|string|float|int|bool|null $index
28+
* @param string|int $index
2929
* @return void
3030
*/
3131
public function offsetUnset($index) {}

ext/spl/spl_array_arginfo.h

Lines changed: 1 addition & 1 deletion
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: 300e02d3d9a00f39b74c453e96b719a251ea5690 */
2+
* Stub hash: 93e4c96c631badd30f847fb24636cb881563a949 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_MASK(0, input, MAY_BE_ARRAY|MAY_BE_OBJECT, "[]")

ext/spl/spl_dllist.c

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -739,58 +739,55 @@ PHP_METHOD(SplDoublyLinkedList, offsetExists)
739739
/* {{{ Returns the value at the specified $index. */
740740
PHP_METHOD(SplDoublyLinkedList, offsetGet)
741741
{
742-
zval *zindex;
743742
zend_long index;
744743
spl_dllist_object *intern;
745744
spl_ptr_llist_element *element;
746745

747-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
746+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
748747
RETURN_THROWS();
749748
}
750749

751750
intern = Z_SPLDLLIST_P(ZEND_THIS);
752-
index = spl_offset_convert_to_long(zindex);
753751

754752
if (index < 0 || index >= intern->llist->count) {
755-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
753+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is out of range");
756754
RETURN_THROWS();
757755
}
758756

759757
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
760-
761-
if (element != NULL) {
762-
zval *value = &element->data;
763-
764-
ZVAL_COPY_DEREF(return_value, value);
765-
} else {
766-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
758+
if (element == NULL) {
759+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is an invalid offset");
760+
RETURN_THROWS();
767761
}
762+
763+
zval *value = &element->data;
764+
ZVAL_COPY_DEREF(return_value, value);
768765
} /* }}} */
769766

770767
/* {{{ Sets the value at the specified $index to $newval. */
771768
PHP_METHOD(SplDoublyLinkedList, offsetSet)
772769
{
773-
zval *zindex, *value;
774-
spl_dllist_object *intern;
770+
zend_long index;
771+
zend_bool index_is_null = 1;
772+
zval *value;
773+
spl_dllist_object *intern;
775774

776-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
777-
RETURN_THROWS();
778-
}
775+
ZEND_PARSE_PARAMETERS_START(2, 2)
776+
Z_PARAM_LONG_OR_NULL(index, index_is_null)
777+
Z_PARAM_ZVAL(value)
778+
ZEND_PARSE_PARAMETERS_END();
779779

780780
intern = Z_SPLDLLIST_P(ZEND_THIS);
781781

782-
if (Z_TYPE_P(zindex) == IS_NULL) {
782+
if (index_is_null) {
783783
/* $obj[] = ... */
784784
spl_ptr_llist_push(intern->llist, value);
785785
} else {
786786
/* $obj[$foo] = ... */
787-
zend_long index;
788787
spl_ptr_llist_element *element;
789788

790-
index = spl_offset_convert_to_long(zindex);
791-
792789
if (index < 0 || index >= intern->llist->count) {
793-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
790+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is out of range");
794791
RETURN_THROWS();
795792
}
796793

@@ -813,7 +810,7 @@ PHP_METHOD(SplDoublyLinkedList, offsetSet)
813810
}
814811
} else {
815812
zval_ptr_dtor(value);
816-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
813+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is an invalid offset");
817814
RETURN_THROWS();
818815
}
819816
}
@@ -822,22 +819,20 @@ PHP_METHOD(SplDoublyLinkedList, offsetSet)
822819
/* {{{ Unsets the value at the specified $index. */
823820
PHP_METHOD(SplDoublyLinkedList, offsetUnset)
824821
{
825-
zval *zindex;
826822
zend_long index;
827823
spl_dllist_object *intern;
828824
spl_ptr_llist_element *element;
829825
spl_ptr_llist *llist;
830826

831-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zindex) == FAILURE) {
827+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
832828
RETURN_THROWS();
833829
}
834830

835831
intern = Z_SPLDLLIST_P(ZEND_THIS);
836-
index = spl_offset_convert_to_long(zindex);
837832
llist = intern->llist;
838833

839834
if (index < 0 || index >= intern->llist->count) {
840-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0);
835+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is out of range");
841836
RETURN_THROWS();
842837
}
843838

@@ -878,7 +873,7 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
878873

879874
SPL_LLIST_DELREF(element);
880875
} else {
881-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0);
876+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is an invalid offset");
882877
RETURN_THROWS();
883878
}
884879
} /* }}} */
@@ -1243,20 +1238,19 @@ PHP_METHOD(SplDoublyLinkedList, __unserialize) {
12431238
/* {{{ Inserts a new entry before the specified $index consisting of $newval. */
12441239
PHP_METHOD(SplDoublyLinkedList, add)
12451240
{
1246-
zval *zindex, *value;
1241+
zval *value;
12471242
spl_dllist_object *intern;
12481243
spl_ptr_llist_element *element;
12491244
zend_long index;
12501245

1251-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) {
1246+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &index, &value) == FAILURE) {
12521247
RETURN_THROWS();
12531248
}
12541249

12551250
intern = Z_SPLDLLIST_P(ZEND_THIS);
1256-
index = spl_offset_convert_to_long(zindex);
12571251

12581252
if (index < 0 || index > intern->llist->count) {
1259-
zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0);
1253+
zend_argument_error(spl_ce_OutOfRangeException, 1, "is out of range");
12601254
RETURN_THROWS();
12611255
}
12621256

0 commit comments

Comments
 (0)