Skip to content

Commit c564fd8

Browse files
arjenscholsodabrew
authored andcommitted
Cleanup all checks for unsupported libmemcached versions (#295)
1 parent 7f6c333 commit c564fd8

7 files changed

+17
-153
lines changed

Diff for: config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ if test "$PHP_MEMCACHED" != "no"; then
318318
AC_DEFINE(HAVE_MEMCACHED_EXIST, [1], [Whether memcached_exist is defined])
319319
fi
320320

321-
PHP_MEMCACHED_FILES="php_memcached.c php_libmemcached_compat.c g_fmt.c"
321+
PHP_MEMCACHED_FILES="php_memcached.c g_fmt.c"
322322

323323
if test "$PHP_SYSTEM_FASTLZ" != "no"; then
324324
AC_CHECK_HEADERS([fastlz.h], [ac_cv_have_fastlz="yes"], [ac_cv_have_fastlz="no"])

Diff for: package.xml

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ Tests
7272
<file role='src' name='php_memcached_private.h'/>
7373
<file role='src' name='php_memcached_session.c'/>
7474
<file role='src' name='php_memcached_session.h'/>
75-
<file role='src' name='php_libmemcached_compat.h'/>
76-
<file role='src' name='php_libmemcached_compat.c'/>
7775
<file role='src' name='php_memcached_server.h'/>
7876
<file role='src' name='php_memcached_server.c'/>
7977
<file role='src' name='g_fmt.c'/>

Diff for: php_libmemcached_compat.c

-37
This file was deleted.

Diff for: php_libmemcached_compat.h

-59
This file was deleted.

Diff for: php_memcached.c

+8-50
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,6 @@ PHP_METHOD(Memcached, setByKey)
17531753
}
17541754
/* }}} */
17551755

1756-
#ifdef HAVE_MEMCACHED_TOUCH
17571756
/* {{{ Memcached::touch(string key, [, int expiration ])
17581757
Sets a new expiration for the given key */
17591758
PHP_METHOD(Memcached, touch)
@@ -1769,8 +1768,6 @@ PHP_METHOD(Memcached, touchByKey)
17691768
php_memc_store_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, MEMC_OP_TOUCH, 1);
17701769
}
17711770
/* }}} */
1772-
#endif
1773-
17741771

17751772
/* {{{ Memcached::setMulti(array items [, int expiration ])
17761773
Sets the keys/values specified in the items array */
@@ -2305,17 +2302,7 @@ PHP_METHOD(Memcached, addServer)
23052302
MEMC_METHOD_FETCH_OBJECT;
23062303
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
23072304

2308-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000002
2309-
if (ZSTR_VAL(host)[0] == '/') { /* unix domain socket */
2310-
status = memcached_server_add_unix_socket_with_weight(intern->memc, ZSTR_VAL(host), weight);
2311-
} else if (memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_USE_UDP)) {
2312-
status = memcached_server_add_udp_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
2313-
} else {
2314-
status = memcached_server_add_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
2315-
}
2316-
#else
23172305
status = memcached_server_add_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
2318-
#endif
23192306

23202307
if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
23212308
RETURN_FALSE;
@@ -2511,7 +2498,6 @@ PHP_METHOD(Memcached, flushBuffers)
25112498
}
25122499
/* }}} */
25132500

2514-
#ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
25152501
/* {{{ Memcached::getLastErrorMessage()
25162502
Returns the last error message that occurred */
25172503
PHP_METHOD(Memcached, getLastErrorMessage)
@@ -2559,7 +2545,6 @@ PHP_METHOD(Memcached, getLastErrorErrno)
25592545
RETURN_LONG(memcached_last_error_errno(intern->memc));
25602546
}
25612547
/* }}} */
2562-
#endif
25632548

25642549
/* {{{ Memcached::getLastDisconnectedServer()
25652550
Returns the last disconnected server
@@ -2794,11 +2779,7 @@ static PHP_METHOD(Memcached, getOption)
27942779

27952780
result = memcached_callback_get(intern->memc, MEMCACHED_CALLBACK_PREFIX_KEY, &retval);
27962781
if (retval == MEMCACHED_SUCCESS && result) {
2797-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2798-
RETURN_STRINGL(result, strlen(result));
2799-
#else
28002782
RETURN_STRING(result);
2801-
#endif
28022783
} else {
28032784
RETURN_EMPTY_STRING();
28042785
}
@@ -2863,23 +2844,11 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
28632844
{
28642845
zend_string *str;
28652846
char *key;
2866-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2867-
char tmp[MEMCACHED_PREFIX_KEY_MAX_SIZE - 1];
2868-
#endif
28692847
str = zval_get_string(value);
28702848
if (ZSTR_LEN(str) == 0) {
28712849
key = NULL;
28722850
} else {
2873-
/*
2874-
work-around a bug in libmemcached in version 0.49 that truncates the trailing
2875-
character of the key prefix, to avoid the issue we pad it with a '0'
2876-
*/
2877-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
2878-
snprintf(tmp, sizeof(tmp), "%s0", ZSTR_VAL(str));
2879-
key = tmp;
2880-
#else
28812851
key = ZSTR_VAL(str);
2882-
#endif
28832852
}
28842853
if (memcached_callback_set(intern->memc, MEMCACHED_CALLBACK_PREFIX_KEY, key) == MEMCACHED_BAD_KEY_PROVIDED) {
28852854
zend_string_release(str);
@@ -2908,14 +2877,9 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
29082877
* (non-weighted) case. We have to clean up ourselves.
29092878
*/
29102879
if (!lval) {
2911-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX > 0x00037000
2912-
(void)memcached_behavior_set_key_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
2913-
(void)memcached_behavior_set_distribution_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
2914-
(void)memcached_behavior_set_distribution(intern->memc, MEMCACHED_DISTRIBUTION_MODULA);
2915-
#else
2916-
intern->memc->hash = 0;
2917-
intern->memc->distribution = 0;
2918-
#endif
2880+
(void)memcached_behavior_set_key_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
2881+
(void)memcached_behavior_set_distribution_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
2882+
(void)memcached_behavior_set_distribution(intern->memc, MEMCACHED_DISTRIBUTION_MODULA);
29192883
}
29202884
break;
29212885

@@ -3997,10 +3961,10 @@ static zend_function_entry memcached_class_methods[] = {
39973961

39983962
MEMC_ME(set, arginfo_set)
39993963
MEMC_ME(setByKey, arginfo_setByKey)
4000-
#ifdef HAVE_MEMCACHED_TOUCH
3964+
40013965
MEMC_ME(touch, arginfo_touch)
40023966
MEMC_ME(touchByKey, arginfo_touchByKey)
4003-
#endif
3967+
40043968
MEMC_ME(setMulti, arginfo_setMulti)
40053969
MEMC_ME(setMultiByKey, arginfo_setMultiByKey)
40063970

@@ -4032,11 +3996,10 @@ static zend_function_entry memcached_class_methods[] = {
40323996
MEMC_ME(quit, arginfo_quit)
40333997
MEMC_ME(flushBuffers, arginfo_flushBuffers)
40343998

4035-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
40363999
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
40374000
MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
40384001
MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)
4039-
#endif
4002+
40404003
MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)
40414004

40424005
MEMC_ME(getStats, arginfo_getStats)
@@ -4229,9 +4192,8 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
42294192
REGISTER_MEMC_CLASS_CONST_LONG(OPT_DISTRIBUTION, MEMCACHED_BEHAVIOR_DISTRIBUTION);
42304193
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_MODULA);
42314194
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT);
4232-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
42334195
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_VIRTUAL_BUCKET, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET);
4234-
#endif
4196+
42354197
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
42364198
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_HASH, MEMCACHED_BEHAVIOR_KETAMA_HASH);
42374199
REGISTER_MEMC_CLASS_CONST_LONG(OPT_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE);
@@ -4257,14 +4219,10 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
42574219
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SORT_HOSTS, MEMCACHED_BEHAVIOR_SORT_HOSTS);
42584220
REGISTER_MEMC_CLASS_CONST_LONG(OPT_VERIFY_KEY, MEMCACHED_BEHAVIOR_VERIFY_KEY);
42594221
REGISTER_MEMC_CLASS_CONST_LONG(OPT_USE_UDP, MEMCACHED_BEHAVIOR_USE_UDP);
4260-
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00037000
42614222
REGISTER_MEMC_CLASS_CONST_LONG(OPT_NUMBER_OF_REPLICAS, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS);
42624223
REGISTER_MEMC_CLASS_CONST_LONG(OPT_RANDOMIZE_REPLICA_READ, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ);
4263-
#endif
4264-
#ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
42654224
REGISTER_MEMC_CLASS_CONST_LONG(OPT_REMOVE_FAILED_SERVERS, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS);
4266-
#endif
4267-
#ifdef HAVE_MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT
4225+
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000018
42684226
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SERVER_TIMEOUT_LIMIT, MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT);
42694227
#endif
42704228

Diff for: php_memcached_private.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
# include "config.h"
2626
#endif
2727

28-
#include "php_libmemcached_compat.h"
28+
#include <libmemcached/memcached.h>
29+
30+
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
31+
typedef const memcached_instance_st * php_memcached_instance_st;
32+
#else
33+
typedef memcached_server_instance_st php_memcached_instance_st;
34+
#endif
2935

3036
#include <stdlib.h>
3137
#include <string.h>
@@ -208,8 +214,6 @@ PHP_MINFO_FUNCTION(memcached);
208214

209215
char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
210216

211-
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);
212-
213217
zend_bool php_memc_init_sasl_if_needed();
214218

215219
#endif /* PHP_MEMCACHED_PRIVATE_H */

Diff for: php_memcached_session.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ PS_VALIDATE_SID_FUNC(memcached)
527527
{
528528
memcached_st *memc = PS_GET_MOD_DATA();
529529

530-
if (php_memcached_exist(memc, key) == MEMCACHED_SUCCESS) {
530+
if (memcached_exist(memc, key->val, key->len) == MEMCACHED_SUCCESS) {
531531
return SUCCESS;
532532
} else {
533533
return FAILURE;

0 commit comments

Comments
 (0)