Skip to content

main/output.c: Refine int return type to bool or zend_result #13997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
static php_iconv_err_t php_iconv_stream_filter_register_factory(void);
static php_iconv_err_t php_iconv_stream_filter_unregister_factory(void);

static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len);
static zend_result php_iconv_output_conflict(const char *handler_name, size_t handler_name_len);
static php_output_handler *php_iconv_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags);
static int php_iconv_output_handler(void **nothing, php_output_context *output_context);
static zend_result php_iconv_output_handler(void **nothing, php_output_context *output_context);
/* }}} */

/* {{{ static globals */
Expand Down Expand Up @@ -281,7 +281,7 @@ static const char *get_output_encoding(void) {
}


static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len)
static zend_result php_iconv_output_conflict(const char *handler_name, size_t handler_name_len)
{
if (php_output_get_level()) {
if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_iconv_handler"))
Expand All @@ -297,7 +297,7 @@ static php_output_handler *php_iconv_output_handler_init(const char *handler_nam
return php_output_handler_create_internal(handler_name, handler_name_len, php_iconv_output_handler, chunk_size, flags);
}

static int php_iconv_output_handler(void **nothing, php_output_context *output_context)
static zend_result php_iconv_output_handler(void **nothing, php_output_context *output_context)
{
char *s, *content_type, *mimetype = NULL;
int output_status, mimetype_len = 0;
Expand Down
6 changes: 3 additions & 3 deletions ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options);
static PHP_INI_MH(php_tidy_set_clean_output);
static void php_tidy_clean_output_start(const char *name, size_t name_len);
static php_output_handler *php_tidy_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags);
static int php_tidy_output_handler(void **nothing, php_output_context *output_context);
static zend_result php_tidy_output_handler(void **nothing, php_output_context *output_context);

static PHP_MINIT_FUNCTION(tidy);
static PHP_MSHUTDOWN_FUNCTION(tidy);
Expand Down Expand Up @@ -953,9 +953,9 @@ static php_output_handler *php_tidy_output_handler_init(const char *handler_name
return php_output_handler_create_internal(handler_name, handler_name_len, php_tidy_output_handler, chunk_size, flags);
}

static int php_tidy_output_handler(void **nothing, php_output_context *output_context)
static zend_result php_tidy_output_handler(void **nothing, php_output_context *output_context)
{
int status = FAILURE;
zend_result status = FAILURE;
TidyDoc doc;
TidyBuffer inbuf, outbuf, errbuf;

Expand Down
10 changes: 5 additions & 5 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void php_zlib_free(voidpf opaque, voidpf address)
/* }}} */

/* {{{ php_zlib_output_conflict_check() */
static int php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len)
static zend_result php_zlib_output_conflict_check(const char *handler_name, size_t handler_name_len)
{
if (php_output_get_level() > 0) {
if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME))
Expand Down Expand Up @@ -166,7 +166,7 @@ static int php_zlib_output_encoding(void)
/* }}} */

/* {{{ php_zlib_output_handler_ex() */
static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context)
static zend_result php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context *output_context)
{
int flags = Z_SYNC_FLUSH;

Expand Down Expand Up @@ -252,7 +252,7 @@ static int php_zlib_output_handler_ex(php_zlib_context *ctx, php_output_context
/* }}} */

/* {{{ php_zlib_output_handler() */
static int php_zlib_output_handler(void **handler_context, php_output_context *output_context)
static zend_result php_zlib_output_handler(void **handler_context, php_output_context *output_context)
{
php_zlib_context *ctx = *(php_zlib_context **) handler_context;

Expand Down Expand Up @@ -526,7 +526,7 @@ PHP_FUNCTION(ob_gzhandler)
size_t in_len;
zend_long flags = 0;
php_output_context ctx = {0};
int encoding, rv;
int encoding;

/*
* NOTE that the real ob_gzhandler is an alias to "zlib output compression".
Expand Down Expand Up @@ -564,7 +564,7 @@ PHP_FUNCTION(ob_gzhandler)
ctx.in.data = in_str;
ctx.in.used = in_len;

rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx);
zend_result rv = php_zlib_output_handler_ex(ZLIBG(ob_gzhandler), &ctx);

if (SUCCESS != rv) {
if (ctx.out.data && ctx.out.free) {
Expand Down
80 changes: 40 additions & 40 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ static HashTable php_output_handler_reverse_conflicts;
/* }}} */

/* {{{ forward declarations */
static inline int php_output_lock_error(int op);
static inline bool php_output_lock_error(int op);
static inline void php_output_op(int op, const char *str, size_t len);

static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags);
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);
static inline bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf);
static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry);

static inline void php_output_context_init(php_output_context *context, int op);
static inline void php_output_context_reset(php_output_context *context);
static inline void php_output_context_swap(php_output_context *context);
static inline void php_output_context_dtor(php_output_context *context);

static int php_output_stack_pop(int flags);
static zend_result php_output_stack_pop(int flags);

static int php_output_stack_apply_op(void *h, void *c);
static int php_output_stack_apply_clean(void *h, void *c);
static int php_output_stack_apply_list(void *h, void *z);
static int php_output_stack_apply_status(void *h, void *z);

static int php_output_handler_compat_func(void **handler_context, php_output_context *output_context);
static int php_output_handler_default_func(void **handler_context, php_output_context *output_context);
static int php_output_handler_devnull_func(void **handler_context, php_output_context *output_context);
static zend_result php_output_handler_compat_func(void **handler_context, php_output_context *output_context);
static zend_result php_output_handler_default_func(void **handler_context, php_output_context *output_context);
static zend_result php_output_handler_devnull_func(void **handler_context, php_output_context *output_context);
/* }}} */

/* {{{ static void php_output_init_globals(zend_output_globals *G)
Expand Down Expand Up @@ -250,7 +250,7 @@ PHPAPI size_t php_output_write(const char *str, size_t len)

/* {{{ SUCCESS|FAILURE php_output_flush(void)
* Flush the most recent output handlers buffer */
PHPAPI int php_output_flush(void)
PHPAPI zend_result php_output_flush(void)
{
php_output_context context;

Expand Down Expand Up @@ -281,7 +281,7 @@ PHPAPI void php_output_flush_all(void)

/* {{{ SUCCESS|FAILURE php_output_clean(void)
* Cleans the most recent output handlers buffer if the handler is cleanable */
PHPAPI int php_output_clean(void)
PHPAPI zend_result php_output_clean(void)
{
php_output_context context;

Expand Down Expand Up @@ -309,7 +309,7 @@ PHPAPI void php_output_clean_all(void)

/* {{{ SUCCESS|FAILURE php_output_end(void)
* Finalizes the most recent output handler at pops it off the stack if the handler is removable */
PHPAPI int php_output_end(void)
PHPAPI zend_result php_output_end(void)
{
if (php_output_stack_pop(PHP_OUTPUT_POP_TRY)) {
return SUCCESS;
Expand All @@ -328,7 +328,7 @@ PHPAPI void php_output_end_all(void)

/* {{{ SUCCESS|FAILURE php_output_discard(void)
* Discards the most recent output handlers buffer and pops it off the stack if the handler is removable */
PHPAPI int php_output_discard(void)
PHPAPI zend_result php_output_discard(void)
{
if (php_output_stack_pop(PHP_OUTPUT_POP_DISCARD|PHP_OUTPUT_POP_TRY)) {
return SUCCESS;
Expand Down Expand Up @@ -357,7 +357,7 @@ PHPAPI int php_output_get_level(void)

/* {{{ SUCCESS|FAILURE php_output_get_contents(zval *z)
* Get the contents of the active output handlers buffer */
PHPAPI int php_output_get_contents(zval *p)
PHPAPI zend_result php_output_get_contents(zval *p)
{
if (OG(active)) {
ZVAL_STRINGL(p, OG(active)->buffer.data, OG(active)->buffer.used);
Expand All @@ -370,7 +370,7 @@ PHPAPI int php_output_get_contents(zval *p)

/* {{{ SUCCESS|FAILURE php_output_get_length(zval *z)
* Get the length of the active output handlers buffer */
PHPAPI int php_output_get_length(zval *p)
PHPAPI zend_result php_output_get_length(zval *p)
{
if (OG(active)) {
ZVAL_LONG(p, OG(active)->buffer.used);
Expand All @@ -392,7 +392,7 @@ PHPAPI php_output_handler* php_output_get_active_handler(void)

/* {{{ SUCCESS|FAILURE php_output_handler_start_default(void)
* Start a "default output handler" */
PHPAPI int php_output_start_default(void)
PHPAPI zend_result php_output_start_default(void)
{
php_output_handler *handler;

Expand All @@ -407,7 +407,7 @@ PHPAPI int php_output_start_default(void)

/* {{{ SUCCESS|FAILURE php_output_handler_start_devnull(void)
* Start a "null output handler" */
PHPAPI int php_output_start_devnull(void)
PHPAPI zend_result php_output_start_devnull(void)
{
php_output_handler *handler;

Expand All @@ -422,7 +422,7 @@ PHPAPI int php_output_start_devnull(void)

/* {{{ SUCCESS|FAILURE php_output_start_user(zval *handler, size_t chunk_size, int flags)
* Start a user level output handler */
PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int flags)
PHPAPI zend_result php_output_start_user(zval *output_handler, size_t chunk_size, int flags)
{
php_output_handler *handler;

Expand All @@ -441,7 +441,7 @@ PHPAPI int php_output_start_user(zval *output_handler, size_t chunk_size, int fl

/* {{{ SUCCESS|FAILURE php_output_start_internal(zval *name, php_output_handler_func_t handler, size_t chunk_size, int flags)
* 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)
PHPAPI zend_result php_output_start_internal(const char *name, size_t name_len, php_output_handler_func_t output_handler, size_t chunk_size, int flags)
{
php_output_handler *handler;

Expand Down Expand Up @@ -526,7 +526,7 @@ PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *op

/* {{{ SUCCESS|FAILURE php_output_handler_start(php_output_handler *handler)
* 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)
PHPAPI zend_result php_output_handler_start(php_output_handler *handler)
{
HashTable *rconflicts;
php_output_handler_conflict_check_t conflict;
Expand All @@ -553,9 +553,9 @@ PHPAPI int php_output_handler_start(php_output_handler *handler)
}
/* }}} */

/* {{{ int php_output_handler_started(zval *name)
/* {{{ bool php_output_handler_started(zval *name)
* Check whether a certain output handler is in use */
PHPAPI int php_output_handler_started(const char *name, size_t name_len)
PHPAPI bool php_output_handler_started(const char *name, size_t name_len)
{
php_output_handler **handlers;
int i, count = php_output_get_level();
Expand All @@ -565,34 +565,34 @@ PHPAPI int php_output_handler_started(const char *name, size_t name_len)

for (i = 0; i < count; ++i) {
if (zend_string_equals_cstr(handlers[i]->name, name, name_len)) {
return 1;
return true;
}
}
}

return 0;
return false;
}
/* }}} */

/* {{{ int php_output_handler_conflict(zval *handler_new, zval *handler_old)
/* {{{ bool php_output_handler_conflict(zval *handler_new, zval *handler_old)
* 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)
PHPAPI bool php_output_handler_conflict(const char *handler_new, size_t handler_new_len, const char *handler_set, size_t handler_set_len)
{
if (php_output_handler_started(handler_set, handler_set_len)) {
if (handler_new_len != handler_set_len || memcmp(handler_new, handler_set, handler_set_len)) {
php_error_docref("ref.outcontrol", E_WARNING, "Output handler '%s' conflicts with '%s'", handler_new, handler_set);
} else {
php_error_docref("ref.outcontrol", E_WARNING, "Output handler '%s' cannot be used twice", handler_new);
}
return 1;
return true;
}
return 0;
return false;
}
/* }}} */

/* {{{ SUCCESS|FAILURE php_output_handler_conflict_register(zval *name, php_output_handler_conflict_check_t check_func)
* 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)
PHPAPI zend_result php_output_handler_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func)
{
zend_string *str;

Expand All @@ -609,7 +609,7 @@ PHPAPI int php_output_handler_conflict_register(const char *name, size_t name_le

/* {{{ SUCCESS|FAILURE php_output_handler_reverse_conflict_register(zval *name, php_output_handler_conflict_check_t check_func)
* 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)
PHPAPI zend_result php_output_handler_reverse_conflict_register(const char *name, size_t name_len, php_output_handler_conflict_check_t check_func)
{
HashTable rev, *rev_ptr = NULL;

Expand Down Expand Up @@ -646,7 +646,7 @@ PHPAPI php_output_handler_alias_ctor_t php_output_handler_alias(const char *name

/* {{{ SUCCESS|FAILURE php_output_handler_alias_register(zval *name, php_output_handler_alias_ctor_t func)
* 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)
PHPAPI zend_result php_output_handler_alias_register(const char *name, size_t name_len, php_output_handler_alias_ctor_t func)
{
zend_string *str;

Expand All @@ -663,7 +663,7 @@ PHPAPI int php_output_handler_alias_register(const char *name, size_t name_len,

/* {{{ SUCCESS|FAILURE php_output_handler_hook(php_output_handler_hook_t type, void *arg)
* 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)
PHPAPI zend_result php_output_handler_hook(php_output_handler_hook_t type, void *arg)
{
if (OG(running)) {
switch (type) {
Expand Down Expand Up @@ -751,18 +751,18 @@ PHPAPI int php_output_get_start_lineno(void)
}
/* }}} */

/* {{{ static int php_output_lock_error(int op)
/* {{{ static bool php_output_lock_error(int op)
* 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)
static inline bool php_output_lock_error(int op)
{
/* if there's no ob active, ob has been stopped */
if (op && OG(active) && OG(running)) {
/* fatal error */
php_output_deactivate();
php_error_docref("ref.outcontrol", E_ERROR, "Cannot use output buffering in output buffering display handlers");
return 1;
return true;
}
return 0;
return false;
}
/* }}} */

Expand Down Expand Up @@ -865,9 +865,9 @@ static inline php_output_handler *php_output_handler_init(zend_string *name, siz
}
/* }}} */

/* {{{ static int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf)
/* {{{ static bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf)
* 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)
static inline bool php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf)
{
if (buf->used) {
OG(flags) |= PHP_OUTPUT_WRITTEN;
Expand All @@ -886,10 +886,10 @@ static inline int php_output_handler_append(php_output_handler *handler, const p
/* chunked buffering */
if (handler->size && (handler->buffer.used >= handler->size)) {
/* store away errors and/or any intermediate output */
return OG(running) ? 1 : 0;
return OG(running) ? true : false;
}
}
return 1;
return true;
}
/* }}} */

Expand Down Expand Up @@ -1243,7 +1243,7 @@ static int php_output_stack_pop(int flags)

/* {{{ 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 */
static int php_output_handler_compat_func(void **handler_context, php_output_context *output_context)
static zend_result 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;

Expand All @@ -1269,7 +1269,7 @@ static int php_output_handler_compat_func(void **handler_context, php_output_con

/* {{{ static SUCCESS|FAILURE php_output_handler_default_func(void *ctx, php_output_context *)
* Default output handler */
static int php_output_handler_default_func(void **handler_context, php_output_context *output_context)
static zend_result php_output_handler_default_func(void **handler_context, php_output_context *output_context)
{
php_output_context_pass(output_context);
return SUCCESS;
Expand All @@ -1278,7 +1278,7 @@ static int php_output_handler_default_func(void **handler_context, php_output_co

/* {{{ static SUCCESS|FAILURE php_output_handler_devnull_func(void *ctx, php_output_context *)
* Null output handler */
static int php_output_handler_devnull_func(void **handler_context, php_output_context *output_context)
static zend_result php_output_handler_devnull_func(void **handler_context, php_output_context *output_context)
{
return SUCCESS;
}
Expand Down
Loading