Skip to content

Cleanup all checks for unsupported libmemcached versions #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ if test "$PHP_MEMCACHED" != "no"; then
AC_DEFINE(HAVE_MEMCACHED_EXIST, [1], [Whether memcached_exist is defined])
fi

PHP_MEMCACHED_FILES="php_memcached.c php_libmemcached_compat.c g_fmt.c"
PHP_MEMCACHED_FILES="php_memcached.c g_fmt.c"

if test "$PHP_SYSTEM_FASTLZ" != "no"; then
AC_CHECK_HEADERS([fastlz.h], [ac_cv_have_fastlz="yes"], [ac_cv_have_fastlz="no"])
Expand Down
2 changes: 0 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ Tests
<file role='src' name='php_memcached_private.h'/>
<file role='src' name='php_memcached_session.c'/>
<file role='src' name='php_memcached_session.h'/>
<file role='src' name='php_libmemcached_compat.h'/>
<file role='src' name='php_libmemcached_compat.c'/>
<file role='src' name='php_memcached_server.h'/>
<file role='src' name='php_memcached_server.c'/>
<file role='src' name='g_fmt.c'/>
Expand Down
37 changes: 0 additions & 37 deletions php_libmemcached_compat.c

This file was deleted.

59 changes: 0 additions & 59 deletions php_libmemcached_compat.h

This file was deleted.

58 changes: 8 additions & 50 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,6 @@ PHP_METHOD(Memcached, setByKey)
}
/* }}} */

#ifdef HAVE_MEMCACHED_TOUCH
/* {{{ Memcached::touch(string key, [, int expiration ])
Sets a new expiration for the given key */
PHP_METHOD(Memcached, touch)
Expand All @@ -1769,8 +1768,6 @@ PHP_METHOD(Memcached, touchByKey)
php_memc_store_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, MEMC_OP_TOUCH, 1);
}
/* }}} */
#endif


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

#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000002
if (ZSTR_VAL(host)[0] == '/') { /* unix domain socket */
status = memcached_server_add_unix_socket_with_weight(intern->memc, ZSTR_VAL(host), weight);
} else if (memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_USE_UDP)) {
status = memcached_server_add_udp_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
} else {
status = memcached_server_add_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
}
#else
status = memcached_server_add_with_weight(intern->memc, ZSTR_VAL(host), port, weight);
#endif

if (s_memc_status_handle_result_code(intern, status) == FAILURE) {
RETURN_FALSE;
Expand Down Expand Up @@ -2511,7 +2498,6 @@ PHP_METHOD(Memcached, flushBuffers)
}
/* }}} */

#ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
/* {{{ Memcached::getLastErrorMessage()
Returns the last error message that occurred */
PHP_METHOD(Memcached, getLastErrorMessage)
Expand Down Expand Up @@ -2559,7 +2545,6 @@ PHP_METHOD(Memcached, getLastErrorErrno)
RETURN_LONG(memcached_last_error_errno(intern->memc));
}
/* }}} */
#endif

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

result = memcached_callback_get(intern->memc, MEMCACHED_CALLBACK_PREFIX_KEY, &retval);
if (retval == MEMCACHED_SUCCESS && result) {
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
RETURN_STRINGL(result, strlen(result));
#else
RETURN_STRING(result);
#endif
} else {
RETURN_EMPTY_STRING();
}
Expand Down Expand Up @@ -2863,23 +2844,11 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
{
zend_string *str;
char *key;
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
char tmp[MEMCACHED_PREFIX_KEY_MAX_SIZE - 1];
#endif
str = zval_get_string(value);
if (ZSTR_VAL(str) == 0) {
key = NULL;
} else {
/*
work-around a bug in libmemcached in version 0.49 that truncates the trailing
character of the key prefix, to avoid the issue we pad it with a '0'
*/
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX == 0x00049000
snprintf(tmp, sizeof(tmp), "%s0", ZSTR_VAL(str));
key = tmp;
#else
key = ZSTR_VAL(str);
#endif
}
if (memcached_callback_set(intern->memc, MEMCACHED_CALLBACK_PREFIX_KEY, key) == MEMCACHED_BAD_KEY_PROVIDED) {
zend_string_release(str);
Expand Down Expand Up @@ -2908,14 +2877,9 @@ int php_memc_set_option(php_memc_object_t *intern, long option, zval *value)
* (non-weighted) case. We have to clean up ourselves.
*/
if (!lval) {
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX > 0x00037000
(void)memcached_behavior_set_key_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
(void)memcached_behavior_set_distribution_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
(void)memcached_behavior_set_distribution(intern->memc, MEMCACHED_DISTRIBUTION_MODULA);
#else
intern->memc->hash = 0;
intern->memc->distribution = 0;
#endif
(void)memcached_behavior_set_key_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
(void)memcached_behavior_set_distribution_hash(intern->memc, MEMCACHED_HASH_DEFAULT);
(void)memcached_behavior_set_distribution(intern->memc, MEMCACHED_DISTRIBUTION_MODULA);
}
break;

Expand Down Expand Up @@ -3997,10 +3961,10 @@ static zend_function_entry memcached_class_methods[] = {

MEMC_ME(set, arginfo_set)
MEMC_ME(setByKey, arginfo_setByKey)
#ifdef HAVE_MEMCACHED_TOUCH

MEMC_ME(touch, arginfo_touch)
MEMC_ME(touchByKey, arginfo_touchByKey)
#endif

MEMC_ME(setMulti, arginfo_setMulti)
MEMC_ME(setMultiByKey, arginfo_setMultiByKey)

Expand Down Expand Up @@ -4032,11 +3996,10 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(quit, arginfo_quit)
MEMC_ME(flushBuffers, arginfo_flushBuffers)

#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)
#endif

MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)

MEMC_ME(getStats, arginfo_getStats)
Expand Down Expand Up @@ -4229,9 +4192,8 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(OPT_DISTRIBUTION, MEMCACHED_BEHAVIOR_DISTRIBUTION);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_MODULA);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT);
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_VIRTUAL_BUCKET, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET);
#endif

REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_HASH, MEMCACHED_BEHAVIOR_KETAMA_HASH);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE);
Expand All @@ -4257,14 +4219,10 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SORT_HOSTS, MEMCACHED_BEHAVIOR_SORT_HOSTS);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_VERIFY_KEY, MEMCACHED_BEHAVIOR_VERIFY_KEY);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_USE_UDP, MEMCACHED_BEHAVIOR_USE_UDP);
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00037000
REGISTER_MEMC_CLASS_CONST_LONG(OPT_NUMBER_OF_REPLICAS, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_RANDOMIZE_REPLICA_READ, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ);
#endif
#ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
REGISTER_MEMC_CLASS_CONST_LONG(OPT_REMOVE_FAILED_SERVERS, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS);
#endif
#ifdef HAVE_MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000018
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SERVER_TIMEOUT_LIMIT, MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT);
Copy link
Contributor

@sodabrew sodabrew Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this libmemcached 1.0.18 or higher? It hasn't caused compile to fail on any older 1.0.x version.

I mis-re-read the diff.

#endif

Expand Down
10 changes: 7 additions & 3 deletions php_memcached_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
# include "config.h"
#endif

#include "php_libmemcached_compat.h"
#include <libmemcached/memcached.h>

#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
typedef const memcached_instance_st * php_memcached_instance_st;
#else
typedef memcached_server_instance_st php_memcached_instance_st;
#endif

#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -208,8 +214,6 @@ PHP_MINFO_FUNCTION(memcached);

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

memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);

zend_bool php_memc_init_sasl_if_needed();

#endif /* PHP_MEMCACHED_PRIVATE_H */
Expand Down
2 changes: 1 addition & 1 deletion php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ PS_VALIDATE_SID_FUNC(memcached)
{
memcached_st *memc = PS_GET_MOD_DATA();

if (php_memcached_exist(memc, key) == MEMCACHED_SUCCESS) {
if (memcached_exist(memc, key->val, key->len) == MEMCACHED_SUCCESS) {
return SUCCESS;
} else {
return FAILURE;
Expand Down