Skip to content

Commit a86de05

Browse files
authored
Fix compiling with memcached binary protocol enabled (#312)
1 parent fa620a4 commit a86de05

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

php_memcached.c

+3-19
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
# include "ext/msgpack/php_msgpack.h"
5252
#endif
5353

54-
#ifdef ZTS
55-
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
56-
#else
57-
#define MEMC_G(v) (php_memcached_globals.memc.v)
58-
#endif
59-
6054
static int le_memc;
6155

6256
static int php_memc_list_entry(void) {
@@ -238,24 +232,14 @@ static inline php_memc_server_t *php_memc_server_fetch_object(zend_object *obj)
238232
}
239233
#define Z_MEMC_SERVER_P(zv) php_memc_server_fetch_object(Z_OBJ_P(zv))
240234

241-
#ifdef ZTS
242-
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
243-
#else
244-
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
245-
#endif
235+
static zend_object_handlers memcached_server_object_handlers;
236+
static zend_class_entry *memcached_server_ce = NULL;
246237
#endif
247238

248239
static zend_class_entry *memcached_ce = NULL;
249-
250240
static zend_class_entry *memcached_exception_ce = NULL;
251-
252241
static zend_object_handlers memcached_object_handlers;
253242

254-
#ifdef HAVE_MEMCACHED_PROTOCOL
255-
static zend_object_handlers memcached_server_object_handlers;
256-
static zend_class_entry *memcached_server_ce = NULL;
257-
#endif
258-
259243
#ifdef HAVE_SPL
260244
static zend_class_entry *spl_ce_RuntimeException = NULL;
261245
#endif
@@ -3644,7 +3628,7 @@ PHP_METHOD(MemcachedServer, run)
36443628
static
36453629
PHP_METHOD(MemcachedServer, on)
36463630
{
3647-
long event;
3631+
zend_long event;
36483632
zend_fcall_info fci;
36493633
zend_fcall_info_cache fci_cache;
36503634
zend_bool rc = 0;

php_memcached.h

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root);
4242
extern zend_module_entry memcached_module_entry;
4343
#define phpext_memcached_ptr &memcached_module_entry
4444

45+
#ifdef ZTS
46+
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
47+
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
48+
#else
49+
#define MEMC_G(v) (php_memcached_globals.memc.v)
50+
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
51+
#endif
52+
4553
#endif /* PHP_MEMCACHED_H */
4654

4755
/*

php_memcached_server.c

+14-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#undef _NDEBUG
2525
#include <assert.h>
2626

27-
#define MEMC_GET_CB(cb_type) (MEMC_G(server.callbacks)[cb_type])
27+
#define MEMC_GET_CB(cb_type) (MEMC_SERVER_G(callbacks)[cb_type])
2828
#define MEMC_HAS_CB(cb_type) (MEMC_GET_CB(cb_type).fci.size > 0)
2929

3030
#define MEMC_MAKE_ZVAL_COOKIE(my_zcookie, my_ptr) \
@@ -37,7 +37,7 @@
3737
#define MEMC_MAKE_RESULT_CAS(my_zresult_cas, my_result_cas) \
3838
do { \
3939
my_result_cas = 0; \
40-
my_result_cas = zval_get_double(my_zresult_cas); \
40+
my_result_cas = zval_get_double(&my_zresult_cas); \
4141
} while (0)
4242

4343

@@ -56,27 +56,22 @@ typedef struct {
5656
} php_memc_client_t;
5757

5858
static
59-
long s_invoke_php_callback (php_memc_server_cb_t *cb, zval ***params, ssize_t param_count)
59+
long s_invoke_php_callback (php_memc_server_cb_t *cb, zval *params, ssize_t param_count)
6060
{
61-
long retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
62-
zval *retval_ptr = NULL;
61+
zval *retval = NULL;
6362

64-
cb->fci.params = params;
63+
cb->fci.retval = retval;
64+
cb->fci.params = params;
6565
cb->fci.param_count = param_count;
66-
67-
/* Call the cb */
68-
cb->fci.no_separation = 1;
69-
cb->fci.retval_ptr_ptr = &retval_ptr;
66+
cb->fci.no_separation = 1;
7067

7168
if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) {
72-
char *buf = php_memc_printable_func (&(cb->fci), &(cb->fci_cache));
69+
char *buf = php_memc_printable_func(&(cb->fci), &(cb->fci_cache));
7370
php_error_docref(NULL, E_WARNING, "Failed to invoke callback %s()", buf);
7471
efree (buf);
7572
}
76-
if (retval_ptr) {
77-
retval = zval_get_long(retval_ptr);
78-
}
79-
return retval;
73+
74+
return retval == NULL ? PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND : zval_get_long(retval);
8075
}
8176

8277
// memcached protocol callbacks
@@ -217,7 +212,7 @@ protocol_binary_response_status s_incr_decr_handler (php_memc_event_t event, con
217212

218213
retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 7);
219214

220-
*result = (uint64_t)zval_get_long(zresult);
215+
*result = (uint64_t)zval_get_long(&zresult);
221216

222217
MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas);
223218

@@ -301,7 +296,7 @@ protocol_binary_response_status s_flush_handler(const void *cookie, uint32_t whe
301296
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie);
302297

303298
ZVAL_COPY(&params[0], &zcookie);
304-
ZVAL_COPY(&params[1], &zwhen)
299+
ZVAL_COPY(&params[1], &zwhen);
305300

306301
retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_FLUSH), params, 2);
307302

@@ -561,7 +556,7 @@ protocol_binary_response_status s_version_handler (const void *cookie,
561556
convert_to_string(&zversion);
562557
}
563558

564-
retval = response_handler (cookie, Z_STRVAL_P(zversion), (uint32_t) Z_STRLEN_P(zversion));
559+
retval = response_handler (cookie, Z_STRVAL(zversion), (uint32_t) Z_STRLEN(zversion));
565560
}
566561

567562
zval_ptr_dtor(&params[0]);
@@ -592,7 +587,7 @@ void s_handle_memcached_event (evutil_socket_t fd, short what, void *arg)
592587
socklen_t addr_in_len = sizeof(addr_in);
593588

594589
if (getpeername (fd, (struct sockaddr *) &addr_in, &addr_in_len) == 0) {
595-
ZVAL_STRING(&zremoteip, inet_ntoa (addr_in.sin_addr), 1);
590+
ZVAL_STRING(&zremoteip, inet_ntoa (addr_in.sin_addr));
596591
ZVAL_LONG(&zremoteport, ntohs (addr_in.sin_port));
597592
} else {
598593
php_error_docref(NULL, E_WARNING, "getpeername failed: %s", strerror (errno));

0 commit comments

Comments
 (0)