[libvirt] [libvirt-php PATCH 17/35] fix PHP 5 compat

Neal Gompa ngompa13 at gmail.com
Fri Apr 8 22:08:26 UTC 2016


From: Remi Collet <fedora at famillecollet.com>

---
 src/libvirt-php.c | 75 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 44 insertions(+), 31 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 2700c77..3977302 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -59,6 +59,9 @@ const char *features_binaries[] = { NULL };
 typedef size_t strsize_t;
 
 #define VIRT_COPY_OPT
+#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str)
+#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len)
+
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
 	if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
 		RETURN_FALSE; \
@@ -70,6 +73,8 @@ typedef long zend_long;
 typedef unsigned long zend_ulong;
 
 #define VIRT_COPY_OPT ,1
+#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str, 1)
+#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len,1)
 
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
 	ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
@@ -2062,7 +2067,7 @@ static int libvirt_virConnectCredType[] = {
 PHP_FUNCTION(libvirt_get_last_error)
 {
     if (LIBVIRT_G (last_error) == NULL) RETURN_NULL();
-    RETURN_STRING(LIBVIRT_G (last_error) VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(LIBVIRT_G(last_error));
 }
 
 /*
@@ -2079,7 +2084,11 @@ PHP_FUNCTION(libvirt_connect)
     php_libvirt_connection *conn;
     php_libvirt_cred_value *creds=NULL;
     zval* zcreds=NULL;
+#if PHP_MAJOR_VERSION >= 7
     zval *data;
+#else
+    zval **data;
+#endif
     int i;
     int j;
     int credscount=0;
@@ -2753,7 +2762,7 @@ PHP_FUNCTION(libvirt_connect_get_uri)
     DPRINTF("%s: virConnectGetURI returned %s\n", PHPFUNC, uri);
     if (uri == NULL) RETURN_FALSE;
 
-    RETVAL_STRING(uri VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(uri);
     free(uri);
 }
 
@@ -2776,7 +2785,7 @@ PHP_FUNCTION(libvirt_connect_get_hostname)
     DPRINTF("%s: virConnectGetHostname returned %s\n", PHPFUNC, hostname);
     if (hostname==NULL) RETURN_FALSE;
 
-    RETVAL_STRING(hostname VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(hostname);
     free(hostname);
 }
 
@@ -3093,7 +3102,7 @@ PHP_FUNCTION(libvirt_connect_get_sysinfo)
     sysinfo=virConnectGetSysinfo(conn->conn, 0);
     if (sysinfo==NULL) RETURN_FALSE;
 
-    RETVAL_STRING(sysinfo VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(sysinfo);
     free(sysinfo);
 }
 
@@ -3377,7 +3386,11 @@ long get_next_free_numeric_value(virDomainPtr domain, char *xpath)
     HashTable *arr_hash;
     HashPosition pointer;
     // int array_count;
+#if PHP_MAJOR_VERSION >= 7
     zval *data;
+#else
+    zval **data;
+#endif
     unsigned long index;
     long max_slot = -1;
 
@@ -4065,7 +4078,7 @@ PHP_FUNCTION(libvirt_domain_get_metadata)
         }
     }
     else {
-        RETVAL_STRING(ret VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(ret);
         free(ret);
     }
 }
@@ -4218,7 +4231,7 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command)
        ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags);
        if (ret == NULL) RETURN_FALSE;
 
-       RETURN_STRING(ret VIRT_COPY_OPT);
+       VIRT_RETVAL_STRING(ret);
 }
 
 /*
@@ -4415,7 +4428,7 @@ PHP_FUNCTION(libvirt_stream_recv)
         ZVAL_STRINGL(zbuf, recv_buf, retval);
         efree(recv_buf);
 #else
-        ZVAL_STRINGL(zbuf, recv_buf, retval, 0)
+        ZVAL_STRINGL(zbuf, recv_buf, retval, 0);
 #endif
     }
 
@@ -4519,7 +4532,7 @@ PHP_FUNCTION(libvirt_domain_get_name)
     DPRINTF("%s: virDomainGetName(%p) returned %s\n", PHPFUNC, domain->domain, name);
     if (name==NULL) RETURN_FALSE;
 
-    RETURN_STRING(name VIRT_COPY_OPT);  //we can use the copy mechanism as we need not to free name (we even can not!)
+    VIRT_RETVAL_STRING(name);  //we can use the copy mechanism as we need not to free name (we even can not!)
 }
 
 /*
@@ -4777,7 +4790,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot)
     }
 
     /* This is necessary to make the output binary safe */
-    ZVAL_STRINGL(return_value, buf, fsize VIRT_COPY_OPT);
+    VIRT_ZVAL_STRINGL(return_value, buf, fsize);
 
     efree(buf);
     free(tmp);
@@ -5106,9 +5119,9 @@ PHP_FUNCTION(libvirt_connect_get_capabilities)
 
     tmp = get_string_from_xpath(caps, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(caps VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(caps);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(caps);
@@ -5142,7 +5155,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator)
         RETURN_FALSE;
     }
 
-    RETVAL_STRING(tmp VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(tmp);
     free(tmp);
 }
 
@@ -5640,9 +5653,9 @@ PHP_FUNCTION(libvirt_domain_new)
 PHP_FUNCTION(libvirt_domain_new_get_vnc)
 {
     if (LIBVIRT_G(vnc_location))
-        RETURN_STRING(LIBVIRT_G(vnc_location) VIRT_COPY_OPT);
-
-    RETURN_NULL();
+        VIRT_RETVAL_STRING(LIBVIRT_G(vnc_location));
+    else
+        RETVAL_NULL();
 }
 
 /*
@@ -5678,9 +5691,9 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(xml VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(xml);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(tmp);
@@ -7369,7 +7382,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml)
     xml = virDomainSnapshotGetXMLDesc(snapshot->snapshot, flags);
     if (xml==NULL) RETURN_FALSE;
 
-    RETVAL_STRING(xml VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(xml);
     free(xml);
 }
 
@@ -7698,7 +7711,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_name)
     DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval);
     if (retval == NULL) RETURN_FALSE;
 
-    RETURN_STRING(retval VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(retval);
 }
 
 /*
@@ -7720,7 +7733,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_path)
     DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval);
     if (retval == NULL) RETURN_FALSE;
 
-    RETURN_STRING(retval VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(retval);
 }
 
 /*
@@ -7784,9 +7797,9 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(xml VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(xml);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(xml);
@@ -8070,7 +8083,7 @@ PHP_FUNCTION(libvirt_storagepool_get_name)
     if (name == NULL)
         RETURN_FALSE;
 
-    RETURN_STRING(name VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(name);
 }
 
 /*
@@ -8147,9 +8160,9 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(xml VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(xml);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(xml);
@@ -8882,7 +8895,7 @@ PHP_FUNCTION(libvirt_list_networks)
 
         for (i=0;i<count;i++)
         {
-            add_next_index_string(return_value,  names[i]);
+            add_next_index_string(return_value,  names[i] VIRT_COPY_OPT);
             free(names[i]);
         }
 
@@ -9057,9 +9070,9 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(xml VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(xml);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(xml);
@@ -9340,7 +9353,7 @@ PHP_FUNCTION(libvirt_network_get_bridge)
         RETURN_FALSE;
     }
 
-    RETURN_STRING(name VIRT_COPY_OPT);
+    VIRT_RETVAL_STRING(name);
 }
 
 /*
@@ -9540,9 +9553,9 @@ PHP_FUNCTION(libvirt_network_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-        RETVAL_STRING(xml VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(xml);
     } else {
-        RETVAL_STRING(tmp VIRT_COPY_OPT);
+        VIRT_RETVAL_STRING(tmp);
     }
 
     free(xml);
-- 
2.5.5




More information about the libvir-list mailing list