Skip to content

Commit a393d6d

Browse files
committed
Restore php_libmemcached_compat with workaround for missing memcached_exists
This partially reverts commit c564fd8 from #295
1 parent e4f4878 commit a393d6d

7 files changed

+75
-11
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 g_fmt.c"
321+
PHP_MEMCACHED_FILES="php_memcached.c php_libmemcached_compat.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
@@ -73,6 +73,8 @@ Tests
7373
<file role='src' name='php_memcached_private.h'/>
7474
<file role='src' name='php_memcached_session.c'/>
7575
<file role='src' name='php_memcached_session.h'/>
76+
<file role='src' name='php_libmemcached_compat.h'/>
77+
<file role='src' name='php_libmemcached_compat.c'/>
7678
<file role='src' name='php_memcached_server.h'/>
7779
<file role='src' name='php_memcached_server.c'/>
7880
<file role='src' name='g_fmt.c'/>

Diff for: php_libmemcached_compat.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) 2009 The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.0 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.php.net/license/3_0.txt. |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: Andrei Zmievski <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#include "php_memcached.h"
18+
#include "php_memcached_private.h"
19+
#include "php_libmemcached_compat.h"
20+
21+
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key)
22+
{
23+
#ifdef HAVE_MEMCACHED_EXIST
24+
return memcached_exist (memc, key->val, key->len);
25+
#else
26+
memcached_return rc = MEMCACHED_SUCCESS;
27+
uint32_t flags = 0;
28+
size_t value_length = 0;
29+
char *value = NULL;
30+
31+
value = memcached_get (memc, key->val, key->len, &value_length, &flags, &rc);
32+
if (value) {
33+
free (value);
34+
}
35+
return rc;
36+
#endif
37+
}

Diff for: php_libmemcached_compat.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) 2009 The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.0 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.php.net/license/3_0.txt. |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: Andrei Zmievski <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef PHP_LIBMEMCACHED_COMPAT
18+
#define PHP_LIBMEMCACHED_COMPAT
19+
20+
/* this is the version(s) we support */
21+
#include <libmemcached/memcached.h>
22+
23+
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);
24+
25+
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000017
26+
typedef const memcached_instance_st * php_memcached_instance_st;
27+
#else
28+
typedef memcached_server_instance_st php_memcached_instance_st;
29+
#endif
30+
31+
#endif

Diff for: php_memcached.c

-2
Original file line numberDiff line numberDiff line change
@@ -4022,7 +4022,6 @@ static zend_function_entry memcached_class_methods[] = {
40224022
MEMC_ME(getLastErrorMessage, arginfo_getLastErrorMessage)
40234023
MEMC_ME(getLastErrorCode, arginfo_getLastErrorCode)
40244024
MEMC_ME(getLastErrorErrno, arginfo_getLastErrorErrno)
4025-
40264025
MEMC_ME(getLastDisconnectedServer, arginfo_getLastDisconnectedServer)
40274026

40284027
MEMC_ME(getStats, arginfo_getStats)
@@ -4216,7 +4215,6 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
42164215
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_MODULA);
42174216
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT);
42184217
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_VIRTUAL_BUCKET, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET);
4219-
42204218
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
42214219
REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_HASH, MEMCACHED_BEHAVIOR_KETAMA_HASH);
42224220
REGISTER_MEMC_CLASS_CONST_LONG(OPT_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE);

Diff for: php_memcached_private.h

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

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
28+
#include "php_libmemcached_compat.h"
3529

3630
#include <stdlib.h>
3731
#include <string.h>
@@ -214,6 +208,8 @@ PHP_MINFO_FUNCTION(memcached);
214208

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

211+
memcached_return php_memcached_exist (memcached_st *memc, zend_string *key);
212+
217213
zend_bool php_memc_init_sasl_if_needed();
218214

219215
#endif /* PHP_MEMCACHED_PRIVATE_H */

Diff for: php_memcached_session.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ PS_VALIDATE_SID_FUNC(memcached)
530530
{
531531
memcached_st *memc = PS_GET_MOD_DATA();
532532

533-
if (memcached_exist(memc, key->val, key->len) == MEMCACHED_SUCCESS) {
533+
if (php_memcached_exist(memc, key) == MEMCACHED_SUCCESS) {
534534
return SUCCESS;
535535
} else {
536536
return FAILURE;

0 commit comments

Comments
 (0)