summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThies C. Arntzen <thies@php.net>1999-12-07 11:37:30 +0000
committerThies C. Arntzen <thies@php.net>1999-12-07 11:37:30 +0000
commita807dd31e9d6b565a62036eaf91a43e865e7d9e2 (patch)
tree70ddaa92ac06fbafc05ca9c500acadc242c879e4
parent512c641794e1b6f5895cfdf80b4907e693ab5398 (diff)
downloadphp-git-a807dd31e9d6b565a62036eaf91a43e865e7d9e2.tar.gz
new assert() module. (Not yet finished!)
-rw-r--r--ext/standard/Makefile.am2
-rw-r--r--ext/standard/assert.c230
-rw-r--r--ext/standard/php_assert.h28
-rw-r--r--main/internal_functions.c.in33
-rw-r--r--main/internal_functions_win32.c4
5 files changed, 273 insertions, 24 deletions
diff --git a/ext/standard/Makefile.am b/ext/standard/Makefile.am
index 294807cf6e..6191a23f2a 100644
--- a/ext/standard/Makefile.am
+++ b/ext/standard/Makefile.am
@@ -6,7 +6,7 @@ libphpext_standard_la_SOURCES=\
formatted_print.c fsock.c head.c html.c image.c info.c iptc.c lcg.c \
link.c mail.c math.c md5.c metaphone.c microtime.c pack.c pageinfo.c \
parsedate.y post.c quot_print.c rand.c reg.c soundex.c string.c \
- syslog.c type.c uniqid.c url.c url_scanner.c var.c output.c
+ syslog.c type.c uniqid.c url.c url_scanner.c var.c output.c assert.c
$(srcdir)/url_scanner.c: $(srcdir)/url_scanner.re
-re2c $< > $@.new && mv $@.new $@
diff --git a/ext/standard/assert.c b/ext/standard/assert.c
new file mode 100644
index 0000000000..b8b72e3844
--- /dev/null
+++ b/ext/standard/assert.c
@@ -0,0 +1,230 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Thies C. Arntzen (thies@digicol.de) |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+/* {{{ includes/startup/misc */
+
+#include "php.h"
+#include "php_assert.h"
+
+typedef struct {
+ int active;
+ int exit;
+ char *callback;
+} php_assert_globals;
+
+#ifdef ZTS
+#define ASSERT(v) (assert_globals->v)
+#define ASSERTLS_FETCH() php_assert_globals *assert_globals = ts_resource(assert_globals_id)
+int assert_globals_id;
+#else
+#define ASSERT(v) (assert_globals.v)
+#define ASSERTLS_FETCH()
+php_assert_globals assert_globals;
+#endif
+
+PHP_MINIT_FUNCTION(assert);
+PHP_MSHUTDOWN_FUNCTION(assert);
+PHP_RINIT_FUNCTION(assert);
+PHP_RSHUTDOWN_FUNCTION(assert);
+PHP_MINFO_FUNCTION(assert);
+
+PHP_FUNCTION(assert);
+PHP_FUNCTION(assert_options);
+
+static zend_function_entry php_assert_functions[] = {
+ PHP_FE(assert, NULL)
+ PHP_FE(assert_options, NULL)
+ {NULL, NULL, NULL}
+};
+
+
+zend_module_entry assert_module_entry = {
+ "Assertion",
+ php_assert_functions,
+ PHP_MINIT(assert),
+ PHP_MSHUTDOWN(assert),
+ PHP_RINIT(assert),
+ PHP_RSHUTDOWN(assert),
+ PHP_MINFO(assert),
+ STANDARD_MODULE_PROPERTIES
+};
+
+#define ASSERT_ACTIVE 1
+#define ASSERT_CALLBACK 2
+#define ASSERT_EXIT 3
+
+#ifdef ZTS
+static void php_assert_init_globals(php_assert_globals *assert_globals)
+{
+ ASSERT(active) = 0;
+ ASSERT(exit) = 0;
+ ASSERT(callback) = 0;
+}
+#endif
+
+PHP_MINIT_FUNCTION(assert)
+{
+
+#ifdef ZTS
+ assert_globals_id = ts_allocate_id(sizeof(php_assert_globals), (ts_allocate_ctor) php_assert_init_globals, NULL);
+#else
+ ASSERT(active) = 0;
+ ASSERT(exit) = 0;
+ ASSERT(callback) = 0;
+#endif
+
+ REGISTER_LONG_CONSTANT("ASSERT_ACTIVE", ASSERT_ACTIVE, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ASSERT_CALLBACK", ASSERT_CALLBACK, CONST_CS|CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("ASSERT_EXIT", ASSERT_EXIT, CONST_CS|CONST_PERSISTENT);
+
+ return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(assert)
+{
+ return SUCCESS;
+}
+
+PHP_RINIT_FUNCTION(assert)
+{
+ return SUCCESS;
+}
+
+PHP_RSHUTDOWN_FUNCTION(assert)
+{
+ return SUCCESS;
+}
+
+PHP_MINFO_FUNCTION(assert)
+{
+}
+
+/* }}} */
+/* {{{ internal functions */
+/* }}} */
+/* {{{ proto int assert(string|int assertion)
+ checks if assertion is false */
+
+PHP_FUNCTION(assert)
+{
+ pval **assertion;
+ int val;
+ char *myeval = empty_string;
+ ASSERTLS_FETCH();
+
+ if (! ASSERT(active)) {
+ RETURN_TRUE;
+ }
+
+ if (ARG_COUNT(ht) != 1 || getParametersEx(1, &assertion) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if ((*assertion)->type == IS_STRING) {
+ zval retval;
+ CLS_FETCH();
+ ELS_FETCH();
+
+ myeval = (*assertion)->value.str.val;
+ zend_eval_string(myeval, &retval CLS_CC ELS_CC);
+ convert_to_boolean(&retval);
+ val = retval.value.lval;
+ } else {
+ convert_to_boolean_ex(assertion);
+ val = (*assertion)->value.lval;
+ }
+
+ if (val) {
+ RETURN_TRUE;
+ }
+ php_error(E_WARNING,"Assertion \"%s\" failed",myeval);
+
+ if (ASSERT(exit)) {
+ zend_bailout();
+ }
+}
+
+/* }}} */
+/* {{{ proto mixed assert_options(int what,mixed value)
+ set/get the various assert flags. */
+
+PHP_FUNCTION(assert_options)
+{
+ pval **what,**value;
+ int oldint;
+ char *oldstr;
+ int ac = ARG_COUNT(ht);
+ ASSERTLS_FETCH();
+
+ if (ac < 1 || ac > 2 || getParametersEx(ac, &what, &value) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long_ex(what);
+
+ switch ((*what)->value.lval) {
+ case ASSERT_ACTIVE:
+ oldint = ASSERT(active);
+ if (ac == 2) {
+ convert_to_long_ex(value);
+ ASSERT(active) = (*value)->value.lval;
+ }
+ RETURN_LONG(oldint);
+ break;
+
+ case ASSERT_EXIT:
+ oldint = ASSERT(exit);
+ if (ac == 2) {
+ convert_to_long_ex(value);
+ ASSERT(exit) = (*value)->value.lval;
+ }
+ RETURN_LONG(oldint);
+ break;
+
+ case ASSERT_CALLBACK:
+ oldstr = ASSERT(callback);
+ RETVAL_STRING(oldstr,1);
+
+ if (ac == 2) {
+ convert_to_string_ex(value);
+ ASSERT(callback) = estrndup((*value)->value.str.val,(*value)->value.str.len);
+ }
+ if (oldstr) {
+ efree(oldstr);
+ }
+ return;
+ break;
+
+ default:
+ php_error(E_WARNING,"Unknown value %d.",(*what)->value.lval);
+ break;
+ }
+
+ RETURN_FALSE;
+}
+
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ext/standard/php_assert.h b/ext/standard/php_assert.h
new file mode 100644
index 0000000000..597eb6af4c
--- /dev/null
+++ b/ext/standard/php_assert.h
@@ -0,0 +1,28 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Thies C. Arntzen (thies@digicol.de) |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#ifndef _PHP_ASSERT_H
+#define _PHP_ASSERT_H
+
+extern zend_module_entry assert_module_entry;
+#define phpext_assert_ptr &assert_module_entry
+
+
+#endif /* _PHP_ASSERT_H */
diff --git a/main/internal_functions.c.in b/main/internal_functions.c.in
index c797ae6616..7b3020fa3d 100644
--- a/main/internal_functions.c.in
+++ b/main/internal_functions.c.in
@@ -1,27 +1,16 @@
-/*
+/*
+----------------------------------------------------------------------+
- | PHP HTML Embedded Scripting Language Version 3.0 |
+ | PHP version 4.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+ | Copyright (c) 1997, 1998, 1999 The PHP Group |
+----------------------------------------------------------------------+
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of one of the following licenses: |
- | |
- | A) the GNU General Public License as published by the Free Software |
- | Foundation; either version 2 of the License, or (at your option) |
- | any later version. |
- | |
- | B) the PHP License as published by the PHP Development Team and |
- | included in the distribution in the file: LICENSE |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of both licenses referred to here. |
- | If you did not, or have any questions about PHP licensing, please |
- | contact core@php.net. |
+ | This source file is subject to version 2.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
@@ -31,7 +20,6 @@
/* $Id$ */
-
#include "php.h"
#include "modules.h"
#include "internal_functions_registry.h"
@@ -67,6 +55,7 @@ zend_module_entry *php3_builtin_modules[] = {
phpext_metaphone_ptr,
phpext_output_ptr,
phpext_array_ptr,
+ phpext_assert_ptr,
@EXT_MODULE_PTRS@
};
diff --git a/main/internal_functions_win32.c b/main/internal_functions_win32.c
index 244303d9d3..c93de106b5 100644
--- a/main/internal_functions_win32.c
+++ b/main/internal_functions_win32.c
@@ -47,6 +47,7 @@
#include "ext/standard/php_lcg.h"
#include "ext/standard/php_output.h"
#include "ext/standard/php_array.h"
+#include "ext/standard/php_assert.h"
#include "ext/COM/php_COM.h"
#include "ext/standard/reg.h"
#include "ext/pcre/php_pcre.h"
@@ -84,7 +85,8 @@ zend_module_entry *php3_builtin_modules[] = {
phpext_lcg_ptr,
phpext_session_ptr,
phpext_output_ptr,
- phpext_array_ptr
+ phpext_array_ptr,
+ phpext_assert_ptr
};