[libvirt] [libvirt-php][PATCH 0/8] Couple of php fixes

Pushed under php-autopush rule. Michal Privoznik (8): libvirt_domain_get_network_info: Don't overwrite retval libvirt_storagepool_get_autostart: Rework translate_counter_type: Rework libvirt_domain_block_commit: Reindent libvirt_domain_qemu_agent_command: Reindent libvirt_domain_disk_add: Reindent libvirt_domain_disk_remove: Reindent libvirt_list_storagepools: Reindent src/libvirt-php.c | 129 ++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 68 deletions(-) -- 2.8.4

In e0d6f457 I've tried to fix a memleak. However, in libvirt_domain_get_network_info instead of plain 'return' I've put 'RETURN_TRUE'. This macro throws away whatever return value we've constructed so far and replace it with integer value of 1. Le sigh. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 57ef1a0..33b4c5d 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -7181,7 +7181,7 @@ PHP_FUNCTION(libvirt_domain_get_network_info) free(xml); free(xpath); free(tmp); - RETURN_TRUE; + return; error: free(xml); -- 2.8.4

This function is written just too complicated. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 33b4c5d..54de2e3 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -8684,23 +8684,15 @@ PHP_FUNCTION(libvirt_storagepool_get_autostart) { php_libvirt_storagepool *pool = NULL; zval *zpool; - int flags = 0; + int autostart; GET_STORAGEPOOL_FROM_ARGS ("r", &zpool); - if (virStoragePoolGetAutostart (pool->pool, &flags) == 0) - { - if (flags == 0) { - RETURN_FALSE; - } - else { - RETURN_TRUE; - } - } - else - { - RETURN_FALSE; - } + if (virStoragePoolGetAutostart(pool->pool, &autostart) == 0 && + autostart != 0) + RETURN_TRUE; + + RETURN_FALSE; } /* -- 2.8.4

Firstly, this function returns const char *. Then it is static. Then it's body can be written better. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 54de2e3..dfadf15 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -904,25 +904,26 @@ int set_logfile(char *filename, long maxsize TSRMLS_DC) * Arguments: @type [int]: integer identifier of the counter type * Returns: string interpretation of the counter type */ -char *translate_counter_type(int type) +static const char * +translate_counter_type(int type) { switch (type) { - case INT_RESOURCE_CONNECTION: return "connection"; - break; - case INT_RESOURCE_DOMAIN: return "domain"; - break; - case INT_RESOURCE_STREAM: return "stream"; - break; - case INT_RESOURCE_NETWORK: return "network"; - break; - case INT_RESOURCE_NODEDEV: return "node device"; - break; - case INT_RESOURCE_STORAGEPOOL: return "storage pool"; - break; - case INT_RESOURCE_VOLUME: return "storage volume"; - break; - case INT_RESOURCE_SNAPSHOT: return "snapshot"; - break; + case INT_RESOURCE_CONNECTION: + return "connection"; + case INT_RESOURCE_DOMAIN: + return "domain"; + case INT_RESOURCE_STREAM: + return "stream"; + case INT_RESOURCE_NETWORK: + return "network"; + case INT_RESOURCE_NODEDEV: + return "node device"; + case INT_RESOURCE_STORAGEPOOL: + return "storage pool"; + case INT_RESOURCE_VOLUME: + return "storage volume"; + case INT_RESOURCE_SNAPSHOT: + return "snapshot"; } return "unknown"; -- 2.8.4

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index dfadf15..28183a6 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -7009,24 +7009,24 @@ PHP_FUNCTION(libvirt_domain_block_resize) */ PHP_FUNCTION(libvirt_domain_block_commit) { - php_libvirt_domain *domain=NULL; - zval *zdomain; - int retval; - char *disk; - int disk_len; - char *base = NULL; - int base_len; - char *top = NULL; - int top_len; - long bandwidth = 0; - long flags = 0; + php_libvirt_domain *domain=NULL; + zval *zdomain; + int retval; + char *disk; + int disk_len; + char *base = NULL; + int base_len; + char *top = NULL; + int top_len; + long bandwidth = 0; + long flags = 0; - GET_DOMAIN_FROM_ARGS("rsssll",&zdomain, &disk, &disk_len, &base, &base_len, &top, &top_len, &bandwidth, &flags); + GET_DOMAIN_FROM_ARGS("rsssll",&zdomain, &disk, &disk_len, &base, &base_len, &top, &top_len, &bandwidth, &flags); - retval=virDomainBlockCommit(domain->domain, disk, base, top, bandwidth, flags); - if (retval == -1) RETURN_FALSE; + retval=virDomainBlockCommit(domain->domain, disk, base, top, bandwidth, flags); + if (retval == -1) RETURN_FALSE; - RETURN_TRUE; + RETURN_TRUE; } -- 2.8.4

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 28183a6..30ada47 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -4373,21 +4373,21 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid) */ PHP_FUNCTION(libvirt_domain_qemu_agent_command) { - php_libvirt_domain *domain=NULL; - zval *zdomain; - const char *cmd; - strsize_t cmd_len; - char *ret; - zend_long timeout = -1; - zend_long flags = 0; + php_libvirt_domain *domain=NULL; + zval *zdomain; + const char *cmd; + strsize_t cmd_len; + char *ret; + zend_long timeout = -1; + zend_long flags = 0; - GET_DOMAIN_FROM_ARGS("rs|ll", &zdomain, &cmd, &cmd_len, &timeout, &flags); + GET_DOMAIN_FROM_ARGS("rs|ll", &zdomain, &cmd, &cmd_len, &timeout, &flags); - ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags); - if (ret == NULL) RETURN_FALSE; + ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags); + if (ret == NULL) RETURN_FALSE; - VIRT_RETVAL_STRING(ret); - free(ret); + VIRT_RETVAL_STRING(ret); + free(ret); } /* -- 2.8.4

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 30ada47..067fb90 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -6170,11 +6170,11 @@ PHP_FUNCTION(libvirt_domain_disk_add) } if (asprintf(&newXml, - " <disk type='file' device='disk'>\n" - " <driver name='qemu' type='%s'/>\n" - " <source file='%s'/>\n" - " <target dev='%s' bus='%s'/>\n" - " </disk>", driver, img, dev, typ) < 0) { + " <disk type='file' device='disk'>\n" + " <driver name='qemu' type='%s'/>\n" + " <source file='%s'/>\n" + " <target dev='%s' bus='%s'/>\n" + " </disk>", driver, img, dev, typ) < 0) { set_error("Out of memory" TSRMLS_CC); goto error; } -- 2.8.4

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 067fb90..6546ad5 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -6243,9 +6243,9 @@ PHP_FUNCTION(libvirt_domain_disk_remove) } if (asprintf(&newXml, - " <disk type='file' device='disk'>\n" - " <target dev='%s'/>\n" - " </disk>", dev) < 0) { + " <disk type='file' device='disk'>\n" + " <target dev='%s'/>\n" + " </disk>", dev) < 0) { set_error("Out of memory" TSRMLS_CC); goto error; } -- 2.8.4

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 6546ad5..3aed882 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -8785,7 +8785,7 @@ PHP_FUNCTION(libvirt_list_storagepools) if ((expectedcount = virConnectNumOfDefinedStoragePools (conn->conn)) < 0) - RETURN_FALSE; + RETURN_FALSE; names = (char **)emalloc (expectedcount * sizeof(char *)); count = virConnectListDefinedStoragePools (conn->conn, names, expectedcount); if ((count != expectedcount) || (count < 0)) -- 2.8.4
participants (1)
-
Michal Privoznik