summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2012-01-25 17:22:46 +0000
committerMichael Wallner <mike@php.net>2012-01-25 17:22:46 +0000
commitbfccc4ed582ca432df9de3f2aedb3533be23c8ed (patch)
tree8d580256d66788aeb7284d35630c4dd75bf5f5c8
parent0116466974123e9e8c4aa69a1d008152821ca85b (diff)
downloadphp-git-bfccc4ed582ca432df9de3f2aedb3533be23c8ed.tar.gz
fix crash with display_startup_errors=1
-rw-r--r--main/output.c35
-rw-r--r--main/php_output.h2
2 files changed, 31 insertions, 6 deletions
diff --git a/main/output.c b/main/output.c
index 1a93f3c68e..577fd7ee08 100644
--- a/main/output.c
+++ b/main/output.c
@@ -85,6 +85,18 @@ static inline void php_output_init_globals(zend_output_globals *G)
}
/* }}} */
+/* {{{ stderr writer if not PHP_OUTPUT_ACTIVATED */
+static int php_output_stderr(const char *str, size_t str_len)
+{
+ fwrite(str, 1, str_len, stderr);
+/* See http://support.microsoft.com/kb/190351 */
+#ifdef PHP_WIN32
+ fflush(stderr);
+#endif
+ return str_len;
+}
+/* }}} */
+
/* {{{ void php_output_startup(void)
* Set up module globals and initalize the conflict and reverse conflict hash tables */
PHPAPI void php_output_startup(void)
@@ -117,6 +129,7 @@ PHPAPI int php_output_activate(TSRMLS_D)
#endif
zend_stack_init(&OG(handlers));
+ OG(flags) |= PHP_OUTPUT_ACTIVATED;
return SUCCESS;
}
@@ -139,6 +152,8 @@ PHPAPI void php_output_deactivate(TSRMLS_D)
}
zend_stack_destroy(&OG(handlers));
}
+
+ OG(flags) ^= PHP_OUTPUT_ACTIVATED;
}
/* }}} */
@@ -174,9 +189,11 @@ PHPAPI void php_output_set_status(int status TSRMLS_DC)
* Get output control status */
PHPAPI int php_output_get_status(TSRMLS_D)
{
- return OG(flags)
- | (OG(active) ? PHP_OUTPUT_ACTIVE : 0)
- | (OG(running)? PHP_OUTPUT_LOCKED : 0);
+ return (
+ OG(flags)
+ | (OG(active) ? PHP_OUTPUT_ACTIVE : 0)
+ | (OG(running)? PHP_OUTPUT_LOCKED : 0)
+ ) & 0xff;
}
/* }}} */
@@ -187,7 +204,10 @@ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
if (OG(flags) & PHP_OUTPUT_DISABLED) {
return 0;
}
- return sapi_module.ub_write(str, len TSRMLS_CC);
+ if (OG(flags) & PHP_OUTPUT_ACTIVATED) {
+ return sapi_module.ub_write(str, len TSRMLS_CC);
+ }
+ return php_output_stderr(str, len);
}
/* }}} */
@@ -198,8 +218,11 @@ PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC)
if (OG(flags) & PHP_OUTPUT_DISABLED) {
return 0;
}
- php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC);
- return (int) len;
+ if (OG(flags) & PHP_OUTPUT_ACTIVATED) {
+ php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC);
+ return (int) len;
+ }
+ return php_output_stderr(str, len);
}
/* }}} */
diff --git a/main/php_output.h b/main/php_output.h
index 398b5d7b4b..e4ab0f920a 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -67,6 +67,8 @@ typedef enum _php_output_handler_status_t {
/* supplementary flags for php_output_get_status() */
#define PHP_OUTPUT_ACTIVE 0x10
#define PHP_OUTPUT_LOCKED 0x20
+/* output layer is ready to use */
+#define PHP_OUTPUT_ACTIVATED 0x100000
/* handler hooks */
typedef enum _php_output_handler_hook_t {