|
25 | 25 | #include "zend_exceptions.h"
|
26 | 26 | #include "zend_closures.h"
|
27 | 27 | #include "main/SAPI.h"
|
| 28 | +#include "Zend/zend_bit_enum.h" |
28 | 29 |
|
29 | 30 | #include <ffi.h>
|
30 | 31 |
|
@@ -98,11 +99,11 @@ typedef enum _zend_ffi_type_kind {
|
98 | 99 |
|
99 | 100 | #include "ffi_arginfo.h"
|
100 | 101 |
|
101 |
| -typedef enum _zend_ffi_flags { |
102 |
| - ZEND_FFI_FLAG_CONST = (1 << 0), |
103 |
| - ZEND_FFI_FLAG_OWNED = (1 << 1), |
104 |
| - ZEND_FFI_FLAG_PERSISTENT = (1 << 2), |
105 |
| -} zend_ffi_flags; |
| 102 | +#define ZEND_FFI_FLAGS_CASES(_) \ |
| 103 | + _(ZEND_FFI_FLAG_CONST, 1 << 0) \ |
| 104 | + _(ZEND_FFI_FLAG_OWNED, 1 << 1) \ |
| 105 | + _(ZEND_FFI_FLAG_PERSISTENT, 1 << 2) |
| 106 | +ZEND_BIT_ENUM(zend_ffi_flags, ZEND_FFI_FLAGS_CASES); |
106 | 107 |
|
107 | 108 | struct _zend_ffi_type {
|
108 | 109 | zend_ffi_type_kind kind;
|
@@ -261,7 +262,7 @@ static zend_object *zend_ffi_cdata_new(zend_class_entry *class_type) /* {{{ */
|
261 | 262 |
|
262 | 263 | cdata->type = NULL;
|
263 | 264 | cdata->ptr = NULL;
|
264 |
| - cdata->flags = (zend_ffi_flags)0; |
| 265 | + cdata->flags = zend_ffi_flags_init(0); |
265 | 266 |
|
266 | 267 | return &cdata->std;
|
267 | 268 | }
|
@@ -1110,7 +1111,7 @@ static zval *zend_ffi_cdata_get(zend_object *obj, zend_string *member, int read_
|
1110 | 1111 | return &EG(uninitialized_zval);
|
1111 | 1112 | }
|
1112 | 1113 |
|
1113 |
| - zend_ffi_cdata_to_zval(cdata, cdata->ptr, type, BP_VAR_R, rv, (zend_ffi_flags)0, 0, 0); |
| 1114 | + zend_ffi_cdata_to_zval(cdata, cdata->ptr, type, BP_VAR_R, rv, zend_ffi_flags_init(0), 0, 0); |
1114 | 1115 | return rv;
|
1115 | 1116 | }
|
1116 | 1117 | /* }}} */
|
@@ -2833,7 +2834,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
|
2833 | 2834 | }
|
2834 | 2835 |
|
2835 | 2836 | if (ZEND_FFI_TYPE(type->func.ret_type)->kind != ZEND_FFI_TYPE_VOID) {
|
2836 |
| - zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, (zend_ffi_flags)0, 1, 0); |
| 2837 | + zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, zend_ffi_flags_init(0), 1, 0); |
2837 | 2838 | } else {
|
2838 | 2839 | ZVAL_NULL(return_value);
|
2839 | 2840 | }
|
@@ -3868,7 +3869,7 @@ ZEND_METHOD(FFI, free) /* {{{ */
|
3868 | 3869 | } else if (!(cdata->flags & ZEND_FFI_FLAG_OWNED)) {
|
3869 | 3870 | pefree(cdata->ptr, cdata->flags & ZEND_FFI_FLAG_PERSISTENT);
|
3870 | 3871 | cdata->ptr = NULL;
|
3871 |
| - cdata->flags = (zend_ffi_flags)(cdata->flags & ~(ZEND_FFI_FLAG_OWNED|ZEND_FFI_FLAG_PERSISTENT)); |
| 3872 | + cdata->flags = zend_ffi_flags_init(cdata->flags & ~(ZEND_FFI_FLAG_OWNED|ZEND_FFI_FLAG_PERSISTENT)); |
3872 | 3873 | cdata->std.handlers = &zend_ffi_cdata_free_handlers;
|
3873 | 3874 | } else {
|
3874 | 3875 | zend_throw_error(zend_ffi_exception_ce, "free() non a C pointer");
|
@@ -4042,7 +4043,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
|
4042 | 4043 | if (old_cdata->flags & ZEND_FFI_FLAG_OWNED) {
|
4043 | 4044 | if (GC_REFCOUNT(&old_cdata->std) == 1 && Z_REFCOUNT_P(arg) == 1) {
|
4044 | 4045 | /* transfer ownership */
|
4045 |
| - old_cdata->flags = (zend_ffi_flags)(old_cdata->flags & ~ZEND_FFI_FLAG_OWNED); |
| 4046 | + old_cdata->flags = zend_ffi_flags_init(old_cdata->flags & ~ZEND_FFI_FLAG_OWNED); |
4046 | 4047 | cdata->flags |= ZEND_FFI_FLAG_OWNED;
|
4047 | 4048 | } else {
|
4048 | 4049 | //???zend_throw_error(zend_ffi_exception_ce, "Attempt to cast owned C pointer");
|
@@ -4279,7 +4280,7 @@ ZEND_METHOD(FFI, addr) /* {{{ */
|
4279 | 4280 | }
|
4280 | 4281 | if (cdata->flags & ZEND_FFI_FLAG_OWNED) {
|
4281 | 4282 | /* transfer ownership */
|
4282 |
| - cdata->flags = (zend_ffi_flags)(cdata->flags & ~ZEND_FFI_FLAG_OWNED); |
| 4283 | + cdata->flags = zend_ffi_flags_init(cdata->flags & ~ZEND_FFI_FLAG_OWNED); |
4283 | 4284 | new_cdata->flags |= ZEND_FFI_FLAG_OWNED;
|
4284 | 4285 | }
|
4285 | 4286 | }
|
|
0 commit comments