]> granicus.if.org Git - php/commitdiff
add a standard Exception class.
authorSterling Hughes <sterling@php.net>
Sun, 23 Mar 2003 04:32:24 +0000 (04:32 +0000)
committerSterling Hughes <sterling@php.net>
Sun, 23 Mar 2003 04:32:24 +0000 (04:32 +0000)
Zend/Makefile.am
Zend/zend.c
Zend/zend_default_classes.c [new file with mode: 0644]
Zend/zend_default_classes.h [new file with mode: 0644]
Zend/zend_exceptions.c [new file with mode: 0644]
Zend/zend_exceptions.h [new file with mode: 0644]
configure.in

index cf28ff6b5fbb2f22f54b82d2f2c00fb072765507..8f1948eefc29e99c6ce1b551dcb8a64c8ceba262 100644 (file)
@@ -14,7 +14,7 @@ libZend_la_SOURCES=\
        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_classes.c
 
 libZend_la_LDFLAGS =
 libZend_la_LIBADD = @ZEND_EXTRA_LIBS@
index 0ae2f7dbfa099deea4dab146b4f67710d892da01..cc4484c31e6623317253397fdff6f9ea084d0bb3 100644 (file)
@@ -25,6 +25,7 @@
 #include "zend_constants.h"
 #include "zend_list.h"
 #include "zend_API.h"
+#include "zend_default_classes.h"
 #include "zend_builtin_functions.h"
 #include "zend_ini.h"
 
@@ -609,6 +610,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
        if (start_builtin_functions) {
                zend_startup_builtin_functions(TSRMLS_C);
        }
+       zend_register_default_classes(TSRMLS_C);
 
        zend_ini_startup(TSRMLS_C);
 
diff --git a/Zend/zend_default_classes.c b/Zend/zend_default_classes.c
new file mode 100644 (file)
index 0000000..bb58bde
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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 <sterling@php.net>                          |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#include "zend.h"
+#include "zend_API.h"
+
+zend_class_entry *default_exception_ptr;
+
+ZEND_FUNCTION(exception)
+{
+       zval **message;
+       zval **code;
+       zval  *tmp;
+       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);
+       }
+
+       MAKE_STD_ZVAL(tmp);
+       ZVAL_STRING(tmp, zend_get_executed_filename(TSRMLS_C), 1);
+       zend_hash_update(Z_OBJPROP_P(object), "file", sizeof("file"), (void **) &tmp, sizeof(zval *), NULL);
+       tmp = NULL;
+
+       MAKE_STD_ZVAL(tmp);
+       ZVAL_LONG(tmp, zend_get_executed_lineno(TSRMLS_C));
+       zend_hash_update(Z_OBJPROP_P(object), "line", sizeof("line"), (void **) &tmp, sizeof(zval *), NULL);
+}
+
+#define DEFAULT_0_PARAMS \
+       if (ZEND_NUM_ARGS() > 0) { \
+               ZEND_WRONG_PARAM_COUNT(); \
+       }
+
+static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC)
+{
+       zval **value;
+
+       if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       *return_value = **value;
+       zval_copy_ctor(return_value);
+}
+
+ZEND_FUNCTION(getfile)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "file", sizeof("file"), return_value);
+}
+
+ZEND_FUNCTION(getline)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "line", sizeof("line"), return_value);
+}
+
+ZEND_FUNCTION(getmessage)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "message", sizeof("message"), return_value);
+}
+
+ZEND_FUNCTION(getcode)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "code", sizeof("code"), return_value);
+}
+
+static zend_function_entry default_exception_functions[] = {
+       ZEND_FE(exception, NULL)
+       ZEND_FE(getmessage, NULL)
+       ZEND_FE(getcode, NULL)
+       ZEND_FE(getfile, NULL)
+       ZEND_FE(getline, 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_classes(TSRMLS_D)
+{
+       zend_register_default_exception(TSRMLS_CC);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/Zend/zend_default_classes.h b/Zend/zend_default_classes.h
new file mode 100644 (file)
index 0000000..3e7eae5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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 <sterling@php.net>                          |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef ZEND_DEFAULT_INTERFACES_H
+#define ZEND_DEFAULT_INTERFACES_H
+
+BEGIN_EXTERN_C()
+
+ZEND_API void zend_register_default_classes(TSRMLS_D);
+       
+END_EXTERN_C()
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
new file mode 100644 (file)
index 0000000..bb58bde
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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 <sterling@php.net>                          |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#include "zend.h"
+#include "zend_API.h"
+
+zend_class_entry *default_exception_ptr;
+
+ZEND_FUNCTION(exception)
+{
+       zval **message;
+       zval **code;
+       zval  *tmp;
+       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);
+       }
+
+       MAKE_STD_ZVAL(tmp);
+       ZVAL_STRING(tmp, zend_get_executed_filename(TSRMLS_C), 1);
+       zend_hash_update(Z_OBJPROP_P(object), "file", sizeof("file"), (void **) &tmp, sizeof(zval *), NULL);
+       tmp = NULL;
+
+       MAKE_STD_ZVAL(tmp);
+       ZVAL_LONG(tmp, zend_get_executed_lineno(TSRMLS_C));
+       zend_hash_update(Z_OBJPROP_P(object), "line", sizeof("line"), (void **) &tmp, sizeof(zval *), NULL);
+}
+
+#define DEFAULT_0_PARAMS \
+       if (ZEND_NUM_ARGS() > 0) { \
+               ZEND_WRONG_PARAM_COUNT(); \
+       }
+
+static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC)
+{
+       zval **value;
+
+       if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       *return_value = **value;
+       zval_copy_ctor(return_value);
+}
+
+ZEND_FUNCTION(getfile)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "file", sizeof("file"), return_value);
+}
+
+ZEND_FUNCTION(getline)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "line", sizeof("line"), return_value);
+}
+
+ZEND_FUNCTION(getmessage)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "message", sizeof("message"), return_value);
+}
+
+ZEND_FUNCTION(getcode)
+{
+       DEFAULT_0_PARAMS;
+
+       _default_exception_get_entry(getThis(), "code", sizeof("code"), return_value);
+}
+
+static zend_function_entry default_exception_functions[] = {
+       ZEND_FE(exception, NULL)
+       ZEND_FE(getmessage, NULL)
+       ZEND_FE(getcode, NULL)
+       ZEND_FE(getfile, NULL)
+       ZEND_FE(getline, 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_classes(TSRMLS_D)
+{
+       zend_register_default_exception(TSRMLS_CC);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
diff --git a/Zend/zend_exceptions.h b/Zend/zend_exceptions.h
new file mode 100644 (file)
index 0000000..3e7eae5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+   +----------------------------------------------------------------------+
+   | 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 <sterling@php.net>                          |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef ZEND_DEFAULT_INTERFACES_H
+#define ZEND_DEFAULT_INTERFACES_H
+
+BEGIN_EXTERN_C()
+
+ZEND_API void zend_register_default_classes(TSRMLS_D);
+       
+END_EXTERN_C()
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
index 2d0c3671593e73f8e8590dfb9ae445df02324d5d..43d666d2f330fabd4eab55521bdf8e8bf50889f0 100644 (file)
@@ -1129,7 +1129,7 @@ PHP_ADD_SOURCES(Zend, \
     zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \
     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_multibyte.c zend_ts_hash.c zend_stream.c)
+    zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c zend_stream.c zend_default_classes.c)
 
 if test -r "$abs_srcdir/Zend/zend_objects.c"; then
   PHP_ADD_SOURCES(Zend, zend_objects.c zend_object_handlers.c zend_objects_API.c zend_mm.c)