From 6b3e773c9e562b86958e20d5506a7c0fbe031bf0 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 4 Sep 2015 18:59:05 +0000 Subject: Fix compile errors in cluster_library.c, fixing all compilation errors --- cluster_library.c | 347 ++++++++++++++++++++++++------------------------------ 1 file changed, 156 insertions(+), 191 deletions(-) (limited to 'cluster_library.c') diff --git a/cluster_library.c b/cluster_library.c index 24e656e8..31b61957 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -11,14 +11,13 @@ extern zend_class_entry *redis_cluster_exception_ce; /* Some debug methods that will go away when we're through with them */ static void cluster_dump_nodes(redisCluster *c) { - redisClusterNode **pp, *p; + redisClusterNode *p; for(zend_hash_internal_pointer_reset(c->nodes); zend_hash_has_more_elements(c->nodes)==SUCCESS; zend_hash_move_forward(c->nodes)) { - zend_hash_get_current_data(c->nodes, (void**)&pp); - p = *pp; + p = zend_hash_get_current_data_ptr(c->nodes); const char *slave = (p->slave) ? "slave" : "master"; php_printf("%d %s %d %d", p->sock->port, slave,p->sock->prefix_len, @@ -42,29 +41,29 @@ static void cluster_log(char *fmt, ...) /* Debug function to dump a clusterReply structure recursively */ static void dump_reply(clusterReply *reply, int indent) { - smart_str buf = {0}; + smart_string buf = {0}; int i; switch(reply->type) { case TYPE_ERR: - smart_str_appendl(&buf, "(error) ", sizeof("(error) ")-1); - smart_str_appendl(&buf, reply->str, reply->len); + smart_string_appendl(&buf, "(error) ", sizeof("(error) ")-1); + smart_string_appendl(&buf, reply->str, reply->len); break; case TYPE_LINE: - smart_str_appendl(&buf, reply->str, reply->len); + smart_string_appendl(&buf, reply->str, reply->len); break; case TYPE_INT: - smart_str_appendl(&buf, "(integer) ", sizeof("(integer) ")-1); - smart_str_append_long(&buf, reply->integer); + smart_string_appendl(&buf, "(integer) ", sizeof("(integer) ")-1); + smart_string_append_long(&buf, reply->integer); break; case TYPE_BULK: - smart_str_appendl(&buf,"\"", 1); - smart_str_appendl(&buf, reply->str, reply->len); - smart_str_appendl(&buf, "\"", 1); + smart_string_appendl(&buf,"\"", 1); + smart_string_appendl(&buf, reply->str, reply->len); + smart_string_appendl(&buf, "\"", 1); break; case TYPE_MULTIBULK: if(reply->elements == (size_t)-1) { - smart_str_appendl(&buf, "(nil)", sizeof("(nil)")-1); + smart_string_appendl(&buf, "(nil)", sizeof("(nil)")-1); } else { for(i=0;ielements;i++) { dump_reply(reply->element[i], indent+2); @@ -80,7 +79,7 @@ static void dump_reply(clusterReply *reply, int indent) { php_printf(" "); } - smart_str_0(&buf); + smart_string_0(&buf); php_printf("%s", buf.c); php_printf("\n"); @@ -137,7 +136,8 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements, switch(r->type) { case TYPE_ERR: case TYPE_LINE: - if(redis_sock_gets(sock,buf,sizeof(buf),&r->len TSRMLS_CC)<0) { + //TODO Sean-Der + if(redis_sock_gets(sock, buf, sizeof(buf), (size_t *) &r->len) < 0) { *err = 1; return; } @@ -174,7 +174,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements, static RedisSock *cluster_slot_sock(redisCluster *c, unsigned short slot, ulong slaveidx) { - redisClusterNode **node; + redisClusterNode *node; /* Return the master if we're not looking for a slave */ if (slaveidx == 0) { @@ -182,11 +182,11 @@ static RedisSock *cluster_slot_sock(redisCluster *c, unsigned short slot, } /* Abort if we can't find this slave */ - if (!SLOT_SLAVES(c, slot) || zend_hash_index_find(SLOT_SLAVES(c,slot), - slaveidx, (void**)&node)==FAILURE) return NULL; + if (!SLOT_SLAVES(c, slot) || (node = zend_hash_index_find_ptr(SLOT_SLAVES(c,slot), + slaveidx)) == NULL) return NULL; /* Success, return the slave */ - return (*node)->sock; + return node->sock; } /* Read the response from a cluster */ @@ -340,7 +340,7 @@ PHP_REDIS_API int cluster_send_discard(redisCluster *c, short slot TSRMLS_DC) { * */ /* Free cluster distribution list inside a HashTable */ -static void cluster_dist_free_ht(void *p) { +static void cluster_dist_free_ht(zval *p) { clusterDistList *dl = *(clusterDistList**)p; int i; @@ -413,7 +413,7 @@ int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key, { int key_free; short slot; - clusterDistList **ppdl, *dl; + clusterDistList *ppdl, *dl; clusterKeyVal *retptr; // Prefix our key and hash it @@ -427,12 +427,11 @@ int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key, } // Look for this slot - if(zend_hash_index_find(ht, (ulong)slot, (void**)&ppdl)==FAILURE) { + if((ppdl = zend_hash_index_find_ptr(ht, (ulong)slot)) == NULL) { dl = cluster_dl_create(); - zend_hash_index_update(ht, (ulong)slot, (void**)&dl, - sizeof(clusterDistList*), NULL); + zend_hash_index_update_ptr(ht, (ulong)slot, dl); } else { - dl = *ppdl; + dl = ppdl; } // Now actually add this key @@ -476,7 +475,7 @@ void cluster_multi_add(clusterMultiCmd *mc, char *data, int data_len) { void cluster_multi_fini(clusterMultiCmd *mc) { mc->cmd.len = 0; redis_cmd_init_sstr(&(mc->cmd), mc->argc, mc->kw, mc->kw_len); - smart_str_appendl(&(mc->cmd), mc->args.c, mc->args.len); + smart_string_appendl(&(mc->cmd), mc->args.c, mc->args.len); } /* Set our last error string encountered */ @@ -506,7 +505,7 @@ static void cluster_set_err(redisCluster *c, char *err, int err_len) } /* Destructor for slaves */ -static void ht_free_slave(void *data) { +static void ht_free_slave(zval *data) { if(*(redisClusterNode**)data) { cluster_free_node(*(redisClusterNode**)data); } @@ -670,8 +669,7 @@ cluster_node_add_slave(redisClusterNode *master, redisClusterNode *slave) index = master->slaves->nNextFreeElement; } - return zend_hash_index_update(master->slaves, index, (void*)&slave, - sizeof(redisClusterNode*), NULL) != SUCCESS; + return zend_hash_index_update_ptr(master->slaves, index, slave) != NULL; } /* Sanity check/validation for CLUSTER SLOTS command */ @@ -687,7 +685,7 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) { int i,j, hlen, klen; short low, high; clusterReply *r2, *r3; - redisClusterNode **ppnode, *master, *slave; + redisClusterNode *pnode, *master, *slave; unsigned short port; char *host, key[1024]; @@ -712,12 +710,11 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) { // If the node is new, create and add to nodes. Otherwise use it. klen = snprintf(key,sizeof(key),"%s:%ld",host,port); - if(zend_hash_find(c->nodes,key,klen+1,(void**)&ppnode)==FAILURE) { + if( (pnode = zend_hash_str_find_ptr(c->nodes, key, klen+1)) == NULL) { master = cluster_node_create(c, host, hlen, port, low, 0); - zend_hash_update(c->nodes, key, klen+1, (void*)&master, - sizeof(redisClusterNode*), NULL); + zend_hash_str_update_ptr(c->nodes, key, klen+1, master); } else { - master = *ppnode; + master = pnode; } // Attach slaves @@ -759,7 +756,7 @@ PHP_REDIS_API void cluster_free_node(redisClusterNode *node) { /* Get or create a redisClusterNode that corresponds to the asking redirection */ static redisClusterNode *cluster_get_asking_node(redisCluster *c TSRMLS_DC) { - redisClusterNode **ppNode; + redisClusterNode *pNode; char key[1024]; int key_len; @@ -767,16 +764,16 @@ static redisClusterNode *cluster_get_asking_node(redisCluster *c TSRMLS_DC) { key_len = snprintf(key, sizeof(key), "%s:%u", c->redir_host, c->redir_port); /* See if we've already attached to it */ - if (zend_hash_find(c->nodes, key, key_len+1, (void**)&ppNode) == SUCCESS) { - return *ppNode; + if ((pNode = zend_hash_str_find_ptr(c->nodes, key, key_len+1)) != NULL) { + return pNode; } /* This host:port is unknown to us, so add it */ - *ppNode = cluster_node_create(c, c->redir_host, c->redir_host_len, + pNode = cluster_node_create(c, c->redir_host, c->redir_host_len, c->redir_port, c->redir_slot, 0); /* Return the node */ - return *ppNode; + return pNode; } /* Get or create a node at the host:port we were asked to check, and return the @@ -786,13 +783,13 @@ static RedisSock *cluster_get_asking_sock(redisCluster *c TSRMLS_DC) { } /* Our context seeds will be a hash table with RedisSock* pointers */ -static void ht_free_seed(void *data) { +static void ht_free_seed(zval *data) { RedisSock *redis_sock = *(RedisSock**)data; if(redis_sock) redis_free_socket(redis_sock); } /* Free redisClusterNode objects we've stored */ -static void ht_free_node(void *data) { +static void ht_free_node(zval *data) { redisClusterNode *node = *(redisClusterNode**)data; cluster_free_node(node); } @@ -846,7 +843,7 @@ PHP_REDIS_API void cluster_free(redisCluster *c) { if (c->err) efree(c->err); /* Free structure itself */ - efree(c); + efree(c); } /* Initialize seeds */ @@ -855,7 +852,7 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) { RedisSock *redis_sock; char *str, *psep, key[1024]; int key_len; - zval **z_seed; + zval *z_seed; // Iterate our seeds array for(zend_hash_internal_pointer_reset(ht_seeds); @@ -863,14 +860,14 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) { zend_hash_move_forward(ht_seeds)) { // Grab seed string - zend_hash_get_current_data(ht_seeds, (void**)&z_seed); + z_seed = zend_hash_get_current_data(ht_seeds); // Skip anything that isn't a string - if(Z_TYPE_PP(z_seed)!=IS_STRING) + if(Z_TYPE_P(z_seed) != IS_STRING) continue; // Grab a copy of the string - str = Z_STRVAL_PP(z_seed); + str = Z_STRVAL_P(z_seed); // Must be in host:port form if(!(psep = strchr(str, ':'))) @@ -886,8 +883,7 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) { redis_sock->port); // Add to our seed HashTable - zend_hash_update(cluster->seeds, key, key_len+1, (void*)&redis_sock, - sizeof(RedisSock*),NULL); + zend_hash_str_update_ptr(cluster->seeds, key, key_len+1, redis_sock); } // Success if at least one seed seems valid @@ -897,7 +893,7 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) { /* Initial mapping of our cluster keyspace */ PHP_REDIS_API int cluster_map_keyspace(redisCluster *c TSRMLS_DC) { - RedisSock **seed; + RedisSock *seed; clusterReply *slots=NULL; int mapped=0; @@ -907,15 +903,15 @@ cluster_map_keyspace(redisCluster *c TSRMLS_DC) { zend_hash_move_forward(c->seeds)) { // Grab the redis_sock for this seed - zend_hash_get_current_data(c->seeds, (void**)&seed); + seed = zend_hash_get_current_data_ptr(c->seeds); // Attempt to connect to this seed node - if(redis_sock_connect(*seed TSRMLS_CC)!=0) { + if(redis_sock_connect(seed TSRMLS_CC)!=0) { continue; } // Parse out cluster nodes. Flag mapped if we are valid - slots = cluster_get_slots(*seed TSRMLS_CC); + slots = cluster_get_slots(seed TSRMLS_CC); if(slots) mapped = !cluster_map_slots(c, slots); // Bin anything mapped, if we failed somewhere @@ -1039,14 +1035,14 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type /* Disconnect from each node we're connected to */ PHP_REDIS_API void cluster_disconnect(redisCluster *c TSRMLS_DC) { - redisClusterNode **node; + redisClusterNode *node; for(zend_hash_internal_pointer_reset(c->nodes); - zend_hash_get_current_data(c->nodes, (void**)&node)==SUCCESS; + (node = zend_hash_get_current_data_ptr(c->nodes)) != NULL; zend_hash_move_forward(c->nodes)) { - redis_sock_disconnect((*node)->sock TSRMLS_CC); - (*node)->sock->lazy_connect = 1; + redis_sock_disconnect(node->sock TSRMLS_CC); + node->sock->lazy_connect = 1; } } @@ -1136,7 +1132,7 @@ static int cluster_dist_write(redisCluster *c, const char *cmd, size_t sz, static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz, int direct TSRMLS_DC) { - redisClusterNode **seed_node; + redisClusterNode *seed_node; RedisSock *redis_sock; int failover; @@ -1184,18 +1180,18 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz, zend_hash_move_forward(c->nodes)) { /* Grab node */ - zend_hash_get_current_data(c->nodes, (void**)&seed_node); + seed_node = zend_hash_get_current_data_ptr(c->nodes); /* Skip this node if it's the one that failed, or if it's a slave */ - if((*seed_node)->sock == redis_sock || (*seed_node)->slave) continue; + if(seed_node->sock == redis_sock || seed_node->slave) continue; /* Connect to this node if we haven't already */ - CLUSTER_LAZY_CONNECT((*seed_node)->sock); + CLUSTER_LAZY_CONNECT(seed_node->sock); /* Attempt to write our request to this node */ - if (CLUSTER_SEND_PAYLOAD((*seed_node)->sock, cmd, sz)) { - c->cmd_slot = (*seed_node)->slot; - c->cmd_sock = (*seed_node)->sock; + if (CLUSTER_SEND_PAYLOAD(seed_node->sock, cmd, sz)) { + c->cmd_slot = seed_node->slot; + c->cmd_sock = seed_node->sock; return 0; } } @@ -1208,14 +1204,14 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz, static redisClusterNode *cluster_find_node(redisCluster *c, const char *host, unsigned short port) { - redisClusterNode **ret = NULL; + redisClusterNode *ret = NULL; int key_len; char key[1024]; key_len = snprintf(key,sizeof(key),"%s:%d", host, port); - if(zend_hash_find(c->nodes, key, key_len+1, (void**)&ret)==SUCCESS) { - return *ret; + if((ret = zend_hash_str_find_ptr(c->nodes, key, key_len+1)) != NULL) { + return ret; } /* Not found */ @@ -1449,7 +1445,7 @@ PHP_REDIS_API void cluster_bulk_raw_resp(INTERNAL_FUNCTION_PARAMETERS, if(c->flags->mode != MULTI) { RETURN_FALSE; } else { - add_next_index_bool(c->multi_resp, 0); + add_next_index_bool(&c->multi_resp, 0); } } @@ -1482,9 +1478,9 @@ PHP_REDIS_API void cluster_bulk_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster zval *z = NULL; if (redis_unserialize(c->flags, resp, c->reply_len, &z TSRMLS_CC)) { efree(resp); - add_next_index_zval(c->multi_resp, z); + add_next_index_zval(&c->multi_resp, z); } else { - add_next_index_stringl(c->multi_resp, resp, c->reply_len, 0); + add_next_index_stringl(&c->multi_resp, resp, c->reply_len); } } } @@ -1590,35 +1586,31 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * void *ctx) { subscribeContext *sctx = (subscribeContext*)ctx; - zval *z_tab, **z_tmp, *z_ret, **z_args[4]; + zval z_tab, *z_tmp, z_ret, z_args[4]; int pull=0; // Consume each MULTI BULK response (one per channel/pattern) while(sctx->argc--) { - z_tab = cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, - pull, mbulk_resp_loop_raw); + cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, pull, mbulk_resp_loop_raw, &z_tab); - if(!z_tab) { + if(Z_TYPE(z_tab) == IS_UNDEF) { efree(sctx); RETURN_FALSE; } - if(zend_hash_index_find(Z_ARRVAL_P(z_tab),0,(void**)&z_tmp)==FAILURE || - strcasecmp(Z_STRVAL_PP(z_tmp), sctx->kw) != 0) + if((z_tmp = zend_hash_index_find(Z_ARRVAL(z_tab), 0)) == NULL || strcasecmp(Z_STRVAL_P(z_tmp), sctx->kw) != 0) { - zval_dtor(z_tab); - FREE_ZVAL(z_tab); + zval_dtor(&z_tab); efree(sctx); RETURN_FALSE; } - zval_dtor(z_tab); - efree(z_tab); + zval_dtor(&z_tab); pull = 1; } // Set up our callback pointers - sctx->cb.retval_ptr_ptr = &z_ret; + sctx->cb.retval = &z_ret; sctx->cb.params = z_args; sctx->cb.no_separation = 0; @@ -1628,56 +1620,49 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * /* Multibulk response, {[pattern], type, channel, payload} */ while(1) { /* Arguments */ - zval **z_type, **z_chan, **z_pat, **z_data; + zval *z_type, *z_chan, *z_pat, *z_data; int tab_idx=1, is_pmsg; // Get the next subscribe response - z_tab = cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, - 1, mbulk_resp_loop); + cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, 1, mbulk_resp_loop, &z_tab); - if(!z_tab || zend_hash_index_find(Z_ARRVAL_P(z_tab), 0, (void**)&z_type) - ==FAILURE) + if(Z_TYPE(z_tab) == IS_UNDEF || (z_type = zend_hash_index_find(Z_ARRVAL(z_tab), 0)) == NULL) { break; } // Make sure we have a message or pmessage - if(!strncmp(Z_STRVAL_PP(z_type), "message", 7) || - !strncmp(Z_STRVAL_PP(z_type), "pmessage", 8)) + if(!strncmp(Z_STRVAL_P(z_type), "message", 7) || + !strncmp(Z_STRVAL_P(z_type), "pmessage", 8)) { - is_pmsg = *Z_STRVAL_PP(z_type) == 'p'; + is_pmsg = *Z_STRVAL_P(z_type) == 'p'; } else { - zval_dtor(z_tab); - efree(z_tab); + zval_dtor(&z_tab); continue; } - if(is_pmsg && zend_hash_index_find(Z_ARRVAL_P(z_tab), tab_idx++, - (void**)&z_pat)==FAILURE) - { + if(is_pmsg && (z_pat = zend_hash_index_find(Z_ARRVAL(z_tab), tab_idx++)) == NULL) { break; } // Extract channel and data - if(zend_hash_index_find(Z_ARRVAL_P(z_tab), tab_idx++, - (void**)&z_chan)==FAILURE || - zend_hash_index_find(Z_ARRVAL_P(z_tab), tab_idx++, - (void**)&z_data)==FAILURE) + if((z_chan = zend_hash_index_find(Z_ARRVAL(z_tab), tab_idx++)) == NULL || + (z_data = zend_hash_index_find(Z_ARRVAL(z_tab), tab_idx++)) == NULL) { break; } // Always pass our object through - z_args[0] = &getThis(); + ZVAL_DUP(&z_args[0], getThis()); // Set up calbacks depending on type if(is_pmsg) { - z_args[1] = z_pat; - z_args[2] = z_chan; - z_args[3] = z_data; + ZVAL_DUP(&z_args[1], z_pat); + ZVAL_DUP(&z_args[2], z_chan); + ZVAL_DUP(&z_args[3], z_data); } else { - z_args[1] = z_chan; - z_args[2] = z_data; + ZVAL_DUP(&z_args[1], z_chan); + ZVAL_DUP(&z_args[2], z_data); } // Set arg count @@ -1691,10 +1676,9 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * } // If we have a return value, free it - if(z_ret) zval_ptr_dtor(&z_ret); + if(Z_TYPE(z_ret) != IS_UNDEF) zval_ptr_dtor(&z_ret); - zval_dtor(z_tab); - efree(z_tab); + zval_dtor(&z_tab); } // We're no longer subscribing, due to an error @@ -1702,9 +1686,8 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * // Cleanup efree(sctx); - if(z_tab) { - zval_dtor(z_tab); - efree(z_tab); + if(Z_TYPE(z_tab) != IS_UNDEF) { + zval_dtor(&z_tab); } // Failure @@ -1716,7 +1699,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) { subscribeContext *sctx = (subscribeContext*)ctx; - zval *z_tab, **z_chan, **z_flag; + zval z_tab, *z_chan, *z_flag; int pull = 0, argc = sctx->argc; efree(sctx); @@ -1724,39 +1707,33 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS, // Consume each response while(argc--) { - z_tab = cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, - c, pull, mbulk_resp_loop_raw); + cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, pull, mbulk_resp_loop_raw, &z_tab); // Fail if we didn't get an array or can't find index 1 - if(!z_tab || zend_hash_index_find(Z_ARRVAL_P(z_tab), 1, - (void**)&z_chan)==FAILURE) + if(Z_TYPE(z_tab) == IS_UNDEF || (z_chan = zend_hash_index_find(Z_ARRVAL(z_tab), 1)) == NULL) { - if(z_tab) { - zval_dtor(z_tab); - efree(z_tab); + if(Z_TYPE(z_tab) != IS_UNDEF) { + zval_dtor(&z_tab); } zval_dtor(return_value); RETURN_FALSE; } // Find the flag for this channel/pattern - if(zend_hash_index_find(Z_ARRVAL_P(z_tab), 2, (void**)&z_flag) - ==FAILURE || Z_STRLEN_PP(z_flag)!=2) + if((z_flag = zend_hash_index_find(Z_ARRVAL(z_tab), 2)) == NULL || Z_STRLEN_P(z_flag) != 2) { - zval_dtor(z_tab); - efree(z_tab); + zval_dtor(&z_tab); zval_dtor(return_value); RETURN_FALSE; } // Redis will give us either :1 or :0 here - char *flag = Z_STRVAL_PP(z_flag); + char *flag = Z_STRVAL_P(z_flag); // Add result - add_assoc_bool(return_value, Z_STRVAL_PP(z_chan), flag[1]=='1'); + add_assoc_bool(return_value, Z_STRVAL_P(z_chan), flag[1]=='1'); - zval_dtor(z_tab); - efree(z_tab); + zval_dtor(&z_tab); pull = 1; } } @@ -1764,7 +1741,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS, /* Recursive MULTI BULK -> PHP style response handling */ static void cluster_mbulk_variant_resp(clusterReply *r, zval *z_ret) { - zval *z_sub_ele; + zval z_sub_ele; int i; switch(r->type) { @@ -1776,17 +1753,16 @@ static void cluster_mbulk_variant_resp(clusterReply *r, zval *z_ret) break; case TYPE_BULK: if (r->len > -1) - add_next_index_stringl(z_ret, r->str, r->len, 0); + add_next_index_stringl(z_ret, r->str, r->len); else add_next_index_null(z_ret); break; case TYPE_MULTIBULK: - MAKE_STD_ZVAL(z_sub_ele); - array_init(z_sub_ele); + array_init(&z_sub_ele); for(i=0;ielements;i++) { - cluster_mbulk_variant_resp(r->element[i], z_sub_ele); + cluster_mbulk_variant_resp(r->element[i], &z_sub_ele); } - add_next_index_zval(z_ret, z_sub_ele); + add_next_index_zval(z_ret, &z_sub_ele); break; default: add_next_index_bool(z_ret, 0); @@ -1800,7 +1776,7 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust void *ctx) { clusterReply *r; - zval *z_arr; + zval z_arr; int i; // Make sure we can read it @@ -1821,18 +1797,16 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust RETVAL_TRUE; break; case TYPE_BULK: - RETVAL_STRINGL(r->str, r->len, 0); + RETVAL_STRINGL(r->str, r->len); break; case TYPE_MULTIBULK: - MAKE_STD_ZVAL(z_arr); - array_init(z_arr); + array_init(&z_arr); for(i=0;ielements;i++) { - cluster_mbulk_variant_resp(r->element[i], z_arr); + cluster_mbulk_variant_resp(r->element[i], &z_arr); } - *return_value = *z_arr; - efree(z_arr); + ZVAL_DUP(return_value, &z_arr); break; default: RETVAL_FALSE; @@ -1841,22 +1815,22 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust } else { switch(r->type) { case TYPE_INT: - add_next_index_long(c->multi_resp, r->integer); + add_next_index_long(&c->multi_resp, r->integer); break; case TYPE_ERR: - add_next_index_bool(c->multi_resp, 0); + add_next_index_bool(&c->multi_resp, 0); break; case TYPE_LINE: - add_next_index_bool(c->multi_resp, 1); + add_next_index_bool(&c->multi_resp, 1); break; case TYPE_BULK: - add_next_index_stringl(c->multi_resp, r->str, r->len, 0); + add_next_index_stringl(&c->multi_resp, r->str, r->len); break; case TYPE_MULTIBULK: - cluster_mbulk_variant_resp(r, c->multi_resp); + cluster_mbulk_variant_resp(r, &c->multi_resp); break; default: - add_next_index_bool(c->multi_resp, 0); + add_next_index_bool(&c->multi_resp, 0); break; } } @@ -1869,7 +1843,7 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, mbulk_cb cb, void *ctx) { - zval *z_result; + zval z_result; /* Return FALSE if we didn't get a multi-bulk response */ if (c->reply_type != TYPE_MULTIBULK) { @@ -1877,8 +1851,7 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, } /* Allocate our array */ - MAKE_STD_ZVAL(z_result); - array_init(z_result); + array_init(&z_result); /* Consume replies as long as there are more than zero */ if (c->reply_len > 0) { @@ -1886,19 +1859,17 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, c->cmd_sock->serializer = c->flags->serializer; /* Call our specified callback */ - if (cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) { - zval_dtor(z_result); - FREE_ZVAL(z_result); + if (cb(c->cmd_sock, &z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) { + zval_dtor(&z_result); CLUSTER_RETURN_FALSE(c); } } // Success, make this array our return value if(CLUSTER_IS_ATOMIC(c)) { - *return_value = *z_result; - efree(z_result); + ZVAL_DUP(return_value, &z_result); } else { - add_next_index_zval(c->multi_resp, z_result); + add_next_index_zval(&c->multi_resp, &z_result); } } @@ -1963,7 +1934,7 @@ PHP_REDIS_API int cluster_scan_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) { - zval *z_result; + zval z_result; char *info; // Read our bulk response @@ -1973,15 +1944,14 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster } /* Parse response, free memory */ - z_result = redis_parse_info_response(info); + redis_parse_info_response(info, &z_result); efree(info); // Return our array if(CLUSTER_IS_ATOMIC(c)) { - *return_value = *z_result; - efree(z_result); + ZVAL_DUP(return_value, &z_result); } else { - add_next_index_zval(c->multi_resp, z_result); + add_next_index_zval(&c->multi_resp, &z_result); } } @@ -1989,7 +1959,7 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster PHP_REDIS_API void cluster_client_list_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) { - zval *z_result; + zval z_result; char *info; /* Read the bulk response */ @@ -1999,55 +1969,51 @@ PHP_REDIS_API void cluster_client_list_resp(INTERNAL_FUNCTION_PARAMETERS, redisC } /* Parse it and free the bulk string */ - z_result = redis_parse_client_list_response(info); + redis_parse_client_list_response(info, &z_result); efree(info); if (CLUSTER_IS_ATOMIC(c)) { - *return_value = *z_result; - efree(z_result); + ZVAL_DUP(return_value, &z_result); } else { - add_next_index_zval(c->multi_resp, z_result); + add_next_index_zval(&c->multi_resp, &z_result); } } /* MULTI BULK response loop where we might pull the next one */ -PHP_REDIS_API zval *cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, - redisCluster *c, int pull, mbulk_cb cb) +PHP_REDIS_API void cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, + redisCluster *c, int pull, mbulk_cb cb, zval *z_result) { - zval *z_result; - // Pull our next response if directed if(pull) { if(cluster_check_response(c, &c->reply_type TSRMLS_CC)<0) { - return NULL; + ZVAL_UNDEF(z_result); + return; } } // Validate reply type and length if(c->reply_type != TYPE_MULTIBULK || c->reply_len == -1) { - return NULL; + ZVAL_UNDEF(z_result); + return; } - MAKE_STD_ZVAL(z_result); array_init(z_result); // Call our callback if(cb(c->cmd_sock, z_result, c->reply_len, NULL TSRMLS_CC)==FAILURE) { - zval_dtor(z_result); - FREE_ZVAL(z_result); - return NULL; + ZVAL_UNDEF(z_result); + return; } - return z_result; + return; } /* MULTI MULTI BULK reply (for EXEC) */ PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) { - MAKE_STD_ZVAL(c->multi_resp); - array_init(c->multi_resp); + array_init(&c->multi_resp); clusterFoldItem *fi = c->multi_head; while(fi) { @@ -2060,23 +2026,22 @@ PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, c->cmd_sock = SLOT_SOCK(c, fi->slot); if(cluster_check_response(c, &c->reply_type TSRMLS_CC)<0) { - zval_dtor(c->multi_resp); - efree(c->multi_resp); + zval_dtor(&c->multi_resp); RETURN_FALSE; } fi->callback(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, fi->ctx); } else { /* Just add false */ - add_next_index_bool(c->multi_resp, 0); + add_next_index_bool(&c->multi_resp, 0); } fi = fi->next; } // Set our return array zval_dtor(return_value); - *return_value = *c->multi_resp; - efree(c->multi_resp); + ZVAL_DUP(return_value, &c->multi_resp); + zval_dtor(&c->multi_resp); } /* Generic handler for MGET */ @@ -2105,7 +2070,7 @@ PHP_REDIS_API void cluster_mbulk_mget_resp(INTERNAL_FUNCTION_PARAMETERS, *return_value = *(mctx->z_multi); efree(mctx->z_multi); } else { - add_next_index_zval(c->multi_resp, mctx->z_multi); + add_next_index_zval(&c->multi_resp, mctx->z_multi); } } @@ -2141,7 +2106,7 @@ PHP_REDIS_API void cluster_msetnx_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluste *return_value = *(mctx->z_multi); efree(mctx->z_multi); } else { - add_next_index_zval(c->multi_resp, mctx->z_multi); + add_next_index_zval(&c->multi_resp, mctx->z_multi); } } @@ -2170,7 +2135,7 @@ PHP_REDIS_API void cluster_del_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster * if(CLUSTER_IS_ATOMIC(c)) { ZVAL_LONG(return_value, Z_LVAL_P(mctx->z_multi)); } else { - add_next_index_long(c->multi_resp, Z_LVAL_P(mctx->z_multi)); + add_next_index_long(&c->multi_resp, Z_LVAL_P(mctx->z_multi)); } efree(mctx->z_multi); } @@ -2198,9 +2163,9 @@ PHP_REDIS_API void cluster_mset_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster // Set our return if it's the last call if(mctx->last) { if(CLUSTER_IS_ATOMIC(c)) { - ZVAL_BOOL(return_value, Z_BVAL_P(mctx->z_multi)); + ZVAL_BOOL(return_value, Z_TYPE_P(mctx->z_multi) == IS_TRUE); } else { - add_next_index_bool(c->multi_resp, Z_BVAL_P(mctx->z_multi)); + add_next_index_bool(&c->multi_resp, Z_TYPE_P(mctx->z_multi) == IS_TRUE); } efree(mctx->z_multi); } @@ -2270,7 +2235,7 @@ int mbulk_resp_loop_raw(RedisSock *redis_sock, zval *z_result, if(line == NULL) return FAILURE; // Add to our result array - add_next_index_stringl(z_result, line, line_len, 0); + add_next_index_stringl(z_result, line, line_len); } // Success! @@ -2288,14 +2253,14 @@ int mbulk_resp_loop(RedisSock *redis_sock, zval *z_result, while(count--) { /* Read our line */ line = redis_sock_read(redis_sock, &line_len TSRMLS_CC); - + if (line != NULL) { zval *z = NULL; if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) { add_next_index_zval(z_result, z); efree(line); } else { - add_next_index_stringl(z_result, line, line_len, 0); + add_next_index_stringl(z_result, line, line_len); } } else { if (line) efree(line); @@ -2337,7 +2302,7 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result, efree(line); } else { add_assoc_stringl_ex(z_result, key, 1+key_len, line, - line_len, 0); + line_len); } efree(key); } @@ -2407,7 +2372,7 @@ int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result, 1+Z_STRLEN_P(z_keys[i]), z); } else { add_assoc_stringl_ex(z_result, Z_STRVAL_P(z_keys[i]), - 1+Z_STRLEN_P(z_keys[i]), line, line_len, 0); + 1+Z_STRLEN_P(z_keys[i]), line, line_len); } } else { add_assoc_bool_ex(z_result, Z_STRVAL_P(z_keys[i]), -- cgit v1.2.3