From acd765555fa5ae6444093fba17783af05ae09cd0 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 10 Nov 2021 09:33:07 +0100 Subject: [PATCH] PHP-8.2 compat with __toString --- src/php_http_cookie.c | 39 ++++++++++++++++++++----------------- src/php_http_header.c | 22 +++++++++++---------- src/php_http_message.c | 5 +++-- src/php_http_message_body.c | 13 ++++++++----- src/php_http_params.c | 6 ++++-- src/php_http_querystring.c | 39 ++++++++++++++++++++----------------- src/php_http_url.c | 6 ++++-- 7 files changed, 73 insertions(+), 57 deletions(-) diff --git a/src/php_http_cookie.c b/src/php_http_cookie.c index ecdf94e..dd4c6c6 100644 --- a/src/php_http_cookie.c +++ b/src/php_http_cookie.c @@ -17,16 +17,16 @@ php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list) if (!list) { list = emalloc(sizeof(*list)); } - + zend_hash_init(&list->cookies, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_init(&list->extras, 0, NULL, ZVAL_PTR_DTOR, 0); - + list->path = NULL; list->domain = NULL; list->expires = -1; list->max_age = -1; list->flags = 0; - + return list; } @@ -51,7 +51,7 @@ void php_http_cookie_list_dtor(php_http_cookie_list_t *list) if (list) { zend_hash_destroy(&list->cookies); zend_hash_destroy(&list->extras); - + PTR_SET(list->path, NULL); PTR_SET(list->domain, NULL); } @@ -206,15 +206,15 @@ void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct) { zval cookies, extras, tmp; HashTable *ht = HASH_OF(strct); - + array_init_size(&cookies, zend_hash_num_elements(&list->cookies)); array_copy(&list->cookies, Z_ARRVAL(cookies)); zend_symtable_str_update(ht, ZEND_STRL("cookies"), &cookies); - + array_init_size(&extras, zend_hash_num_elements(&list->extras)); array_copy(&list->extras, Z_ARRVAL(extras)); zend_symtable_str_update(ht, ZEND_STRL("extras"), &extras); - + ZVAL_LONG(&tmp, list->flags); zend_symtable_str_update(ht, ZEND_STRL("flags"), &tmp); ZVAL_LONG(&tmp, list->expires); @@ -286,22 +286,22 @@ php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t list->domain = estrndup(str->val, str->len); zend_string_release(str); } - + return list; } static inline void append_encoded(php_http_buffer_t *buf, const char *key, size_t key_len, const char *val, size_t val_len) { zend_string *enc_str[2]; - + enc_str[0] = php_raw_url_encode(key, key_len); enc_str[1] = php_raw_url_encode(val, val_len); - + php_http_buffer_append(buf, enc_str[0]->val, enc_str[0]->len); php_http_buffer_appends(buf, "="); php_http_buffer_append(buf, enc_str[1]->val, enc_str[1]->len); php_http_buffer_appends(buf, "; "); - + zend_string_release(enc_str[0]); zend_string_release(enc_str[1]); } @@ -311,7 +311,7 @@ void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, si php_http_buffer_t buf; zend_hash_key key; zval *val; - + php_http_buffer_init(&buf); ZEND_HASH_FOREACH_KEY_VAL(&list->cookies, key.h, key.key, val) @@ -325,7 +325,7 @@ void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, si zend_string_release(str); } ZEND_HASH_FOREACH_END(); - + if (list->domain && *list->domain) { php_http_buffer_appendf(&buf, "domain=%s; ", list->domain); } @@ -340,7 +340,7 @@ void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, si if (list->max_age >= 0) { php_http_buffer_appendf(&buf, "max-age=%ld; ", list->max_age); } - + ZEND_HASH_FOREACH_KEY_VAL(&list->extras, key.h, key.key, val) { zend_string *str = zval_get_string(val); @@ -352,14 +352,14 @@ void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, si zend_string_release(str); } ZEND_HASH_FOREACH_END(); - + if (list->flags & PHP_HTTP_COOKIE_SECURE) { php_http_buffer_appends(&buf, "secure; "); } if (list->flags & PHP_HTTP_COOKIE_HTTPONLY) { php_http_buffer_appends(&buf, "httpOnly; "); } - + php_http_buffer_fix(&buf); *str = buf.data; *len = buf.used; @@ -943,7 +943,7 @@ static PHP_METHOD(HttpCookie, setFlags) } ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_toString, 0, 0, 0) -ZEND_END_ARG_INFO();; +ZEND_END_ARG_INFO(); static PHP_METHOD(HttpCookie, toString) { php_http_cookie_object_t *obj; @@ -981,6 +981,9 @@ static PHP_METHOD(HttpCookie, toArray) php_http_cookie_list_to_struct(obj->list, return_value); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpCookie___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_cookie_methods[] = { PHP_ME(HttpCookie, __construct, ai_HttpCookie___construct, ZEND_ACC_PUBLIC) PHP_ME(HttpCookie, getCookies, ai_HttpCookie_getCookies, ZEND_ACC_PUBLIC) @@ -1010,7 +1013,7 @@ static zend_function_entry php_http_cookie_methods[] = { PHP_ME(HttpCookie, toArray, ai_HttpCookie_toArray, ZEND_ACC_PUBLIC) PHP_ME(HttpCookie, toString, ai_HttpCookie_toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpCookie, __toString, toString, ai_HttpCookie_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpCookie, __toString, toString, ai_HttpCookie___toString, ZEND_ACC_PUBLIC) EMPTY_FUNCTION_ENTRY }; diff --git a/src/php_http_header.c b/src/php_http_header.c index c9b1e0d..c475a81 100644 --- a/src/php_http_header.c +++ b/src/php_http_header.c @@ -17,18 +17,18 @@ ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTa php_http_header_parser_t ctx; php_http_buffer_t buf; php_http_header_parser_state_t rs; - + if (!php_http_buffer_from_string_ex(&buf, header, length)) { php_error_docref(NULL, E_WARNING, "Could not allocate buffer"); return FAILURE; } - + if (!php_http_header_parser_init(&ctx)) { php_http_buffer_dtor(&buf); php_error_docref(NULL, E_WARNING, "Could not initialize header parser"); return FAILURE; } - + rs = php_http_header_parser_parse(&ctx, &buf, PHP_HTTP_HEADER_PARSER_CLEANUP, headers, callback_func, callback_data); php_http_header_parser_dtor(&ctx); php_http_buffer_dtor(&buf); @@ -362,21 +362,21 @@ ZEND_END_ARG_INFO(); PHP_METHOD(HttpHeader, getParams) { zval value_tmp, zctor, zparams_obj, *zargs = NULL; - + ZVAL_STRINGL(&zctor, "__construct", lenof("__construct")); - + object_init_ex(&zparams_obj, php_http_params_get_class_entry()); - + zargs = (zval *) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval)); ZVAL_COPY_VALUE(&zargs[0], zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value_tmp)); if (ZEND_NUM_ARGS()) { zend_get_parameters_array(ZEND_NUM_ARGS(), ZEND_NUM_ARGS(), &zargs[1]); } - + if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs)) { RETVAL_ZVAL(&zparams_obj, 0, 1); } - + zval_ptr_dtor(&zctor); if (zargs) { efree(zargs); @@ -432,14 +432,17 @@ PHP_METHOD(HttpHeader, parse) } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_header_methods[] = { PHP_ME(HttpHeader, __construct, ai_HttpHeader___construct, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, __unserialize, ai_HttpHeader___unserialize, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, __serialize, ai_HttpHeader___serialize, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, match, ai_HttpHeader_match, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, negotiate, ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC) PHP_ME(HttpHeader, getParams, ai_HttpHeader_getParams, ZEND_ACC_PUBLIC) @@ -473,4 +476,3 @@ PHP_MINIT_FUNCTION(http_header) * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - diff --git a/src/php_http_message.c b/src/php_http_message.c index ac3c641..b82ec0e 100644 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@ -1699,8 +1699,6 @@ static PHP_METHOD(HttpMessage, getParentMessage) RETVAL_OBJECT(&obj->parent->zo, 1); } -ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0) -ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString, 0, 0, 0) ZEND_ARG_INFO(0, include_parent) ZEND_END_ARG_INFO(); @@ -2060,6 +2058,9 @@ static PHP_METHOD(HttpMessage, current) } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_message_methods[] = { PHP_ME(HttpMessage, __construct, ai_HttpMessage___construct, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, getBody, ai_HttpMessage_getBody, ZEND_ACC_PUBLIC) diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index 90714d9..8bde1a7 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -670,9 +670,9 @@ PHP_METHOD(HttpMessageBody, __construct) } } -ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody___toString, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_serialize, 0, 0, 0) ZEND_END_ARG_INFO(); -PHP_METHOD(HttpMessageBody, __toString) +PHP_METHOD(HttpMessageBody, serialize) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis()); @@ -951,11 +951,14 @@ PHP_METHOD(HttpMessageBody, stat) } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessageBody___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_message_body_methods[] = { PHP_ME(HttpMessageBody, __construct, ai_HttpMessageBody___construct, ZEND_ACC_PUBLIC) - PHP_ME(HttpMessageBody, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) - PHP_MALIAS(HttpMessageBody, toString, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) - PHP_MALIAS(HttpMessageBody, serialize, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, serialize, ai_HttpMessageBody_serialize, ZEND_ACC_PUBLIC) + PHP_MALIAS(HttpMessageBody, toString, serialize, ai_HttpMessageBody_serialize, ZEND_ACC_PUBLIC) + PHP_MALIAS(HttpMessageBody, __toString, serialize, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpMessageBody, unserialize, ai_HttpMessageBody_unserialize, ZEND_ACC_PUBLIC) PHP_ME(HttpMessageBody, __serialize, ai_HttpMessageBody___serialize, ZEND_ACC_PUBLIC) PHP_ME(HttpMessageBody, __unserialize,ai_HttpMessageBody___unserialize,ZEND_ACC_PUBLIC) diff --git a/src/php_http_params.c b/src/php_http_params.c index b04af04..f40b89f 100644 --- a/src/php_http_params.c +++ b/src/php_http_params.c @@ -1290,12 +1290,15 @@ PHP_METHOD(HttpParams, offsetSet) } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_params_methods[] = { PHP_ME(HttpParams, __construct, ai_HttpParams___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(HttpParams, toArray, ai_HttpParams_toArray, ZEND_ACC_PUBLIC) PHP_ME(HttpParams, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpParams, __toString, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpParams, __toString, toString, ai_HttpParams___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpParams, offsetExists, ai_HttpParams_offsetExists, ZEND_ACC_PUBLIC) PHP_ME(HttpParams, offsetUnset, ai_HttpParams_offsetUnset, ZEND_ACC_PUBLIC) @@ -1345,4 +1348,3 @@ PHP_MINIT_FUNCTION(http_params) * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - diff --git a/src/php_http_querystring.c b/src/php_http_querystring.c index 7ef5a20..06d52c5 100644 --- a/src/php_http_querystring.c +++ b/src/php_http_querystring.c @@ -98,7 +98,7 @@ ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie zval *entry; zend_string *xkey, *xstr; php_http_arrkey_t key; - + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(src), key.h, key.key, entry) { if (key.key) { @@ -107,7 +107,7 @@ ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie return FAILURE; } } - + if (Z_TYPE_P(entry) == IS_STRING) { if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_P(entry), Z_STRLEN_P(entry), &xstr, oe, ie)) { if (key.key) { @@ -123,7 +123,7 @@ ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie } } else if (Z_TYPE_P(entry) == IS_ARRAY) { zval subarray; - + array_init(&subarray); if (key.key) { add_assoc_zval_ex(dst, xkey->val, xkey->len, &subarray); @@ -137,7 +137,7 @@ ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie return FAILURE; } } - + if (key.key) { zend_string_release(xkey); } @@ -357,7 +357,7 @@ PHP_METHOD(HttpQueryString, __construct) { zval *params = NULL; zend_error_handling zeh; - + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z", ¶ms), invalid_arg, return); zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh); @@ -446,7 +446,7 @@ PHP_METHOD(HttpQueryString, get) zend_long type = 0; zend_bool del = 0; zval *ztype = NULL, *defval = NULL; - + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|szzb", &name_str, &name_len, &ztype, &defval, &del)) { if (name_str && name_len) { if (ztype) { @@ -454,7 +454,7 @@ PHP_METHOD(HttpQueryString, get) type = Z_LVAL_P(ztype); } else if(Z_TYPE_P(ztype) == IS_STRING) { switch (Z_STRVAL_P(ztype)[0]) { - case 'B': + case 'B': case 'b': type = PHP_HTTP_QUERYSTRING_TYPE_BOOL; break; case 'L': case 'l': @@ -463,7 +463,7 @@ PHP_METHOD(HttpQueryString, get) case 'd': case 'D': case 'F': - case 'f': type = PHP_HTTP_QUERYSTRING_TYPE_FLOAT; break; + case 'f': type = PHP_HTTP_QUERYSTRING_TYPE_FLOAT; break; case 'S': case 's': type = PHP_HTTP_QUERYSTRING_TYPE_STRING; break; case 'A': @@ -486,11 +486,11 @@ ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, set) { zval *params; - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms)) { return; } - + php_http_querystring_set(getThis(), params, QS_MERGE); RETVAL_ZVAL(getThis(), 1, 0); } @@ -504,7 +504,7 @@ PHP_METHOD(HttpQueryString, mod) zend_error_handling zeh; php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms), invalid_arg, return); - + zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh); ZVAL_OBJ(return_value, Z_OBJ_HT_P(instance)->clone_obj(Z_OBJ_P(instance))); /* make sure we do not inherit the reference to _GET */ @@ -561,7 +561,7 @@ PHP_METHOD(HttpQueryString, xlate) php_http_querystring_set(getThis(), &na, 0); RETVAL_ZVAL(getThis(), 1, 0); - + zval_ptr_dtor(&na); } #endif /* HAVE_ICONV */ @@ -605,7 +605,7 @@ ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, unserialize) { zval *serialized; - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "z", &serialized)) { return; } @@ -628,7 +628,7 @@ PHP_METHOD(HttpQueryString, offsetGet) if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) { return; } - + qa = zend_read_property(php_http_querystring_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("queryArray"), 0, &qa_tmp); ZVAL_DEREF(qa); @@ -647,7 +647,7 @@ PHP_METHOD(HttpQueryString, offsetSet) { zend_string *offset; zval *value, param, znull; - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &offset, &value)) { return; } @@ -675,7 +675,7 @@ PHP_METHOD(HttpQueryString, offsetExists) if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) { return; } - + qa = zend_read_property(php_http_querystring_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("queryArray"), 0, &qa_tmp); ZVAL_DEREF(qa); @@ -694,7 +694,7 @@ PHP_METHOD(HttpQueryString, offsetUnset) { zend_string *offset; zval param, znull; - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) { return; } @@ -706,12 +706,15 @@ PHP_METHOD(HttpQueryString, offsetUnset) zval_ptr_dtor(¶m); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_querystring_methods[] = { PHP_ME(HttpQueryString, __construct, ai_HttpQueryString___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(HttpQueryString, toArray, ai_HttpQueryString_toArray, ZEND_ACC_PUBLIC) PHP_ME(HttpQueryString, toString, ai_HttpQueryString_toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpQueryString, __toString, toString, ai_HttpQueryString_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpQueryString, __toString, toString, ai_HttpQueryString___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpQueryString, get, ai_HttpQueryString_get, ZEND_ACC_PUBLIC) PHP_ME(HttpQueryString, set, ai_HttpQueryString_set, ZEND_ACC_PUBLIC) diff --git a/src/php_http_url.c b/src/php_http_url.c index 21e38e2..943a436 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -2034,11 +2034,14 @@ PHP_METHOD(HttpUrl, toArray) php_http_url_free(&purl); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpUrl___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO(); + static zend_function_entry php_http_url_methods[] = { PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC) PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC) PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl___toString, ZEND_ACC_PUBLIC) PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC) EMPTY_FUNCTION_ENTRY }; @@ -2108,4 +2111,3 @@ PHP_MINIT_FUNCTION(http_url) * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - -- 2.30.2