Skip to content

Commit c4b11a9

Browse files
committed
put macros in order
1 parent 690bb8d commit c4b11a9

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed

common.h

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -467,36 +467,12 @@ typedef enum _PUBSUB_TYPE {
467467
#define REDIS_ERR_SYNC_MSG "MASTERDOWN Link with MASTER is down and slave-serve-stale-data is set to 'no'"
468468
#define REDIS_ERR_SYNC_KW "MASTERDOWN"
469469

470-
#define IF_MULTI() if(redis_sock->mode == MULTI)
471-
#define IF_MULTI_OR_ATOMIC() if(redis_sock->mode == MULTI || redis_sock->mode == ATOMIC)\
472-
473-
#define IF_MULTI_OR_PIPELINE() if(redis_sock->mode == MULTI || redis_sock->mode == PIPELINE)
474-
#define IF_PIPELINE() if(redis_sock->mode == PIPELINE)
475-
#define IF_NOT_PIPELINE() if(redis_sock->mode != PIPELINE)
476-
#define IF_NOT_MULTI() if(redis_sock->mode != MULTI)
477-
#define IF_NOT_ATOMIC() if(redis_sock->mode != ATOMIC)
478-
#define IF_ATOMIC() if(redis_sock->mode == ATOMIC)
479-
#define ELSE_IF_MULTI() else IF_MULTI() { \
480-
if(redis_response_enqueued(redis_sock TSRMLS_CC) == 1) { \
481-
RETURN_ZVAL(getThis(), 1, 0);\
482-
} else { \
483-
RETURN_FALSE; \
484-
} \
485-
}
486-
487-
#define ELSE_IF_PIPELINE() else IF_PIPELINE() { \
488-
RETURN_ZVAL(getThis(), 1, 0);\
489-
}
490-
491-
#define MULTI_RESPONSE(callback) IF_MULTI_OR_PIPELINE() { \
492-
fold_item *f1, *current; \
493-
f1 = malloc(sizeof(fold_item)); \
494-
f1->fun = (void *)callback; \
495-
f1->next = NULL; \
496-
current = redis_sock->current;\
497-
if(current) current->next = f1; \
498-
redis_sock->current = f1; \
499-
}
470+
#define IF_ATOMIC() if (redis_sock->mode == ATOMIC)
471+
#define IF_NOT_ATOMIC() if (redis_sock->mode != ATOMIC)
472+
#define IF_MULTI() if (redis_sock->mode == MULTI)
473+
#define IF_NOT_MULTI() if (redis_sock->mode != MULTI)
474+
#define IF_PIPELINE() if (redis_sock->mode == PIPELINE)
475+
#define IF_NOT_PIPELINE() if (redis_sock->mode != PIPELINE)
500476

501477
#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) request_item *tmp; \
502478
struct request_item *current_request;\
@@ -521,7 +497,7 @@ typedef enum _PUBSUB_TYPE {
521497
}
522498

523499
#define REDIS_SAVE_CALLBACK(callback, closure_context) \
524-
IF_MULTI_OR_PIPELINE() { \
500+
IF_NOT_ATOMIC() { \
525501
fold_item *f1, *current; \
526502
f1 = malloc(sizeof(fold_item)); \
527503
f1->fun = (void *)callback; \

library.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ PHP_REDIS_API void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, Redi
848848
double ret;
849849

850850
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
851-
IF_MULTI_OR_PIPELINE() {
851+
IF_NOT_ATOMIC() {
852852
add_next_index_bool(z_tab, 0);
853853
return;
854854
} else {
@@ -858,7 +858,7 @@ PHP_REDIS_API void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, Redi
858858

859859
ret = atof(response);
860860
efree(response);
861-
IF_MULTI_OR_PIPELINE() {
861+
IF_NOT_ATOMIC() {
862862
add_next_index_double(z_tab, ret);
863863
} else {
864864
RETURN_DOUBLE(ret);
@@ -871,7 +871,7 @@ PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
871871
long l;
872872

873873
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
874-
IF_MULTI_OR_PIPELINE() {
874+
IF_NOT_ATOMIC() {
875875
add_next_index_bool(z_tab, 0);
876876
return;
877877
} else {
@@ -894,7 +894,7 @@ PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
894894
}
895895

896896
efree(response);
897-
IF_MULTI_OR_PIPELINE() {
897+
IF_NOT_ATOMIC() {
898898
add_next_index_long(z_tab, l);
899899
} else {
900900
RETURN_LONG(l);
@@ -917,7 +917,7 @@ PHP_REDIS_API void redis_info_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
917917
/* Free source response */
918918
efree(response);
919919

920-
IF_MULTI_OR_PIPELINE() {
920+
IF_NOT_ATOMIC() {
921921
add_next_index_zval(z_tab, z_ret);
922922
} else {
923923
RETVAL_ZVAL(z_ret, 0, 1);
@@ -999,7 +999,7 @@ PHP_REDIS_API void redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
999999
efree(resp);
10001000

10011001
/* Return or append depending if we're atomic */
1002-
IF_MULTI_OR_PIPELINE() {
1002+
IF_NOT_ATOMIC() {
10031003
add_next_index_zval(z_tab, z_ret);
10041004
} else {
10051005
RETVAL_ZVAL(z_ret, 0, 1);
@@ -1127,7 +1127,7 @@ redis_boolean_response_impl(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
11271127
if (ret && success_callback != NULL) {
11281128
success_callback(redis_sock);
11291129
}
1130-
IF_MULTI_OR_PIPELINE() {
1130+
IF_NOT_ATOMIC() {
11311131
add_next_index_bool(z_tab, ret);
11321132
} else {
11331133
RETURN_BOOL(ret);
@@ -1153,7 +1153,7 @@ PHP_REDIS_API void redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
11531153
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))
11541154
== NULL)
11551155
{
1156-
IF_MULTI_OR_PIPELINE() {
1156+
IF_NOT_ATOMIC() {
11571157
add_next_index_bool(z_tab, 0);
11581158
return;
11591159
} else {
@@ -1167,7 +1167,7 @@ PHP_REDIS_API void redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
11671167
#else
11681168
long long ret = atoll(response + 1);
11691169
#endif
1170-
IF_MULTI_OR_PIPELINE() {
1170+
IF_NOT_ATOMIC() {
11711171
if(ret > LONG_MAX) { /* overflow */
11721172
add_next_index_stringl(z_tab, response + 1, response_len - 1);
11731173
} else {
@@ -1184,7 +1184,7 @@ PHP_REDIS_API void redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
11841184
}
11851185
} else {
11861186
efree(response);
1187-
IF_MULTI_OR_PIPELINE() {
1187+
IF_NOT_ATOMIC() {
11881188
add_next_index_null(z_tab);
11891189
} else {
11901190
RETURN_FALSE;
@@ -1269,7 +1269,7 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
12691269
}
12701270

12711271
if(inbuf[0] != '*') {
1272-
IF_MULTI_OR_PIPELINE() {
1272+
IF_NOT_ATOMIC() {
12731273
add_next_index_bool(z_tab, 0);
12741274
} else {
12751275
RETVAL_FALSE;
@@ -1290,7 +1290,7 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
12901290
/* Zip keys and values */
12911291
array_zip_values_and_scores(redis_sock, z_multi_result, decode TSRMLS_CC);
12921292

1293-
IF_MULTI_OR_PIPELINE() {
1293+
IF_NOT_ATOMIC() {
12941294
add_next_index_zval(z_tab, z_multi_result);
12951295
} else {
12961296
RETVAL_ZVAL(z_multi_result, 0, 1);
@@ -1341,7 +1341,7 @@ PHP_REDIS_API void redis_1_response(INTERNAL_FUNCTION_PARAMETERS,
13411341
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))
13421342
== NULL)
13431343
{
1344-
IF_MULTI_OR_PIPELINE() {
1344+
IF_NOT_ATOMIC() {
13451345
add_next_index_bool(z_tab, 0);
13461346
return;
13471347
} else {
@@ -1351,7 +1351,7 @@ PHP_REDIS_API void redis_1_response(INTERNAL_FUNCTION_PARAMETERS,
13511351
ret = response[1];
13521352
efree(response);
13531353

1354-
IF_MULTI_OR_PIPELINE() {
1354+
IF_NOT_ATOMIC() {
13551355
if(ret == '1') {
13561356
add_next_index_bool(z_tab, 1);
13571357
} else {
@@ -1374,13 +1374,13 @@ PHP_REDIS_API void redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
13741374
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))
13751375
== NULL)
13761376
{
1377-
IF_MULTI_OR_PIPELINE() {
1377+
IF_NOT_ATOMIC() {
13781378
add_next_index_bool(z_tab, 0);
13791379
return;
13801380
}
13811381
RETURN_FALSE;
13821382
}
1383-
IF_MULTI_OR_PIPELINE() {
1383+
IF_NOT_ATOMIC() {
13841384
zval zv, *z = &zv;
13851385
if (redis_unserialize(redis_sock, response, response_len, z TSRMLS_CC)) {
13861386
#if (PHP_MAJOR_VERSION < 7)
@@ -1411,13 +1411,13 @@ redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
14111411
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))
14121412
== NULL)
14131413
{
1414-
IF_MULTI_OR_PIPELINE() {
1414+
IF_NOT_ATOMIC() {
14151415
add_next_index_bool(z_tab, 0);
14161416
return;
14171417
}
14181418
RETURN_FALSE;
14191419
}
1420-
IF_MULTI_OR_PIPELINE() {
1420+
IF_NOT_ATOMIC() {
14211421
add_next_index_stringl(z_tab, response, response_len);
14221422
} else {
14231423
RETVAL_STRINGL(response, response_len);
@@ -1434,7 +1434,7 @@ PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
14341434

14351435
/* Add or return false if we can't read from the socket */
14361436
if((resp = redis_sock_read(redis_sock, &resp_len TSRMLS_CC))==NULL) {
1437-
IF_MULTI_OR_PIPELINE() {
1437+
IF_NOT_ATOMIC() {
14381438
add_next_index_bool(z_tab, 0);
14391439
return;
14401440
}
@@ -1482,7 +1482,7 @@ PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
14821482

14831483
efree(resp);
14841484

1485-
IF_MULTI_OR_PIPELINE() {
1485+
IF_NOT_ATOMIC() {
14861486
add_next_index_zval(z_tab, z_result);
14871487
} else {
14881488
RETVAL_ZVAL(z_result, 0, 1);
@@ -1736,7 +1736,7 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17361736
}
17371737

17381738
if(inbuf[0] != '*') {
1739-
IF_MULTI_OR_PIPELINE() {
1739+
IF_NOT_ATOMIC() {
17401740
add_next_index_bool(z_tab, 0);
17411741
} else {
17421742
if (inbuf[0] == '-') {
@@ -1757,7 +1757,7 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17571757
redis_mbulk_reply_loop(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock,
17581758
z_multi_result, numElems, UNSERIALIZE_ALL);
17591759

1760-
IF_MULTI_OR_PIPELINE() {
1760+
IF_NOT_ATOMIC() {
17611761
add_next_index_zval(z_tab, z_multi_result);
17621762
} else {
17631763
RETVAL_ZVAL(z_multi_result, 0, 1);
@@ -1783,7 +1783,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
17831783
}
17841784

17851785
if(inbuf[0] != '*') {
1786-
IF_MULTI_OR_PIPELINE() {
1786+
IF_NOT_ATOMIC() {
17871787
add_next_index_bool(z_tab, 0);
17881788
} else {
17891789
if (inbuf[0] == '-') {
@@ -1804,7 +1804,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
18041804
redis_mbulk_reply_loop(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock,
18051805
z_multi_result, numElems, UNSERIALIZE_NONE);
18061806

1807-
IF_MULTI_OR_PIPELINE() {
1807+
IF_NOT_ATOMIC() {
18081808
add_next_index_zval(z_tab, z_multi_result);
18091809
} else {
18101810
RETVAL_ZVAL(z_multi_result, 0, 1);
@@ -1871,7 +1871,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
18711871
}
18721872

18731873
if(inbuf[0] != '*') {
1874-
IF_MULTI_OR_PIPELINE() {
1874+
IF_NOT_ATOMIC() {
18751875
add_next_index_bool(z_tab, 0);
18761876
} else {
18771877
RETVAL_FALSE;
@@ -1906,7 +1906,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
19061906
}
19071907
efree(z_keys);
19081908

1909-
IF_MULTI_OR_PIPELINE() {
1909+
IF_NOT_ATOMIC() {
19101910
add_next_index_zval(z_tab, z_multi_result);
19111911
} else {
19121912
RETVAL_ZVAL(z_multi_result, 0, 1);
@@ -2357,7 +2357,7 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
23572357
return FAILURE;
23582358
}
23592359

2360-
IF_MULTI_OR_PIPELINE() {
2360+
IF_NOT_ATOMIC() {
23612361
add_next_index_zval(z_tab, z_ret);
23622362
} else {
23632363
/* Set our return value */

0 commit comments

Comments
 (0)