summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/SAPI.c2
-rw-r--r--main/SAPI.h10
-rw-r--r--main/fopen_wrappers.c2
-rw-r--r--main/main.c11
-rw-r--r--main/output.c26
-rw-r--r--main/php.h2
-rw-r--r--main/php_globals.h54
-rw-r--r--main/php_ini.c2
-rw-r--r--main/php_memory_streams.h8
-rw-r--r--main/php_network.h7
-rw-r--r--main/php_output.h3
-rw-r--r--main/php_streams.h3
-rw-r--r--main/php_variables.c22
-rw-r--r--main/php_version.h8
-rw-r--r--main/rfc1867.c12
-rw-r--r--main/spprintf.c2
-rw-r--r--main/streams/memory.c109
-rw-r--r--main/streams/plain_wrapper.c4
-rw-r--r--main/streams/userspace.c2
-rw-r--r--main/streams/xp_socket.c7
20 files changed, 135 insertions, 161 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 0a7f219e84..79d9610a53 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -606,7 +606,7 @@ static void sapi_remove_header(zend_llist *l, char *name, size_t len) {
}
}
-SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, zend_bool duplicate, zend_bool replace)
+SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace)
{
sapi_header_line ctr = {0};
int r;
diff --git a/main/SAPI.h b/main/SAPI.h
index b0d2928369..4de2189a6d 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -83,9 +83,9 @@ typedef struct {
const char *content_type;
- zend_bool headers_only;
- zend_bool no_headers;
- zend_bool headers_read;
+ bool headers_only;
+ bool no_headers;
+ bool headers_read;
sapi_post_entry *post_entry;
@@ -122,7 +122,7 @@ typedef struct _sapi_globals_struct {
HashTable *rfc1867_uploaded_files;
zend_long post_max_size;
int options;
- zend_bool sapi_started;
+ bool sapi_started;
double global_request_time;
HashTable known_post_content_types;
zval callback_func;
@@ -177,7 +177,7 @@ BEGIN_EXTERN_C()
SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg);
/* Deprecated functions. Use sapi_header_op instead. */
-SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, zend_bool duplicate, zend_bool replace);
+SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace);
#define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1)
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 88519bc726..633c5e3b2b 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -342,7 +342,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
char *filename = NULL;
zend_string *resolved_path = NULL;
size_t length;
- zend_bool orig_display_errors;
+ bool orig_display_errors;
path_info = SG(request_info).request_uri;
#if HAVE_PWD_H
diff --git a/main/main.c b/main/main.c
index d2d19a5ee8..ac7170c88a 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1138,7 +1138,7 @@ static void clear_last_error() {
static void report_zend_debug_error_notify_cb(int type, const char *error_filename, uint32_t error_lineno, zend_string *message)
{
if (PG(report_zend_debug)) {
- zend_bool trigger_break;
+ bool trigger_break;
switch (type) {
case E_ERROR:
@@ -1162,7 +1162,7 @@ static void report_zend_debug_error_notify_cb(int type, const char *error_filena
extended error handling function */
static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message)
{
- zend_bool display;
+ bool display;
int type = orig_type & E_ALL;
/* check for repeated errors to be ignored */
@@ -1443,7 +1443,7 @@ PHP_FUNCTION(set_time_limit)
/* {{{ php_fopen_wrapper_for_zend */
static FILE *php_fopen_wrapper_for_zend(const char *filename, zend_string **opened_path)
{
- return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
+ return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
}
/* }}} */
@@ -1727,7 +1727,7 @@ int php_request_startup(void)
/* {{{ php_request_shutdown */
void php_request_shutdown(void *dummy)
{
- zend_bool report_memleaks;
+ bool report_memleaks;
EG(flags) |= EG_FLAGS_IN_SHUTDOWN;
@@ -1757,7 +1757,7 @@ void php_request_shutdown(void *dummy)
/* 3. Flush all output buffers */
zend_try {
- zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
+ bool send_buffer = SG(request_info).headers_only ? 0 : 1;
if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
(size_t)PG(memory_limit) < zend_memory_usage(1)
@@ -1826,6 +1826,7 @@ void php_request_shutdown(void *dummy)
} zend_end_try();
/* 15. Free Willy (here be crashes) */
+ zend_arena_destroy(CG(arena));
zend_interned_strings_deactivate();
zend_try {
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
diff --git a/main/output.c b/main/output.c
index d155123834..ec844973c5 100644
--- a/main/output.c
+++ b/main/output.c
@@ -103,20 +103,20 @@ static size_t (*php_output_direct)(const char *str, size_t str_len) = php_output
static void php_output_header(void)
{
if (!SG(headers_sent)) {
- if (!OG(output_start_filename_str)) {
+ if (!OG(output_start_filename)) {
if (zend_is_compiling()) {
- OG(output_start_filename_str) = zend_get_compiled_filename();
+ OG(output_start_filename) = zend_get_compiled_filename();
OG(output_start_lineno) = zend_get_compiled_lineno();
} else if (zend_is_executing()) {
- OG(output_start_filename_str) = zend_get_executed_filename_ex();
+ OG(output_start_filename) = zend_get_executed_filename_ex();
OG(output_start_lineno) = zend_get_executed_lineno();
}
- if (OG(output_start_filename_str)) {
- zend_string_addref(OG(output_start_filename_str));
+ if (OG(output_start_filename)) {
+ zend_string_addref(OG(output_start_filename));
}
#if PHP_OUTPUT_DEBUG
fprintf(stderr, "!!! output started at: %s (%d)\n",
- ZSTR_VAL(OG(output_start_filename_str)), OG(output_start_lineno));
+ ZSTR_VAL(OG(output_start_filename)), OG(output_start_lineno));
#endif
}
if (!php_header()) {
@@ -195,9 +195,9 @@ PHPAPI void php_output_deactivate(void)
zend_stack_destroy(&OG(handlers));
}
- if (OG(output_start_filename_str)) {
- zend_string_release(OG(output_start_filename_str));
- OG(output_start_filename_str) = NULL;
+ if (OG(output_start_filename)) {
+ zend_string_release(OG(output_start_filename));
+ OG(output_start_filename) = NULL;
}
}
/* }}} */
@@ -758,7 +758,7 @@ PHPAPI void php_output_set_implicit_flush(int flush)
* Get the file name where output has started */
PHPAPI const char *php_output_get_start_filename(void)
{
- return OG(output_start_filename_str) ? ZSTR_VAL(OG(output_start_filename_str)) : NULL;
+ return OG(output_start_filename) ? ZSTR_VAL(OG(output_start_filename)) : NULL;
}
/* }}} */
@@ -807,7 +807,7 @@ static inline void php_output_context_reset(php_output_context *context)
/* {{{ 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)
+static inline void php_output_context_feed(php_output_context *context, char *data, size_t size, size_t used, bool free)
{
if (context->in.free && context->in.data) {
efree(context->in.data);
@@ -970,7 +970,7 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
/* user handler may have returned TRUE */
status = PHP_OUTPUT_HANDLER_NO_DATA;
if (Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) {
- convert_to_string_ex(&retval);
+ convert_to_string(&retval);
if (Z_STRLEN(retval)) {
context->out.data = estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
context->out.used = Z_STRLEN(retval);
@@ -1491,7 +1491,7 @@ PHP_FUNCTION(ob_list_handlers)
/* {{{ Return the status of the active or all output buffers */
PHP_FUNCTION(ob_get_status)
{
- zend_bool full_status = 0;
+ bool full_status = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_status) == FAILURE) {
RETURN_THROWS();
diff --git a/main/php.h b/main/php.h
index f796577249..68076befde 100644
--- a/main/php.h
+++ b/main/php.h
@@ -22,7 +22,7 @@
#include <dmalloc.h>
#endif
-#define PHP_API_VERSION 20200930
+#define PHP_API_VERSION 20201009
#define PHP_HAVE_STREAMS
#define YYDEBUG 0
#define PHP_DEFAULT_CHARSET "UTF-8"
diff --git a/main/php_globals.h b/main/php_globals.h
index e079866645..e619694d18 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -51,11 +51,11 @@ typedef struct _arg_separators {
} arg_separators;
struct _php_core_globals {
- zend_bool implicit_flush;
+ bool implicit_flush;
zend_long output_buffering;
- zend_bool enable_dl;
+ bool enable_dl;
char *output_handler;
@@ -66,12 +66,12 @@ struct _php_core_globals {
zend_long max_input_time;
zend_uchar display_errors;
- zend_bool display_startup_errors;
- zend_bool log_errors;
+ bool display_startup_errors;
+ bool log_errors;
zend_long log_errors_max_len;
- zend_bool ignore_repeated_errors;
- zend_bool ignore_repeated_source;
- zend_bool report_memleaks;
+ bool ignore_repeated_errors;
+ bool ignore_repeated_source;
+ bool report_memleaks;
char *error_log;
char *doc_root;
@@ -102,7 +102,7 @@ struct _php_core_globals {
HashTable rfc1867_protected_variables;
short connection_status;
- zend_bool ignore_user_abort;
+ bool ignore_user_abort;
unsigned char header_is_being_sent;
@@ -110,27 +110,27 @@ struct _php_core_globals {
zval http_globals[6];
- zend_bool expose_php;
+ bool expose_php;
- zend_bool register_argc_argv;
- zend_bool auto_globals_jit;
+ bool register_argc_argv;
+ bool auto_globals_jit;
char *docref_root;
char *docref_ext;
- zend_bool html_errors;
- zend_bool xmlrpc_errors;
+ bool html_errors;
+ bool xmlrpc_errors;
zend_long xmlrpc_error_number;
- zend_bool activated_auto_globals[8];
+ bool activated_auto_globals[8];
- zend_bool modules_activated;
- zend_bool file_uploads;
- zend_bool during_request_startup;
- zend_bool allow_url_fopen;
- zend_bool enable_post_data_reading;
- zend_bool report_zend_debug;
+ bool modules_activated;
+ bool file_uploads;
+ bool during_request_startup;
+ bool allow_url_fopen;
+ bool enable_post_data_reading;
+ bool report_zend_debug;
int last_error_type;
zend_string *last_error_message;
@@ -140,31 +140,31 @@ struct _php_core_globals {
char *php_sys_temp_dir;
char *disable_classes;
- zend_bool allow_url_include;
+ bool allow_url_include;
#ifdef PHP_WIN32
- zend_bool com_initialized;
+ bool com_initialized;
#endif
zend_long max_input_nesting_level;
zend_long max_input_vars;
- zend_bool in_user_include;
+ bool in_user_include;
char *user_ini_filename;
zend_long user_ini_cache_ttl;
char *request_order;
- zend_bool mail_x_header;
+ bool mail_x_header;
char *mail_log;
- zend_bool in_error_log;
+ bool in_error_log;
#ifdef PHP_WIN32
- zend_bool windows_show_crt_warning;
+ bool windows_show_crt_warning;
#endif
zend_long syslog_facility;
char *syslog_ident;
- zend_bool have_called_openlog;
+ bool have_called_openlog;
zend_long syslog_filter;
};
diff --git a/main/php_ini.c b/main/php_ini.c
index 52e3a20ebf..0fa3a33365 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -117,7 +117,7 @@ PHPAPI ZEND_COLD void display_ini_entries(zend_module_entry *module)
{
int module_number;
zend_ini_entry *ini_entry;
- zend_bool first = 1;
+ bool first = 1;
if (module) {
module_number = module->module_number;
diff --git a/main/php_memory_streams.h b/main/php_memory_streams.h
index 5d0b978aad..030784e6f6 100644
--- a/main/php_memory_streams.h
+++ b/main/php_memory_streams.h
@@ -28,8 +28,8 @@
#define php_stream_memory_create(mode) _php_stream_memory_create((mode) STREAMS_CC)
#define php_stream_memory_create_rel(mode) _php_stream_memory_create((mode) STREAMS_REL_CC)
-#define php_stream_memory_open(mode, buf, length) _php_stream_memory_open((mode), (buf), (length) STREAMS_CC)
-#define php_stream_memory_get_buffer(stream, length) _php_stream_memory_get_buffer((stream), (length) STREAMS_CC)
+#define php_stream_memory_open(mode, str) _php_stream_memory_open((mode), (str) STREAMS_CC)
+#define php_stream_memory_get_buffer(stream) _php_stream_memory_get_buffer((stream) STREAMS_CC)
#define php_stream_temp_new() php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM)
#define php_stream_temp_create(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_CC)
@@ -40,8 +40,8 @@
BEGIN_EXTERN_C()
PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC);
-PHPAPI php_stream *_php_stream_memory_open(int mode, const char *buf, size_t length STREAMS_DC);
-PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC);
+PHPAPI php_stream *_php_stream_memory_open(int mode, zend_string *buf STREAMS_DC);
+PHPAPI zend_string *_php_stream_memory_get_buffer(php_stream *stream STREAMS_DC);
PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC);
PHPAPI php_stream *_php_stream_temp_create_ex(int mode, size_t max_memory_usage, const char *tmpdir STREAMS_DC);
diff --git a/main/php_network.h b/main/php_network.h
index 437069b4fc..5c8cee3fa8 100644
--- a/main/php_network.h
+++ b/main/php_network.h
@@ -49,6 +49,13 @@
# define EWOULDBLOCK EAGAIN
#endif
+/* This is a work around for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */
+#if EAGAIN != EWOULDBLOCK
+# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
+#else
+# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN)
+#endif
+
#ifdef PHP_WIN32
#define php_socket_errno() WSAGetLastError()
#else
diff --git a/main/php_output.h b/main/php_output.h
index eba63e6039..18f611dece 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -137,10 +137,9 @@ ZEND_BEGIN_MODULE_GLOBALS(output)
zend_stack handlers;
php_output_handler *active;
php_output_handler *running;
- const char *output_start_filename; /* TODO: Unused, remove */
+ zend_string *output_start_filename;
int output_start_lineno;
int flags;
- zend_string *output_start_filename_str;
ZEND_END_MODULE_GLOBALS(output)
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(output)
diff --git a/main/php_streams.h b/main/php_streams.h
index 6d6c73bb95..60be0a79eb 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -554,9 +554,6 @@ END_EXTERN_C()
/* Allow blocking reads on anonymous pipes on Windows. */
#define STREAM_USE_BLOCKING_PIPE 0x00008000
-/* Antique - no longer has meaning */
-#define IGNORE_URL_WIN 0
-
int php_init_stream_wrappers(int module_number);
int php_shutdown_stream_wrappers(int module_number);
void php_shutdown_stream_hashes(void);
diff --git a/main/php_variables.c b/main/php_variables.c
index 312c22ef07..4c284cacfb 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -62,7 +62,7 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
char *var, *var_orig;
size_t var_len, index_len;
zval gpc_element, *gpc_element_p;
- zend_bool is_array = 0;
+ bool is_array = 0;
HashTable *symtable1 = NULL;
ALLOCA_FLAG(use_heap)
@@ -276,7 +276,7 @@ typedef struct post_var_data {
size_t already_scanned;
} post_var_data_t;
-static zend_bool add_post_var(zval *arr, post_var_data_t *var, zend_bool eof)
+static bool add_post_var(zval *arr, post_var_data_t *var, bool eof)
{
char *start, *ksep, *vsep, *val;
size_t klen, vlen;
@@ -327,7 +327,7 @@ static zend_bool add_post_var(zval *arr, post_var_data_t *var, zend_bool eof)
return 1;
}
-static inline int add_post_vars(zval *arr, post_var_data_t *vars, zend_bool eof)
+static inline int add_post_vars(zval *arr, post_var_data_t *vars, bool eof)
{
uint64_t max_vars = PG(max_input_vars);
@@ -581,7 +581,7 @@ void _php_import_environment_variables(zval *array_ptr)
tsrm_env_unlock();
}
-zend_bool php_std_auto_global_callback(char *name, uint32_t name_len)
+bool php_std_auto_global_callback(char *name, uint32_t name_len)
{
zend_printf("%s\n", name);
return 0; /* don't rearm */
@@ -727,7 +727,7 @@ PHPAPI int php_hash_environment(void)
}
/* }}} */
-static zend_bool php_auto_globals_create_get(zend_string *name)
+static bool php_auto_globals_create_get(zend_string *name)
{
if (PG(variables_order) && (strchr(PG(variables_order),'G') || strchr(PG(variables_order),'g'))) {
sapi_module.treat_data(PARSE_GET, NULL, NULL);
@@ -742,7 +742,7 @@ static zend_bool php_auto_globals_create_get(zend_string *name)
return 0; /* don't rearm */
}
-static zend_bool php_auto_globals_create_post(zend_string *name)
+static bool php_auto_globals_create_post(zend_string *name)
{
if (PG(variables_order) &&
(strchr(PG(variables_order),'P') || strchr(PG(variables_order),'p')) &&
@@ -761,7 +761,7 @@ static zend_bool php_auto_globals_create_post(zend_string *name)
return 0; /* don't rearm */
}
-static zend_bool php_auto_globals_create_cookie(zend_string *name)
+static bool php_auto_globals_create_cookie(zend_string *name)
{
if (PG(variables_order) && (strchr(PG(variables_order),'C') || strchr(PG(variables_order),'c'))) {
sapi_module.treat_data(PARSE_COOKIE, NULL, NULL);
@@ -776,7 +776,7 @@ static zend_bool php_auto_globals_create_cookie(zend_string *name)
return 0; /* don't rearm */
}
-static zend_bool php_auto_globals_create_files(zend_string *name)
+static bool php_auto_globals_create_files(zend_string *name)
{
if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) == IS_UNDEF) {
array_init(&PG(http_globals)[TRACK_VARS_FILES]);
@@ -804,7 +804,7 @@ static void check_http_proxy(HashTable *var_table)
}
}
-static zend_bool php_auto_globals_create_server(zend_string *name)
+static bool php_auto_globals_create_server(zend_string *name)
{
if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
php_register_server_variables();
@@ -841,7 +841,7 @@ static zend_bool php_auto_globals_create_server(zend_string *name)
return 0; /* don't rearm */
}
-static zend_bool php_auto_globals_create_env(zend_string *name)
+static bool php_auto_globals_create_env(zend_string *name)
{
zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_ENV]);
array_init(&PG(http_globals)[TRACK_VARS_ENV]);
@@ -857,7 +857,7 @@ static zend_bool php_auto_globals_create_env(zend_string *name)
return 0; /* don't rearm */
}
-static zend_bool php_auto_globals_create_request(zend_string *name)
+static bool php_auto_globals_create_request(zend_string *name)
{
zval form_variables;
unsigned char _gpc_flags[3] = {0, 0, 0};
diff --git a/main/php_version.h b/main/php_version.h
index dd8b4b7b0b..66d4367856 100644
--- a/main/php_version.h
+++ b/main/php_version.h
@@ -1,8 +1,8 @@
/* automatically generated by configure */
/* edit configure.ac to change version number */
#define PHP_MAJOR_VERSION 8
-#define PHP_MINOR_VERSION 0
-#define PHP_RELEASE_VERSION 4
+#define PHP_MINOR_VERSION 1
+#define PHP_RELEASE_VERSION 0
#define PHP_EXTRA_VERSION "-dev"
-#define PHP_VERSION "8.0.4-dev"
-#define PHP_VERSION_ID 80004
+#define PHP_VERSION "8.1.0-dev"
+#define PHP_VERSION_ID 80100
diff --git a/main/rfc1867.c b/main/rfc1867.c
index c2f606c64a..f73aabdcba 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -52,7 +52,7 @@ static php_rfc1867_basename_t php_rfc1867_basename = NULL;
PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra) = NULL;
-static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, zend_bool override_protection);
+static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, bool override_protection);
/* The longest property name we use in an uploaded file array */
#define MAX_SIZE_OF_INDEX sizeof("[tmp_name]")
@@ -148,14 +148,14 @@ static void add_protected_variable(char *varname) /* {{{ */
}
/* }}} */
-static zend_bool is_protected_variable(char *varname) /* {{{ */
+static bool is_protected_variable(char *varname) /* {{{ */
{
normalize_protected_variable(varname);
return zend_hash_str_exists(&PG(rfc1867_protected_variables), varname, strlen(varname));
}
/* }}} */
-static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, zend_bool override_protection) /* {{{ */
+static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, bool override_protection) /* {{{ */
{
if (override_protection || !is_protected_variable(var)) {
php_register_variable_safe(var, strval, val_len, track_vars_array);
@@ -163,7 +163,7 @@ static void safe_php_register_variable(char *var, char *strval, size_t val_len,
}
/* }}} */
-static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars_array, zend_bool override_protection) /* {{{ */
+static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars_array, bool override_protection) /* {{{ */
{
if (override_protection || !is_protected_variable(var)) {
php_register_variable_ex(var, val, track_vars_array);
@@ -171,13 +171,13 @@ static void safe_php_register_variable_ex(char *var, zval *val, zval *track_vars
}
/* }}} */
-static void register_http_post_files_variable(char *strvar, char *val, zval *http_post_files, zend_bool override_protection) /* {{{ */
+static void register_http_post_files_variable(char *strvar, char *val, zval *http_post_files, bool override_protection) /* {{{ */
{
safe_php_register_variable(strvar, val, strlen(val), http_post_files, override_protection);
}
/* }}} */
-static void register_http_post_files_variable_ex(char *var, zval *val, zval *http_post_files, zend_bool override_protection) /* {{{ */
+static void register_http_post_files_variable_ex(char *var, zval *val, zval *http_post_files, bool override_protection) /* {{{ */
{
safe_php_register_variable_ex(var, val, http_post_files, override_protection);
}
diff --git a/main/spprintf.c b/main/spprintf.c
index 768a27470c..980294ea23 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -185,7 +185,7 @@ static size_t strnlen(const char *s, size_t maxlen) {
/*
* Do format conversion placing the output in buffer
*/
-static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt, va_list ap) /* {{{ */
+static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_list ap) /* {{{ */
{
char *s = NULL;
size_t s_len;
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 0def3b1a3d..36515b8543 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -33,10 +33,8 @@ PHPAPI size_t php_url_decode(char *str, size_t len);
/* {{{ ------- MEMORY stream implementation -------*/
typedef struct {
- char *data;
+ zend_string *data;
size_t fpos;
- size_t fsize;
- size_t smax;
int mode;
} php_stream_memory_data;
@@ -50,23 +48,16 @@ static ssize_t php_stream_memory_write(php_stream *stream, const char *buf, size
if (ms->mode & TEMP_STREAM_READONLY) {
return (ssize_t) -1;
} else if (ms->mode & TEMP_STREAM_APPEND) {
- ms->fpos = ms->fsize;
+ ms->fpos = ZSTR_LEN(ms->data);
}
- if (ms->fpos + count > ms->fsize) {
- char *tmp;
- if (!ms->data) {
- tmp = emalloc(ms->fpos + count);
- } else {
- tmp = erealloc(ms->data, ms->fpos + count);
- }
- ms->data = tmp;
- ms->fsize = ms->fpos + count;
+ if (ms->fpos + count > ZSTR_LEN(ms->data)) {
+ ms->data = zend_string_realloc(ms->data, ms->fpos + count, 0);
+ } else {
+ ms->data = zend_string_separate(ms->data, 0);
}
- if (!ms->data)
- count = 0;
if (count) {
- assert(buf!= NULL);
- memcpy(ms->data+ms->fpos, (char*)buf, count);
+ ZEND_ASSERT(buf != NULL);
+ memcpy(ZSTR_VAL(ms->data) + ms->fpos, (char*) buf, count);
ms->fpos += count;
}
return count;
@@ -80,17 +71,16 @@ static ssize_t php_stream_memory_read(php_stream *stream, char *buf, size_t coun
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
assert(ms != NULL);
- if (ms->fpos == ms->fsize) {
+ if (ms->fpos == ZSTR_LEN(ms->data)) {
stream->eof = 1;
count = 0;
} else {
- if (ms->fpos + count >= ms->fsize) {
- count = ms->fsize - ms->fpos;
+ if (ms->fpos + count > ZSTR_LEN(ms->data)) {
+ count = ZSTR_LEN(ms->data) - ms->fpos;
}
if (count) {
- assert(ms->data!= NULL);
- assert(buf!= NULL);
- memcpy(buf, ms->data+ms->fpos, count);
+ ZEND_ASSERT(buf != NULL);
+ memcpy(buf, ZSTR_VAL(ms->data) + ms->fpos, count);
ms->fpos += count;
}
}
@@ -103,11 +93,8 @@ static ssize_t php_stream_memory_read(php_stream *stream, char *buf, size_t coun
static int php_stream_memory_close(php_stream *stream, int close_handle)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
- assert(ms != NULL);
-
- if (ms->data && close_handle && ms->mode != TEMP_STREAM_READONLY) {
- efree(ms->data);
- }
+ ZEND_ASSERT(ms != NULL);
+ zend_string_release(ms->data);
efree(ms);
return 0;
}
@@ -143,8 +130,8 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
return 0;
}
} else {
- if (ms->fpos + (size_t)(offset) > ms->fsize) {
- ms->fpos = ms->fsize;
+ if (ms->fpos + (size_t)(offset) > ZSTR_LEN(ms->data)) {
+ ms->fpos = ZSTR_LEN(ms->data);
*newoffs = -1;
return -1;
} else {
@@ -155,8 +142,8 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
}
}
case SEEK_SET:
- if (ms->fsize < (size_t)(offset)) {
- ms->fpos = ms->fsize;
+ if (ZSTR_LEN(ms->data) < (size_t)(offset)) {
+ ms->fpos = ZSTR_LEN(ms->data);
*newoffs = -1;
return -1;
} else {
@@ -167,15 +154,15 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
}
case SEEK_END:
if (offset > 0) {
- ms->fpos = ms->fsize;
+ ms->fpos = ZSTR_LEN(ms->data);
*newoffs = -1;
return -1;
- } else if (ms->fsize < (size_t)(-offset)) {
+ } else if (ZSTR_LEN(ms->data) < (size_t)(-offset)) {
ms->fpos = 0;
*newoffs = -1;
return -1;
} else {
- ms->fpos = ms->fsize + offset;
+ ms->fpos = ZSTR_LEN(ms->data) + offset;
*newoffs = ms->fpos;
stream->eof = 0;
return 0;
@@ -205,7 +192,7 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) /
ssb->sb.st_mode = ms->mode & TEMP_STREAM_READONLY ? 0444 : 0666;
- ssb->sb.st_size = ms->fsize;
+ ssb->sb.st_size = ZSTR_LEN(ms->data);
ssb->sb.st_mode |= S_IFREG; /* regular file */
ssb->sb.st_mtime = timestamp;
ssb->sb.st_atime = timestamp;
@@ -242,16 +229,16 @@ static int php_stream_memory_set_option(php_stream *stream, int option, int valu
return PHP_STREAM_OPTION_RETURN_ERR;
}
newsize = *(size_t*)ptrparam;
- if (newsize <= ms->fsize) {
+ if (newsize <= ZSTR_LEN(ms->data)) {
+ ms->data = zend_string_truncate(ms->data, newsize, 0);
if (newsize < ms->fpos) {
ms->fpos = newsize;
}
} else {
- ms->data = erealloc(ms->data, newsize);
- memset(ms->data+ms->fsize, 0, newsize - ms->fsize);
- ms->fsize = newsize;
+ size_t old_size = ZSTR_LEN(ms->data);
+ ms->data = zend_string_realloc(ms->data, newsize, 0);
+ memset(ZSTR_VAL(ms->data) + old_size, 0, newsize - old_size);
}
- ms->fsize = newsize;
return PHP_STREAM_OPTION_RETURN_OK;
}
}
@@ -301,10 +288,8 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC)
php_stream *stream;
self = emalloc(sizeof(*self));
- self->data = NULL;
+ self->data = ZSTR_EMPTY_ALLOC();
self->fpos = 0;
- self->fsize = 0;
- self->smax = ~0u;
self->mode = mode;
stream = php_stream_alloc_rel(&php_stream_memory_ops, self, 0, _php_stream_mode_to_str(mode));
@@ -315,24 +300,14 @@ PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC)
/* {{{ */
-PHPAPI php_stream *_php_stream_memory_open(int mode, const char *buf, size_t length STREAMS_DC)
+PHPAPI php_stream *_php_stream_memory_open(int mode, zend_string *buf STREAMS_DC)
{
php_stream *stream;
php_stream_memory_data *ms;
if ((stream = php_stream_memory_create_rel(mode)) != NULL) {
ms = (php_stream_memory_data*)stream->abstract;
-
- if (mode == TEMP_STREAM_READONLY || mode == TEMP_STREAM_TAKE_BUFFER) {
- /* use the buffer directly */
- ms->data = (char *) buf;
- ms->fsize = length;
- } else {
- if (length) {
- assert(buf != NULL);
- php_stream_write(stream, buf, length);
- }
- }
+ ms->data = zend_string_copy(buf);
}
return stream;
}
@@ -340,14 +315,10 @@ PHPAPI php_stream *_php_stream_memory_open(int mode, const char *buf, size_t len
/* {{{ */
-PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC)
+PHPAPI zend_string *_php_stream_memory_get_buffer(php_stream *stream STREAMS_DC)
{
php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract;
-
- assert(ms != NULL);
- assert(length != 0);
-
- *length = ms->fsize;
+ ZEND_ASSERT(ms != NULL);
return ms->data;
}
/* }}} */
@@ -375,16 +346,15 @@ static ssize_t php_stream_temp_write(php_stream *stream, const char *buf, size_t
return -1;
}
if (php_stream_is(ts->innerstream, PHP_STREAM_IS_MEMORY)) {
- size_t memsize;
- char *membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize);
+ zend_string *membuf = php_stream_memory_get_buffer(ts->innerstream);
- if (memsize + count >= ts->smax) {
+ if (ZSTR_LEN(membuf) + count >= ts->smax) {
php_stream *file = php_stream_fopen_temporary_file(ts->tmpdir, "php", NULL);
if (file == NULL) {
php_error_docref(NULL, E_WARNING, "Unable to create temporary file, Check permissions in temporary files directory.");
return 0;
}
- php_stream_write(file, membuf, memsize);
+ php_stream_write(file, ZSTR_VAL(membuf), ZSTR_LEN(membuf));
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
ts->innerstream = file;
php_stream_encloses(stream, ts->innerstream);
@@ -479,8 +449,7 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret)
{
php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract;
php_stream *file;
- size_t memsize;
- char *membuf;
+ zend_string *membuf;
zend_off_t pos;
assert(ts != NULL);
@@ -513,8 +482,8 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret)
}
/* perform the conversion and then pass the request on to the innerstream */
- membuf = php_stream_memory_get_buffer(ts->innerstream, &memsize);
- php_stream_write(file, membuf, memsize);
+ membuf = php_stream_memory_get_buffer(ts->innerstream);
+ php_stream_write(file, ZSTR_VAL(membuf), ZSTR_LEN(membuf));
pos = php_stream_tell(ts->innerstream);
php_stream_free_enclosed(ts->innerstream, PHP_STREAM_FREE_CLOSE);
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index e3eda978d8..a63c225a0d 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -351,7 +351,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
ssize_t bytes_written = write(data->fd, buf, count);
#endif
if (bytes_written < 0) {
- if (errno == EWOULDBLOCK || errno == EAGAIN) {
+ if (PHP_IS_TRANSIENT_ERROR(errno)) {
return 0;
}
if (errno == EINTR) {
@@ -422,7 +422,7 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
}
if (ret < 0) {
- if (errno == EWOULDBLOCK || errno == EAGAIN) {
+ if (PHP_IS_TRANSIENT_ERROR(errno)) {
/* Not an error. */
ret = 0;
} else if (errno == EINTR) {
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 0e9059a99e..d9e864594c 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -310,7 +310,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
zval args[4];
int call_result;
php_stream *stream = NULL;
- zend_bool old_in_user_include;
+ bool old_in_user_include;
/* Try to catch bad usage without preventing flexibility */
if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) {
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index a369bf5ff2..e3ff3fe2ec 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -75,7 +75,8 @@ retry:
if (didwrite <= 0) {
char *estr;
int err = php_socket_errno();
- if (err == EWOULDBLOCK || err == EAGAIN) {
+
+ if (PHP_IS_TRANSIENT_ERROR(err)) {
if (sock->is_blocked) {
int retval;
@@ -169,7 +170,7 @@ static ssize_t php_sockop_read(php_stream *stream, char *buf, size_t count)
err = php_socket_errno();
if (nr_bytes < 0) {
- if (err == EAGAIN || err == EWOULDBLOCK) {
+ if (PHP_IS_TRANSIENT_ERROR(err)) {
nr_bytes = 0;
} else {
stream->eof = 1;
@@ -815,7 +816,7 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
php_stream_xport_param *xparam STREAMS_DC)
{
int clisock;
- zend_bool nodelay = 0;
+ bool nodelay = 0;
zval *tmpzval = NULL;
xparam->outputs.client = NULL;