mirror of
https://github.com/php/php-src.git
synced 2024-11-28 12:26:37 +08:00
Merge branch 'PHP-7.4'
This commit is contained in:
commit
c4a6998c62
@ -292,9 +292,6 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle)
|
||||
zend_llist_del_element(&CG(open_files), file_handle, (int (*)(void *, void *)) zend_compare_file_handles);
|
||||
/* zend_file_handle_dtor() operates on the copy, so we have to NULLify the original here */
|
||||
file_handle->opened_path = NULL;
|
||||
if (file_handle->free_filename) {
|
||||
file_handle->filename = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API void zend_lex_tstring(zval *zv)
|
||||
|
@ -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,17 +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;
|
||||
handle->free_filename = 0;
|
||||
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) /* {{{ */
|
||||
@ -134,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;
|
||||
|
||||
@ -155,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);
|
||||
@ -195,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);
|
||||
@ -211,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;
|
||||
} /* }}} */
|
||||
@ -245,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);
|
||||
}
|
||||
@ -261,9 +220,9 @@ 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->free_filename && fh->filename) {
|
||||
efree((char*)fh->filename);
|
||||
fh->filename = NULL;
|
||||
if (fh->buf) {
|
||||
efree(fh->buf);
|
||||
fh->buf = NULL;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@ -278,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;
|
||||
}
|
||||
|
@ -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,7 +56,8 @@ typedef struct _zend_file_handle {
|
||||
const char *filename;
|
||||
zend_string *opened_path;
|
||||
zend_stream_type type;
|
||||
zend_bool free_filename;
|
||||
char *buf;
|
||||
size_t len;
|
||||
} zend_file_handle;
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
|
@ -961,7 +961,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);
|
||||
|
||||
|
@ -3261,11 +3261,9 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type)
|
||||
efree(f.opened_path);
|
||||
}
|
||||
f.opened_path = file_handle->opened_path;
|
||||
f.free_filename = file_handle->free_filename;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -3289,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1554,17 +1554,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->free_filename = 0;
|
||||
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);
|
||||
|
@ -1313,7 +1313,6 @@ static int cli_main( int argc, char * argv[] )
|
||||
highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini);
|
||||
} else if (source_highlight == 2) {
|
||||
file_handle.filename = *p;
|
||||
file_handle.free_filename = 0;
|
||||
file_handle.opened_path = NULL;
|
||||
ret = php_lint_script(&file_handle);
|
||||
if (ret==SUCCESS) {
|
||||
@ -1324,7 +1323,6 @@ static int cli_main( int argc, char * argv[] )
|
||||
|
||||
} else {
|
||||
file_handle.filename = *p;
|
||||
file_handle.free_filename = 0;
|
||||
file_handle.opened_path = NULL;
|
||||
|
||||
php_execute_script(&file_handle);
|
||||
|
@ -294,10 +294,6 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
|
||||
zend_string_release(file->opened_path);
|
||||
file->opened_path = zend_string_init(filename, strlen(filename), 0);
|
||||
} else {
|
||||
if (file->free_filename) {
|
||||
efree((char *) file->filename);
|
||||
}
|
||||
file->free_filename = 0;
|
||||
file->filename = filename;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user