diff options
Diffstat (limited to 'ext/ffi/ffi.c')
-rw-r--r-- | ext/ffi/ffi.c | 85 |
1 files changed, 37 insertions, 48 deletions
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index e3da06698f..21c6dcf451 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -124,8 +124,8 @@ struct _zend_ffi_type { typedef struct _zend_ffi_field { size_t offset; - zend_bool is_const; - zend_bool is_nested; /* part of nested anonymous struct */ + bool is_const; + bool is_nested; /* part of nested anonymous struct */ uint8_t first_bit; uint8_t bits; zend_ffi_type *type; @@ -140,7 +140,7 @@ typedef enum _zend_ffi_symbol_kind { typedef struct _zend_ffi_symbol { zend_ffi_symbol_kind kind; - zend_bool is_const; + bool is_const; zend_ffi_type *type; union { void *addr; @@ -158,7 +158,7 @@ typedef struct _zend_ffi { DL_HANDLE lib; HashTable *symbols; HashTable *tags; - zend_bool persistent; + bool persistent; } zend_ffi; #define ZEND_FFI_TYPE_OWNED (1<<0) @@ -209,7 +209,7 @@ static void _zend_ffi_type_dtor(zend_ffi_type *type); static void zend_ffi_finalize_type(zend_ffi_dcl *dcl); static int zend_ffi_is_same_type(zend_ffi_type *type1, zend_ffi_type *type2); static zend_ffi_type *zend_ffi_remember_type(zend_ffi_type *type); -static char *zend_ffi_parse_directives(const char *filename, char *code_pos, char **scope_name, char **lib, zend_bool preload); +static char *zend_ffi_parse_directives(const char *filename, char *code_pos, char **scope_name, char **lib, bool preload); static ZEND_FUNCTION(ffi_trampoline); static ZEND_COLD void zend_ffi_return_unsupported(zend_ffi_type *type); static ZEND_COLD void zend_ffi_pass_unsupported(zend_ffi_type *type); @@ -482,7 +482,7 @@ static zend_never_inline zend_ffi_cdata *zend_ffi_cdata_to_zval_slow_ret(void *p } /* }}} */ -static zend_always_inline void zend_ffi_cdata_to_zval(zend_ffi_cdata *cdata, void *ptr, zend_ffi_type *type, int read_type, zval *rv, zend_ffi_flags flags, zend_bool is_ret, zend_bool debug_union) /* {{{ */ +static zend_always_inline void zend_ffi_cdata_to_zval(zend_ffi_cdata *cdata, void *ptr, zend_ffi_type *type, int read_type, zval *rv, zend_ffi_flags flags, bool is_ret, bool debug_union) /* {{{ */ { if (read_type == BP_VAR_R) { zend_ffi_type_kind kind = type->kind; @@ -1826,7 +1826,7 @@ typedef struct _zend_ffi_cdata_iterator { zend_object_iterator it; zend_long key; zval value; - zend_bool by_ref; + bool by_ref; } zend_ffi_cdata_iterator; static void zend_ffi_cdata_it_dtor(zend_object_iterator *iter) /* {{{ */ @@ -2031,7 +2031,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp) } /* }}} */ -static int zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, zend_bool check_only) /* {{{ */ +static int zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ { zend_ffi_cdata *cdata = (zend_ffi_cdata*)obj; zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); @@ -3122,7 +3122,7 @@ static zend_ffi_type *zend_ffi_remember_type(zend_ffi_type *type) /* {{{ */ } /* }}} */ -static zend_ffi *zend_ffi_load(const char *filename, zend_bool preload) /* {{{ */ +static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */ { struct stat buf; int fd; @@ -3479,7 +3479,7 @@ static int zend_ffi_validate_vla(zend_ffi_type *type) /* {{{ */ } /* }}} */ -static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, zend_bool allow_incomplete_tag, zend_bool allow_incomplete_array) /* {{{ */ +static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, bool allow_incomplete_tag, bool allow_incomplete_array) /* {{{ */ { if (!allow_incomplete_tag && (type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG)) { if (FFI_G(tags)) { @@ -3523,7 +3523,7 @@ static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, zend_bool allo } /* }}} */ -static int zend_ffi_validate_type(zend_ffi_type *type, zend_bool allow_incomplete_tag, zend_bool allow_incomplete_array) /* {{{ */ +static int zend_ffi_validate_type(zend_ffi_type *type, bool allow_incomplete_tag, bool allow_incomplete_array) /* {{{ */ { if (type->kind == ZEND_FFI_TYPE_VOID) { zend_ffi_throw_parser_error("void type is not allowed at line %d", FFI_G(line)); @@ -3533,7 +3533,7 @@ static int zend_ffi_validate_type(zend_ffi_type *type, zend_bool allow_incomplet } /* }}} */ -static int zend_ffi_validate_var_type(zend_ffi_type *type, zend_bool allow_incomplete_array) /* {{{ */ +static int zend_ffi_validate_var_type(zend_ffi_type *type, bool allow_incomplete_array) /* {{{ */ { if (type->kind == ZEND_FFI_TYPE_FUNC) { zend_ffi_throw_parser_error("function type is not allowed at line %d", FFI_G(line)); @@ -3617,9 +3617,9 @@ ZEND_METHOD(FFI, new) /* {{{ */ zend_ffi_type *type, *type_ptr; zend_ffi_cdata *cdata; void *ptr; - zend_bool owned = 1; - zend_bool persistent = 0; - zend_bool is_const = 0; + bool owned = 1; + bool persistent = 0; + bool is_const = 0; zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED; ZEND_FFI_VALIDATE_API_RESTRICTION(); @@ -3736,7 +3736,7 @@ ZEND_METHOD(FFI, free) /* {{{ */ ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS_EX2(zv, zend_ffi_cdata_ce, 0, 1, 0); + Z_PARAM_OBJECT_OF_CLASS_EX(zv, zend_ffi_cdata_ce, 0, 1); ZEND_PARSE_PARAMETERS_END(); cdata = (zend_ffi_cdata*)Z_OBJ_P(zv); @@ -3769,7 +3769,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ zend_object *ztype = NULL; zend_ffi_type *old_type, *type, *type_ptr; zend_ffi_cdata *old_cdata, *cdata; - zend_bool is_const = 0; + bool is_const = 0; zval *zv, *arg; void *ptr; @@ -4227,7 +4227,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */ ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(3, 3) - Z_PARAM_OBJECT_OF_CLASS_EX2(zv1, zend_ffi_cdata_ce, 0, 1, 0); + Z_PARAM_OBJECT_OF_CLASS_EX(zv1, zend_ffi_cdata_ce, 0, 1); Z_PARAM_ZVAL(zv2) Z_PARAM_LONG(size) ZEND_PARSE_PARAMETERS_END(); @@ -4357,7 +4357,7 @@ ZEND_METHOD(FFI, memset) /* {{{ */ ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(3, 3) - Z_PARAM_OBJECT_OF_CLASS_EX2(zv, zend_ffi_cdata_ce, 0, 1, 0); + Z_PARAM_OBJECT_OF_CLASS_EX(zv, zend_ffi_cdata_ce, 0, 1); Z_PARAM_LONG(ch) Z_PARAM_LONG(size) ZEND_PARSE_PARAMETERS_END(); @@ -4385,11 +4385,11 @@ ZEND_METHOD(FFI, string) /* {{{ */ zend_ffi_type *type; void *ptr; zend_long size; - zend_bool size_is_null = 1; + bool size_is_null = 1; ZEND_FFI_VALIDATE_API_RESTRICTION(); ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_OBJECT_OF_CLASS_EX2(zv, zend_ffi_cdata_ce, 0, 1, 0); + Z_PARAM_OBJECT_OF_CLASS_EX(zv, zend_ffi_cdata_ce, 0, 1); Z_PARAM_OPTIONAL Z_PARAM_LONG_OR_NULL(size, size_is_null) ZEND_PARSE_PARAMETERS_END(); @@ -4470,7 +4470,7 @@ ZEND_METHOD(FFI_CType, getName) /* {{{ */ } } -static char *zend_ffi_parse_directives(const char *filename, char *code_pos, char **scope_name, char **lib, zend_bool preload) /* {{{ */ +static char *zend_ffi_parse_directives(const char *filename, char *code_pos, char **scope_name, char **lib, bool preload) /* {{{ */ { char *p; @@ -4834,7 +4834,7 @@ static int zend_ffi_preload(char *preload) /* {{{ */ { zend_ffi *ffi; char *s = NULL, *e, *filename; - zend_bool is_glob = 0; + bool is_glob = 0; e = preload; while (*e) { @@ -4899,22 +4899,15 @@ static int zend_ffi_preload(char *preload) /* {{{ */ /* {{{ ZEND_MINIT_FUNCTION */ ZEND_MINIT_FUNCTION(ffi) { - zend_class_entry ce; - REGISTER_INI_ENTRIES(); FFI_G(is_cli) = strcmp(sapi_module.name, "cli") == 0; - INIT_NS_CLASS_ENTRY(ce, "FFI", "Exception", NULL); - zend_ffi_exception_ce = zend_register_internal_class_ex(&ce, zend_ce_error); + zend_ffi_exception_ce = register_class_FFI_Exception(zend_ce_error); - INIT_NS_CLASS_ENTRY(ce, "FFI", "ParserException", NULL); - zend_ffi_parser_exception_ce = zend_register_internal_class_ex(&ce, zend_ffi_exception_ce); - zend_ffi_parser_exception_ce->ce_flags |= ZEND_ACC_FINAL; + zend_ffi_parser_exception_ce = register_class_FFI_ParserException(zend_ffi_exception_ce); - INIT_CLASS_ENTRY(ce, "FFI", class_FFI_methods); - zend_ffi_ce = zend_register_internal_class(&ce); - zend_ffi_ce->ce_flags |= ZEND_ACC_FINAL; + zend_ffi_ce = register_class_FFI(); zend_ffi_ce->create_object = zend_ffi_new; zend_ffi_ce->serialize = zend_class_serialize_deny; zend_ffi_ce->unserialize = zend_class_unserialize_deny; @@ -4949,9 +4942,7 @@ ZEND_MINIT_FUNCTION(ffi) zend_declare_class_constant_long(zend_ffi_ce, "__BIGGEST_ALIGNMENT__", sizeof("__BIGGEST_ALIGNMENT__")-1, __BIGGEST_ALIGNMENT__); - INIT_NS_CLASS_ENTRY(ce, "FFI", "CData", NULL); - zend_ffi_cdata_ce = zend_register_internal_class(&ce); - zend_ffi_cdata_ce->ce_flags |= ZEND_ACC_FINAL; + zend_ffi_cdata_ce = register_class_FFI_CData(); zend_ffi_cdata_ce->create_object = zend_ffi_cdata_new; zend_ffi_cdata_ce->get_iterator = zend_ffi_cdata_get_iterator; zend_ffi_cdata_ce->serialize = zend_class_serialize_deny; @@ -5027,9 +5018,7 @@ ZEND_MINIT_FUNCTION(ffi) zend_ffi_cdata_free_handlers.get_properties = zend_fake_get_properties; zend_ffi_cdata_free_handlers.get_gc = zend_fake_get_gc; - INIT_NS_CLASS_ENTRY(ce, "FFI", "CType", class_FFI_CType_methods); - zend_ffi_ctype_ce = zend_register_internal_class(&ce); - zend_ffi_ctype_ce->ce_flags |= ZEND_ACC_FINAL; + zend_ffi_ctype_ce = register_class_FFI_CType(); zend_ffi_ctype_ce->create_object = zend_ffi_ctype_new; zend_ffi_ctype_ce->serialize = zend_class_serialize_deny; zend_ffi_ctype_ce->unserialize = zend_class_unserialize_deny; @@ -5438,8 +5427,8 @@ void zend_ffi_add_enum_val(zend_ffi_dcl *enum_dcl, const char *name, size_t name const zend_ffi_type *sym_type; int64_t value; zend_ffi_type *enum_type = ZEND_FFI_TYPE(enum_dcl->type); - zend_bool overflow = 0; - zend_bool is_signed = + bool overflow = 0; + bool is_signed = (enum_type->enumeration.kind == ZEND_FFI_TYPE_SINT8 || enum_type->enumeration.kind == ZEND_FFI_TYPE_SINT16 || enum_type->enumeration.kind == ZEND_FFI_TYPE_SINT32 || @@ -5624,7 +5613,7 @@ void zend_ffi_add_field(zend_ffi_dcl *struct_dcl, const char *name, size_t name_ struct_type->size += field_type->size; } field->type = field_dcl->type; - field->is_const = (zend_bool)(field_dcl->attr & ZEND_FFI_ATTR_CONST); + field->is_const = (bool)(field_dcl->attr & ZEND_FFI_ATTR_CONST); field->is_nested = 0; field->first_bit = 0; field->bits = 0; @@ -5792,7 +5781,7 @@ void zend_ffi_add_bit_field(zend_ffi_dcl *struct_dcl, const char *name, size_t n } } field->type = field_dcl->type; - field->is_const = (zend_bool)(field_dcl->attr & ZEND_FFI_ATTR_CONST); + field->is_const = (bool)(field_dcl->attr & ZEND_FFI_ATTR_CONST); field->is_nested = 0; field_dcl->type = field_type; /* reset "owned" flag */ @@ -6111,7 +6100,7 @@ void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl) /* { if ((dcl->flags & ZEND_FFI_DCL_STORAGE_CLASS) == ZEND_FFI_DCL_TYPEDEF && sym->kind == ZEND_FFI_SYM_TYPE && zend_ffi_is_same_type(ZEND_FFI_TYPE(sym->type), ZEND_FFI_TYPE(dcl->type)) - && sym->is_const == (zend_bool)(dcl->attr & ZEND_FFI_ATTR_CONST)) { + && sym->is_const == (bool)(dcl->attr & ZEND_FFI_ATTR_CONST)) { /* allowed redeclaration */ zend_ffi_type_dtor(dcl->type); return; @@ -6129,7 +6118,7 @@ void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl) /* { } else { if (sym->kind == ZEND_FFI_SYM_VAR && zend_ffi_is_same_type(ZEND_FFI_TYPE(sym->type), type) - && sym->is_const == (zend_bool)(dcl->attr & ZEND_FFI_ATTR_CONST)) { + && sym->is_const == (bool)(dcl->attr & ZEND_FFI_ATTR_CONST)) { /* allowed redeclaration */ zend_ffi_type_dtor(dcl->type); return; @@ -6158,7 +6147,7 @@ void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl) /* { sym = pemalloc(sizeof(zend_ffi_symbol), FFI_G(persistent)); sym->kind = ZEND_FFI_SYM_TYPE; sym->type = dcl->type; - sym->is_const = (zend_bool)(dcl->attr & ZEND_FFI_ATTR_CONST); + sym->is_const = (bool)(dcl->attr & ZEND_FFI_ATTR_CONST); dcl->type = ZEND_FFI_TYPE(dcl->type); /* reset "owned" flag */ zend_hash_str_add_new_ptr(FFI_G(symbols), name, name_len, sym); } else { @@ -6174,7 +6163,7 @@ void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl) /* { sym = pemalloc(sizeof(zend_ffi_symbol), FFI_G(persistent)); sym->kind = (type->kind == ZEND_FFI_TYPE_FUNC) ? ZEND_FFI_SYM_FUNC : ZEND_FFI_SYM_VAR; sym->type = dcl->type; - sym->is_const = (zend_bool)(dcl->attr & ZEND_FFI_ATTR_CONST); + sym->is_const = (bool)(dcl->attr & ZEND_FFI_ATTR_CONST); dcl->type = type; /* reset "owned" flag */ zend_hash_str_add_new_ptr(FFI_G(symbols), name, name_len, sym); } else { @@ -6186,7 +6175,7 @@ void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl) /* { } /* }}} */ -void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl, zend_bool incomplete) /* {{{ */ +void zend_ffi_declare_tag(const char *name, size_t name_len, zend_ffi_dcl *dcl, bool incomplete) /* {{{ */ { zend_ffi_tag *tag; zend_ffi_type *type; |