[PATCH] THRIFT-5318: Update PHP thrift_protocol extension for PHP 8 Client: php Patch...
authorTyler Christensen <tylerc@qualtrics.com>
Wed, 2 Dec 2020 00:13:29 +0000 (17:13 -0700)
committerLaszlo Boszormenyi (GCS) <gcs@debian.org>
Fri, 24 Sep 2021 15:18:04 +0000 (16:18 +0100)
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 <kanashiro@ubuntu.com>
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

lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
lib/php/src/ext/thrift_protocol/php_thrift_protocol.h
lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php [new file with mode: 0644]
lib/php/src/ext/thrift_protocol/php_thrift_protocol_arginfo.h [new file with mode: 0644]

index e152d08a3600bb4d651f83259c894065619ed89e..cf06cbf68664eeccc8fbb89ade03801da02b1e7e 100644 (file)
@@ -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);
index 04209973cfab0d32345a2c20481f7f6da30f9cce..b8dc7de7e3f79829a4dd129aba61fba847d7530b 100644 (file)
 
 #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 (file)
index 0000000..e9601c3
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+/** @generate-function-entries */
+
+// php /path/to/php-src/build/gen_stub.php lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php
+
+function thrift_protocol_write_binary(object $protocol, string $method_name, int $msgtype, object $request_struct, int $seqID, bool $strict_write): void {}
+
+function thrift_protocol_read_binary(object $protocol, string $obj_typename, bool $strict_read, int $buffer_size=8192): object {}
+
+function thrift_protocol_read_binary_after_message_begin(object $protocol, string $obj_typename, bool $strict_read, int $buffer_size=8192): object {}
diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol_arginfo.h b/lib/php/src/ext/thrift_protocol/php_thrift_protocol_arginfo.h
new file mode 100644 (file)
index 0000000..a727db0
--- /dev/null
@@ -0,0 +1,33 @@
+/* This is a generated file, edit the .stub.php file instead.
+ * Stub hash: 3bd6e0bc99143d614ddb80ee0aec192e385c8927 */
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_thrift_protocol_write_binary, 0, 6, IS_VOID, 0)
+       ZEND_ARG_TYPE_INFO(0, protocol, IS_OBJECT, 0)
+       ZEND_ARG_TYPE_INFO(0, method_name, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, msgtype, IS_LONG, 0)
+       ZEND_ARG_TYPE_INFO(0, request_struct, IS_OBJECT, 0)
+       ZEND_ARG_TYPE_INFO(0, seqID, IS_LONG, 0)
+       ZEND_ARG_TYPE_INFO(0, strict_write, _IS_BOOL, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_thrift_protocol_read_binary, 0, 3, IS_OBJECT, 0)
+       ZEND_ARG_TYPE_INFO(0, protocol, IS_OBJECT, 0)
+       ZEND_ARG_TYPE_INFO(0, obj_typename, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, strict_read, _IS_BOOL, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, buffer_size, IS_LONG, 0, "8192")
+ZEND_END_ARG_INFO()
+
+#define arginfo_thrift_protocol_read_binary_after_message_begin arginfo_thrift_protocol_read_binary
+
+
+ZEND_FUNCTION(thrift_protocol_write_binary);
+ZEND_FUNCTION(thrift_protocol_read_binary);
+ZEND_FUNCTION(thrift_protocol_read_binary_after_message_begin);
+
+
+static const zend_function_entry ext_functions[] = {
+       ZEND_FE(thrift_protocol_write_binary, arginfo_thrift_protocol_write_binary)
+       ZEND_FE(thrift_protocol_read_binary, arginfo_thrift_protocol_read_binary)
+       ZEND_FE(thrift_protocol_read_binary_after_message_begin, arginfo_thrift_protocol_read_binary_after_message_begin)
+       ZEND_FE_END
+};