Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix remaining compiler warning. #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e3b2a46
fix warning: variable 'redis_inst' set but not used [-Wunused-but-set…
remicollet Aug 30, 2012
83053ea
warning: variable 'redis_inst' set but not used (compiler can't check…
remicollet Aug 30, 2012
0d725ed
redis.c:2350:17: warning: variable 'type' set but not used
remicollet Aug 30, 2012
297d83e
redis.c:2394:7: warning: variable 'nb_keys' set but not used
remicollet Aug 30, 2012
518599f
redis.c:2273:11: warning: variable 'object' set but not used
remicollet Aug 30, 2012
fa9bfeb
redis.c:2699:25: warning: variable 'type' set but not used
remicollet Aug 30, 2012
fa28264
redis.c:4652:13: warning: variable 'type' set but not used
remicollet Aug 30, 2012
eccffe5
redis.c:4650:23: warning: variable 'hval_len' set but not used
remicollet Aug 30, 2012
1defd42
redis.c:5414:23: warning: 'ce' may be used uninitialized in this func…
remicollet Aug 30, 2012
31b3840
redis.c:5413:23: warning: 'z_fun' may be used uninitialized in this f…
remicollet Aug 30, 2012
2c907f2
redis.c:5412:3: warning: 'callback_type', 'callback_ft_name_len', 'ca…
remicollet Aug 30, 2012
bdc5336
redis.c:2388:26: warning: 'timeout' may be used uninitialized in this…
remicollet Aug 30, 2012
bad9073
redis.c:4300:33: warning: 'arr_weights_hash' may be used uninitialize…
remicollet Aug 30, 2012
1cd7baa
redis.c:3508:21: warning: 'p', 'cmd' may be used uninitialized in thi…
remicollet Aug 30, 2012
d4bdb35
fix test report (backtrace index)
remicollet Aug 30, 2012
ac09cec
fix php warning during tests
remicollet Aug 30, 2012
2516eb2
proposal for multi-version test suite ("All tests passed." with 2.6.0…
remicollet Aug 31, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,12 +2270,12 @@ 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;
int single_array = 0;
int timeout;
int timeout = 0;
int pos;
int array_size;

Expand Down Expand Up @@ -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. */
}
Expand Down Expand Up @@ -2392,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");
}

Expand Down Expand Up @@ -2465,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);
Expand Down Expand Up @@ -2703,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. */
}
Expand Down Expand Up @@ -3441,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;
Expand Down Expand Up @@ -4205,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;
Expand Down Expand Up @@ -4655,12 +4647,11 @@ 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;
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. */
}
Expand All @@ -4674,14 +4665,13 @@ 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. */
}

/* 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));
Expand Down Expand Up @@ -5298,10 +5288,9 @@ PHP_METHOD(Redis, subscribe)
zval *z_tab, **tmp;
char *type_response;

int callback_type;
zval *z_o, *z_fun,*z_ret, *z_args[3];
int callback_type = 0;
zval *z_o, *z_fun = NULL,*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) {
Expand Down Expand Up @@ -5387,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} */
Expand Down Expand Up @@ -5421,14 +5412,12 @@ 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;

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);
Expand Down
6 changes: 2 additions & 4 deletions redis_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
72 changes: 52 additions & 20 deletions tests/TestRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()
{

Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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)));
Expand All @@ -1595,9 +1624,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() {
Expand All @@ -1617,16 +1649,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
Expand Down Expand Up @@ -3013,7 +3045,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);
Expand All @@ -3022,7 +3054,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() {
Expand Down Expand Up @@ -3093,7 +3125,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
Expand All @@ -3109,7 +3141,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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down