Skip to content

Fix compiling with memcached binary protocol enabled #312

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
Feb 7, 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
22 changes: 3 additions & 19 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
# include "ext/msgpack/php_msgpack.h"
#endif

#ifdef ZTS
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
#else
#define MEMC_G(v) (php_memcached_globals.memc.v)
#endif

static int le_memc;

static int php_memc_list_entry(void) {
Expand Down Expand Up @@ -238,24 +232,14 @@ static inline php_memc_server_t *php_memc_server_fetch_object(zend_object *obj)
}
#define Z_MEMC_SERVER_P(zv) php_memc_server_fetch_object(Z_OBJ_P(zv))

#ifdef ZTS
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
#else
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
#endif
static zend_object_handlers memcached_server_object_handlers;
static zend_class_entry *memcached_server_ce = NULL;
#endif

static zend_class_entry *memcached_ce = NULL;

static zend_class_entry *memcached_exception_ce = NULL;

static zend_object_handlers memcached_object_handlers;

#ifdef HAVE_MEMCACHED_PROTOCOL
static zend_object_handlers memcached_server_object_handlers;
static zend_class_entry *memcached_server_ce = NULL;
#endif

#ifdef HAVE_SPL
static zend_class_entry *spl_ce_RuntimeException = NULL;
#endif
Expand Down Expand Up @@ -3644,7 +3628,7 @@ PHP_METHOD(MemcachedServer, run)
static
PHP_METHOD(MemcachedServer, on)
{
long event;
zend_long event;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
zend_bool rc = 0;
Expand Down
8 changes: 8 additions & 0 deletions php_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root);
extern zend_module_entry memcached_module_entry;
#define phpext_memcached_ptr &memcached_module_entry

#ifdef ZTS
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc.v)
#define MEMC_SERVER_G(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, server.v)
#else
#define MEMC_G(v) (php_memcached_globals.memc.v)
#define MEMC_SERVER_G(v) (php_memcached_globals.server.v)
#endif

#endif /* PHP_MEMCACHED_H */

/*
Expand Down
33 changes: 14 additions & 19 deletions php_memcached_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#undef _NDEBUG
#include <assert.h>

#define MEMC_GET_CB(cb_type) (MEMC_G(server.callbacks)[cb_type])
#define MEMC_GET_CB(cb_type) (MEMC_SERVER_G(callbacks)[cb_type])
#define MEMC_HAS_CB(cb_type) (MEMC_GET_CB(cb_type).fci.size > 0)

#define MEMC_MAKE_ZVAL_COOKIE(my_zcookie, my_ptr) \
Expand All @@ -37,7 +37,7 @@
#define MEMC_MAKE_RESULT_CAS(my_zresult_cas, my_result_cas) \
do { \
my_result_cas = 0; \
my_result_cas = zval_get_double(my_zresult_cas); \
my_result_cas = zval_get_double(&my_zresult_cas); \
} while (0)


Expand All @@ -56,27 +56,22 @@ typedef struct {
} php_memc_client_t;

static
long s_invoke_php_callback (php_memc_server_cb_t *cb, zval ***params, ssize_t param_count)
long s_invoke_php_callback (php_memc_server_cb_t *cb, zval *params, ssize_t param_count)
{
long retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
zval *retval_ptr = NULL;
zval *retval = NULL;

cb->fci.params = params;
cb->fci.retval = retval;
cb->fci.params = params;
cb->fci.param_count = param_count;

/* Call the cb */
cb->fci.no_separation = 1;
cb->fci.retval_ptr_ptr = &retval_ptr;
cb->fci.no_separation = 1;

if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) {
char *buf = php_memc_printable_func (&(cb->fci), &(cb->fci_cache));
char *buf = php_memc_printable_func(&(cb->fci), &(cb->fci_cache));
php_error_docref(NULL, E_WARNING, "Failed to invoke callback %s()", buf);
efree (buf);
}
if (retval_ptr) {
retval = zval_get_long(retval_ptr);
}
return retval;

return retval == NULL ? PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND : zval_get_long(retval);
}

// memcached protocol callbacks
Expand Down Expand Up @@ -217,7 +212,7 @@ protocol_binary_response_status s_incr_decr_handler (php_memc_event_t event, con

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

*result = (uint64_t)zval_get_long(zresult);
*result = (uint64_t)zval_get_long(&zresult);

MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas);

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

ZVAL_COPY(&params[0], &zcookie);
ZVAL_COPY(&params[1], &zwhen)
ZVAL_COPY(&params[1], &zwhen);

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

Expand Down Expand Up @@ -561,7 +556,7 @@ protocol_binary_response_status s_version_handler (const void *cookie,
convert_to_string(&zversion);
}

retval = response_handler (cookie, Z_STRVAL_P(zversion), (uint32_t) Z_STRLEN_P(zversion));
retval = response_handler (cookie, Z_STRVAL(zversion), (uint32_t) Z_STRLEN(zversion));
}

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

if (getpeername (fd, (struct sockaddr *) &addr_in, &addr_in_len) == 0) {
ZVAL_STRING(&zremoteip, inet_ntoa (addr_in.sin_addr), 1);
ZVAL_STRING(&zremoteip, inet_ntoa (addr_in.sin_addr));
ZVAL_LONG(&zremoteport, ntohs (addr_in.sin_port));
} else {
php_error_docref(NULL, E_WARNING, "getpeername failed: %s", strerror (errno));
Expand Down