Skip to content

Commit ea8f934

Browse files
authored
Zend: Expose zendi_try_get_long() function via a public API (php#10175)
1 parent b0d8c10 commit ea8f934

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Zend/zend_operators.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static zend_always_inline zend_result zendi_try_convert_scalar_to_number(zval *o
375375
}
376376
/* }}} */
377377

378-
static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bool *failed) /* {{{ */
378+
static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval *op, bool *failed) /* {{{ */
379379
{
380380
*failed = 0;
381381
switch (Z_TYPE_P(op)) {
@@ -453,6 +453,15 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
453453
}
454454
/* }}} */
455455

456+
ZEND_API zend_long ZEND_FASTCALL zval_try_get_long(const zval *op, bool *failed)
457+
{
458+
if (EXPECTED(Z_TYPE_P(op) == IS_LONG)) {
459+
*failed = false;
460+
return Z_LVAL_P(op);
461+
}
462+
return zendi_try_get_long(op, failed);
463+
}
464+
456465
#define ZEND_TRY_BINARY_OP1_OBJECT_OPERATION(opcode) \
457466
if (UNEXPECTED(Z_TYPE_P(op1) == IS_OBJECT) \
458467
&& UNEXPECTED(Z_OBJ_HANDLER_P(op1, do_operation))) { \

Zend/zend_operators.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ZEND_API void ZEND_FASTCALL convert_to_array(zval *op);
275275
ZEND_API void ZEND_FASTCALL convert_to_object(zval *op);
276276

277277
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict);
278+
ZEND_API zend_long ZEND_FASTCALL zval_try_get_long(const zval *op, bool *failed);
278279
ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op);
279280
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op);
280281
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op);

0 commit comments

Comments
 (0)