@@ -164,7 +164,7 @@ ra_find_name(const char *name) {
164164/* laod array from INI settings */
165165RedisArray * ra_load_array (const char * name TSRMLS_DC ) {
166166
167- zval * z_data , z_fun , z_dist , z_algo ;
167+ zval * z_data , z_fun , z_dist ;
168168 zval z_params_hosts ;
169169 zval z_params_prev ;
170170 zval z_params_funs ;
@@ -180,6 +180,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
180180 zval z_params_consistent ;
181181 RedisArray * ra = NULL ;
182182
183+ zend_string * algorithm = NULL ;
183184 zend_bool b_index = 0 , b_autorehash = 0 , b_pconnect = 0 , consistent = 0 ;
184185 long l_retry_interval = 0 ;
185186 zend_bool b_lazy_connect = 0 ;
@@ -235,9 +236,8 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
235236 if ((iptr = INI_STR ("redis.arrays.algorithm" )) != NULL ) {
236237 sapi_module .treat_data (PARSE_STRING , estrdup (iptr ), & z_params_algo TSRMLS_CC );
237238 }
238- ZVAL_NULL (& z_algo );
239239 if ((z_data = zend_hash_str_find (Z_ARRVAL (z_params_algo ), name , name_len )) != NULL ) {
240- ZVAL_ZVAL ( & z_algo , z_data , 1 , 0 );
240+ algorithm = zval_get_string ( z_data );
241241 }
242242
243243 /* find index option */
@@ -340,13 +340,15 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
340340
341341
342342 /* create RedisArray object */
343- ra = ra_make_array (hHosts , & z_fun , & z_dist , & z_algo , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect , d_connect_timeout , read_timeout , consistent TSRMLS_CC );
343+ ra = ra_make_array (hHosts , & z_fun , & z_dist , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect , d_connect_timeout , read_timeout , consistent , algorithm TSRMLS_CC );
344344 if (ra ) {
345345 ra -> auto_rehash = b_autorehash ;
346346 if (ra -> prev ) ra -> prev -> auto_rehash = b_autorehash ;
347347 }
348348
349349 /* cleanup */
350+ if (algorithm ) zend_string_release (algorithm );
351+
350352 zval_dtor (& z_params_hosts );
351353 zval_dtor (& z_params_prev );
352354 zval_dtor (& z_params_funs );
@@ -360,7 +362,6 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
360362 zval_dtor (& z_params_read_timeout );
361363 zval_dtor (& z_params_lazy_connect );
362364 zval_dtor (& z_params_consistent );
363- zval_dtor (& z_algo );
364365 zval_dtor (& z_dist );
365366 zval_dtor (& z_fun );
366367
@@ -408,7 +409,7 @@ ra_make_continuum(zend_string **hosts, int nb_hosts)
408409}
409410
410411RedisArray *
411- ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , zval * z_algo , HashTable * hosts_prev , zend_bool b_index , zend_bool b_pconnect , long retry_interval , zend_bool b_lazy_connect , double connect_timeout , double read_timeout , zend_bool consistent TSRMLS_DC ) {
412+ ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , HashTable * hosts_prev , zend_bool b_index , zend_bool b_pconnect , long retry_interval , zend_bool b_lazy_connect , double connect_timeout , double read_timeout , zend_bool consistent , zend_string * algorithm TSRMLS_DC ) {
412413
413414 int i , count ;
414415 RedisArray * ra ;
@@ -418,7 +419,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
418419 /* create object */
419420 ra = emalloc (sizeof (RedisArray ));
420421 ra -> hosts = ecalloc (count , sizeof (* ra -> hosts ));
421- ra -> redis = ecalloc (count , sizeof (zval ));
422+ ra -> redis = ecalloc (count , sizeof (* ra -> redis ));
422423 ra -> count = 0 ;
423424 ra -> z_multi_exec = NULL ;
424425 ra -> index = b_index ;
@@ -427,6 +428,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
427428 ra -> connect_timeout = connect_timeout ;
428429 ra -> read_timeout = read_timeout ;
429430 ra -> continuum = NULL ;
431+ ra -> algorithm = NULL ;
430432
431433 if (ra_load_hosts (ra , hosts , retry_interval , b_lazy_connect TSRMLS_CC ) == NULL || !ra -> count ) {
432434 for (i = 0 ; i < ra -> count ; ++ i ) {
@@ -438,15 +440,15 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
438440 efree (ra );
439441 return NULL ;
440442 }
441- ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , z_algo , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect , connect_timeout , read_timeout , consistent TSRMLS_CC ) : NULL ;
443+ ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect , connect_timeout , read_timeout , consistent , algorithm TSRMLS_CC ) : NULL ;
442444
443445 /* init array data structures */
444446 ra_init_function_table (ra );
445447
446448 /* Set hash function and distribtor if provided */
447449 ZVAL_ZVAL (& ra -> z_fun , z_fun , 1 , 0 );
448450 ZVAL_ZVAL (& ra -> z_dist , z_dist , 1 , 0 );
449- ZVAL_ZVAL ( & ra -> z_algo , z_algo , 1 , 0 );
451+ if ( algorithm ) ra -> algorithm = zend_string_copy ( algorithm );
450452
451453 /* init continuum */
452454 if (consistent ) {
@@ -552,7 +554,7 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
552554 const php_hash_ops * ops ;
553555
554556 /* hash */
555- if (Z_TYPE ( ra -> z_algo ) == IS_STRING && (ops = php_hash_fetch_ops (Z_STRVAL (ra -> z_algo ), Z_STRLEN (ra -> z_algo ))) != NULL ) {
557+ if (ra -> algorithm && (ops = php_hash_fetch_ops (ZSTR_VAL (ra -> algorithm ), ZSTR_LEN (ra -> algorithm ))) != NULL ) {
556558 void * ctx = emalloc (ops -> context_size );
557559 unsigned char * digest = emalloc (ops -> digest_size );
558560
0 commit comments