[libvirt-php PATCH 09/35] adapt add_assoc_string_ex

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

 



From: Remi Collet <fedora@xxxxxxxxxxxxxxxxx>

---
 src/libvirt-php.c | 299 ++++++++++++++++++------------------------------------
 1 file changed, 99 insertions(+), 200 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index d37fd6f..0459bb9 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -58,6 +58,7 @@ const char *features_binaries[] = { NULL };
 #if PHP_MAJOR_VERSION >= 7
 typedef size_t strsize_t;
 
+#define VIRT_COPY_OPT
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
 	if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
 		RETURN_FALSE; \
@@ -68,6 +69,8 @@ typedef int strsize_t;
 typedef long zend_long;
 typedef unsigned long zend_ulong;
 
+#define VIRT_COPY_OPT ,1
+
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
 	ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
 
@@ -1995,7 +1998,7 @@ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\
 #define LONGLONG_ASSOC(out,key,in) \
     if (LIBVIRT_G(longlong_to_string_ini)) { \
         snprintf(tmpnumber,63,"%llu",in); \
-        add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber,1); \
+        add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber VIRT_COPY_OPT); \
     } \
 else \
 { \
@@ -2059,11 +2062,7 @@ static int libvirt_virConnectCredType[] = {
 PHP_FUNCTION(libvirt_get_last_error)
 {
     if (LIBVIRT_G (last_error) == NULL) RETURN_NULL();
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(LIBVIRT_G (last_error));
-#else
-    RETURN_STRING(LIBVIRT_G (last_error),1);
-#endif
+    RETURN_STRING(LIBVIRT_G (last_error) VIRT_COPY_OPT);
 }
 
 /*
@@ -2223,7 +2222,7 @@ PHP_FUNCTION(libvirt_node_get_info)
     if (retval==-1) RETURN_FALSE;
 
     array_init(return_value);
-    add_assoc_string_ex(return_value, "model", 6, info.model, 1);
+    add_assoc_string_ex(return_value, "model", 6, info.model VIRT_COPY_OPT);
     add_assoc_long(return_value, "memory", (long)info.memory);
     add_assoc_long(return_value, "cpus", (long)info.cpus);
     add_assoc_long(return_value, "nodes", (long)info.nodes);
@@ -2318,9 +2317,9 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats)
         add_assoc_long(return_value, "cpu", cpunr);
     else
         if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS)
-            add_assoc_string_ex(return_value, "cpu", 4, "all", 1);
+            add_assoc_string_ex(return_value, "cpu", 4, "all" VIRT_COPY_OPT);
         else
-            add_assoc_string_ex(return_value, "cpu", 4, "unknown", 1);
+            add_assoc_string_ex(return_value, "cpu", 4, "unknown" VIRT_COPY_OPT);
 
     free(params);
     params = NULL;
@@ -2532,21 +2531,21 @@ PHP_FUNCTION(libvirt_connect_get_machine_types)
                             char tmp3[2048] = { 0 };
 
                             snprintf(key, sizeof(key), "%d", k);
-                            //add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k], 1);
+                            //add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT);
 
                             snprintf(tmp3, sizeof(tmp3), "//capabilities/guest/arch[@name=\"%s\"]/machine[text()=\"%s\"]/@maxCpus",
                                      ret[i], ret3[k]);
 
                             numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL);
                             if (numTmp == NULL)
-                                add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k], 1);
+                                add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT);
                             else {
                                 zval *arr4;
                                 ALLOC_INIT_ZVAL(arr4);
                                 array_init(arr4);
 
-                                add_assoc_string_ex(arr4, "name", 5, ret3[k], 1);
-                                add_assoc_string_ex(arr4, "maxCpus", 9, numTmp, 1);
+                                add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT);
+                                add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT);
 
                                 add_assoc_zval_ex(arr2, key, strlen(key) + 1, arr4);
                                 free(numTmp);
@@ -2574,14 +2573,14 @@ PHP_FUNCTION(libvirt_connect_get_machine_types)
 
                             numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL);
                             if (numTmp == NULL)
-                                add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k], 1);
+                                add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT);
                             else {
                                 zval *arr4;
                                 ALLOC_INIT_ZVAL(arr4);
                                 array_init(arr4);
 
-                                add_assoc_string_ex(arr4, "name", 5, ret3[k], 1);
-                                add_assoc_string_ex(arr4, "maxCpus", 9, numTmp, 1);
+                                add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT);
+                                add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT);
 
                                 add_assoc_zval_ex(arr3, key, strlen(key) + 1, arr4);
                                 free(numTmp);
@@ -2624,21 +2623,21 @@ PHP_FUNCTION(libvirt_connect_get_information)
     tmp = virConnectGetURI(conn->conn);
     DPRINTF("%s: Got connection URI of %s...\n", PHPFUNC, tmp);
     array_init(return_value);
-    add_assoc_string_ex(return_value, "uri", 4, tmp ? tmp : "unknown", 1);
+    add_assoc_string_ex(return_value, "uri", 4, tmp ? tmp : "unknown" VIRT_COPY_OPT);
     free(tmp);
     tmp = virConnectGetHostname(conn->conn);
-    add_assoc_string_ex(return_value, "hostname", 9, tmp ? tmp : "unknown", 1);
+    add_assoc_string_ex(return_value, "hostname", 9, tmp ? tmp : "unknown" VIRT_COPY_OPT);
     free(tmp);
 
     if ((virConnectGetVersion(conn->conn, &hvVer) == 0) && (type = virConnectGetType(conn->conn)))
     {
-        add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type, 1);
+        add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT);
         add_assoc_long(return_value, "hypervisor_major",(long)((hvVer/1000000) % 1000));
         add_assoc_long(return_value, "hypervisor_minor",(long)((hvVer/1000) % 1000));
         add_assoc_long(return_value, "hypervisor_release",(long)(hvVer %1000));
         snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type,
                  (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000));
-        add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr, 1);
+        add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT);
     }
 
     if (strcmp(type, "QEMU") == 0) {
@@ -2651,21 +2650,21 @@ PHP_FUNCTION(libvirt_connect_get_information)
     add_assoc_long(return_value, "hypervisor_maxvcpus", maxvcpus);
     iTmp = virConnectIsEncrypted(conn->conn);
     if (iTmp == 1)
-        add_assoc_string_ex(return_value, "encrypted", 10, "Yes", 1);
+        add_assoc_string_ex(return_value, "encrypted", 10, "Yes" VIRT_COPY_OPT);
     else
         if (iTmp == 0)
-            add_assoc_string_ex(return_value, "encrypted", 10, "No", 1);
+            add_assoc_string_ex(return_value, "encrypted", 10, "No" VIRT_COPY_OPT);
         else
-            add_assoc_string_ex(return_value, "encrypted", 10, "unknown", 1);
+            add_assoc_string_ex(return_value, "encrypted", 10, "unknown" VIRT_COPY_OPT);
 
     iTmp = virConnectIsSecure(conn->conn);
     if (iTmp == 1)
-        add_assoc_string_ex(return_value, "secure", 7, "Yes", 1);
+        add_assoc_string_ex(return_value, "secure", 7, "Yes" VIRT_COPY_OPT);
     else
         if (iTmp == 0)
-            add_assoc_string_ex(return_value, "secure", 7, "No", 1);
+            add_assoc_string_ex(return_value, "secure", 7, "No" VIRT_COPY_OPT);
         else
-            add_assoc_string_ex(return_value, "secure", 7, "unknown", 1);
+            add_assoc_string_ex(return_value, "secure", 7, "unknown" VIRT_COPY_OPT);
 
     add_assoc_long(return_value, "num_inactive_domains", virConnectNumOfDefinedDomains(conn->conn));
     add_assoc_long(return_value, "num_inactive_interfaces", virConnectNumOfDefinedInterfaces(conn->conn));
@@ -2704,11 +2703,7 @@ PHP_FUNCTION(libvirt_connect_get_uri)
     DPRINTF("%s: virConnectGetURI returned %s\n", PHPFUNC, uri);
     if (uri == NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(uri);
-#else
-    RETVAL_STRING(uri, 1);
-#endif
+    RETVAL_STRING(uri VIRT_COPY_OPT);
     free(uri);
 }
 
@@ -2731,11 +2726,7 @@ PHP_FUNCTION(libvirt_connect_get_hostname)
     DPRINTF("%s: virConnectGetHostname returned %s\n", PHPFUNC, hostname);
     if (hostname==NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(hostname);
-#else
-    RETVAL_STRING(hostname, 1);
-#endif
+    RETVAL_STRING(hostname VIRT_COPY_OPT);
     free(hostname);
 }
 
@@ -2888,14 +2879,14 @@ PHP_FUNCTION(libvirt_connect_get_hypervisor)
     DPRINTF("%s: virConnectGetType returned %s\n", PHPFUNC, type);
 
     array_init(return_value);
-    add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type, 1);
+    add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT);
     add_assoc_long(return_value, "major",(long)((hvVer/1000000) % 1000));
     add_assoc_long(return_value, "minor",(long)((hvVer/1000) % 1000));
     add_assoc_long(return_value, "release",(long)(hvVer %1000));
 
     snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type,
              (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000));
-    add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr, 1);
+    add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT);
 }
 
 /*
@@ -2990,7 +2981,7 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats)
                 add_assoc_bool(arr2, params.field, params.value.b);
                 break;
             case VIR_TYPED_PARAM_STRING:
-                add_assoc_string_ex(arr2, params.field, strlen(params.field)+1, params.value.s, strlen(params.value.s)+1);
+                add_assoc_string_ex(arr2, params.field, strlen(params.field)+1, params.value.s VIRT_COPY_OPT);
                 break;
             }
         }
@@ -3043,11 +3034,7 @@ PHP_FUNCTION(libvirt_connect_get_sysinfo)
     sysinfo=virConnectGetSysinfo(conn->conn, 0);
     if (sysinfo==NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(sysinfo);
-#else
-    RETVAL_STRING(sysinfo, 1);
-#endif
+    RETVAL_STRING(sysinfo VIRT_COPY_OPT);
     free(sysinfo);
 }
 
@@ -3115,7 +3102,7 @@ char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal)
                 value = (char *)xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
 
                 snprintf(key, sizeof(key), "%d", i);
-                add_assoc_string_ex(*val, key, strlen(key)+1, value, 1);
+                add_assoc_string_ex(*val, key, strlen(key)+1, value VIRT_COPY_OPT);
                 ret++;
             }
         }
@@ -4019,11 +4006,7 @@ PHP_FUNCTION(libvirt_domain_get_metadata)
         }
     }
     else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(ret);
-#else
-        RETVAL_STRING(ret, 1);
-#endif
+        RETVAL_STRING(ret VIRT_COPY_OPT);
         free(ret);
     }
 }
@@ -4176,11 +4159,7 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command)
        ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags);
        if (ret == NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-       RETURN_STRING(ret);
-#else
-       RETURN_STRING(ret, 1);
-#endif
+       RETURN_STRING(ret VIRT_COPY_OPT);
 }
 
 /*
@@ -4480,11 +4459,7 @@ PHP_FUNCTION(libvirt_domain_get_name)
     DPRINTF("%s: virDomainGetName(%p) returned %s\n", PHPFUNC, domain->domain, name);
     if (name==NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(name);
-#else
-    RETURN_STRING(name, 1);  //we can use the copy mechanism as we need not to free name (we even can not!)
-#endif
+    RETURN_STRING(name VIRT_COPY_OPT);  //we can use the copy mechanism as we need not to free name (we even can not!)
 }
 
 /*
@@ -4509,7 +4484,7 @@ PHP_FUNCTION(libvirt_domain_get_uuid_string)
     if (retval!=0) RETURN_FALSE;
 
 #if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(uuid);
+    RETVAL_STRING(uuid VIRT_COPY_OPT);
     efree(uuid);
 #else
     RETURN_STRING(uuid,0);
@@ -4610,12 +4585,12 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
         if (WEXITSTATUS(exitStatus) != 0)
             RETURN_FALSE;
 
-        add_assoc_string_ex(return_value, "file", 5, fileNew, 1);
-        add_assoc_string_ex(return_value, "mime", 5, "image/png", 1);
+        add_assoc_string_ex(return_value, "file", 5, fileNew VIRT_COPY_OPT);
+        add_assoc_string_ex(return_value, "mime", 5, "image/png" VIRT_COPY_OPT);
     }
     else {
-        add_assoc_string_ex(return_value, "file", 5, file, 1);
-        add_assoc_string_ex(return_value, "mime", 5, mime, 1);
+        add_assoc_string_ex(return_value, "file", 5, file VIRT_COPY_OPT);
+        add_assoc_string_ex(return_value, "mime", 5, mime VIRT_COPY_OPT);
     }
 }
 
@@ -5073,17 +5048,9 @@ PHP_FUNCTION(libvirt_connect_get_capabilities)
 
     tmp = get_string_from_xpath(caps, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(caps);
-#else
-        RETVAL_STRING(caps, 1);
-#endif
+        RETVAL_STRING(caps VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(caps);
@@ -5118,11 +5085,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator)
         RETURN_FALSE;
     }
 
-#if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(tmp);
-#else
-    RETVAL_STRING(tmp, 1);
-#endif
+    RETVAL_STRING(tmp VIRT_COPY_OPT);
     free(tmp);
 }
 
@@ -5187,7 +5150,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models)
             tTokenizer t = tokenize(tmp, ",");
             for (i = 0; i < t.numTokens; i++) {
                 snprintf(tmp2, sizeof(tmp2), "%d", i);
-                add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[i], 1);
+                add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[i] VIRT_COPY_OPT);
             }
             free_tokens(t);
         }
@@ -5280,14 +5243,14 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models)
                 zval *arr;
                 ALLOC_INIT_ZVAL(arr);
                 array_init(arr);
-                add_assoc_string_ex(arr, "name", 5, t.tokens[0], 1);
-                add_assoc_string_ex(arr, "description", 12, desc, 1);
+                add_assoc_string_ex(arr, "name", 5, t.tokens[0] VIRT_COPY_OPT);
+                add_assoc_string_ex(arr, "description", 12, desc VIRT_COPY_OPT);
                 add_next_index_zval(return_value, arr);
             }
             else {
                 char tmp2[16] = { 0 };
                 snprintf(tmp2, sizeof(tmp2), "%d", n++);
-                add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[0], 1);
+                add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[0] VIRT_COPY_OPT);
             }
 
             free_tokens(t);
@@ -5554,11 +5517,7 @@ PHP_FUNCTION(libvirt_domain_new)
 PHP_FUNCTION(libvirt_domain_new_get_vnc)
 {
     if (LIBVIRT_G(vnc_location))
-#if PHP_MAJOR_VERSION >= 7
-        RETURN_STRING(LIBVIRT_G(vnc_location));
-#else
-        RETURN_STRING(LIBVIRT_G(vnc_location),1);
-#endif
+        RETURN_STRING(LIBVIRT_G(vnc_location) VIRT_COPY_OPT);
 
     RETURN_NULL();
 }
@@ -5596,17 +5555,9 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(xml);
-#else
-        RETVAL_STRING(xml, 1);
-#endif
+        RETVAL_STRING(xml VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(tmp);
@@ -6760,8 +6711,8 @@ PHP_FUNCTION(libvirt_domain_get_network_info)
     }
 
     array_init(return_value);
-    add_assoc_string_ex(return_value, "mac", 4, mac, 1);
-    add_assoc_string_ex(return_value, "network", 8, tmp, 1);
+    add_assoc_string_ex(return_value, "mac", 4, mac VIRT_COPY_OPT);
+    add_assoc_string_ex(return_value, "network", 8, tmp VIRT_COPY_OPT);
 
     free(tmp);
     free(xpath);
@@ -6772,9 +6723,9 @@ PHP_FUNCTION(libvirt_domain_get_network_info)
     }
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "nic_type", 9, tmp, 1);
+        add_assoc_string_ex(return_value, "nic_type", 9, tmp VIRT_COPY_OPT);
     else
-        add_assoc_string_ex(return_value, "nic_type", 9, "default", 1);
+        add_assoc_string_ex(return_value, "nic_type", 9, "default" VIRT_COPY_OPT);
 
     free(xml);
     free(xpath);
@@ -6858,12 +6809,12 @@ PHP_FUNCTION(libvirt_domain_get_block_info)
 
     array_init(return_value);
     LONGLONG_INIT;
-    add_assoc_string_ex(return_value, "device", 7, dev, 1);
+    add_assoc_string_ex(return_value, "device", 7, dev VIRT_COPY_OPT);
 
     if (isFile)
-        add_assoc_string_ex(return_value, "file", 5, tmp, 1);
+        add_assoc_string_ex(return_value, "file", 5, tmp VIRT_COPY_OPT);
     else
-        add_assoc_string_ex(return_value, "partition", 10, tmp, 1);
+        add_assoc_string_ex(return_value, "partition", 10, tmp VIRT_COPY_OPT);
 
     free(xpath);
     if (asprintf(&xpath, "//domain/devices/disk/target[@dev='%s']/../driver/@type", dev) < 0) {
@@ -6873,7 +6824,7 @@ PHP_FUNCTION(libvirt_domain_get_block_info)
     free(tmp);
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if (tmp != NULL)
-        add_assoc_string_ex(return_value, "type", 5, tmp, 1);
+        add_assoc_string_ex(return_value, "type", 5, tmp VIRT_COPY_OPT);
 
     LONGLONG_ASSOC(return_value, "capacity", info.capacity);
     LONGLONG_ASSOC(return_value, "allocation", info.allocation);
@@ -6929,7 +6880,7 @@ PHP_FUNCTION(libvirt_domain_xml_xpath)
     if (rc == 0)
         RETURN_FALSE;
 
-    add_assoc_string_ex(return_value, "xpath", 6, (char *)zpath, 1);
+    add_assoc_string_ex(return_value, "xpath", 6, (char *)zpath VIRT_COPY_OPT);
     if (rc < 0)
         add_assoc_long(return_value, "error_code", (long)rc);
 }
@@ -7289,11 +7240,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml)
     xml = virDomainSnapshotGetXMLDesc(snapshot->snapshot, flags);
     if (xml==NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETVAL_STRING(xml);
-#else
-    RETVAL_STRING(xml, 1);
-#endif
+    RETVAL_STRING(xml VIRT_COPY_OPT);
     free(xml);
 }
 
@@ -7622,11 +7569,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_name)
     DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval);
     if (retval == NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(retval);
-#else
-    RETURN_STRING (retval, 1);
-#endif
+    RETURN_STRING(retval VIRT_COPY_OPT);
 }
 
 /*
@@ -7648,11 +7591,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_path)
     DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval);
     if (retval == NULL) RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(retval);
-#else
-    RETURN_STRING (retval, 1);
-#endif
+    RETURN_STRING(retval VIRT_COPY_OPT);
 }
 
 /*
@@ -7716,17 +7655,9 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(xml);
-#else
-        RETVAL_STRING(xml, 1);
-#endif
+        RETVAL_STRING(xml VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(xml);
@@ -8010,11 +7941,7 @@ PHP_FUNCTION(libvirt_storagepool_get_name)
     if (name == NULL)
         RETURN_FALSE;
 
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(name);
-#else
-    RETURN_STRING(name, 1);
-#endif
+    RETURN_STRING(name VIRT_COPY_OPT);
 }
 
 /*
@@ -8091,17 +8018,9 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(xml);
-#else
-        RETVAL_STRING(xml, 1);
-#endif
+        RETVAL_STRING(xml VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(xml);
@@ -9002,17 +8921,9 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(xml);
-#else
-        RETVAL_STRING(xml, 1);
-#endif
+        RETVAL_STRING(xml VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(xml);
@@ -9057,18 +8968,18 @@ PHP_FUNCTION(libvirt_nodedev_get_information)
         goto error;
     }
 
-    add_assoc_string_ex(return_value, "name", 5, tmp, 1);
+    add_assoc_string_ex(return_value, "name", 5, tmp VIRT_COPY_OPT);
 
     /* Get parent name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "parent", 7, tmp, 1);
+        add_assoc_string_ex(return_value, "parent", 7, tmp VIRT_COPY_OPT);
 
     /* Get capability */
     cap = get_string_from_xpath(xml, "//device/capability/@type", NULL, &retval);
     if ((cap != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "capability", 11, cap, 1);
+        add_assoc_string_ex(return_value, "capability", 11, cap VIRT_COPY_OPT);
 
     /* System capability is having hardware and firmware sub-blocks */
     if (strcmp(cap, "system") == 0) {
@@ -9076,92 +8987,92 @@ PHP_FUNCTION(libvirt_nodedev_get_information)
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "hardware_vendor", 16, tmp, 1);
+            add_assoc_string_ex(return_value, "hardware_vendor", 16, tmp VIRT_COPY_OPT);
 
         /* Get hardware version */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/hardware/version", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "hardware_version", 17, tmp, 1);
+            add_assoc_string_ex(return_value, "hardware_version", 17, tmp VIRT_COPY_OPT);
 
         /* Get hardware serial */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "hardware_serial", 16, tmp, 1);
+            add_assoc_string_ex(return_value, "hardware_serial", 16, tmp VIRT_COPY_OPT);
 
         /* Get hardware UUID */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid", NULL, &retval);
         if (tmp != NULL)
-            add_assoc_string_ex(return_value, "hardware_uuid", 15, tmp, 1);
+            add_assoc_string_ex(return_value, "hardware_uuid", 15, tmp VIRT_COPY_OPT);
 
         /* Get firmware vendor */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "firmware_vendor", 16, tmp, 1);
+            add_assoc_string_ex(return_value, "firmware_vendor", 16, tmp VIRT_COPY_OPT);
 
         /* Get firmware version */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/firmware/version", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "firmware_version", 17, tmp, 1);
+            add_assoc_string_ex(return_value, "firmware_version", 17, tmp VIRT_COPY_OPT);
 
         /* Get firmware release date */
         free(tmp);
         tmp = get_string_from_xpath(xml, "//device/capability/firmware/release_date", NULL, &retval);
         if ((tmp != NULL) && (retval > 0))
-            add_assoc_string_ex(return_value, "firmware_release_date", 22, tmp, 1);
+            add_assoc_string_ex(return_value, "firmware_release_date", 22, tmp VIRT_COPY_OPT);
     }
 
     /* Get product_id */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "product_id", 11, tmp, 1);
+        add_assoc_string_ex(return_value, "product_id", 11, tmp VIRT_COPY_OPT);
 
     /* Get product_name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/product", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "product_name", 13, tmp, 1);
+        add_assoc_string_ex(return_value, "product_name", 13, tmp VIRT_COPY_OPT);
 
     /* Get vendor_id */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "vendor_id", 10, tmp, 1);
+        add_assoc_string_ex(return_value, "vendor_id", 10, tmp VIRT_COPY_OPT);
 
     /* Get vendor_name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "vendor_name", 12, tmp, 1);
+        add_assoc_string_ex(return_value, "vendor_name", 12, tmp VIRT_COPY_OPT);
 
     /* Get driver name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/driver/name", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "driver_name", 12, tmp, 1);
+        add_assoc_string_ex(return_value, "driver_name", 12, tmp VIRT_COPY_OPT);
 
     /* Get driver name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "interface_name", 15, tmp, 1);
+        add_assoc_string_ex(return_value, "interface_name", 15, tmp VIRT_COPY_OPT);
 
     /* Get driver name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/address", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "address", 8, tmp, 1);
+        add_assoc_string_ex(return_value, "address", 8, tmp VIRT_COPY_OPT);
 
     /* Get driver name */
     free(tmp);
     tmp = get_string_from_xpath(xml, "//device/capability/capability/@type", NULL, &retval);
     if ((tmp != NULL) && (retval > 0))
-        add_assoc_string_ex(return_value, "capabilities", 11, tmp, 1);
+        add_assoc_string_ex(return_value, "capabilities", 11, tmp VIRT_COPY_OPT);
 
     free(cap);
     free(tmp);
@@ -9293,11 +9204,7 @@ PHP_FUNCTION(libvirt_network_get_bridge)
         RETURN_FALSE;
     }
 
-#if PHP_MAJOR_VERSION >= 7
-    RETURN_STRING(name);
-#else
-    RETURN_STRING(name, 1);
-#endif
+    RETURN_STRING(name VIRT_COPY_OPT);
 }
 
 /*
@@ -9370,42 +9277,42 @@ PHP_FUNCTION(libvirt_network_get_information)
         RETURN_FALSE;
     }
 
-    add_assoc_string_ex(return_value, "name", 5, name, 1);
+    add_assoc_string_ex(return_value, "name", 5, name VIRT_COPY_OPT);
 
     /* Get gateway IP address */
     ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL, &retval);
     if (ipaddr && retval > 0)
-        add_assoc_string_ex(return_value, "ip", 3, ipaddr, 1);
+        add_assoc_string_ex(return_value, "ip", 3, ipaddr VIRT_COPY_OPT);
 
     /* Get netmask */
     netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL, &retval);
     if (netmask && retval > 0) {
         int subnet_bits = get_subnet_bits(netmask);
-        add_assoc_string_ex(return_value, "netmask", 8, netmask, 1);
+        add_assoc_string_ex(return_value, "netmask", 8, netmask VIRT_COPY_OPT);
         add_assoc_long(return_value, "netmask_bits", (long) subnet_bits);
 
         /* Format CIDR address representation */
         ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1;
         snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits);
-        add_assoc_string_ex(return_value, "ip_range", 9, fixedtemp, 1);
+        add_assoc_string_ex(return_value, "ip_range", 9, fixedtemp VIRT_COPY_OPT);
     }
 
     /* Get forwarding settings */
     mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL, &retval);
     if (mode && retval > 0)
-        add_assoc_string_ex(return_value, "forwarding", 11, mode, 1);
+        add_assoc_string_ex(return_value, "forwarding", 11, mode VIRT_COPY_OPT);
 
     /* Get forwarding settings */
     dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL, &retval);
     if (dev && retval > 0)
-        add_assoc_string_ex(return_value, "forward_dev", 12, dev, 1);
+        add_assoc_string_ex(return_value, "forward_dev", 12, dev VIRT_COPY_OPT);
 
     /* Get DHCP values */
     dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start", NULL, &retval);
     dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL, &retval);
     if (dhcp_start && dhcp_end && retval > 0) {
-        add_assoc_string_ex(return_value, "dhcp_start", 11, dhcp_start,  1);
-        add_assoc_string_ex(return_value, "dhcp_end", 9, dhcp_end, 1);
+        add_assoc_string_ex(return_value, "dhcp_start", 11, dhcp_start VIRT_COPY_OPT);
+        add_assoc_string_ex(return_value, "dhcp_end", 9, dhcp_end VIRT_COPY_OPT);
     }
 
     free(dhcp_end);
@@ -9497,17 +9404,9 @@ PHP_FUNCTION(libvirt_network_get_xml_desc)
 
     tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
     if ((tmp == NULL) || (retval < 0)) {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(xml);
-#else
-        RETVAL_STRING(xml, 1);
-#endif
+        RETVAL_STRING(xml VIRT_COPY_OPT);
     } else {
-#if PHP_MAJOR_VERSION >= 7
-        RETVAL_STRING(tmp);
-#else
-        RETVAL_STRING(tmp, 1);
-#endif
+        RETVAL_STRING(tmp VIRT_COPY_OPT);
     }
 
     free(xml);
@@ -9547,7 +9446,7 @@ PHP_FUNCTION(libvirt_version)
     add_assoc_long(return_value, "libvirt.minor",(long)((libVer/1000) % 1000));
     add_assoc_long(return_value, "libvirt.major",(long)((libVer/1000000) % 1000));
 
-    add_assoc_string_ex(return_value, "connector.version", 18, PHP_LIBVIRT_WORLD_VERSION, 1);
+    add_assoc_string_ex(return_value, "connector.version", 18, PHP_LIBVIRT_WORLD_VERSION VIRT_COPY_OPT);
     add_assoc_long(return_value, "connector.major", VERSION_MAJOR);
     add_assoc_long(return_value, "connector.minor", VERSION_MINOR);
     add_assoc_long(return_value, "connector.release", VERSION_MICRO);
-- 
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]