jani Fri, 03 Dec 2010 15:34:24 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305947
Log: - CS and "de-facto" style of returning NULL for failing parse-params, sync partially with PHP_5_3 too (reordering part :) Changed paths: U php/php-src/trunk/main/output.c U php/php-src/trunk/tests/output/ob_start_basic_006.phpt U php/php-src/trunk/tests/output/ob_start_error_001.phpt
Modified: php/php-src/trunk/main/output.c =================================================================== --- php/php-src/trunk/main/output.c 2010-12-03 15:30:54 UTC (rev 305946) +++ php/php-src/trunk/main/output.c 2010-12-03 15:34:24 UTC (rev 305947) @@ -78,7 +78,7 @@ /* }}} */ /* {{{ static void php_output_init_globals(zend_output_globals *G) - Initialize the module globals on MINIT */ + * Initialize the module globals on MINIT */ static inline void php_output_init_globals(zend_output_globals *G) { memset(G, 0, sizeof(*G)); @@ -86,7 +86,7 @@ /* }}} */ /* {{{ void php_output_startup(void) - Set up module globals and initalize the conflict and reverse conflict hash tables */ + * Set up module globals and initalize the conflict and reverse conflict hash tables */ PHPAPI void php_output_startup(void) { ZEND_INIT_MODULE_GLOBALS(output, php_output_init_globals, NULL); @@ -97,7 +97,7 @@ /* }}} */ /* {{{ void php_output_shutdown(void) - Destroy module globals and the conflict and reverse conflict hash tables */ + * Destroy module globals and the conflict and reverse conflict hash tables */ PHPAPI void php_output_shutdown(void) { zend_hash_destroy(&php_output_handler_aliases); @@ -107,7 +107,7 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_activate(TSRMLS_D) - Reset output globals and setup the output handler stack */ + * Reset output globals and setup the output handler stack */ PHPAPI int php_output_activate(TSRMLS_D) { #ifdef ZTS @@ -115,22 +115,22 @@ #else memset(&output_globals, 0, sizeof(zend_output_globals)); #endif - + zend_stack_init(&OG(handlers)); - + return SUCCESS; } /* }}} */ /* {{{ void php_output_deactivate(TSRMLS_D) - Destroy the output handler stack */ + * Destroy the output handler stack */ PHPAPI void php_output_deactivate(TSRMLS_D) { php_output_handler **handler = NULL; - + OG(active) = NULL; OG(running) = NULL; - + /* release all output handlers */ if (OG(handlers).elements) { while (SUCCESS == zend_stack_top(&OG(handlers), (void *) &handler)) { @@ -163,7 +163,7 @@ /* }}} */ /* {{{ void php_output_set_status(int status TSRMLS_DC) - Used by SAPIs to disable output */ + * Used by SAPIs to disable output */ PHPAPI void php_output_set_status(int status TSRMLS_DC) { OG(flags) = status & 0xf; @@ -171,7 +171,7 @@ /* }}} */ /* {{{ int php_output_get_status(TSRMLS_C) - Get output control status */ + * Get output control status */ PHPAPI int php_output_get_status(TSRMLS_D) { return OG(flags) @@ -181,7 +181,7 @@ /* }}} */ /* {{{ int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) - Unbuffered write */ + * Unbuffered write */ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC) { if (OG(flags) & PHP_OUTPUT_DISABLED) { @@ -192,7 +192,7 @@ /* }}} */ /* {{{ int php_output_write(const char *str, size_t len TSRMLS_DC) - Buffered write */ + * Buffered write */ PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC) { if (OG(flags) & PHP_OUTPUT_DISABLED) { @@ -204,11 +204,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_flush(TSRMLS_D) - Flush the most recent output handlers buffer */ + * Flush the most recent output handlers buffer */ PHPAPI int php_output_flush(TSRMLS_D) { php_output_context context; - + if (OG(active) && (OG(active)->flags & PHP_OUTPUT_HANDLER_FLUSHABLE)) { php_output_context_init(&context, PHP_OUTPUT_HANDLER_FLUSH TSRMLS_CC); php_output_handler_op(OG(active), &context); @@ -225,7 +225,7 @@ /* }}} */ /* {{{ void php_output_flush_all(TSRMLS_C) - Flush all output buffers subsequently */ + * Flush all output buffers subsequently */ PHPAPI void php_output_flush_all(TSRMLS_D) { if (OG(active)) { @@ -235,11 +235,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_clean(TSRMLS_D) - Cleans the most recent output handlers buffer if the handler is cleanable */ + * Cleans the most recent output handlers buffer if the handler is cleanable */ PHPAPI int php_output_clean(TSRMLS_D) { php_output_context context; - + if (OG(active) && (OG(active)->flags & PHP_OUTPUT_HANDLER_CLEANABLE)) { OG(active)->buffer.used = 0; php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN TSRMLS_CC); @@ -252,11 +252,11 @@ /* }}} */ /* {{{ void php_output_clean_all(TSRMLS_D) - Cleans all output handler buffers, without regard whether the handler is cleanable */ + * Cleans all output handler buffers, without regard whether the handler is cleanable */ PHPAPI void php_output_clean_all(TSRMLS_D) { php_output_context context; - + if (OG(active)) { php_output_context_init(&context, PHP_OUTPUT_HANDLER_CLEAN TSRMLS_CC); zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_clean, &context); @@ -264,7 +264,7 @@ } /* {{{ SUCCESS|FAILURE php_output_end(TSRMLS_D) - Finalizes the most recent output handler at pops it off the stack if the handler is removable */ + * Finalizes the most recent output handler at pops it off the stack if the handler is removable */ PHPAPI int php_output_end(TSRMLS_D) { if (php_output_stack_pop(PHP_OUTPUT_POP_TRY TSRMLS_CC)) { @@ -275,7 +275,7 @@ /* }}} */ /* {{{ void php_output_end_all(TSRMLS_D) - Finalizes all output handlers and ends output buffering without regard whether a handler is removable */ + * Finalizes all output handlers and ends output buffering without regard whether a handler is removable */ PHPAPI void php_output_end_all(TSRMLS_D) { while (OG(active) && php_output_stack_pop(PHP_OUTPUT_POP_FORCE TSRMLS_CC)); @@ -283,7 +283,7 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_discard(TSRMLS_D) - Discards the most recent output handlers buffer and pops it off the stack if the handler is removable */ + * Discards the most recent output handlers buffer and pops it off the stack if the handler is removable */ PHPAPI int php_output_discard(TSRMLS_D) { if (php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_TRY TSRMLS_CC)) { @@ -294,7 +294,7 @@ /* }}} */ /* {{{ void php_output_discard_all(TSRMLS_D) - Discard all output handlers and buffers without regard whether a handler is removable */ + * Discard all output handlers and buffers without regard whether a handler is removable */ PHPAPI void php_output_discard_all(TSRMLS_D) { while (OG(active)) { @@ -304,7 +304,7 @@ /* }}} */ /* {{{ int php_output_get_level(TSRMLS_D) - Get output buffering level, ie. how many output handlers the stack contains */ + * Get output buffering level, ie. how many output handlers the stack contains */ PHPAPI int php_output_get_level(TSRMLS_D) { return OG(active) ? zend_stack_count(&OG(handlers)) : 0; @@ -312,7 +312,7 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_get_contents(zval *z TSRMLS_DC) - Get the contents of the active output handlers buffer */ + * Get the contents of the active output handlers buffer */ PHPAPI int php_output_get_contents(zval *p TSRMLS_DC) { if (OG(active)) { @@ -325,7 +325,7 @@ } /* {{{ SUCCESS|FAILURE php_output_get_length(zval *z TSRMLS_DC) - Get the length of the active output handlers buffer */ + * Get the length of the active output handlers buffer */ PHPAPI int php_output_get_length(zval *p TSRMLS_DC) { if (OG(active)) { @@ -339,11 +339,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_start_default(TSRMLS_D) - Start a "default output handler" */ + * Start a "default output handler" */ PHPAPI int php_output_start_default(TSRMLS_D) { php_output_handler *handler; - + handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) { return SUCCESS; @@ -354,11 +354,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_start_devnull(TSRMLS_D) - Start a "null output handler" */ + * Start a "null output handler" */ PHPAPI int php_output_start_devnull(TSRMLS_D) { php_output_handler *handler; - + handler = php_output_handler_create_internal(ZEND_STRL(php_output_devnull_handler_name), php_output_handler_devnull_func, PHP_OUTPUT_HANDLER_DEFAULT_SIZE, 0 TSRMLS_CC); if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) { return SUCCESS; @@ -369,11 +369,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_start_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC) - Start a user level output handler */ + * Start a user level output handler */ PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; - + if (output_handler) { handler = php_output_handler_create_user(output_handler, chunk_size, flags TSRMLS_CC); } else { @@ -388,11 +388,11 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_start_internal(zval *name, php_output_handler_func_t handler, size_t chunk_size, int flags TSRMLS_DC) - Start an internal output handler that does not have to maintain a non-global state */ + * Start an internal output handler that does not have to maintain a non-global state */ PHPAPI int php_output_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; - + handler = php_output_handler_create_internal(name, name_len, php_output_handler_compat_func, chunk_size, flags TSRMLS_CC); php_output_handler_set_context(handler, output_handler, NULL TSRMLS_CC); if (SUCCESS == php_output_handler_start(handler TSRMLS_CC)) { @@ -404,14 +404,14 @@ /* }}} */ /* {{{ php_output_handler *php_output_handler_create_user(zval *handler, size_t chunk_size, int flags TSRMLS_DC) - Create a user level output handler */ + * Create a user level output handler */ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, size_t chunk_size, int flags TSRMLS_DC) { char *handler_name = NULL, *error = NULL; php_output_handler *handler = NULL; php_output_handler_alias_ctor_t *alias = NULL; php_output_handler_user_func_t *user = NULL; - + switch (Z_TYPE_P(output_handler)) { case IS_NULL: handler = php_output_handler_create_internal(ZEND_STRL(php_output_default_handler_name), php_output_handler_default_func, chunk_size, flags TSRMLS_CC); @@ -439,26 +439,26 @@ efree(handler_name); } } - + return handler; } /* }}} */ /* {{{ php_output_handler *php_output_handler_create_internal(zval *name, php_output_handler_context_func_t handler, size_t chunk_size, int flags TSRMLS_DC) - Create an internal output handler that can maintain a non-global state */ + * Create an internal output handler that can maintain a non-global state */ PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; handler = php_output_handler_init(name, name_len, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC); handler->func.internal = output_handler; - + return handler; } /* }}} */ /* {{{ void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC) - Set the context/state of an output handler. Calls the dtor of the previous context if there is one */ + * Set the context/state of an output handler. Calls the dtor of the previous context if there is one */ PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC) { if (handler->dtor && handler->opaq) { @@ -470,13 +470,13 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_start(php_output_handler *handler TSRMLS_DC) - Starts the set up output handler and pushes it on top of the stack. Checks for any conflicts regarding the output handler to start */ + * Starts the set up output handler and pushes it on top of the stack. Checks for any conflicts regarding the output handler to start */ PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC) { HashPosition pos; HashTable *rconflicts; php_output_handler_conflict_check_t *conflict; - + if (php_output_lock_error(PHP_OUTPUT_HANDLER_START TSRMLS_CC) || !handler) { return FAILURE; } @@ -486,9 +486,10 @@ } } if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, handler->name, handler->name_len+1, (void *) &rconflicts)) { - for ( zend_hash_internal_pointer_reset_ex(rconflicts, &pos); - zend_hash_get_current_data_ex(rconflicts, (void *) &conflict, &pos) == SUCCESS; - zend_hash_move_forward_ex(rconflicts, &pos)) { + for (zend_hash_internal_pointer_reset_ex(rconflicts, &pos); + zend_hash_get_current_data_ex(rconflicts, (void *) &conflict, &pos) == SUCCESS; + zend_hash_move_forward_ex(rconflicts, &pos) + ) { if (SUCCESS != (*conflict)(handler->name, handler->name_len TSRMLS_CC)) { return FAILURE; } @@ -504,28 +505,28 @@ /* }}} */ /* {{{ int php_output_handler_started(zval *name TSRMLS_DC) - Check whether a certain output handler is in use */ + * Check whether a certain output handler is in use */ PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_DC) { php_output_handler **handlers; int i, count = php_output_get_level(TSRMLS_C); - + if (count) { handlers = *(php_output_handler ***) zend_stack_base(&OG(handlers)); - + for (i = 0; i < count; ++i) { if (name_len == handlers[i]->name_len && !memcmp(handlers[i]->name, name, name_len)) { return 1; } } } - + return 0; } /* }}} */ /* {{{ int php_output_handler_conflict(zval *handler_new, zval *handler_old TSRMLS_DC) - Check whether a certain handler is in use and issue a warning that the new handler would conflict with the already used one */ + * Check whether a certain handler is in use and issue a warning that the new handler would conflict with the already used one */ PHPAPI int php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len TSRMLS_DC) { if (php_output_handler_started(handler_set, handler_set_len TSRMLS_CC)) { @@ -541,7 +542,7 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_conflict_register(zval *name, php_output_handler_conflict_check_t check_func TSRMLS_DC) - Register a conflict checking function on MINIT */ + * Register a conflict checking function on MINIT */ PHPAPI int php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC) { if (!EG(current_module)) { @@ -553,16 +554,16 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_reverse_conflict_register(zval *name, php_output_handler_conflict_check_t check_func TSRMLS_DC) - Register a reverse conflict checking function on MINIT */ + * Register a reverse conflict checking function on MINIT */ PHPAPI int php_output_handler_reverse_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func TSRMLS_DC) { HashTable rev, *rev_ptr = NULL; - + if (!EG(current_module)) { zend_error(E_ERROR, "Cannot register a reverse output handler conflict outside of MINIT"); return FAILURE; } - + if (SUCCESS == zend_hash_find(&php_output_handler_reverse_conflicts, name, name_len+1, (void *) &rev_ptr)) { return zend_hash_next_index_insert(rev_ptr, &check_func, sizeof(php_output_handler_conflict_check_t *), NULL); } else { @@ -581,18 +582,18 @@ /* }}} */ /* {{{ php_output_handler_alias_ctor_t php_output_handler_alias(zval *name TSRMLS_DC) - Get an internal output handler for a user handler if it exists */ + * Get an internal output handler for a user handler if it exists */ PHPAPI php_output_handler_alias_ctor_t *php_output_handler_alias(const char *name, size_t name_len TSRMLS_DC) { php_output_handler_alias_ctor_t *func = NULL; - + zend_hash_find(&php_output_handler_aliases, name, name_len+1, (void *) &func); return func; } /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_alias_register(zval *name, php_output_handler_alias_ctor_t func TSRMLS_DC) - Registers an internal output handler as alias for a user handler */ + * Registers an internal output handler as alias for a user handler */ PHPAPI int php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func TSRMLS_DC) { if (!EG(current_module)) { @@ -604,7 +605,7 @@ /* }}} */ /* {{{ SUCCESS|FAILURE php_output_handler_hook(php_output_handler_hook_t type, void *arg TSMRLS_DC) - Output handler hook for output handler functions to check/modify the current handlers abilities */ + * Output handler hook for output handler functions to check/modify the current handlers abilities */ PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC) { if (OG(running)) { @@ -624,7 +625,7 @@ OG(running)->flags |= PHP_OUTPUT_HANDLER_DISABLED; return SUCCESS; default: - break; + break; } } return FAILURE; @@ -632,7 +633,7 @@ /* }}} */ /* {{{ void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC) - Destroy an output handler */ + * Destroy an output handler */ PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC) { STR_FREE(handler->name); @@ -649,7 +650,7 @@ /* }}} */ /* {{{ void php_output_handler_free(php_output_handler **handler TSMRLS_DC) - Destroy and free an output handler */ + * Destroy and free an output handler */ PHPAPI void php_output_handler_free(php_output_handler **h TSRMLS_DC) { if (*h) { @@ -661,7 +662,7 @@ /* }}} */ /* void php_output_set_implicit_flush(int enabled TSRMLS_DC) - Enable or disable implicit flush */ + * Enable or disable implicit flush */ PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC) { if (flush) { @@ -673,7 +674,7 @@ /* }}} */ /* {{{ char *php_output_get_start_filename(TSRMLS_D) - Get the file name where output has started */ + * Get the file name where output has started */ PHPAPI char *php_output_get_start_filename(TSRMLS_D) { return OG(output_start_filename); @@ -681,7 +682,7 @@ /* }}} */ /* {{{ int php_output_get_start_lineno(TSRMLS_D) - Get the line number where output has started */ + * Get the line number where output has started */ PHPAPI int php_output_get_start_lineno(TSRMLS_D) { return OG(output_start_lineno); @@ -689,7 +690,7 @@ /* }}} */ /* {{{ static int php_output_lock_error(int op TSRMLS_DC) - Checks whether an unallowed operation is attempted from within the output handler and issues a fatal error */ + * Checks whether an unallowed operation is attempted from within the output handler and issues a fatal error */ static inline int php_output_lock_error(int op TSRMLS_DC) { /* if there's no ob active, ob has been stopped */ @@ -704,23 +705,23 @@ /* }}} */ /* {{{ static php_output_context *php_output_context_init(php_output_context *context, int op TSRMLS_DC) - Initialize a new output context */ + * Initialize a new output context */ static inline php_output_context *php_output_context_init(php_output_context *context, int op TSRMLS_DC) { if (!context) { context = emalloc(sizeof(php_output_context)); } - + memset(context, 0, sizeof(php_output_context)); TSRMLS_SET_CTX(context->tsrm_ls); context->op = op; - + return context; } /* }}} */ /* {{{ static void php_output_context_reset(php_output_context *context) - Reset an output context */ + * Reset an output context */ static inline void php_output_context_reset(php_output_context *context) { int op = context->op; @@ -730,8 +731,8 @@ } /* }}} */ -/* {{{ static void php_output_context_feed(php_output_context *context, char *, size_t, size_t) - Feed output contexts input buffer */ +/* {{{ static void php_output_context_feed(php_output_context *context, char *, size_t, size_t) + * Feed output contexts input buffer */ static inline void php_output_context_feed(php_output_context *context, char *data, size_t size, size_t used, zend_bool free) { if (context->in.free && context->in.data) { @@ -745,7 +746,7 @@ /* }}} */ /* {{{ static void php_output_context_swap(php_output_context *context) - Swap output contexts buffers */ + * Swap output contexts buffers */ static inline void php_output_context_swap(php_output_context *context) { if (context->in.free && context->in.data) { @@ -763,7 +764,7 @@ /* }}} */ /* {{{ static void php_output_context_pass(php_output_context *context) - Pass input to output buffer */ + * Pass input to output buffer */ static inline void php_output_context_pass(php_output_context *context) { context->out.data = context->in.data; @@ -778,7 +779,7 @@ /* }}} */ /* {{{ static void php_output_context_dtor(php_output_context *context) - Destroy the contents of an output context */ + * Destroy the contents of an output context */ static inline void php_output_context_dtor(php_output_context *context) { if (context->in.free && context->in.data) { @@ -793,11 +794,11 @@ /* }}} */ /* {{{ static php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags TSRMLS_DC) - Allocates and initializes a php_output_handler structure */ + * Allocates and initializes a php_output_handler structure */ static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; - + handler = ecalloc(1, sizeof(php_output_handler)); handler->name = estrndup(name, name_len); handler->name_len = name_len; @@ -805,13 +806,13 @@ handler->flags = flags; handler->buffer.size = PHP_OUTPUT_HANDLER_INITBUF_SIZE(chunk_size); handler->buffer.data = emalloc(handler->buffer.size); - + return handler; } /* }}} */ /* {{{ static int php_output_handler_appen(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC) - Appends input to the output handlers buffer and indicates whether the buffer does not have to be processed by the output handler */ + * Appends input to the output handlers buffer and indicates whether the buffer does not have to be processed by the output handler */ static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC) { if (buf->used) { @@ -821,13 +822,13 @@ size_t grow_int = PHP_OUTPUT_HANDLER_INITBUF_SIZE(handler->size); size_t grow_buf = PHP_OUTPUT_HANDLER_INITBUF_SIZE(buf->used - (handler->buffer.size - handler->buffer.used)); size_t grow_max = MAX(grow_int, grow_buf); - + handler->buffer.data = erealloc(handler->buffer.data, handler->buffer.size + grow_max); handler->buffer.size += grow_max; } memcpy(handler->buffer.data + handler->buffer.used, buf->data, buf->used); handler->buffer.used += buf->used; - + /* chunked buffering */ if (handler->size && (handler->buffer.used >= handler->size)) { /* store away errors and/or any intermediate output */ @@ -839,13 +840,13 @@ /* }}} */ /* {{{ static php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context) - Output handler operation dispatcher, applying context op to the php_output_handler handler */ + * Output handler operation dispatcher, applying context op to the php_output_handler handler */ static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context) { php_output_handler_status_t status; int original_op = context->op; PHP_OUTPUT_TSRMLS(context); - + #if PHP_OUTPUT_DEBUG fprintf(stderr, ">>> op(%d, " "handler=%p, " @@ -867,12 +868,12 @@ context->in.used ); #endif - + if (php_output_lock_error(context->op TSRMLS_CC)) { /* fatal error */ return PHP_OUTPUT_HANDLER_FAILURE; } - + /* storable? */ if (php_output_handler_append(handler, &context->in TSRMLS_CC) && !context->op) { status = PHP_OUTPUT_HANDLER_NO_DATA; @@ -881,17 +882,17 @@ if (!(handler->flags & PHP_OUTPUT_HANDLER_STARTED)) { context->op |= PHP_OUTPUT_HANDLER_START; } - + OG(running) = handler; if (handler->flags & PHP_OUTPUT_HANDLER_USER) { zval *retval = NULL, *ob_data, *ob_mode; - + MAKE_STD_ZVAL(ob_data); ZVAL_STRINGL(ob_data, handler->buffer.data, handler->buffer.used, 1); MAKE_STD_ZVAL(ob_mode); ZVAL_LONG(ob_mode, (long) context->op); zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 2, &ob_data, &ob_mode); - + #define PHP_OUTPUT_USER_SUCCESS(retval) (retval && !(Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)==0)) if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) { /* user handler may have returned TRUE */ @@ -909,18 +910,18 @@ /* call failed, pass internal buffer along */ status = PHP_OUTPUT_HANDLER_FAILURE; } - + zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 0); zval_ptr_dtor(&ob_data); zval_ptr_dtor(&ob_mode); if (retval) { zval_ptr_dtor(&retval); } - + } else { php_output_context_feed(context, handler->buffer.data, handler->buffer.size, handler->buffer.used, 0); - + if (SUCCESS == handler->func.internal(&handler->opaq, context)) { if (context->out.used) { status = PHP_OUTPUT_HANDLER_SUCCESS; @@ -934,7 +935,7 @@ handler->flags |= PHP_OUTPUT_HANDLER_STARTED; OG(running) = NULL; } - + switch (status) { case PHP_OUTPUT_HANDLER_FAILURE: /* disable this handler */ @@ -960,7 +961,7 @@ php_output_context_reset(context); break; } - + context->op = original_op; return status; } @@ -968,19 +969,19 @@ /* {{{ static void php_output_op(int op, const char *str, size_t len TSRMLS_DC) - Output op dispatcher, passes input and output handlers output through the output handler stack until it gets written to the SAPI */ + * Output op dispatcher, passes input and output handlers output through the output handler stack until it gets written to the SAPI */ static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC) { php_output_context context; php_output_handler **active; int obh_cnt; - + if (php_output_lock_error(op TSRMLS_CC)) { return; } - + php_output_context_init(&context, op TSRMLS_CC); - + /* * broken up for better performance: * - apply op to the one active handler; note that OG(active) might be popped off the stack on a flush @@ -989,7 +990,7 @@ if (OG(active) && (obh_cnt = zend_stack_count(&OG(handlers)))) { context.in.data = (char *) str; context.in.used = len; - + if (obh_cnt > 1) { zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_TOPDOWN, php_output_stack_apply_op, &context); } else if ((SUCCESS == zend_stack_top(&OG(handlers), (void *) &active)) && (!((*active)->flags & PHP_OUTPUT_HANDLER_DISABLED))) { @@ -1001,7 +1002,7 @@ context.out.data = (char *) str; context.out.used = len; } - + if (context.out.data && context.out.used) { #if PHP_OUTPUT_DEBUG fprintf(stderr, "::: sapi_write('%s', %zu)\n", context.out.data, context.out.used); @@ -1029,20 +1030,20 @@ /* }}} */ /* {{{ static int php_output_stack_apply_op(void *h, void *c) - Operation callback for the stack apply function */ + * Operation callback for the stack apply function */ static int php_output_stack_apply_op(void *h, void *c) { int was_disabled; php_output_handler_status_t status; php_output_handler *handler = *(php_output_handler **) h; php_output_context *context = (php_output_context *) c; - + if ((was_disabled = (handler->flags & PHP_OUTPUT_HANDLER_DISABLED))) { status = PHP_OUTPUT_HANDLER_FAILURE; } else { status = php_output_handler_op(handler, context); } - + /* * handler ate all => break * handler returned data or failed resp. is disabled => continue @@ -1050,14 +1051,14 @@ switch (status) { case PHP_OUTPUT_HANDLER_NO_DATA: return 1; - + case PHP_OUTPUT_HANDLER_SUCCESS: /* swap contexts buffers, unless this is the last handler in the stack */ if (handler->level) { php_output_context_swap(context); } return 0; - + case PHP_OUTPUT_HANDLER_FAILURE: default: if (was_disabled) { @@ -1077,12 +1078,12 @@ /* }}} */ /* {{{ static int php_output_stack_apply_clean(void *h, void *c) - Clean callback for the stack apply function */ + * Clean callback for the stack apply function */ static int php_output_stack_apply_clean(void *h, void *c) { php_output_handler *handler = *(php_output_handler **) h; php_output_context *context = (php_output_context *) c; - + handler->buffer.used = 0; php_output_handler_op(handler, context); php_output_context_reset(context); @@ -1091,38 +1092,38 @@ /* }}} */ /* {{{ static int php_output_stack_apply_list(void *h, void *z) - List callback for the stack apply function */ + * List callback for the stack apply function */ static int php_output_stack_apply_list(void *h, void *z) { php_output_handler *handler = *(php_output_handler **) h; zval *array = (zval *) z; - + add_next_index_stringl(array, handler->name, handler->name_len, 1); return 0; } /* }}} */ /* {{{ static int php_output_stack_apply_status(void *h, void *z) - Status callback for the stack apply function */ + * Status callback for the stack apply function */ static int php_output_stack_apply_status(void *h, void *z) { php_output_handler *handler = *(php_output_handler **) h; zval *array = (zval *) z; - + add_next_index_zval(array, php_output_handler_status(handler, NULL)); - + return 0; } /* {{{ static zval *php_output_handler_status(php_output_handler *handler, zval *entry) - Returns an array with the status of the output handler */ + * Returns an array with the status of the output handler */ static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry) { if (!entry) { MAKE_STD_ZVAL(entry); array_init(entry); } - + add_assoc_stringl(entry, "name", handler->name, handler->name_len, 1); add_assoc_long(entry, "type", (long) (handler->flags & 0xf)); add_assoc_long(entry, "flags", (long) handler->flags); @@ -1130,18 +1131,18 @@ add_assoc_long(entry, "chunk_size", (long) handler->size); add_assoc_long(entry, "buffer_size", (long) handler->buffer.size); add_assoc_long(entry, "buffer_used", (long) handler->buffer.used); - + return entry; } /* }}} */ /* {{{ static int php_output_stack_pop(int flags TSRMLS_DC) - Pops an output handler off the stack */ + * Pops an output handler off the stack */ static inline int php_output_stack_pop(int flags TSRMLS_DC) { php_output_context context; php_output_handler **current, *orphan = OG(active); - + if (!orphan) { if (!(flags & PHP_OUTPUT_POP_SILENT)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer. No buffer to %s", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send"); @@ -1154,7 +1155,7 @@ return 0; } else { php_output_context_init(&context, PHP_OUTPUT_HANDLER_FINAL TSRMLS_CC); - + /* don't run the output handler if it's disabled */ if (!(orphan->flags & PHP_OUTPUT_HANDLER_DISABLED)) { /* didn't it start yet? */ @@ -1168,7 +1169,7 @@ } php_output_handler_op(orphan, &context); } - + /* pop it off the stack */ zend_stack_del_top(&OG(handlers)); if (SUCCESS == zend_stack_top(&OG(handlers), (void *) ¤t)) { @@ -1176,31 +1177,31 @@ } else { OG(active) = NULL; } - + /* pass output along */ if (context.out.data && context.out.used && !(flags & PHP_OUTPUT_POP_DISCARD)) { php_output_write(context.out.data, context.out.used TSRMLS_CC); } - + /* destroy the handler (after write!) */ php_output_handler_free(&orphan TSRMLS_CC); php_output_context_dtor(&context); - + return 1; } } /* }}} */ /* {{{ static SUCCESS|FAILURE php_output_handler_compat_func(void *ctx, php_output_context *) - php_output_handler_context_func_t for php_output_handler_func_t output handlers */ + * php_output_handler_context_func_t for php_output_handler_func_t output handlers */ static int php_output_handler_compat_func(void **handler_context, php_output_context *output_context) { php_output_handler_func_t func = *(php_output_handler_func_t *) handler_context; PHP_OUTPUT_TSRMLS(output_context); - + if (func) { uint safe_out_len; - + func(output_context->in.data, output_context->in.used, &output_context->out.data, &safe_out_len, output_context->op TSRMLS_CC); output_context->out.used = safe_out_len; output_context->out.free = 1; @@ -1211,7 +1212,7 @@ /* }}} */ /* {{{ static SUCCESS|FAILURE php_output_handler_default_func(void *ctx, php_output_context *) - Default output handler */ + * Default output handler */ static int php_output_handler_default_func(void **handler_context, php_output_context *output_context) { php_output_context_pass(output_context); @@ -1220,7 +1221,7 @@ /* }}} */ /* {{{ static SUCCESS|FAILURE php_output_handler_devnull_func(void *ctx, php_output_context *) - Null output handler */ + * Null output handler */ static int php_output_handler_devnull_func(void **handler_context, php_output_context *output_context) { return SUCCESS; @@ -1238,15 +1239,16 @@ zval *output_handler = NULL; long chunk_size = 0; long flags = PHP_OUTPUT_HANDLER_STDFLAGS; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/ll", &output_handler, &chunk_size, &flags)) { - RETURN_FALSE; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/ll", &output_handler, &chunk_size, &flags) == FAILURE) { + return; } - if (chunk_size < 0) + if (chunk_size < 0) { chunk_size = 0; + } - if (SUCCESS != php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC)) { + if (php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC) == FAILURE) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to create buffer"); RETURN_FALSE; } @@ -1261,11 +1263,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(active)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush"); RETURN_FALSE; } + if (SUCCESS != php_output_flush(TSRMLS_C)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name, OG(active)->level); RETURN_FALSE; @@ -1274,7 +1277,6 @@ } /* }}} */ - /* {{{ proto bool ob_clean(void) Clean (delete) the current output buffer */ PHP_FUNCTION(ob_clean) @@ -1282,11 +1284,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(active)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); RETURN_FALSE; } + if (SUCCESS != php_output_clean(TSRMLS_C)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); RETURN_FALSE; @@ -1302,11 +1305,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(active)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush"); RETURN_FALSE; } + RETURN_BOOL(SUCCESS == php_output_end(TSRMLS_C)); } /* }}} */ @@ -1318,11 +1322,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(active)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); RETURN_FALSE; } + RETURN_BOOL(SUCCESS == php_output_discard(TSRMLS_C)); } /* }}} */ @@ -1334,11 +1339,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - - if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) { + + if (php_output_get_contents(return_value TSRMLS_CC) == FAILURE) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush"); RETURN_FALSE; } + if (SUCCESS != php_output_end(TSRMLS_C)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); } @@ -1352,11 +1358,12 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - - if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) { + + if (php_output_get_contents(return_value TSRMLS_CC) == FAILURE) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); RETURN_FALSE; } + if (SUCCESS != php_output_discard(TSRMLS_C)) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); } @@ -1370,7 +1377,8 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - if (SUCCESS != php_output_get_contents(return_value TSRMLS_CC)) { + + if (php_output_get_contents(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } } @@ -1383,6 +1391,7 @@ if (zend_parse_parameters_none() == FAILURE) { return; } + RETURN_LONG(php_output_get_level(TSRMLS_C)); } /* }}} */ @@ -1394,15 +1403,15 @@ if (zend_parse_parameters_none() == FAILURE) { return; } - if (SUCCESS != php_output_get_length(return_value TSRMLS_CC)) { + + if (php_output_get_length(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } } /* }}} */ /* {{{ proto false|array ob_list_handlers() - * List all output_buffers in an array - */ + List all output_buffers in an array */ PHP_FUNCTION(ob_list_handlers) { if (zend_parse_parameters_none() == FAILURE) { @@ -1414,7 +1423,7 @@ if (!OG(active)) { return; } - + zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_BOTTOMUP, php_output_stack_apply_list, return_value); } /* }}} */ @@ -1424,15 +1433,17 @@ PHP_FUNCTION(ob_get_status) { zend_bool full_status = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status)) { - RETURN_FALSE; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status) == FAILURE) { + return; } + if (!OG(active)) { RETURN_FALSE; } - + array_init(return_value); + if (full_status) { zend_stack_apply_with_argument(&OG(handlers), ZEND_STACK_APPLY_BOTTOMUP, php_output_stack_apply_status, return_value); } else { @@ -1446,10 +1457,12 @@ PHP_FUNCTION(ob_implicit_flush) { long flag = 1; - - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag)) { - php_output_set_implicit_flush(flag TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) { + return; } + + php_output_set_implicit_flush(flag TSRMLS_CC); } /* }}} */ @@ -1473,7 +1486,7 @@ int name_len, value_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) { - RETURN_FALSE; + return; } if (php_url_scanner_add_var(name, name_len, value, value_len, 1 TSRMLS_CC) == SUCCESS) { Modified: php/php-src/trunk/tests/output/ob_start_basic_006.phpt =================================================================== --- php/php-src/trunk/tests/output/ob_start_basic_006.phpt 2010-12-03 15:30:54 UTC (rev 305946) +++ php/php-src/trunk/tests/output/ob_start_basic_006.phpt 2010-12-03 15:34:24 UTC (rev 305947) @@ -74,30 +74,40 @@ --EXPECTF-- ---> Test arrays: +Warning: ob_start(): array must have exactly two members in %s on line 44 + Notice: ob_start(): failed to create buffer in %s on line 44 bool(false) Array ( ) +Warning: ob_start(): class 'f' not found in %s on line 47 + Notice: ob_start(): failed to create buffer in %s on line 47 bool(false) Array ( ) +Warning: ob_start(): array must have exactly two members in %s on line 50 + Notice: ob_start(): failed to create buffer in %s on line 50 bool(false) Array ( ) +Warning: ob_start(): array must have exactly two members in %s on line 53 + Notice: ob_start(): failed to create buffer in %s on line 53 bool(false) Array ( ) +Warning: ob_start(): array must have exactly two members in %s on line 56 + Notice: ob_start(): failed to create buffer in %s on line 56 bool(false) Array @@ -116,6 +126,8 @@ ) +Warning: ob_start(): array must have exactly two members in %s on line 68 + Notice: ob_start(): failed to create buffer in %s on line 68 bool(false) Array Modified: php/php-src/trunk/tests/output/ob_start_error_001.phpt =================================================================== --- php/php-src/trunk/tests/output/ob_start_error_001.phpt 2010-12-03 15:30:54 UTC (rev 305946) +++ php/php-src/trunk/tests/output/ob_start_error_001.phpt 2010-12-03 15:34:24 UTC (rev 305947) @@ -33,7 +33,7 @@ - Too many arguments Warning: ob_start() expects at most 3 parameters, 4 given in %s on line 17 -bool(false) +NULL - Arg 1 wrong type @@ -45,9 +45,9 @@ - Arg 2 wrong type Warning: ob_start() expects parameter 2 to be long, string given in %s on line 23 -bool(false) +NULL - Arg 3 wrong type Warning: ob_start() expects parameter 3 to be long, string given in %s on line 26 -bool(false) +NULL
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php