[libvirt] [libvirt-php PATCH 2/7] add wrappers for PHP resource handling.

Dawid Zamirski dzamirski at datto.com
Thu Jun 22 19:14:02 UTC 2017


There were quite a few places in code that were using preprocessor
directives to handle differences in dealing with resources between PHP
versions which can be dealt with by using typdefs and macros.
---
 src/libvirt-php.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index d25fa94..0422661 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -121,6 +121,19 @@ typedef uint64_t arch_uint;
 
 #if PHP_MAJOR_VERSION >= 7
 typedef size_t strsize_t;
+typedef zend_resource virt_resource;
+
+#define VIRT_RETURN_RESOURCE(_resource) \
+    RETVAL_RES(_resource)
+
+#define VIRT_REGISTER_RESOURCE(_resource, _le_resource)          \
+    VIRT_RETURN_RESOURCE(zend_register_resource(_resource, _le_resource))
+
+#define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
+    zval zret; \
+    ZVAL_RES(&zret, zend_register_resource(res_##_name, le_libvirt_##_name)); \
+    add_next_index_zval(return_value, &zret); \
+    } while(0)
 
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
     if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
@@ -165,6 +178,20 @@ typedef size_t strsize_t;
 typedef int strsize_t;
 typedef long zend_long;
 typedef unsigned long zend_ulong;
+typedef zend_rsrc_list_entry virt_resource;
+
+#define VIRT_RETURN_RESOURCE(_resource) \
+    RETVAL_RESOURCE((long) _resource)
+
+#define VIRT_REGISTER_RESOURCE(_resource, _le_resource) \
+    ZEND_REGISTER_RESOURCE(return_value, _resource, _le_resource)
+
+#define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
+    zval *zret; \
+    ALLOC_INIT_ZVAL(zret); \
+    ZEND_REGISTER_RESOURCE(zret, res_##_name, le_libvirt_##_name); \
+    add_next_index_zval(return_value, zret); \
+    } while(0)
 
 #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
     ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
-- 
2.13.0




More information about the libvir-list mailing list