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

[libvirt] [libvirt-php PATCH 1/7] move macros to header file.



So that PHP version handling wrappers are all in one place
---
 src/libvirt-php.c | 88 -------------------------------------------------------
 src/libvirt-php.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 88 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index c2ab0da..ece98d6 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -45,94 +45,6 @@ const char *features[] = { NULL };
 const char *features_binaries[] = { NULL };
 #endif
 
-#if PHP_MAJOR_VERSION >= 7
-typedef size_t strsize_t;
-
-
-#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
-    if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
-        RETURN_FALSE; \
-    }
-
-#define VIRT_RETVAL_STRING(_str)    \
-    RETVAL_STRING(_str)
-#define VIRT_RETVAL_STRINGL(_str, _len) \
-    RETVAL_STRINGL(_str, _len)
-#define VIRT_RETURN_STRING(_str)    \
-    RETURN_STRING(_str)
-#define VIRT_RETURN_STRINGL(_str, _len) \
-    RETURN_STRINGL(_str, _len)
-#define VIRT_ZVAL_STRINGL(_zv, _str, _len)  \
-    ZVAL_STRINGL(_zv, _str, _len)
-#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str)  \
-    add_index_string(_arg, _idx, _str)
-#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str)  \
-    add_next_index_string(_arg, _str)
-#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
-    add_assoc_string(_arg, _key, _str)
-#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
-    add_assoc_string_ex(_arg, _key, _key_len, _value)
-
-#define VIRT_FOREACH(_ht, _pos, _zv) \
-    for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
-         (_zv = zend_hash_get_current_data_ex(_ht, &_pos)) != NULL; \
-         zend_hash_move_forward_ex(_ht, &_pos)) \
-
-#define VIRT_FOREACH_END(_dummy)
-
-#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
-    do { \
-    zend_string *tmp_key_info; \
-    _info.type = zend_hash_get_current_key_ex(_ht, &tmp_key_info, &_idx, &_pos); \
-    _info.name = ZSTR_VAL(tmp_key_info); \
-    _info.length = ZSTR_LEN(tmp_key_info); \
-    } while(0)
-
-#else /* PHP_MAJOR_VERSION < 7 */
-typedef int strsize_t;
-typedef long zend_long;
-typedef unsigned long zend_ulong;
-
-#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
-    ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
-
-#define VIRT_RETVAL_STRING(_str)    \
-    RETVAL_STRING(_str, 1)
-#define VIRT_RETVAL_STRINGL(_str, _len) \
-    RETVAL_STRINGL(_str, _len, 1)
-#define VIRT_RETURN_STRING(_str)    \
-    RETURN_STRING(_str, 1)
-#define VIRT_RETURN_STRINGL(_str, _len) \
-    RETURN_STRINGL(_str, _len, 1)
-#define VIRT_ZVAL_STRINGL(_zv, _str, _len)  \
-    ZVAL_STRINGL(_zv, _str, _len, 1)
-#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str)  \
-    add_index_string(_arg, _idx, _str, 1)
-#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str)  \
-    add_next_index_string(_arg, _str, 1)
-#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
-    add_assoc_string(_arg, _key, _str, 1)
-#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
-    add_assoc_string_ex(_arg, _key, _key_len, _value, 1)
-
-#define VIRT_FOREACH(_ht, _pos, _zv) \
-    { \
-    zval **pzv = &_zv; \
-    for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
-         zend_hash_get_current_data_ex(_ht, (void **) &pzv, &_pos) == SUCCESS; \
-         zend_hash_move_forward_ex(_ht, &_pos)) { \
-        _zv = *pzv;
-
-#define VIRT_FOREACH_END(_dummy) \
-    }}
-
-#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
-    do { \
-    _info.type = zend_hash_get_current_key_ex(_ht, &_info.name, &_info.length, &_idx, 0, &_pos); \
-    } while(0)
-
-#endif /* PHP_MAJOR_VERSION < 7 */
-
 /* ZEND thread safe per request globals definition */
 int le_libvirt_connection;
 int le_libvirt_domain;
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index f9dec09..d25fa94 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -121,10 +121,89 @@ typedef uint64_t arch_uint;
 
 #if PHP_MAJOR_VERSION >= 7
 typedef size_t strsize_t;
+
+#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
+    if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
+        RETURN_FALSE; \
+    }
+
+#define VIRT_RETVAL_STRING(_str)    \
+    RETVAL_STRING(_str)
+#define VIRT_RETVAL_STRINGL(_str, _len) \
+    RETVAL_STRINGL(_str, _len)
+#define VIRT_RETURN_STRING(_str)    \
+    RETURN_STRING(_str)
+#define VIRT_RETURN_STRINGL(_str, _len) \
+    RETURN_STRINGL(_str, _len)
+#define VIRT_ZVAL_STRINGL(_zv, _str, _len)  \
+    ZVAL_STRINGL(_zv, _str, _len)
+#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str)  \
+    add_index_string(_arg, _idx, _str)
+#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str)  \
+    add_next_index_string(_arg, _str)
+#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
+    add_assoc_string(_arg, _key, _str)
+#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
+    add_assoc_string_ex(_arg, _key, _key_len, _value)
+
+#define VIRT_FOREACH(_ht, _pos, _zv) \
+    for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
+         (_zv = zend_hash_get_current_data_ex(_ht, &_pos)) != NULL; \
+         zend_hash_move_forward_ex(_ht, &_pos)) \
+
+#define VIRT_FOREACH_END(_dummy)
+
+#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
+    do { \
+    zend_string *tmp_key_info; \
+    _info.type = zend_hash_get_current_key_ex(_ht, &tmp_key_info, &_idx, &_pos); \
+    _info.name = ZSTR_VAL(tmp_key_info); \
+    _info.length = ZSTR_LEN(tmp_key_info); \
+    } while(0)
+
 #else /* PHP_MAJOR_VERSION < 7 */
 typedef int strsize_t;
 typedef long zend_long;
 typedef unsigned long zend_ulong;
+
+#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
+    ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
+
+#define VIRT_RETVAL_STRING(_str)    \
+    RETVAL_STRING(_str, 1)
+#define VIRT_RETVAL_STRINGL(_str, _len) \
+    RETVAL_STRINGL(_str, _len, 1)
+#define VIRT_RETURN_STRING(_str)    \
+    RETURN_STRING(_str, 1)
+#define VIRT_RETURN_STRINGL(_str, _len) \
+    RETURN_STRINGL(_str, _len, 1)
+#define VIRT_ZVAL_STRINGL(_zv, _str, _len)  \
+    ZVAL_STRINGL(_zv, _str, _len, 1)
+#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str)  \
+    add_index_string(_arg, _idx, _str, 1)
+#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str)  \
+    add_next_index_string(_arg, _str, 1)
+#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
+    add_assoc_string(_arg, _key, _str, 1)
+#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
+    add_assoc_string_ex(_arg, _key, _key_len, _value, 1)
+
+#define VIRT_FOREACH(_ht, _pos, _zv) \
+    { \
+    zval **pzv = &_zv; \
+    for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
+         zend_hash_get_current_data_ex(_ht, (void **) &pzv, &_pos) == SUCCESS; \
+         zend_hash_move_forward_ex(_ht, &_pos)) { \
+        _zv = *pzv;
+
+#define VIRT_FOREACH_END(_dummy) \
+    }}
+
+#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
+    do { \
+    _info.type = zend_hash_get_current_key_ex(_ht, &_info.name, &_info.length, &_idx, 0, &_pos); \
+    } while(0)
+
 #endif /* PHP_MAJOR_VERSION < 7 */
 
 typedef struct tTokenizer {
-- 
2.13.0


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