Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ PHP 8.6 INTERNALS UPGRADE NOTES
zend_enum_RoundingMode parameter.
. Added Z_PARAM_ENUM().
. Added zend_enum_fetch_case_id().
. Added zend_enum_get_case_by_id().
. ZEND_INI_GET_ADDR() is now a void* pointer instead of a char* pointer. This
more correctly represents the generic nature of the returned pointer and
allows to remove explicit casts, but possibly breaks pointer arithmetic
Expand Down
5 changes: 5 additions & 0 deletions Zend/zend_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *
return zend_enum_case_from_class_constant(c);
}

ZEND_API zend_object *zend_enum_get_case_by_id(zend_class_entry *ce, int id) {
zend_class_constant *c = Z_PTR(CE_CONSTANTS_TABLE(ce)->arData[id - 1].val);
return zend_enum_case_from_class_constant(c);
}

void zend_enum_startup(void)
{
for (size_t i = 0; i < sizeof(zarginfo_class_UnitEnum_cases)/sizeof(zend_arg_info); i++) {
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ZEND_API void zend_enum_add_case(zend_class_entry *ce, zend_string *case_name, z
ZEND_API void zend_enum_add_case_cstr(zend_class_entry *ce, const char *name, zval *value);
ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name);
ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name);
ZEND_API zend_object *zend_enum_get_case_by_id(zend_class_entry *ce, int id);
ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try_from);

static zend_always_inline int zend_enum_fetch_case_id(zend_object *zobj)
Expand Down
15 changes: 8 additions & 7 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ typedef psetid_t cpu_set_t;
#include "Zend/zend_max_execution_timer.h"

#include "pcntl_arginfo.h"
#include "pcntl_decl.h"
static zend_class_entry *QosClass_ce;

ZEND_DECLARE_MODULE_GLOBALS(pcntl)
Expand Down Expand Up @@ -1839,28 +1840,28 @@ static qos_class_t qos_enum_to_pthread(zend_enum_Pcntl_QosClass entry)

static zend_object *qos_lval_to_zval(qos_class_t qos_class)
{
const char *entryname;
int entry_id;
switch (qos_class)
{
case QOS_CLASS_USER_INTERACTIVE:
entryname = "UserInteractive";
entry_id = ZEND_ENUM_Pcntl_QosClass_UserInteractive;
break;
case QOS_CLASS_USER_INITIATED:
entryname = "UserInitiated";
entry_id = ZEND_ENUM_Pcntl_QosClass_UserInitiated;
break;
case QOS_CLASS_UTILITY:
entryname = "Utility";
entry_id = ZEND_ENUM_Pcntl_QosClass_Utility;
break;
case QOS_CLASS_BACKGROUND:
entryname = "Background";
entry_id = ZEND_ENUM_Pcntl_QosClass_Background;
break;
case QOS_CLASS_DEFAULT:
default:
entryname = "Default";
entry_id = ZEND_ENUM_Pcntl_QosClass_Default;
break;
}

return zend_enum_get_case_cstr(QosClass_ce, entryname);
return zend_enum_get_case_by_id(QosClass_ce, entry_id);
}

PHP_FUNCTION(pcntl_getqos_class)
Expand Down
22 changes: 8 additions & 14 deletions ext/standard/io_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "php_network.h"
#include "php_poll.h"
#include "io_poll_arginfo.h"
#include "io_poll_decl.h"

/* Class entries */
static zend_class_entry *php_io_poll_backend_class_entry;
Expand Down Expand Up @@ -118,38 +119,31 @@ static zend_result php_io_poll_events_to_event_enums(uint32_t events, zval *even
array_init(event_enums);

if (events & PHP_POLL_READ) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "Read"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_Read));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_WRITE) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "Write"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_Write));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_ERROR) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "Error"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_Error));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_HUP) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "HangUp"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_HangUp));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_RDHUP) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "ReadHangUp"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_ReadHangUp));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_ONESHOT) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "OneShot"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_OneShot));
add_next_index_zval(event_enums, &enum_case);
}
if (events & PHP_POLL_ET) {
ZVAL_OBJ(&enum_case, zend_enum_get_case_cstr(php_io_poll_event_class_entry, "EdgeTriggered"));
GC_ADDREF(Z_OBJ(enum_case));
ZVAL_OBJ_COPY(&enum_case, zend_enum_get_case_by_id(php_io_poll_event_class_entry, ZEND_ENUM_Io_Poll_Event_EdgeTriggered));
add_next_index_zval(event_enums, &enum_case);
}

Expand Down
24 changes: 12 additions & 12 deletions ext/uri/uri_parser_rfc3986.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ ZEND_ATTRIBUTE_NONNULL void php_uri_parser_rfc3986_uri_type_read(php_uri_parser_
{
const UriUriA *uriparser_uri = get_uri_for_reading(uri, PHP_URI_COMPONENT_READ_MODE_RAW);

const char *type;
zend_object *value;

if (has_text_range(&uriparser_uri->scheme)) {
type = "Uri";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_type, ZEND_ENUM_Uri_Rfc3986_UriType_Uri);
} else if (has_text_range(&uriparser_uri->hostText)) {
type = "NetworkPathReference";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_type, ZEND_ENUM_Uri_Rfc3986_UriType_NetworkPathReference);
} else if (uriparser_uri->absolutePath) {
type = "AbsolutePathReference";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_type, ZEND_ENUM_Uri_Rfc3986_UriType_AbsolutePathReference);
} else {
type = "RelativePathReference";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_type, ZEND_ENUM_Uri_Rfc3986_UriType_RelativePathReference);
}

ZVAL_OBJ_COPY(retval, zend_enum_get_case_cstr(php_uri_ce_rfc3986_uri_type, type));
ZVAL_OBJ_COPY(retval, value);
}

ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_scheme_read(void *uri, const php_uri_component_read_mode read_mode, zval *retval)
Expand Down Expand Up @@ -290,19 +290,19 @@ ZEND_ATTRIBUTE_NONNULL void php_uri_parser_rfc3986_host_type_read(php_uri_parser
return;
}

const char *type;
zend_object *value;

if (uriparser_uri->hostData.ip4 != NULL) {
type = "IPv4";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_host_type, ZEND_ENUM_Uri_Rfc3986_UriHostType_IPv4);
} else if (uriparser_uri->hostData.ip6 != NULL) {
type = "IPv6";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_host_type, ZEND_ENUM_Uri_Rfc3986_UriHostType_IPv6);
} else if (has_text_range(&uriparser_uri->hostData.ipFuture)) {
type = "IPvFuture";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_host_type, ZEND_ENUM_Uri_Rfc3986_UriHostType_IPvFuture);
} else {
type = "RegisteredName";
value = zend_enum_get_case_by_id(php_uri_ce_rfc3986_uri_host_type, ZEND_ENUM_Uri_Rfc3986_UriHostType_RegisteredName);
}

ZVAL_OBJ_COPY(retval, zend_enum_get_case_cstr(php_uri_ce_rfc3986_uri_host_type, type));
ZVAL_OBJ_COPY(retval, value);
}

static zend_result php_uri_parser_rfc3986_host_write(void *uri, const zval *value, zval *errors)
Expand Down
3 changes: 2 additions & 1 deletion ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "zend_mm_custom_handlers.h"
#include "ext/uri/php_uri.h"
#include "zend_observer.h"
#include "test_decl.h"

#if defined(HAVE_LIBXML) && !defined(PHP_WIN32)
# include <libxml/globals.h>
Expand Down Expand Up @@ -622,7 +623,7 @@ static ZEND_FUNCTION(zend_get_unit_enum)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_OBJ_COPY(zend_enum_get_case_cstr(zend_test_unit_enum, "Foo"));
RETURN_OBJ_COPY(zend_enum_get_case_by_id(zend_test_unit_enum, ZEND_ENUM_ZendTestUnitEnum_Foo));
}

static ZEND_FUNCTION(zend_test_zend_ini_parse_quantity)
Expand Down
1 change: 1 addition & 0 deletions main/streams/stream_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static void php_stream_error_create_object(zval *zv, php_stream_error_entry *ent
case_name = "Generic";
}

/* TODO: migrate to zend_enum_get_case_by_id() */
zend_object *enum_obj = zend_enum_get_case_cstr(php_ce_stream_error_code, case_name);
ZEND_ASSERT(enum_obj != NULL);

Expand Down
Loading