Created
February 5, 2015 22:11
-
-
Save anonymous/15cbc9947edb4f0a71fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/php_libmemcached_compat.c b/php_libmemcached_compat.c | |
index f238709..f49b162 100644 | |
--- a/php_libmemcached_compat.c | |
+++ b/php_libmemcached_compat.c | |
@@ -49,4 +49,5 @@ memcached_st *php_memc_create_str (const char *str, size_t str_len) | |
} | |
return memc; | |
#endif | |
-} | |
\ No newline at end of file | |
+} | |
+ | |
diff --git a/php_memcached.c b/php_memcached.c | |
index c1bce93..3a25a1a 100644 | |
--- a/php_memcached.c | |
+++ b/php_memcached.c | |
@@ -122,14 +122,6 @@ | |
php_memc_t* i_obj = NULL; \ | |
struct memc_obj* m_obj = NULL; | |
-#define MEMC_METHOD_FETCH_OBJECT \ | |
- i_obj = (php_memc_t *) zend_object_store_get_object( object TSRMLS_CC ); \ | |
- m_obj = i_obj->obj; \ | |
- if (!m_obj) { \ | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memcached constructor was not called"); \ | |
- return; \ | |
- } | |
- | |
#ifndef DVAL_TO_LVAL | |
#ifdef _WIN64 | |
# define DVAL_TO_LVAL(d, l) \ | |
@@ -150,12 +142,6 @@ | |
#define RETURN_FROM_GET RETURN_FALSE | |
-#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3) | |
-#define zend_parse_parameters_none() \ | |
- zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") | |
-#endif | |
- | |
- | |
/**************************************** | |
Structures and definitions | |
****************************************/ | |
@@ -165,8 +151,6 @@ enum memcached_compression_type { | |
}; | |
typedef struct { | |
- zend_object zo; | |
- | |
struct memc_obj { | |
memcached_st *memc; | |
zend_bool compression; | |
@@ -182,8 +166,22 @@ typedef struct { | |
zend_bool is_pristine; | |
int rescode; | |
int memc_errno; | |
+ zend_object zo; | |
} php_memc_t; | |
+static inline php_memc_t *php_memc_fetch_object(zend_object *obj) { | |
+ return (php_memc_t *)((char *)(obj) - XtOffsetOf(php_memc_t, zo)); | |
+} | |
+#define Z_MEMC_OBJ_P(zv) php_memc_fetch_object(Z_OBJ_P(zv)); | |
+ | |
+#define MEMC_METHOD_FETCH_OBJECT \ | |
+ i_obj = Z_MEMC_OBJ_P(object); \ | |
+ m_obj = i_obj->obj; \ | |
+ if (!m_obj) { \ | |
+ php_error_docref(NULL, E_WARNING, "Memcached constructor was not called"); \ | |
+ return; \ | |
+ } | |
+ | |
#ifdef HAVE_MEMCACHED_PROTOCOL | |
typedef struct { | |
@@ -244,41 +242,41 @@ static PHP_INI_MH(OnUpdateCompressionType) | |
{ | |
if (!new_value) { | |
MEMC_G(compression_type_real) = COMPRESSION_TYPE_FASTLZ; | |
- } else if (!strcmp(new_value, "fastlz")) { | |
+ } else if (!strcmp(new_value->val, "fastlz")) { | |
MEMC_G(compression_type_real) = COMPRESSION_TYPE_FASTLZ; | |
- } else if (!strcmp(new_value, "zlib")) { | |
+ } else if (!strcmp(new_value->val, "zlib")) { | |
MEMC_G(compression_type_real) = COMPRESSION_TYPE_ZLIB; | |
} else { | |
return FAILURE; | |
} | |
- return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); | |
+ return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); | |
} | |
static PHP_INI_MH(OnUpdateSerializer) | |
{ | |
if (!new_value) { | |
MEMC_G(serializer) = SERIALIZER_DEFAULT; | |
- } else if (!strcmp(new_value, "php")) { | |
+ } else if (!strcmp(new_value->val, "php")) { | |
MEMC_G(serializer) = SERIALIZER_PHP; | |
#ifdef HAVE_MEMCACHED_IGBINARY | |
- } else if (!strcmp(new_value, "igbinary")) { | |
+ } else if (!strcmp(new_value->val, "igbinary")) { | |
MEMC_G(serializer) = SERIALIZER_IGBINARY; | |
#endif // IGBINARY | |
#ifdef HAVE_JSON_API | |
- } else if (!strcmp(new_value, "json")) { | |
+ } else if (!strcmp(new_value->val, "json")) { | |
MEMC_G(serializer) = SERIALIZER_JSON; | |
- } else if (!strcmp(new_value, "json_array")) { | |
+ } else if (!strcmp(new_value->val, "json_array")) { | |
MEMC_G(serializer) = SERIALIZER_JSON_ARRAY; | |
#endif // JSON | |
#ifdef HAVE_MEMCACHED_MSGPACK | |
- } else if (!strcmp(new_value, "msgpack")) { | |
+ } else if (!strcmp(new_value->val, "msgpack")) { | |
MEMC_G(serializer) = SERIALIZER_MSGPACK; | |
#endif // msgpack | |
} else { | |
return FAILURE; | |
} | |
- return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); | |
+ return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); | |
} | |
/* {{{ INI entries */ | |
@@ -316,9 +314,9 @@ PHP_INI_END() | |
/**************************************** | |
Forward declarations | |
****************************************/ | |
-static int php_memc_handle_error(php_memc_t *i_obj, memcached_return status TSRMLS_DC); | |
-static char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags, enum memcached_serializer serializer, enum memcached_compression_type compression_type TSRMLS_DC); | |
-static int php_memc_zval_from_payload(zval *value, const char *payload, size_t payload_len, uint32_t flags, enum memcached_serializer serializer TSRMLS_DC); | |
+static int php_memc_handle_error(php_memc_t *i_obj, memcached_return status); | |
+static char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags, enum memcached_serializer serializer, enum memcached_compression_type compression_type); | |
+static int php_memc_zval_from_payload(zval *value, const char *payload, size_t payload_len, uint32_t flags, enum memcached_serializer serializer); | |
static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key); | |
static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key); | |
static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool by_key); | |
@@ -326,68 +324,66 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
static void php_memc_delete_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key); | |
static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key); | |
static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key); | |
-static memcached_return php_memc_do_cache_callback(zval *memc_obj, zend_fcall_info *fci, zend_fcall_info_cache *fcc, char *key, size_t key_len, zval *value TSRMLS_DC); | |
-static int php_memc_do_result_callback(zval *memc_obj, zend_fcall_info *fci, zend_fcall_info_cache *fcc, memcached_result_st *result TSRMLS_DC); | |
+static memcached_return php_memc_do_cache_callback(zval *memc_obj, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string *key, zval *value); | |
+static int php_memc_do_result_callback(zval *memc_obj, zend_fcall_info *fci, zend_fcall_info_cache *fcc, memcached_result_st *result); | |
static memcached_return php_memc_do_serverlist_callback(const memcached_st *ptr, php_memcached_instance_st instance, void *in_context); | |
static memcached_return php_memc_do_stats_callback(const memcached_st *ptr, php_memcached_instance_st instance, void *in_context); | |
static memcached_return php_memc_do_version_callback(const memcached_st *ptr, php_memcached_instance_st instance, void *in_context); | |
-static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent TSRMLS_DC); | |
+static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent); | |
/**************************************** | |
Method implementations | |
****************************************/ | |
-char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) | |
+char *php_memc_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) | |
{ | |
char *buffer = NULL; | |
- if (fci->object_ptr) { | |
- spprintf (&buffer, 0, "%s::%s", Z_OBJCE_P (fci->object_ptr)->name, fci_cache->function_handler->common.function_name); | |
+ if (fci->object) { | |
+ spprintf (&buffer, 0, "%s::%s", fci->object->ce->name->val, fci_cache->function_handler->common.function_name); | |
} else { | |
- if (Z_TYPE_P (fci->function_name) == IS_OBJECT) { | |
- spprintf (&buffer, 0, "%s", Z_OBJCE_P (fci->function_name)->name); | |
+ if (Z_TYPE (fci->function_name) == IS_OBJECT) { | |
+ spprintf (&buffer, 0, "%s", Z_OBJCE (fci->function_name)->name->val); | |
} | |
else { | |
- spprintf (&buffer, 0, "%s", Z_STRVAL_P (fci->function_name)); | |
+ spprintf (&buffer, 0, "%s", Z_STRVAL (fci->function_name)); | |
} | |
} | |
return buffer; | |
} | |
-static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, char *persistent_id, int persistent_id_len TSRMLS_DC) | |
+static zend_bool php_memcached_on_new_callback(zval *object, zend_fcall_info *fci, zend_fcall_info_cache *fci_cache, zend_string *persistent_id) | |
{ | |
- zend_bool retval = 1; | |
- zval pid_z; | |
- zval *retval_ptr, *pid_z_ptr = &pid_z; | |
- zval **params[2]; | |
+ zend_bool ret = 1; | |
+ zval retval; | |
+ zval params[2]; | |
- INIT_ZVAL(pid_z); | |
if (persistent_id) { | |
- ZVAL_STRINGL(pid_z_ptr, persistent_id, persistent_id_len, 1); | |
+ ZVAL_STR(¶ms[1], persistent_id); | |
+ } else { | |
+ ZVAL_NULL(¶ms[1]); | |
} | |
/* Call the cb */ | |
- params[0] = &object; | |
- params[1] = &pid_z_ptr; | |
+ ZVAL_COPY(¶ms[0], object); | |
fci->params = params; | |
fci->param_count = 2; | |
- fci->retval_ptr_ptr = &retval_ptr; | |
+ fci->retval = &retval; | |
fci->no_separation = 1; | |
- if (zend_call_function(fci, fci_cache TSRMLS_CC) == FAILURE) { | |
- char *buf = php_memc_printable_func (fci, fci_cache TSRMLS_CC); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to invoke 'on_new' callback %s()", buf); | |
+ if (zend_call_function(fci, fci_cache) == FAILURE) { | |
+ char *buf = php_memc_printable_func (fci, fci_cache); | |
+ php_error_docref(NULL, E_WARNING, "Failed to invoke 'on_new' callback %s()", buf); | |
efree (buf); | |
- retval = 0; | |
+ ret = 0; | |
} | |
- zval_dtor(pid_z_ptr); | |
- if (retval_ptr) { | |
- zval_ptr_dtor(&retval_ptr); | |
- } | |
- return retval; | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(&retval); | |
+ return ret; | |
} | |
static int le_memc, le_memc_sess; | |
@@ -404,32 +400,28 @@ static PHP_METHOD(Memcached, __construct) | |
zval *object = getThis(); | |
php_memc_t *i_obj; | |
struct memc_obj *m_obj = NULL; | |
- char *persistent_id = NULL, *conn_str = NULL; | |
- int persistent_id_len, conn_str_len; | |
+ zend_string *persistent_id = NULL; | |
+ zend_string *conn_str = NULL; | |
zend_bool is_persistent = 0; | |
- | |
- char *plist_key = NULL; | |
- int plist_key_len = 0; | |
- | |
+ zend_string *plist_key = NULL; | |
zend_fcall_info fci = {0}; | |
zend_fcall_info_cache fci_cache; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!f!s", &persistent_id, &persistent_id_len, &fci, &fci_cache, &conn_str, &conn_str_len) == FAILURE) { | |
- ZVAL_NULL(object); | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!f!S", &persistent_id, &fci, &fci_cache, &conn_str) == FAILURE) { | |
+ ZEND_CTOR_MAKE_NULL(); | |
return; | |
} | |
- i_obj = (php_memc_t *) zend_object_store_get_object(object TSRMLS_CC); | |
+ i_obj = Z_MEMC_OBJ_P(object); | |
i_obj->is_pristine = 0; | |
- if (persistent_id && *persistent_id) { | |
- zend_rsrc_list_entry *le = NULL; | |
+ if (persistent_id && persistent_id->len) { | |
+ zend_resource *le; | |
is_persistent = 1; | |
- plist_key_len = spprintf(&plist_key, 0, "memcached:id=%s", persistent_id); | |
- plist_key_len += 1; | |
- | |
- if (zend_hash_find(&EG(persistent_list), plist_key, plist_key_len, (void *)&le) == SUCCESS) { | |
+ plist_key = zend_string_alloc(sizeof("memcached:id=") + persistent_id->len - 1, 0); | |
+ snprintf(plist_key->val, plist_key->len + 1, "memcached:id=%s", persistent_id->val); | |
+ if ((le = zend_hash_find_ptr(&EG(persistent_list), plist_key)) != NULL) { | |
if (le->type == php_memc_list_entry()) { | |
m_obj = (struct memc_obj *) le->ptr; | |
} | |
@@ -443,27 +435,27 @@ static PHP_METHOD(Memcached, __construct) | |
m_obj = pecalloc(1, sizeof(*m_obj), is_persistent); | |
if (m_obj == NULL) { | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "out of memory: cannot allocate handle"); | |
+ php_error_docref(NULL, E_ERROR, "out of memory: cannot allocate handle"); | |
/* not reached */ | |
} | |
if (conn_str) { | |
- m_obj->memc = php_memc_create_str(conn_str, conn_str_len); | |
+ m_obj->memc = php_memc_create_str(conn_str->val, conn_str->len); | |
if (!m_obj->memc) { | |
char error_buffer[1024]; | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
#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); | |
+ if (libmemcached_check_configuration(conn_str->val, conn_str->len, error_buffer, sizeof(error_buffer)) != MEMCACHED_SUCCESS) { | |
+ php_error_docref(NULL, E_ERROR, "configuration error %s", error_buffer); | |
} else { | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "could not allocate libmemcached structure"); | |
+ php_error_docref(NULL, E_ERROR, "could not allocate libmemcached structure"); | |
} | |
#else | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "could not allocate libmemcached structure"); | |
+ php_error_docref(NULL, E_ERROR, "could not allocate libmemcached structure"); | |
#endif | |
/* not reached */ | |
} | |
@@ -471,9 +463,9 @@ static PHP_METHOD(Memcached, __construct) | |
m_obj->memc = memcached_create(NULL); | |
if (m_obj->memc == NULL) { | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "could not allocate libmemcached structure"); | |
+ php_error_docref(NULL, E_ERROR, "could not allocate libmemcached structure"); | |
/* not reached */ | |
} | |
} | |
@@ -487,15 +479,15 @@ static PHP_METHOD(Memcached, __construct) | |
i_obj->is_pristine = 1; | |
if (fci.size) { /* will be 0 when not available */ | |
- if (!php_memcached_on_new_callback(object, &fci, &fci_cache, persistent_id, persistent_id_len TSRMLS_CC) || EG(exception)) { | |
+ if (!php_memcached_on_new_callback(object, &fci, &fci_cache, persistent_id) || EG(exception)) { | |
/* error calling or exception thrown from callback */ | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
i_obj->obj = NULL; | |
if (is_persistent) { | |
- php_memc_destroy(m_obj, is_persistent TSRMLS_CC); | |
+ php_memc_destroy(m_obj, is_persistent); | |
} | |
return; | |
@@ -503,23 +495,24 @@ static PHP_METHOD(Memcached, __construct) | |
} | |
if (is_persistent) { | |
- zend_rsrc_list_entry le; | |
+ zend_resource le; | |
le.type = php_memc_list_entry(); | |
le.ptr = m_obj; | |
- if (zend_hash_update(&EG(persistent_list), (char *)plist_key, | |
- plist_key_len, (void *)&le, sizeof(le), NULL) == FAILURE) { | |
+ GC_REFCOUNT(&le) = 1; | |
+ /* plist_key is not a persistent allocated key, thus we use str_update here */ | |
+ if (zend_hash_str_update_mem(&EG(persistent_list), plist_key->val, plist_key->len, &le, sizeof(le)) == NULL) { | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "could not register persistent entry"); | |
+ php_error_docref(NULL, E_ERROR, "could not register persistent entry"); | |
/* not reached */ | |
} | |
} | |
} | |
if (plist_key) { | |
- efree(plist_key); | |
+ zend_string_release(plist_key); | |
} | |
} | |
/* }}} */ | |
@@ -543,10 +536,8 @@ PHP_METHOD(Memcached, getByKey) | |
/* {{{ -- php_memc_get_impl */ | |
static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
- char *key = NULL; | |
- int key_len = 0; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *key; | |
+ zend_string *server_key = NULL; | |
const char *payload = NULL; | |
size_t payload_len = 0; | |
uint32_t flags = 0; | |
@@ -555,6 +546,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
size_t key_lens[1] = { 0 }; | |
zval *cas_token = NULL; | |
zval *udf_flags = NULL; | |
+ uint64_t orig_cas_flag; | |
zend_fcall_info fci = empty_fcall_info; | |
zend_fcall_info_cache fcc = empty_fcall_info_cache; | |
memcached_result_st result; | |
@@ -562,12 +554,12 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|f!zz", &server_key, | |
- &server_key_len, &key, &key_len, &fci, &fcc, &cas_token, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|f!zz", &server_key, &key, | |
+ &fci, &fcc, &cas_token, &udf_flags) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f!zz", &key, &key_len, | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|f!zz", &key, | |
&fci, &fcc, &cas_token, &udf_flags) == FAILURE) { | |
return; | |
} | |
@@ -576,31 +568,33 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (key_len == 0 || strchr(key, ' ')) { | |
+ if (key->len == 0 || strchr(key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FROM_GET; | |
} | |
- keys[0] = key; | |
- key_lens[0] = key_len; | |
+ keys[0] = key->val; | |
+ key_lens[0] = key->len; | |
- uint64_t orig_cas_flag; | |
orig_cas_flag = memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS); | |
/* | |
* Enable CAS support, but only if it is currently disabled. | |
*/ | |
- if (cas_token && PZVAL_IS_REF(cas_token) && orig_cas_flag == 0) { | |
+ if (cas_token && Z_ISREF_P(cas_token) && orig_cas_flag == 0) { | |
memcached_behavior_set(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1); | |
} | |
- status = memcached_mget_by_key(m_obj->memc, server_key, server_key_len, keys, key_lens, 1); | |
- | |
- if (cas_token && PZVAL_IS_REF(cas_token) && orig_cas_flag == 0) { | |
+ if (by_key) { | |
+ status = memcached_mget_by_key(m_obj->memc, server_key->val, server_key->len, keys, key_lens, 1); | |
+ } else { | |
+ status = memcached_mget(m_obj->memc, keys, key_lens, 1); | |
+ } | |
+ if (cas_token && Z_ISREF_P(cas_token) && orig_cas_flag == 0) { | |
memcached_behavior_set(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, orig_cas_flag); | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FROM_GET; | |
} | |
@@ -618,14 +612,16 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
* ourselves. | |
*/ | |
if (cas_token) { | |
+ ZVAL_DEREF(cas_token); | |
+ zval_ptr_dtor(cas_token); | |
ZVAL_DOUBLE(cas_token, 0.0); | |
} | |
if (status == MEMCACHED_NOTFOUND && fci.size != 0) { | |
- status = php_memc_do_cache_callback(getThis(), &fci, &fcc, key, key_len, return_value TSRMLS_CC); | |
+ status = php_memc_do_cache_callback(getThis(), &fci, &fcc, key, return_value); | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
memcached_result_free(&result); | |
RETURN_FROM_GET; | |
} | |
@@ -651,18 +647,21 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
cas = memcached_result_cas(&result); | |
} | |
- if (php_memc_zval_from_payload(return_value, payload, payload_len, flags, m_obj->serializer TSRMLS_CC) < 0) { | |
+ if (php_memc_zval_from_payload(return_value, payload, payload_len, flags, m_obj->serializer) < 0) { | |
memcached_result_free(&result); | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
RETURN_FROM_GET; | |
} | |
if (cas_token) { | |
- zval_dtor(cas_token); | |
+ ZVAL_DEREF(cas_token); | |
+ zval_ptr_dtor(cas_token); | |
ZVAL_DOUBLE(cas_token, (double)cas); | |
} | |
if (udf_flags) { | |
+ ZVAL_DEREF(udf_flags); | |
+ SEPARATE_ZVAL(udf_flags); | |
zval_dtor(udf_flags); | |
ZVAL_LONG(udf_flags, MEMC_VAL_GET_USER_FLAGS(flags)); | |
} | |
@@ -691,10 +690,9 @@ PHP_METHOD(Memcached, getMultiByKey) | |
static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
zval *keys = NULL; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *server_key = NULL; | |
size_t num_keys = 0; | |
- zval **entry = NULL; | |
+ zval *entry = NULL; | |
const char *payload = NULL; | |
size_t payload_len = 0; | |
const char **mkeys = NULL; | |
@@ -706,7 +704,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
zval *cas_tokens = NULL; | |
zval *udf_flags = NULL; | |
uint64_t orig_cas_flag = 0; | |
- zval *value; | |
+ zval value; | |
long get_flags = 0; | |
int i = 0; | |
zend_bool preserve_order; | |
@@ -715,12 +713,12 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa/|zlz", &server_key, | |
- &server_key_len, &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa/|zlz", &server_key, | |
+ &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|zlz", &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|zlz", &keys, &cas_tokens, &get_flags, &udf_flags) == FAILURE) { | |
return; | |
} | |
} | |
@@ -738,24 +736,21 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
* Create the array of keys for libmemcached. If none of the keys were valid | |
* (strings), set bad key result code and return. | |
*/ | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(keys)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(keys), (void**)&entry) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(keys))) { | |
- | |
- if (Z_TYPE_PP(entry) != IS_STRING) { | |
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { | |
+ if (Z_TYPE_P(entry) != IS_STRING) { | |
convert_to_string_ex(entry); | |
} | |
- if (Z_TYPE_PP(entry) == IS_STRING && Z_STRLEN_PP(entry) > 0) { | |
- mkeys[i] = Z_STRVAL_PP(entry); | |
- mkeys_len[i] = Z_STRLEN_PP(entry); | |
+ if (Z_TYPE_P(entry) == IS_STRING && Z_STRLEN_P(entry) > 0) { | |
+ mkeys[i] = Z_STRVAL_P(entry); | |
+ mkeys_len[i] = Z_STRLEN_P(entry); | |
if (preserve_order) { | |
- add_assoc_null_ex(return_value, mkeys[i], mkeys_len[i] + 1); | |
+ add_assoc_null_ex(return_value, mkeys[i], mkeys_len[i]); | |
} | |
i++; | |
} | |
- } | |
+ } ZEND_HASH_FOREACH_END(); | |
if (i == 0) { | |
i_obj->rescode = MEMCACHED_NOTFOUND; | |
@@ -767,21 +762,25 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
/* | |
* Enable CAS support, but only if it is currently disabled. | |
*/ | |
- if (cas_tokens && PZVAL_IS_REF(cas_tokens)) { | |
+ if (cas_tokens && Z_ISREF_P(cas_tokens)) { | |
orig_cas_flag = memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS); | |
if (orig_cas_flag == 0) { | |
memcached_behavior_set(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1); | |
} | |
} | |
- status = memcached_mget_by_key(m_obj->memc, server_key, server_key_len, mkeys, mkeys_len, i); | |
+ if (by_key) { | |
+ status = memcached_mget_by_key(m_obj->memc, server_key->val, server_key->len, mkeys, mkeys_len, i); | |
+ } else { | |
+ status = memcached_mget(m_obj->memc, mkeys, mkeys_len, i); | |
+ } | |
/* Handle error, but ignore, there might still be some result */ | |
- php_memc_handle_error(i_obj, status TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, status); | |
/* | |
* Restore the CAS support flag, but only if we had to turn it on. | |
*/ | |
- if (cas_tokens && PZVAL_IS_REF(cas_tokens) && orig_cas_flag == 0) { | |
+ if (cas_tokens && Z_ISREF_P(cas_tokens) && orig_cas_flag == 0) { | |
memcached_behavior_set(m_obj->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, orig_cas_flag); | |
} | |
@@ -793,15 +792,16 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
* returned as doubles, because we cannot store potential 64-bit values in longs. | |
*/ | |
if (cas_tokens) { | |
- if (PZVAL_IS_REF(cas_tokens)) { | |
+ if (Z_ISREF_P(cas_tokens)) { | |
/* cas_tokens was passed by reference, we'll create an array for it. */ | |
+ ZVAL_DEREF(cas_tokens); | |
+ SEPARATE_ZVAL(cas_tokens); | |
zval_dtor(cas_tokens); | |
array_init(cas_tokens); | |
} else { | |
/* Not passed by reference, we allow this (eg.: if you specify null | |
to not enable cas but you want to use the udf_flags parameter). | |
We destruct it and set it to null for the peace of mind. */ | |
- zval_dtor(cas_tokens); | |
cas_tokens = NULL; | |
} | |
} | |
@@ -811,6 +811,8 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
* returned as longs. | |
*/ | |
if (udf_flags) { | |
+ ZVAL_DEREF(udf_flags); | |
+ SEPARATE_ZVAL(udf_flags); | |
zval_dtor(udf_flags); | |
array_init(udf_flags); | |
} | |
@@ -821,7 +823,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
if (status != MEMCACHED_SUCCESS) { | |
status = MEMCACHED_SOME_ERRORS; | |
- php_memc_handle_error(i_obj, status TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, status); | |
continue; | |
} | |
@@ -838,13 +840,11 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
memcpy (res_key, tmp_key, res_key_len >= MEMCACHED_MAX_KEY ? MEMCACHED_MAX_KEY - 1 : res_key_len); | |
res_key [res_key_len] = '\0'; | |
- ALLOC_INIT_ZVAL(value); | |
- | |
- if (php_memc_zval_from_payload(value, payload, payload_len, flags, m_obj->serializer TSRMLS_CC) < 0) { | |
+ if (php_memc_zval_from_payload(&value, payload, payload_len, flags, m_obj->serializer) < 0) { | |
zval_ptr_dtor(&value); | |
if (EG(exception)) { | |
status = MEMC_RES_PAYLOAD_FAILURE; | |
- php_memc_handle_error(i_obj, status TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, status); | |
memcached_quit(m_obj->memc); | |
break; | |
@@ -855,13 +855,13 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
continue; | |
} | |
- add_assoc_zval_ex(return_value, res_key, res_key_len+1, value); | |
+ add_assoc_zval_ex(return_value, res_key, res_key_len, &value); | |
if (cas_tokens) { | |
cas = memcached_result_cas(&result); | |
- add_assoc_double_ex(cas_tokens, res_key, res_key_len+1, (double)cas); | |
+ add_assoc_double_ex(cas_tokens, res_key, res_key_len, (double)cas); | |
} | |
if (udf_flags) { | |
- add_assoc_long_ex(udf_flags, res_key, res_key_len+1, MEMC_VAL_GET_USER_FLAGS(flags)); | |
+ add_assoc_long_ex(udf_flags, res_key, res_key_len, MEMC_VAL_GET_USER_FLAGS(flags)); | |
} | |
} | |
@@ -870,10 +870,14 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
if (EG(exception)) { | |
/* XXX: cas_tokens should only be set on success, currently we're destructive */ | |
if (cas_tokens) { | |
+ ZVAL_DEREF(cas_tokens); | |
+ SEPARATE_ZVAL(cas_tokens); | |
zval_dtor(cas_tokens); | |
ZVAL_NULL(cas_tokens); | |
} | |
if (udf_flags) { | |
+ ZVAL_DEREF(udf_flags); | |
+ SEPARATE_ZVAL(udf_flags); | |
zval_dtor(udf_flags); | |
ZVAL_NULL(udf_flags); | |
} | |
@@ -903,11 +907,10 @@ PHP_METHOD(Memcached, getDelayedByKey) | |
static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
zval *keys = NULL; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *server_key = NULL; | |
zend_bool with_cas = 0; | |
size_t num_keys = 0; | |
- zval **entry = NULL; | |
+ zval *entry = NULL; | |
const char **mkeys = NULL; | |
size_t *mkeys_len = NULL; | |
uint64_t orig_cas_flag = 0; | |
@@ -918,12 +921,12 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa/|bf!", &server_key, | |
- &server_key_len, &keys, &with_cas, &fci, &fcc) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa/|bf!", &server_key, | |
+ &keys, &with_cas, &fci, &fcc) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|bf!", &keys, &with_cas, | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|bf!", &keys, &with_cas, | |
&fci, &fcc) == FAILURE) { | |
return; | |
} | |
@@ -940,20 +943,17 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
mkeys = safe_emalloc(num_keys, sizeof(*mkeys), 0); | |
mkeys_len = safe_emalloc(num_keys, sizeof(*mkeys_len), 0); | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(keys)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(keys), (void**)&entry) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(keys))) { | |
- | |
- if (Z_TYPE_PP(entry) != IS_STRING) { | |
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { | |
+ if (Z_TYPE_P(entry) != IS_STRING) { | |
convert_to_string_ex(entry); | |
} | |
- if (Z_TYPE_PP(entry) == IS_STRING && Z_STRLEN_PP(entry) > 0) { | |
- mkeys[i] = Z_STRVAL_PP(entry); | |
- mkeys_len[i] = Z_STRLEN_PP(entry); | |
+ if (Z_TYPE_P(entry) == IS_STRING && Z_STRLEN_P(entry) > 0) { | |
+ mkeys[i] = Z_STRVAL_P(entry); | |
+ mkeys_len[i] = Z_STRLEN_P(entry); | |
i++; | |
} | |
- } | |
+ } ZEND_HASH_FOREACH_END(); | |
if (i == 0) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
@@ -976,8 +976,11 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
/* | |
* Issue the request, but collect results only if the result callback is provided. | |
*/ | |
- status = memcached_mget_by_key(m_obj->memc, server_key, server_key_len, mkeys, mkeys_len, i); | |
- | |
+ if (by_key) { | |
+ status = memcached_mget_by_key(m_obj->memc, server_key->val, server_key->len, mkeys, mkeys_len, i); | |
+ } else { | |
+ status = memcached_mget(m_obj->memc, mkeys, mkeys_len, i); | |
+ } | |
/* | |
* Restore the CAS support flag, but only if we had to turn it on. | |
*/ | |
@@ -987,7 +990,7 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
efree(mkeys); | |
efree(mkeys_len); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
zval_dtor(return_value); | |
RETURN_FALSE; | |
} | |
@@ -1001,7 +1004,7 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
memcached_result_create(m_obj->memc, &result); | |
while ((memcached_fetch_result(m_obj->memc, &result, &status)) != NULL) { | |
- if (php_memc_do_result_callback(getThis(), &fci, &fcc, &result TSRMLS_CC) < 0) { | |
+ if (php_memc_do_result_callback(getThis(), &fci, &fcc, &result) < 0) { | |
status = MEMCACHED_FAILURE; | |
break; | |
} | |
@@ -1012,7 +1015,7 @@ static void php_memc_getDelayed_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ | |
if (status == MEMCACHED_END) { | |
status = MEMCACHED_SUCCESS; | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
} | |
@@ -1029,7 +1032,7 @@ PHP_METHOD(Memcached, fetch) | |
size_t res_key_len = 0; | |
const char *payload = NULL; | |
size_t payload_len = 0; | |
- zval *value; | |
+ zval value; | |
uint32_t flags = 0; | |
uint64_t cas = 0; | |
memcached_result_st result; | |
@@ -1045,7 +1048,7 @@ PHP_METHOD(Memcached, fetch) | |
memcached_result_create(m_obj->memc, &result); | |
if ((memcached_fetch_result(m_obj->memc, &result, &status)) == NULL) { | |
- php_memc_handle_error(i_obj, status TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, status); | |
memcached_result_free(&result); | |
RETURN_FALSE; | |
} | |
@@ -1057,9 +1060,7 @@ PHP_METHOD(Memcached, fetch) | |
res_key_len = memcached_result_key_length(&result); | |
cas = memcached_result_cas(&result); | |
- ALLOC_INIT_ZVAL(value); | |
- | |
- if (php_memc_zval_from_payload(value, payload, payload_len, flags, m_obj->serializer TSRMLS_CC) < 0) { | |
+ if (php_memc_zval_from_payload(&value, payload, payload_len, flags, m_obj->serializer) < 0) { | |
memcached_result_free(&result); | |
zval_ptr_dtor(&value); | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
@@ -1067,14 +1068,14 @@ PHP_METHOD(Memcached, fetch) | |
} | |
array_init(return_value); | |
- add_assoc_stringl_ex(return_value, ZEND_STRS("key"), res_key, res_key_len, 1); | |
- add_assoc_zval_ex(return_value, ZEND_STRS("value"), value); | |
+ add_assoc_stringl_ex(return_value, ZEND_STRL("key"), (char *)res_key, res_key_len); | |
+ add_assoc_zval_ex(return_value, ZEND_STRL("value"), &value); | |
if (cas != 0) { | |
/* XXX: also check against ULLONG_MAX or memc_behavior */ | |
- add_assoc_double_ex(return_value, ZEND_STRS("cas"), (double)cas); | |
+ add_assoc_double_ex(return_value, ZEND_STRL("cas"), (double)cas); | |
} | |
if (MEMC_VAL_GET_USER_FLAGS(flags) != 0) { | |
- add_assoc_long_ex(return_value, ZEND_STRS("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
+ add_assoc_long_ex(return_value, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
} | |
memcached_result_free(&result); | |
@@ -1089,7 +1090,7 @@ PHP_METHOD(Memcached, fetchAll) | |
size_t res_key_len = 0; | |
const char *payload = NULL; | |
size_t payload_len = 0; | |
- zval *value, *entry; | |
+ zval value, entry; | |
uint32_t flags; | |
uint64_t cas = 0; | |
memcached_result_st result; | |
@@ -1114,9 +1115,7 @@ PHP_METHOD(Memcached, fetchAll) | |
res_key_len = memcached_result_key_length(&result); | |
cas = memcached_result_cas(&result); | |
- ALLOC_INIT_ZVAL(value); | |
- | |
- if (php_memc_zval_from_payload(value, payload, payload_len, flags, m_obj->serializer TSRMLS_CC) < 0) { | |
+ if (php_memc_zval_from_payload(&value, payload, payload_len, flags, m_obj->serializer) < 0) { | |
memcached_result_free(&result); | |
zval_ptr_dtor(&value); | |
zval_dtor(return_value); | |
@@ -1124,23 +1123,22 @@ PHP_METHOD(Memcached, fetchAll) | |
RETURN_FALSE; | |
} | |
- MAKE_STD_ZVAL(entry); | |
- array_init(entry); | |
- add_assoc_stringl_ex(entry, ZEND_STRS("key"), res_key, res_key_len, 1); | |
- add_assoc_zval_ex(entry, ZEND_STRS("value"), value); | |
+ array_init(&entry); | |
+ add_assoc_stringl_ex(&entry, ZEND_STRL("key"), (char *)res_key, res_key_len); | |
+ add_assoc_zval_ex(&entry, ZEND_STRL("value"), &value); | |
if (cas != 0) { | |
/* XXX: also check against ULLONG_MAX or memc_behavior */ | |
- add_assoc_double_ex(entry, ZEND_STRS("cas"), (double)cas); | |
+ add_assoc_double_ex(&entry, ZEND_STRL("cas"), (double)cas); | |
} | |
if (MEMC_VAL_GET_USER_FLAGS(flags) != 0) { | |
- add_assoc_long_ex(entry, ZEND_STRS("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
+ add_assoc_long_ex(&entry, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
} | |
- add_next_index_zval(return_value, entry); | |
+ add_next_index_zval(return_value, &entry); | |
} | |
memcached_result_free(&result); | |
- if (status != MEMCACHED_END && php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (status != MEMCACHED_END && php_memc_handle_error(i_obj, status) < 0) { | |
zval_dtor(return_value); | |
RETURN_FALSE; | |
} | |
@@ -1227,13 +1225,11 @@ PHP_METHOD(Memcached, setMultiByKey) | |
static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
zval *entries; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *server_key = NULL; | |
time_t expiration = 0; | |
long udf_flags = 0; | |
- zval **entry; | |
- char *str_key; | |
- uint str_key_len; | |
+ zval *entry; | |
+ zend_string *skey, *str_key = NULL; | |
ulong num_key; | |
char *payload; | |
size_t payload_len; | |
@@ -1241,15 +1237,16 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
uint32_t retry = 0; | |
memcached_return status; | |
char tmp_key[MEMCACHED_MAX_KEY]; | |
+ int tmp_len = 0; | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|ll", &server_key, | |
- &server_key_len, &entries, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa|ll", &server_key, | |
+ &entries, &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ll", &entries, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ll", &entries, &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} | |
@@ -1263,24 +1260,21 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
*/ | |
if (udf_flags > 0) { | |
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
+ php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
} | |
} | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(entries)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(entries), (void**)&entry) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(entries))) { | |
- int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(entries), &str_key, &str_key_len, &num_key, 0, NULL); | |
- | |
- if (key_type == HASH_KEY_IS_LONG) { | |
+ ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P(entries), num_key, skey, entry) { | |
+ if (skey) { | |
+ str_key = skey; | |
+ } else if (num_key || num_key == 0) { | |
/* Array keys are unsigned, but php integers are signed. | |
* Keys must be converted to signed strings that match | |
* php integers. */ | |
assert(sizeof(tmp_key) >= sizeof(ZEND_TOSTR(LONG_MIN))); | |
- | |
- str_key_len = sprintf(tmp_key, "%ld", (long)num_key) + 1; | |
- str_key = (char *)tmp_key; | |
- } else if (key_type != HASH_KEY_IS_STRING) { | |
+ tmp_len = sprintf(tmp_key, "%ld", (long)num_key); | |
+ str_key = zend_string_init(tmp_key, tmp_len, 0); | |
+ } else { | |
continue; | |
} | |
@@ -1293,26 +1287,41 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke | |
MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); | |
} | |
- payload = php_memc_zval_to_payload(*entry, &payload_len, &flags, m_obj->serializer, m_obj->compression_type TSRMLS_CC); | |
+ payload = php_memc_zval_to_payload(entry, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); | |
if (payload == NULL) { | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
+ if (!skey) { | |
+ zend_string_release(str_key); | |
+ } | |
RETURN_FALSE; | |
} | |
retry: | |
if (!by_key) { | |
- status = memcached_set(m_obj->memc, str_key, str_key_len-1, payload, payload_len, expiration, flags); | |
+ status = memcached_set(m_obj->memc, str_key->val, str_key->len, payload, payload_len, expiration, flags); | |
+ if (!skey) { | |
+ zend_string_release(str_key); | |
+ } | |
} else { | |
- status = memcached_set_by_key(m_obj->memc, server_key, server_key_len, str_key, str_key_len-1, payload, payload_len, expiration, flags); | |
+ status = memcached_set_by_key(m_obj->memc, server_key->val, server_key->len, str_key->val, str_key->len, payload, payload_len, expiration, flags); | |
+ if (!skey) { | |
+ zend_string_release(str_key); | |
+ } | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
PHP_MEMC_FAILOVER_RETRY | |
+ if (!skey) { | |
+ zend_string_release(str_key); | |
+ } | |
efree(payload); | |
RETURN_FALSE; | |
} | |
+ if (!skey) { | |
+ zend_string_release(str_key); | |
+ } | |
efree(payload); | |
- } | |
+ } ZEND_HASH_FOREACH_END(); | |
RETURN_TRUE; | |
} | |
@@ -1382,16 +1391,12 @@ PHP_METHOD(Memcached, replaceByKey) | |
} | |
/* }}} */ | |
- | |
/* {{{ -- php_memc_store_impl */ | |
static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool by_key) | |
{ | |
- char *key = NULL; | |
- int key_len = 0; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
- char *s_value = NULL; | |
- int s_value_len = 0; | |
+ zend_string *key; | |
+ zend_string *server_key = NULL; | |
+ zend_string *s_value; | |
zval s_zvalue; | |
zval *value; | |
long expiration = 0; | |
@@ -1405,41 +1410,33 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool | |
if (by_key) { | |
if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &server_key, | |
- &server_key_len, &key, &key_len, &s_value, &s_value_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS", &server_key, &key, &s_value) == FAILURE) { | |
return; | |
} | |
- INIT_ZVAL(s_zvalue); | |
value = &s_zvalue; | |
- ZVAL_STRINGL(value, s_value, s_value_len, 0); | |
+ ZVAL_STR(value, s_value); | |
} else if (op == MEMC_OP_TOUCH) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &server_key, | |
- &server_key_len, &key, &key_len, &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &server_key, &key, &expiration) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz|ll", &server_key, | |
- &server_key_len, &key, &key_len, &value, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSz|ll", &server_key, &key, &value, &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} | |
} else { | |
if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, | |
- &s_value, &s_value_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &s_value) == FAILURE) { | |
return; | |
} | |
- INIT_ZVAL(s_zvalue); | |
value = &s_zvalue; | |
- ZVAL_STRINGL(value, s_value, s_value_len, 0); | |
+ ZVAL_STR(value, s_value); | |
} else if (op == MEMC_OP_TOUCH) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, | |
- &key_len, &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &key, &expiration) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|ll", &key, &key_len, | |
- &value, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz|ll", &key, &value, &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} | |
@@ -1448,7 +1445,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (key_len == 0 || strchr(key, ' ')) { | |
+ if (key->len == 0 || strchr(key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FALSE; | |
} | |
@@ -1460,7 +1457,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool | |
* append/prepend new data, and store it again. | |
*/ | |
if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot append/prepend with compression turned on"); | |
+ php_error_docref(NULL, E_WARNING, "cannot append/prepend with compression turned on"); | |
return; | |
} | |
MEMC_VAL_SET_FLAG(flags, MEMC_VAL_COMPRESSED); | |
@@ -1472,7 +1469,7 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool | |
*/ | |
if (udf_flags > 0) { | |
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
+ php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
} | |
MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); | |
} | |
@@ -1480,11 +1477,11 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool | |
if (op == MEMC_OP_TOUCH) { | |
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000016 | |
if (memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.16"); | |
+ php_error_docref(NULL, E_WARNING, "using touch command with binary protocol is not recommended with libmemcached versions below 1.0.16"); | |
} | |
#endif | |
} else { | |
- payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type TSRMLS_CC); | |
+ payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); | |
if (payload == NULL) { | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
RETURN_FALSE; | |
@@ -1494,55 +1491,55 @@ retry: | |
switch (op) { | |
case MEMC_OP_SET: | |
if (!server_key) { | |
- status = memcached_set(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags); | |
} else { | |
- status = memcached_set_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_set_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, payload, payload_len, expiration, flags); | |
} | |
break; | |
#ifdef HAVE_MEMCACHED_TOUCH | |
case MEMC_OP_TOUCH: | |
if (!server_key) { | |
- status = memcached_touch(m_obj->memc, key, key_len, expiration); | |
+ status = memcached_touch(m_obj->memc, key->val, key->len, expiration); | |
} else { | |
- status = memcached_touch_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, expiration); | |
+ status = memcached_touch_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, expiration); | |
} | |
break; | |
#endif | |
case MEMC_OP_ADD: | |
if (!server_key) { | |
- status = memcached_add(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_add(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags); | |
} else { | |
- status = memcached_add_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_add_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, payload, payload_len, expiration, flags); | |
} | |
break; | |
case MEMC_OP_REPLACE: | |
if (!server_key) { | |
- status = memcached_replace(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_replace(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags); | |
} else { | |
- status = memcached_replace_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_replace_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, payload, payload_len, expiration, flags); | |
} | |
break; | |
case MEMC_OP_APPEND: | |
if (!server_key) { | |
- status = memcached_append(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_append(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags); | |
} else { | |
- status = memcached_append_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_append_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, payload, payload_len, expiration, flags); | |
} | |
break; | |
case MEMC_OP_PREPEND: | |
if (!server_key) { | |
- status = memcached_prepend(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_prepend(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags); | |
} else { | |
- status = memcached_prepend_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, payload, payload_len, expiration, flags); | |
+ status = memcached_prepend_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, payload, payload_len, expiration, flags); | |
} | |
break; | |
@@ -1553,7 +1550,7 @@ retry: | |
break; | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
PHP_MEMC_FAILOVER_RETRY | |
RETVAL_FALSE; | |
} else { | |
@@ -1571,10 +1568,8 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
double cas_d; | |
uint64_t cas; | |
- char *key = NULL; | |
- int key_len = 0; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *key; | |
+ zend_string *server_key = NULL; | |
zval *value; | |
time_t expiration = 0; | |
long udf_flags = 0; | |
@@ -1585,13 +1580,13 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dssz|ll", &cas_d, &server_key, | |
- &server_key_len, &key, &key_len, &value, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "dSSz|ll", &cas_d, &server_key, &key, | |
+ &value, &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dsz|ll", &cas_d, &key, &key_len, | |
- &value, &expiration, &udf_flags) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "dSz|ll", &cas_d, &key, &value, | |
+ &expiration, &udf_flags) == FAILURE) { | |
return; | |
} | |
} | |
@@ -1599,7 +1594,7 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (key_len == 0 || strchr(key, ' ')) { | |
+ if (key->len == 0 || strchr(key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FALSE; | |
} | |
@@ -1616,24 +1611,24 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
*/ | |
if (udf_flags > 0) { | |
if ((uint32_t) udf_flags > MEMC_VAL_USER_FLAGS_MAX) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
+ php_error_docref(NULL, E_WARNING, "udf_flags will be limited to %u", MEMC_VAL_USER_FLAGS_MAX); | |
} | |
MEMC_VAL_SET_USER_FLAGS(flags, ((uint32_t) udf_flags)); | |
} | |
- payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type TSRMLS_CC); | |
+ payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); | |
if (payload == NULL) { | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
RETURN_FALSE; | |
} | |
if (by_key) { | |
- status = memcached_cas_by_key(m_obj->memc, server_key, server_key_len, key, key_len, payload, payload_len, expiration, flags, cas); | |
+ status = memcached_cas_by_key(m_obj->memc, server_key->val, server_key->len, key->val, key->len, payload, payload_len, expiration, flags, cas); | |
} else { | |
- status = memcached_cas(m_obj->memc, key, key_len, payload, payload_len, expiration, flags, cas); | |
+ status = memcached_cas(m_obj->memc, key->val, key->len, payload, payload_len, expiration, flags, cas); | |
} | |
efree(payload); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
@@ -1692,40 +1687,38 @@ PHP_METHOD(Memcached, deleteMultiByKey) | |
/* {{{ -- php_memc_delete_impl */ | |
static void php_memc_delete_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
- char *key = NULL; | |
- int key_len = 0; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *key, *server_key; | |
time_t expiration = 0; | |
memcached_return status; | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &server_key, | |
- &server_key_len, &key, &key_len, &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|l", &server_key, &key, &expiration) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &key_len, | |
- &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &key, &expiration) == FAILURE) { | |
return; | |
} | |
- server_key = key; | |
- server_key_len = key_len; | |
+ server_key = key; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (key_len == 0 || strchr(key, ' ')) { | |
+ if (key->len == 0 || strchr(key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FALSE; | |
} | |
- status = memcached_delete_by_key(m_obj->memc, server_key, server_key_len, key, | |
- key_len, expiration); | |
+ if (by_key) { | |
+ status = memcached_delete_by_key(m_obj->memc, server_key->val, server_key->len, key->val, | |
+ key->len, expiration); | |
+ } else { | |
+ status = memcached_delete(m_obj->memc, key->val, key->len, expiration); | |
+ } | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
@@ -1737,21 +1730,19 @@ static void php_memc_delete_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key) | |
{ | |
zval *entries; | |
- char *server_key = NULL; | |
- int server_key_len = 0; | |
+ zend_string *server_key = NULL; | |
time_t expiration = 0; | |
- zval **entry; | |
+ zval *entry; | |
memcached_return status; | |
MEMC_METHOD_INIT_VARS; | |
if (by_key) { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa/|l", &server_key, | |
- &server_key_len, &entries, &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa/|l", &server_key, &entries, &expiration) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &entries, &expiration) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|l", &entries, &expiration) == FAILURE) { | |
return; | |
} | |
} | |
@@ -1760,31 +1751,28 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
array_init(return_value); | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(entries)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(entries), (void**)&entry) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(entries))) { | |
- | |
- if (Z_TYPE_PP(entry) != IS_STRING) { | |
+ ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P(entries), entry) { | |
+ if (Z_TYPE_P(entry) != IS_STRING) { | |
convert_to_string_ex(entry); | |
} | |
- if (Z_STRLEN_PP(entry) == 0) { | |
+ if (Z_STRLEN_P(entry) == 0) { | |
continue; | |
} | |
- if (!by_key) { | |
- server_key = Z_STRVAL_PP(entry); | |
- server_key_len = Z_STRLEN_PP(entry); | |
+ if (by_key) { | |
+ status = memcached_delete_by_key(m_obj->memc, server_key->val, server_key->len, Z_STRVAL_P(entry), Z_STRLEN_P(entry), expiration); | |
+ } else { | |
+ status = memcached_delete_by_key(m_obj->memc, Z_STRVAL_P(entry), Z_STRLEN_P(entry), Z_STRVAL_P(entry), Z_STRLEN_P(entry), expiration); | |
} | |
- status = memcached_delete_by_key(m_obj->memc, server_key, server_key_len, Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), expiration); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
- add_assoc_long(return_value, Z_STRVAL_PP(entry), status); | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
+ add_assoc_long(return_value, Z_STRVAL_P(entry), status); | |
} else { | |
- add_assoc_bool(return_value, Z_STRVAL_PP(entry), 1); | |
+ add_assoc_bool(return_value, Z_STRVAL_P(entry), 1); | |
} | |
- } | |
+ } ZEND_HASH_FOREACH_END(); | |
return; | |
} | |
@@ -1793,8 +1781,7 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by | |
/* {{{ -- php_memc_incdec_impl */ | |
static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key, zend_bool incr) | |
{ | |
- char *key, *server_key; | |
- int key_len, server_key_len; | |
+ zend_string *key, *server_key = NULL; | |
long offset = 1; | |
uint64_t value, initial = 0; | |
time_t expiry = 0; | |
@@ -1805,11 +1792,11 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key, | |
MEMC_METHOD_INIT_VARS; | |
if (!by_key) { | |
- if (zend_parse_parameters(n_args TSRMLS_CC, "s|lll", &key, &key_len, &offset, &initial, &expiry) == FAILURE) { | |
+ if (zend_parse_parameters(n_args, "S|lll", &key, &offset, &initial, &expiry) == FAILURE) { | |
return; | |
} | |
} else { | |
- if (zend_parse_parameters(n_args TSRMLS_CC, "ss|lll", &server_key, &server_key_len, &key, &key_len, &offset, &initial, &expiry) == FAILURE) { | |
+ if (zend_parse_parameters(n_args, "SS|lll", &server_key, &key, &offset, &initial, &expiry) == FAILURE) { | |
return; | |
} | |
} | |
@@ -1817,13 +1804,13 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key, | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (key_len == 0 || strchr(key, ' ')) { | |
+ if (key->len == 0 || strchr(key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FALSE; | |
} | |
if (offset < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "offset has to be > 0"); | |
+ php_error_docref(NULL, E_WARNING, "offset has to be > 0"); | |
RETURN_FALSE; | |
} | |
@@ -1831,38 +1818,38 @@ retry: | |
if ((!by_key && n_args < 3) || (by_key && n_args < 4)) { | |
if (by_key) { | |
if (incr) { | |
- status = memcached_increment_by_key(m_obj->memc, server_key, server_key_len, key, key_len, (unsigned int)offset, &value); | |
+ status = memcached_increment_by_key(m_obj->memc, server_key->val, server_key->len, key->val, key->len, (unsigned int)offset, &value); | |
} else { | |
- status = memcached_decrement_by_key(m_obj->memc, server_key, server_key_len, key, key_len, (unsigned int)offset, &value); | |
+ status = memcached_decrement_by_key(m_obj->memc, server_key->val, server_key->len, key->val, key->len, (unsigned int)offset, &value); | |
} | |
} else { | |
if (incr) { | |
- status = memcached_increment(m_obj->memc, key, key_len, (unsigned int)offset, &value); | |
+ status = memcached_increment(m_obj->memc, key->val, key->len, (unsigned int)offset, &value); | |
} else { | |
- status = memcached_decrement(m_obj->memc, key, key_len, (unsigned int)offset, &value); | |
+ status = memcached_decrement(m_obj->memc, key->val, key->len, (unsigned int)offset, &value); | |
} | |
} | |
} else { | |
if (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Initial value is only supported with binary protocol"); | |
+ php_error_docref(NULL, E_WARNING, "Initial value is only supported with binary protocol"); | |
RETURN_FALSE; | |
} | |
if (by_key) { | |
if (incr) { | |
- status = memcached_increment_with_initial_by_key(m_obj->memc, server_key, server_key_len, key, key_len, (unsigned int)offset, initial, expiry, &value); | |
+ status = memcached_increment_with_initial_by_key(m_obj->memc, server_key->val, server_key->len, key->val, key->len, (unsigned int)offset, initial, expiry, &value); | |
} else { | |
- status = memcached_decrement_with_initial_by_key(m_obj->memc, server_key, server_key_len, key, key_len, (unsigned int)offset, initial, expiry, &value); | |
+ status = memcached_decrement_with_initial_by_key(m_obj->memc, server_key->val, server_key->len, key->val, key->len, (unsigned int)offset, initial, expiry, &value); | |
} | |
} else { | |
if (incr) { | |
- status = memcached_increment_with_initial(m_obj->memc, key, key_len, (unsigned int)offset, initial, expiry, &value); | |
+ status = memcached_increment_with_initial(m_obj->memc, key->val, key->len, (unsigned int)offset, initial, expiry, &value); | |
} else { | |
- status = memcached_decrement_with_initial(m_obj->memc, key, key_len, (unsigned int)offset, initial, expiry, &value); | |
+ status = memcached_decrement_with_initial(m_obj->memc, key->val, key->len, (unsigned int)offset, initial, expiry, &value); | |
} | |
} | |
} | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
PHP_MEMC_FAILOVER_RETRY | |
RETURN_FALSE; | |
} | |
@@ -1907,14 +1894,12 @@ PHP_METHOD(Memcached, incrementByKey) | |
Adds the given memcache server to the list */ | |
PHP_METHOD(Memcached, addServer) | |
{ | |
- char *host; | |
- int host_len; | |
+ zend_string *host; | |
long port, weight = 0; | |
memcached_return status; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &host, &host_len, | |
- &port, &weight) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l", &host, &port, &weight) == FAILURE) { | |
return; | |
} | |
@@ -1922,18 +1907,18 @@ PHP_METHOD(Memcached, addServer) | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000002 | |
- if (host[0] == '/') { /* unix domain socket */ | |
- status = memcached_server_add_unix_socket_with_weight(m_obj->memc, host, weight); | |
+ if (host->val[0] == '/') { /* unix domain socket */ | |
+ status = memcached_server_add_unix_socket_with_weight(m_obj->memc, host->val, weight); | |
} else if (memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_USE_UDP)) { | |
- status = memcached_server_add_udp_with_weight(m_obj->memc, host, port, weight); | |
+ status = memcached_server_add_udp_with_weight(m_obj->memc, host->val, port, weight); | |
} else { | |
- status = memcached_server_add_with_weight(m_obj->memc, host, port, weight); | |
+ status = memcached_server_add_with_weight(m_obj->memc, host->val, port, weight); | |
} | |
#else | |
- status = memcached_server_add_with_weight(m_obj->memc, host, port, weight); | |
+ status = memcached_server_add_with_weight(m_obj->memc, host->val, port, weight); | |
#endif | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
@@ -1946,45 +1931,46 @@ PHP_METHOD(Memcached, addServer) | |
PHP_METHOD(Memcached, addServers) | |
{ | |
zval *servers; | |
- zval **entry; | |
- zval **z_host, **z_port, **z_weight = NULL; | |
+ zval *entry; | |
+ zval *z_host, *z_port, *z_weight = NULL; | |
uint32_t weight = 0; | |
+ HashPosition pos; | |
int entry_size, i = 0; | |
memcached_server_st *list = NULL; | |
memcached_return status; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &servers) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &servers) == FAILURE) { | |
return; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(servers)), i = 0; | |
- zend_hash_get_current_data(Z_ARRVAL_P(servers), (void **)&entry) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(servers)), i++) { | |
- | |
- if (Z_TYPE_PP(entry) != IS_ARRAY) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "server list entry #%d is not an array", i+1); | |
+ ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P(servers), entry) { | |
+ if (Z_TYPE_P(entry) != IS_ARRAY) { | |
+ php_error_docref(NULL, E_WARNING, "server list entry #%d is not an array", i+1); | |
+ i++; | |
continue; | |
} | |
- entry_size = zend_hash_num_elements(Z_ARRVAL_PP(entry)); | |
+ entry_size = zend_hash_num_elements(Z_ARRVAL_P(entry)); | |
if (entry_size > 1) { | |
- zend_hash_internal_pointer_reset(Z_ARRVAL_PP(entry)); | |
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(entry), &pos); | |
/* Check that we have a host */ | |
- if (zend_hash_get_current_data(Z_ARRVAL_PP(entry), (void **)&z_host) == FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not get server host for entry #%d", i+1); | |
+ if ((z_host = zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), &pos)) == NULL) { | |
+ php_error_docref(NULL, E_WARNING, "could not get server host for entry #%d", i+1); | |
+ i++; | |
continue; | |
} | |
/* Check that we have a port */ | |
- if (zend_hash_move_forward(Z_ARRVAL_PP(entry)) == FAILURE || | |
- zend_hash_get_current_data(Z_ARRVAL_PP(entry), (void **)&z_port) == FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not get server port for entry #%d", i+1); | |
+ if (zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos) == FAILURE || | |
+ (z_port = zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), &pos)) == NULL) { | |
+ php_error_docref(NULL, E_WARNING, "could not get server port for entry #%d", i+1); | |
+ i++; | |
continue; | |
} | |
@@ -1994,30 +1980,31 @@ PHP_METHOD(Memcached, addServers) | |
weight = 0; | |
if (entry_size > 2) { | |
/* Try to get weight */ | |
- if (zend_hash_move_forward(Z_ARRVAL_PP(entry)) == FAILURE || | |
- zend_hash_get_current_data(Z_ARRVAL_PP(entry), (void **)&z_weight) == FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not get server weight for entry #%d", i+1); | |
+ if (zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos) == FAILURE || | |
+ (z_weight = zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), &pos)) == NULL) { | |
+ php_error_docref(NULL, E_WARNING, "could not get server weight for entry #%d", i+1); | |
} | |
convert_to_long_ex(z_weight); | |
- weight = Z_LVAL_PP(z_weight); | |
+ weight = Z_LVAL_P(z_weight); | |
} | |
- list = memcached_server_list_append_with_weight(list, Z_STRVAL_PP(z_host), | |
- Z_LVAL_PP(z_port), weight, &status); | |
+ list = memcached_server_list_append_with_weight(list, Z_STRVAL_P(z_host), | |
+ Z_LVAL_P(z_port), weight, &status); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) == 0) { | |
+ if (php_memc_handle_error(i_obj, status) == 0) { | |
+ i++; | |
continue; | |
} | |
} | |
- | |
+ i++; | |
/* catch-all for all errors */ | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not add entry #%d to the server list", i+1); | |
- } | |
+ php_error_docref(NULL, E_WARNING, "could not add entry #%d to the server list", i+1); | |
+ } ZEND_HASH_FOREACH_END(); | |
status = memcached_server_push(m_obj->memc, list); | |
memcached_server_list_free(list); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
@@ -2025,7 +2012,6 @@ PHP_METHOD(Memcached, addServers) | |
} | |
/* }}} */ | |
- | |
/* {{{ Memcached::getServerList() | |
Returns the list of the memcache servers in use */ | |
PHP_METHOD(Memcached, getServerList) | |
@@ -2051,32 +2037,31 @@ PHP_METHOD(Memcached, getServerList) | |
Returns the server identified by the given server key */ | |
PHP_METHOD(Memcached, getServerByKey) | |
{ | |
- char *server_key; | |
- int server_key_len; | |
+ zend_string *server_key; | |
php_memcached_instance_st server_instance; | |
memcached_return error; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &server_key, &server_key_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &server_key) == FAILURE) { | |
return; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
- if (server_key_len == 0 || strchr(server_key, ' ')) { | |
+ if (server_key->len == 0 || strchr(server_key->val, ' ')) { | |
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED; | |
RETURN_FALSE; | |
} | |
- server_instance = memcached_server_by_key(m_obj->memc, server_key, server_key_len, &error); | |
+ server_instance = memcached_server_by_key(m_obj->memc, server_key->val, server_key->len, &error); | |
if (server_instance == NULL) { | |
- php_memc_handle_error(i_obj, error TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, error); | |
RETURN_FALSE; | |
} | |
array_init(return_value); | |
- add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance), 1); | |
+ add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance)); | |
add_assoc_long(return_value, "port", memcached_server_port(server_instance)); | |
add_assoc_long(return_value, "weight", 0); | |
} | |
@@ -2144,7 +2129,7 @@ PHP_METHOD(Memcached, getLastErrorMessage) | |
MEMC_METHOD_FETCH_OBJECT; | |
- RETURN_STRING(memcached_last_error_message(m_obj->memc), 1); | |
+ RETURN_STRING(memcached_last_error_message(m_obj->memc)); | |
} | |
/* }}} */ | |
@@ -2201,7 +2186,7 @@ PHP_METHOD(Memcached, getLastDisconnectedServer) | |
} | |
array_init(return_value); | |
- add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance), 1); | |
+ add_assoc_string(return_value, "host", (char*) memcached_server_name(server_instance)); | |
add_assoc_long(return_value, "port", memcached_server_port(server_instance)); | |
} | |
/* }}} */ | |
@@ -2228,7 +2213,7 @@ PHP_METHOD(Memcached, getStats) | |
} | |
stats = memcached_stat(m_obj->memc, NULL, &status); | |
- php_memc_handle_error(i_obj, status TSRMLS_CC); | |
+ php_memc_handle_error(i_obj, status); | |
if (stats == NULL) { | |
RETURN_FALSE; | |
} else if (status != MEMCACHED_SUCCESS && status != MEMCACHED_SOME_ERRORS) { | |
@@ -2266,7 +2251,7 @@ PHP_METHOD(Memcached, getVersion) | |
array_init(return_value); | |
status = memcached_version(m_obj->memc); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
zval_dtor(return_value); | |
RETURN_FALSE; | |
} | |
@@ -2284,7 +2269,7 @@ static memcached_return php_memc_dump_func_callback(const memcached_st *ptr __at | |
const char *key, size_t key_length, void *context) | |
{ | |
zval *ctx = (zval*) context; | |
- add_next_index_string(ctx, (char*) key, 1); | |
+ add_next_index_string(ctx, (char*) key); | |
return MEMCACHED_SUCCESS; | |
} | |
@@ -2300,7 +2285,7 @@ PHP_METHOD(Memcached, getAllKeys) | |
array_init(return_value); | |
rc = memcached_dump(m_obj->memc, callback, return_value, 1); | |
- if (php_memc_handle_error(i_obj, rc TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, rc) < 0) { | |
zval_dtor(return_value); | |
RETURN_FALSE; | |
} | |
@@ -2315,7 +2300,7 @@ static PHP_METHOD(Memcached, flush) | |
memcached_return status; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &delay) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &delay) == FAILURE) { | |
return; | |
} | |
@@ -2323,7 +2308,7 @@ static PHP_METHOD(Memcached, flush) | |
i_obj->rescode = MEMCACHED_SUCCESS; | |
status = memcached_flush(m_obj->memc, delay); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
@@ -2340,7 +2325,7 @@ static PHP_METHOD(Memcached, getOption) | |
memcached_behavior flag; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &option) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &option) == FAILURE) { | |
return; | |
} | |
@@ -2361,9 +2346,9 @@ static PHP_METHOD(Memcached, getOption) | |
result = memcached_callback_get(m_obj->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) - 1, 1); | |
+ RETURN_STRINGL(result, strlen(result)); | |
#else | |
- RETURN_STRING(result, 1); | |
+ RETURN_STRING(result); | |
#endif | |
} else { | |
RETURN_EMPTY_STRING(); | |
@@ -2381,7 +2366,7 @@ static PHP_METHOD(Memcached, getOption) | |
case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: | |
case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE: | |
if (memcached_server_count(m_obj->memc) == 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "no servers defined"); | |
+ php_error_docref(NULL, E_WARNING, "no servers defined"); | |
return; | |
} | |
@@ -2396,7 +2381,7 @@ static PHP_METHOD(Memcached, getOption) | |
} | |
/* }}} */ | |
-static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRMLS_DC) | |
+static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value) | |
{ | |
memcached_return rc = MEMCACHED_FAILURE; | |
memcached_behavior flag; | |
@@ -2443,7 +2428,7 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
} | |
if (memcached_callback_set(m_obj->memc, MEMCACHED_CALLBACK_PREFIX_KEY, key) == MEMCACHED_BAD_KEY_PROVIDED) { | |
i_obj->rescode = MEMCACHED_INVALID_ARGUMENTS; | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad key provided"); | |
+ php_error_docref(NULL, E_WARNING, "bad key provided"); | |
return 0; | |
} | |
} | |
@@ -2455,8 +2440,8 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
convert_to_long(value); | |
rc = memcached_behavior_set(m_obj->memc, flag, (uint64_t) Z_LVAL_P(value)); | |
- if (php_memc_handle_error(i_obj, rc TSRMLS_CC) < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "error setting memcached option: %s", memcached_strerror (m_obj->memc, rc)); | |
+ if (php_memc_handle_error(i_obj, rc) < 0) { | |
+ php_error_docref(NULL, E_WARNING, "error setting memcached option: %s", memcached_strerror (m_obj->memc, rc)); | |
return 0; | |
} | |
@@ -2505,7 +2490,7 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
} else { | |
m_obj->serializer = SERIALIZER_PHP; | |
i_obj->rescode = MEMCACHED_INVALID_ARGUMENTS; | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid serializer provided"); | |
+ php_error_docref(NULL, E_WARNING, "invalid serializer provided"); | |
return 0; | |
} | |
break; | |
@@ -2535,8 +2520,8 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
} | |
} | |
- if (php_memc_handle_error(i_obj, rc TSRMLS_CC) < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "error setting memcached option: %s", memcached_strerror (m_obj->memc, rc)); | |
+ if (php_memc_handle_error(i_obj, rc) < 0) { | |
+ php_error_docref(NULL, E_WARNING, "error setting memcached option: %s", memcached_strerror (m_obj->memc, rc)); | |
return 0; | |
} | |
break; | |
@@ -2545,9 +2530,9 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML | |
} | |
static | |
-uint32_t *s_zval_to_uint32_array (zval *input, size_t *num_elements TSRMLS_DC) | |
+uint32_t *s_zval_to_uint32_array (zval *input, size_t *num_elements) | |
{ | |
- zval **ppzval; | |
+ zval *pzval; | |
uint32_t *retval; | |
size_t i = 0; | |
@@ -2559,34 +2544,25 @@ uint32_t *s_zval_to_uint32_array (zval *input, size_t *num_elements TSRMLS_DC) | |
retval = ecalloc(*num_elements, sizeof(uint32_t)); | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(input)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(input), (void **) &ppzval) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(input)), i++) { | |
- | |
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), pzval) { | |
long value = 0; | |
- if (Z_TYPE_PP(ppzval) == IS_LONG) { | |
- value = Z_LVAL_PP(ppzval); | |
- } | |
- else { | |
- zval tmp_zval, *tmp_pzval; | |
- tmp_zval = **ppzval; | |
- zval_copy_ctor(&tmp_zval); | |
- tmp_pzval = &tmp_zval; | |
- convert_to_long(tmp_pzval); | |
- | |
- value = (Z_LVAL_P(tmp_pzval) > 0) ? Z_LVAL_P(tmp_pzval) : 0; | |
- zval_dtor(tmp_pzval); | |
+ if (Z_TYPE_P(pzval) == IS_LONG) { | |
+ value = Z_LVAL_P(pzval); | |
+ } else { | |
+ value = zval_get_long(pzval); | |
+ value = value > 0? value : 0; | |
} | |
if (value < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "the map must contain positive integers"); | |
+ php_error_docref(NULL, E_WARNING, "the map must contain positive integers"); | |
efree (retval); | |
*num_elements = 0; | |
return NULL; | |
} | |
retval [i] = (uint32_t) value; | |
- } | |
+ i++; | |
+ } ZEND_HASH_FOREACH_END(); | |
return retval; | |
} | |
@@ -2605,35 +2581,35 @@ PHP_METHOD(Memcached, setBucket) | |
memcached_return rc; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa!l", &zserver_map, &zforward_map, &replicas) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa!l", &zserver_map, &zforward_map, &replicas) == FAILURE) { | |
return; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
if (zend_hash_num_elements (Z_ARRVAL_P(zserver_map)) == 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "server map cannot be empty"); | |
+ php_error_docref(NULL, E_WARNING, "server map cannot be empty"); | |
RETURN_FALSE; | |
} | |
if (zforward_map && zend_hash_num_elements (Z_ARRVAL_P(zserver_map)) != zend_hash_num_elements (Z_ARRVAL_P(zforward_map))) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "forward_map length must match the server_map length"); | |
+ php_error_docref(NULL, E_WARNING, "forward_map length must match the server_map length"); | |
RETURN_FALSE; | |
} | |
if (replicas < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "replicas must be larger than zero"); | |
+ php_error_docref(NULL, E_WARNING, "replicas must be larger than zero"); | |
RETURN_FALSE; | |
} | |
- server_map = s_zval_to_uint32_array (zserver_map, &server_map_len TSRMLS_CC); | |
+ server_map = s_zval_to_uint32_array (zserver_map, &server_map_len); | |
if (!server_map) { | |
RETURN_FALSE; | |
} | |
if (zforward_map) { | |
- forward_map = s_zval_to_uint32_array (zforward_map, &forward_map_len TSRMLS_CC); | |
+ forward_map = s_zval_to_uint32_array (zforward_map, &forward_map_len); | |
if (!forward_map) { | |
efree (server_map); | |
@@ -2643,7 +2619,7 @@ PHP_METHOD(Memcached, setBucket) | |
rc = memcached_bucket_set (m_obj->memc, server_map, forward_map, (uint32_t) server_map_len, replicas); | |
- if (php_memc_handle_error(i_obj, rc TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, rc) < 0) { | |
retval = 0;; | |
} | |
@@ -2662,38 +2638,33 @@ static PHP_METHOD(Memcached, setOptions) | |
{ | |
zval *options; | |
zend_bool ok = 1; | |
- uint key_len; | |
- char *key; | |
+ zend_string *key; | |
ulong key_index; | |
- zval **value; | |
+ zval *value; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &options) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &options) == FAILURE) { | |
return; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(options)); | |
- zend_hash_get_current_data(Z_ARRVAL_P(options), (void *) &value) == SUCCESS; | |
- zend_hash_move_forward(Z_ARRVAL_P(options))) { | |
- | |
- if (zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &key, &key_len, &key_index, 0, NULL) == HASH_KEY_IS_LONG) { | |
- zval copy = **value; | |
- zval_copy_ctor(©); | |
- INIT_PZVAL(©); | |
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), key_index, key, value) { | |
+ if (key) { | |
+ php_error_docref(NULL, E_WARNING, "invalid configuration option"); | |
+ ok = 0; | |
+ } else { | |
+ zval copy; | |
+ ZVAL_DUP(©, value); | |
- if (!php_memc_set_option(i_obj, (long) key_index, © TSRMLS_CC)) { | |
+ if (!php_memc_set_option(i_obj, (long) key_index, ©)) { | |
ok = 0; | |
} | |
zval_dtor(©); | |
- } else { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid configuration option"); | |
- ok = 0; | |
} | |
- } | |
+ } ZEND_HASH_FOREACH_END(); | |
RETURN_BOOL(ok); | |
} | |
@@ -2707,13 +2678,13 @@ static PHP_METHOD(Memcached, setOption) | |
zval *value; | |
MEMC_METHOD_INIT_VARS; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &option, &value) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/", &option, &value) == FAILURE) { | |
return; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
- RETURN_BOOL(php_memc_set_option(i_obj, option, value TSRMLS_CC)); | |
+ RETURN_BOOL(php_memc_set_option(i_obj, option, value)); | |
} | |
/* }}} */ | |
@@ -2724,29 +2695,27 @@ static PHP_METHOD(Memcached, setSaslAuthData) | |
{ | |
MEMC_METHOD_INIT_VARS; | |
memcached_return status; | |
+ zend_string *user, *pass; | |
- char *user, *pass; | |
- int user_len, pass_len; | |
- | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &user, &user_len, &pass, &pass_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &user, &pass) == FAILURE) { | |
return; | |
} | |
if (!MEMC_G(use_sasl)) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "SASL support (memcached.use_sasl) isn't enabled in php.ini"); | |
+ php_error_docref(NULL, E_WARNING, "SASL support (memcached.use_sasl) isn't enabled in php.ini"); | |
RETURN_FALSE; | |
} | |
MEMC_METHOD_FETCH_OBJECT; | |
if (!memcached_behavior_get(m_obj->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "SASL is only supported with binary protocol"); | |
+ php_error_docref(NULL, E_WARNING, "SASL is only supported with binary protocol"); | |
RETURN_FALSE; | |
} | |
m_obj->has_sasl_data = 1; | |
- status = memcached_set_sasl_auth_data(m_obj->memc, user, pass); | |
+ status = memcached_set_sasl_auth_data(m_obj->memc, user->val, pass->val); | |
- if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) { | |
+ if (php_memc_handle_error(i_obj, status) < 0) { | |
RETURN_FALSE; | |
} | |
RETURN_TRUE; | |
@@ -2784,7 +2753,7 @@ static PHP_METHOD(Memcached, getResultMessage) | |
switch (i_obj->rescode) { | |
case MEMC_RES_PAYLOAD_FAILURE: | |
- RETURN_STRING("PAYLOAD FAILURE", 1); | |
+ RETURN_STRING("PAYLOAD FAILURE"); | |
break; | |
case MEMCACHED_ERRNO: | |
@@ -2795,11 +2764,11 @@ static PHP_METHOD(Memcached, getResultMessage) | |
int str_len; | |
str_len = spprintf(&str, 0, "%s: %s", memcached_strerror(m_obj->memc, (memcached_return)i_obj->rescode), | |
strerror(i_obj->memc_errno)); | |
- RETURN_STRINGL(str, str_len, 0); | |
+ RETURN_STRINGL(str, str_len); | |
} | |
/* Fall through */ | |
default: | |
- RETURN_STRING(memcached_strerror(m_obj->memc, (memcached_return)i_obj->rescode), 1); | |
+ RETURN_STRING(memcached_strerror(m_obj->memc, (memcached_return)i_obj->rescode)); | |
break; | |
} | |
@@ -2843,7 +2812,7 @@ static PHP_METHOD(Memcached, isPristine) | |
****************************************/ | |
/* {{{ constructor/destructor */ | |
-static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent TSRMLS_DC) | |
+static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent) | |
{ | |
#if HAVE_MEMCACHED_SASL | |
if (m_obj->has_sasl_data) { | |
@@ -2857,65 +2826,51 @@ static void php_memc_destroy(struct memc_obj *m_obj, zend_bool persistent TSRMLS | |
pefree(m_obj, persistent); | |
} | |
-static void php_memc_free_storage(php_memc_t *i_obj TSRMLS_DC) | |
+static void php_memc_free_storage(zend_object *obj) | |
{ | |
- zend_object_std_dtor(&i_obj->zo TSRMLS_CC); | |
- | |
+ php_memc_t *i_obj = php_memc_fetch_object(obj); | |
+ | |
if (i_obj->obj && !i_obj->is_persistent) { | |
- php_memc_destroy(i_obj->obj, 0 TSRMLS_CC); | |
+ php_memc_destroy(i_obj->obj, 0); | |
} | |
+ zend_object_std_dtor(&i_obj->zo); | |
i_obj->obj = NULL; | |
- efree(i_obj); | |
} | |
-zend_object_value php_memc_new(zend_class_entry *ce TSRMLS_DC) | |
+zend_object *php_memc_new(zend_class_entry *ce) | |
{ | |
- zend_object_value retval; | |
- php_memc_t *i_obj; | |
- | |
- i_obj = ecalloc(1, sizeof(*i_obj)); | |
- zend_object_std_init( &i_obj->zo, ce TSRMLS_CC ); | |
-#if PHP_VERSION_ID >= 50400 | |
- object_properties_init( (zend_object *) i_obj, ce); | |
-#else | |
- { | |
- zval *tmp; | |
- zend_hash_copy(i_obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); | |
- } | |
-#endif | |
- | |
- retval.handle = zend_objects_store_put(i_obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_memc_free_storage, NULL TSRMLS_CC); | |
- retval.handlers = &memcached_object_handlers; | |
- | |
- return retval; | |
+ php_memc_t *i_obj = ecalloc(1, sizeof(php_memc_t) + zend_object_properties_size(ce)); | |
+ | |
+ zend_object_std_init(&i_obj->zo, ce); | |
+ object_properties_init(&i_obj->zo, ce); | |
+ | |
+ i_obj->zo.handlers = &memcached_object_handlers; | |
+ | |
+ return &i_obj->zo; | |
} | |
#ifdef HAVE_MEMCACHED_PROTOCOL | |
static | |
-void php_memc_server_free_storage(php_memc_server_t *intern TSRMLS_DC) | |
+void php_memc_server_free_storage(php_memc_server_t *intern) | |
{ | |
- zend_object_std_dtor(&intern->zo TSRMLS_CC); | |
+ zend_object_std_dtor(&intern->zo); | |
efree (intern); | |
} | |
-zend_object_value php_memc_server_new(zend_class_entry *ce TSRMLS_DC) | |
+zend_object_value php_memc_server_new(zend_class_entry *ce) | |
{ | |
zend_object_value retval; | |
php_memc_server_t *intern; | |
zval *tmp; | |
intern = ecalloc(1, sizeof(php_memc_server_t)); | |
- zend_object_std_init (&intern->zo, ce TSRMLS_CC); | |
-#if PHP_VERSION_ID >= 50400 | |
- object_properties_init( (zend_object *) intern, ce); | |
-#else | |
- zend_hash_copy(intern->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); | |
-#endif | |
+ zend_object_std_init(&intern->zo, ce); | |
+ object_properties_init(&intern->zo, ce); | |
intern->handler = php_memc_proto_handler_new (); | |
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_memc_server_free_storage, NULL TSRMLS_CC); | |
+ retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_memc_server_free_storage, NULL); | |
retval.handlers = &memcached_server_object_handlers; | |
return retval; | |
@@ -2924,20 +2879,20 @@ zend_object_value php_memc_server_new(zend_class_entry *ce TSRMLS_DC) | |
ZEND_RSRC_DTOR_FUNC(php_memc_dtor) | |
{ | |
- if (rsrc->ptr) { | |
- struct memc_obj *m_obj = (struct memc_obj *)rsrc->ptr; | |
- php_memc_destroy(m_obj, 1 TSRMLS_CC); | |
- rsrc->ptr = NULL; | |
+ if (res->ptr) { | |
+ struct memc_obj *m_obj = (struct memc_obj *)res->ptr; | |
+ php_memc_destroy(m_obj, 1); | |
+ res->ptr = NULL; | |
} | |
} | |
ZEND_RSRC_DTOR_FUNC(php_memc_sess_dtor) | |
{ | |
- if (rsrc->ptr) { | |
- memcached_sess *memc_sess = (memcached_sess *)rsrc->ptr; | |
+ if (res->ptr) { | |
+ memcached_sess *memc_sess = (memcached_sess *)res->ptr; | |
memcached_free(memc_sess->memc_sess); | |
- pefree(rsrc->ptr, 1); | |
- rsrc->ptr = NULL; | |
+ pefree(res->ptr, 1); | |
+ res->ptr = NULL; | |
} | |
} | |
/* }}} */ | |
@@ -2946,18 +2901,17 @@ ZEND_RSRC_DTOR_FUNC(php_memc_sess_dtor) | |
static memcached_return php_memc_do_serverlist_callback(const memcached_st *ptr, php_memcached_instance_st instance, void *in_context) | |
{ | |
struct callbackContext* context = (struct callbackContext*) in_context; | |
- zval *array; | |
+ zval array; | |
- MAKE_STD_ZVAL(array); | |
- array_init(array); | |
- add_assoc_string(array, "host", (char*) memcached_server_name(instance), 1); | |
- add_assoc_long(array, "port", memcached_server_port(instance)); | |
+ array_init(&array); | |
+ add_assoc_string(&array, "host", (char*) memcached_server_name(instance)); | |
+ add_assoc_long(&array, "port", memcached_server_port(instance)); | |
/* | |
* API does not allow to get at this field. | |
add_assoc_long(array, "weight", instance->weight); | |
*/ | |
- add_next_index_zval(context->return_value, array); | |
+ add_next_index_zval(context->return_value, &array); | |
return MEMCACHED_SUCCESS; | |
} | |
@@ -2966,38 +2920,37 @@ static memcached_return php_memc_do_stats_callback(const memcached_st *ptr, php_ | |
char *hostport = NULL; | |
int hostport_len; | |
struct callbackContext* context = (struct callbackContext*) in_context; | |
- zval *entry; | |
+ zval entry; | |
hostport_len = spprintf(&hostport, 0, "%s:%d", memcached_server_name(instance), memcached_server_port(instance)); | |
- MAKE_STD_ZVAL(entry); | |
- array_init(entry); | |
- | |
- add_assoc_long(entry, "pid", context->stats[context->i].pid); | |
- add_assoc_long(entry, "uptime", context->stats[context->i].uptime); | |
- add_assoc_long(entry, "threads", context->stats[context->i].threads); | |
- add_assoc_long(entry, "time", context->stats[context->i].time); | |
- add_assoc_long(entry, "pointer_size", context->stats[context->i].pointer_size); | |
- add_assoc_long(entry, "rusage_user_seconds", context->stats[context->i].rusage_user_seconds); | |
- add_assoc_long(entry, "rusage_user_microseconds", context->stats[context->i].rusage_user_microseconds); | |
- add_assoc_long(entry, "rusage_system_seconds", context->stats[context->i].rusage_system_seconds); | |
- add_assoc_long(entry, "rusage_system_microseconds", context->stats[context->i].rusage_system_microseconds); | |
- add_assoc_long(entry, "curr_items", context->stats[context->i].curr_items); | |
- add_assoc_long(entry, "total_items", context->stats[context->i].total_items); | |
- add_assoc_long(entry, "limit_maxbytes", context->stats[context->i].limit_maxbytes); | |
- add_assoc_long(entry, "curr_connections", context->stats[context->i].curr_connections); | |
- add_assoc_long(entry, "total_connections", context->stats[context->i].total_connections); | |
- add_assoc_long(entry, "connection_structures", context->stats[context->i].connection_structures); | |
- add_assoc_long(entry, "bytes", context->stats[context->i].bytes); | |
- add_assoc_long(entry, "cmd_get", context->stats[context->i].cmd_get); | |
- add_assoc_long(entry, "cmd_set", context->stats[context->i].cmd_set); | |
- add_assoc_long(entry, "get_hits", context->stats[context->i].get_hits); | |
- add_assoc_long(entry, "get_misses", context->stats[context->i].get_misses); | |
- add_assoc_long(entry, "evictions", context->stats[context->i].evictions); | |
- add_assoc_long(entry, "bytes_read", context->stats[context->i].bytes_read); | |
- add_assoc_long(entry, "bytes_written", context->stats[context->i].bytes_written); | |
- add_assoc_stringl(entry, "version", context->stats[context->i].version, strlen(context->stats[context->i].version), 1); | |
- | |
- add_assoc_zval_ex(context->return_value, hostport, hostport_len+1, entry); | |
+ array_init(&entry); | |
+ | |
+ add_assoc_long(&entry, "pid", context->stats[context->i].pid); | |
+ add_assoc_long(&entry, "uptime", context->stats[context->i].uptime); | |
+ add_assoc_long(&entry, "threads", context->stats[context->i].threads); | |
+ add_assoc_long(&entry, "time", context->stats[context->i].time); | |
+ add_assoc_long(&entry, "pointer_size", context->stats[context->i].pointer_size); | |
+ add_assoc_long(&entry, "rusage_user_seconds", context->stats[context->i].rusage_user_seconds); | |
+ add_assoc_long(&entry, "rusage_user_microseconds", context->stats[context->i].rusage_user_microseconds); | |
+ add_assoc_long(&entry, "rusage_system_seconds", context->stats[context->i].rusage_system_seconds); | |
+ add_assoc_long(&entry, "rusage_system_microseconds", context->stats[context->i].rusage_system_microseconds); | |
+ add_assoc_long(&entry, "curr_items", context->stats[context->i].curr_items); | |
+ add_assoc_long(&entry, "total_items", context->stats[context->i].total_items); | |
+ add_assoc_long(&entry, "limit_maxbytes", context->stats[context->i].limit_maxbytes); | |
+ add_assoc_long(&entry, "curr_connections", context->stats[context->i].curr_connections); | |
+ add_assoc_long(&entry, "total_connections", context->stats[context->i].total_connections); | |
+ add_assoc_long(&entry, "connection_structures", context->stats[context->i].connection_structures); | |
+ add_assoc_long(&entry, "bytes", context->stats[context->i].bytes); | |
+ add_assoc_long(&entry, "cmd_get", context->stats[context->i].cmd_get); | |
+ add_assoc_long(&entry, "cmd_set", context->stats[context->i].cmd_set); | |
+ add_assoc_long(&entry, "get_hits", context->stats[context->i].get_hits); | |
+ add_assoc_long(&entry, "get_misses", context->stats[context->i].get_misses); | |
+ add_assoc_long(&entry, "evictions", context->stats[context->i].evictions); | |
+ add_assoc_long(&entry, "bytes_read", context->stats[context->i].bytes_read); | |
+ add_assoc_long(&entry, "bytes_written", context->stats[context->i].bytes_written); | |
+ add_assoc_stringl(&entry, "version", context->stats[context->i].version, strlen(context->stats[context->i].version)); | |
+ | |
+ add_assoc_zval_ex(context->return_value, hostport, hostport_len, &entry); | |
efree(hostport); | |
/* Increment the server count in our context structure. Failure to do so will cause only the stats for the last server to get displayed. */ | |
@@ -3012,7 +2965,7 @@ static memcached_return php_memc_do_version_callback(const memcached_st *ptr, ph | |
int hostport_len, version_len; | |
struct callbackContext* context = (struct callbackContext*) in_context; | |
- hostport_len = spprintf(&hostport, 0, "%s:%d", memcached_server_name(instance), memcached_server_port(instance)); | |
+ hostport_len = spprintf(&hostport, 0, "%s:%d", memcached_server_name(instance), memcached_server_port(instance) - 1); | |
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX >= 0x01000009 | |
version_len = snprintf(version, sizeof(version), "%d.%d.%d", | |
memcached_server_major_version(instance), | |
@@ -3025,12 +2978,12 @@ static memcached_return php_memc_do_version_callback(const memcached_st *ptr, ph | |
instance->micro_version); | |
#endif | |
- add_assoc_stringl_ex(context->return_value, hostport, hostport_len+1, version, version_len, 1); | |
+ add_assoc_stringl_ex(context->return_value, hostport, hostport_len, version, version_len); | |
efree(hostport); | |
return MEMCACHED_SUCCESS; | |
} | |
-static int php_memc_handle_error(php_memc_t *i_obj, memcached_return status TSRMLS_DC) | |
+static int php_memc_handle_error(php_memc_t *i_obj, memcached_return status) | |
{ | |
int result = 0; | |
@@ -3077,7 +3030,7 @@ static int php_memc_handle_error(php_memc_t *i_obj, memcached_return status TSRM | |
} | |
static | |
-char *s_compress_value (enum memcached_compression_type compression_type, const char *payload, size_t *payload_len, uint32_t *flags TSRMLS_DC) | |
+char *s_compress_value (enum memcached_compression_type compression_type, const char *payload, size_t *payload_len, uint32_t *flags) | |
{ | |
/* status */ | |
zend_bool compress_status = 0; | |
@@ -3117,7 +3070,7 @@ char *s_compress_value (enum memcached_compression_type compression_type, const | |
*payload_len = compressed_size + sizeof(uint32_t); | |
if (!compress_status) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not compress value"); | |
+ php_error_docref(NULL, E_WARNING, "could not compress value"); | |
MEMC_VAL_DEL_FLAG(*flags, MEMC_VAL_COMPRESSED); | |
efree (buffer); | |
@@ -3135,7 +3088,7 @@ char *s_compress_value (enum memcached_compression_type compression_type, const | |
} | |
static | |
-zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, smart_str *buf, uint32_t *flags TSRMLS_DC) | |
+zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, smart_str *buf, uint32_t *flags) | |
{ | |
switch (serializer) { | |
@@ -3144,8 +3097,8 @@ zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, | |
*/ | |
#ifdef HAVE_MEMCACHED_IGBINARY | |
case SERIALIZER_IGBINARY: | |
- if (igbinary_serialize((uint8_t **) &buf->c, &buf->len, value TSRMLS_CC) != 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not serialize value with igbinary"); | |
+ if (igbinary_serialize((uint8_t **) &buf->c, &buf->len, value) != 0) { | |
+ php_error_docref(NULL, E_WARNING, "could not serialize value with igbinary"); | |
return 0; | |
} | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_IGBINARY); | |
@@ -3160,9 +3113,9 @@ zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, | |
case SERIALIZER_JSON_ARRAY: | |
{ | |
#if HAVE_JSON_API_5_2 | |
- php_json_encode(buf, value TSRMLS_CC); | |
+ php_json_encode(buf, value); | |
#elif HAVE_JSON_API_5_3 | |
- php_json_encode(buf, value, 0 TSRMLS_CC); /* options */ | |
+ php_json_encode(buf, value, 0); /* options */ | |
#endif | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_JSON); | |
} | |
@@ -3174,9 +3127,9 @@ zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, | |
*/ | |
#ifdef HAVE_MEMCACHED_MSGPACK | |
case SERIALIZER_MSGPACK: | |
- php_msgpack_serialize(buf, value TSRMLS_CC); | |
+ php_msgpack_serialize(buf, value); | |
if (!buf->c) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not serialize value with msgpack"); | |
+ php_error_docref(NULL, E_WARNING, "could not serialize value with msgpack"); | |
return 0; | |
} | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_MSGPACK); | |
@@ -3190,11 +3143,11 @@ zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, | |
{ | |
php_serialize_data_t var_hash; | |
PHP_VAR_SERIALIZE_INIT(var_hash); | |
- php_var_serialize(buf, &value, &var_hash TSRMLS_CC); | |
+ php_var_serialize(buf, value, &var_hash); | |
PHP_VAR_SERIALIZE_DESTROY(var_hash); | |
- if (!buf->c) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not serialize value"); | |
+ if (!buf->s) { | |
+ php_error_docref(NULL, E_WARNING, "could not serialize value"); | |
return 0; | |
} | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_SERIALIZED); | |
@@ -3203,14 +3156,14 @@ zend_bool s_serialize_value (enum memcached_serializer serializer, zval *value, | |
} | |
/* Check for exceptions caused by serializers */ | |
- if (EG(exception) && buf->len) { | |
+ if (EG(exception) && buf->s->len) { | |
return 0; | |
} | |
return 1; | |
} | |
static | |
-char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags, enum memcached_serializer serializer, enum memcached_compression_type compression_type TSRMLS_DC) | |
+char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags, enum memcached_serializer serializer, enum memcached_compression_type compression_type) | |
{ | |
const char *pl; | |
size_t pl_len = 0; | |
@@ -3240,26 +3193,28 @@ char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_DOUBLE); | |
break; | |
- case IS_BOOL: | |
- if (Z_BVAL_P(value)) { | |
- pl_len = 1; | |
- tmp[0] = '1'; | |
- tmp[1] = '\0'; | |
- } else { | |
- pl_len = 0; | |
- tmp[0] = '\0'; | |
- } | |
+ case IS_TRUE: | |
+ pl_len = 1; | |
+ tmp[0] = '1'; | |
+ tmp[1] = '\0'; | |
+ pl = tmp; | |
+ MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_BOOL); | |
+ break; | |
+ | |
+ case IS_FALSE: | |
+ pl_len = 0; | |
+ tmp[0] = '\0'; | |
pl = tmp; | |
MEMC_VAL_SET_TYPE(*flags, MEMC_VAL_IS_BOOL); | |
break; | |
default: | |
- if (!s_serialize_value (serializer, value, &buf, flags TSRMLS_CC)) { | |
- smart_str_free (&buf); | |
+ if (!s_serialize_value (serializer, value, &buf, flags)) { | |
+ smart_str_free(&buf); | |
return NULL; | |
} | |
- pl = buf.c; | |
- pl_len = buf.len; | |
+ pl = buf.s->val; | |
+ pl_len = buf.s->len; | |
break; | |
} | |
@@ -3272,7 +3227,7 @@ char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags | |
if (MEMC_VAL_HAS_FLAG(*flags, MEMC_VAL_COMPRESSED)) { | |
/* status */ | |
*payload_len = pl_len; | |
- payload = s_compress_value (compression_type, pl, payload_len, flags TSRMLS_CC); | |
+ payload = s_compress_value (compression_type, pl, payload_len, flags); | |
} | |
/* If compression failed or value is below threshold we just use plain value */ | |
@@ -3281,14 +3236,14 @@ char *php_memc_zval_to_payload(zval *value, size_t *payload_len, uint32_t *flags | |
payload = estrndup(pl, pl_len); | |
} | |
- if (buf.len) { | |
+ if (buf.s) { | |
smart_str_free(&buf); | |
} | |
return payload; | |
} | |
static | |
-char *s_decompress_value (const char *payload, size_t *payload_len, uint32_t flags TSRMLS_DC) | |
+char *s_decompress_value (const char *payload, size_t *payload_len, uint32_t flags) | |
{ | |
char *buffer = NULL; | |
uint32_t len; | |
@@ -3329,7 +3284,7 @@ char *s_decompress_value (const char *payload, size_t *payload_len, uint32_t fla | |
} | |
if (!decompress_status) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not decompress value"); | |
+ php_error_docref(NULL, E_WARNING, "could not decompress value"); | |
efree(buffer); | |
return NULL; | |
} | |
@@ -3339,7 +3294,7 @@ char *s_decompress_value (const char *payload, size_t *payload_len, uint32_t fla | |
} | |
static | |
-zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_type, zval *value, const char *payload, size_t payload_len TSRMLS_DC) | |
+zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_type, zval *value, const char *payload, size_t payload_len) | |
{ | |
switch (val_type) { | |
case MEMC_VAL_IS_SERIALIZED: | |
@@ -3348,10 +3303,10 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ | |
php_unserialize_data_t var_hash; | |
PHP_VAR_UNSERIALIZE_INIT(var_hash); | |
- if (!php_var_unserialize(&value, (const unsigned char **)&payload_tmp, (const unsigned char *)payload_tmp + payload_len, &var_hash TSRMLS_CC)) { | |
+ if (!php_var_unserialize(value, (const unsigned char **)&payload_tmp, (const unsigned char *)payload_tmp + payload_len, &var_hash)) { | |
ZVAL_FALSE(value); | |
PHP_VAR_UNSERIALIZE_DESTROY(var_hash); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value"); | |
+ php_error_docref(NULL, E_WARNING, "could not unserialize value"); | |
return 0; | |
} | |
PHP_VAR_UNSERIALIZE_DESTROY(var_hash); | |
@@ -3360,14 +3315,14 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ | |
case MEMC_VAL_IS_IGBINARY: | |
#ifdef HAVE_MEMCACHED_IGBINARY | |
- if (igbinary_unserialize((uint8_t *)payload, payload_len, &value TSRMLS_CC)) { | |
+ if (igbinary_unserialize((uint8_t *)payload, payload_len, &value)) { | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value with igbinary"); | |
+ php_error_docref(NULL, E_WARNING, "could not unserialize value with igbinary"); | |
return 0; | |
} | |
#else | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value, no igbinary support"); | |
+ php_error_docref(NULL, E_WARNING, "could not unserialize value, no igbinary support"); | |
return 0; | |
#endif | |
break; | |
@@ -3375,23 +3330,23 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ | |
case MEMC_VAL_IS_JSON: | |
#ifdef HAVE_JSON_API | |
# if HAVE_JSON_API_5_2 | |
- php_json_decode(value, payload, payload_len, (serializer == SERIALIZER_JSON_ARRAY) TSRMLS_CC); | |
+ php_json_decode(value, payload, payload_len, (serializer == SERIALIZER_JSON_ARRAY)); | |
# elif HAVE_JSON_API_5_3 | |
- php_json_decode(value, payload, payload_len, (serializer == SERIALIZER_JSON_ARRAY), JSON_PARSER_DEFAULT_DEPTH TSRMLS_CC); | |
+ php_json_decode(value, payload, payload_len, (serializer == SERIALIZER_JSON_ARRAY), JSON_PARSER_DEFAULT_DEPTH); | |
# endif | |
#else | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value, no json support"); | |
+ php_error_docref(NULL, E_WARNING, "could not unserialize value, no json support"); | |
return 0; | |
#endif | |
break; | |
case MEMC_VAL_IS_MSGPACK: | |
#ifdef HAVE_MEMCACHED_MSGPACK | |
- php_msgpack_unserialize(value, payload, payload_len TSRMLS_CC); | |
+ php_msgpack_unserialize(value, payload, payload_len); | |
#else | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not unserialize value, no msgpack support"); | |
+ php_error_docref(NULL, E_WARNING, "could not unserialize value, no msgpack support"); | |
return 0; | |
#endif | |
break; | |
@@ -3400,7 +3355,7 @@ zend_bool s_unserialize_value (enum memcached_serializer serializer, int val_typ | |
} | |
/* The caller MUST free the payload */ | |
-static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_t payload_len, uint32_t flags, enum memcached_serializer serializer TSRMLS_DC) | |
+static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_t payload_len, uint32_t flags, enum memcached_serializer serializer) | |
{ | |
/* | |
A NULL payload is completely valid if length is 0, it is simply empty. | |
@@ -3411,7 +3366,7 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
if (payload_in == NULL && payload_len > 0) { | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, | |
+ php_error_docref(NULL, E_WARNING, | |
"Could not handle non-existing value of length %zu", payload_len); | |
return -1; | |
} else if (payload_in == NULL) { | |
@@ -3424,7 +3379,7 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
} | |
if (MEMC_VAL_HAS_FLAG(flags, MEMC_VAL_COMPRESSED)) { | |
- char *datas = s_decompress_value (payload_in, &payload_len, flags TSRMLS_CC); | |
+ char *datas = s_decompress_value (payload_in, &payload_len, flags); | |
if (!datas) { | |
ZVAL_FALSE(value); | |
return -1; | |
@@ -3437,12 +3392,7 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
switch (MEMC_VAL_GET_TYPE(flags)) { | |
case MEMC_VAL_IS_STRING: | |
- if (payload_emalloc) { | |
- ZVAL_STRINGL(value, pl, payload_len, 0); | |
- payload_emalloc = 0; | |
- } else { | |
- ZVAL_STRINGL(value, pl, payload_len, 1); | |
- } | |
+ ZVAL_STRINGL(value, pl, payload_len); | |
break; | |
case MEMC_VAL_IS_LONG: | |
@@ -3451,7 +3401,7 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
char conv_buf [128]; | |
if (payload_len >= 128) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read long value, too big"); | |
+ php_error_docref(NULL, E_WARNING, "could not read long value, too big"); | |
retval = -1; | |
} | |
else { | |
@@ -3469,7 +3419,7 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
char conv_buf [128]; | |
if (payload_len >= 128) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read double value, too big"); | |
+ php_error_docref(NULL, E_WARNING, "could not read double value, too big"); | |
retval = -1; | |
} | |
else { | |
@@ -3497,14 +3447,14 @@ static int php_memc_zval_from_payload(zval *value, const char *payload_in, size_ | |
case MEMC_VAL_IS_IGBINARY: | |
case MEMC_VAL_IS_JSON: | |
case MEMC_VAL_IS_MSGPACK: | |
- if (!s_unserialize_value (serializer, MEMC_VAL_GET_TYPE(flags), value, pl, payload_len TSRMLS_CC)) { | |
+ if (!s_unserialize_value (serializer, MEMC_VAL_GET_TYPE(flags), value, pl, payload_len)) { | |
retval = -1; | |
} | |
break; | |
default: | |
ZVAL_FALSE(value); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown payload type"); | |
+ php_error_docref(NULL, E_WARNING, "unknown payload type"); | |
retval = -1; | |
break; | |
} | |
@@ -3528,17 +3478,20 @@ zend_class_entry *php_memc_get_exception(void) | |
} | |
PHP_MEMCACHED_API | |
-zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC) | |
+zend_class_entry *php_memc_get_exception_base(int root) | |
{ | |
#if HAVE_SPL | |
if (!root) { | |
if (!spl_ce_RuntimeException) { | |
- zend_class_entry **pce; | |
- | |
- if (zend_hash_find(CG(class_table), "runtimeexception", | |
- sizeof("RuntimeException"), (void **) &pce) == SUCCESS) { | |
- spl_ce_RuntimeException = *pce; | |
- return *pce; | |
+ zend_class_entry *pce; | |
+ zval *pce_z; | |
+ | |
+ if ((pce_z = zend_hash_str_find(CG(class_table), | |
+ "runtimeexception", | |
+ sizeof("RuntimeException") - 1)) != NULL) { | |
+ pce = Z_CE_P(pce_z); | |
+ spl_ce_RuntimeException = pce; | |
+ return pce; | |
} | |
} else { | |
return spl_ce_RuntimeException; | |
@@ -3548,20 +3501,20 @@ zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC) | |
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2) | |
return zend_exception_get_default(); | |
#else | |
- return zend_exception_get_default(TSRMLS_C); | |
+ return zend_exception_get_default(); | |
#endif | |
} | |
static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_info *fci, | |
- zend_fcall_info_cache *fcc, char *key, | |
- size_t key_len, zval *value TSRMLS_DC) | |
+ zend_fcall_info_cache *fcc, zend_string *key, zval *value) | |
{ | |
char *payload = NULL; | |
size_t payload_len = 0; | |
- zval **params[4]; | |
- zval *retval; | |
- zval *z_key; | |
- zval *z_expiration; | |
+ zval params[4]; | |
+ zval retval; | |
+ zval z_key; | |
+ zval z_val; | |
+ zval *expiration, z_expiration; | |
uint32_t flags = 0; | |
memcached_return rc; | |
@@ -3569,40 +3522,39 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i | |
memcached_return status = MEMCACHED_SUCCESS; | |
int result; | |
- MAKE_STD_ZVAL(z_key); | |
- MAKE_STD_ZVAL(z_expiration); | |
- ZVAL_STRINGL(z_key, key, key_len, 1); | |
- ZVAL_NULL(value); | |
- ZVAL_LONG(z_expiration, 0); | |
+ ZVAL_STR(&z_key, key); | |
+ ZVAL_NULL(&z_val); | |
+ ZVAL_NEW_REF(&z_val, value); | |
+ ZVAL_NEW_REF(&z_expiration, value); | |
+ ZVAL_LONG(Z_REFVAL(z_expiration), 0); | |
- params[0] = &zmemc_obj; | |
- params[1] = &z_key; | |
- params[2] = &value; | |
- params[3] = &z_expiration; | |
+ ZVAL_COPY(¶ms[0], zmemc_obj); | |
+ ZVAL_COPY(¶ms[1], &z_key); | |
+ ZVAL_COPY_VALUE(¶ms[2], &z_val); | |
+ ZVAL_COPY_VALUE(¶ms[3], &z_expiration); | |
- fci->retval_ptr_ptr = &retval; | |
+ fci->retval = &retval; | |
fci->params = params; | |
- fci->param_count = sizeof(params) / sizeof(params[0]); | |
+ fci->param_count = 4; | |
- result = zend_call_function(fci, fcc TSRMLS_CC); | |
- if (result == SUCCESS && retval) { | |
- i_obj = (php_memc_t *) zend_object_store_get_object(zmemc_obj TSRMLS_CC); | |
- struct memc_obj *m_obj = i_obj->obj; | |
+ result = zend_call_function(fci, fcc); | |
+ ZVAL_DUP(value, Z_REFVAL(z_val)); | |
+ expiration = Z_REFVAL(z_expiration); | |
+ if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { | |
+ struct memc_obj *m_obj; | |
+ i_obj = Z_MEMC_OBJ_P(zmemc_obj) | |
+ m_obj = i_obj->obj; | |
- if (zend_is_true(retval)) { | |
- time_t expiration; | |
+ if (zend_is_true(&retval)) { | |
+ time_t expir; | |
- if (Z_TYPE_P(z_expiration) != IS_LONG) { | |
- convert_to_long(z_expiration); | |
- } | |
+ expir = zval_get_long(expiration); | |
- expiration = Z_LVAL_P(z_expiration); | |
- | |
- payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type TSRMLS_CC); | |
+ payload = php_memc_zval_to_payload(value, &payload_len, &flags, m_obj->serializer, m_obj->compression_type); | |
if (payload == NULL) { | |
status = (memcached_return)MEMC_RES_PAYLOAD_FAILURE; | |
} else { | |
- rc = memcached_set(m_obj->memc, key, key_len, payload, payload_len, expiration, flags); | |
+ rc = memcached_set(m_obj->memc, key->val, key->len, payload, payload_len, expir, flags); | |
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED) { | |
status = rc; | |
} | |
@@ -3616,18 +3568,19 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i | |
} else { | |
if (result == FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not invoke cache callback"); | |
+ php_error_docref(NULL, E_WARNING, "could not invoke cache callback"); | |
} | |
status = MEMCACHED_FAILURE; | |
zval_dtor(value); | |
ZVAL_NULL(value); | |
} | |
- if (retval) { | |
+ if (&retval) { | |
zval_ptr_dtor(&retval); | |
} | |
zval_ptr_dtor(&z_key); | |
+ zval_ptr_dtor(&z_val); | |
zval_ptr_dtor(&z_expiration); | |
return status; | |
@@ -3635,24 +3588,23 @@ static memcached_return php_memc_do_cache_callback(zval *zmemc_obj, zend_fcall_i | |
static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci, | |
zend_fcall_info_cache *fcc, | |
- memcached_result_st *result TSRMLS_DC) | |
+ memcached_result_st *result) | |
{ | |
const char *res_key = NULL; | |
size_t res_key_len = 0; | |
const char *payload = NULL; | |
size_t payload_len = 0; | |
- zval *value, *retval = NULL; | |
+ zval value; | |
+ zval retval; | |
uint64_t cas = 0; | |
- zval **params[2]; | |
- zval *z_result; | |
+ zval params[2]; | |
+ zval z_result; | |
uint32_t flags = 0; | |
int rc = 0; | |
php_memc_t *i_obj = NULL; | |
- params[0] = &zmemc_obj; | |
- params[1] = &z_result; | |
- | |
- fci->retval_ptr_ptr = &retval; | |
+ ZVAL_COPY(¶ms[0], zmemc_obj); | |
+ fci->retval = &retval; | |
fci->params = params; | |
fci->param_count = 2; | |
@@ -3663,35 +3615,35 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci, | |
res_key_len = memcached_result_key_length(result); | |
cas = memcached_result_cas(result); | |
- ALLOC_INIT_ZVAL(value); | |
- | |
- i_obj = (php_memc_t *) zend_object_store_get_object(zmemc_obj TSRMLS_CC); | |
+ i_obj = Z_MEMC_OBJ_P(zmemc_obj); | |
- if (php_memc_zval_from_payload(value, payload, payload_len, flags, i_obj->obj->serializer TSRMLS_CC) < 0) { | |
+ if (php_memc_zval_from_payload(&value, payload, payload_len, flags, i_obj->obj->serializer) < 0) { | |
zval_ptr_dtor(&value); | |
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE; | |
return -1; | |
} | |
- MAKE_STD_ZVAL(z_result); | |
- array_init(z_result); | |
- add_assoc_stringl_ex(z_result, ZEND_STRS("key"), res_key, res_key_len, 1); | |
- add_assoc_zval_ex(z_result, ZEND_STRS("value"), value); | |
+ array_init(&z_result); | |
+ ZVAL_COPY(¶ms[1], &z_result); | |
+ add_assoc_stringl_ex(&z_result, ZEND_STRL("key"), (char *)res_key, res_key_len); | |
+ add_assoc_zval_ex(&z_result, ZEND_STRL("value"), &value); | |
if (cas != 0) { | |
- add_assoc_double_ex(z_result, ZEND_STRS("cas"), (double)cas); | |
+ add_assoc_double_ex(&z_result, ZEND_STRL("cas"), (double)cas); | |
} | |
if (MEMC_VAL_GET_USER_FLAGS(flags) != 0) { | |
- add_assoc_long_ex(z_result, ZEND_STRS("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
+ add_assoc_long_ex(&z_result, ZEND_STRL("flags"), MEMC_VAL_GET_USER_FLAGS(flags)); | |
} | |
- if (zend_call_function(fci, fcc TSRMLS_CC) == FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not invoke result callback"); | |
+ if (zend_call_function(fci, fcc) == FAILURE) { | |
+ php_error_docref(NULL, E_WARNING, "could not invoke result callback"); | |
rc = -1; | |
} | |
- if (retval) { | |
+ if (&retval) { | |
zval_ptr_dtor(&retval); | |
} | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
zval_ptr_dtor(&z_result); | |
return rc; | |
@@ -3716,13 +3668,12 @@ PHP_METHOD(MemcachedServer, run) | |
{ | |
int i; | |
zend_bool rc; | |
- char *address; | |
- int address_len; | |
+ zend *address; | |
php_memc_server_t *intern; | |
- intern = (php_memc_server_t *) zend_object_store_get_object(getThis() TSRMLS_CC); | |
+ intern = Z_MEMC_OBJ_P(getThis()); | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &address, &address_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &address) == FAILURE) { | |
return; | |
} | |
@@ -3743,7 +3694,7 @@ PHP_METHOD(MemcachedServer, on) | |
zend_fcall_info_cache fci_cache; | |
zend_bool rc = 0; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lf!", &event, &fci, &fci_cache) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lf!", &event, &fci, &fci_cache) == FAILURE) { | |
return; | |
} | |
@@ -4245,9 +4196,9 @@ zend_module_entry memcached_module_entry = { | |
/* {{{ php_memc_register_constants */ | |
static void php_memc_register_constants(INIT_FUNC_ARGS) | |
{ | |
- #define REGISTER_MEMC_CLASS_CONST_LONG(name, value) zend_declare_class_constant_long(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value TSRMLS_CC) | |
- #define REGISTER_MEMC_CLASS_CONST_BOOL(name, value) zend_declare_class_constant_bool(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value TSRMLS_CC) | |
- #define REGISTER_MEMC_CLASS_CONST_NULL(name) zend_declare_class_constant_null(php_memc_get_ce() , ZEND_STRS( #name ) - 1 TSRMLS_CC) | |
+ #define REGISTER_MEMC_CLASS_CONST_LONG(name, value) zend_declare_class_constant_long(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value) | |
+ #define REGISTER_MEMC_CLASS_CONST_BOOL(name, value) zend_declare_class_constant_bool(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value) | |
+ #define REGISTER_MEMC_CLASS_CONST_NULL(name) zend_declare_class_constant_null(php_memc_get_ce() , ZEND_STRS( #name ) - 1) | |
/* | |
* Class options | |
@@ -4489,13 +4440,15 @@ PHP_MINIT_FUNCTION(memcached) | |
zend_class_entry ce; | |
memcpy(&memcached_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); | |
+ memcached_object_handlers.offset = XtOffsetOf(php_memc_t, zo); | |
memcached_object_handlers.clone_obj = NULL; | |
+ memcached_object_handlers.free_obj = php_memc_free_storage; | |
le_memc = zend_register_list_destructors_ex(NULL, php_memc_dtor, "Memcached persistent connection", module_number); | |
le_memc_sess = zend_register_list_destructors_ex(NULL, php_memc_sess_dtor, "Memcached Sessions persistent connection", module_number); | |
INIT_CLASS_ENTRY(ce, "Memcached", memcached_class_methods); | |
- memcached_ce = zend_register_internal_class(&ce TSRMLS_CC); | |
+ memcached_ce = zend_register_internal_class(&ce); | |
memcached_ce->create_object = php_memc_new; | |
#ifdef HAVE_MEMCACHED_PROTOCOL | |
@@ -4503,12 +4456,12 @@ PHP_MINIT_FUNCTION(memcached) | |
memcached_server_object_handlers.clone_obj = NULL; | |
INIT_CLASS_ENTRY(ce, "MemcachedServer", memcached_server_class_methods); | |
- memcached_server_ce = zend_register_internal_class(&ce TSRMLS_CC); | |
+ memcached_server_ce = zend_register_internal_class(&ce); | |
memcached_server_ce->create_object = php_memc_server_new; | |
#endif | |
INIT_CLASS_ENTRY(ce, "MemcachedException", NULL); | |
- memcached_exception_ce = zend_register_internal_class_ex(&ce, php_memc_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC); | |
+ memcached_exception_ce = zend_register_internal_class_ex(&ce, php_memc_get_exception_base(0)); | |
/* TODO | |
* possibly declare custom exception property here | |
*/ | |
@@ -4523,7 +4476,7 @@ PHP_MINIT_FUNCTION(memcached) | |
#if HAVE_MEMCACHED_SASL | |
if (MEMC_G(use_sasl)) { | |
if (sasl_client_init(NULL) != SASL_OK) { | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to initialize SASL library"); | |
+ php_error_docref(NULL, E_ERROR, "Failed to initialize SASL library"); | |
return FAILURE; | |
} | |
} | |
diff --git a/php_memcached.h b/php_memcached.h | |
index bce8e37..b96ef37 100644 | |
--- a/php_memcached.h | |
+++ b/php_memcached.h | |
@@ -20,6 +20,7 @@ | |
#define PHP_MEMCACHED_H | |
#include "php.h" | |
+#include "Zend/zend_smart_str.h" | |
#include "main/php_config.h" | |
#ifdef HAVE_CONFIG_H | |
@@ -36,7 +37,7 @@ | |
PHP_MEMCACHED_API zend_class_entry *php_memc_get_ce(void); | |
PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception(void); | |
-PHP_MEMCACHED_API zend_class_entry *php_memc_get_exception_base(int root TSRMLS_DC); | |
+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 | |
diff --git a/php_memcached_private.h b/php_memcached_private.h | |
index 0ec2d76..2929818 100644 | |
--- a/php_memcached_private.h | |
+++ b/php_memcached_private.h | |
@@ -41,7 +41,7 @@ | |
#include <ext/standard/info.h> | |
#include <zend_extensions.h> | |
#include <zend_exceptions.h> | |
-#include <ext/standard/php_smart_str.h> | |
+#include <ext/standard/php_smart_string.h> | |
#include <ext/standard/php_var.h> | |
#include <ext/standard/basic_functions.h> | |
diff --git a/php_memcached_server.c b/php_memcached_server.c | |
index 42ccc8e..eb225db 100644 | |
--- a/php_memcached_server.c | |
+++ b/php_memcached_server.c | |
@@ -60,7 +60,7 @@ typedef struct { | |
} php_memc_client_t; | |
static | |
-long s_invoke_php_callback (php_memc_server_cb_t *cb, zval ***params, ssize_t param_count TSRMLS_DC) | |
+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; | |
@@ -72,9 +72,9 @@ long s_invoke_php_callback (php_memc_server_cb_t *cb, zval ***params, ssize_t pa | |
cb->fci.no_separation = 1; | |
cb->fci.retval_ptr_ptr = &retval_ptr; | |
- if (zend_call_function(&(cb->fci), &(cb->fci_cache) TSRMLS_CC) == FAILURE) { | |
- char *buf = php_memc_printable_func (&(cb->fci), &(cb->fci_cache) TSRMLS_CC); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to invoke callback %s()", buf); | |
+ if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) { | |
+ 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) { | |
@@ -91,10 +91,8 @@ protocol_binary_response_status s_add_handler(const void *cookie, const void *ke | |
uint32_t data_len, uint32_t flags, uint32_t exptime, uint64_t *result_cas) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zvalue, *zflags, *zexptime, *zresult_cas; | |
- zval **params [6]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zvalue, zflags, zexptime, zresult_cas; | |
+ zval params[6]; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_ADD)) { | |
return retval; | |
@@ -102,32 +100,29 @@ protocol_binary_response_status s_add_handler(const void *cookie, const void *ke | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zvalue); | |
- ZVAL_STRINGL(zvalue, data, data_len, 1); | |
- | |
- MAKE_STD_ZVAL(zflags); | |
- ZVAL_LONG(zflags, flags); | |
- | |
- MAKE_STD_ZVAL(zexptime); | |
- ZVAL_LONG(zexptime, exptime); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_STRINGL(&zvalue, data, data_len); | |
+ ZVAL_LONG(&zflags, flags); | |
+ ZVAL_LONG(&zexptime, exptime); | |
+ ZVAL_NULL(&zresult_cas); | |
- MAKE_STD_ZVAL(zresult_cas); | |
- ZVAL_NULL(zresult_cas); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zvalue); | |
+ ZVAL_COPY(¶ms[3], &zflags); | |
+ ZVAL_COPY(¶ms[4], &zexptime); | |
+ ZVAL_COPY(¶ms[5], &zresult_cas); | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zvalue; | |
- params [3] = &zflags; | |
- params [4] = &zexptime; | |
- params [5] = &zresult_cas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_ADD), params, 6 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_ADD), params, 6); | |
MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
+ zval_ptr_dtor(¶ms[5]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zvalue); | |
@@ -143,10 +138,8 @@ protocol_binary_response_status s_append_prepend_handler (php_memc_event_t event | |
const void *data, uint32_t data_len, uint64_t cas, uint64_t *result_cas) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zvalue, *zcas, *zresult_cas; | |
- zval **params [5]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zvalue, zcas, zresult_cas; | |
+ zval params[5]; | |
if (!MEMC_HAS_CB(event)) { | |
return retval; | |
@@ -154,28 +147,26 @@ protocol_binary_response_status s_append_prepend_handler (php_memc_event_t event | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zvalue); | |
- ZVAL_STRINGL(zvalue, data, data_len, 1); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_STRINGL(&zvalue, data, data_len); | |
+ ZVAL_DOUBLE(&zcas, cas); | |
+ ZVAL_NULL(&zresult_cas); | |
- MAKE_STD_ZVAL(zcas); | |
- ZVAL_DOUBLE(zcas, cas); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zvalue); | |
+ ZVAL_COPY(¶ms[3], &zcas); | |
+ ZVAL_COPY(¶ms[4], &zresult_cas); | |
- MAKE_STD_ZVAL(zresult_cas); | |
- ZVAL_NULL(zresult_cas); | |
- | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zvalue; | |
- params [3] = &zcas; | |
- params [4] = &zresult_cas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 5 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 5); | |
MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zvalue); | |
@@ -206,10 +197,8 @@ protocol_binary_response_status s_incr_decr_handler (php_memc_event_t event, con | |
uint64_t initial, uint32_t expiration, uint64_t *result, uint64_t *result_cas) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zdelta, *zinital, *zexpiration, *zresult, *zresult_cas; | |
- zval **params [7]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zdelta, zinital, zexpiration, zresult, zresult_cas; | |
+ zval params[7]; | |
if (!MEMC_HAS_CB(event)) { | |
return retval; | |
@@ -217,41 +206,37 @@ protocol_binary_response_status s_incr_decr_handler (php_memc_event_t event, con | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zdelta); | |
- ZVAL_LONG(zdelta, (long) delta); | |
- | |
- MAKE_STD_ZVAL(zinital); | |
- ZVAL_LONG(zinital, (long) initial); | |
- | |
- MAKE_STD_ZVAL(zexpiration); | |
- ZVAL_LONG(zexpiration, (long) expiration); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_LONG(&zdelta, (long) delta); | |
+ ZVAL_LONG(&zinital, (long) initial); | |
+ ZVAL_LONG(&zexpiration, (long) expiration); | |
+ ZVAL_LONG(&zresult, 0); | |
+ ZVAL_NULL(&zresult_cas); | |
- MAKE_STD_ZVAL(zresult); | |
- ZVAL_LONG(zresult, 0); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zdelta); | |
+ ZVAL_COPY(¶ms[3], &zinital); | |
+ ZVAL_COPY(¶ms[4], &zexpiration); | |
+ ZVAL_COPY(¶ms[5], &zresult); | |
+ ZVAL_COPY(¶ms[6], &zresult_cas); | |
- MAKE_STD_ZVAL(zresult_cas); | |
- ZVAL_NULL(zresult_cas); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 7); | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zdelta; | |
- params [3] = &zinital; | |
- params [4] = &zexpiration; | |
- params [5] = &zresult; | |
- params [6] = &zresult_cas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 7 TSRMLS_CC); | |
- | |
- if (Z_TYPE_P(zresult) != IS_LONG) { | |
- convert_to_long (zresult); | |
+ if (Z_TYPE(zresult) != IS_LONG) { | |
+ convert_to_long (&zresult); | |
} | |
- *result = (uint64_t) Z_LVAL_P(zresult); | |
+ *result = (uint64_t) Z_LVAL(zresult); | |
MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
+ zval_ptr_dtor(¶ms[5]); | |
+ zval_ptr_dtor(¶ms[6]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zdelta); | |
@@ -284,10 +269,8 @@ protocol_binary_response_status s_delete_handler (const void *cookie, const void | |
uint16_t key_len, uint64_t cas) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zcas; | |
- zval **params [3]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zcas; | |
+ zval params[3]; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_DELETE)) { | |
return retval; | |
@@ -295,21 +278,21 @@ protocol_binary_response_status s_delete_handler (const void *cookie, const void | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zcas); | |
- ZVAL_DOUBLE(zcas, (double) cas); | |
- | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zcas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_DELETE), params, 3 TSRMLS_CC); | |
- | |
- zval_ptr_dtor (&zcookie); | |
- zval_ptr_dtor (&zkey); | |
- zval_ptr_dtor (&zcas); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_DOUBLE(&zcas, (double) cas); | |
+ | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zcas); | |
+ | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_DELETE), params, 3); | |
+ | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(&zcookie); | |
+ zval_ptr_dtor(&zkey); | |
+ zval_ptr_dtor(&zcas); | |
return retval; | |
} | |
@@ -317,10 +300,8 @@ static | |
protocol_binary_response_status s_flush_handler(const void *cookie, uint32_t when) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zwhen; | |
- zval **params [2]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zwhen; | |
+ zval params[2]; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_FLUSH)) { | |
return retval; | |
@@ -328,16 +309,15 @@ protocol_binary_response_status s_flush_handler(const void *cookie, uint32_t whe | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zwhen); | |
- ZVAL_LONG(zwhen, (long) when); | |
- | |
- params [0] = &zcookie; | |
- params [1] = &zwhen; | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zwhen) | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_FLUSH), params, 2 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_FLUSH), params, 2); | |
- zval_ptr_dtor (&zcookie); | |
- zval_ptr_dtor (&zwhen); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(&zcookie); | |
+ zval_ptr_dtor(&zwhen); | |
return retval; | |
} | |
@@ -346,10 +326,8 @@ protocol_binary_response_status s_get_handler (const void *cookie, const void *k | |
memcached_binary_protocol_get_response_handler response_handler) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zvalue, *zflags, *zresult_cas; | |
- zval **params [5]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zvalue, zflags, zresult_cas; | |
+ zval params[5]; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_GET)) { | |
return retval; | |
@@ -357,52 +335,50 @@ protocol_binary_response_status s_get_handler (const void *cookie, const void *k | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zvalue); | |
- ZVAL_NULL(zvalue); | |
- | |
- MAKE_STD_ZVAL(zflags); | |
- ZVAL_NULL(zflags); | |
- | |
- MAKE_STD_ZVAL(zresult_cas); | |
- ZVAL_NULL(zresult_cas); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zvalue); | |
+ ZVAL_COPY(¶ms[3], &zflags); | |
+ ZVAL_COPY(¶ms[4], &zresult_cas); | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zvalue; | |
- params [3] = &zflags; | |
- params [4] = &zresult_cas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_GET), params, 5 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_GET), params, 5); | |
/* Succeeded in getting the key */ | |
if (retval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { | |
uint32_t flags = 0; | |
uint64_t result_cas = 0; | |
- if (Z_TYPE_P (zvalue) == IS_NULL) { | |
- zval_ptr_dtor (&zcookie); | |
- zval_ptr_dtor (&zkey); | |
- zval_ptr_dtor (&zvalue); | |
- zval_ptr_dtor (&zflags); | |
- zval_ptr_dtor (&zresult_cas); | |
+ if (Z_TYPE(zvalue) == IS_NULL) { | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
+ zval_ptr_dtor(&zcookie); | |
+ zval_ptr_dtor(&zkey); | |
+ zval_ptr_dtor(&zvalue); | |
+ zval_ptr_dtor(&zflags); | |
+ zval_ptr_dtor(&zresult_cas); | |
return PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; | |
} | |
- if (Z_TYPE_P (zvalue) != IS_STRING) { | |
- convert_to_string (zvalue); | |
+ if (Z_TYPE(zvalue) != IS_STRING) { | |
+ convert_to_string (&zvalue); | |
} | |
- if (Z_TYPE_P (zflags) == IS_LONG) { | |
- flags = Z_LVAL_P (zflags); | |
+ if (Z_TYPE(zflags) == IS_LONG) { | |
+ flags = Z_LVAL(zflags); | |
} | |
MEMC_MAKE_RESULT_CAS(zresult_cas, result_cas); | |
- retval = response_handler(cookie, key, key_len, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), flags, result_cas); | |
+ retval = response_handler(cookie, key, key_len, Z_STRVAL(zvalue), Z_STRLEN(zvalue), flags, result_cas); | |
} | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zvalue); | |
@@ -415,10 +391,8 @@ static | |
protocol_binary_response_status s_noop_handler(const void *cookie) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie; | |
- zval **params [1]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie; | |
+ zval params[1]; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_NOOP)) { | |
return retval; | |
@@ -426,10 +400,11 @@ protocol_binary_response_status s_noop_handler(const void *cookie) | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- params [0] = &zcookie; | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_NOOP), params, 1 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_NOOP), params, 1); | |
+ zval_ptr_dtor(¶ms[0]); | |
zval_ptr_dtor (&zcookie); | |
return retval; | |
} | |
@@ -437,11 +412,9 @@ protocol_binary_response_status s_noop_handler(const void *cookie) | |
static | |
protocol_binary_response_status s_quit_handler(const void *cookie) | |
{ | |
- zval **params [1]; | |
+ zval params[1]; | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_QUIT)) { | |
return retval; | |
@@ -449,9 +422,11 @@ protocol_binary_response_status s_quit_handler(const void *cookie) | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- params [0] = &zcookie; | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_QUIT), params, 1 TSRMLS_CC); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_QUIT), params, 1); | |
+ | |
+ zval_ptr_dtor(¶ms[0]); | |
zval_ptr_dtor (&zcookie); | |
return retval; | |
} | |
@@ -463,10 +438,8 @@ protocol_binary_response_status s_set_replace_handler (php_memc_event_t event, c | |
uint32_t data_len, uint32_t flags, uint32_t expiration, uint64_t cas, uint64_t *result_cas) | |
{ | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zdata, *zflags, *zexpiration, *zcas, *zresult_cas; | |
- zval **params [7]; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zdata, zflags, zexpiration, zcas, zresult_cas; | |
+ zval params[7]; | |
if (!MEMC_HAS_CB(event)) { | |
return retval; | |
@@ -474,36 +447,32 @@ protocol_binary_response_status s_set_replace_handler (php_memc_event_t event, c | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
- | |
- MAKE_STD_ZVAL(zdata); | |
- ZVAL_STRINGL(zdata, ((char *) data), (int) data_len, 1); | |
- | |
- MAKE_STD_ZVAL(zflags); | |
- ZVAL_LONG(zflags, (long) flags); | |
- | |
- MAKE_STD_ZVAL(zexpiration); | |
- ZVAL_LONG(zexpiration, (long) expiration); | |
- | |
- MAKE_STD_ZVAL(zcas); | |
- ZVAL_DOUBLE(zcas, (double) cas); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_STRINGL(&zdata, ((char *) data), (int) data_len); | |
+ ZVAL_LONG(&zflags, (long) flags); | |
+ ZVAL_LONG(&zexpiration, (long) expiration); | |
+ ZVAL_DOUBLE(&zcas, (double) cas); | |
+ ZVAL_NULL(&zresult_cas); | |
- MAKE_STD_ZVAL(zresult_cas); | |
- ZVAL_NULL(zresult_cas); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zdata); | |
+ ZVAL_COPY(¶ms[3], &zflags); | |
+ ZVAL_COPY(¶ms[4], &zexpiration); | |
+ ZVAL_COPY(¶ms[5], &zcas); | |
+ ZVAL_COPY(¶ms[6], &zresult_cas); | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zdata; | |
- params [3] = &zflags; | |
- params [4] = &zexpiration; | |
- params [5] = &zcas; | |
- params [6] = &zresult_cas; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 7 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(event), params, 7); | |
MEMC_MAKE_RESULT_CAS(zresult_cas, *result_cas); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
+ zval_ptr_dtor(¶ms[3]); | |
+ zval_ptr_dtor(¶ms[4]); | |
+ zval_ptr_dtor(¶ms[5]); | |
+ zval_ptr_dtor(¶ms[6]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zdata); | |
@@ -535,11 +504,9 @@ static | |
protocol_binary_response_status s_stat_handler (const void *cookie, const void *key, uint16_t key_len, | |
memcached_binary_protocol_stat_response_handler response_handler) | |
{ | |
- zval **params [3]; | |
+ zval params[3]; | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zkey, *zbody; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zkey, zbody; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_STAT)) { | |
return retval; | |
@@ -547,29 +514,30 @@ protocol_binary_response_status s_stat_handler (const void *cookie, const void * | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zkey); | |
- ZVAL_STRINGL(zkey, key, key_len, 1); | |
+ ZVAL_STRINGL(&zkey, key, key_len); | |
+ ZVAL_NULL(&zbody); | |
- MAKE_STD_ZVAL(zbody); | |
- ZVAL_NULL(zbody); | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zkey); | |
+ ZVAL_COPY(¶ms[2], &zbody); | |
- params [0] = &zcookie; | |
- params [1] = &zkey; | |
- params [2] = &zbody; | |
- | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_STAT), params, 3 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_STAT), params, 3); | |
if (retval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { | |
- if (Z_TYPE_P (zbody) == IS_NULL) { | |
+ if (Z_TYPE(zbody) == IS_NULL) { | |
retval = response_handler(cookie, NULL, 0, NULL, 0); | |
} | |
else { | |
- if (Z_TYPE_P (zbody) != IS_STRING) { | |
- convert_to_string (zbody); | |
+ if (Z_TYPE(zbody) != IS_STRING) { | |
+ convert_to_string(&zbody); | |
} | |
- retval = response_handler(cookie, key, key_len, Z_STRVAL_P (zbody), (uint32_t) Z_STRLEN_P (zbody)); | |
+ retval = response_handler(cookie, key, key_len, Z_STRVAL(zbody), (uint32_t) Z_STRLEN(zbody)); | |
} | |
} | |
+ | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(¶ms[2]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zkey); | |
zval_ptr_dtor (&zbody); | |
@@ -580,11 +548,9 @@ static | |
protocol_binary_response_status s_version_handler (const void *cookie, | |
memcached_binary_protocol_version_response_handler response_handler) | |
{ | |
- zval **params [2]; | |
+ zval params[2]; | |
protocol_binary_response_status retval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; | |
- zval *zcookie, *zversion; | |
- | |
- TSRMLS_FETCH(); | |
+ zval zcookie, zversion; | |
if (!MEMC_HAS_CB(MEMC_SERVER_ON_VERSION)) { | |
return retval; | |
@@ -592,21 +558,23 @@ protocol_binary_response_status s_version_handler (const void *cookie, | |
MEMC_MAKE_ZVAL_COOKIE(zcookie, cookie); | |
- MAKE_STD_ZVAL(zversion); | |
- ZVAL_NULL(zversion); | |
+ ZVAL_NULL(&zversion); | |
- params [0] = &zcookie; | |
- params [1] = &zversion; | |
+ ZVAL_COPY(¶ms[0], &zcookie); | |
+ ZVAL_COPY(¶ms[1], &zversion); | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_VERSION), params, 2 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_VERSION), params, 2); | |
if (retval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { | |
- if (Z_TYPE_P (zversion) != IS_STRING) { | |
- convert_to_string (zversion); | |
+ if (Z_TYPE(zversion) != IS_STRING) { | |
+ convert_to_string(&zversion); | |
} | |
retval = response_handler (cookie, Z_STRVAL_P(zversion), (uint32_t) Z_STRLEN_P(zversion)); | |
} | |
+ | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
zval_ptr_dtor (&zcookie); | |
zval_ptr_dtor (&zversion); | |
return retval; | |
@@ -623,36 +591,33 @@ void s_handle_memcached_event (evutil_socket_t fd, short what, void *arg) | |
php_memc_client_t *client = (php_memc_client_t *) arg; | |
memcached_protocol_event_t events; | |
- TSRMLS_FETCH(); | |
- | |
if (!client->on_connect_invoked) { | |
if (MEMC_HAS_CB(MEMC_SERVER_ON_CONNECT)) { | |
- zval *zremoteip, *zremoteport; | |
- zval **params [2]; | |
+ zval zremoteip, zremoteport; | |
+ zval params[2]; | |
protocol_binary_response_status retval; | |
struct sockaddr_in addr_in; | |
socklen_t addr_in_len = sizeof(addr_in); | |
- MAKE_STD_ZVAL(zremoteip); | |
- MAKE_STD_ZVAL(zremoteport); | |
- | |
if (getpeername (fd, (struct sockaddr *) &addr_in, &addr_in_len) == 0) { | |
- ZVAL_STRING(zremoteip, inet_ntoa (addr_in.sin_addr), 1); | |
- ZVAL_LONG(zremoteport, ntohs (addr_in.sin_port)); | |
+ ZVAL_STRING(&zremoteip, inet_ntoa (addr_in.sin_addr), 1); | |
+ ZVAL_LONG(&zremoteport, ntohs (addr_in.sin_port)); | |
} else { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "getpeername failed: %s", strerror (errno)); | |
- ZVAL_NULL(zremoteip); | |
- ZVAL_NULL(zremoteport); | |
+ php_error_docref(NULL, E_WARNING, "getpeername failed: %s", strerror (errno)); | |
+ ZVAL_NULL(&zremoteip); | |
+ ZVAL_NULL(&zremoteport); | |
} | |
- params [0] = &zremoteip; | |
- params [1] = &zremoteport; | |
+ ZVAL_COPY(¶ms[0], &zremoteip); | |
+ ZVAL_COPY(¶ms[1], &zremoteport); | |
- retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_CONNECT), params, 2 TSRMLS_CC); | |
+ retval = s_invoke_php_callback (&MEMC_GET_CB(MEMC_SERVER_ON_CONNECT), params, 2); | |
- zval_ptr_dtor (&zremoteip); | |
- zval_ptr_dtor (&zremoteport); | |
+ zval_ptr_dtor(¶ms[0]); | |
+ zval_ptr_dtor(¶ms[1]); | |
+ zval_ptr_dtor(&zremoteip); | |
+ zval_ptr_dtor(&zremoteport); | |
if (retval != PROTOCOL_BINARY_RESPONSE_SUCCESS) { | |
memcached_protocol_client_destroy (client->protocol_client); | |
@@ -683,7 +648,7 @@ void s_handle_memcached_event (evutil_socket_t fd, short what, void *arg) | |
rc = event_base_once (client->event_base, fd, flags, s_handle_memcached_event, client, NULL); | |
if (rc != 0) { | |
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "Failed to schedule events"); | |
+ php_error_docref (NULL, E_WARNING, "Failed to schedule events"); | |
} | |
} | |
@@ -698,14 +663,12 @@ void s_accept_cb (evutil_socket_t fd, short what, void *arg) | |
php_memc_proto_handler_t *handler = (php_memc_proto_handler_t *) arg; | |
- TSRMLS_FETCH(); | |
- | |
/* Accept the connection */ | |
addr_len = sizeof (addr); | |
sock = accept (fd, (struct sockaddr *) &addr, &addr_len); | |
if (sock == -1) { | |
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "Failed to accept the client: %s", strerror (errno)); | |
+ php_error_docref (NULL, E_WARNING, "Failed to accept the client: %s", strerror (errno)); | |
return; | |
} | |
@@ -715,7 +678,7 @@ void s_accept_cb (evutil_socket_t fd, short what, void *arg) | |
client->on_connect_invoked = 0; | |
if (!client->protocol_client) { | |
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "Failed to allocate protocol client"); | |
+ php_error_docref (NULL, E_WARNING, "Failed to allocate protocol client"); | |
efree (client); | |
evutil_closesocket (sock); | |
return; | |
@@ -725,7 +688,7 @@ void s_accept_cb (evutil_socket_t fd, short what, void *arg) | |
rc = event_base_once (handler->event_base, sock, EV_READ, s_handle_memcached_event, client, NULL); | |
if (rc != 0) { | |
- php_error_docref (NULL TSRMLS_CC, E_WARNING, "Failed to add event for client"); | |
+ php_error_docref (NULL, E_WARNING, "Failed to add event for client"); | |
memcached_protocol_client_destroy (client->protocol_client); | |
efree (client); | |
evutil_closesocket (sock); | |
@@ -771,59 +734,55 @@ evutil_socket_t s_create_listening_socket (const char *spec) | |
int rc; | |
- TSRMLS_FETCH(); | |
- | |
addr_len = sizeof (struct sockaddr); | |
rc = evutil_parse_sockaddr_port (spec, (struct sockaddr *) &addr, &addr_len); | |
if (rc != 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse bind address"); | |
+ php_error_docref(NULL, E_WARNING, "Failed to parse bind address"); | |
return -1; | |
} | |
sock = socket (AF_INET, SOCK_STREAM, 0); | |
if (sock < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "socket failed: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "socket failed: %s", strerror (errno)); | |
return -1; | |
} | |
rc = bind (sock, (struct sockaddr *) &addr, addr_len); | |
if (rc < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "bind failed: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "bind failed: %s", strerror (errno)); | |
return -1; | |
} | |
rc = listen (sock, 1024); | |
if (rc < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "listen failed: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "listen failed: %s", strerror (errno)); | |
return -1; | |
} | |
rc = evutil_make_socket_nonblocking (sock); | |
if (rc != 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to make socket non-blocking: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "failed to make socket non-blocking: %s", strerror (errno)); | |
return -1; | |
} | |
rc = evutil_make_listen_socket_reuseable (sock); | |
if (rc != 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to make socket reuseable: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "failed to make socket reuseable: %s", strerror (errno)); | |
return -1; | |
} | |
rc = evutil_make_socket_closeonexec (sock); | |
if (rc != 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to make socket closeonexec: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_WARNING, "failed to make socket closeonexec: %s", strerror (errno)); | |
return -1; | |
} | |
return sock; | |
} | |
-zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *handler, const char *address) | |
+zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *handler, zend_string *address) | |
{ | |
struct event *accept_event; | |
- evutil_socket_t sock = s_create_listening_socket (address); | |
- | |
- TSRMLS_FETCH(); | |
+ evutil_socket_t sock = s_create_listening_socket (address->val); | |
if (sock == -1) { | |
return 0; | |
@@ -831,22 +790,22 @@ zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *handler, const c | |
handler->event_base = event_base_new(); | |
if (!handler->event_base) { | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "failed to allocate memory: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_ERROR, "failed to allocate memory: %s", strerror (errno)); | |
} | |
accept_event = event_new (handler->event_base, sock, EV_READ | EV_PERSIST, s_accept_cb, handler); | |
if (!accept_event) { | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "failed to allocate memory: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_ERROR, "failed to allocate memory: %s", strerror (errno)); | |
} | |
event_add (accept_event, NULL); | |
switch (event_base_dispatch (handler->event_base)) { | |
case -1: | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "event_base_dispatch() failed: %s", strerror (errno)); | |
+ php_error_docref(NULL, E_ERROR, "event_base_dispatch() failed: %s", strerror (errno)); | |
return 0; | |
break; | |
case 1: | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "no events registered"); | |
+ php_error_docref(NULL, E_ERROR, "no events registered"); | |
return 0; | |
break; | |
@@ -865,4 +824,11 @@ void php_memc_proto_handler_destroy (php_memc_proto_handler_t **ptr) | |
efree (handler); | |
*ptr = NULL; | |
-} | |
\ No newline at end of file | |
+} | |
+/* | |
+ * Local variables: | |
+ * tab-width: 4 | |
+ * c-basic-offset: 4 | |
+ * End: | |
+ * vim: noet sw=4 ts=4 fdm=marker: | |
+ */ | |
diff --git a/php_memcached_server.h b/php_memcached_server.h | |
index 31676c5..285c608 100644 | |
--- a/php_memcached_server.h | |
+++ b/php_memcached_server.h | |
@@ -33,8 +33,8 @@ php_memc_proto_handler_t *php_memc_proto_handler_new (); | |
void php_memc_proto_handler_destroy (php_memc_proto_handler_t **ptr); | |
-zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *h, const char *address); | |
+zend_bool php_memc_proto_handler_run (php_memc_proto_handler_t *h, zend_string *address); | |
#endif | |
-#endif | |
\ No newline at end of file | |
+#endif | |
diff --git a/php_memcached_session.c b/php_memcached_session.c | |
index a3ef567..1d2dbe3 100644 | |
--- a/php_memcached_session.c | |
+++ b/php_memcached_session.c | |
@@ -27,7 +27,7 @@ ps_module ps_mod_memcached = { | |
PS_MOD(memcached) | |
}; | |
-static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC) | |
+static int php_memc_sess_lock(memcached_st *memc, const char *key) | |
{ | |
char *lock_key = NULL; | |
int lock_key_len = 0; | |
@@ -72,7 +72,7 @@ static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC) | |
write_retry_attempts--; | |
continue; | |
} | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Write of lock failed"); | |
+ php_error_docref(NULL, E_WARNING, "Write of lock failed"); | |
break; | |
} | |
@@ -85,7 +85,7 @@ static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC) | |
return -1; | |
} | |
-static void php_memc_sess_unlock(memcached_st *memc TSRMLS_DC) | |
+static void php_memc_sess_unlock(memcached_st *memc) | |
{ | |
if (MEMC_G(sess_locked)) { | |
memcached_delete(memc, MEMC_G(sess_lock_key), MEMC_G(sess_lock_key_len), 0); | |
@@ -103,13 +103,14 @@ PS_OPEN_FUNC(memcached) | |
int plist_key_len = 0; | |
if (!strncmp((char *)save_path, "PERSISTENT=", sizeof("PERSISTENT=") - 1)) { | |
- zend_rsrc_list_entry *le = NULL; | |
+ zend_resource *le = NULL; | |
+ zval *le_z = NULL; | |
char *e; | |
p = (char *)save_path + sizeof("PERSISTENT=") - 1; | |
if (!*p) { | |
error: | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid persistent id for session storage"); | |
+ php_error_docref(NULL, E_WARNING, "Invalid persistent id for session storage"); | |
return FAILURE; | |
} | |
if ((e = strchr(p, ' '))) { | |
@@ -118,7 +119,9 @@ error: | |
goto error; | |
} | |
plist_key_len++; | |
- if (zend_hash_find(&EG(persistent_list), plist_key, plist_key_len, (void *)&le) == SUCCESS) { | |
+ | |
+ if ((le_z = zend_hash_str_find(&EG(persistent_list), plist_key, plist_key_len)) != NULL) { | |
+ le = Z_RES_P(le_z); | |
if (le->type == php_memc_sess_list_entry()) { | |
memc_sess = (memcached_sess *) le->ptr; | |
PS_SET_MOD_DATA(memc_sess); | |
@@ -146,7 +149,7 @@ error: | |
efree(plist_key); | |
} | |
memcached_free(memc_sess->memc_sess); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to enable memcached consistent hashing"); | |
+ php_error_docref(NULL, E_WARNING, "failed to enable memcached consistent hashing"); | |
return FAILURE; | |
} | |
} | |
@@ -160,7 +163,7 @@ error: | |
efree(plist_key); | |
} | |
memcached_free(memc_sess->memc_sess); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad memcached key prefix in memcached.sess_prefix"); | |
+ php_error_docref(NULL, E_WARNING, "bad memcached key prefix in memcached.sess_prefix"); | |
return FAILURE; | |
} | |
@@ -169,10 +172,10 @@ error: | |
} | |
} else { | |
memcached_server_list_free(servers); | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not allocate libmemcached structure"); | |
+ php_error_docref(NULL, E_WARNING, "could not allocate libmemcached structure"); | |
} | |
} else { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to parse session.save_path"); | |
+ php_error_docref(NULL, E_WARNING, "failed to parse session.save_path"); | |
} | |
} else { | |
memc_sess->memc_sess = php_memc_create_str(p, strlen(p)); | |
@@ -180,12 +183,12 @@ error: | |
#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); | |
+ php_error_docref(NULL, E_WARNING, "session.save_path configuration error %s", error_buffer); | |
} else { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to initialize memcached session storage"); | |
+ php_error_docref(NULL, E_WARNING, "failed to initialize memcached session storage"); | |
} | |
#else | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to initialize memcached session storage"); | |
+ php_error_docref(NULL, E_WARNING, "failed to initialize memcached session storage"); | |
#endif | |
} else { | |
@@ -193,21 +196,25 @@ success: | |
PS_SET_MOD_DATA(memc_sess); | |
if (plist_key) { | |
- zend_rsrc_list_entry le; | |
+ zend_resource le; | |
+ zend_string *tmp_key; | |
le.type = php_memc_sess_list_entry(); | |
le.ptr = memc_sess; | |
- if (zend_hash_update(&EG(persistent_list), (char *)plist_key, plist_key_len, (void *)&le, sizeof(le), NULL) == FAILURE) { | |
+ tmp_key = zend_string_init(plist_key, plist_key_len, 0); | |
+ if (zend_hash_update_mem(&EG(persistent_list), tmp_key, (void *)&le, sizeof(le)) == NULL) { | |
+ zend_string_release(tmp_key); | |
efree(plist_key); | |
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "could not register persistent entry"); | |
+ php_error_docref(NULL, E_ERROR, "could not register persistent entry"); | |
} | |
+ zend_string_release(tmp_key); | |
efree(plist_key); | |
} | |
if (MEMC_G(sess_binary_enabled)) { | |
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, (uint64_t) 1) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session binary protocol"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached session binary protocol"); | |
return FAILURE; | |
} | |
} | |
@@ -220,11 +227,11 @@ success: | |
if (MEMC_G(sess_sasl_username) && MEMC_G(sess_sasl_password)) { | |
/* Force binary protocol */ | |
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, (uint64_t) 1) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session binary protocol"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached session binary protocol"); | |
return FAILURE; | |
} | |
if (memcached_set_sasl_auth_data(memc_sess->memc_sess, MEMC_G(sess_sasl_username), MEMC_G(sess_sasl_password)) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session sasl credentials"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached session sasl credentials"); | |
return FAILURE; | |
} | |
MEMC_G(sess_sasl_data) = 1; | |
@@ -235,23 +242,23 @@ success: | |
#endif | |
if (MEMC_G(sess_number_of_replicas) > 0) { | |
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, (uint64_t) MEMC_G(sess_number_of_replicas)) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session number of replicas"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached session number of replicas"); | |
return FAILURE; | |
} | |
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, (uint64_t) MEMC_G(sess_randomize_replica_read)) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached session randomize replica read"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached session randomize replica read"); | |
} | |
} | |
if (memcached_behavior_set(memc_sess->memc_sess, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, (uint64_t) MEMC_G(sess_connect_timeout)) == MEMCACHED_FAILURE) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set memcached connection timeout"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set memcached connection timeout"); | |
return FAILURE; | |
} | |
#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) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to set: remove failed servers"); | |
+ php_error_docref(NULL, E_WARNING, "failed to set: remove failed servers"); | |
return FAILURE; | |
} | |
} | |
@@ -272,7 +279,7 @@ PS_CLOSE_FUNC(memcached) | |
memcached_sess *memc_sess = PS_GET_MOD_DATA(); | |
if (MEMC_G(sess_locking_enabled)) { | |
- php_memc_sess_unlock(memc_sess->memc_sess TSRMLS_CC); | |
+ php_memc_sess_unlock(memc_sess->memc_sess); | |
} | |
if (memc_sess->memc_sess) { | |
if (!memc_sess->is_persistent) { | |
@@ -294,7 +301,7 @@ PS_READ_FUNC(memcached) | |
{ | |
char *payload = NULL; | |
size_t payload_len = 0; | |
- int key_len = strlen(key); | |
+ int key_len = key->len; | |
uint32_t flags = 0; | |
memcached_return status; | |
memcached_sess *memc_sess = PS_GET_MOD_DATA(); | |
@@ -302,23 +309,21 @@ PS_READ_FUNC(memcached) | |
key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock." | |
if (!key_length || key_length >= MEMCACHED_MAX_KEY) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The session id is too long or contains illegal characters"); | |
- PS(invalid_session_id) = 1; | |
+ php_error_docref(NULL, E_WARNING, "The session id is too long or contains illegal characters"); | |
return FAILURE; | |
} | |
if (MEMC_G(sess_locking_enabled)) { | |
- if (php_memc_sess_lock(memc_sess->memc_sess, key TSRMLS_CC) < 0) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to clear session lock record"); | |
+ if (php_memc_sess_lock(memc_sess->memc_sess, key->val) < 0) { | |
+ php_error_docref(NULL, E_WARNING, "Unable to clear session lock record"); | |
return FAILURE; | |
} | |
} | |
- payload = memcached_get(memc_sess->memc_sess, key, key_len, &payload_len, &flags, &status); | |
+ payload = memcached_get(memc_sess->memc_sess, key->val, key_len, &payload_len, &flags, &status); | |
if (status == MEMCACHED_SUCCESS) { | |
- *val = estrndup(payload, payload_len); | |
- *vallen = payload_len; | |
+ *val = zend_string_init(payload, payload_len, 1); | |
free(payload); | |
return SUCCESS; | |
} else { | |
@@ -328,7 +333,7 @@ PS_READ_FUNC(memcached) | |
PS_WRITE_FUNC(memcached) | |
{ | |
- int key_len = strlen(key); | |
+ int key_len = key->len; | |
time_t expiration = 0; | |
long write_try_attempts = 1; | |
memcached_return status; | |
@@ -337,8 +342,7 @@ PS_WRITE_FUNC(memcached) | |
key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock." | |
if (!key_length || key_length >= MEMCACHED_MAX_KEY) { | |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The session id is too long or contains illegal characters"); | |
- PS(invalid_session_id) = 1; | |
+ php_error_docref(NULL, E_WARNING, "The session id is too long or contains illegal characters"); | |
return FAILURE; | |
} | |
@@ -352,7 +356,7 @@ PS_WRITE_FUNC(memcached) | |
} | |
do { | |
- status = memcached_set(memc_sess->memc_sess, key, key_len, val, vallen, expiration, 0); | |
+ status = memcached_set(memc_sess->memc_sess, key->val, key_len, val->val, val->len, expiration, 0); | |
if (status == MEMCACHED_SUCCESS) { | |
return SUCCESS; | |
} else { | |
@@ -367,9 +371,9 @@ PS_DESTROY_FUNC(memcached) | |
{ | |
memcached_sess *memc_sess = PS_GET_MOD_DATA(); | |
- memcached_delete(memc_sess->memc_sess, key, strlen(key), 0); | |
+ memcached_delete(memc_sess->memc_sess, key->val, key->len, 0); | |
if (MEMC_G(sess_locking_enabled)) { | |
- php_memc_sess_unlock(memc_sess->memc_sess TSRMLS_CC); | |
+ php_memc_sess_unlock(memc_sess->memc_sess); | |
} | |
return SUCCESS; | |
diff --git a/tests/version.phpt b/tests/version.phpt | |
index f9adcc5..8ffe275 100644 | |
--- a/tests/version.phpt | |
+++ b/tests/version.phpt | |
@@ -13,6 +13,6 @@ echo "OK" . PHP_EOL; | |
--EXPECTF-- | |
array(1) { | |
["%s:%d"]=> | |
- string(6) "%d.%d.%d" | |
+ string(%d) "%d.%d.%d" | |
} | |
-OK | |
\ No newline at end of file | |
+OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment