Blame SOURCES/0013-php-add-arginfo-to-php-bindings.patch

65aaff
From d451e0e42c75429279426e9eb5a7701cd4681d07 Mon Sep 17 00:00:00 2001
65aaff
From: Geoff Amey <gamey@datto.com>
65aaff
Date: Wed, 15 Jun 2022 17:06:56 -0400
65aaff
Subject: [PATCH] php: add arginfo to php bindings
65aaff
65aaff
Starting with PHP8, arginfo is mandatory for PHP extensions. This patch
65aaff
updates the generator for the PHP bindings to generate the arginfo
65aaff
structures, using the Zend API macros. Only basic arginfo is added,
65aaff
without full documentation of argument and return types, in order to
65aaff
ensure compatibility with as many versions of PHP as possible.
65aaff
65aaff
(cherry picked from commit ec27979398b0871c1a3e0e244849f8435c9c9a8d)
65aaff
---
65aaff
 .gitignore       |  1 +
65aaff
 generator/php.ml | 37 ++++++++++++++++++++++++++++++++++---
65aaff
 2 files changed, 35 insertions(+), 3 deletions(-)
65aaff
65aaff
diff --git a/.gitignore b/.gitignore
65aaff
index a36ccc86a..356c01fbd 100644
65aaff
--- a/.gitignore
65aaff
+++ b/.gitignore
65aaff
@@ -325,6 +325,7 @@ Makefile.in
65aaff
 /php/extension/configure.in
65aaff
 /php/extension/env
65aaff
 /php/extension/guestfs_php.c
65aaff
+/php/extension/guestfs_php.dep
65aaff
 /php/extension/install-sh
65aaff
 /php/extension/libtool
65aaff
 /php/extension/ltmain.sh
65aaff
diff --git a/generator/php.ml b/generator/php.ml
65aaff
index 5c7ef48e8..acdc7b877 100644
65aaff
--- a/generator/php.ml
65aaff
+++ b/generator/php.ml
65aaff
@@ -130,6 +130,37 @@ typedef size_t guestfs_string_length;
65aaff
 typedef int guestfs_string_length;
65aaff
 #endif
65aaff
 
65aaff
+/* Declare argument info structures */
65aaff
+ZEND_BEGIN_ARG_INFO_EX(arginfo_create, 0, 0, 0)
65aaff
+ZEND_END_ARG_INFO()
65aaff
+
65aaff
+ZEND_BEGIN_ARG_INFO_EX(arginfo_last_error, 0, 0, 1)
65aaff
+  ZEND_ARG_INFO(0, g)
65aaff
+ZEND_END_ARG_INFO()
65aaff
+
65aaff
+";
65aaff
+  List.iter (
65aaff
+    fun { name = shortname; style = ret, args, optargs; } ->
65aaff
+      let len = List.length args in
65aaff
+      pr "ZEND_BEGIN_ARG_INFO_EX(arginfo_%s, 0, 0, %d)\n" shortname (len + 1);
65aaff
+      pr "  ZEND_ARG_INFO(0, g)\n";
65aaff
+      List.iter (
65aaff
+        function
65aaff
+        | BufferIn n | Bool n | Int n | Int64 n | OptString n
65aaff
+        | Pointer(_, n) | String (_, n) | StringList (_, n) ->
65aaff
+          pr "  ZEND_ARG_INFO(0, %s)\n" n
65aaff
+        ) args;
65aaff
+
65aaff
+      List.iter (
65aaff
+        function
65aaff
+        | OBool n | OInt n | OInt64 n | OString n | OStringList n ->
65aaff
+          pr "  ZEND_ARG_INFO(0, %s)\n" n
65aaff
+      ) optargs;
65aaff
+      pr "ZEND_END_ARG_INFO()\n\n";
65aaff
+  ) (actions |> external_functions |> sort);
65aaff
+
65aaff
+  pr "
65aaff
+
65aaff
 /* Convert array to list of strings.
65aaff
  * http://marc.info/?l=pecl-dev&m=112205192100631&w=2
65aaff
  */
65aaff
@@ -204,12 +235,12 @@ PHP_MINIT_FUNCTION (guestfs_php)
65aaff
 }
65aaff
 
65aaff
 static zend_function_entry guestfs_php_functions[] = {
65aaff
-  PHP_FE (guestfs_create, NULL)
65aaff
-  PHP_FE (guestfs_last_error, NULL)
65aaff
+  PHP_FE (guestfs_create, arginfo_create)
65aaff
+  PHP_FE (guestfs_last_error, arginfo_last_error)
65aaff
 ";
65aaff
 
65aaff
   List.iter (
65aaff
-    fun { name } -> pr "  PHP_FE (guestfs_%s, NULL)\n" name
65aaff
+    fun { name } -> pr "  PHP_FE (guestfs_%s, arginfo_%s)\n" name name
65aaff
   ) (actions |> external_functions |> sort);
65aaff
 
65aaff
   pr "  { NULL, NULL, NULL }
65aaff
-- 
65aaff
2.31.1
65aaff