Skip to content

Commit a5ad9ee

Browse files
committed
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.
1 parent bb9ef2b commit a5ad9ee

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

ext/intl/breakiterator/breakiterator_iterators.cpp

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#include "../intl_convert.h"
2929
#include "../locale/locale.h"
3030
#include <zend_exceptions.h>
31+
#include <zend_interfaces.h>
3132
}
3233

3334
static zend_class_entry *IntlPartsIterator_ce_ptr;
@@ -229,49 +230,20 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv,
229230
((zoi_break_iter_parts*)ii->iterator)->key_type = key_type;
230231
}
231232

232-
U_CFUNC zend_object *IntlPartsIterator_object_create(zend_class_entry *ce)
233-
{
234-
zend_object *retval = IntlIterator_ce_ptr->create_object(ce);
235-
retval->handlers = &IntlPartsIterator_handlers;
236-
237-
return retval;
238-
}
239-
240-
U_CFUNC zend_function *IntlPartsIterator_get_method(zend_object **object_ptr, zend_string *method, const zval *key)
233+
U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator)
241234
{
242-
zend_function *ret;
243-
zend_string *lc_method_name;
244-
ALLOCA_FLAG(use_heap);
245-
246-
if (key == NULL) {
247-
ZSTR_ALLOCA_ALLOC(lc_method_name, ZSTR_LEN(method), use_heap);
248-
zend_str_tolower_copy(ZSTR_VAL(lc_method_name), ZSTR_VAL(method), ZSTR_LEN(method));
249-
} else {
250-
lc_method_name = Z_STR_P(key);
251-
}
235+
INTLITERATOR_METHOD_INIT_VARS;
252236

253-
if (ZSTR_LEN(method) == sizeof("getrulestatus") - 1
254-
&& memcmp("getrulestatus", ZSTR_VAL(lc_method_name), ZSTR_LEN(lc_method_name)) == 0) {
255-
IntlIterator_object *obj = php_intl_iterator_fetch_object(*object_ptr);
256-
if (obj->iterator && !Z_ISUNDEF(obj->iterator->data)) {
257-
zval *break_iter_zv = &obj->iterator->data;
258-
*object_ptr = Z_OBJ_P(break_iter_zv);
259-
ret = Z_OBJ_HANDLER_P(break_iter_zv, get_method)(object_ptr, method, key);
260-
goto end;
261-
}
237+
if (zend_parse_parameters_none() == FAILURE) {
238+
RETURN_THROWS();
262239
}
263240

264-
ret = zend_std_get_method(object_ptr, method, key);
265-
266-
end:
267-
if (key == NULL) {
268-
ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
269-
}
241+
INTLITERATOR_METHOD_FETCH_OBJECT;
270242

271-
return ret;
243+
RETURN_COPY_DEREF(&ii->iterator->data);
272244
}
273245

274-
U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator)
246+
U_CFUNC PHP_METHOD(IntlPartsIterator, getRuleStatus)
275247
{
276248
INTLITERATOR_METHOD_INIT_VARS;
277249

@@ -281,18 +253,16 @@ U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator)
281253

282254
INTLITERATOR_METHOD_FETCH_OBJECT;
283255

284-
RETURN_COPY_DEREF(&ii->iterator->data);
256+
zval *iter = &ii->iterator->data;
257+
ZEND_ASSERT(Z_TYPE_P(iter) == IS_OBJECT);
258+
zend_call_method_with_0_params(
259+
Z_OBJ_P(iter), Z_OBJCE_P(iter), NULL, "getrulestatus", return_value);
285260
}
286261

287262
U_CFUNC void breakiterator_register_IntlPartsIterator_class(void)
288263
{
289264
/* Create and register 'BreakIterator' class. */
290265
IntlPartsIterator_ce_ptr = register_class_IntlPartsIterator(IntlIterator_ce_ptr);
291-
IntlPartsIterator_ce_ptr->create_object = IntlPartsIterator_object_create;
292-
293-
memcpy(&IntlPartsIterator_handlers, &IntlIterator_handlers,
294-
sizeof IntlPartsIterator_handlers);
295-
IntlPartsIterator_handlers.get_method = IntlPartsIterator_get_method;
296266

297267
#define PARTSITER_DECL_LONG_CONST(name) \
298268
zend_declare_class_constant_long(IntlPartsIterator_ce_ptr, #name, \

ext/intl/breakiterator/breakiterator_iterators.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ class IntlPartsIterator extends IntlIterator
66
{
77
/** @tentative-return-type */
88
public function getBreakIterator(): IntlBreakIterator {}
9+
10+
/** @tentative-return-type */
11+
public function getRuleStatus(): int {}
912
}

ext/intl/breakiterator/breakiterator_iterators_arginfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: e99b1e4a81bff12f44d22075d4b9f3f4627b1050 */
2+
* Stub hash: 267199a0a3532b5acf1d700f14329cdb2f2db0e1 */
33

44
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_IntlPartsIterator_getBreakIterator, 0, 0, IntlBreakIterator, 0)
55
ZEND_END_ARG_INFO()
66

7+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlPartsIterator_getRuleStatus, 0, 0, IS_LONG, 0)
8+
ZEND_END_ARG_INFO()
9+
710

811
ZEND_METHOD(IntlPartsIterator, getBreakIterator);
12+
ZEND_METHOD(IntlPartsIterator, getRuleStatus);
913

1014

1115
static const zend_function_entry class_IntlPartsIterator_methods[] = {
1216
ZEND_ME(IntlPartsIterator, getBreakIterator, arginfo_class_IntlPartsIterator_getBreakIterator, ZEND_ACC_PUBLIC)
17+
ZEND_ME(IntlPartsIterator, getRuleStatus, arginfo_class_IntlPartsIterator_getRuleStatus, ZEND_ACC_PUBLIC)
1318
ZEND_FE_END
1419
};
1520

0 commit comments

Comments
 (0)