helly Tue Sep 2 08:12:06 2003 EDT Modified files: /php-src/main main.c Log: Error message clean up part IV: spprintf/estrndup don't return on 'out of mem' Error message clean up part V: Show PHP Startup/Shutdown Index: php-src/main/main.c diff -u php-src/main/main.c:1.574 php-src/main/main.c:1.575 --- php-src/main/main.c:1.574 Mon Sep 1 20:35:51 2003 +++ php-src/main/main.c Tue Sep 2 08:12:05 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.574 2003/09/02 00:35:51 helly Exp $ */ +/* $Id: main.c,v 1.575 2003/09/02 12:12:05 helly Exp $ */ /* {{{ includes */ @@ -337,8 +337,11 @@ PHP_INI_END() /* }}} */ -/* True global (no need for thread safety */ +/* True globals (no need for thread safety */ +/* But don't make them a single int bitfield */ static int module_initialized = 0; +static int module_startup = 1; +static int module_shutdown = 0; /* {{{ php_log_err */ @@ -410,6 +413,23 @@ } /* }}} */ +/* {{{ php_verror helpers */ + +/* {{{ php_during_module_startup */ +static int php_during_module_startup() +{ + return module_startup; +} +/* }}} */ + +/* {{{ php_during_module_shutdown */ +static int php_during_module_shutdown() +{ + return module_shutdown; +} +/* }}} */ + +/* {{{ get_active_class_name */ static char *get_active_class_name(char **space TSRMLS_DC) { if (!zend_is_executing(TSRMLS_C)) { @@ -436,6 +456,8 @@ return ""; } } +/* }}} */ +/* }}} */ /* {{{ php_verror */ /* php_verror is called from php_error_docref<n> functions. @@ -451,12 +473,14 @@ int buffer_len = 0; char *space; char *class_name = get_active_class_name(&space TSRMLS_CC); - char *function = get_active_function_name(TSRMLS_C); + char *function; char *origin; char *message; + int is_function = 0; + /* get error text into buffer and escape for html if necessary */ buffer_len = vspprintf(&buffer, 0, format, args); - if (buffer && PG(html_errors)) { + if (PG(html_errors)) { int len; char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC); efree(buffer); @@ -464,93 +488,87 @@ buffer_len = len; } - if (buffer) { + /* which function caused the problem if any at all */ + if (php_during_module_startup()) { + function = "PHP Startup"; + } else if (php_during_module_shutdown()) { + function = "PHP Shutdown"; + } else { + function = get_active_function_name(TSRMLS_C); if (!function || !strlen(function)) { function = "Unknown"; - spprintf(&origin, 0, "%s", function); } else { - spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); + is_function = 1; } } - if (buffer && origin) { - if (docref && docref[0] == '#') { - docref_target = strchr(docref, '#'); - docref = NULL; - } - if (!docref) { - if (function) { - spprintf(&docref_buf, 0, "function.%s", function); - if (docref_buf) { - while((p=strchr(docref_buf, '_'))!=NULL) *p = '-'; - docref = docref_buf; - } + /* if we still have memory then format the origin */ + if (is_function) { + spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); + } else { + spprintf(&origin, 0, "%s", function); + } + + /* origin and buffer available, so lets come up with the error message */ + if (docref && docref[0] == '#') { + docref_target = strchr(docref, '#'); + docref = NULL; + } + if (!docref && is_function) { + spprintf(&docref_buf, 0, "function.%s", function); + while((p = strchr(docref_buf, '_')) != NULL) { + *p = '-'; + } + docref = docref_buf; + } + if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) { + if (strncmp(docref, "http://", 7)) { + docref_root = PG(docref_root); + /* now check copy of extension */ + ref = estrdup(docref); + if (docref_buf) { + efree(docref_buf); } - } - if (docref && (PG(html_errors) || strlen(PG(docref_root)))) { - if (strncmp(docref, "http://", 7)) { - docref_root = PG(docref_root); - /* now check copy of extension */ - ref = estrdup(docref); - if (ref) { - if (docref_buf) { - efree(docref_buf); - } - docref_buf = ref; - docref = docref_buf; - p = strrchr(ref, '#'); - if (p) { - target = estrdup(p); - if (target) { - docref_target = target; - *p = '\0'; - } - } - if ((!p || target) && PG(docref_ext) && strlen(PG(docref_ext))) { - spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext)); - if (docref_buf) { - efree(ref); - docref = docref_buf; - } - } + docref_buf = ref; + docref = docref_buf; + p = strrchr(ref, '#'); + if (p) { + target = estrdup(p); + if (target) { + docref_target = target; + *p = '\0'; } } - if (PG(html_errors)) { - spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer); - } else { - spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer); - } - if (target) { - efree(target); + if ((!p || target) && PG(docref_ext) && strlen(PG(docref_ext))) { + spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext)); + efree(ref); + docref = docref_buf; } + } + if (PG(html_errors)) { + spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer); } else { - spprintf(&message, 0, "%s: %s ", origin, buffer); + spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer); } - efree(buffer); - efree(origin); - if (docref_buf) { - efree(docref_buf); - } - php_error(type, "%s", message); - - if (PG(track_errors) && EG(active_symbol_table)) { - zval *tmp; - ALLOC_ZVAL(tmp); - INIT_PZVAL(tmp); - Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len); - Z_STRLEN_P(tmp) = buffer_len; - Z_TYPE_P(tmp) = IS_STRING; - zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL); + if (target) { + efree(target); } - efree(message); } else { - if (buffer) { - efree(buffer); - } - if (origin) { - efree(origin); - } - php_error(E_ERROR, "%s%s%s(%s): Out of memory", class_name, space, function, params); + spprintf(&message, 0, "%s: %s ", origin, buffer); + } + efree(buffer); + efree(origin); + if (docref_buf) { + efree(docref_buf); + } + php_error(type, "%s", message); + efree(message); + + if (PG(track_errors) && EG(active_symbol_table)) { + zval *tmp; + ALLOC_INIT_ZVAL(tmp); + ZVAL_STRINGL(tmp, buffer, buffer_len, 1); + zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(pval *), NULL); } } /* }}} */ @@ -1454,6 +1472,7 @@ /* */ module_initialized = 1; sapi_deactivate(TSRMLS_C); + module_startup = 0; /* we're done */ return SUCCESS; @@ -1480,6 +1499,8 @@ void php_module_shutdown(TSRMLS_D) { int module_number=0; /* for UNREGISTER_INI_ENTRIES() */ + + module_shutdown = 1; if (!module_initialized) { return;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php