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

Skip to content

Commit 28fe4c1

Browse files
committed
Merge pull request phpredis#240 from remicollet/master
Fix remaining compiler warning.
2 parents 6915597 + 2516eb2 commit 28fe4c1

File tree

4 files changed

+71
-52
lines changed

4 files changed

+71
-52
lines changed

redis.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,12 +2270,12 @@ PHP_METHOD(Redis, sMembers)
22702270
PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_len,
22712271
int min_argc, RedisSock **out_sock, int has_timeout, int all_keys, int can_serialize)
22722272
{
2273-
zval *object, **z_args, *z_array;
2273+
zval **z_args, *z_array;
22742274
char **keys, *cmd;
22752275
int cmd_len, *keys_len, *keys_to_free;
22762276
int i, j, argc = ZEND_NUM_ARGS(), real_argc = 0;
22772277
int single_array = 0;
2278-
int timeout;
2278+
int timeout = 0;
22792279
int pos;
22802280
int array_size;
22812281

@@ -2347,10 +2347,9 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
23472347
char *key;
23482348
unsigned int key_len;
23492349
unsigned long idx;
2350-
int type;
23512350
zval **z_value_pp;
23522351

2353-
type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
2352+
zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
23542353
if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
23552354
continue; /* this should never happen, according to the PHP people. */
23562355
}
@@ -2392,12 +2391,7 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
23922391
real_argc++;
23932392
}
23942393
} else {
2395-
int nb_keys;
2396-
if(!has_timeout) {
2397-
nb_keys = argc;
2398-
} else if(has_timeout && Z_TYPE_P(z_args[argc - 1]) == IS_LONG) {
2399-
nb_keys = argc - 1;
2400-
} else {
2394+
if(has_timeout && Z_TYPE_P(z_args[argc - 1]) != IS_LONG) {
24012395
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Syntax error on timeout");
24022396
}
24032397

@@ -2465,7 +2459,6 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
24652459

24662460
if(z_args) efree(z_args);
24672461

2468-
object = getThis();
24692462
/*
24702463
cmd[cmd_len] = 0;
24712464
php_printf("cmd=[%s]\n", cmd);
@@ -2703,10 +2696,9 @@ PHP_METHOD(Redis, sort) {
27032696
char *key;
27042697
unsigned int key_len;
27052698
unsigned long idx;
2706-
int type;
27072699
zval **z_value_pp;
27082700

2709-
type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
2701+
zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
27102702
if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
27112703
continue; /* this should never happen, according to the PHP people. */
27122704
}
@@ -3441,7 +3433,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
34413433
zval *object;
34423434
RedisSock *redis_sock;
34433435

3444-
char *cmd, *p;
3436+
char *cmd = NULL, *p = NULL;
34453437
int cmd_len = 0, argc = 0, kw_len = strlen(kw);
34463438
int step = 0; // 0: compute size; 1: copy strings.
34473439
zval *z_array;
@@ -4205,7 +4197,7 @@ PHP_METHOD(Redis, zIncrBy)
42054197
PHPAPI void generic_z_command(INTERNAL_FUNCTION_PARAMETERS, char *command, int command_len) {
42064198

42074199
zval *object, *keys_array, *weights_array = NULL, **data;
4208-
HashTable *arr_weights_hash, *arr_keys_hash;
4200+
HashTable *arr_weights_hash = NULL, *arr_keys_hash;
42094201
int key_output_len, array_weights_count, array_keys_count, operation_len = 0;
42104202
char *key_output, *operation;
42114203
RedisSock *redis_sock;
@@ -4655,12 +4647,11 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int
46554647

46564648
char *tablekey, *hkey, *hval;
46574649
unsigned int tablekey_len;
4658-
int hkey_len, hval_len;
4650+
int hkey_len;
46594651
unsigned long idx;
4660-
int type;
46614652
zval **z_key_pp, **z_value_pp;
46624653

4663-
type = zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL);
4654+
zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL);
46644655
if(zend_hash_get_current_data(keytable, (void**)&z_key_pp) == FAILURE) {
46654656
continue; /* this should never happen, according to the PHP people. */
46664657
}
@@ -4674,14 +4665,13 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int
46744665
zend_hash_move_forward(keytable);
46754666

46764667
/* fetch again */
4677-
type = zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL);
4668+
zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL);
46784669
if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
46794670
continue; /* this should never happen, according to the PHP people. */
46804671
}
46814672

46824673
/* get current value, a hash value now. */
46834674
hval = Z_STRVAL_PP(z_value_pp);
4684-
hval_len = Z_STRLEN_PP(z_value_pp);
46854675

46864676
if(use_atof) { /* zipping a score */
46874677
add_assoc_double_ex(z_ret, hkey, 1+hkey_len, atof(hval));
@@ -5298,10 +5288,9 @@ PHP_METHOD(Redis, subscribe)
52985288
zval *z_tab, **tmp;
52995289
char *type_response;
53005290

5301-
int callback_type;
5302-
zval *z_o, *z_fun,*z_ret, *z_args[3];
5291+
int callback_type = 0;
5292+
zval *z_o, *z_fun = NULL,*z_ret, *z_args[3];
53035293
char *method_name;
5304-
zend_class_entry *ce;
53055294

53065295
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oaz|z",
53075296
&object, redis_ce, &array, &z_callback) == FAILURE) {
@@ -5387,6 +5376,8 @@ PHP_METHOD(Redis, subscribe)
53875376
callback_ft_name = Z_STRVAL_P(z_callback);
53885377
callback_ft_name_len = strlen(callback_ft_name);
53895378
callback_type = R_SUB_CALLBACK_FT_TYPE;
5379+
MAKE_STD_ZVAL(z_fun);
5380+
ZVAL_STRINGL(z_fun, callback_ft_name, callback_ft_name_len, 0);
53905381
}
53915382

53925383
/* Multibulk Response, format : {message type, originating channel, message payload} */
@@ -5421,14 +5412,12 @@ PHP_METHOD(Redis, subscribe)
54215412
switch(callback_type) {
54225413
case R_SUB_CALLBACK_CLASS_TYPE:
54235414
MAKE_STD_ZVAL(z_ret);
5424-
call_user_function(&ce->function_table, &z_o, z_fun, z_ret, 3, z_args TSRMLS_CC);
5415+
call_user_function(&redis_ce->function_table, &z_o, z_fun, z_ret, 3, z_args TSRMLS_CC);
54255416
efree(z_ret);
54265417
break;
54275418

54285419
case R_SUB_CALLBACK_FT_TYPE:
54295420
MAKE_STD_ZVAL(z_ret);
5430-
MAKE_STD_ZVAL(z_fun);
5431-
ZVAL_STRINGL(z_fun, callback_ft_name, callback_ft_name_len, 0);
54325421
call_user_function(EG(function_table), NULL, z_fun, z_ret, 3, z_args TSRMLS_CC);
54335422
efree(z_fun);
54345423
efree(z_ret);

redis_array.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static void
264264
ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, int cmd_len, zval *z_args, zval *z_new_target) {
265265

266266
zval **zp_tmp, z_tmp;
267-
char *key;
267+
char *key = NULL; // set to avoid "unused-but-set-variable"
268268
int key_len;
269269
int i;
270270
zval *redis_inst;
@@ -715,7 +715,7 @@ PHP_METHOD(RedisArray, mget)
715715
int *pos, argc, *argc_each;
716716
HashTable *h_keys;
717717
HashPosition pointer;
718-
zval **redis_instances, *redis_inst, **argv;
718+
zval **redis_instances, **argv;
719719

720720
/* Multi/exec support */
721721
HANDLE_MULTI_EXEC("MGET");
@@ -771,8 +771,6 @@ PHP_METHOD(RedisArray, mget)
771771
/* calls */
772772
for(n = 0; n < ra->count; ++n) { /* for each node */
773773

774-
redis_inst = ra->redis[n];
775-
776774
/* copy args for MGET call on node. */
777775
MAKE_STD_ZVAL(z_argarray);
778776
array_init(z_argarray);

tests/TestRedis.php

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Redis_Test extends TestSuite
1818
public function setUp()
1919
{
2020
$this->redis = $this->newInstance();
21+
$info = $this->redis->info();
22+
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
2123
}
2224

2325
private function newInstance() {
@@ -44,6 +46,12 @@ public function reset()
4446
$this->tearDown();
4547
}
4648

49+
public function testMinimumVersion()
50+
{
51+
// Minimum server version required for tests
52+
$this->assertTrue(version_compare($this->version, "2.4.0", "ge"));
53+
}
54+
4755
public function testPing()
4856
{
4957

@@ -848,8 +856,14 @@ public function testSortAsc() {
848856
}
849857

850858
// SORT list → [ghi, def, abc]
851-
$this->assertEquals(array_reverse($list), $this->redis->sortAsc('list'));
852-
$this->assertEquals(array_reverse($list), $this->redis->sort('list', array('sort' => 'asc')));
859+
if (version_compare($this->version, "2.5.0", "lt")) {
860+
$this->assertEquals(array_reverse($list), $this->redis->sortAsc('list'));
861+
$this->assertEquals(array_reverse($list), $this->redis->sort('list', array('sort' => 'asc')));
862+
} else {
863+
// TODO rewrite, from 2.6.0 release notes:
864+
// SORT now will refuse to sort in numerical mode elements that can't be parsed
865+
// as numbers
866+
}
853867

854868
// SORT list ALPHA → [abc, def, ghi]
855869
$this->assertEquals($list, $this->redis->sortAscAlpha('list'));
@@ -883,7 +897,13 @@ public function testSortDesc() {
883897
}
884898

885899
// SORT list → [ghi, abc, def]
886-
$this->assertEquals(array_reverse($list), $this->redis->sortDesc('list'));
900+
if (version_compare($this->version, "2.5.0", "lt")) {
901+
$this->assertEquals(array_reverse($list), $this->redis->sortDesc('list'));
902+
} else {
903+
// TODO rewrite, from 2.6.0 release notes:
904+
// SORT now will refuse to sort in numerical mode elements that can't be parsed
905+
// as numbers
906+
}
887907

888908
// SORT list ALPHA → [abc, def, ghi]
889909
$this->assertEquals(array('ghi', 'def', 'abc'), $this->redis->sortDescAlpha('list'));
@@ -1580,13 +1600,22 @@ public function testinfo() {
15801600
"connected_clients",
15811601
"connected_slaves",
15821602
"used_memory",
1583-
"changes_since_last_save",
1584-
"bgsave_in_progress",
1585-
"last_save_time",
15861603
"total_connections_received",
15871604
"total_commands_processed",
15881605
"role");
1589-
1606+
if (version_compare($this->version, "2.5.0", "lt")) {
1607+
array_push($keys,
1608+
"changes_since_last_save",
1609+
"bgsave_in_progress",
1610+
"last_save_time"
1611+
);
1612+
} else {
1613+
array_push($keys,
1614+
"rdb_changes_since_last_save",
1615+
"rdb_bgsave_in_progress",
1616+
"rdb_last_save_time"
1617+
);
1618+
}
15901619

15911620
foreach($keys as $k) {
15921621
$this->assertTrue(in_array($k, array_keys($info)));
@@ -1595,9 +1624,12 @@ public function testinfo() {
15951624
// INFO COMMANDSTATS
15961625
$info = $this->redis->info("COMMANDSTATS");
15971626

1598-
foreach($info as $k => $value) {
1599-
$this->assertTrue(strpos($k, 'cmdstat_') !== false);
1600-
}
1627+
$this->assertTrue(is_array($info));
1628+
if (is_array($info)) {
1629+
foreach($info as $k => $value) {
1630+
$this->assertTrue(strpos($k, 'cmdstat_') !== false);
1631+
}
1632+
}
16011633
}
16021634

16031635
public function testSelect() {
@@ -1617,16 +1649,16 @@ public function testMset() {
16171649

16181650
$this->assertFalse($this->redis->mset(array())); // set ø → FALSE
16191651

1620-
1652+
16211653
/*
16221654
* Integer keys
16231655
*/
16241656

1625-
// No prefix
1626-
$set_array = Array(-1 => 'neg1', -2 => 'neg2', -3 => 'neg3', 1 => 'one', 2 => 'two', '3' => 'three');
1627-
$this->redis->delete(array_keys($set_array));
1628-
$this->assertTrue($this->redis->mset($set_array));
1629-
$this->assertEquals($this->redis->mget(array_keys($set_array)), array_values($set_array));
1657+
// No prefix
1658+
$set_array = Array(-1 => 'neg1', -2 => 'neg2', -3 => 'neg3', 1 => 'one', 2 => 'two', '3' => 'three');
1659+
$this->redis->delete(array_keys($set_array));
1660+
$this->assertTrue($this->redis->mset($set_array));
1661+
$this->assertEquals($this->redis->mget(array_keys($set_array)), array_values($set_array));
16301662
$this->redis->delete(array_keys($set_array));
16311663

16321664
// With a prefix
@@ -3013,7 +3045,7 @@ public function testScript() {
30133045
// None should exist
30143046
$result = $this->redis->script('exists', $s1_sha, $s2_sha, $s3_sha);
30153047
$this->assertTrue(is_array($result) && count($result) == 3);
3016-
$this->assertTrue(count(array_filter($result)) == 0);
3048+
$this->assertTrue(is_array($result) && count(array_filter($result)) == 0);
30173049

30183050
// Load them up
30193051
$this->assertTrue($this->redis->script('load', $s1_src) == $s1_sha);
@@ -3022,7 +3054,7 @@ public function testScript() {
30223054

30233055
// They should all exist
30243056
$result = $this->redis->script('exists', $s1_sha, $s2_sha, $s3_sha);
3025-
$this->assertTrue(count(array_filter($result)) == 3);
3057+
$this->assertTrue(is_array($result) && count(array_filter($result)) == 3);
30263058
}
30273059

30283060
public function testEval() {
@@ -3093,7 +3125,7 @@ public function testEval() {
30933125

30943126
// Now run our script, and check our values against each other
30953127
$eval_result = $this->redis->eval($nested_script);
3096-
$this->assertTrue(count($this->array_diff_recursive($eval_result, $expected)) == 0);
3128+
$this->assertTrue(is_array($eval_result) && count($this->array_diff_recursive($eval_result, $expected)) == 0);
30973129

30983130
/*
30993131
* Nested reply wihin a multi/pipeline block
@@ -3109,7 +3141,7 @@ public function testEval() {
31093141
$replies = $this->redis->exec();
31103142

31113143
foreach($replies as $reply) {
3112-
$this->assertTrue(count($this->array_diff_recursive($reply, $expected)) == 0);
3144+
$this->assertTrue(is_array($reply) && count($this->array_diff_recursive($reply, $expected)) == 0);
31133145
}
31143146
}
31153147

tests/test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function assertTrue($bool) {
1616
$bt = debug_backtrace(false);
1717
$count = count($bt);
1818
self::$errors []= sprintf("Assertion failed: %s:%d (%s)\n",
19-
$bt[$count - 2]["file"], $bt[$count - 3]["line"], $bt[$count - 1]["function"]);
19+
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
2020
}
2121

2222
protected function assertEquals($a, $b) {
@@ -27,7 +27,7 @@ protected function assertEquals($a, $b) {
2727
$count = count($bt);
2828
self::$errors []= sprintf("Assertion failed (%s !== %s): %s:%d (%s)\n",
2929
print_r($a, true), print_r($b, true),
30-
$bt[$count - 2]["file"], $bt[$count - 3]["line"], $bt[$count - 1]["function"]);
30+
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
3131
}
3232

3333
public static function run($className) {

0 commit comments

Comments
 (0)