[libvirt-php PATCH 13/35] buildable with PHP 7

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Remi Collet <fedora@xxxxxxxxxxxxxxxxx>

---
 src/libvirt-php.c | 98 +++++++++++++++++++++++++++++++++++++++++++++----------
 src/libvirt-php.h |  4 +++
 2 files changed, 85 insertions(+), 17 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index c1587f9..1959074 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -2008,7 +2008,7 @@ else \
 #define LONGLONG_INDEX(out,key,in) \
     if (LIBVIRT_G(longlong_to_string_ini)) { \
         snprintf(tmpnumber,63,"%llu",in); \
-        add_index_string(out,key,tmpnumber,1); \
+        add_index_string(out,key,tmpnumber VIRT_COPY_OPT); \
     } \
 else \
 { \
@@ -2194,11 +2194,12 @@ PHP_FUNCTION(libvirt_connect)
     DPRINTF("%s: Connection to %s established, returning %p\n", PHPFUNC, url, conn->conn);
 
 #if PHP_MAJOR_VERSION >= 7
-    ZVAL_RES(return_value, zend_register_resource(conn, le_libvirt_connection));
+    conn->resource_id = zend_register_resource(conn, le_libvirt_connection);
+    ZVAL_RES(return_value, conn->resource_id);
 #else
     ZEND_REGISTER_RESOURCE(return_value, conn, le_libvirt_connection);
+    conn->resource_id = Z_LVAL_P(return_value);
 #endif
-    conn->resource_id=Z_LVAL_P(return_value);
 }
 
 /*
@@ -4407,14 +4408,15 @@ PHP_FUNCTION(libvirt_stream_recv)
     if (retval < 0) {
         efree(recv_buf);
         zval_dtor(zbuf);
-        Z_TYPE_P(zbuf) = IS_NULL;
+        ZVAL_NULL(zbuf);
     } else {
         recv_buf[retval] = '\0';
-        /* Rebuild buffer zval */
-        zval_dtor(zbuf);
-        Z_STRVAL_P(zbuf) = recv_buf;
-        Z_STRLEN_P(zbuf) = retval;
-        Z_TYPE_P(zbuf) = IS_STRING;
+#if PHP_MAJOR_VERSION >= 7
+        ZVAL_STRINGL(zbuf, recv_buf, retval);
+        efree(recv_buf);
+#else
+        ZVAL_STRINGL(zbuf, recv_buf, retval, 0)
+#endif
     }
 
     if (retval == -1) {
@@ -4775,9 +4777,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot)
     }
 
     /* This is necessary to make the output binary safe */
-    Z_STRLEN_P(return_value) = fsize;
-    Z_STRVAL_P(return_value) = buf;
-    Z_TYPE_P(return_value) = IS_STRING;
+    ZVAL_STRINGL(return_value, buf, fsize VIRT_COPY_OPT);
 
     efree(buf);
     free(tmp);
@@ -5130,7 +5130,6 @@ PHP_FUNCTION(libvirt_connect_get_emulator)
     char *arch = NULL;
     int arch_len;
     char *tmp;
-    char *emulator;
 
     GET_CONNECTION_FROM_ARGS("r|s",&zconn,&arch,&arch_len);
 
@@ -5327,10 +5326,15 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network)
 {
     HashTable *arr_hash;
     // int array_count;
+#if PHP_MAJOR_VERSION >= 7
+    zval *data;
+    zend_string *key;
+#else
     zval **data; // removed **zvalue
-    HashPosition pointer;
     char *key;
     unsigned int key_len;
+#endif
+    HashPosition pointer;
     unsigned long index;
 
     arr_hash = Z_ARRVAL_P(arr);
@@ -5341,6 +5345,43 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network)
     if (network != NULL)
         memset(network, 0, sizeof(tVMNetwork));
 
+#if PHP_MAJOR_VERSION >= 7
+    for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
+         (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL;
+         zend_hash_move_forward_ex(arr_hash, &pointer)) {
+        if ((Z_TYPE_P(data) == IS_STRING) || (Z_TYPE_P(data) == IS_LONG)) {
+            if (zend_hash_get_current_key_ex(arr_hash, &key, &index, &pointer) == HASH_KEY_IS_STRING) {
+                if (disk != NULL) {
+                    if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "path") == 0)
+                        disk->path = strdup( Z_STRVAL_P(data) );
+                    else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "driver") == 0)
+                        disk->driver = strdup( Z_STRVAL_P(data) );
+                    else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "bus") == 0)
+                        disk->bus = strdup( Z_STRVAL_P(data) );
+                    else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "dev") == 0)
+                        disk->dev = strdup( Z_STRVAL_P(data) );
+                    else if (strcmp(ZSTR_VAL(key), "size") == 0) {
+                        if (Z_TYPE_P(data) == IS_LONG)
+                            disk->size = Z_LVAL_P(data);
+                        else
+                            disk->size = size_def_to_mbytes(Z_STRVAL_P(data));
+                    }
+                    else if ((Z_TYPE_P(data) == IS_LONG) && strcmp(ZSTR_VAL(key), "dev") == 0)
+                        disk->flags = Z_LVAL_P(data);
+                } else {
+                    if (network != NULL) {
+                        if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "mac") == 0)
+                            network->mac = strdup( Z_STRVAL_P(data) );
+                        else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "network") == 0)
+                            network->network = strdup( Z_STRVAL_P(data) );
+                        else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "model") == 0)
+                            network->model = strdup( Z_STRVAL_P(data) );
+                    }
+                }
+            }
+        }
+    }
+#else
     for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
          zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS;
          zend_hash_move_forward_ex(arr_hash, &pointer)) {
@@ -5379,6 +5420,7 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network)
             }
         }
     }
+#endif
 }
 
 /*
@@ -5420,7 +5462,11 @@ PHP_FUNCTION(libvirt_domain_new)
     long maxmemMB = -1;
     HashTable *arr_hash;
     int numDisks, numNets, i;
+#if PHP_MAJOR_VERSION >= 7
+    zval *data;
+#else
     zval **data; // removed **zvalue
+#endif
     HashPosition pointer;
     char vncl[2048] = { 0 };
     char tmpname[1024] = { 0 };
@@ -5451,12 +5497,19 @@ PHP_FUNCTION(libvirt_domain_new)
     memset(vmDisks, 0, numDisks * sizeof(tVMDisk));
     i = 0;
     for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
+#if PHP_MAJOR_VERSION >= 7
+        (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL;
+        zend_hash_move_forward_ex(arr_hash, &pointer)) {
+        if (Z_TYPE_P(data) == IS_ARRAY) {
+            tVMDisk disk;
+            parse_array(data, &disk, NULL);
+#else
         zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS;
         zend_hash_move_forward_ex(arr_hash, &pointer)) {
         if (Z_TYPE_PP(data) == IS_ARRAY) {
             tVMDisk disk;
             parse_array(*data, &disk, NULL);
-
+#endif
             if (disk.path != NULL) {
                 //DPRINTF("Disk => path = '%s', driver = '%s', bus = '%s', dev = '%s', size = %ld MB, flags = %d\n",
                 //  disk.path, disk.driver, disk.bus, disk.dev, disk.size, disk.flags);
@@ -5473,12 +5526,19 @@ PHP_FUNCTION(libvirt_domain_new)
     memset(vmNetworks, 0, numNets * sizeof(tVMNetwork));
     i = 0;
     for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
+#if PHP_MAJOR_VERSION >= 7
+        (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL;
+        zend_hash_move_forward_ex(arr_hash, &pointer)) {
+        if (Z_TYPE_P(data) == IS_ARRAY) {
+            tVMNetwork network;
+            parse_array(data, NULL, &network);
+#else
         zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS;
         zend_hash_move_forward_ex(arr_hash, &pointer)) {
         if (Z_TYPE_PP(data) == IS_ARRAY) {
             tVMNetwork network;
             parse_array(*data, NULL, &network);
-
+#endif
             if (network.mac != NULL) {
                 //DPRINTF("Network => mac = '%s', network = '%s', model = '%s'\n", network.mac, network.network, network.model);
                 vmNetworks[i++] = network;
@@ -7003,7 +7063,11 @@ PHP_FUNCTION(libvirt_domain_get_connect)
 
     conn= domain->conn;
     if (conn->conn == NULL) RETURN_FALSE;
+#if PHP_MAJOR_VERSION >= 7
+    ZVAL_RES(return_value, conn->resource_id);
+#else
     RETURN_RESOURCE(conn->resource_id);
+#endif
 }
 
 /*
@@ -8836,7 +8900,7 @@ PHP_FUNCTION(libvirt_list_networks)
 
         for (i=0;i<count;i++)
         {
-            add_next_index_string(return_value, names[i], 1);
+            add_next_index_string(return_value, names[i] VIRT_COPY_OPT);
             free(names[i]);
         }
 
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index 6b56547..2ffe9f3 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -258,7 +258,11 @@ typedef struct tBMPFile {
 /* Libvirt-php types */
 typedef struct _php_libvirt_connection {
     virConnectPtr conn;
+#if PHP_MAJOR_VERSION >= 7
+    zend_resource *resource_id;
+#else
     long resource_id;
+#endif
 } php_libvirt_connection;
 
 typedef struct _php_libvirt_stream {
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]