Permalink
Browse files

Version based tests: Do version checks in one place, fix check when s…

…etting options
  • Loading branch information...
1 parent 411a64f commit feed35e22040b874ba6fc8659dc16b498e6e4150 @mkoppanen mkoppanen committed Nov 24, 2013
Showing with 49 additions and 99 deletions.
  1. +4 −79 config.m4
  2. +1 −1 php_libmemcached_compat.c
  3. +22 −1 php_libmemcached_compat.h
  4. +20 −16 php_memcached.c
  5. +2 −2 php_memcached_session.c
View
@@ -273,6 +273,10 @@ if test "$PHP_MEMCACHED" != "no"; then
if test "$PHP_LIBMEMCACHED_DIR" != "no" && test "$PHP_LIBMEMCACHED_DIR" != "yes"; then
export PKG_CONFIG_PATH="$PHP_LIBMEMCACHED_DIR/$PHP_LIBDIR/pkgconfig"
+
+ if test ! -f "$PHP_LIBMEMCACHED_DIR/include/libmemcached/memcached.h"; then
+ AC_MSG_ERROR(Unable to find memcached.h under $PHP_LIBMEMCACHED_DIR)
+ fi
else
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/$PHP_LIBDIR/pkgconfig:/usr/$PHP_LIBDIR/pkgconfig:/opt/$PHP_LIBDIR/pkgconfig"
fi
@@ -294,64 +298,9 @@ if test "$PHP_MEMCACHED" != "no"; then
#
# Added -lpthread here because AC_TRY_LINK tests on CentOS 6 seem to fail with undefined reference to pthread_once
#
- LIBS="$LIBS -lpthread"
ORIG_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $INCLUDES"
- AC_CACHE_CHECK([whether memcached_instance_st is defined], ac_cv_have_memcached_instance_st, [
- AC_TRY_COMPILE(
- [ #include <libmemcached/memcached.h> ],
- [ const memcached_instance_st *instance = NULL; ],
- [ ac_cv_have_memcached_instance_st="yes" ],
- [ ac_cv_have_memcached_instance_st="no" ]
- )
- ])
-
- AC_CACHE_CHECK([whether MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS is defined], ac_cv_have_libmemcached_remove_failed_servers, [
- AC_TRY_COMPILE(
- [ #include <libmemcached/memcached.h> ],
- [ (void)MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS; ],
- [ ac_cv_have_libmemcached_remove_failed_servers="yes" ],
- [ ac_cv_have_libmemcached_remove_failed_servers="no" ]
- )
- ])
-
- AC_CACHE_CHECK([whether MEMCACHED_SERVER_TEMPORARILY_DISABLED is defined], ac_cv_have_libmemcached_server_temporarily_disabled, [
- AC_TRY_COMPILE(
- [ #include <libmemcached/memcached.h> ],
- [ (void)MEMCACHED_SERVER_TEMPORARILY_DISABLED; ],
- [ ac_cv_have_libmemcached_server_temporarily_disabled="yes" ],
- [ ac_cv_have_libmemcached_server_temporarily_disabled="no" ]
- )
- ])
-
- AC_CACHE_CHECK([whether memcached function exists], ac_cv_have_libmemcached_memcached, [
- AC_TRY_LINK(
- [ #include <libmemcached/memcached.h> ],
- [ memcached("t", sizeof ("t")); ],
- [ ac_cv_have_libmemcached_memcached="yes" ],
- [ ac_cv_have_libmemcached_memcached="no" ]
- )
- ])
-
- AC_CACHE_CHECK([whether libmemcached_check_configuration function exists], ac_cv_have_libmemcached_check_configuration, [
- AC_TRY_LINK(
- [ #include <libmemcached/memcached.h> ],
- [ libmemcached_check_configuration("", 1, "", 1); ],
- [ ac_cv_have_libmemcached_check_configuration="yes" ],
- [ ac_cv_have_libmemcached_check_configuration="no" ]
- )
- ])
-
- AC_CACHE_CHECK([whether memcached_touch function exists], ac_cv_have_libmemcached_touch, [
- AC_TRY_LINK(
- [ #include <libmemcached/memcached.h> ],
- [ memcached_touch (NULL, NULL, 0, 0); ],
- [ ac_cv_have_libmemcached_touch="yes" ],
- [ ac_cv_have_libmemcached_touch="no" ]
- )
- ])
-
AC_MSG_CHECKING([whether to enable sasl support])
if test "$PHP_MEMCACHED_SASL" != "no"; then
AC_MSG_RESULT(yes)
@@ -387,30 +336,6 @@ if test "$PHP_MEMCACHED" != "no"; then
AC_MSG_RESULT([no])
fi
- if test "$ac_cv_have_memcached_instance_st" = "yes"; then
- AC_DEFINE(HAVE_MEMCACHED_INSTANCE_ST, [1], [Whether memcached_instance_st is defined])
- fi
-
- if test "$ac_cv_have_libmemcached_remove_failed_servers" = "yes"; then
- AC_DEFINE(HAVE_LIBMEMCACHED_REMOVE_FAILED_SERVERS, [1], [Whether MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS is defined])
- fi
-
- if test "$ac_cv_have_libmemcached_server_temporarily_disabled" = "yes"; then
- AC_DEFINE(HAVE_LIBMEMCACHED_SERVER_TEMPORARILY_MARKER_DISABLED, [1], [Whether MEMCACHED_SERVER_TEMPORARILY_DISABLED is defined])
- fi
-
- if test "$ac_cv_have_libmemcached_memcached" = "yes"; then
- AC_DEFINE(HAVE_LIBMEMCACHED_MEMCACHED, [1], [Whether memcached is defined])
- fi
-
- if test "$ac_cv_have_libmemcached_check_configuration" = "yes"; then
- AC_DEFINE(HAVE_LIBMEMCACHED_CHECK_CONFIGURATION, [1], [Whether libmemcached_check_configuration is defined])
- fi
-
- if test "$ac_cv_have_libmemcached_touch" = "yes"; then
- AC_DEFINE(HAVE_LIBMEMCACHED_TOUCH, [1], [Whether memcached_touch is defined])
- fi
-
PHP_MEMCACHED_FILES="php_memcached.c php_libmemcached_compat.c fastlz/fastlz.c g_fmt.c"
if test "$PHP_MEMCACHED_SESSION" != "no"; then
@@ -20,7 +20,7 @@
memcached_st *php_memc_create_str (const char *str, size_t str_len)
{
-#if HAVE_LIBMEMCACHED_MEMCACHED
+#ifdef HAVE_LIBMEMCACHED_MEMCACHED
return memcached (str, str_len);
#else
memcached_return rc;
@@ -22,10 +22,31 @@
memcached_st *php_memc_create_str (const char *str, size_t str_len);
-#ifndef HAVE_LIBMEMCACHED_SERVER_TEMPORARILY_MARKER_DISABLED
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x00052000
# define MEMCACHED_SERVER_TEMPORARILY_DISABLED (1024 << 2)
#endif
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000002
+# define HAVE_MEMCACHED_TOUCH 1
+#endif
+
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
+# define HAVE_MEMCACHED_INSTANCE_ST 1
+#endif
+
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
+# define HAVE_LIBMEMCACHED_CHECK_CONFIGURATION 1
+#endif
+
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000002
+# define HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS 1
+#endif
+
+#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
+# define HAVE_LIBMEMCACHED_MEMCACHED 1
+#endif
+
+
#ifdef HAVE_MEMCACHED_INSTANCE_ST
typedef const memcached_instance_st * php_memcached_instance_st;
#else
View
@@ -452,7 +452,7 @@ static PHP_METHOD(Memcached, __construct)
if (plist_key) {
efree(plist_key);
}
-#if HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
+#ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
if (libmemcached_check_configuration(conn_str, conn_str_len, error_buffer, sizeof(error_buffer)) != MEMCACHED_SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "configuration error %s", error_buffer);
} else {
@@ -1159,7 +1159,7 @@ PHP_METHOD(Memcached, setByKey)
}
/* }}} */
-#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000002
+#ifdef HAVE_MEMCACHED_TOUCH
/* {{{ Memcached::touch(string key, [, int expiration ])
Sets a new expiration for the given key */
PHP_METHOD(Memcached, touch)
@@ -1496,7 +1496,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
key_len, payload, payload_len, expiration, flags);
}
break;
-#ifdef HAVE_LIBMEMCACHED_TOUCH
+#ifdef HAVE_MEMCACHED_TOUCH
case MEMC_OP_TOUCH:
if (!server_key) {
status = memcached_touch(m_obj->memc, key, key_len, expiration);
@@ -2126,7 +2126,7 @@ PHP_METHOD(Memcached, flushBuffers)
}
/* }}} */
-#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
+#ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
/* {{{ Memcached::getLastErrorMessage()
Returns the last error message that occurred */
PHP_METHOD(Memcached, getLastErrorMessage)
@@ -2515,14 +2515,19 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML
/*
* Assume that it's a libmemcached behavior option.
*/
- flag = (memcached_behavior) option;
- convert_to_long(value);
-
- if (flag >= 0 && flag < MEMCACHED_BEHAVIOR_MAX) {
- rc = memcached_behavior_set(m_obj->memc, flag, (uint64_t) Z_LVAL_P(value));
+ if (option < 0) {
+ rc = MEMCACHED_INVALID_ARGUMENTS;
}
else {
- rc = MEMCACHED_INVALID_ARGUMENTS;
+ flag = (memcached_behavior) option;
+ convert_to_long(value);
+
+ if (flag < MEMCACHED_BEHAVIOR_MAX) {
+ rc = memcached_behavior_set(m_obj->memc, flag, (uint64_t) Z_LVAL_P(value));
+ }
+ else {
+ rc = MEMCACHED_INVALID_ARGUMENTS;
+ }
}
if (php_memc_handle_error(i_obj, rc TSRMLS_CC) < 0) {
@@ -4124,7 +4129,7 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(set, arginfo_set)
MEMC_ME(setByKey, arginfo_setByKey)
-#if HAVE_LIBMEMCACHED_TOUCH
+#ifdef HAVE_MEMCACHED_TOUCH
MEMC_ME(touch, arginfo_touch)
MEMC_ME(touchByKey, arginfo_touchByKey)
#endif
@@ -4155,10 +4160,9 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(addServers, arginfo_addServers)
MEMC_ME(getServerList, arginfo_getServerList)
MEMC_ME(getServerByKey, arginfo_getServerByKey)
- MEMC_ME(resetServerList, arginfo_resetServerList)
- MEMC_ME(quit, arginfo_quit)
- MEMC_ME(flushBuffers, arginfo_flushBuffers)
-
+ MEMC_ME(resetServerList, arginfo_resetServerList)
+ MEMC_ME(quit, arginfo_quit)
+ MEMC_ME(flushBuffers, arginfo_flushBuffers)
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x00049000
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
@@ -4346,7 +4350,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
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
-#if defined(HAVE_LIBMEMCACHED_REMOVE_FAILED_SERVERS) && HAVE_LIBMEMCACHED_REMOVE_FAILED_SERVERS
+#ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
REGISTER_MEMC_CLASS_CONST_LONG(OPT_REMOVE_FAILED_SERVERS, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS);
#endif
@@ -177,7 +177,7 @@ PS_OPEN_FUNC(memcached)
} else {
memc_sess->memc_sess = php_memc_create_str(p, strlen(p));
if (!memc_sess->memc_sess) {
-#if HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
+#ifdef HAVE_LIBMEMCACHED_CHECK_CONFIGURATION
char error_buffer[1024];
if (libmemcached_check_configuration(p, strlen(p), error_buffer, sizeof(error_buffer)) != MEMCACHED_SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.save_path configuration error %s", error_buffer);
@@ -247,7 +247,7 @@ PS_OPEN_FUNC(memcached)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached connection timeout");
return FAILURE;
}
-#if HAVE_LIBMEMCACHED_REMOVE_FAILED_SERVERS
+#ifdef HAVE_MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS
/* Allow libmemcached remove failed servers */
if (MEMC_G(sess_remove_failed_enabled)) {
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS, (uint64_t) 1) == MEMCACHED_FAILURE) {

0 comments on commit feed35e

Please sign in to comment.