Skip to content

Commit fd687b7

Browse files
committed
More work
1 parent 8326adb commit fd687b7

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

php_memcached.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,16 @@ PHP_INI_MH(OnUpdateSessionPrefixString)
326326
static
327327
PHP_INI_MH(OnUpdateConsistentHash)
328328
{
329-
if (!strcmp(ZSTR_VAL(new_value), "ketama")) {
330-
MEMC_SESS_INI(consistent_hash_type) = MEMCACHED_BEHAVIOR_KETAMA;
329+
if (!new_value) {
330+
MEMC_SESS_INI(consistent_hash_type) = MEMCACHED_BEHAVIOR_KETAMA;
331+
} else if (!strcmp(ZSTR_VAL(new_value), "ketama")) {
332+
MEMC_SESS_INI(consistent_hash_type) = MEMCACHED_BEHAVIOR_KETAMA;
331333
} else if (!strcmp(ZSTR_VAL(new_value), "ketama_weighted")) {
332-
MEMC_SESS_INI(consistent_hash_type) = MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
334+
MEMC_SESS_INI(consistent_hash_type) = MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
333335
} else {
336+
php_error_docref(NULL, E_WARNING, "memcached.consistent_has_type must be ketama or ketama_weighted");
334337
return FAILURE;
335338
}
336-
337339
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
338340
}
339341

@@ -371,7 +373,7 @@ PHP_INI_BEGIN()
371373
MEMC_SESSION_INI_BOOL ("binary_protocol", "1", OnUpdateBool, binary_protocol_enabled)
372374
#endif
373375
MEMC_SESSION_INI_BOOL ("consistent_hash", "1", OnUpdateBool, consistent_hash_enabled)
374-
MEMC_SESSION_INI_BOOL ("consistent_hash_type", "ketama", OnUpdateConsistentHash, consistent_hash_type)
376+
MEMC_SESSION_INI_ENTRY("consistent_hash_type", "ketama", OnUpdateConsistentHash, consistent_hash_type)
375377
MEMC_SESSION_INI_ENTRY("number_of_replicas", "0", OnUpdateLongGEZero, number_of_replicas)
376378
MEMC_SESSION_INI_BOOL ("randomize_replica_read", "0", OnUpdateBool, randomize_replica_read_enabled)
377379
MEMC_SESSION_INI_BOOL ("remove_failed_servers", "0", OnUpdateBool, remove_failed_servers_enabled)

php_memcached_private.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ typedef unsigned long int uint32_t;
7979
# define GC_SET_REFCOUNT(p, rc) GC_REFCOUNT(p) = rc
8080
#endif
8181

82-
/* Globals accessor macros */
83-
#ifdef ZTS
84-
# define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
85-
# define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
86-
# define MEMC_SESS_INI(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, session.v)
87-
#else
88-
# define MEMC_G(v) (php_memcached_globals.memc.v)
89-
# define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
90-
# define MEMC_SESS_INI(v) (php_memcached_globals.session.v)
91-
#endif
92-
93-
#define MEMC_SESS_STR_INI(vv) ((MEMC_SESS_INI(vv) && *MEMC_SESS_INI(vv)) ? MEMC_SESS_INI(vv) : NULL)
94-
9582
/****************************************
9683
Structures and definitions
9784
****************************************/
@@ -169,7 +156,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
169156

170157
zend_bool binary_protocol_enabled;
171158
zend_bool consistent_hash_enabled;
172-
zend_bool consistent_hash_type;
159+
int consistent_hash_type;
173160

174161
zend_long server_failure_limit;
175162
zend_long number_of_replicas;
@@ -221,6 +208,19 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
221208

222209
ZEND_END_MODULE_GLOBALS(php_memcached)
223210

211+
/* Globals accessor macros */
212+
#ifdef ZTS
213+
# define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
214+
# define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
215+
# define MEMC_SESS_INI(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, session.v)
216+
#else
217+
# define MEMC_G(v) (php_memcached_globals.memc.v)
218+
# define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
219+
# define MEMC_SESS_INI(v) (php_memcached_globals.session.v)
220+
#endif
221+
222+
#define MEMC_SESS_STR_INI(vv) ((MEMC_SESS_INI(vv) && *MEMC_SESS_INI(vv)) ? MEMC_SESS_INI(vv) : NULL)
223+
224224
PHP_RINIT_FUNCTION(memcached);
225225
PHP_RSHUTDOWN_FUNCTION(memcached);
226226
PHP_MINIT_FUNCTION(memcached);

php_memcached_session.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ static
179179
zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
180180
{
181181
#define check_set_behavior(behavior, value) \
182-
if ((value) != memcached_behavior_get(memc, (behavior))) { \
182+
int b = (behavior); \
183+
uint64_t v = (value); \
184+
if (v != memcached_behavior_get(memc, b)) { \
183185
memcached_return rc; \
184-
if ((rc = memcached_behavior_set(memc, (behavior), (value))) != MEMCACHED_SUCCESS) { \
186+
if ((rc = memcached_behavior_set(memc, b, v)) != MEMCACHED_SUCCESS) { \
185187
if (!silent) { \
186188
php_error_docref(NULL, E_WARNING, "failed to initialise session memcached configuration: %s", memcached_strerror(memc, rc)); \
187189
} \

0 commit comments

Comments
 (0)