From: Tyler Christensen Date: Wed, 2 Dec 2020 00:13:29 +0000 (-0700) Subject: [PATCH] THRIFT-5318: Update PHP thrift_protocol extension for PHP 8 Client: php Patch... X-Git-Tag: archive/raspbian/0.13.0-7+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=998851d0e4113db7873c5e3b99fd4870d729f74c;p=thrift.git [PATCH] THRIFT-5318: Update PHP thrift_protocol extension for PHP 8 Client: php Patch: Tyler Christensen & Rasmus Lerdorf This closes #2288 See https://github.com/php/php-src/blob/PHP-8.0.0/UPGRADING.INTERNALS Origin: backport, https://github.com/apache/thrift/commit/b04e39a7e91d7828cce916 Reviewed-By: Lucas Kanashiro Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/thrift/+bug/1940473 Bug: https://issues.apache.org/jira/projects/THRIFT/issues/THRIFT-5318?filter=allissues Last-Updated: 2021-08-18 Gbp-Pq: Name THRIFT-5318_support_php8.patch --- diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp index e152d08..cf06cbf 100644 --- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp +++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp @@ -85,17 +85,10 @@ const int8_t T_EXCEPTION = 3; const int INVALID_DATA = 1; const int BAD_VERSION = 4; -static zend_function_entry thrift_protocol_functions[] = { - PHP_FE(thrift_protocol_write_binary, nullptr) - PHP_FE(thrift_protocol_read_binary, nullptr) - PHP_FE(thrift_protocol_read_binary_after_message_begin, nullptr) - {nullptr, nullptr, nullptr} -}; - zend_module_entry thrift_protocol_module_entry = { STANDARD_MODULE_HEADER, "thrift_protocol", - thrift_protocol_functions, + ext_functions, nullptr, nullptr, nullptr, @@ -414,7 +407,7 @@ void createObject(const char* obj_typename, zval* return_value, int nargs = 0, z object_and_properties_init(return_value, ce, nullptr); zend_function* constructor = zend_std_get_constructor(Z_OBJ_P(return_value)); zval ctor_rv; - zend_call_method(return_value, ce, &constructor, NULL, 0, &ctor_rv, nargs, arg1, arg2); + zend_call_method(Z4_OBJ_P(return_value), ce, &constructor, NULL, 0, &ctor_rv, nargs, arg1, arg2); zval_dtor(&ctor_rv); if (EG(exception)) { zend_object *ex = EG(exception); @@ -928,7 +921,7 @@ void validate_thrift_object(zval* object) { zval* is_required = zend_hash_str_find(fieldspec, "isRequired", sizeof("isRequired")-1); zval rv; - zval* prop = zend_read_property(object_class_entry, object, varname, strlen(varname), false, &rv); + zval* prop = zend_read_property(object_class_entry, Z4_OBJ_P(object), varname, strlen(varname), false, &rv); if (Z_TYPE_INFO_P(is_required) == IS_TRUE && Z_TYPE_P(prop) == IS_NULL) { char errbuf[128]; @@ -969,7 +962,7 @@ void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTabl ZVAL_UNDEF(&rv); binary_deserialize(ttype, transport, &rv, fieldspec); - zend_update_property(ce, zthis, varname, strlen(varname), &rv); + zend_update_property(ce, Z4_OBJ_P(zthis), varname, strlen(varname), &rv); zval_ptr_dtor(&rv); } else { @@ -1010,7 +1003,7 @@ void binary_serialize_spec(zval* zthis, PHPOutputTransport& transport, HashTable int8_t ttype = Z_LVAL_P(val_ptr); zval rv; - zval* prop = zend_read_property(Z_OBJCE_P(zthis), zthis, varname, strlen(varname), false, &rv); + zval* prop = zend_read_property(Z_OBJCE_P(zthis), Z4_OBJ_P(zthis), varname, strlen(varname), false, &rv); if (Z_TYPE_P(prop) == IS_REFERENCE){ ZVAL_DEREF(prop); diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.h b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.h index 0420997..b8dc7de 100644 --- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.h +++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.h @@ -19,10 +19,58 @@ #pragma once -PHP_FUNCTION(thrift_protocol_write_binary); -PHP_FUNCTION(thrift_protocol_read_binary); -PHP_FUNCTION(thrift_protocol_read_binary_after_message_begin); +/* backward compat macros */ -extern zend_module_entry thrift_protocol_module_entry; -#define phpext_thrift_protocol_ptr &thrift_protocol_module_entry +#if PHP_VERSION_ID >= 80000 +# define Z4_OBJ_P(zval) (Z_OBJ_P(zval)) +#else +# define Z4_OBJ_P(zval) (zval) +#endif +#ifndef IS_MIXED +# define IS_MIXED 0 +#endif + +#ifndef ZEND_PARSE_PARAMETERS_NONE +#define ZEND_PARSE_PARAMETERS_NONE() \ + ZEND_PARSE_PARAMETERS_START(0, 0) \ + ZEND_PARSE_PARAMETERS_END() +#endif +#ifndef ZEND_ARG_INFO_WITH_DEFAULT_VALUE +#define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \ + ZEND_ARG_INFO(pass_by_ref, name) +#endif + +#if PHP_VERSION_ID < 70200 +#undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX +#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ + static const zend_internal_arg_info name[] = { \ + { (const char*)(zend_uintptr_t)(required_num_args), ( #class_name ), 0, return_reference, allow_null, 0 }, +#endif + +#ifndef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX +# define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) +#endif + +#ifndef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX +# define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(name, return_reference, num_args, type) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, num_args) +#endif + +#ifndef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX +# define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) +#endif + +#ifndef ZEND_ARG_TYPE_MASK +# define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) \ + ZEND_ARG_TYPE_INFO(pass_by_ref, name, 0, 0) +#endif + +#ifndef ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE +# define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \ + ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) +#endif + +#include "php_thrift_protocol_arginfo.h" diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php new file mode 100644 index 0000000..e9601c3 --- /dev/null +++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php @@ -0,0 +1,10 @@ +