Skip to content

Commit 39bd738

Browse files
committed
Remove version checks in phar
No need to keep around compatability code for PHP 5.0 and PHP 6.
1 parent 91a9569 commit 39bd738

File tree

6 files changed

+2
-538
lines changed

6 files changed

+2
-538
lines changed

ext/phar/phar.c

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
static void destroy_phar_data(void *pDest);
2828

2929
ZEND_DECLARE_MODULE_GLOBALS(phar)
30-
#if PHP_VERSION_ID >= 50300
3130
char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
32-
#endif
3331

3432
/**
3533
* set's phar->is_writeable based on the current INI value
@@ -3319,31 +3317,17 @@ static size_t phar_zend_stream_reader(void *handle, char *buf, size_t len TSRMLS
33193317
}
33203318
/* }}} */
33213319

3322-
#if PHP_VERSION_ID >= 50300
33233320
static size_t phar_zend_stream_fsizer(void *handle TSRMLS_DC) /* {{{ */
33243321
{
33253322
return ((phar_archive_data*)handle)->halt_offset + 32;
33263323
} /* }}} */
33273324

3328-
#else /* PHP_VERSION_ID */
3329-
3330-
static long phar_stream_fteller_for_zend(void *handle TSRMLS_DC) /* {{{ */
3331-
{
3332-
return (long)php_stream_tell(phar_get_pharfp((phar_archive_data*)handle TSRMLS_CC));
3333-
}
3334-
/* }}} */
3335-
#endif
3336-
33373325
zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
3338-
#if PHP_VERSION_ID >= 50300
33393326
#define phar_orig_zend_open zend_stream_open_function
33403327
static char *phar_resolve_path(const char *filename, int filename_len TSRMLS_DC)
33413328
{
33423329
return phar_find_in_include_path((char *) filename, filename_len, NULL TSRMLS_CC);
33433330
}
3344-
#else
3345-
int (*phar_orig_zend_open)(const char *filename, zend_file_handle *handle TSRMLS_DC);
3346-
#endif
33473331

33483332
static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */
33493333
{
@@ -3376,7 +3360,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
33763360
}
33773361
} else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) {
33783362
/* compressed phar */
3379-
#if PHP_VERSION_ID >= 50300
33803363
file_handle->type = ZEND_HANDLE_STREAM;
33813364
/* we do our own reading directly from the phar, don't change the next line */
33823365
file_handle->handle.stream.handle = phar;
@@ -3388,18 +3371,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
33883371
php_stream_rewind(PHAR_GLOBALS->cached_fp[phar->phar_pos].fp) :
33893372
php_stream_rewind(phar->fp);
33903373
memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap));
3391-
#else /* PHP_VERSION_ID */
3392-
file_handle->type = ZEND_HANDLE_STREAM;
3393-
/* we do our own reading directly from the phar, don't change the next line */
3394-
file_handle->handle.stream.handle = phar;
3395-
file_handle->handle.stream.reader = phar_zend_stream_reader;
3396-
file_handle->handle.stream.closer = NULL; /* don't close - let phar handle this one */
3397-
file_handle->handle.stream.fteller = phar_stream_fteller_for_zend;
3398-
file_handle->handle.stream.interactive = 0;
3399-
phar->is_persistent ?
3400-
php_stream_rewind(PHAR_GLOBALS->cached_fp[phar->phar_pos].fp) :
3401-
php_stream_rewind(phar->fp);
3402-
#endif
34033374
}
34043375
}
34053376
}
@@ -3424,60 +3395,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
34243395
}
34253396
/* }}} */
34263397

3427-
#if PHP_VERSION_ID < 50300
3428-
int phar_zend_open(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
3429-
{
3430-
char *arch, *entry;
3431-
int arch_len, entry_len;
3432-
3433-
/* this code is obsoleted in php 5.3 */
3434-
entry = (char *) filename;
3435-
if (!IS_ABSOLUTE_PATH(entry, strlen(entry)) && !strstr(entry, "://")) {
3436-
phar_archive_data **pphar = NULL;
3437-
char *fname;
3438-
int fname_len;
3439-
3440-
fname = (char*)zend_get_executed_filename(TSRMLS_C);
3441-
fname_len = strlen(fname);
3442-
3443-
if (fname_len > 7 && !strncasecmp(fname, "phar://", 7)) {
3444-
if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) {
3445-
zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar);
3446-
if (!pphar && PHAR_G(manifest_cached)) {
3447-
zend_hash_find(&cached_phars, arch, arch_len, (void **) &pphar);
3448-
}
3449-
efree(arch);
3450-
efree(entry);
3451-
}
3452-
}
3453-
3454-
/* retrieving an include within the current directory, so use this if possible */
3455-
if (!(entry = phar_find_in_include_path((char *) filename, strlen(filename), NULL TSRMLS_CC))) {
3456-
/* this file is not in the phar, use the original path */
3457-
goto skip_phar;
3458-
}
3459-
3460-
if (SUCCESS == phar_orig_zend_open(entry, handle TSRMLS_CC)) {
3461-
if (!handle->opened_path) {
3462-
handle->opened_path = entry;
3463-
}
3464-
if (entry != filename) {
3465-
handle->free_filename = 1;
3466-
}
3467-
return SUCCESS;
3468-
}
3469-
3470-
if (entry != filename) {
3471-
efree(entry);
3472-
}
3473-
3474-
return FAILURE;
3475-
}
3476-
skip_phar:
3477-
return phar_orig_zend_open(filename, handle TSRMLS_CC);
3478-
}
3479-
/* }}} */
3480-
#endif
34813398
typedef zend_op_array* (zend_compile_t)(zend_file_handle*, int TSRMLS_DC);
34823399
typedef zend_compile_t* (compile_hook)(zend_compile_t *ptr);
34833400

@@ -3554,13 +3471,8 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */
35543471
phar_orig_compile_file = zend_compile_file;
35553472
zend_compile_file = phar_compile_file;
35563473

3557-
#if PHP_VERSION_ID >= 50300
35583474
phar_save_resolve_path = zend_resolve_path;
35593475
zend_resolve_path = phar_resolve_path;
3560-
#else
3561-
phar_orig_zend_open = zend_stream_open_function;
3562-
zend_stream_open_function = phar_zend_open;
3563-
#endif
35643476

35653477
phar_object_init(TSRMLS_C);
35663478

@@ -3581,11 +3493,6 @@ PHP_MSHUTDOWN_FUNCTION(phar) /* {{{ */
35813493
zend_compile_file = phar_orig_compile_file;
35823494
}
35833495

3584-
#if PHP_VERSION_ID < 50300
3585-
if (zend_stream_open_function == phar_zend_open) {
3586-
zend_stream_open_function = phar_orig_zend_open;
3587-
}
3588-
#endif
35893496
if (PHAR_G(manifest_cached)) {
35903497
zend_hash_destroy(&(cached_phars));
35913498
zend_hash_destroy(&(cached_alias));

ext/phar/phar_internal.h

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -513,76 +513,17 @@ union _phar_entry_object {
513513
#endif
514514

515515
#ifndef PHAR_MAIN
516-
# if PHP_VERSION_ID >= 50300
517516
extern char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
518-
# endif
519-
#endif
520-
521-
#if PHP_VERSION_ID < 50209
522-
static inline size_t phar_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC)
523-
{
524-
size_t ret = php_stream_copy_to_stream(src, dest, maxlen);
525-
if (len) {
526-
*len = ret;
527-
}
528-
if (ret) {
529-
return SUCCESS;
530-
}
531-
return FAILURE;
532-
}
533-
#else
534-
# define phar_stream_copy_to_stream(src, dest, maxlen, len) _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC)
535-
536517
#endif
537518

538-
#if PHP_VERSION_ID >= 60000
539-
typedef zstr phar_zstr;
540-
#define PHAR_STR(a, b) \
541-
spprintf(&b, 0, "%s", a.s);
542-
#define PHAR_ZSTR(a, b) \
543-
b = ZSTR(a);
544-
#define PHAR_STR_FREE(a) \
545-
efree(a);
546-
static inline int phar_make_unicode(zstr *c_var, char *arKey, uint nKeyLength TSRMLS_DC)
547-
{
548-
int c_var_len;
549-
UConverter *conv = ZEND_U_CONVERTER(UG(runtime_encoding_conv));
519+
#define phar_stream_copy_to_stream(src, dest, maxlen, len) _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC)
550520

551-
c_var->u = NULL;
552-
if (zend_string_to_unicode(conv, &c_var->u, &c_var_len, arKey, nKeyLength TSRMLS_CC) == FAILURE) {
553-
554-
if (c_var->u) {
555-
efree(c_var->u);
556-
}
557-
return 0;
558-
559-
}
560-
return c_var_len;
561-
}
562-
static inline int phar_find_key(HashTable *_SERVER, char *key, int len, void **stuff TSRMLS_DC)
563-
{
564-
if (SUCCESS == zend_hash_find(_SERVER, key, len, stuff)) {
565-
return 1;
566-
} else {
567-
int s = len;
568-
zstr var;
569-
s = phar_make_unicode(&var, key, len TSRMLS_CC);
570-
if (SUCCESS == zend_u_hash_find(_SERVER, IS_UNICODE, var, s, stuff)) {
571-
efree(var.u);
572-
return 1;
573-
}
574-
efree(var.u);
575-
return 0;
576-
}
577-
}
578-
#else
579521
typedef char *phar_zstr;
580522
#define PHAR_STR(a, b) \
581523
b = a;
582524
#define PHAR_ZSTR(a, b) \
583525
b = a;
584526
#define PHAR_STR_FREE(a)
585-
#endif
586527

587528
BEGIN_EXTERN_C()
588529

0 commit comments

Comments
 (0)