On 09.04.2016 00:08, Neal Gompa wrote:
From: Remi Collet <fedora(a)famillecollet.com>
---
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);
I'm afraid, this will not fly. While preprocessing this code, my
compiler tries to expand RETURN_STRING() macro first (with VIRT_COPY_OPT
still not expanded). Therefore it finds an argument missing and produces
an compilation error.
What we can do here is create a wrapper over RETURN_STRING, e.g.
VIR_RETURN_STRING() that will behave differently for PHP7 and the rest.
Unfortunately, this is where I have to stop the review as it's getting
hairy and I gotta run. Sorry.
Michal