summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-07-16 17:17:19 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-07-16 17:44:32 +0200
commitb317f0eb59eb1265cbc7ed3eb00f757e2ff65e4d (patch)
treee97d72be1c9a148d1b32a0c94450bc9f119133ad
parente0eca262852dba1a78afcde64a49126c81fead1a (diff)
downloadphp-git-b317f0eb59eb1265cbc7ed3eb00f757e2ff65e4d.tar.gz
Remove ZEND_HANDLE_MAPPED
The buf/len members are now simply used in addition to the main stream, without changing the handle kind.
-rw-r--r--Zend/zend_stream.c111
-rw-r--r--Zend/zend_stream.h13
-rw-r--r--ext/opcache/ZendAccelerator.c1
-rw-r--r--ext/phar/phar.c2
-rw-r--r--main/main.c7
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c3
6 files changed, 42 insertions, 95 deletions
diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c
index 9e81e3acab..0360c38b34 100644
--- a/Zend/zend_stream.c
+++ b/Zend/zend_stream.c
@@ -51,35 +51,11 @@ static size_t zend_stream_stdio_fsizer(void *handle) /* {{{ */
return 0;
} /* }}} */
-static void zend_stream_unmap(zend_stream *stream) { /* {{{ */
- if (stream->mmap.buf) {
- efree(stream->mmap.buf);
- }
- stream->mmap.len = 0;
- stream->mmap.buf = 0;
- stream->handle = stream->mmap.old_handle;
-} /* }}} */
-
-static void zend_stream_mmap_closer(zend_stream *stream) /* {{{ */
-{
- zend_stream_unmap(stream);
- if (stream->mmap.old_closer && stream->handle) {
- stream->mmap.old_closer(stream->handle);
- }
-} /* }}} */
-
-static inline int zend_stream_is_mmap(zend_file_handle *file_handle) { /* {{{ */
- return file_handle->type == ZEND_HANDLE_MAPPED;
-} /* }}} */
-
static size_t zend_stream_fsize(zend_file_handle *file_handle) /* {{{ */
{
zend_stat_t buf;
- if (zend_stream_is_mmap(file_handle)) {
- return file_handle->handle.stream.mmap.len;
- }
- if (file_handle->type == ZEND_HANDLE_STREAM || file_handle->type == ZEND_HANDLE_MAPPED) {
+ if (file_handle->type == ZEND_HANDLE_STREAM) {
return file_handle->handle.stream.fsizer(file_handle->handle.stream.handle);
}
if (file_handle->handle.fp && zend_fstat(fileno(file_handle->handle.fp), &buf) == 0) {
@@ -109,16 +85,14 @@ ZEND_API void zend_stream_init_filename(zend_file_handle *handle, const char *fi
ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle) /* {{{ */
{
+ zend_string *opened_path;
if (zend_stream_open_function) {
return zend_stream_open_function(filename, handle);
}
- handle->type = ZEND_HANDLE_FP;
- handle->opened_path = NULL;
- handle->handle.fp = zend_fopen(filename, &handle->opened_path);
- handle->filename = filename;
- memset(&handle->handle.stream.mmap, 0, sizeof(zend_mmap));
- return (handle->handle.fp) ? SUCCESS : FAILURE;
+ zend_stream_init_fp(handle, zend_fopen(filename, &opened_path), filename);
+ handle->opened_path = opened_path;
+ return handle->handle.fp ? SUCCESS : FAILURE;
} /* }}} */
static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
@@ -133,7 +107,7 @@ static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
static size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len) /* {{{ */
{
- if (!zend_stream_is_mmap(file_handle) && file_handle->handle.stream.isatty) {
+ if (file_handle->handle.stream.isatty) {
int c = '*';
size_t n;
@@ -154,35 +128,29 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
size_t size;
zend_stream_type old_type;
+ if (file_handle->buf) {
+ *buf = file_handle->buf;
+ *len = file_handle->len;
+ return SUCCESS;
+ }
+
if (file_handle->type == ZEND_HANDLE_FILENAME) {
if (zend_stream_open(file_handle->filename, file_handle) == FAILURE) {
return FAILURE;
}
}
- switch (file_handle->type) {
- case ZEND_HANDLE_FP:
- if (!file_handle->handle.fp) {
- return FAILURE;
- }
- memset(&file_handle->handle.stream.mmap, 0, sizeof(zend_mmap));
- file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle));
- file_handle->handle.stream.reader = (zend_stream_reader_t)zend_stream_stdio_reader;
- file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_stdio_closer;
- file_handle->handle.stream.fsizer = (zend_stream_fsizer_t)zend_stream_stdio_fsizer;
- memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap));
- /* no break; */
- case ZEND_HANDLE_STREAM:
- /* nothing to do */
- break;
-
- case ZEND_HANDLE_MAPPED:
- *buf = file_handle->handle.stream.mmap.buf;
- *len = file_handle->handle.stream.mmap.len;
- return SUCCESS;
-
- default:
+ if (file_handle->type == ZEND_HANDLE_FP) {
+ if (!file_handle->handle.fp) {
return FAILURE;
+ }
+
+ file_handle->type = ZEND_HANDLE_STREAM;
+ file_handle->handle.stream.handle = file_handle->handle.fp;
+ file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle));
+ file_handle->handle.stream.reader = (zend_stream_reader_t)zend_stream_stdio_reader;
+ file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_stdio_closer;
+ file_handle->handle.stream.fsizer = (zend_stream_fsizer_t)zend_stream_stdio_fsizer;
}
size = zend_stream_fsize(file_handle);
@@ -194,8 +162,8 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
file_handle->type = ZEND_HANDLE_STREAM; /* we might still be _FP but we need fsize() work */
if (old_type == ZEND_HANDLE_FP && !file_handle->handle.stream.isatty && size) {
- file_handle->handle.stream.mmap.buf = *buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
- file_handle->handle.stream.mmap.len = zend_stream_read(file_handle, *buf, size);
+ file_handle->buf = *buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
+ file_handle->len = zend_stream_read(file_handle, *buf, size);
} else {
size_t read, remain = 4*1024;
*buf = emalloc(remain);
@@ -210,29 +178,22 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
remain = size;
}
}
- file_handle->handle.stream.mmap.len = size;
+ file_handle->len = size;
if (size && remain < ZEND_MMAP_AHEAD) {
*buf = safe_erealloc(*buf, size, 1, ZEND_MMAP_AHEAD);
}
- file_handle->handle.stream.mmap.buf = *buf;
+ file_handle->buf = *buf;
}
- if (file_handle->handle.stream.mmap.len == 0) {
+ if (file_handle->len == 0) {
*buf = erealloc(*buf, ZEND_MMAP_AHEAD);
- file_handle->handle.stream.mmap.buf = *buf;
+ file_handle->buf = *buf;
}
- if (ZEND_MMAP_AHEAD) {
- memset(file_handle->handle.stream.mmap.buf + file_handle->handle.stream.mmap.len, 0, ZEND_MMAP_AHEAD);
- }
- file_handle->type = ZEND_HANDLE_MAPPED;
- file_handle->handle.stream.mmap.old_handle = file_handle->handle.stream.handle;
- file_handle->handle.stream.mmap.old_closer = file_handle->handle.stream.closer;
- file_handle->handle.stream.handle = &file_handle->handle.stream;
- file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_mmap_closer;
+ memset(file_handle->buf + file_handle->len, 0, ZEND_MMAP_AHEAD);
- *buf = file_handle->handle.stream.mmap.buf;
- *len = file_handle->handle.stream.mmap.len;
+ *buf = file_handle->buf;
+ *len = file_handle->len;
return SUCCESS;
} /* }}} */
@@ -244,7 +205,6 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
fclose(fh->handle.fp);
break;
case ZEND_HANDLE_STREAM:
- case ZEND_HANDLE_MAPPED:
if (fh->handle.stream.closer && fh->handle.stream.handle) {
fh->handle.stream.closer(fh->handle.stream.handle);
}
@@ -260,6 +220,10 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
zend_string_release_ex(fh->opened_path, 0);
fh->opened_path = NULL;
}
+ if (fh->buf) {
+ efree(fh->buf);
+ fh->buf = NULL;
+ }
}
/* }}} */
@@ -273,11 +237,6 @@ ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *
return fh1->handle.fp == fh2->handle.fp;
case ZEND_HANDLE_STREAM:
return fh1->handle.stream.handle == fh2->handle.stream.handle;
- case ZEND_HANDLE_MAPPED:
- return (fh1->handle.stream.handle == &fh1->handle.stream &&
- fh2->handle.stream.handle == &fh2->handle.stream &&
- fh1->handle.stream.mmap.old_handle == fh2->handle.stream.mmap.old_handle)
- || fh1->handle.stream.handle == fh2->handle.stream.handle;
default:
return 0;
}
diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h
index a554bb884c..87aec7aff3 100644
--- a/Zend/zend_stream.h
+++ b/Zend/zend_stream.h
@@ -37,21 +37,12 @@ typedef void (*zend_stream_closer_t)(void* handle);
typedef enum {
ZEND_HANDLE_FILENAME,
ZEND_HANDLE_FP,
- ZEND_HANDLE_STREAM,
- ZEND_HANDLE_MAPPED
+ ZEND_HANDLE_STREAM
} zend_stream_type;
-typedef struct _zend_mmap {
- size_t len;
- char *buf;
- void *old_handle;
- zend_stream_closer_t old_closer;
-} zend_mmap;
-
typedef struct _zend_stream {
void *handle;
int isatty;
- zend_mmap mmap;
zend_stream_reader_t reader;
zend_stream_fsizer_t fsizer;
zend_stream_closer_t closer;
@@ -65,6 +56,8 @@ typedef struct _zend_file_handle {
const char *filename;
zend_string *opened_path;
zend_stream_type type;
+ char *buf;
+ size_t len;
} zend_file_handle;
BEGIN_EXTERN_C()
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index cc57637642..6fe08d6faa 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -970,7 +970,6 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_
}
break;
case ZEND_HANDLE_FILENAME:
- case ZEND_HANDLE_MAPPED:
if (file_handle->opened_path) {
char *file_path = ZSTR_VAL(file_handle->opened_path);
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 8da3c364e1..db81b14d8e 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -3264,7 +3264,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type)
switch (file_handle->type) {
case ZEND_HANDLE_STREAM:
- case ZEND_HANDLE_MAPPED:
if (file_handle->handle.stream.closer && file_handle->handle.stream.handle) {
file_handle->handle.stream.closer(file_handle->handle.stream.handle);
}
@@ -3288,7 +3287,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type)
phar->is_persistent ?
php_stream_rewind(PHAR_G(cached_fp)[phar->phar_pos].fp) :
php_stream_rewind(phar->fp);
- memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap));
}
}
}
diff --git a/main/main.c b/main/main.c
index d3eae3c148..8b1ad1df2e 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1580,16 +1580,17 @@ static int php_stream_open_for_zend(const char *filename, zend_file_handle *hand
PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode) /* {{{ */
{
- php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
-
+ zend_string *opened_path;
+ php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &opened_path);
if (stream) {
+ memset(handle, 0, sizeof(zend_file_handle));
handle->type = ZEND_HANDLE_STREAM;
handle->filename = (char*)filename;
+ handle->opened_path = opened_path;
handle->handle.stream.handle = stream;
handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
handle->handle.stream.fsizer = php_zend_stream_fsizer;
handle->handle.stream.isatty = 0;
- memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
handle->handle.stream.closer = php_zend_stream_closer;
/* suppress warning if this stream is not explicitly closed */
php_stream_auto_cleanup(stream);
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index fc7a9b4290..24155a7860 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -577,9 +577,6 @@ int phpdbg_compile(void) /* {{{ */
if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS && zend_stream_fixup(&fh, &buf, &len) == SUCCESS) {
CG(skip_shebang) = 1;
PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE);
-
- fh.handle.stream.mmap.buf = buf;
- fh.handle.stream.mmap.len = len;
zend_destroy_file_handle(&fh);
if (EG(exception)) {
zend_exception_error(EG(exception), E_ERROR);