Skip to content

Commit a5e53f1

Browse files
committed
Fixed compilation issues with Clang.
(GitHub issue phpredis#116).
1 parent 5d8839f commit a5e53f1

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PHPAPI void redis_stream_close(RedisSock *redis_sock TSRMLS_DC);
3232
PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC);
3333
//PHPAPI int redis_sock_get(zval *id, RedisSock **redis_sock TSRMLS_DC);
3434
PHPAPI void redis_free_socket(RedisSock *redis_sock);
35+
PHPAPI void redis_send_discard(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock);
3536

3637
PHPAPI int
3738
redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len TSRMLS_DC);
@@ -40,3 +41,4 @@ redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_DC);
4041

4142
PHPAPI int
4243
redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_DC);
44+

redis.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,19 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
21862186
cmd[cmd_len] = 0;
21872187
php_printf("cmd=[%s]\n", cmd);
21882188
*/
2189-
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
2189+
2190+
/* call REDIS_PROCESS_REQUEST and skip void returns */
2191+
IF_MULTI_OR_ATOMIC() {
2192+
if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
2193+
efree(cmd);
2194+
return FAILURE;
2195+
}
2196+
efree(cmd);
2197+
}
2198+
IF_PIPELINE() {
2199+
PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len);
2200+
efree(cmd);
2201+
}
21902202

21912203
return SUCCESS;
21922204
}
@@ -3164,7 +3176,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, void (*fun)(INTERNAL_FUNCTI
31643176
}
31653177

31663178
val_free = redis_serialize(redis_sock, *z_value_pp, &val, &val_len TSRMLS_CC);
3167-
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
3179+
key_free = redis_key_prefix(redis_sock, &key, (int*)&key_len TSRMLS_CC);
31683180

31693181
if(step == 0) { /* counting */
31703182
cmd_len += 1 + integer_length(key_len) + 2
@@ -4234,7 +4246,18 @@ generic_hash_command_1(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_
42344246
cmd_len = redis_cmd_format_static(&cmd, keyword, "s", key, key_len);
42354247
if(key_free) efree(key);
42364248

4237-
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
4249+
/* call REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len) without breaking the return value */
4250+
IF_MULTI_OR_ATOMIC() {
4251+
if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
4252+
efree(cmd);
4253+
return NULL;
4254+
}
4255+
efree(cmd);
4256+
}
4257+
IF_PIPELINE() {
4258+
PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len);
4259+
efree(cmd);
4260+
}
42384261
return redis_sock;
42394262
}
42404263

redis_array.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,9 @@ PHP_METHOD(RedisArray, mset)
792792
HashPosition pointer;
793793
zval **redis_instances, *redis_inst, **argv;
794794
char *key, **keys;
795-
int key_len, type, *key_lens;
796-
long idx;
795+
unsigned int key_len;
796+
int type, *key_lens;
797+
unsigned long idx;
797798

798799
/* Multi/exec support */
799800
HANDLE_MULTI_EXEC("MSET");
@@ -833,11 +834,11 @@ PHP_METHOD(RedisArray, mset)
833834
continue;
834835
}
835836

836-
redis_instances[i] = ra_find_node(ra, key, key_len - 1, &pos[i] TSRMLS_CC); /* -1 because of PHP assoc keys which count \0... */
837+
redis_instances[i] = ra_find_node(ra, key, (int)key_len - 1, &pos[i] TSRMLS_CC); /* -1 because of PHP assoc keys which count \0... */
837838
argc_each[pos[i]]++; /* count number of keys per node */
838839
argv[i] = *data;
839840
keys[i] = key;
840-
key_lens[i] = key_len - 1;
841+
key_lens[i] = (int)key_len - 1;
841842
}
842843

843844

redis_array_impl.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,20 +501,20 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
501501
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(z_pairs), &pos);
502502
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(z_pairs), (void **)&z_entry_pp, &pos) == SUCCESS) {
503503
char *key;
504-
int key_len;
505-
long num_key;
504+
unsigned int key_len;
505+
unsigned long num_key;
506506
zval *z_new;
507507
MAKE_STD_ZVAL(z_new);
508508

509509
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(z_pairs), &key, &key_len, &num_key, 1, &pos)) {
510510
case HASH_KEY_IS_STRING:
511-
ZVAL_STRINGL(z_new, key, key_len - 1, 0);
511+
ZVAL_STRINGL(z_new, key, (int)key_len - 1, 0);
512512
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), &z_new, sizeof(zval *), NULL);
513513
break;
514514

515515
case HASH_KEY_IS_LONG:
516516
Z_TYPE_P(z_new) = IS_LONG;
517-
Z_LVAL_P(z_new) = num_key;
517+
Z_LVAL_P(z_new) = (long)num_key;
518518
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), &z_new, sizeof(zval *), NULL);
519519
break;
520520
}
@@ -775,6 +775,8 @@ ra_del_key(const char *key, int key_len, zval *z_from TSRMLS_DC) {
775775

776776
/* close transaction */
777777
ra_index_exec(z_from, NULL, 0 TSRMLS_CC);
778+
779+
return 1;
778780
}
779781

780782
static zend_bool
@@ -806,8 +808,9 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
806808
int count;
807809
HashTable *h_zset_vals;
808810
char *val;
809-
int val_len, i;
810-
long idx;
811+
unsigned int val_len;
812+
int i;
813+
unsigned long idx;
811814
int type;
812815

813816
/* run ZRANGE key 0 -1 WITHSCORES on source */
@@ -855,10 +858,10 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
855858
MAKE_STD_ZVAL(z_zadd_args[i+1]);
856859
switch (zend_hash_get_current_key_ex(h_zset_vals, &val, &val_len, &idx, 0, NULL)) {
857860
case HASH_KEY_IS_STRING:
858-
ZVAL_STRINGL(z_zadd_args[i+1], val, val_len-1, 0); /* we have to remove 1 because it is an array key. */
861+
ZVAL_STRINGL(z_zadd_args[i+1], val, (int)val_len-1, 0); /* we have to remove 1 because it is an array key. */
859862
break;
860863
case HASH_KEY_IS_LONG:
861-
ZVAL_LONG(z_zadd_args[i+1], idx);
864+
ZVAL_LONG(z_zadd_args[i+1], (long)idx);
862865
break;
863866
default:
864867
return -1; // Todo: log error

0 commit comments

Comments
 (0)