Skip to content

Commit 62b1293

Browse files
committed
Fix Z_BLOCK breakage when built against zlib < 1.2.4
1 parent fbd1f1f commit 62b1293

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

ext/zlib/tests/deflate_add_basic.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ $flushTypes = [
4141
'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH,
4242
'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH,
4343
'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH,
44-
'ZLIB_BLOCK' => ZLIB_BLOCK,
4544
];
4645

46+
/* Z_BLOCK is only defined when built against zlib > 1.2.3 */
47+
if (defined(ZLIB_BLOCK)) {
48+
$flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK;
49+
}
50+
4751
foreach ($modes as $modeKey => $mode) {
4852
foreach ($flushSizes as $flushSize) {
4953
foreach ($flushTypes as $flushTypeKey => $flushType) {

ext/zlib/tests/inflate_add_basic.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ $flushTypes = [
4040
'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH,
4141
'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH,
4242
'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH,
43-
'ZLIB_BLOCK' => ZLIB_BLOCK,
4443
];
4544

45+
/* Z_BLOCK is only defined when built against zlib > 1.2.3 */
46+
if (defined(ZLIB_BLOCK)) {
47+
$flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK;
48+
}
49+
4650
$uncompressed = "";
4751
for ($i=0;$i<(32768*2);$i++) {
4852
$uncompressed .= chr(rand(48,125));

ext/zlib/zlib.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#undef gzseek
4747
#undef gztell
4848

49+
/* Z_BLOCK was added in zlib 1.2.4 and stable distros (RHEL6, at least) still
50+
* package zlib 1.2.3
51+
*/
52+
#ifdef Z_BLOCK
53+
#define HAVE_Z_BLOCK 1
54+
#endif
55+
4956
int le_deflate;
5057
int le_inflate;
5158

@@ -814,7 +821,9 @@ PHP_FUNCTION(inflate_add)
814821
case Z_PARTIAL_FLUSH:
815822
case Z_SYNC_FLUSH:
816823
case Z_FULL_FLUSH:
824+
#ifdef HAVE_Z_BLOCK
817825
case Z_BLOCK:
826+
#endif
818827
case Z_FINISH:
819828
break;
820829

@@ -960,7 +969,9 @@ PHP_FUNCTION(deflate_add)
960969
case Z_PARTIAL_FLUSH:
961970
case Z_SYNC_FLUSH:
962971
case Z_FULL_FLUSH:
972+
#ifdef HAVE_Z_BLOCK
963973
case Z_BLOCK:
974+
#endif
964975
case Z_FINISH:
965976
break;
966977

@@ -1268,7 +1279,9 @@ static PHP_MINIT_FUNCTION(zlib)
12681279
REGISTER_LONG_CONSTANT("ZLIB_PARTIAL_FLUSH", Z_PARTIAL_FLUSH, CONST_CS|CONST_PERSISTENT);
12691280
REGISTER_LONG_CONSTANT("ZLIB_SYNC_FLUSH", Z_SYNC_FLUSH, CONST_CS|CONST_PERSISTENT);
12701281
REGISTER_LONG_CONSTANT("ZLIB_FULL_FLUSH", Z_FULL_FLUSH, CONST_CS|CONST_PERSISTENT);
1282+
#ifdef HAVE_Z_BLOCK
12711283
REGISTER_LONG_CONSTANT("ZLIB_BLOCK", Z_BLOCK, CONST_CS|CONST_PERSISTENT);
1284+
#endif
12721285
REGISTER_LONG_CONSTANT("ZLIB_FINISH", Z_FINISH, CONST_CS|CONST_PERSISTENT);
12731286
REGISTER_INI_ENTRIES();
12741287
return SUCCESS;

0 commit comments

Comments
 (0)