]> granicus.if.org Git - php/commitdiff
- error message enhancements
authorMichael Wallner <mike@php.net>
Wed, 9 Aug 2006 13:56:45 +0000 (13:56 +0000)
committerMichael Wallner <mike@php.net>
Wed, 9 Aug 2006 13:56:45 +0000 (13:56 +0000)
- avoid duplicate error messages
- add PHP_OUTPUT_HANDLER_FLUSHABLE
- add PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
- add more tests

main/output.c
main/php_output.h
tests/output/ob_013.phpt
tests/output/ob_018.phpt [new file with mode: 0644]
tests/output/ob_019.phpt [new file with mode: 0644]

index ed49e99f43a3be4e12000f38f6c29180a2a5a801..e439f119f91f7b011893d4c19669b24a80f22aed 100644 (file)
@@ -157,6 +157,7 @@ PHPAPI void php_output_register_constants(TSRMLS_D)
        REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_END", PHP_OUTPUT_HANDLER_FINAL, CONST_CS | CONST_PERSISTENT);
 
        REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CLEANABLE", PHP_OUTPUT_HANDLER_CLEANABLE, CONST_CS | CONST_PERSISTENT);
+       REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FLUSHABLE", PHP_OUTPUT_HANDLER_FLUSHABLE, CONST_CS | CONST_PERSISTENT);
        REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_REMOVABLE", PHP_OUTPUT_HANDLER_REMOVABLE, CONST_CS | CONST_PERSISTENT);
        REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STDFLAGS", PHP_OUTPUT_HANDLER_STDFLAGS, CONST_CS | CONST_PERSISTENT);
        REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STARTED", PHP_OUTPUT_HANDLER_STARTED, CONST_CS | CONST_PERSISTENT);
@@ -266,13 +267,13 @@ PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC)
 }
 /* }}} */
 
-/* {{{ void php_output_flush(TSRMLS_D)
+/* {{{ SUCCESS|FAILURE php_output_flush(TSRMLS_D)
        Flush the most recent output handlers buffer */
-PHPAPI void php_output_flush(TSRMLS_D)
+PHPAPI int php_output_flush(TSRMLS_D)
 {
        php_output_context context;
        
-       if (OG(active)) {
+       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);
                if (context.out.data && context.out.used) {
@@ -281,7 +282,9 @@ PHPAPI void php_output_flush(TSRMLS_D)
                        zend_stack_push(&OG(handlers), &OG(active), sizeof(php_output_handler *));
                }
                php_output_context_dtor(&context);
+               return SUCCESS;
        }
+       return FAILURE;
 }
 /* }}} */
 
@@ -638,7 +641,7 @@ PHPAPI php_output_handler_context_func_t *php_output_handler_alias(zval *name TS
 /* }}} */
 
 /* {{{ SUCCESS|FAILURE php_output_handler_alias_register(zval *name, php_output_handler_context_func_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_ex(zval *name, php_output_handler_context_func_t func TSRMLS_DC)
 {
        if (!EG(current_module)) {
@@ -661,6 +664,8 @@ PHPAPI int php_output_handler_hook(int type, void *arg TSRMLS_DC)
                        case PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS:
                                *(int *) arg = OG(running)->flags;
                                return SUCCESS;
+                       case PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL:
+                               *(int *) arg = OG(running)->level;
                        case PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE:
                                OG(running)->flags &= ~PHP_OUTPUT_HANDLER_STDFLAGS;
                                return SUCCESS;
@@ -1165,10 +1170,10 @@ static inline int php_output_stack_pop(int discard, int shutdown TSRMLS_DC)
        php_output_handler **current, *orphan = OG(active);
        
        if (!orphan) {
-               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete.");
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer. No buffer to %s", discard?"discard":"send", discard?"discard":"send");
                return 0;
        } else if (!shutdown && !(orphan->flags & PHP_OUTPUT_HANDLER_REMOVABLE)) {
-               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", orphan->name);
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %v (%d)", discard?"discard":"send", Z_UNIVAL_P(orphan->name), orphan->level);
                return 0;
        } else {
                php_output_context_init(&context, PHP_OUTPUT_HANDLER_FINAL TSRMLS_CC);
@@ -1259,7 +1264,7 @@ PHP_FUNCTION(ob_start)
        long chunk_size = 0;
        long flags = PHP_OUTPUT_HANDLER_STDFLAGS;
        
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/lb", &output_handler, &chunk_size, &flags)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/ll", &output_handler, &chunk_size, &flags)) {
                RETURN_FALSE;
        }
        if (chunk_size < 0) {
@@ -1286,8 +1291,10 @@ PHP_FUNCTION(ob_flush)
                php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush");
                RETURN_FALSE;
        }
-       
-       php_output_flush(TSRMLS_C);
+       if (SUCCESS != php_output_flush(TSRMLS_C)) {
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %v (%d)", Z_UNIVAL_P(OG(active)->name), OG(active)->level);
+               RETURN_FALSE;
+       }
        RETURN_TRUE;
 }
 /* }}} */
@@ -1306,7 +1313,7 @@ PHP_FUNCTION(ob_clean)
                RETURN_FALSE;
        }
        if (SUCCESS != php_output_clean(TSRMLS_C)) {
-               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v", Z_UNIVAL_P(OG(active)->name));
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v (%d)", Z_UNIVAL_P(OG(active)->name), OG(active)->level);
                RETURN_FALSE;
        }
        RETURN_TRUE;
@@ -1325,11 +1332,7 @@ PHP_FUNCTION(ob_end_flush)
                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 %v", Z_UNIVAL_P(OG(active)->name));
-               RETURN_FALSE;
-       }
-       RETURN_TRUE;
+       RETURN_BOOL(SUCCESS == php_output_end(TSRMLS_C));
 }
 /* }}} */
 
@@ -1345,11 +1348,7 @@ PHP_FUNCTION(ob_end_clean)
                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 %v", Z_UNIVAL_P(OG(active)->name));
-               RETURN_FALSE;
-       }
-       RETURN_TRUE;
+       RETURN_BOOL(SUCCESS == php_output_discard(TSRMLS_C));
 }
 /* }}} */
 
@@ -1366,7 +1365,7 @@ PHP_FUNCTION(ob_get_flush)
                RETURN_FALSE;
        }
        if (SUCCESS != php_output_end(TSRMLS_C)) {
-               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v", Z_UNIVAL_P(OG(active)->name));
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v (%d)", Z_UNIVAL_P(OG(active)->name), OG(active)->level);
        }
 }
 /* }}} */
@@ -1384,7 +1383,7 @@ PHP_FUNCTION(ob_get_clean)
                RETURN_FALSE;
        }
        if (SUCCESS != php_output_discard(TSRMLS_C)) {
-               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v", Z_UNIVAL_P(OG(active)->name));
+               php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %v (%d)", Z_UNIVAL_P(OG(active)->name), OG(active)->level);
        }
 }
 /* }}} */
@@ -1443,7 +1442,7 @@ PHP_FUNCTION(ob_list_handlers)
 }
 /* }}} */
 
-/* {{{ proto false|array ob_get_status([bool full_status])
+/* {{{ proto false|array ob_get_status([bool full_status]) U
    Return the status of the active or all output buffers */
 PHP_FUNCTION(ob_get_status)
 {
@@ -1465,7 +1464,7 @@ PHP_FUNCTION(ob_get_status)
 }
 /* }}} */
 
-/* {{{ proto void ob_implicit_flush([int flag])
+/* {{{ proto void ob_implicit_flush([int flag]) U
    Turn implicit flush on/off and is equivalent to calling flush() after every output call */
 PHP_FUNCTION(ob_implicit_flush)
 {
index c2a7451dd5747b7aaaccdb49c820a85bd6c0ecba..0c275c6da71b6dd7f27083250d3fce16abf6187c 100644 (file)
@@ -38,8 +38,9 @@
 
 /* handler ability flags */
 #define PHP_OUTPUT_HANDLER_CLEANABLE   0x0010
-#define PHP_OUTPUT_HANDLER_REMOVABLE   0x0020
-#define PHP_OUTPUT_HANDLER_STDFLAGS            0x0030
+#define PHP_OUTPUT_HANDLER_FLUSHABLE   0x0020
+#define PHP_OUTPUT_HANDLER_REMOVABLE   0x0040
+#define PHP_OUTPUT_HANDLER_STDFLAGS            0x0070
 
 /* handler status flags */
 #define PHP_OUTPUT_HANDLER_STARTED             0x1000
@@ -60,8 +61,9 @@
 /* handler hooks */
 #define PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ       1
 #define PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS      2
-#define PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE      3
-#define PHP_OUTPUT_HANDLER_HOOK_DISABLE                4
+#define PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL      3
+#define PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE      4
+#define PHP_OUTPUT_HANDLER_HOOK_DISABLE                5
 
 #define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
 ( (s) ? \
@@ -183,7 +185,7 @@ PHPAPI int php_output_write_unicode(const UChar *str, size_t len TSRMLS_DC);
 PHPAPI int php_output_write_ascii(const char *str, size_t len TSRMLS_DC);
 PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC);
 
-PHPAPI void php_output_flush(TSRMLS_D);
+PHPAPI int php_output_flush(TSRMLS_D);
 PHPAPI void php_output_flush_all(TSRMLS_D);
 PHPAPI int php_output_clean(TSRMLS_D);
 PHPAPI void php_output_clean_all(TSRMLS_D);
index 0a179728371244c728ac3f248b6f67fe51f11652..e764461172fccf0ecaf54cacb6ef7d3ab925a9be 100644 (file)
@@ -39,7 +39,7 @@ Array
 (
     [name] => d
     [type] => 1
-    [flags] => 4145
+    [flags] => 4209
     [level] => 4
     [chunk_size] => 0
     [buffer_size] => 16384
@@ -51,7 +51,7 @@ Array
         (
             [name] => default output handler
             [type] => 0
-            [flags] => 48
+            [flags] => 112
             [level] => 0
             [chunk_size] => 0
             [buffer_size] => 16384
@@ -62,7 +62,7 @@ Array
         (
             [name] => a
             [type] => 1
-            [flags] => 49
+            [flags] => 113
             [level] => 1
             [chunk_size] => 0
             [buffer_size] => 16384
@@ -73,7 +73,7 @@ Array
         (
             [name] => b
             [type] => 1
-            [flags] => 49
+            [flags] => 113
             [level] => 2
             [chunk_size] => 0
             [buffer_size] => 16384
@@ -84,7 +84,7 @@ Array
         (
             [name] => c
             [type] => 1
-            [flags] => 49
+            [flags] => 113
             [level] => 3
             [chunk_size] => 0
             [buffer_size] => 16384
@@ -95,7 +95,7 @@ Array
         (
             [name] => d
             [type] => 1
-            [flags] => 4145
+            [flags] => 4209
             [level] => 4
             [chunk_size] => 0
             [buffer_size] => 16384
diff --git a/tests/output/ob_018.phpt b/tests/output/ob_018.phpt
new file mode 100644 (file)
index 0000000..2be99fe
Binary files /dev/null and b/tests/output/ob_018.phpt differ
diff --git a/tests/output/ob_019.phpt b/tests/output/ob_019.phpt
new file mode 100644 (file)
index 0000000..ea61d44
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+output buffering - flags
+--FILE--
+<?php
+declare(encoding="latin1");
+
+echo "\n==".ob_get_level()."==\n";
+ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE);
+echo "N:clean\n";
+ob_clean();
+ob_flush();
+
+echo "\n==".ob_get_level()."==\n";
+ob_start(null, 0, PHP_OUTPUT_HANDLER_FLUSHABLE);
+echo "Y:flush\n";
+ob_clean();
+ob_flush();
+
+echo "\n==".ob_get_level()."==\n";
+ob_start(null, 0, PHP_OUTPUT_HANDLER_REMOVABLE);
+echo "N:remove-clean\n";
+ob_end_clean();
+
+echo "\n==".ob_get_level()."==\n";
+ob_start(null, 0, PHP_OUTPUT_HANDLER_REMOVABLE);
+echo "Y:remove-flush\n";
+ob_end_flush();
+
+echo "\n==".ob_get_level()."==\n";
+ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
+echo "N:standard\n";
+ob_end_clean();
+
+?>
+--EXPECTF--
+
+==0==
+
+Notice: ob_flush(): failed to flush buffer of default output handler (0) in %sob_019.php on line %d
+
+==1==
+Y:flush
+
+Notice: ob_clean(): failed to delete buffer of default output handler (1) in %sob_019.php on line %d
+
+==2==
+
+==2==
+Y:remove-flush
+
+==2==