Skip to content

Commit db6d93f

Browse files
committed
Remove some more unnecessary macros from phar
1 parent e6b2283 commit db6d93f

File tree

6 files changed

+30
-45
lines changed

6 files changed

+30
-45
lines changed

ext/phar/phar.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, int fname_len, char *a
16391639

16401640
php_stream_filter_append(&temp->writefilters, filter);
16411641

1642-
if (SUCCESS != phar_stream_copy_to_stream(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1642+
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
16431643
if (err) {
16441644
php_stream_close(temp);
16451645
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\", ext/zlib is buggy in PHP versions older than 5.2.6")
@@ -1681,7 +1681,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, int fname_len, char *a
16811681

16821682
php_stream_filter_append(&temp->writefilters, filter);
16831683

1684-
if (SUCCESS != phar_stream_copy_to_stream(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1684+
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
16851685
php_stream_close(temp);
16861686
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file")
16871687
}
@@ -2677,7 +2677,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert,
26772677
size_t written;
26782678

26792679
if (!user_stub && phar->halt_offset && oldfile && !phar->is_brandnew) {
2680-
phar_stream_copy_to_stream(oldfile, newfile, phar->halt_offset, &written);
2680+
php_stream_copy_to_stream_ex(oldfile, newfile, phar->halt_offset, &written);
26812681
newstub = NULL;
26822682
} else {
26832683
/* this is either a brand new phar or a default stub overwrite */
@@ -2865,7 +2865,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert,
28652865
return EOF;
28662866
}
28672867
php_stream_filter_append((&entry->cfp->writefilters), filter);
2868-
if (SUCCESS != phar_stream_copy_to_stream(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
2868+
if (SUCCESS != php_stream_copy_to_stream_ex(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
28692869
if (closeoldfile) {
28702870
php_stream_close(oldfile);
28712871
}
@@ -3097,7 +3097,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert,
30973097
/* this will have changed for all files that have either changed compression or been modified */
30983098
entry->offset = entry->offset_abs = offset;
30993099
offset += entry->compressed_filesize;
3100-
if (phar_stream_copy_to_stream(file, newfile, entry->compressed_filesize, &wrote) == FAILURE) {
3100+
if (php_stream_copy_to_stream_ex(file, newfile, entry->compressed_filesize, &wrote) == FAILURE) {
31013101
if (closeoldfile) {
31023102
php_stream_close(oldfile);
31033103
}
@@ -3243,7 +3243,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert,
32433243
}
32443244

32453245
php_stream_filter_append(&phar->fp->writefilters, filter);
3246-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
3246+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
32473247
php_stream_filter_flush(filter, 1);
32483248
php_stream_filter_remove(filter, 1 TSRMLS_CC);
32493249
php_stream_close(phar->fp);
@@ -3252,14 +3252,14 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert,
32523252
} else if (phar->flags & PHAR_FILE_COMPRESSED_BZ2) {
32533253
filter = php_stream_filter_create("bzip2.compress", NULL, php_stream_is_persistent(phar->fp) TSRMLS_CC);
32543254
php_stream_filter_append(&phar->fp->writefilters, filter);
3255-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
3255+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
32563256
php_stream_filter_flush(filter, 1);
32573257
php_stream_filter_remove(filter, 1 TSRMLS_CC);
32583258
php_stream_close(phar->fp);
32593259
/* use the temp stream as our base */
32603260
phar->fp = newfile;
32613261
} else {
3262-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
3262+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
32633263
/* we could also reopen the file in "rb" mode but there is no need for that */
32643264
php_stream_close(newfile);
32653265
}

ext/phar/phar_internal.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@
6868
#include "ext/hash/php_hash_sha.h"
6969
#endif
7070

71-
#ifndef E_RECOVERABLE_ERROR
72-
# define E_RECOVERABLE_ERROR E_ERROR
73-
#endif
74-
75-
#ifndef pestrndup
76-
# define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
77-
#endif
78-
79-
#ifndef ALLOC_PERMANENT_ZVAL
80-
# define ALLOC_PERMANENT_ZVAL(z) \
81-
(z) = (zval*)malloc(sizeof(zval))
82-
#endif
83-
8471
/* PHP_ because this is public information via MINFO */
8572
#define PHP_PHAR_API_VERSION "1.1.1"
8673
/* x.y.z maps to 0xyz0 */
@@ -516,8 +503,6 @@ union _phar_entry_object {
516503
extern char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
517504
#endif
518505

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)
520-
521506
BEGIN_EXTERN_C()
522507

523508
#ifdef PHP_WIN32

ext/phar/phar_object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{
17071707
data->internal_file->fp_type = PHAR_UFP;
17081708
data->internal_file->offset_abs = data->internal_file->offset = php_stream_tell(p_obj->fp);
17091709
data->fp = NULL;
1710-
phar_stream_copy_to_stream(fp, p_obj->fp, PHP_STREAM_COPY_ALL, &contents_len);
1710+
php_stream_copy_to_stream_ex(fp, p_obj->fp, PHP_STREAM_COPY_ALL, &contents_len);
17111711
data->internal_file->uncompressed_filesize = data->internal_file->compressed_filesize =
17121712
php_stream_tell(p_obj->fp) - data->internal_file->offset;
17131713
}
@@ -1997,7 +1997,7 @@ static int phar_copy_file_contents(phar_entry_info *entry, php_stream *fp TSRMLS
19971997
link = entry;
19981998
}
19991999

2000-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
2000+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0 TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
20012001
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
20022002
"Cannot convert phar archive \"%s\", unable to copy entry \"%s\" contents", entry->phar->fname, entry->filename);
20032003
return FAILURE;
@@ -3651,7 +3651,7 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, int filenam
36513651
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s could not be written to", filename);
36523652
return;
36533653
}
3654-
phar_stream_copy_to_stream(contents_file, data->fp, PHP_STREAM_COPY_ALL, &contents_len);
3654+
php_stream_copy_to_stream_ex(contents_file, data->fp, PHP_STREAM_COPY_ALL, &contents_len);
36553655
}
36563656

36573657
data->internal_file->compressed_filesize = data->internal_file->uncompressed_filesize = contents_len;
@@ -4224,7 +4224,7 @@ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char *
42244224
return FAILURE;
42254225
}
42264226

4227-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), fp, entry->uncompressed_filesize, NULL)) {
4227+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0 TSRMLS_CC), fp, entry->uncompressed_filesize, NULL)) {
42284228
spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", copying contents failed", entry->filename, fullpath);
42294229
efree(fullpath);
42304230
php_stream_close(fp);

ext/phar/tar.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ static int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC) /* {{{ *
783783
return ZEND_HASH_APPLY_STOP;
784784
}
785785

786-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), fp->new, entry->uncompressed_filesize, NULL)) {
786+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0 TSRMLS_CC), fp->new, entry->uncompressed_filesize, NULL)) {
787787
if (fp->error) {
788788
spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, contents of file \"%s\" could not be written", entry->phar->fname, entry->filename);
789789
}
@@ -1288,7 +1288,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau
12881288

12891289
if (!filter) {
12901290
/* copy contents uncompressed rather than lose them */
1291-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
1291+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
12921292
php_stream_close(newfile);
12931293
if (error) {
12941294
spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname);
@@ -1297,7 +1297,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau
12971297
}
12981298

12991299
php_stream_filter_append(&phar->fp->writefilters, filter);
1300-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
1300+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
13011301
php_stream_filter_flush(filter, 1);
13021302
php_stream_filter_remove(filter, 1 TSRMLS_CC);
13031303
php_stream_close(phar->fp);
@@ -1308,14 +1308,14 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau
13081308

13091309
filter = php_stream_filter_create("bzip2.compress", NULL, php_stream_is_persistent(phar->fp) TSRMLS_CC);
13101310
php_stream_filter_append(&phar->fp->writefilters, filter);
1311-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
1311+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
13121312
php_stream_filter_flush(filter, 1);
13131313
php_stream_filter_remove(filter, 1 TSRMLS_CC);
13141314
php_stream_close(phar->fp);
13151315
/* use the temp stream as our base */
13161316
phar->fp = newfile;
13171317
} else {
1318-
phar_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
1318+
php_stream_copy_to_stream_ex(newfile, phar->fp, PHP_STREAM_COPY_ALL, NULL);
13191319
/* we could also reopen the file in "rb" mode but there is no need for that */
13201320
php_stream_close(newfile);
13211321
}

ext/phar/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **er
678678
link = source;
679679
}
680680

681-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
681+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
682682
php_stream_close(dest->fp);
683683
dest->fp_type = PHAR_FP;
684684
if (error) {
@@ -780,7 +780,7 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS
780780
php_stream_seek(phar_get_entrypfp(entry TSRMLS_CC), phar_get_fp_offset(entry TSRMLS_CC), SEEK_SET);
781781

782782
if (entry->uncompressed_filesize) {
783-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_entrypfp(entry TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
783+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_entrypfp(entry TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
784784
spprintf(error, 4096, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, entry->filename);
785785
php_stream_filter_remove(filter, 1 TSRMLS_CC);
786786
return FAILURE;
@@ -886,7 +886,7 @@ int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{
886886
link = entry;
887887
}
888888

889-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
889+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0 TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
890890
if (error) {
891891
spprintf(error, 4096, "phar error: cannot separate entry file \"%s\" contents in phar archive \"%s\" for write access", entry->filename, entry->phar->fname);
892892
}

ext/phar/zip.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias,
417417

418418
php_stream_seek(fp, 0, SEEK_SET);
419419
/* copy file contents + local headers and zip comment, if any, to be hashed for signature */
420-
phar_stream_copy_to_stream(fp, sigfile, entry.header_offset, NULL);
420+
php_stream_copy_to_stream_ex(fp, sigfile, entry.header_offset, NULL);
421421
/* seek to central directory */
422422
php_stream_seek(fp, PHAR_GET_32(locator.cdir_offset), SEEK_SET);
423423
/* copy central directory header */
424-
phar_stream_copy_to_stream(fp, sigfile, beforeus - PHAR_GET_32(locator.cdir_offset), NULL);
424+
php_stream_copy_to_stream_ex(fp, sigfile, beforeus - PHAR_GET_32(locator.cdir_offset), NULL);
425425
if (metadata) {
426426
php_stream_write(sigfile, metadata, PHAR_GET_16(locator.comment_len));
427427
}
@@ -905,7 +905,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */
905905

906906
php_stream_filter_append((&entry->cfp->writefilters), filter);
907907

908-
if (SUCCESS != phar_stream_copy_to_stream(efp, entry->cfp, entry->uncompressed_filesize, NULL)) {
908+
if (SUCCESS != php_stream_copy_to_stream_ex(efp, entry->cfp, entry->uncompressed_filesize, NULL)) {
909909
spprintf(p->error, 0, "unable to copy compressed file contents of file \"%s\" while creating new phar \"%s\"", entry->filename, entry->phar->fname);
910910
return ZEND_HASH_APPLY_STOP;
911911
}
@@ -1010,7 +1010,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */
10101010

10111011
if (!not_really_modified && entry->is_modified) {
10121012
if (entry->cfp) {
1013-
if (SUCCESS != phar_stream_copy_to_stream(entry->cfp, p->filefp, entry->compressed_filesize, NULL)) {
1013+
if (SUCCESS != php_stream_copy_to_stream_ex(entry->cfp, p->filefp, entry->compressed_filesize, NULL)) {
10141014
spprintf(p->error, 0, "unable to write compressed contents of file \"%s\" in zip-based phar \"%s\"", entry->filename, entry->phar->fname);
10151015
return ZEND_HASH_APPLY_STOP;
10161016
}
@@ -1024,7 +1024,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */
10241024

10251025
phar_seek_efp(entry, 0, SEEK_SET, 0, 0 TSRMLS_CC);
10261026

1027-
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), p->filefp, entry->uncompressed_filesize, NULL)) {
1027+
if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0 TSRMLS_CC), p->filefp, entry->uncompressed_filesize, NULL)) {
10281028
spprintf(p->error, 0, "unable to write contents of file \"%s\" in zip-based phar \"%s\"", entry->filename, entry->phar->fname);
10291029
return ZEND_HASH_APPLY_STOP;
10301030
}
@@ -1050,7 +1050,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */
10501050
}
10511051
}
10521052

1053-
if (!entry->is_dir && entry->compressed_filesize && SUCCESS != phar_stream_copy_to_stream(p->old, p->filefp, entry->compressed_filesize, NULL)) {
1053+
if (!entry->is_dir && entry->compressed_filesize && SUCCESS != php_stream_copy_to_stream_ex(p->old, p->filefp, entry->compressed_filesize, NULL)) {
10541054
spprintf(p->error, 0, "unable to copy contents of file \"%s\" while creating zip-based phar \"%s\"", entry->filename, entry->phar->fname);
10551055
return ZEND_HASH_APPLY_STOP;
10561056
}
@@ -1093,10 +1093,10 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas
10931093
st = tell = php_stream_tell(pass->filefp);
10941094
/* copy the local files, central directory, and the zip comment to generate the hash */
10951095
php_stream_seek(pass->filefp, 0, SEEK_SET);
1096-
phar_stream_copy_to_stream(pass->filefp, newfile, tell, NULL);
1096+
php_stream_copy_to_stream_ex(pass->filefp, newfile, tell, NULL);
10971097
tell = php_stream_tell(pass->centralfp);
10981098
php_stream_seek(pass->centralfp, 0, SEEK_SET);
1099-
phar_stream_copy_to_stream(pass->centralfp, newfile, tell, NULL);
1099+
php_stream_copy_to_stream_ex(pass->centralfp, newfile, tell, NULL);
11001100
if (metadata->c) {
11011101
php_stream_write(newfile, metadata->c, metadata->len);
11021102
}
@@ -1431,7 +1431,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau
14311431

14321432
{
14331433
size_t clen;
1434-
int ret = phar_stream_copy_to_stream(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL, &clen);
1434+
int ret = php_stream_copy_to_stream_ex(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL, &clen);
14351435
if (SUCCESS != ret || clen != cdir_size) {
14361436
if (error) {
14371437
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);
@@ -1501,7 +1501,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau
15011501
return EOF;
15021502
}
15031503
php_stream_rewind(pass.filefp);
1504-
phar_stream_copy_to_stream(pass.filefp, phar->fp, PHP_STREAM_COPY_ALL, NULL);
1504+
php_stream_copy_to_stream_ex(pass.filefp, phar->fp, PHP_STREAM_COPY_ALL, NULL);
15051505
/* we could also reopen the file in "rb" mode but there is no need for that */
15061506
php_stream_close(pass.filefp);
15071507
}

0 commit comments

Comments
 (0)