2020#include <ext/standard/php_math.h>
2121#include <ext/standard/php_rand.h>
2222
23- #ifdef PHP_WIN32
24- # if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION <= 4
25- /* This proto is available from 5.5 on only */
26- PHPAPI int usleep (unsigned int useconds );
27- # endif
28- #endif
29-
3023#define UNSERIALIZE_NONE 0
3124#define UNSERIALIZE_KEYS 1
3225#define UNSERIALIZE_VALS 2
@@ -130,12 +123,12 @@ static void redis_error_throw(char *err, size_t err_len TSRMLS_DC) {
130123 }
131124}
132125
133- PHP_REDIS_API void redis_stream_close (RedisSock * redis_sock TSRMLS_DC ) {
134- if (!redis_sock -> persistent ) {
135- php_stream_close (redis_sock -> stream );
136- } else {
137- php_stream_pclose (redis_sock -> stream );
138- }
126+ PHPAPI void redis_stream_close (RedisSock * redis_sock TSRMLS_DC ) {
127+ if (!redis_sock -> persistent ) {
128+ php_stream_close (redis_sock -> stream );
129+ } else {
130+ php_stream_pclose (redis_sock -> stream );
131+ }
139132}
140133
141134PHP_REDIS_API int redis_check_eof (RedisSock * redis_sock , int no_throw TSRMLS_DC )
@@ -509,7 +502,8 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
509502 redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
510503 redis_sock -> mode = ATOMIC ;
511504 redis_sock -> watching = 0 ;
512- zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
505+ zend_throw_exception (redis_exception_ce , "read error on connection" ,
506+ 0 TSRMLS_CC );
513507 return NULL ;
514508 }
515509
@@ -1086,8 +1080,7 @@ PHPAPI zval* redis_parse_client_list_response(char *response) {
10861080 } else {
10871081 add_assoc_string (z_sub_result , key , value , 0 );
10881082 }
1089-
1090- /* If we hit a '\n', then we can add this user to our list */
1083+ // If we hit a '\n', then we can add this user to our list
10911084 if (* p == '\n' ) {
10921085 /* Add our user */
10931086 add_next_index_zval (z_result , z_sub_result );
@@ -1099,7 +1092,7 @@ PHPAPI zval* redis_parse_client_list_response(char *response) {
10991092 }
11001093 }
11011094
1102- /* Free our key */
1095+ // Free our key
11031096 efree (key );
11041097 } else {
11051098 // Something is wrong
@@ -1384,9 +1377,10 @@ PHPAPI int redis_mbulk_reply_zipped_vals(INTERNAL_FUNCTION_PARAMETERS, RedisSock
13841377 z_tab , UNSERIALIZE_VALS , SCORE_DECODE_NONE );
13851378}
13861379
1387- PHPAPI void redis_1_response (INTERNAL_FUNCTION_PARAMETERS ,
1388- RedisSock * redis_sock , zval * z_tab , void * ctx )
1380+ PHP_REDIS_API void redis_1_response (INTERNAL_FUNCTION_PARAMETERS ,
1381+ RedisSock * redis_sock , zval * z_tab , void * ctx )
13891382{
1383+
13901384 char * response ;
13911385 int response_len ;
13921386 char ret ;
@@ -1765,23 +1759,23 @@ PHPAPI int redis_sock_set_err(RedisSock *redis_sock, const char *msg,
17651759 redis_sock -> err = erealloc (redis_sock -> err , msg_len + 1 );
17661760 }
17671761
1768- /* Copy in our new error message, set new length, and null terminate */
1769- memcpy (redis_sock -> err , msg , msg_len );
1770- redis_sock -> err [msg_len ] = '\0' ;
1771- redis_sock -> err_len = msg_len ;
1772- } else {
1773- /* Free our last error */
1774- if (redis_sock -> err != NULL ) {
1775- efree (redis_sock -> err );
1776- }
1762+ // Copy in our new error message, set new length, and null terminate
1763+ memcpy (redis_sock -> err , msg , msg_len );
1764+ redis_sock -> err [msg_len ] = '\0' ;
1765+ redis_sock -> err_len = msg_len ;
1766+ } else {
1767+ // Free our last error
1768+ if (redis_sock -> err != NULL ) {
1769+ efree (redis_sock -> err );
1770+ }
17771771
1778- /* Set to null, with zero length */
1779- redis_sock -> err = NULL ;
1780- redis_sock -> err_len = 0 ;
1781- }
1772+ // Set to null, with zero length
1773+ redis_sock -> err = NULL ;
1774+ redis_sock -> err_len = 0 ;
1775+ }
17821776
1783- /* Success */
1784- return 0 ;
1777+ // Success
1778+ return 0 ;
17851779}
17861780
17871781/**
@@ -1813,12 +1807,10 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
18131807 IF_MULTI_OR_PIPELINE () {
18141808 add_next_index_bool (z_tab , 0 );
18151809 } else {
1816- /* Capture our error if redis has given us one */
18171810 if (inbuf [0 ] == '-' ) {
18181811 err_len = strlen (inbuf + 1 ) - 2 ;
18191812 redis_sock_set_err (redis_sock , inbuf + 1 , err_len );
18201813 }
1821-
18221814 RETVAL_FALSE ;
18231815 }
18241816 return -1 ;
@@ -2147,14 +2139,16 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
21472139
21482140 case REDIS_SERIALIZER_IGBINARY :
21492141#ifdef HAVE_REDIS_IGBINARY
2150- if (!* return_value ) {
2151- MAKE_STD_ZVAL (* return_value );
2152- rv_free = 1 ;
2153- }
2154- if (igbinary_unserialize ((const uint8_t * )val , (size_t )val_len , return_value TSRMLS_CC ) == 0 ) {
2155- return 1 ;
2156- }
2157- if (rv_free == 1 ) efree (* return_value );
2142+ if (!* return_value ) {
2143+ MAKE_STD_ZVAL (* return_value );
2144+ rv_free = 1 ;
2145+ }
2146+ if (igbinary_unserialize ((const uint8_t * )val , (size_t )val_len ,
2147+ return_value TSRMLS_CC ) == 0 )
2148+ {
2149+ return 1 ;
2150+ }
2151+ if (rv_free == 1 ) efree (* return_value );
21582152#endif
21592153 return 0 ;
21602154 break ;
0 commit comments