Skip to content

Commit 2eaee8b

Browse files
committed
send uncompress value and proper set compressed flags when errors
1 parent d4dbc2b commit 2eaee8b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

php_memcached.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ int php_memc_list_entry(void)
107107
#define MEMC_VAL_COMPRESSION_ZLIB (1<<1)
108108
#define MEMC_VAL_COMPRESSION_FASTLZ (1<<2)
109109

110-
#define MEMC_VAL_GET_FLAGS(internal_flags) ((internal_flags & MEMC_MASK_INTERNAL) >> 4)
111-
#define MEMC_VAL_SET_FLAG(internal_flags, internal_flag) ((internal_flags) |= ((internal_flag << 4) & MEMC_MASK_INTERNAL))
112-
#define MEMC_VAL_HAS_FLAG(internal_flags, internal_flag) ((MEMC_VAL_GET_FLAGS(internal_flags) & internal_flag) == internal_flag)
113-
#define MEMC_VAL_DEL_FLAG(internal_flags, internal_flag) internal_flags &= ~((internal_flag << 4) & MEMC_MASK_INTERNAL)
110+
#define MEMC_VAL_GET_FLAGS(internal_flags) (((internal_flags) & MEMC_MASK_INTERNAL) >> 4)
111+
#define MEMC_VAL_SET_FLAG(internal_flags, internal_flag) ((internal_flags) |= (((internal_flag) << 4) & MEMC_MASK_INTERNAL))
112+
#define MEMC_VAL_HAS_FLAG(internal_flags, internal_flag) ((MEMC_VAL_GET_FLAGS(internal_flags) & (internal_flag)) == (internal_flag))
113+
#define MEMC_VAL_DEL_FLAG(internal_flags, internal_flag) (internal_flags &= (~(((internal_flag) << 4) & MEMC_MASK_INTERNAL)))
114114

115115
/****************************************
116116
User-defined flags
@@ -822,7 +822,7 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str
822822

823823
if (compressed_size > 0) {
824824
compress_status = 1;
825-
MEMC_VAL_SET_FLAG(*flags, MEMC_VAL_COMPRESSION_FASTLZ);
825+
MEMC_VAL_SET_FLAG(*flags, MEMC_VAL_COMPRESSED | MEMC_VAL_COMPRESSION_FASTLZ);
826826
}
827827
}
828828
break;
@@ -834,7 +834,7 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str
834834

835835
if (status == Z_OK) {
836836
compress_status = 1;
837-
MEMC_VAL_SET_FLAG(*flags, MEMC_VAL_COMPRESSION_ZLIB);
837+
MEMC_VAL_SET_FLAG(*flags, MEMC_VAL_COMPRESSED | MEMC_VAL_COMPRESSION_ZLIB);
838838
}
839839
}
840840
break;
@@ -846,14 +846,14 @@ zend_bool s_compress_value (php_memc_compression_type compression_type, zend_str
846846

847847
if (!compress_status) {
848848
php_error_docref(NULL, E_WARNING, "could not compress value");
849-
MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSED);
849+
MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSED | MEMC_VAL_COMPRESSION_FASTLZ | MEMC_VAL_COMPRESSION_ZLIB);
850850
efree (buffer);
851851
return 0;
852852
}
853853

854854
/* This means the value was too small to be compressed, still a success */
855855
if (payload->len < (compressed_size * MEMC_G(compression_factor))) {
856-
MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSED);
856+
MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSED | MEMC_VAL_COMPRESSION_FASTLZ | MEMC_VAL_COMPRESSION_ZLIB);
857857
efree (buffer);
858858
return 1;
859859
}
@@ -1017,12 +1017,7 @@ zend_string *s_zval_to_payload(php_memc_object_t *intern, zval *value, uint32_t
10171017

10181018
/* If we have compression flag, compress the value */
10191019
if (should_compress) {
1020-
/* status */
1021-
if (!s_compress_value (memc_user_data->compression_type, &payload, flags)) {
1022-
zend_string_release(payload);
1023-
return NULL;
1024-
}
1025-
MEMC_VAL_SET_FLAG(*flags, MEMC_VAL_COMPRESSED);
1020+
s_compress_value (memc_user_data->compression_type, &payload, flags);
10261021
}
10271022

10281023
if (memc_user_data->set_udf_flags >= 0) {

0 commit comments

Comments
 (0)