diff options
-rw-r--r-- | ext/standard/image.c | 19 | ||||
-rw-r--r-- | ext/zlib/tests/gzclose_basic.phpt | 4 | ||||
-rw-r--r-- | ext/zlib/tests/gzeof_variation1.phpt | 4 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 66 | ||||
-rw-r--r-- | ext/zlib/zlib_filter.c | 41 |
5 files changed, 65 insertions, 69 deletions
diff --git a/ext/standard/image.c b/ext/standard/image.c index 8b51688bd6..4dcfe83e38 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -202,11 +202,12 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) long bits; unsigned char a[64]; unsigned long len=64, szlength; - int factor=1,maxfactor=16; - int slength, status=0; - char *b, *buf=NULL, *bufz=NULL; + int factor = 1,maxfactor = 16; + int status = 0; + char *b, *buf = NULL; + zend_string *bufz; - b = ecalloc (1, len + 1); + b = ecalloc(1, len + 1); if (php_stream_seek(stream, 5, SEEK_CUR)) return NULL; @@ -219,7 +220,7 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) if (php_stream_seek(stream, 8, SEEK_SET)) return NULL; - slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0); + bufz = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); /* * zlib::uncompress() wants to know the output data length @@ -230,13 +231,13 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) */ do { - szlength=slength*(1<<factor++); - buf = (char *) erealloc(buf,szlength); - status = uncompress(buf, &szlength, bufz, slength); + szlength = bufz->len * (1<<factor++); + buf = (char *) erealloc(buf, szlength); + status = uncompress(buf, &szlength, bufz->val, bufz->len); } while ((status==Z_BUF_ERROR)&&(factor<maxfactor)); if (bufz) { - pefree(bufz, 0); + STR_RELEASE(bufz); } if (status == Z_OK) { diff --git a/ext/zlib/tests/gzclose_basic.phpt b/ext/zlib/tests/gzclose_basic.phpt index d61855bf9f..acad3b2f07 100644 --- a/ext/zlib/tests/gzclose_basic.phpt +++ b/ext/zlib/tests/gzclose_basic.phpt @@ -32,8 +32,8 @@ gzread($h, 20); --EXPECTF-- bool(true) -Warning: gzread(): %d is not a valid stream resource in %s on line %d +Warning: gzread(): supplied resource is not a valid stream resource in %s on line %d bool(true) -Warning: gzread(): %d is not a valid stream resource in %s on line %d +Warning: gzread(): supplied resource is not a valid stream resource in %s on line %d ===DONE=== diff --git a/ext/zlib/tests/gzeof_variation1.phpt b/ext/zlib/tests/gzeof_variation1.phpt index 77a1eccb66..ba0d8e5932 100644 --- a/ext/zlib/tests/gzeof_variation1.phpt +++ b/ext/zlib/tests/gzeof_variation1.phpt @@ -26,6 +26,6 @@ unlink($filename); bool(false) bool(false) -Warning: gzeof(): %d is not a valid stream resource in %s on line %d +Warning: gzeof(): supplied resource is not a valid stream resource in %s on line %d bool(false) -===DONE===
\ No newline at end of file +===DONE=== diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 3753f98a67..c38d6eca2c 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -67,15 +67,18 @@ static int php_zlib_output_conflict_check(const char *handler_name, size_t handl /* {{{ php_zlib_output_encoding() */ static int php_zlib_output_encoding(TSRMLS_D) { - zval **enc; + zval *enc; if (!ZLIBG(compression_coding)) { - zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); - if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) { - convert_to_string(*enc); - if (strstr(Z_STRVAL_PP(enc), "gzip")) { + zend_string *name = STR_INIT("_SERVER", sizeof("_SERVER") - 1, 0); + zend_is_auto_global(name TSRMLS_CC); + STR_RELEASE(name); + if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && + (enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) { + convert_to_string(enc); + if (strstr(Z_STRVAL_P(enc), "gzip")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP; - } else if (strstr(Z_STRVAL_PP(enc), "deflate")) { + } else if (strstr(Z_STRVAL_P(enc), "deflate")) { ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE; } } @@ -276,7 +279,7 @@ static php_output_handler *php_zlib_output_handler_init(const char *handler_name /* {{{ php_zlib_output_compression_start() */ static void php_zlib_output_compression_start(TSRMLS_D) { - zval *zoh; + zval zoh; php_output_handler *h; switch (ZLIBG(output_compression)) { @@ -290,9 +293,8 @@ static void php_zlib_output_compression_start(TSRMLS_D) (h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) && (SUCCESS == php_output_handler_start(h TSRMLS_CC))) { if (ZLIBG(output_handler) && *ZLIBG(output_handler)) { - MAKE_STD_ZVAL(zoh); - ZVAL_STRING(zoh, ZLIBG(output_handler), 1); - php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); + ZVAL_STRING(&zoh, ZLIBG(output_handler)); + php_output_start_user(&zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC); zval_ptr_dtor(&zoh); } } @@ -302,42 +304,39 @@ static void php_zlib_output_compression_start(TSRMLS_D) /* }}} */ /* {{{ php_zlib_encode() */ -static int php_zlib_encode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, int level TSRMLS_DC) +static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encoding, int level TSRMLS_DC) { int status; z_stream Z; + zend_string *out; memset(&Z, 0, sizeof(z_stream)); Z.zalloc = php_zlib_alloc; Z.zfree = php_zlib_free; if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) { - *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len); - *out_buf = emalloc(*out_len); + out = STR_ALLOC(PHP_ZLIB_BUFFER_SIZE_GUESS(in_len), 0); Z.next_in = (Bytef *) in_buf; - Z.next_out = (Bytef *) *out_buf; + Z.next_out = (Bytef *) out->val; Z.avail_in = in_len; - Z.avail_out = *out_len; + Z.avail_out = out->len; status = deflate(&Z, Z_FINISH); deflateEnd(&Z); if (Z_STREAM_END == status) { /* size buffer down to actual length */ - *out_buf = erealloc(*out_buf, Z.total_out + 1); - (*out_buf)[*out_len = Z.total_out] = '\0'; - return SUCCESS; + out = STR_REALLOC(out, Z.total_out, 0); + out->val[out->len] = '\0'; + return out; } else { - efree(*out_buf); + STR_FREE(out); } } - *out_buf = NULL; - *out_len = 0; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status)); - return FAILURE; + return NULL; } /* }}} */ @@ -501,7 +500,7 @@ static PHP_FUNCTION(ob_gzhandler) } if (ctx.out.data) { - RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1); + RETVAL_STRINGL(ctx.out.data, ctx.out.used); if (ctx.out.free) { efree(ctx.out.data); } @@ -520,9 +519,9 @@ static PHP_FUNCTION(zlib_get_coding_type) } switch (ZLIBG(compression_coding)) { case PHP_ZLIB_ENCODING_GZIP: - RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1); + RETURN_STRINGL("gzip", sizeof("gzip") - 1); case PHP_ZLIB_ENCODING_DEFLATE: - RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1); + RETURN_STRINGL("deflate", sizeof("deflate") - 1); default: RETURN_FALSE; } @@ -631,17 +630,15 @@ static PHP_FUNCTION(readgzfile) #define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \ static PHP_FUNCTION(name) \ { \ - char *in_buf, *out_buf; \ - int in_len; \ - size_t out_len; \ + zend_string *in, *out; \ long level = -1; \ long encoding = default_encoding; \ if (default_encoding) { \ - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &in_buf, &in_len, &level, &encoding)) { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ll", &in, &level, &encoding)) { \ return; \ } \ } else { \ - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \ + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl|l", &in, &encoding, &level)) { \ return; \ } \ } \ @@ -658,10 +655,10 @@ static PHP_FUNCTION(name) \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \ RETURN_FALSE; \ } \ - if (SUCCESS != php_zlib_encode(in_buf, in_len, &out_buf, &out_len, encoding, level TSRMLS_CC)) { \ + if ((out = php_zlib_encode(in->val, in->len, encoding, level TSRMLS_CC)) == NULL) { \ RETURN_FALSE; \ } \ - RETURN_STRINGL(out_buf, out_len, 0); \ + RETURN_STR(out); \ } #define PHP_ZLIB_DECODE_FUNC(name, encoding) \ @@ -681,7 +678,8 @@ static PHP_FUNCTION(name) \ if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \ RETURN_FALSE; \ } \ - RETURN_STRINGL(out_buf, out_len, 0); \ + RETVAL_STRINGL(out_buf, out_len); \ + efree(out_buf); \ } /* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1]) diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 9a59c3a855..17f141b06c 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -66,12 +66,12 @@ static php_stream_filter_status_t php_zlib_inflate_filter( int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; - if (!thisfilter || !thisfilter->abstract) { + if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } - data = (php_zlib_filter_data *)(thisfilter->abstract); + data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; @@ -156,8 +156,8 @@ static php_stream_filter_status_t php_zlib_inflate_filter( static void php_zlib_inflate_dtor(php_stream_filter *thisfilter TSRMLS_DC) { - if (thisfilter && thisfilter->abstract) { - php_zlib_filter_data *data = thisfilter->abstract; + if (thisfilter && Z_PTR(thisfilter->abstract)) { + php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); if (!data->finished) { inflateEnd(&(data->strm)); } @@ -191,12 +191,12 @@ static php_stream_filter_status_t php_zlib_deflate_filter( int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; - if (!thisfilter || !thisfilter->abstract) { + if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } - data = (php_zlib_filter_data *)(thisfilter->abstract); + data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; @@ -265,8 +265,8 @@ static php_stream_filter_status_t php_zlib_deflate_filter( static void php_zlib_deflate_dtor(php_stream_filter *thisfilter TSRMLS_DC) { - if (thisfilter && thisfilter->abstract) { - php_zlib_filter_data *data = thisfilter->abstract; + if (thisfilter && Z_PTR(thisfilter->abstract)) { + php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); deflateEnd(&(data->strm)); pefree(data->inbuf, data->persistent); pefree(data->outbuf, data->persistent); @@ -324,15 +324,14 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f int windowBits = -MAX_WBITS; if (filterparams) { - zval **tmpzval; + zval *tmpzval; if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) && - zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void **) &tmpzval) == SUCCESS) { + (tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { zval tmp; /* log-2 base of history window (9 - 15) */ - tmp = **tmpzval; - zval_copy_ctor(&tmp); + ZVAL_DUP(&tmp, tmpzval); convert_to_long(&tmp); if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 32) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp)); @@ -354,7 +353,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f if (filterparams) { - zval **tmpzval, tmp; + zval *tmpzval, tmp; /* filterparams can either be a scalar value to indicate compression level (shortcut method) Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ @@ -362,9 +361,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f switch (Z_TYPE_P(filterparams)) { case IS_ARRAY: case IS_OBJECT: - if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; - zval_copy_ctor(&tmp); + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "memory", sizeof("memory") -1))) { + ZVAL_DUP(&tmp, tmpzval); convert_to_long(&tmp); /* Memory Level (1 - 9) */ @@ -375,9 +373,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f } } - if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; - zval_copy_ctor(&tmp); + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { + ZVAL_DUP(&tmp, tmpzval); convert_to_long(&tmp); /* log-2 base of history window (9 - 15) */ @@ -388,8 +385,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f } } - if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) { - tmp = **tmpzval; + if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "level", sizeof("level") - 1))) { + ZVAL_COPY_VALUE(&tmp, tmpzval); /* Psuedo pass through to catch level validating code */ goto factory_setlevel; @@ -398,7 +395,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_STRING: case IS_DOUBLE: case IS_LONG: - tmp = *filterparams; + ZVAL_COPY_VALUE(&tmp, filterparams); factory_setlevel: zval_copy_ctor(&tmp); convert_to_long(&tmp); |