From e3b2a46f2bf4e19d768bfd00e9cee66231bef33a Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:29:27 +0200 Subject: [PATCH 01/17] fix warning: variable 'redis_inst' set but not used [-Wunused-but-set-variable] --- redis_array.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/redis_array.c b/redis_array.c index 93e843c2bc..55f3e76da3 100644 --- a/redis_array.c +++ b/redis_array.c @@ -715,7 +715,7 @@ PHP_METHOD(RedisArray, mget) int *pos, argc, *argc_each; HashTable *h_keys; HashPosition pointer; - zval **redis_instances, *redis_inst, **argv; + zval **redis_instances, **argv; /* Multi/exec support */ HANDLE_MULTI_EXEC("MGET"); @@ -771,8 +771,6 @@ PHP_METHOD(RedisArray, mget) /* calls */ for(n = 0; n < ra->count; ++n) { /* for each node */ - redis_inst = ra->redis[n]; - /* copy args for MGET call on node. */ MAKE_STD_ZVAL(z_argarray); array_init(z_argarray); From 83053eabc2da73d57df0b5ebccc86f40f2f0bcfd Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:36:26 +0200 Subject: [PATCH 02/17] warning: variable 'redis_inst' set but not used (compiler can't check logic here) --- redis_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis_array.c b/redis_array.c index 55f3e76da3..7964c8189b 100644 --- a/redis_array.c +++ b/redis_array.c @@ -264,7 +264,7 @@ static void ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, int cmd_len, zval *z_args, zval *z_new_target) { zval **zp_tmp, z_tmp; - char *key; + char *key = NULL; // set to avoid "unused-but-set-variable" int key_len; int i; zval *redis_inst; From 0d725ed8c1b166f52af9a7fa1bf739b951a2158e Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:41:00 +0200 Subject: [PATCH 03/17] redis.c:2350:17: warning: variable 'type' set but not used --- redis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redis.c b/redis.c index df59a529fc..67e352a846 100755 --- a/redis.c +++ b/redis.c @@ -2347,10 +2347,9 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword char *key; unsigned int key_len; unsigned long idx; - int type; zval **z_value_pp; - type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL); + zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL); if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) { continue; /* this should never happen, according to the PHP people. */ } From 297d83e10706f665202b217e1bb658299fc3b642 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:43:32 +0200 Subject: [PATCH 04/17] redis.c:2394:7: warning: variable 'nb_keys' set but not used --- redis.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/redis.c b/redis.c index 67e352a846..7dfac0bf6d 100755 --- a/redis.c +++ b/redis.c @@ -2391,12 +2391,7 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword real_argc++; } } else { - int nb_keys; - if(!has_timeout) { - nb_keys = argc; - } else if(has_timeout && Z_TYPE_P(z_args[argc - 1]) == IS_LONG) { - nb_keys = argc - 1; - } else { + if(has_timeout && Z_TYPE_P(z_args[argc - 1]) != IS_LONG) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Syntax error on timeout"); } From 518599f8e1ef53824a56083bc19b12cc7aa59c29 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:45:10 +0200 Subject: [PATCH 05/17] redis.c:2273:11: warning: variable 'object' set but not used --- redis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redis.c b/redis.c index 7dfac0bf6d..79ec6e5c2e 100755 --- a/redis.c +++ b/redis.c @@ -2270,7 +2270,7 @@ PHP_METHOD(Redis, sMembers) PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_len, int min_argc, RedisSock **out_sock, int has_timeout, int all_keys, int can_serialize) { - zval *object, **z_args, *z_array; + zval **z_args, *z_array; char **keys, *cmd; int cmd_len, *keys_len, *keys_to_free; int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0; @@ -2459,7 +2459,6 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword if(z_args) efree(z_args); - object = getThis(); /* cmd[cmd_len] = 0; php_printf("cmd=[%s]\n", cmd); From fa9bfeb9f1185f26cf2763975e3aa8a1780f3608 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:46:32 +0200 Subject: [PATCH 06/17] redis.c:2699:25: warning: variable 'type' set but not used --- redis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redis.c b/redis.c index 79ec6e5c2e..4f8781adee 100755 --- a/redis.c +++ b/redis.c @@ -2696,10 +2696,9 @@ PHP_METHOD(Redis, sort) { char *key; unsigned int key_len; unsigned long idx; - int type; zval **z_value_pp; - type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL); + zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL); if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) { continue; /* this should never happen, according to the PHP people. */ } From fa282646e2d4d997e5459ab8c7b2f9ad01cee46d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:48:59 +0200 Subject: [PATCH 07/17] redis.c:4652:13: warning: variable 'type' set but not used --- redis.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/redis.c b/redis.c index 4f8781adee..e122a3dfd9 100755 --- a/redis.c +++ b/redis.c @@ -4649,10 +4649,9 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int unsigned int tablekey_len; int hkey_len, hval_len; unsigned long idx; - int type; zval **z_key_pp, **z_value_pp; - type = zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL); + zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL); if(zend_hash_get_current_data(keytable, (void**)&z_key_pp) == FAILURE) { continue; /* this should never happen, according to the PHP people. */ } @@ -4666,7 +4665,7 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int zend_hash_move_forward(keytable); /* fetch again */ - type = zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL); + zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL); if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) { continue; /* this should never happen, according to the PHP people. */ } From eccffe52bacd391d26936176feea73225a8eff6c Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:50:30 +0200 Subject: [PATCH 08/17] redis.c:4650:23: warning: variable 'hval_len' set but not used --- redis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redis.c b/redis.c index e122a3dfd9..dc80878eb4 100755 --- a/redis.c +++ b/redis.c @@ -4647,7 +4647,7 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int char *tablekey, *hkey, *hval; unsigned int tablekey_len; - int hkey_len, hval_len; + int hkey_len; unsigned long idx; zval **z_key_pp, **z_value_pp; @@ -4672,7 +4672,6 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int /* get current value, a hash value now. */ hval = Z_STRVAL_PP(z_value_pp); - hval_len = Z_STRLEN_PP(z_value_pp); if(use_atof) { /* zipping a score */ add_assoc_double_ex(z_ret, hkey, 1+hkey_len, atof(hval)); From 1defd423a58065904822184ac1197dec260759d2 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 07:58:02 +0200 Subject: [PATCH 09/17] redis.c:5414:23: warning: 'ce' may be used uninitialized in this function (please REVIEW this one) --- redis.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redis.c b/redis.c index dc80878eb4..c46424e665 100755 --- a/redis.c +++ b/redis.c @@ -5291,7 +5291,6 @@ PHP_METHOD(Redis, subscribe) int callback_type; zval *z_o, *z_fun,*z_ret, *z_args[3]; char *method_name; - zend_class_entry *ce; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oaz|z", &object, redis_ce, &array, &z_callback) == FAILURE) { @@ -5411,7 +5410,7 @@ PHP_METHOD(Redis, subscribe) switch(callback_type) { case R_SUB_CALLBACK_CLASS_TYPE: MAKE_STD_ZVAL(z_ret); - call_user_function(&ce->function_table, &z_o, z_fun, z_ret, 3, z_args TSRMLS_CC); + call_user_function(&redis_ce->function_table, &z_o, z_fun, z_ret, 3, z_args TSRMLS_CC); efree(z_ret); break; From 31b38401dcc28c6fb5ec8f8e26dd0f7d5aa912e5 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 08:02:06 +0200 Subject: [PATCH 10/17] redis.c:5413:23: warning: 'z_fun' may be used uninitialized in this function --- redis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis.c b/redis.c index c46424e665..3f38545979 100755 --- a/redis.c +++ b/redis.c @@ -5289,7 +5289,7 @@ PHP_METHOD(Redis, subscribe) char *type_response; int callback_type; - zval *z_o, *z_fun,*z_ret, *z_args[3]; + zval *z_o, *z_fun = NULL,*z_ret, *z_args[3]; char *method_name; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oaz|z", From 2c907f22675f1f5540b1bfbd00504c218f3e2ba4 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 08:07:05 +0200 Subject: [PATCH 11/17] redis.c:5412:3: warning: 'callback_type', 'callback_ft_name_len', 'callback_ft_name' may be used uninitialized in this function --- redis.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/redis.c b/redis.c index 3f38545979..b0b8856256 100755 --- a/redis.c +++ b/redis.c @@ -5288,7 +5288,7 @@ PHP_METHOD(Redis, subscribe) zval *z_tab, **tmp; char *type_response; - int callback_type; + int callback_type = 0; zval *z_o, *z_fun = NULL,*z_ret, *z_args[3]; char *method_name; @@ -5376,6 +5376,8 @@ PHP_METHOD(Redis, subscribe) callback_ft_name = Z_STRVAL_P(z_callback); callback_ft_name_len = strlen(callback_ft_name); callback_type = R_SUB_CALLBACK_FT_TYPE; + MAKE_STD_ZVAL(z_fun); + ZVAL_STRINGL(z_fun, callback_ft_name, callback_ft_name_len, 0); } /* Multibulk Response, format : {message type, originating channel, message payload} */ @@ -5416,8 +5418,6 @@ PHP_METHOD(Redis, subscribe) case R_SUB_CALLBACK_FT_TYPE: MAKE_STD_ZVAL(z_ret); - MAKE_STD_ZVAL(z_fun); - ZVAL_STRINGL(z_fun, callback_ft_name, callback_ft_name_len, 0); call_user_function(EG(function_table), NULL, z_fun, z_ret, 3, z_args TSRMLS_CC); efree(z_fun); efree(z_ret); From bdc53365662513b903012d4290f571a11ad96666 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 08:08:35 +0200 Subject: [PATCH 12/17] redis.c:2388:26: warning: 'timeout' may be used uninitialized in this function --- redis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis.c b/redis.c index b0b8856256..dbf71c61c7 100755 --- a/redis.c +++ b/redis.c @@ -2275,7 +2275,7 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword int cmd_len, *keys_len, *keys_to_free; int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0; int single_array = 0; - int timeout; + int timeout = 0; int pos; int array_size; From bad9073d2030d5d465c64668baba71c617ad8d93 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 08:10:37 +0200 Subject: [PATCH 13/17] redis.c:4300:33: warning: 'arr_weights_hash' may be used uninitialized in this function --- redis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis.c b/redis.c index dbf71c61c7..06bf42407b 100755 --- a/redis.c +++ b/redis.c @@ -4197,7 +4197,7 @@ PHP_METHOD(Redis, zIncrBy) PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int command_len) { zval *object, *keys_array, *weights_array = NULL, **data; - HashTable *arr_weights_hash, *arr_keys_hash; + HashTable *arr_weights_hash = NULL, *arr_keys_hash; int key_output_len, array_weights_count, array_keys_count, operation_len = 0; char *key_output, *operation; RedisSock *redis_sock; From 1cd7baa01edd2360ae73558f03fe1dd317261983 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 08:14:22 +0200 Subject: [PATCH 14/17] redis.c:3508:21: warning: 'p', 'cmd' may be used uninitialized in this function --- redis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis.c b/redis.c index 06bf42407b..24b2e5fd90 100755 --- a/redis.c +++ b/redis.c @@ -3433,7 +3433,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI zval *object; RedisSock *redis_sock; - char *cmd, *p; + char *cmd = NULL, *p = NULL; int cmd_len = 0, argc = 0, kw_len = strlen(kw); int step = 0; // 0: compute size; 1: copy strings. zval *z_array; From d4bdb35c601599a09aead6f1f55e333c7a388831 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 09:04:24 +0200 Subject: [PATCH 15/17] fix test report (backtrace index) --- tests/test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.php b/tests/test.php index d679e4ff96..1d27062f74 100644 --- a/tests/test.php +++ b/tests/test.php @@ -16,7 +16,7 @@ protected function assertTrue($bool) { $bt = debug_backtrace(false); $count = count($bt); self::$errors []= sprintf("Assertion failed: %s:%d (%s)\n", - $bt[$count - 2]["file"], $bt[$count - 3]["line"], $bt[$count - 1]["function"]); + $bt[0]["file"], $bt[0]["line"], $bt[1]["function"]); } protected function assertEquals($a, $b) { @@ -27,7 +27,7 @@ protected function assertEquals($a, $b) { $count = count($bt); self::$errors []= sprintf("Assertion failed (%s !== %s): %s:%d (%s)\n", print_r($a, true), print_r($b, true), - $bt[$count - 2]["file"], $bt[$count - 3]["line"], $bt[$count - 1]["function"]); + $bt[0]["file"], $bt[0]["line"], $bt[1]["function"]); } public static function run($className) { From ac09cec134248427d89e89012856f873dec640f5 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 30 Aug 2012 09:06:42 +0200 Subject: [PATCH 16/17] fix php warning during tests --- tests/TestRedis.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/TestRedis.php b/tests/TestRedis.php index c3738efd1c..56bccbffac 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -1595,9 +1595,12 @@ public function testinfo() { // INFO COMMANDSTATS $info = $this->redis->info("COMMANDSTATS"); - foreach($info as $k => $value) { - $this->assertTrue(strpos($k, 'cmdstat_') !== false); - } + $this->assertTrue(is_array($info)); + if (is_array($info)) { + foreach($info as $k => $value) { + $this->assertTrue(strpos($k, 'cmdstat_') !== false); + } + } } public function testSelect() { @@ -1617,16 +1620,16 @@ public function testMset() { $this->assertFalse($this->redis->mset(array())); // set ø → FALSE - + /* * Integer keys */ - // No prefix - $set_array = Array(-1 => 'neg1', -2 => 'neg2', -3 => 'neg3', 1 => 'one', 2 => 'two', '3' => 'three'); - $this->redis->delete(array_keys($set_array)); - $this->assertTrue($this->redis->mset($set_array)); - $this->assertEquals($this->redis->mget(array_keys($set_array)), array_values($set_array)); + // No prefix + $set_array = Array(-1 => 'neg1', -2 => 'neg2', -3 => 'neg3', 1 => 'one', 2 => 'two', '3' => 'three'); + $this->redis->delete(array_keys($set_array)); + $this->assertTrue($this->redis->mset($set_array)); + $this->assertEquals($this->redis->mget(array_keys($set_array)), array_values($set_array)); $this->redis->delete(array_keys($set_array)); // With a prefix @@ -3013,7 +3016,7 @@ public function testScript() { // None should exist $result = $this->redis->script('exists', $s1_sha, $s2_sha, $s3_sha); $this->assertTrue(is_array($result) && count($result) == 3); - $this->assertTrue(count(array_filter($result)) == 0); + $this->assertTrue(is_array($result) && count(array_filter($result)) == 0); // Load them up $this->assertTrue($this->redis->script('load', $s1_src) == $s1_sha); @@ -3022,7 +3025,7 @@ public function testScript() { // They should all exist $result = $this->redis->script('exists', $s1_sha, $s2_sha, $s3_sha); - $this->assertTrue(count(array_filter($result)) == 3); + $this->assertTrue(is_array($result) && count(array_filter($result)) == 3); } public function testEval() { @@ -3093,7 +3096,7 @@ public function testEval() { // Now run our script, and check our values against each other $eval_result = $this->redis->eval($nested_script); - $this->assertTrue(count($this->array_diff_recursive($eval_result, $expected)) == 0); + $this->assertTrue(is_array($eval_result) && count($this->array_diff_recursive($eval_result, $expected)) == 0); /* * Nested reply wihin a multi/pipeline block @@ -3109,7 +3112,7 @@ public function testEval() { $replies = $this->redis->exec(); foreach($replies as $reply) { - $this->assertTrue(count($this->array_diff_recursive($reply, $expected)) == 0); + $this->assertTrue(is_array($reply) && count($this->array_diff_recursive($reply, $expected)) == 0); } } From 2516eb22bb8d3c47b72e5874f9eba0d153c06edc Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 31 Aug 2012 15:25:56 +0200 Subject: [PATCH 17/17] proposal for multi-version test suite ("All tests passed." with 2.6.0RC6) --- tests/TestRedis.php | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 56bccbffac..c9e241c991 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -18,6 +18,8 @@ class Redis_Test extends TestSuite public function setUp() { $this->redis = $this->newInstance(); + $info = $this->redis->info(); + $this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0'); } private function newInstance() { @@ -44,6 +46,12 @@ public function reset() $this->tearDown(); } + public function testMinimumVersion() + { + // Minimum server version required for tests + $this->assertTrue(version_compare($this->version, "2.4.0", "ge")); + } + public function testPing() { @@ -848,8 +856,14 @@ public function testSortAsc() { } // SORT list → [ghi, def, abc] - $this->assertEquals(array_reverse($list), $this->redis->sortAsc('list')); - $this->assertEquals(array_reverse($list), $this->redis->sort('list', array('sort' => 'asc'))); + if (version_compare($this->version, "2.5.0", "lt")) { + $this->assertEquals(array_reverse($list), $this->redis->sortAsc('list')); + $this->assertEquals(array_reverse($list), $this->redis->sort('list', array('sort' => 'asc'))); + } else { + // TODO rewrite, from 2.6.0 release notes: + // SORT now will refuse to sort in numerical mode elements that can't be parsed + // as numbers + } // SORT list ALPHA → [abc, def, ghi] $this->assertEquals($list, $this->redis->sortAscAlpha('list')); @@ -883,7 +897,13 @@ public function testSortDesc() { } // SORT list → [ghi, abc, def] - $this->assertEquals(array_reverse($list), $this->redis->sortDesc('list')); + if (version_compare($this->version, "2.5.0", "lt")) { + $this->assertEquals(array_reverse($list), $this->redis->sortDesc('list')); + } else { + // TODO rewrite, from 2.6.0 release notes: + // SORT now will refuse to sort in numerical mode elements that can't be parsed + // as numbers + } // SORT list ALPHA → [abc, def, ghi] $this->assertEquals(array('ghi', 'def', 'abc'), $this->redis->sortDescAlpha('list')); @@ -1580,13 +1600,22 @@ public function testinfo() { "connected_clients", "connected_slaves", "used_memory", - "changes_since_last_save", - "bgsave_in_progress", - "last_save_time", "total_connections_received", "total_commands_processed", "role"); - + if (version_compare($this->version, "2.5.0", "lt")) { + array_push($keys, + "changes_since_last_save", + "bgsave_in_progress", + "last_save_time" + ); + } else { + array_push($keys, + "rdb_changes_since_last_save", + "rdb_bgsave_in_progress", + "rdb_last_save_time" + ); + } foreach($keys as $k) { $this->assertTrue(in_array($k, array_keys($info)));