Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:149 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80202 invoked from network); 22 Mar 2003 21:26:30 -0000 Received: from unknown (HELO carmine.bestweb.net) (209.94.102.73) by pb1.pair.com with SMTP; 22 Mar 2003 21:26:30 -0000 Received: from [192.168.1.100] (unknown [216.179.71.153]) by carmine.bestweb.net (Postfix) with ESMTP id 174A223FBC for ; Sat, 22 Mar 2003 16:26:28 -0500 (EST) To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-Eohz4S2YlMVUtEiixvtp" Organization: Message-ID: <1048367260.848.1147.camel@hasele> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 22 Mar 2003 16:07:40 -0500 Subject: default exceptions, interfaces, etc. From: sterling@bumblebury.com (Sterling Hughes) --=-Eohz4S2YlMVUtEiixvtp Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, Attached is a patch (+ 2 files) that add a default "exception" class to Zend 2. I find this very useful when you just want to throw a simple exception inside of a try {}, but you don't want to create a new exception for each and every error. I'll commit this tommorowish, unless somebody objects. -Sterling -- "Whether you think you can or think you can't -- you are right." - Henry Ford --=-Eohz4S2YlMVUtEiixvtp Content-Disposition: attachment; filename=interfaces.diff Content-Type: text/x-patch; name=interfaces.diff; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Index: Makefile.am =================================================================== RCS file: /repository/ZendEngine2/Makefile.am,v retrieving revision 1.51 diff -u -r1.51 Makefile.am --- Makefile.am 17 Mar 2003 11:23:42 -0000 1.51 +++ Makefile.am 22 Mar 2003 21:13:12 -0000 @@ -14,7 +14,7 @@ zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \ zend_ini.c zend_qsort.c zend_objects.c zend_object_handlers.c \ - zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c + zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c zend_default_interfaces.c libZend_la_LDFLAGS = libZend_la_LIBADD = @ZEND_EXTRA_LIBS@ Index: zend.c =================================================================== RCS file: /repository/ZendEngine2/zend.c,v retrieving revision 1.214 diff -u -r1.214 zend.c --- zend.c 2 Mar 2003 10:04:53 -0000 1.214 +++ zend.c 22 Mar 2003 21:13:14 -0000 @@ -25,6 +25,7 @@ #include "zend_constants.h" #include "zend_list.h" #include "zend_API.h" +#include "zend_default_interfaces.h" #include "zend_builtin_functions.h" #include "zend_ini.h" @@ -609,6 +610,7 @@ if (start_builtin_functions) { zend_startup_builtin_functions(TSRMLS_C); } + zend_register_default_interfaces(TSRMLS_C); zend_ini_startup(TSRMLS_C); --=-Eohz4S2YlMVUtEiixvtp Content-Disposition: attachment; filename=zend_default_interfaces.c Content-Type: text/x-c; name=zend_default_interfaces.c; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit /* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ | Copyright (c) 1998-2003 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.zend.com/license/2_00.txt. | | If you did not receive a copy of the Zend license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@zend.com so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Sterling Hughes | +----------------------------------------------------------------------+ */ /* $Id: $ */ #include "zend.h" #include "zend_API.h" zend_class_entry *default_exception_ptr; ZEND_FUNCTION(exception) { zval **message; zval **code; zval *object; int argc = ZEND_NUM_ARGS(); if (zend_get_parameters_ex(argc, &message, &code) == FAILURE) { ZEND_WRONG_PARAM_COUNT(); } object = getThis(); if (argc > 0) { convert_to_string_ex(message); zval_add_ref(message); zend_hash_update(Z_OBJPROP_P(object), "message", sizeof("message"), (void **) message, sizeof(zval *), NULL); } if (argc > 1) { convert_to_long_ex(code); zval_add_ref(code); zend_hash_update(Z_OBJPROP_P(object), "code", sizeof("code"), (void **) code, sizeof(zval *), NULL); } } ZEND_FUNCTION(getmessage) { zval **message; zval *object; if (ZEND_NUM_ARGS() > 0) { ZEND_WRONG_PARAM_COUNT(); } object = getThis(); if (zend_hash_find(Z_OBJPROP_P(object), "message", sizeof("message"), (void **) &message) == FAILURE) { RETURN_FALSE; } *return_value = **message; zval_copy_ctor(return_value); } ZEND_FUNCTION(getcode) { zval **code; zval *object; if (ZEND_NUM_ARGS() > 0) { ZEND_WRONG_PARAM_COUNT(); } object = getThis(); if (zend_hash_find(Z_OBJPROP_P(object), "code", sizeof("code"), (void **) &code) == FAILURE) { RETURN_FALSE; } *return_value = **code; zval_copy_ctor(return_value); } static zend_function_entry default_exception_functions[] = { ZEND_FE(exception, NULL) ZEND_FE(getmessage, NULL) ZEND_FE(getcode, NULL) {NULL, NULL, NULL} }; static void zend_register_default_exception(TSRMLS_C) { zend_class_entry default_exception; INIT_CLASS_ENTRY(default_exception, "exception", default_exception_functions); default_exception_ptr = zend_register_internal_class(&default_exception TSRMLS_CC); } ZEND_API void zend_register_default_interfaces(TSRMLS_D) { zend_register_default_exception(TSRMLS_CC); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */ --=-Eohz4S2YlMVUtEiixvtp Content-Disposition: attachment; filename=zend_default_interfaces.h Content-Type: text/x-c-header; name=zend_default_interfaces.h; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit /* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ | Copyright (c) 1998-2003 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.zend.com/license/2_00.txt. | | If you did not receive a copy of the Zend license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@zend.com so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Sterling Hughes | +----------------------------------------------------------------------+ */ /* $Id: $ */ #ifndef ZEND_DEFAULT_INTERFACES_H #define ZEND_DEFAULT_INTERFACES_H BEGIN_EXTERN_C() ZEND_API void zend_register_default_interfaces(TSRMLS_D); END_EXTERN_C() #endif /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */ --=-Eohz4S2YlMVUtEiixvtp--