Skip to content

Commit

Permalink
Fixing events manager
Browse files Browse the repository at this point in the history
  • Loading branch information
phalcon committed May 5, 2014
1 parent 2644a22 commit 9492155
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 270 deletions.
2 changes: 1 addition & 1 deletion ext/install
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
export CC="gcc"
export CFLAGS="-O0 -g3 -Wall -fvisibility=hidden"
export CFLAGS="-O2 -Wall -fvisibility=hidden -flt"
if [ -f Makefile ]; then
sudo make --silent clean
sudo phpize --silent --clean
Expand Down
12 changes: 10 additions & 2 deletions ext/kernel/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,11 +1123,19 @@ void zephir_array_merge_recursive_n(zval **a1, zval *a2 TSRMLS_DC)
* @param arg
* @note Reference count of @c arg will be incremented
*/
void zephir_array_unshift(zval *arr, zval *arg)
void zephir_array_unshift(zval *arr, zval *arg TSRMLS_DC)
{
if (likely(Z_TYPE_P(arr) == IS_ARRAY)) {
zval** args[1] = { &arg };
HashTable *newhash = php_splice(Z_ARRVAL_P(arr), 0, 0, args, 1, NULL);

HashTable *newhash = Z_ARRVAL_P(arr);

#if PHP_VERSION_ID < 50600
newhash = php_splice(newhash, 0, 0, args, 1, NULL);
#else
php_splice(newhash, 0, 0, args, 1, NULL TSRMLS_CC);
#endif

HashTable oldhash = *Z_ARRVAL_P(arr);
*Z_ARRVAL_P(arr) = *newhash;

Expand Down
2 changes: 1 addition & 1 deletion ext/kernel/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void zephir_fast_array_merge(zval *return_value, zval **array1, zval **array2 TS
/** Recursive merge */
void zephir_array_merge_recursive_n(zval **a1, zval *a2 TSRMLS_DC);

void zephir_array_unshift(zval *arr, zval *arg);
void zephir_array_unshift(zval *arr, zval *arg TSRMLS_DC);
void zephir_array_keys(zval *return_value, zval *arr TSRMLS_DC);
void zephir_array_values(zval *return_value, zval *arr);
int zephir_array_key_exists(zval *arr, zval *key TSRMLS_DC);
Expand Down
16 changes: 14 additions & 2 deletions ext/kernel/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_

int i, l, ll; char *s;
va_list ap;
zval *fetched, *tmp_arr, *tmp, *p, *item;
zval *fetched, *tmp_arr, *tmp, *p, *item, *old_p;
int separated = 0;

if (Z_TYPE_P(object) == IS_OBJECT) {
Expand Down Expand Up @@ -1042,6 +1042,7 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_
va_start(ap, types_count);

p = tmp_arr;
old_p = NULL;
for (i = 0; i < types_length; ++i) {
switch (types[i]) {

Expand All @@ -1053,6 +1054,7 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_
if (i == (types_length - 1)) {
zephir_array_update_string(&fetched, s, l, value, PH_COPY | PH_SEPARATE);
} else {
old_p = p;
p = fetched;
}
continue;
Expand All @@ -1075,6 +1077,7 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_
if (i == (types_length - 1)) {
zephir_array_update_long(&fetched, ll, value, PH_COPY | PH_SEPARATE, "", 0);
} else {
old_p = p;
p = fetched;
}
continue;
Expand All @@ -1097,6 +1100,7 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_
if (i == (types_length - 1)) {
zephir_array_update_zval(&fetched, item, value, PH_COPY | PH_SEPARATE);
} else {
old_p = p;
p = fetched;
}
continue;
Expand All @@ -1113,7 +1117,15 @@ int zephir_update_property_array_multi(zval *object, const char *property, zend_
break;

case 'a':
zephir_array_append(&p, *value, PH_SEPARATE);
if (Z_REFCOUNT_P(p) > 1) {
SEPARATE_ZVAL_IF_NOT_REF(&p);
switch (types[i - 1]) {
case 'z':
zephir_array_update_zval(&old_p, item, &p, PH_COPY);
break;
}
}
zephir_array_append(&p, *value, 0);
break;
}
}
Expand Down
13 changes: 6 additions & 7 deletions ext/phalcon/cache/backend/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <Zend/zend_interfaces.h>

#include "kernel/main.h"
#include "kernel/memory.h"
#include "kernel/object.h"
#include "kernel/concat.h"
#include "kernel/object.h"
#include "kernel/memory.h"
#include "kernel/fcall.h"
#include "kernel/operators.h"
#include "kernel/exception.h"
Expand Down Expand Up @@ -81,7 +81,7 @@ ZEPHIR_INIT_CLASS(Phalcon_Cache_Backend_Apc) {
PHP_METHOD(Phalcon_Cache_Backend_Apc, get) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName, *lifetime = NULL, *frontend, *prefixedKey, *cachedContent = NULL, *_0;
zval *keyName, *lifetime = NULL, *prefixedKey, *cachedContent = NULL, *_0, *_1;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 1, 1, &keyName, &lifetime);
Expand All @@ -91,8 +91,6 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, get) {
}


ZEPHIR_OBS_VAR(frontend);
zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_VAR(prefixedKey);
ZEPHIR_CONCAT_SVV(prefixedKey, "_PHCA", _0, keyName);
Expand All @@ -102,7 +100,8 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, get) {
if (ZEPHIR_IS_FALSE(cachedContent)) {
RETURN_MM_NULL();
}
ZEPHIR_RETURN_CALL_METHOD(frontend, "afterretrieve", NULL, cachedContent);
_1 = zephir_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC);
ZEPHIR_RETURN_CALL_METHOD(_1, "afterretrieve", NULL, cachedContent);
zephir_check_call_status();
RETURN_MM();

Expand Down Expand Up @@ -149,7 +148,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, save) {
ZEPHIR_CONCAT_SVV(lastKey, "_PHCA", _0, keyName);
}
if (!(zephir_is_true(lastKey))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/apc.zep", 91);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/apc.zep", 89);
return;
}
ZEPHIR_OBS_VAR(frontend);
Expand Down
80 changes: 34 additions & 46 deletions ext/phalcon/cache/backend/libmemcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, _connect) {
PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, get) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName, *lifetime = NULL, *memcache = NULL, *frontend, *prefix, *prefixedKey, *cachedContent = NULL;
zval *keyName, *lifetime = NULL, *memcache = NULL, *prefixedKey, *cachedContent = NULL, *_0, *_1;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 1, 1, &keyName, &lifetime);
Expand All @@ -231,12 +231,9 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, get) {
ZEPHIR_OBS_NVAR(memcache);
zephir_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC);
}
ZEPHIR_OBS_VAR(frontend);
zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
ZEPHIR_OBS_VAR(prefix);
zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_VAR(prefixedKey);
ZEPHIR_CONCAT_VV(prefixedKey, prefix, keyName);
ZEPHIR_CONCAT_VV(prefixedKey, _0, keyName);
zephir_update_property_this(this_ptr, SL("_lastKey"), prefixedKey TSRMLS_CC);
ZEPHIR_CALL_METHOD(&cachedContent, memcache, "get", NULL, prefixedKey);
zephir_check_call_status();
Expand All @@ -246,7 +243,8 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, get) {
if (zephir_is_numeric(cachedContent)) {
RETURN_CCTOR(cachedContent);
} else {
ZEPHIR_CALL_METHOD(NULL, frontend, "afterretrieve", NULL, cachedContent);
_1 = zephir_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC);
ZEPHIR_CALL_METHOD(NULL, _1, "afterretrieve", NULL, cachedContent);
zephir_check_call_status();
}
ZEPHIR_MM_RESTORE();
Expand All @@ -264,7 +262,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, get) {
PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, save) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName = NULL, *content = NULL, *lifetime = NULL, *stopBuffer = NULL, *lastKey = NULL, *prefix, *frontend, *memcache = NULL, *cachedContent = NULL, *preparedContent = NULL, *tmp, *tt1 = NULL, *success = NULL, *options, *specialKey, *keys = NULL, *isBuffering = NULL;
zval *keyName = NULL, *content = NULL, *lifetime = NULL, *stopBuffer = NULL, *lastKey = NULL, *frontend, *memcache = NULL, *cachedContent = NULL, *preparedContent = NULL, *tmp, *tt1 = NULL, *success = NULL, *options, *specialKey, *keys = NULL, *isBuffering = NULL, *_0;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 0, 4, &keyName, &content, &lifetime, &stopBuffer);
Expand All @@ -287,13 +285,12 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, save) {
ZEPHIR_OBS_VAR(lastKey);
zephir_read_property_this(&lastKey, this_ptr, SL("_lastKey"), PH_NOISY_CC);
} else {
ZEPHIR_OBS_VAR(prefix);
zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_NVAR(lastKey);
ZEPHIR_CONCAT_VV(lastKey, prefix, keyName);
ZEPHIR_CONCAT_VV(lastKey, _0, keyName);
}
if (!(zephir_is_true(lastKey))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/libmemcached.zep", 183);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/libmemcached.zep", 180);
return;
}
ZEPHIR_OBS_VAR(frontend);
Expand Down Expand Up @@ -336,17 +333,16 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, save) {
zephir_check_call_status();
}
if (!(zephir_is_true(success))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Failed storing data in memcached", "phalcon/cache/backend/libmemcached.zep", 229);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Failed storing data in memcached", "phalcon/cache/backend/libmemcached.zep", 226);
return;
}
ZEPHIR_OBS_VAR(options);
zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string(options, SS("statsKey")))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 235);
ZEPHIR_OBS_VAR(specialKey);
if (!(zephir_array_isset_string_fetch(&specialKey, options, SS("statsKey"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 232);
return;
}
ZEPHIR_OBS_VAR(specialKey);
zephir_array_fetch_string(&specialKey, options, SL("statsKey"), PH_NOISY TSRMLS_CC);
ZEPHIR_CALL_METHOD(&keys, memcache, "get", NULL, specialKey);
zephir_check_call_status();
if (Z_TYPE_P(keys) != IS_ARRAY) {
Expand Down Expand Up @@ -425,14 +421,14 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, increment) {
/**
* Decrement of a given key, by number $value
*
* @param string $keyName
* @param long $value
* @param string keyName
* @param long value
* @return mixed
*/
PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, decrement) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName = NULL, *value = NULL, *memcache = NULL, *prefix, *prefixedKey, *cachedContent = NULL;
zval *keyName = NULL, *value = NULL, *memcache = NULL, *prefixedKey, *cachedContent = NULL, *_0;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 0, 2, &keyName, &value);
Expand All @@ -459,10 +455,9 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, decrement) {
ZEPHIR_OBS_NVAR(memcache);
zephir_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC);
}
ZEPHIR_OBS_VAR(prefix);
zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_VAR(prefixedKey);
ZEPHIR_CONCAT_VV(prefixedKey, prefix, keyName);
ZEPHIR_CONCAT_VV(prefixedKey, _0, keyName);
zephir_update_property_this(this_ptr, SL("_lastKey"), prefixedKey TSRMLS_CC);
ZEPHIR_CALL_METHOD(&cachedContent, memcache, "decrement", NULL, prefixedKey, value);
zephir_check_call_status();
Expand All @@ -482,7 +477,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, decrement) {
PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, delete) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName, *memcache = NULL, *prefix, *prefixedKey, *options, *keys = NULL, *specialKey;
zval *keyName, *memcache = NULL, *prefixedKey, *options, *keys = NULL, *specialKey, *_0;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 1, 0, &keyName);
Expand All @@ -497,18 +492,16 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, delete) {
ZEPHIR_OBS_NVAR(memcache);
zephir_read_property_this(&memcache, this_ptr, SL("_memcache"), PH_NOISY_CC);
}
ZEPHIR_OBS_VAR(prefix);
zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_VAR(prefixedKey);
ZEPHIR_CONCAT_VV(prefixedKey, prefix, keyName);
ZEPHIR_CONCAT_VV(prefixedKey, _0, keyName);
ZEPHIR_OBS_VAR(options);
zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string(options, SS("statsKey")))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 351);
ZEPHIR_OBS_VAR(specialKey);
if (!(zephir_array_isset_string_fetch(&specialKey, options, SS("statsKey"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 345);
return;
}
ZEPHIR_OBS_VAR(specialKey);
zephir_array_fetch_string(&specialKey, options, SL("statsKey"), PH_NOISY TSRMLS_CC);
ZEPHIR_CALL_METHOD(&keys, memcache, "get", NULL, specialKey);
zephir_check_call_status();
if (Z_TYPE_P(keys) == IS_ARRAY) {
Expand Down Expand Up @@ -554,12 +547,11 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, queryKeys) {
}
ZEPHIR_OBS_VAR(options);
zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string(options, SS("statsKey")))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 388);
ZEPHIR_OBS_VAR(specialKey);
if (!(zephir_array_isset_string_fetch(&specialKey, options, SS("statsKey"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 380);
return;
}
ZEPHIR_OBS_VAR(specialKey);
zephir_array_fetch_string(&specialKey, options, SL("statsKey"), PH_NOISY TSRMLS_CC);
ZEPHIR_CALL_METHOD(&keys, memcache, "get", NULL, specialKey);
zephir_check_call_status();
if (Z_TYPE_P(keys) == IS_ARRAY) {
Expand Down Expand Up @@ -592,7 +584,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, queryKeys) {
PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, exists) {

int ZEPHIR_LAST_CALL_STATUS;
zval *keyName = NULL, *lifetime = NULL, *lastKey = NULL, *memcache = NULL, *value = NULL, *prefix;
zval *keyName = NULL, *lifetime = NULL, *lastKey = NULL, *memcache = NULL, *value = NULL, *_0;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 0, 2, &keyName, &lifetime);
Expand All @@ -609,10 +601,9 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, exists) {
ZEPHIR_OBS_VAR(lastKey);
zephir_read_property_this(&lastKey, this_ptr, SL("_lastKey"), PH_NOISY_CC);
} else {
ZEPHIR_OBS_VAR(prefix);
zephir_read_property_this(&prefix, this_ptr, SL("_prefix"), PH_NOISY_CC);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
ZEPHIR_INIT_NVAR(lastKey);
ZEPHIR_CONCAT_VV(lastKey, prefix, keyName);
ZEPHIR_CONCAT_VV(lastKey, _0, keyName);
}
if (zephir_is_true(lastKey)) {
ZEPHIR_OBS_VAR(memcache);
Expand All @@ -629,10 +620,8 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, exists) {
RETURN_MM_BOOL(0);
}
RETURN_MM_BOOL(1);
} else {
RETURN_MM_BOOL(0);
}
ZEPHIR_MM_RESTORE();
RETURN_MM_BOOL(0);

}

Expand Down Expand Up @@ -660,12 +649,11 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, flush) {
}
ZEPHIR_OBS_VAR(options);
zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string(options, SS("statsKey")))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 459);
ZEPHIR_OBS_VAR(specialKey);
if (!(zephir_array_isset_string_fetch(&specialKey, options, SS("statsKey"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/libmemcached.zep", 448);
return;
}
ZEPHIR_OBS_VAR(specialKey);
zephir_array_fetch_string(&specialKey, options, SL("statsKey"), PH_NOISY TSRMLS_CC);
ZEPHIR_CALL_METHOD(&keys, memcache, "get", NULL, specialKey);
zephir_check_call_status();
if (Z_TYPE_P(keys) == IS_ARRAY) {
Expand Down
Loading

0 comments on commit 9492155

Please sign in to comment.