From a5ad9eeefa4a0cea9a88b0c394a561ebade62209 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 22 Jul 2021 10:32:24 +0200 Subject: [PATCH] Add explicit IntlPartsIterator::getRuleStatus() method Rather than doing a magic forward, explicitly add a forwarding method. This must be the most frivolous use of get_method I've ever seen. --- .../breakiterator/breakiterator_iterators.cpp | 64 +++++-------------- .../breakiterator_iterators.stub.php | 3 + .../breakiterator_iterators_arginfo.h | 7 +- 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/ext/intl/breakiterator/breakiterator_iterators.cpp b/ext/intl/breakiterator/breakiterator_iterators.cpp index 1b9fb92f6a8..47910dae377 100644 --- a/ext/intl/breakiterator/breakiterator_iterators.cpp +++ b/ext/intl/breakiterator/breakiterator_iterators.cpp @@ -28,6 +28,7 @@ extern "C" { #include "../intl_convert.h" #include "../locale/locale.h" #include +#include } static zend_class_entry *IntlPartsIterator_ce_ptr; @@ -229,48 +230,6 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv, ((zoi_break_iter_parts*)ii->iterator)->key_type = key_type; } -U_CFUNC zend_object *IntlPartsIterator_object_create(zend_class_entry *ce) -{ - zend_object *retval = IntlIterator_ce_ptr->create_object(ce); - retval->handlers = &IntlPartsIterator_handlers; - - return retval; -} - -U_CFUNC zend_function *IntlPartsIterator_get_method(zend_object **object_ptr, zend_string *method, const zval *key) -{ - zend_function *ret; - zend_string *lc_method_name; - ALLOCA_FLAG(use_heap); - - if (key == NULL) { - ZSTR_ALLOCA_ALLOC(lc_method_name, ZSTR_LEN(method), use_heap); - zend_str_tolower_copy(ZSTR_VAL(lc_method_name), ZSTR_VAL(method), ZSTR_LEN(method)); - } else { - lc_method_name = Z_STR_P(key); - } - - if (ZSTR_LEN(method) == sizeof("getrulestatus") - 1 - && memcmp("getrulestatus", ZSTR_VAL(lc_method_name), ZSTR_LEN(lc_method_name)) == 0) { - IntlIterator_object *obj = php_intl_iterator_fetch_object(*object_ptr); - if (obj->iterator && !Z_ISUNDEF(obj->iterator->data)) { - zval *break_iter_zv = &obj->iterator->data; - *object_ptr = Z_OBJ_P(break_iter_zv); - ret = Z_OBJ_HANDLER_P(break_iter_zv, get_method)(object_ptr, method, key); - goto end; - } - } - - ret = zend_std_get_method(object_ptr, method, key); - -end: - if (key == NULL) { - ZSTR_ALLOCA_FREE(lc_method_name, use_heap); - } - - return ret; -} - U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator) { INTLITERATOR_METHOD_INIT_VARS; @@ -284,15 +243,26 @@ U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator) RETURN_COPY_DEREF(&ii->iterator->data); } +U_CFUNC PHP_METHOD(IntlPartsIterator, getRuleStatus) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + RETURN_THROWS(); + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + + zval *iter = &ii->iterator->data; + ZEND_ASSERT(Z_TYPE_P(iter) == IS_OBJECT); + zend_call_method_with_0_params( + Z_OBJ_P(iter), Z_OBJCE_P(iter), NULL, "getrulestatus", return_value); +} + U_CFUNC void breakiterator_register_IntlPartsIterator_class(void) { /* Create and register 'BreakIterator' class. */ IntlPartsIterator_ce_ptr = register_class_IntlPartsIterator(IntlIterator_ce_ptr); - IntlPartsIterator_ce_ptr->create_object = IntlPartsIterator_object_create; - - memcpy(&IntlPartsIterator_handlers, &IntlIterator_handlers, - sizeof IntlPartsIterator_handlers); - IntlPartsIterator_handlers.get_method = IntlPartsIterator_get_method; #define PARTSITER_DECL_LONG_CONST(name) \ zend_declare_class_constant_long(IntlPartsIterator_ce_ptr, #name, \ diff --git a/ext/intl/breakiterator/breakiterator_iterators.stub.php b/ext/intl/breakiterator/breakiterator_iterators.stub.php index bf4e42fe383..7e7603fe6fd 100644 --- a/ext/intl/breakiterator/breakiterator_iterators.stub.php +++ b/ext/intl/breakiterator/breakiterator_iterators.stub.php @@ -6,4 +6,7 @@ class IntlPartsIterator extends IntlIterator { /** @tentative-return-type */ public function getBreakIterator(): IntlBreakIterator {} + + /** @tentative-return-type */ + public function getRuleStatus(): int {} } diff --git a/ext/intl/breakiterator/breakiterator_iterators_arginfo.h b/ext/intl/breakiterator/breakiterator_iterators_arginfo.h index 9b8503905c9..ee5e1279b5d 100644 --- a/ext/intl/breakiterator/breakiterator_iterators_arginfo.h +++ b/ext/intl/breakiterator/breakiterator_iterators_arginfo.h @@ -1,15 +1,20 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: e99b1e4a81bff12f44d22075d4b9f3f4627b1050 */ + * Stub hash: 267199a0a3532b5acf1d700f14329cdb2f2db0e1 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_IntlPartsIterator_getBreakIterator, 0, 0, IntlBreakIterator, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlPartsIterator_getRuleStatus, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + ZEND_METHOD(IntlPartsIterator, getBreakIterator); +ZEND_METHOD(IntlPartsIterator, getRuleStatus); static const zend_function_entry class_IntlPartsIterator_methods[] = { ZEND_ME(IntlPartsIterator, getBreakIterator, arginfo_class_IntlPartsIterator_getBreakIterator, ZEND_ACC_PUBLIC) + ZEND_ME(IntlPartsIterator, getRuleStatus, arginfo_class_IntlPartsIterator_getRuleStatus, ZEND_ACC_PUBLIC) ZEND_FE_END };