|
19 | 19 | static php_socket_t php_poll_handle_default_get_fd(php_poll_handle_object *handle) |
20 | 20 | { |
21 | 21 | zval retval; |
22 | | - zval obj; |
23 | | - zval func_name; |
24 | 22 |
|
25 | | - ZVAL_OBJ(&obj, &handle->std); |
26 | | - |
27 | | - /* Prepare function name as zval */ |
28 | | - ZVAL_STRING(&func_name, "getFileDescriptor"); |
| 23 | + /* Grab getFileDescriptor() method pointer which is stored in lowercase in the function table */ |
| 24 | + zend_function *method = zend_hash_str_find_ptr_lc(&handle->std.ce->function_table, ZEND_STRL("getfiledescriptor")); |
| 25 | + ZEND_ASSERT(method && "no default method???"); |
29 | 26 |
|
30 | 27 | /* Call getFileDescriptor() method */ |
31 | | - if (EXPECTED(call_user_function(NULL, &obj, &func_name, &retval, 0, NULL) == SUCCESS)) { |
32 | | - if (Z_TYPE(retval) == IS_LONG) { |
33 | | - php_socket_t fd = Z_LVAL(retval) < 0 ? SOCK_ERR : (php_socket_t) Z_LVAL(retval); |
34 | | - zval_ptr_dtor(&retval); |
35 | | - zval_ptr_dtor(&func_name); /* Clean up function name */ |
36 | | - return fd; |
37 | | - } |
38 | | - zval_ptr_dtor(&retval); |
| 28 | + zend_call_known_function(method, &handle->std, handle->std.ce, &retval, 0, NULL, NULL); |
| 29 | + |
| 30 | + /* No need to deref the return value as the class is final and thus the method cannot be changed to return by-ref */ |
| 31 | + if (EXPECTED(Z_TYPE(retval) == IS_LONG)) { |
| 32 | + php_socket_t fd = Z_LVAL(retval) < 0 ? SOCK_ERR : (php_socket_t) Z_LVAL(retval); |
| 33 | + /* No need to clean the retval as we know it is an integer, and thus it's just on the stack */ |
| 34 | + return fd; |
39 | 35 | } |
40 | 36 |
|
41 | | - zval_ptr_dtor(&func_name); /* Clean up function name */ |
| 37 | + zval_ptr_dtor(&retval); |
42 | 38 | return SOCK_ERR; /* Invalid socket */ |
43 | 39 | } |
44 | 40 |
|
|
0 commit comments