]> granicus.if.org Git - php/commitdiff
- use new zend_fcall_info API
authorMichael Wallner <mike@php.net>
Thu, 12 Oct 2006 12:50:29 +0000 (12:50 +0000)
committerMichael Wallner <mike@php.net>
Thu, 12 Oct 2006 12:50:29 +0000 (12:50 +0000)
- use enums where appropriate

main/output.c
main/php_output.h

index 68a6ba0651120f222902de1ed65c5112ee624017..4638c8985a1ca8b8d7b4076382784c84d7993822 100644 (file)
@@ -53,7 +53,7 @@ static inline int php_output_lock_error(int op TSRMLS_DC);
 static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC);
 
 static inline php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags);
-static inline int php_output_handler_op(php_output_handler *handler, php_output_context *context);
+static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context);
 static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC);
 static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry);
 
@@ -500,25 +500,17 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler,
                                break;
                        }
                default:
-                       user = emalloc(sizeof(php_output_handler_user_func_t));
-                       user->fci = empty_fcall_info;
-                       user->fcc = empty_fcall_info_cache;
-                       
-                       if (SUCCESS == zend_fcall_info_init(output_handler, &user->fci, &user->fcc TSRMLS_CC)) {
-                               /* FIXME: redundancy */
-                               MAKE_STD_ZVAL(handler_name);
-                               zend_make_callable(output_handler, handler_name TSRMLS_CC);
+                       user = ecalloc(1, sizeof(php_output_handler_user_func_t));
+                       MAKE_STD_ZVAL(handler_name);
+                       if (SUCCESS == zend_fcall_info_init(output_handler, &user->fci, &user->fcc, handler_name TSRMLS_CC)) {
                                handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER);
-                               zval_ptr_dtor(&handler_name);
-                               
                                ZVAL_ADDREF(output_handler);
                                user->zoh = output_handler;
-                               user->fci.param_count = 2;
-                               user->fci.params = (zval ***) user->fcp;
                                handler->func.user = user;
                        } else {
                                efree(user);
                        }
+                       zval_ptr_dtor(&handler_name);
        }
        
        return handler;
@@ -682,9 +674,9 @@ PHPAPI int php_output_handler_alias_register(zval *name, php_output_handler_alia
 }
 /* }}} */
 
-/* {{{ SUCCESS|FAILURE php_output_handler_hook(int type, void *arg TSMRLS_DC)
+/* {{{ 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 */
-PHPAPI int php_output_handler_hook(int type, void *arg TSRMLS_DC)
+PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC)
 {
        if (OG(running)) {
                switch (type) {
@@ -702,6 +694,8 @@ PHPAPI int php_output_handler_hook(int type, void *arg TSRMLS_DC)
                        case PHP_OUTPUT_HANDLER_HOOK_DISABLE:
                                OG(running)->flags |= PHP_OUTPUT_HANDLER_DISABLED;
                                return SUCCESS;
+                       default:
+                               break;
                }
        }
        return FAILURE;
@@ -899,11 +893,11 @@ static inline int php_output_handler_append(php_output_handler *handler, const p
 }
 /* }}} */
 
-/* {{{ static PHP_OUTPUT_HANDLER_(SUCCESS|FAILURE|NO_DATA) php_output_handler_op(php_output_handler *handler, php_output_context *context)
+/* {{{ 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 */
-static inline int php_output_handler_op(php_output_handler *handler, php_output_context *context)
+static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context)
 {
-       int status;
+       php_output_handler_status_t status;
        PHP_OUTPUT_TSRMLS(context);
        
 #if PHP_OUTPUT_DEBUG
@@ -944,14 +938,13 @@ static inline int php_output_handler_op(php_output_handler *handler, php_output_
                
                OG(running) = handler;
                if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
-                       zval *retval = NULL, *params[2];
+                       zval *retval = NULL, *ob_data, *ob_mode;
                        
-                       MAKE_STD_ZVAL(params[0]);
-                       ZVAL_STRINGL(params[0], handler->buffer.data, handler->buffer.used, 1);
-                       MAKE_STD_ZVAL(params[1]);
-                       ZVAL_LONG(params[1], (long) context->op);
-                       handler->func.user->fci.params[0] = &params[0];
-                       handler->func.user->fci.params[1] = &params[1];
+                       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_NULL) && (Z_TYPE_P(retval) != IS_BOOL || Z_BVAL_P(retval)))
                        if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) {
@@ -970,8 +963,10 @@ static inline int php_output_handler_op(php_output_handler *handler, php_output_
                                /* call failed, pass internal buffer along */
                                status = PHP_OUTPUT_HANDLER_FAILURE;
                        }
-                       zval_ptr_dtor(&params[0]);
-                       zval_ptr_dtor(&params[1]);
+                       
+                       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);
                        }
@@ -1094,11 +1089,14 @@ static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC)
        Operation callback for the stack apply function */
 static int php_output_stack_apply_op(void *h, void *c)
 {
-       int status = PHP_OUTPUT_HANDLER_FAILURE, was_disabled, op;
+       int was_disabled, op;
+       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))) {
+       if ((was_disabled = (handler->flags & PHP_OUTPUT_HANDLER_DISABLED))) {
+               status = PHP_OUTPUT_HANDLER_FAILURE;
+       } else {
                op = context->op;
                status = php_output_handler_op(handler, context);
                context->op = op;
index 25130942d79d1fc12078c655952911d23a71be1d..d74f4589e5b54488bf67038f7e735cc717047e08 100644 (file)
 #define PHP_OUTPUT_HANDLER_DISABLED            0x2000
 
 /* handler op return values */
-#define PHP_OUTPUT_HANDLER_FAILURE             0
-#define PHP_OUTPUT_HANDLER_SUCCESS             1
-#define PHP_OUTPUT_HANDLER_NO_DATA             2
+typedef enum _php_output_handler_status_t {
+       PHP_OUTPUT_HANDLER_FAILURE,
+       PHP_OUTPUT_HANDLER_SUCCESS,
+       PHP_OUTPUT_HANDLER_NO_DATA,
+} php_output_handler_status_t;
 
 /* php_output_stack_pop() flags */
 #define PHP_OUTPUT_POP_TRY                     0x000
 #define PHP_OUTPUT_LOCKED                              0x20
 
 /* handler hooks */
-#define PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ       1
-#define PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS      2
-#define PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL      3
-#define PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE      4
-#define PHP_OUTPUT_HANDLER_HOOK_DISABLE                5
+typedef enum _php_output_handler_hook_t {
+       PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ,
+       PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS,
+       PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL,
+       PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE,
+       PHP_OUTPUT_HANDLER_HOOK_DISABLE,
+       /* unused */
+       PHP_OUTPUT_HANDLER_HOOK_LAST,
+} php_output_handler_hook_t;
 
 #define PHP_OUTPUT_HANDLER_INITBUF_SIZE(s) \
 ( (s) ? \
@@ -114,7 +120,6 @@ typedef struct _php_output_handler *(*php_output_handler_alias_ctor_t)(zval *han
 typedef struct _php_output_handler_user_func_t {
        zend_fcall_info fci;
        zend_fcall_info_cache fcc;
-       zval **fcp[2];
        zval *zoh;
 } php_output_handler_user_func_t;
 
@@ -229,7 +234,7 @@ PHPAPI php_output_handler *php_output_handler_create_internal(zval *name, php_ou
 PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *opaq, void (*dtor)(void* TSRMLS_DC) TSRMLS_DC);
 PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC);
 PHPAPI int php_output_handler_started(zval *name TSRMLS_DC);
-PHPAPI int php_output_handler_hook(int type, void *arg TSRMLS_DC);
+PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSRMLS_DC);
 PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC);
 PHPAPI void php_output_handler_free(php_output_handler **handler TSRMLS_DC);