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