zeev Tue Mar 6 07:54:49 2001 EDT Modified files: /php4/ext/standard output.c php_output.h Log: Initial work on internal output handlers - should be much quicker Index: php4/ext/standard/output.c diff -u php4/ext/standard/output.c:1.43 php4/ext/standard/output.c:1.44 --- php4/ext/standard/output.c:1.43 Sun Mar 4 07:46:13 2001 +++ php4/ext/standard/output.c Tue Mar 6 07:54:49 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: output.c,v 1.43 2001/03/04 15:46:13 zeev Exp $ */ +/* $Id: output.c,v 1.44 2001/03/06 15:54:49 zeev Exp $ */ #include "php.h" #include "ext/standard/head.h" @@ -123,14 +123,29 @@ int final_buffer_length=0; zval *alternate_buffer=NULL; char *to_be_destroyed_buffer; + char *internal_output_handler_buffer; + int status; SLS_FETCH(); OLS_FETCH(); if (OG(nesting_level)==0) { return; } + status = 0; + if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) { + /* our first call */ + status |= PHP_OUTPUT_HANDLER_START; + } + if (just_flush) { + status |= PHP_OUTPUT_HANDLER_CONT; + } else { + status |= PHP_OUTPUT_HANDLER_END; + } - if (OG(active_ob_buffer).output_handler) { + if (OG(active_ob_buffer).internal_output_handler) { + internal_output_handler_buffer = +OG(active_ob_buffer).internal_output_handler_buffer; + +OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, +OG(active_ob_buffer).text_length, &internal_output_handler_buffer, status); + } else if (OG(active_ob_buffer).output_handler) { zval **params[2]; zval *orig_buffer; zval *z_status; @@ -144,16 +159,7 @@ ALLOC_INIT_ZVAL(z_status); Z_TYPE_P(z_status) = IS_LONG; - Z_LVAL_P(z_status) = 0; - if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) { - /* our first call */ - Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_START; - } - if (just_flush) { - Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_CONT; - } else { - Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_END; - } + Z_LVAL_P(z_status) = status; params[0] = &orig_buffer; params[1] = &z_status; @@ -218,6 +224,10 @@ OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START; OG(php_body_write) = php_b_body_write; } + if (OG(active_ob_buffer).internal_output_handler + && (internal_output_handler_buffer != +OG(active_ob_buffer).internal_output_handler_buffer)) { + efree(internal_output_handler_buffer); + } } @@ -249,6 +259,20 @@ } +PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t +internal_output_handler, uint buffer_size) +{ + OLS_FETCH(); + + if (OG(nesting_level)==0) { + return; + } + + OG(active_ob_buffer).internal_output_handler = internal_output_handler; + OG(active_ob_buffer).internal_output_handler_buffer = (char *) +emalloc(buffer_size); + OG(active_ob_buffer).internal_output_handler_buffer_size = buffer_size; +} + + /* * Output buffering - implementation */ @@ -285,6 +309,7 @@ OG(active_ob_buffer).output_handler = output_handler; OG(active_ob_buffer).chunk_size = chunk_size; OG(active_ob_buffer).status = 0; + OG(active_ob_buffer).internal_output_handler = NULL; } Index: php4/ext/standard/php_output.h diff -u php4/ext/standard/php_output.h:1.20 php4/ext/standard/php_output.h:1.21 --- php4/ext/standard/php_output.h:1.20 Sat Mar 3 17:45:19 2001 +++ php4/ext/standard/php_output.h Tue Mar 6 07:54:49 2001 @@ -16,13 +16,15 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_output.h,v 1.20 2001/03/04 01:45:19 zeev Exp $ */ +/* $Id: php_output.h,v 1.21 2001/03/06 15:54:49 zeev Exp $ */ #ifndef PHP_OUTPUT_H #define PHP_OUTPUT_H #include "php.h" +typedef void (*php_output_handler_func_t)(char *output, uint output_len, char +**handled_output, int status); + PHPAPI void php_output_startup(void); void php_output_register_constants(void); PHPAPI int php_body_write(const char *str, uint str_length); @@ -36,6 +38,7 @@ PHPAPI void php_end_implicit_flush(void); PHPAPI char *php_get_output_start_filename(void); PHPAPI int php_get_output_start_lineno(void); +PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t +internal_output_handler, uint buffer_size); PHP_FUNCTION(ob_start); PHP_FUNCTION(ob_end_flush); @@ -51,9 +54,12 @@ uint size; uint text_length; int block_size; - zval *output_handler; uint chunk_size; int status; + zval *output_handler; + php_output_handler_func_t internal_output_handler; + char *internal_output_handler_buffer; + uint internal_output_handler_buffer_size; } php_ob_buffer; typedef struct _php_output_globals { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]