From: Remi Collet <fedora@xxxxxxxxxxxxxxxxx> --- 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 fe84f16..e497c10 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); @@ -2093,7 +2098,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)); } /* @@ -2110,7 +2115,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; @@ -2784,7 +2793,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); } @@ -2807,7 +2816,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); } @@ -3124,7 +3133,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); } @@ -3408,7 +3417,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; @@ -4096,7 +4109,7 @@ PHP_FUNCTION(libvirt_domain_get_metadata) } } else { - RETVAL_STRING(ret VIRT_COPY_OPT); + VIRT_RETVAL_STRING(ret); free(ret); } } @@ -4249,7 +4262,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); } /* @@ -4446,7 +4459,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 } @@ -4550,7 +4563,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!) } /* @@ -4808,7 +4821,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); @@ -5137,9 +5150,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); @@ -5173,7 +5186,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator) RETURN_FALSE; } - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); free(tmp); } @@ -5671,9 +5684,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(); } /* @@ -5709,9 +5722,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); @@ -7467,7 +7480,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); } @@ -7798,7 +7811,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); } /* @@ -7820,7 +7833,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); } /* @@ -7884,9 +7897,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); @@ -8170,7 +8183,7 @@ PHP_FUNCTION(libvirt_storagepool_get_name) if (name == NULL) RETURN_FALSE; - RETURN_STRING(name VIRT_COPY_OPT); + VIRT_RETVAL_STRING(name); } /* @@ -8247,9 +8260,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); @@ -8997,7 +9010,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]); } @@ -9175,9 +9188,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); @@ -9458,7 +9471,7 @@ PHP_FUNCTION(libvirt_network_get_bridge) RETURN_FALSE; } - RETURN_STRING(name VIRT_COPY_OPT); + VIRT_RETVAL_STRING(name); } /* @@ -9658,9 +9671,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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list