Skip to content

Commit

Permalink
Merge pull request #1097 from sjinks/mem-diag
Browse files Browse the repository at this point in the history
Better diagnostics in phalcon_memory_restore_stack_common() when PHP is built in debug mode
  • Loading branch information
Phalcon committed Aug 16, 2013
2 parents ee12592 + a804b6c commit b3cd3ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion ext/1

This file was deleted.

21 changes: 20 additions & 1 deletion ext/kernel/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#include "config.h"
#endif

#include "php.h"
#include "main/php.h"
#include "php_phalcon.h"

#include "Zend/zend_alloc.h"

#include "kernel/memory.h"
#include "kernel/fcall.h"
#include "kernel/backtrace.h"
Expand Down Expand Up @@ -132,6 +135,12 @@ static void phalcon_memory_restore_stack_common(zend_phalcon_globals *phalcon_gl
size_t i;
phalcon_memory_entry *prev, *active_memory;
phalcon_symbol_table *active_symbol_table;
#if ZEND_DEBUG
char* __zend_filename = __FILE__;
char* __zend_orig_filename = __FILE__;
int __zend_lineno = 0;
int __zend_orig_lineno = 0;
#endif

active_memory = phalcon_globals_ptr->active_memory;
assert(active_memory != NULL);
Expand All @@ -152,6 +161,11 @@ static void phalcon_memory_restore_stack_common(zend_phalcon_globals *phalcon_gl
*/
for (i = 0; i < active_memory->hash_pointer; ++i) {
assert(active_memory->hash_addresses[i] != NULL && *(active_memory->hash_addresses[i]) != NULL);

#if ZEND_DEBUG
_mem_block_check(*active_memory->hash_addresses[i], 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
#endif

if (Z_REFCOUNT_PP(active_memory->hash_addresses[i]) <= 1) {
ZVAL_NULL(*active_memory->hash_addresses[i]);
} else {
Expand All @@ -163,6 +177,11 @@ static void phalcon_memory_restore_stack_common(zend_phalcon_globals *phalcon_gl
for (i = 0; i < active_memory->pointer; ++i) {
if (likely(active_memory->addresses[i] != NULL && *(active_memory->addresses[i]) != NULL)) {
zval **var = active_memory->addresses[i];

#if ZEND_DEBUG
_mem_block_check(*var, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
#endif

#if PHP_VERSION_ID < 50400
if (Z_TYPE_PP(var) > IS_CONSTANT_ARRAY) {
fprintf(stderr, "%s: observed variable #%d (%p) has invalid type %u\n", __func__, (int)i, *var, Z_TYPE_PP(var));
Expand Down

0 comments on commit b3cd3ef

Please sign in to comment.