From e282290d71e4f5a343b7b897312c69168985b896 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 13 May 2015 08:45:20 +0200 Subject: [PATCH 1/4] Rename REGISTER_ITERATOR_INTERFACE macro to REGISTER_INTERFACE (as it is also used to register interfaces that are not related to iterators) --- Zend/zend_interfaces.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 54f8f8c117245..f2a8e1fefb59e 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -551,7 +551,7 @@ const zend_function_entry zend_funcs_serializable[] = { }; /* }}} */ -#define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \ +#define REGISTER_INTERFACE(class_name, class_name_str) \ {\ zend_class_entry ce;\ INIT_CLASS_ENTRY(ce, # class_name_str, zend_funcs_ ## class_name) \ @@ -565,17 +565,17 @@ const zend_function_entry zend_funcs_serializable[] = { /* {{{ zend_register_interfaces */ ZEND_API void zend_register_interfaces(void) { - REGISTER_ITERATOR_INTERFACE(traversable, Traversable); + REGISTER_INTERFACE(traversable, Traversable); - REGISTER_ITERATOR_INTERFACE(aggregate, IteratorAggregate); + REGISTER_INTERFACE(aggregate, IteratorAggregate); REGISTER_ITERATOR_IMPLEMENT(aggregate, traversable); - REGISTER_ITERATOR_INTERFACE(iterator, Iterator); + REGISTER_INTERFACE(iterator, Iterator); REGISTER_ITERATOR_IMPLEMENT(iterator, traversable); - REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess); + REGISTER_INTERFACE(arrayaccess, ArrayAccess); - REGISTER_ITERATOR_INTERFACE(serializable, Serializable) + REGISTER_INTERFACE(serializable, Serializable) } /* }}} */ From 85e87d7f8764a919a16e9ce8b2cb53e3886491e2 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 13 May 2015 09:03:16 +0200 Subject: [PATCH 2/4] Introduce Throwable interface --- Zend/zend_interfaces.c | 12 ++++++++++++ Zend/zend_interfaces.h | 1 + 2 files changed, 13 insertions(+) diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index f2a8e1fefb59e..abf1c46e5ac6f 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -28,6 +28,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate; ZEND_API zend_class_entry *zend_ce_iterator; ZEND_API zend_class_entry *zend_ce_arrayaccess; ZEND_API zend_class_entry *zend_ce_serializable; +ZEND_API zend_class_entry *zend_ce_throwable; /* {{{ zend_call_method Only returns the returned zval if retval_ptr != NULL */ @@ -502,6 +503,13 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e } /* }}}*/ +/* {{{ zend_implement_throwable */ +static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type) +{ + return SUCCESS; +} +/* }}}*/ + /* {{{ function tables */ const zend_function_entry zend_funcs_aggregate[] = { ZEND_ABSTRACT_ME(iterator, getIterator, NULL) @@ -549,6 +557,8 @@ const zend_function_entry zend_funcs_serializable[] = { ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR) ZEND_FE_END }; + +const zend_function_entry *zend_funcs_throwable = NULL; /* }}} */ #define REGISTER_INTERFACE(class_name, class_name_str) \ @@ -576,6 +586,8 @@ ZEND_API void zend_register_interfaces(void) REGISTER_INTERFACE(arrayaccess, ArrayAccess); REGISTER_INTERFACE(serializable, Serializable) + + REGISTER_INTERFACE(throwable, Throwable) } /* }}} */ diff --git a/Zend/zend_interfaces.h b/Zend/zend_interfaces.h index 8a8e0ce988a6b..daf0aae5dc141 100644 --- a/Zend/zend_interfaces.h +++ b/Zend/zend_interfaces.h @@ -31,6 +31,7 @@ extern ZEND_API zend_class_entry *zend_ce_aggregate; extern ZEND_API zend_class_entry *zend_ce_iterator; extern ZEND_API zend_class_entry *zend_ce_arrayaccess; extern ZEND_API zend_class_entry *zend_ce_serializable; +extern ZEND_API zend_class_entry *zend_ce_throwable; typedef struct _zend_user_iterator { zend_object_iterator it; From 412843b26e70834d7df18c4d6e0514cfb506cbd7 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 13 May 2015 09:03:35 +0200 Subject: [PATCH 3/4] Let the default Exception class implement the Throwable interface --- Zend/zend_exceptions.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c6bef24346a18..8c03a4a6cefc9 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -752,6 +752,7 @@ void zend_register_default_exception(void) /* {{{ */ INIT_CLASS_ENTRY(ce, "Exception", NULL); default_exception_ce = zend_register_internal_class_ex(&ce, base_exception_ce); default_exception_ce->create_object = zend_default_exception_new; + zend_class_implements(default_exception_ce, 1, zend_ce_throwable); /* A trick, to make visible private properties of BaseException */ ZEND_HASH_FOREACH_PTR(&default_exception_ce->properties_info, prop) { From 6efb8bf8b4348ebcdae7a6e9a45abf3529a731d0 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 13 May 2015 09:29:14 +0200 Subject: [PATCH 4/4] * Rename ErrorException to Error * Rename EngineException to EngineError and let it extend Error * Rename ParseException to ParseError and let it extend Error * Rename TypeException to TypeError and let it extend Error --- Zend/zend_exceptions.c | 47 +++++++++++++++++++++++++++++------------- Zend/zend_exceptions.h | 2 +- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 8c03a4a6cefc9..45ed142a644bf 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -32,7 +32,7 @@ static zend_class_entry *base_exception_ce; static zend_class_entry *default_exception_ce; -static zend_class_entry *error_exception_ce; +static zend_class_entry *error_ce; static zend_class_entry *engine_exception_ce; static zend_class_entry *parse_exception_ce; static zend_class_entry *type_exception_ce; @@ -740,6 +740,7 @@ void zend_register_default_exception(void) /* {{{ */ base_exception_ce->create_object = NULL; memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); default_exception_handlers.clone_obj = NULL; + zend_class_implements(base_exception_ce, 1, zend_ce_throwable); zend_declare_property_string(base_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED); zend_declare_property_string(base_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE); @@ -752,7 +753,6 @@ void zend_register_default_exception(void) /* {{{ */ INIT_CLASS_ENTRY(ce, "Exception", NULL); default_exception_ce = zend_register_internal_class_ex(&ce, base_exception_ce); default_exception_ce->create_object = zend_default_exception_new; - zend_class_implements(default_exception_ce, 1, zend_ce_throwable); /* A trick, to make visible private properties of BaseException */ ZEND_HASH_FOREACH_PTR(&default_exception_ce->properties_info, prop) { @@ -773,21 +773,40 @@ void zend_register_default_exception(void) /* {{{ */ } } ZEND_HASH_FOREACH_END(); - INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions); - error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce); - error_exception_ce->create_object = zend_error_exception_new; - zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED); + INIT_CLASS_ENTRY(ce, "Error", NULL); + error_ce = zend_register_internal_class_ex(&ce, base_exception_ce); + error_ce->create_object = zend_default_exception_new; + zend_declare_property_long(error_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED); - INIT_CLASS_ENTRY(ce, "EngineException", NULL); - engine_exception_ce = zend_register_internal_class_ex(&ce, base_exception_ce); + /* A trick, to make visible private properties of BaseException */ + ZEND_HASH_FOREACH_PTR(&error_ce->properties_info, prop) { + if (prop->flags & ZEND_ACC_SHADOW) { + if (prop->name->len == sizeof("\0BaseException\0string")-1) { + prop->flags &= ~ZEND_ACC_SHADOW; + prop->flags |= ZEND_ACC_PRIVATE; + prop->ce = error_ce; + } else if (prop->name->len == sizeof("\0BaseException\0trace")-1) { + prop->flags &= ~ZEND_ACC_SHADOW; + prop->flags |= ZEND_ACC_PRIVATE; + prop->ce = error_ce; + } else if (prop->name->len == sizeof("\0BaseException\0previous")-1) { + prop->flags &= ~ZEND_ACC_SHADOW; + prop->flags |= ZEND_ACC_PRIVATE; + prop->ce = error_ce; + } + } + } ZEND_HASH_FOREACH_END(); + + INIT_CLASS_ENTRY(ce, "EngineError", NULL); + engine_exception_ce = zend_register_internal_class_ex(&ce, error_ce); engine_exception_ce->create_object = zend_default_exception_new; - INIT_CLASS_ENTRY(ce, "ParseException", NULL); - parse_exception_ce = zend_register_internal_class_ex(&ce, base_exception_ce); + INIT_CLASS_ENTRY(ce, "ParseError", NULL); + parse_exception_ce = zend_register_internal_class_ex(&ce, error_ce); parse_exception_ce->create_object = zend_default_exception_new; - INIT_CLASS_ENTRY(ce, "TypeException", NULL); - type_exception_ce = zend_register_internal_class_ex(&ce, engine_exception_ce); + INIT_CLASS_ENTRY(ce, "TypeError", NULL); + type_exception_ce = zend_register_internal_class_ex(&ce, error_ce); type_exception_ce->create_object = zend_default_exception_new; } /* }}} */ @@ -804,9 +823,9 @@ ZEND_API zend_class_entry *zend_exception_get_default(void) /* {{{ */ } /* }}} */ -ZEND_API zend_class_entry *zend_get_error_exception(void) /* {{{ */ +ZEND_API zend_class_entry *zend_get_error(void) /* {{{ */ { - return error_exception_ce; + return error_ce; } /* }}} */ diff --git a/Zend/zend_exceptions.h b/Zend/zend_exceptions.h index e2c1f1fac7fe4..49b721ce67272 100644 --- a/Zend/zend_exceptions.h +++ b/Zend/zend_exceptions.h @@ -36,7 +36,7 @@ void zend_register_default_exception(void); ZEND_API zend_class_entry *zend_exception_get_base(void); ZEND_API zend_class_entry *zend_exception_get_default(void); -ZEND_API zend_class_entry *zend_get_error_exception(void); +ZEND_API zend_class_entry *zend_get_error(void); ZEND_API zend_class_entry *zend_get_engine_exception(void); ZEND_API zend_class_entry *zend_get_parse_exception(void); ZEND_API zend_class_entry *zend_get_type_exception(void);