From 40c210ff2e2bbef2b1b9fa570f87d0fe1473d080 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Mon, 5 Aug 2013 02:18:04 +0300 Subject: [PATCH] Added more diagnostics for developer's mode --- ext/annotations/adapter/files.c | 2 +- ext/assets/filters/cssmin.c | 6 +- ext/assets/filters/cssminifier.c | 3 + ext/assets/filters/jsmin.c | 6 +- ext/assets/filters/jsminifier.c | 3 + ext/cli/console.c | 2 +- ext/events/manager.c | 2 +- ext/http/response.c | 2 +- ext/kernel/exception.h | 4 +- ext/kernel/fcall.h | 44 +++++++------- ext/kernel/main.h | 2 +- ext/kernel/memory.c | 87 +++++++++++++++++++++------- ext/kernel/memory.h | 20 +++++-- ext/kernel/object.c | 9 +-- ext/kernel/object.h | 8 +++ ext/kernel/require.c | 4 -- ext/loader.c | 8 +-- ext/logger/adapter.c | 14 ++--- ext/logger/multiple.c | 14 ++--- ext/mvc/application.c | 2 +- ext/mvc/collection.c | 2 +- ext/mvc/model.c | 4 +- ext/mvc/model/behavior/softdelete.c | 3 +- ext/mvc/model/metadata/files.c | 2 +- ext/mvc/model/query.c | 2 +- ext/mvc/view.c | 2 +- ext/mvc/view/engine/php.c | 2 +- ext/mvc/view/engine/volt.c | 2 +- ext/mvc/view/engine/volt/compiler.c | 4 +- ext/paginator/adapter/querybuilder.c | 4 +- ext/php_phalcon.h | 3 + 31 files changed, 164 insertions(+), 108 deletions(-) diff --git a/ext/annotations/adapter/files.c b/ext/annotations/adapter/files.c index 69069b81da0..b2054be587f 100644 --- a/ext/annotations/adapter/files.c +++ b/ext/annotations/adapter/files.c @@ -132,7 +132,7 @@ PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(data); if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } RETURN_CCTOR(data); } diff --git a/ext/assets/filters/cssmin.c b/ext/assets/filters/cssmin.c index 4244d7d1d09..be4a6e3f613 100644 --- a/ext/assets/filters/cssmin.c +++ b/ext/assets/filters/cssmin.c @@ -64,14 +64,10 @@ PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter){ zval *content; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &content); + phalcon_fetch_params(0, 1, 0, &content); if (phalcon_cssmin(return_value, content TSRMLS_CC) == FAILURE) { return; } - - RETURN_MM(); } diff --git a/ext/assets/filters/cssminifier.c b/ext/assets/filters/cssminifier.c index 1ba341c65f0..ac558602cb3 100644 --- a/ext/assets/filters/cssminifier.c +++ b/ext/assets/filters/cssminifier.c @@ -278,6 +278,8 @@ int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) { zval *error = NULL; + PHALCON_MM_GROW(); + ZVAL_NULL(return_value); if (Z_TYPE_P(style) != IS_STRING) { @@ -294,5 +296,6 @@ int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) { return FAILURE; } + PHALCON_MM_RESTORE(); return SUCCESS; } diff --git a/ext/assets/filters/jsmin.c b/ext/assets/filters/jsmin.c index 87ed5d12ef7..5ed68d979ab 100644 --- a/ext/assets/filters/jsmin.c +++ b/ext/assets/filters/jsmin.c @@ -64,14 +64,10 @@ PHP_METHOD(Phalcon_Assets_Filters_Jsmin, filter){ zval *content; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &content); + phalcon_fetch_params(0, 1, 0, &content); if (phalcon_jsmin(return_value, content TSRMLS_CC) == FAILURE) { return; } - - RETURN_MM(); } diff --git a/ext/assets/filters/jsminifier.c b/ext/assets/filters/jsminifier.c index 84ea62d9796..6463f6d64b3 100644 --- a/ext/assets/filters/jsminifier.c +++ b/ext/assets/filters/jsminifier.c @@ -383,6 +383,8 @@ int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { zval *error = NULL; + PHALCON_MM_GROW(); + ZVAL_NULL(return_value); if (Z_TYPE_P(script) != IS_STRING) { @@ -399,5 +401,6 @@ int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { return FAILURE; } + PHALCON_MM_RESTORE(); return SUCCESS; } diff --git a/ext/cli/console.c b/ext/cli/console.c index 5bee366df47..a21a30ed69f 100644 --- a/ext/cli/console.c +++ b/ext/cli/console.c @@ -310,7 +310,7 @@ PHP_METHOD(Phalcon_CLI_Console, handle){ phalcon_array_fetch_string(&path, module, SL("path"), PH_NOISY); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } } else { PHALCON_INIT_NVAR(exception_msg); diff --git a/ext/events/manager.c b/ext/events/manager.c index c95df87f11f..04077971c21 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -337,7 +337,7 @@ PHP_METHOD(Phalcon_Events_Manager, fireQueue){ */ PHALCON_INIT_VAR(iterator); if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/http/response.c b/ext/http/response.c index 8708a0583a1..02f47d63429 100644 --- a/ext/http/response.c +++ b/ext/http/response.c @@ -369,7 +369,7 @@ PHP_METHOD(Phalcon_Http_Response, setExpires){ PHALCON_INIT_VAR(date); if (phalcon_clone(date, datetime TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/kernel/exception.h b/ext/kernel/exception.h index 0929aa2d2fe..ceb7d54813f 100644 --- a/ext/kernel/exception.h +++ b/ext/kernel/exception.h @@ -26,13 +26,13 @@ #define PHALCON_THROW_EXCEPTION_STR(class_entry, message) \ do { \ phalcon_throw_exception_string(class_entry, message, strlen(message) TSRMLS_CC); \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ } while (0) #define PHALCON_THROW_EXCEPTION_ZVAL(class_entry, message) \ do { \ phalcon_throw_exception_zval(class_entry, message TSRMLS_CC); \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ } while (0) #define PHALCON_THROW_EXCEPTION_STRW(class_entry, message) phalcon_throw_exception_string(class_entry, message, strlen(message) TSRMLS_CC) diff --git a/ext/kernel/fcall.h b/ext/kernel/fcall.h index 6b1390a7964..9e43a44e94e 100644 --- a/ext/kernel/fcall.h +++ b/ext/kernel/fcall.h @@ -28,13 +28,13 @@ do { \ if (__builtin_constant_p(func_name)) { \ if (phalcon_call_func_params(return_value, func_name, sizeof(func_name)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_func_params(return_value, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -45,13 +45,13 @@ register ulong _key = key; \ if (__builtin_constant_p(method)) { \ if (phalcon_call_method_params(return_value, object, method, sizeof(method)-1, (_key ? _key : zend_inline_hash_func(method, sizeof(method))) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_method_params(return_value, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -61,13 +61,13 @@ do { \ if (__builtin_constant_p(class_name) && __builtin_constant_p(method)) { \ if (phalcon_call_static_func_params(return_value, class_name, sizeof(class_name)-1, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_static_func_params(return_value, class_name, strlen(class_name), method, strlen(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -77,13 +77,13 @@ do { \ if (__builtin_constant_p(method)) { \ if (phalcon_call_parent_func_params(return_value, this_ptr, class_entry, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_parent_func_params(return_value, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -93,13 +93,13 @@ do { \ if (__builtin_constant_p(method)) { \ if (phalcon_call_self_func_params(return_value, this_ptr, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_self_func_params(return_value, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -109,13 +109,13 @@ do { \ if (__builtin_constant_p(method)) { \ if (phalcon_call_static_zval_str_func_params(return_value, zclass, method, sizeof(method)-1 TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ else { \ if (phalcon_call_static_zval_str_func_params(return_value, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } \ @@ -126,7 +126,7 @@ #define PHALCON_CALL_FUNCTION(return_value, func_name, nparams, ...) \ do { \ if (phalcon_call_func_params(return_value, func_name, strlen(func_name) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -135,7 +135,7 @@ do { \ register ulong _key = key; \ if (phalcon_call_method_params(return_value, object, method, strlen(method), (_key ? _key : (IS_INTERNED(method) ? INTERNED_HASH(method) : 0)) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -143,7 +143,7 @@ #define PHALCON_CALL_STATIC(return_value, class_name, method, nparams, ...) \ do { \ if (phalcon_call_static_func_params(return_value, class_name, strlen(class_name), method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -151,7 +151,7 @@ #define PHALCON_CALL_PARENT(return_value, this_ptr, class_entry, method, nparams, ...) \ do { \ if (phalcon_call_parent_func_params(return_value, this_ptr, class_entry, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -159,7 +159,7 @@ #define PHALCON_CALL_SELF(return_value, this_ptr, method, nparams, ...) \ do { \ if (phalcon_call_self_func_params(return_value, this_ptr, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -167,7 +167,7 @@ #define PHALCON_CALL_ZSTATIC_STR(return_value, zclass, method, nparams, ...) \ do { \ if (phalcon_call_static_zval_str_func_params(return_value, zclass, method, strlen(method) TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -177,7 +177,7 @@ #define PHALCON_CALL_ZMETHOD(return_value, object, method, nparams, ...) \ do { \ if (phalcon_call_method_zval_params(return_value, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -185,7 +185,7 @@ #define PHALCON_CALL_ZSTATIC(return_value, object, method, nparams, ...) \ do { \ if (phalcon_call_static_zval_func_params(return_value, object, method TSRMLS_CC, nparams, __VA_ARGS__) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -196,7 +196,7 @@ #define PHALCON_CALL_USER_FUNC_ARRAY(return_value, handler, params) \ do { \ if (phalcon_call_user_func_array(return_value, handler, params TSRMLS_CC) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) @@ -204,7 +204,7 @@ #define PHALCON_CALL_USER_FUNC_ARRAY_NOEX(return_value, handler, params) \ do { \ if (phalcon_call_user_func_array_noex(return_value, handler, params TSRMLS_CC) == FAILURE) { \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } \ } while (0) diff --git a/ext/kernel/main.h b/ext/kernel/main.h index 214d0e2fe38..55bbc041239 100644 --- a/ext/kernel/main.h +++ b/ext/kernel/main.h @@ -258,7 +258,7 @@ extern int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, i #define phalcon_is_iterable(var, array_hash, hash_pointer, duplicate, reverse) \ if (!phalcon_is_iterable_ex(var, array_hash, hash_pointer, duplicate, reverse)) { \ zend_error(E_ERROR, "The argument is not iterable()"); \ - phalcon_memory_restore_stack(TSRMLS_C); \ + PHALCON_MM_RESTORE(); \ return; \ } diff --git a/ext/kernel/memory.c b/ext/kernel/memory.c index 1b92ebe1aaa..f17c1f60eb4 100644 --- a/ext/kernel/memory.c +++ b/ext/kernel/memory.c @@ -101,18 +101,15 @@ inline void phalcon_cpy_wrt_ctor(zval **dest, zval *var TSRMLS_DC) { Z_UNSET_ISREF_PP(dest); } -/** - * Adds a memory frame in the current executed method - */ -void PHALCON_FASTCALL phalcon_memory_grow_stack(TSRMLS_D) { - - zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; - +static phalcon_memory_entry* phalcon_memory_grow_stack_common(zend_phalcon_globals *phalcon_globals_ptr) +{ assert(phalcon_globals_ptr->start_memory != NULL); if (!phalcon_globals_ptr->active_memory) { phalcon_globals_ptr->active_memory = phalcon_globals_ptr->start_memory; + return phalcon_globals_ptr->start_memory; } - else { + + { phalcon_memory_entry *entry = (phalcon_memory_entry *) ecalloc(1, sizeof(phalcon_memory_entry)); /* ecalloc() will take care of these members entry->pointer = 0; @@ -126,27 +123,18 @@ void PHALCON_FASTCALL phalcon_memory_grow_stack(TSRMLS_D) { entry->prev = phalcon_globals_ptr->active_memory; entry->prev->next = entry; phalcon_globals_ptr->active_memory = entry; + return entry; } } -/** - * Finishes the current memory stack by releasing allocated memory - */ -int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { +static void phalcon_memory_restore_stack_common(zend_phalcon_globals *phalcon_globals_ptr TSRMLS_DC) { size_t i; phalcon_memory_entry *prev, *active_memory; phalcon_symbol_table *active_symbol_table; - zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; active_memory = phalcon_globals_ptr->active_memory; - if (unlikely(active_memory == NULL)) { -#ifndef PHALCON_RELEASE - fprintf(stderr, "WARNING: calling phalcon_memory_restore_stack() without an active memory frame!\n"); - phalcon_print_backtrace(); -#endif - return FAILURE; - } + assert(active_memory != NULL); if (phalcon_globals_ptr->active_symbol_table) { active_symbol_table = phalcon_globals_ptr->active_symbol_table; @@ -205,10 +193,59 @@ int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { active_memory->hash_pointer = 0; phalcon_globals_ptr->active_memory = NULL; } +} + +/** + * Finishes the current memory stack by releasing allocated memory + */ +int PHALCON_FASTCALL phalcon_memory_restore_stack(const char *func TSRMLS_DC) +{ + zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; + + if (unlikely(phalcon_globals_ptr->active_memory == NULL)) { + fprintf(stderr, "WARNING: calling phalcon_memory_restore_stack() without an active memory frame!\n"); + phalcon_print_backtrace(); + return FAILURE; + } + + if (unlikely(phalcon_globals_ptr->active_memory->func != func)) { + fprintf(stderr, "Trying to free someone else's memory frame!\n"); + fprintf(stderr, "The frame was created by %s\n", phalcon_globals_ptr->active_memory->func); + fprintf(stderr, "Calling function: %s\n", func); + phalcon_print_backtrace(); + } + phalcon_globals_ptr->active_memory->func = NULL; + + phalcon_memory_restore_stack_common(phalcon_globals_ptr TSRMLS_CC); return SUCCESS; } +#ifndef PHALCON_RELEASE +/** + * Adds a memory frame in the current executed method + */ +void PHALCON_FASTCALL phalcon_memory_grow_stack(const char *func TSRMLS_DC) { + + phalcon_memory_entry *entry = phalcon_memory_grow_stack_common(PHALCON_VGLOBAL); + entry->func = func; +} +#else +/** + * Adds a memory frame in the current executed method + */ +void PHALCON_FASTCALL phalcon_memory_grow_stack(TSRMLS_D) { + phalcon_memory_grow_stack_common(PHALCON_VGLOBAL); +} + +/** + * Finishes the current memory stack by releasing allocated memory + */ +int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { + phalcon_memory_restore_stack_common(PHALCON_VGLOBAL TSRMLS_CC); +} +#endif + static void phalcon_reallocate_memory(phalcon_memory_entry *frame) { void *buf = perealloc(frame->addresses, sizeof(zval **) * (frame->capacity + 16), unlikely(frame->prev == NULL)); @@ -235,6 +272,14 @@ static void phalcon_reallocate_hmemory(phalcon_memory_entry *frame) static inline void phalcon_do_memory_observe(zval **var, phalcon_memory_entry *frame) { +#ifndef PHALCON_RELEASE + if (unlikely(frame == NULL)) { + TSRMLS_FETCH(); + fprintf(stderr, "PHALCON_MM_GROW() must be called before using any of MM functions or macros!"); + phalcon_memory_grow_stack("N/A" TSRMLS_CC); + } +#endif + if (unlikely(frame->pointer == frame->capacity)) { phalcon_reallocate_memory(frame); } @@ -296,7 +341,7 @@ int PHALCON_FASTCALL phalcon_clean_restore_stack(TSRMLS_D) { zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; while (phalcon_globals_ptr->active_memory != NULL) { - phalcon_memory_restore_stack(TSRMLS_C); + phalcon_memory_restore_stack_common(phalcon_globals_ptr TSRMLS_CC); } return SUCCESS; diff --git a/ext/kernel/memory.h b/ext/kernel/memory.h index 6d5a3ebdfab..63dd3471600 100644 --- a/ext/kernel/memory.h +++ b/ext/kernel/memory.h @@ -23,8 +23,21 @@ extern void phalcon_cpy_wrt(zval **dest, zval *var TSRMLS_DC); extern void phalcon_cpy_wrt_ctor(zval **dest, zval *var TSRMLS_DC); /* Memory Frames */ -extern void PHALCON_FASTCALL phalcon_memory_grow_stack(TSRMLS_D); -extern int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D); +#ifndef PHALCON_RELEASE +void PHALCON_FASTCALL phalcon_memory_grow_stack(const char *func TSRMLS_DC); +int PHALCON_FASTCALL phalcon_memory_restore_stack(const char *func TSRMLS_DC); + +#define PHALCON_MM_GROW() phalcon_memory_grow_stack(__func__ TSRMLS_CC) +#define PHALCON_MM_RESTORE() phalcon_memory_restore_stack(__func__ TSRMLS_CC) + +#else +void PHALCON_FASTCALL phalcon_memory_grow_stack(TSRMLS_D); +int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D); + +#define PHALCON_MM_GROW() phalcon_memory_grow_stack(TSRMLS_C) +#define PHALCON_MM_RESTORE() phalcon_memory_restore_stack(TSRMLS_C) + +#endif extern void PHALCON_FASTCALL phalcon_memory_observe(zval **var TSRMLS_DC); extern void PHALCON_FASTCALL phalcon_memory_remove(zval **var TSRMLS_DC); @@ -44,9 +57,6 @@ extern int phalcon_set_symbol_str(char *key_name, unsigned int key_length, zval extern void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin); -#define PHALCON_MM_GROW() phalcon_memory_grow_stack(TSRMLS_C) -#define PHALCON_MM_RESTORE() phalcon_memory_restore_stack(TSRMLS_C) - /* Memory macros */ #define PHALCON_ALLOC_ZVAL(z) \ ALLOC_INIT_ZVAL(z) diff --git a/ext/kernel/object.c b/ext/kernel/object.c index 8c7ab2aed5c..88262e5d823 100644 --- a/ext/kernel/object.c +++ b/ext/kernel/object.c @@ -48,7 +48,6 @@ int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *c if (phalcon_hash_find(&ce->constants_table, constant_name, constant_length, (void **) &result_ptr) != SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Undefined class constant '%s::%s'", ce->name, constant_name); - phalcon_memory_restore_stack(TSRMLS_C); return FAILURE; } @@ -62,8 +61,8 @@ int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *c int phalcon_instance_of(zval *result, const zval *object, const zend_class_entry *ce TSRMLS_DC) { if (Z_TYPE_P(object) != IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "instanceof expects an object instance, constant given"); - phalcon_memory_restore_stack(TSRMLS_C); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "instanceof expects an object instance"); + ZVAL_FALSE(result); return FAILURE; } @@ -338,10 +337,6 @@ int phalcon_clone(zval *destination, zval *obj TSRMLS_DC) { } } - if (status == FAILURE){ - phalcon_memory_restore_stack(TSRMLS_C); - } - return status; } diff --git a/ext/kernel/object.h b/ext/kernel/object.h index 2a7feec809b..ab874d49eb8 100644 --- a/ext/kernel/object.h +++ b/ext/kernel/object.h @@ -28,6 +28,14 @@ zend_class_entry* phalcon_fetch_self_class(TSRMLS_D); zend_class_entry* phalcon_fetch_parent_class(TSRMLS_D); zend_class_entry* phalcon_fetch_static_class(TSRMLS_D); +#define PHALCON_GET_CLASS_CONSTANT(return_value, ce, const_name) \ + do { \ + if (FAILURE == phalcon_get_class_constant(return_value, ce, const_name, strlen(const_name)+1 TSRMLS_CC)) { \ + PHALCON_MM_RESTORE(); \ + return; \ + } \ + } while (0) + /** Class constants */ extern int phalcon_get_class_constant(zval *return_value, zend_class_entry *ce, char *constant_name, unsigned int constant_length TSRMLS_DC); diff --git a/ext/kernel/require.c b/ext/kernel/require.c index 2fbdb01d78c..a63df98344e 100644 --- a/ext/kernel/require.c +++ b/ext/kernel/require.c @@ -137,10 +137,6 @@ int PHALCON_FASTCALL phalcon_internal_require(zval *return_value, const zval *re } - if (status == FAILURE) { - phalcon_memory_restore_stack(TSRMLS_C); - } - return status; } diff --git a/ext/loader.c b/ext/loader.c index 3c9956784f3..e682a20e72e 100644 --- a/ext/loader.c +++ b/ext/loader.c @@ -484,7 +484,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ } if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } RETURN_MM_TRUE; } @@ -573,7 +573,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ * Simulate a require */ if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** @@ -658,7 +658,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ phalcon_call_method_p3_noret(events_manager, "fire", event_name, this_ptr, file_path); } if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } RETURN_MM_TRUE; } @@ -745,7 +745,7 @@ PHP_METHOD(Phalcon_Loader, autoLoad){ * Simulate a require */ if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/logger/adapter.c b/ext/logger/adapter.c index a8327e87c6e..83b3f258d5a 100644 --- a/ext/logger/adapter.c +++ b/ext/logger/adapter.c @@ -221,7 +221,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, emergence){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "EMERGENCE"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -242,7 +242,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, debug){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "DEBUG"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -262,7 +262,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, error){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "ERROR"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -282,7 +282,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, info){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "INFO"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -302,7 +302,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, notice){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "NOTICE"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -322,7 +322,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, warning){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "WARNING"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } @@ -342,7 +342,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, alert){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "ALERT"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); RETURN_THIS(); } diff --git a/ext/logger/multiple.c b/ext/logger/multiple.c index 72b890d3dd4..bc0fa1fd1a5 100644 --- a/ext/logger/multiple.c +++ b/ext/logger/multiple.c @@ -191,7 +191,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, emergence){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "EMERGENCE"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -212,7 +212,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, debug){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "DEBUG"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -232,7 +232,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, error){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "ERROR"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -252,7 +252,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, info){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "INFO"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -272,7 +272,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, notice){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "NOTICE"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -292,7 +292,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, warning){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "WARNING"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); @@ -312,7 +312,7 @@ PHP_METHOD(Phalcon_Logger_Multiple, alert){ phalcon_fetch_params(1, 1, 0, &message); PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); + PHALCON_GET_CLASS_CONSTANT(type, phalcon_logger_ce, "ALERT"); phalcon_call_method_p2_noret(this_ptr, "log", message, type); PHALCON_MM_RESTORE(); diff --git a/ext/mvc/application.c b/ext/mvc/application.c index f305e250fd3..7933f1c3a9e 100644 --- a/ext/mvc/application.c +++ b/ext/mvc/application.c @@ -380,7 +380,7 @@ PHP_METHOD(Phalcon_Mvc_Application, handle){ if (!phalcon_class_exists(class_name, 0 TSRMLS_CC)) { if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } } else { PHALCON_INIT_NVAR(exception_msg); diff --git a/ext/mvc/collection.c b/ext/mvc/collection.c index 0a308156a88..5a0c5e76b82 100644 --- a/ext/mvc/collection.c +++ b/ext/mvc/collection.c @@ -506,7 +506,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ PHALCON_INIT_VAR(cloned_collection); if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } phalcon_is_iterable(document, &ah0, &hp0, 0, 0); diff --git a/ext/mvc/model.c b/ext/mvc/model.c index 371272a9077..8e357154a01 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -764,7 +764,7 @@ PHP_METHOD(Phalcon_Mvc_Model, cloneResultMap){ PHALCON_INIT_VAR(object); if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** @@ -952,7 +952,7 @@ PHP_METHOD(Phalcon_Mvc_Model, cloneResult){ */ PHALCON_INIT_VAR(object); if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/mvc/model/behavior/softdelete.c b/ext/mvc/model/behavior/softdelete.c index c70c033b642..766fd8bebf1 100644 --- a/ext/mvc/model/behavior/softdelete.c +++ b/ext/mvc/model/behavior/softdelete.c @@ -123,8 +123,9 @@ PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ */ PHALCON_INIT_VAR(update_model); if (phalcon_clone(update_model, model TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } + phalcon_call_method_p2_noret(update_model, "writeattribute", field, value); /** diff --git a/ext/mvc/model/metadata/files.c b/ext/mvc/model/metadata/files.c index bf4f200676d..e3911a836fe 100644 --- a/ext/mvc/model/metadata/files.c +++ b/ext/mvc/model/metadata/files.c @@ -130,7 +130,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(data); if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } RETURN_CCTOR(data); } diff --git a/ext/mvc/model/query.c b/ext/mvc/model/query.c index 3e72813f25a..fd169b4d43b 100644 --- a/ext/mvc/model/query.c +++ b/ext/mvc/model/query.c @@ -4348,7 +4348,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){ */ PHALCON_INIT_VAR(insert_model); if (phalcon_clone(insert_model, base_model TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/mvc/view.c b/ext/mvc/view.c index 61ee1d31114..245689c5cb7 100644 --- a/ext/mvc/view.c +++ b/ext/mvc/view.c @@ -1415,7 +1415,7 @@ PHP_METHOD(Phalcon_Mvc_View, getRender){ */ PHALCON_INIT_VAR(view); if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** diff --git a/ext/mvc/view/engine/php.c b/ext/mvc/view/engine/php.c index 7cf66b3c755..bb67168dbfc 100644 --- a/ext/mvc/view/engine/php.c +++ b/ext/mvc/view/engine/php.c @@ -111,7 +111,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render){ * Require the file */ if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } if (PHALCON_IS_TRUE(must_clean)) { PHALCON_INIT_VAR(contents); diff --git a/ext/mvc/view/engine/volt.c b/ext/mvc/view/engine/volt.c index 2601121741c..4fc423b983d 100644 --- a/ext/mvc/view/engine/volt.c +++ b/ext/mvc/view/engine/volt.c @@ -203,7 +203,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){ } if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } if (PHALCON_IS_TRUE(must_clean)) { PHALCON_INIT_VAR(contents); diff --git a/ext/mvc/view/engine/volt/compiler.c b/ext/mvc/view/engine/volt/compiler.c index 7dcaf534dcd..c9f3ce6ab18 100644 --- a/ext/mvc/view/engine/volt/compiler.c +++ b/ext/mvc/view/engine/volt/compiler.c @@ -2527,7 +2527,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileInclude){ */ PHALCON_INIT_VAR(sub_compiler); if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** @@ -3134,7 +3134,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementList){ */ PHALCON_INIT_NVAR(sub_compiler); if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } PHALCON_INIT_NVAR(temp_compilation); diff --git a/ext/paginator/adapter/querybuilder.c b/ext/paginator/adapter/querybuilder.c index d6a5d31eb0e..5a4b15d8361 100644 --- a/ext/paginator/adapter/querybuilder.c +++ b/ext/paginator/adapter/querybuilder.c @@ -154,7 +154,7 @@ PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ */ PHALCON_INIT_VAR(builder); if (phalcon_clone(builder, original_builder TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } /** @@ -162,7 +162,7 @@ PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ */ PHALCON_INIT_VAR(total_builder); if (phalcon_clone(total_builder, builder TSRMLS_CC) == FAILURE) { - return; + RETURN_MM(); } PHALCON_OBS_VAR(limit); diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index dd27700bd94..2a3d7c61112 100644 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -35,6 +35,9 @@ typedef struct _phalcon_memory_entry { zval ***hash_addresses; struct _phalcon_memory_entry *prev; struct _phalcon_memory_entry *next; +#ifndef PHALCON_RELEASE + const char *func; +#endif } phalcon_memory_entry; /** Virtual Symbol Table */