]> granicus.if.org Git - php/commitdiff
Move definition of Throwable to zend_exceptions.h/c
authorAaron Piotrowski <aaron@trowski.com>
Mon, 15 Jun 2015 23:07:27 +0000 (18:07 -0500)
committerAaron Piotrowski <aaron@trowski.com>
Mon, 15 Jun 2015 23:07:27 +0000 (18:07 -0500)
Also moved REGISTER_ITERATOR_INTERFACE macro to
zend_interfaces.h and renamed it to REGISTER_INTERFACE.

Zend/zend_exceptions.c
Zend/zend_exceptions.h
Zend/zend_interfaces.c
Zend/zend_interfaces.h

index 08342e9050456e80c654f42d1acef1f9612c324b..6b1d41efb987f8be975b14043c122883697af3ab 100644 (file)
@@ -30,6 +30,8 @@
 #include "zend_dtrace.h"
 #include "zend_smart_str.h"
 
+ZEND_API zend_class_entry *zend_ce_throwable;
+
 static zend_class_entry *default_exception_ce;
 static zend_class_entry *error_exception_ce;
 static zend_class_entry *error_ce;
@@ -38,6 +40,21 @@ static zend_class_entry *type_error_ce;
 static zend_object_handlers default_exception_handlers;
 ZEND_API void (*zend_throw_exception_hook)(zval *ex);
 
+/* {{{ zend_implement_throwable */
+static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type)
+{
+       if (instanceof_function(class_type, default_exception_ce) || instanceof_function(class_type, error_ce)) {
+               return SUCCESS;
+       }
+       zend_error_noreturn(E_ERROR, "Class %s cannot implement interface %s, extend %s or %s instead",
+               class_type->name->val,
+               interface->name->val,
+               default_exception_ce->name->val,
+               error_ce->name->val);
+       return FAILURE;
+}
+/* }}} */
+
 static inline zend_class_entry *zend_get_exception_base(zval *object)
 {
        return instanceof_function(Z_OBJCE_P(object), default_exception_ce) ? default_exception_ce : error_ce;
@@ -710,6 +727,20 @@ ZEND_METHOD(exception, __toString)
 }
 /* }}} */
 
+/** {{{ Throwable method definition */
+const zend_function_entry zend_funcs_throwable[] = {
+       ZEND_ABSTRACT_ME(throwable, getMessage,       NULL)
+       ZEND_ABSTRACT_ME(throwable, getCode,          NULL)
+       ZEND_ABSTRACT_ME(throwable, getFile,          NULL)
+       ZEND_ABSTRACT_ME(throwable, getLine,          NULL)
+       ZEND_ABSTRACT_ME(throwable, getTrace,         NULL)
+       ZEND_ABSTRACT_ME(throwable, getPrevious,      NULL)
+       ZEND_ABSTRACT_ME(throwable, getTraceAsString, NULL)
+       ZEND_ABSTRACT_ME(throwable, __toString,       NULL)
+       ZEND_FE_END
+};
+/* }}} */
+
 /* {{{ internal structs */
 /* All functions that may be used in uncaught exception handlers must be final
  * and must not throw exceptions. Otherwise we would need a facility to handle
@@ -760,6 +791,8 @@ void zend_register_default_exception(void) /* {{{ */
 {
        zend_class_entry ce;
        zend_property_info *prop;
+       
+       REGISTER_INTERFACE(throwable, Throwable);
 
        memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        default_exception_handlers.clone_obj = NULL;
index 6f7ceed78eb979381a6a8fd872d111ffbc1c98a1..d22b99c262a39281d60b9fed74b2d43f63f58c00 100644 (file)
@@ -26,6 +26,8 @@
 
 BEGIN_EXTERN_C()
 
+extern ZEND_API zend_class_entry *zend_ce_throwable;
+
 ZEND_API void zend_exception_set_previous(zend_object *exception, zend_object *add_previous);
 ZEND_API void zend_exception_save(void);
 ZEND_API void zend_exception_restore(void);
index e5b2d3f80e9bbedfcb4b071cfabd1b1a1f06a2a1..0e5942554f323ca1446083fb44bc21fbca9b1412 100644 (file)
@@ -28,7 +28,6 @@ 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 */
@@ -503,21 +502,6 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
 }
 /* }}}*/
 
-/* {{{ zend_implement_traversable */
-static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type)
-{
-       if (instanceof_function(class_type, zend_exception_get_default()) || instanceof_function(class_type, zend_get_error())) {
-               return SUCCESS;
-       }
-       zend_error_noreturn(E_ERROR, "Class %s cannot implement interface %s, extend %s or %s instead",
-               class_type->name->val,
-               interface->name->val,
-               zend_exception_get_default()->name->val,
-               zend_get_error()->name->val);
-       return FAILURE;
-}
-/* }}} */
-
 /* {{{ function tables */
 const zend_function_entry zend_funcs_aggregate[] = {
        ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
@@ -567,45 +551,23 @@ const zend_function_entry zend_funcs_serializable[] = {
 };
 /* }}} */
 
-const zend_function_entry zend_funcs_throwable[] = {
-       ZEND_ABSTRACT_ME(throwable, getMessage,       NULL)
-       ZEND_ABSTRACT_ME(throwable, getCode,          NULL)
-       ZEND_ABSTRACT_ME(throwable, getFile,          NULL)
-       ZEND_ABSTRACT_ME(throwable, getLine,          NULL)
-       ZEND_ABSTRACT_ME(throwable, getTrace,         NULL)
-       ZEND_ABSTRACT_ME(throwable, getPrevious,      NULL)
-       ZEND_ABSTRACT_ME(throwable, getTraceAsString, NULL)
-       ZEND_ABSTRACT_ME(throwable, __toString,       NULL)
-       ZEND_FE_END
-};
-
-#define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \
-       {\
-               zend_class_entry ce;\
-               INIT_CLASS_ENTRY(ce, # class_name_str, zend_funcs_ ## class_name) \
-               zend_ce_ ## class_name = zend_register_internal_interface(&ce);\
-               zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
-       }
-
 #define REGISTER_ITERATOR_IMPLEMENT(class_name, interface_name) \
        zend_class_implements(zend_ce_ ## class_name, 1, zend_ce_ ## interface_name)
 
 /* {{{ 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_ITERATOR_INTERFACE(serializable, Serializable);
+       REGISTER_INTERFACE(arrayaccess, ArrayAccess);
 
-       REGISTER_ITERATOR_INTERFACE(throwable, Throwable);
+       REGISTER_INTERFACE(serializable, Serializable);
 }
 /* }}} */
 
index daf0aae5dc14174b71d463c40dffd152c8b0f313..d7b7645e162dc77227458e5639e6647632b540d5 100644 (file)
@@ -31,7 +31,6 @@ 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;
@@ -50,6 +49,14 @@ ZEND_API zval* zend_call_method(zval *object_pp, zend_class_entry *obj_ce, zend_
 #define zend_call_method_with_2_params(obj, obj_ce, fn_proxy, function_name, retval, arg1, arg2) \
        zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 2, arg1, arg2)
 
+#define REGISTER_INTERFACE(class_name, class_name_str) \
+       {\
+               zend_class_entry ce;\
+               INIT_CLASS_ENTRY(ce, # class_name_str, zend_funcs_ ## class_name) \
+               zend_ce_ ## class_name = zend_register_internal_interface(&ce);\
+               zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
+       }
+
 ZEND_API void zend_user_it_rewind(zend_object_iterator *_iter);
 ZEND_API int zend_user_it_valid(zend_object_iterator *_iter);
 ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *key);