Skip to content

Commit ccb7e3b

Browse files
committed
More testing of user flags
1 parent 5bde0d1 commit ccb7e3b

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

php_memcached.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ typedef unsigned long int uint32_t;
151151
****************************************/
152152
#define MEMC_VAL_GET_USER_FLAGS(flags) ((flags & MEMC_MASK_USER) >> 16)
153153
#define MEMC_VAL_SET_USER_FLAGS(flags, udf_flags) ((flags) |= ((udf_flags << 16) & MEMC_MASK_USER))
154-
#define MEMC_VAL_USER_FLAGS_MAX (MEMC_MASK_USER >> 16)
154+
#define MEMC_VAL_USER_FLAGS_MAX ((1 << 16) - 1)
155155

156156
/****************************************
157157
"get" operation flags
@@ -1256,8 +1256,8 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
12561256
i_obj->rescode = MEMCACHED_SUCCESS;
12571257

12581258
/*
1259-
* php_memcached uses 8 bits internally to store type, compression and serialization info.
1260-
* We use 8 upper bits to store user defined flags.
1259+
* php_memcached uses 16 bits internally to store type, compression and serialization info.
1260+
* We use 16 upper bits to store user defined flags.
12611261
*/
12621262
if (udf_flags > 0) {
12631263
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) {
@@ -1465,8 +1465,8 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
14651465
}
14661466

14671467
/*
1468-
* php_memcached uses 8 bits internally to store type, compression and serialization info.
1469-
* We use 8 upper bits to store user defined flags.
1468+
* php_memcached uses 16 bits internally to store type, compression and serialization info.
1469+
* We use 16 upper bits to store user defined flags.
14701470
*/
14711471
if (udf_flags > 0) {
14721472
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) {
@@ -1608,8 +1608,8 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
16081608
}
16091609

16101610
/*
1611-
* php_memcached uses 8 bits internally to store type, compression and serialization info.
1612-
* We use 8 upper bits to store user defined flags.
1611+
* php_memcached uses 16 bits internally to store type, compression and serialization info.
1612+
* We use 16 upper bits to store user defined flags.
16131613
*/
16141614
if (udf_flags > 0) {
16151615
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) {

tests/user-flags.phpt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ function check_flag ($flags, $flag)
1313
define ('FLAG_1', 1);
1414
define ('FLAG_2', 2);
1515
define ('FLAG_4', 4);
16-
16+
define ('FLAG_32', 32);
17+
define ('FLAG_64', 64);
18+
define ('FLAG_TOO_LARGE', pow(2, 16));
1719
$x = 0;
1820

1921
$m = new Memcached();
@@ -24,33 +26,34 @@ $key = uniqid ('udf_test_');
2426

2527
echo "stored with flags" . PHP_EOL;
2628

27-
$m->set ($key, '1', 10, FLAG_1 | FLAG_4);
29+
$m->set ($key, '1', 10, FLAG_1 | FLAG_4 | FLAG_64);
2830
$udf_flags = 0;
2931
$value = $m->get ($key, null, $x, $udf_flags);
3032

3133
var_dump (check_flag ($udf_flags, FLAG_1));
3234
var_dump (check_flag ($udf_flags, FLAG_2));
3335
var_dump (check_flag ($udf_flags, FLAG_4));
34-
36+
var_dump (check_flag ($udf_flags, FLAG_32));
37+
var_dump (check_flag ($udf_flags, FLAG_64));
3538

3639
echo "stored without flags" . PHP_EOL;
3740
$m->set ($key, '1');
3841
$value = $m->get ($key, null, $x, $udf_flags);
3942

40-
var_dump (check_flag ($udf_flags, FLAG_1));
41-
var_dump (check_flag ($udf_flags, FLAG_2));
42-
var_dump (check_flag ($udf_flags, FLAG_4));
43-
43+
var_dump ($udf_flags == 0);
44+
$m->set ($key, '1', 10, FLAG_TOO_LARGE);
4445

4546
echo "DONE TEST\n";
4647
?>
47-
--EXPECT--
48+
--EXPECTF--
4849
stored with flags
4950
bool(true)
5051
bool(false)
5152
bool(true)
52-
stored without flags
53-
bool(false)
54-
bool(false)
5553
bool(false)
54+
bool(true)
55+
stored without flags
56+
bool(true)
57+
58+
Warning: Memcached::set(): udf_flags will be limited to 65535 in %s on line %d
5659
DONE TEST

0 commit comments

Comments
 (0)