} spl_sub_iterator;
typedef struct _spl_recursive_it_object {
- zend_object std;
spl_sub_iterator *iterators;
int level;
RecursiveIteratorMode mode;
zend_class_entry *ce;
smart_str prefix[6];
smart_str postfix[1];
+ zend_object std;
} spl_recursive_it_object;
typedef struct _spl_recursive_it_iterator {
static zend_object_handlers spl_handlers_rec_it_it;
static zend_object_handlers spl_handlers_dual_it;
-#define SPL_FETCH_AND_CHECK_DUAL_IT(var, objzval) \
- do { \
- spl_dual_it_object *it = (spl_dual_it_object *)Z_OBJ_P((objzval)); \
- if (it->dit_type == DIT_Unknown) { \
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, \
- "The object is in an invalid state as the parent constructor was not called"); \
- return; \
- } \
- (var) = it; \
+static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *obj) /* {{{ */ {
+ return (spl_recursive_it_object*)((char*)(obj) - XtOffsetOf(spl_recursive_it_object, std));
+}
+/* }}} */
+
+#define Z_SPLRECURSIVE_IT_P(zv) spl_recursive_it_from_obj(Z_OBJ_P((zv)))
+
+#define SPL_FETCH_AND_CHECK_DUAL_IT(var, objzval) \
+ do { \
+ spl_dual_it_object *it = Z_SPLDUAL_IT_P(objzval); \
+ if (it->dit_type == DIT_Unknown) { \
+ zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, \
+ "The object is in an invalid state as the parent constructor was not called"); \
+ return; \
+ } \
+ (var) = it; \
} while (0)
static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
{
spl_recursive_it_iterator *iter = (spl_recursive_it_iterator*)_iter;
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ(iter->intern.data);
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(&iter->intern.data);
zend_object_iterator *sub_iter;
while (object->level > 0) {
static int spl_recursive_it_valid(zend_object_iterator *iter TSRMLS_DC)
{
- return spl_recursive_it_valid_ex((spl_recursive_it_object*)Z_OBJ(iter->data), &iter->data TSRMLS_CC);
+ return spl_recursive_it_valid_ex(Z_SPLRECURSIVE_IT_P(&iter->data), &iter->data TSRMLS_CC);
}
static zval *spl_recursive_it_get_current_data(zend_object_iterator *iter TSRMLS_DC)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ(iter->data);
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(&iter->data);
zend_object_iterator *sub_iter = object->iterators[object->level].iterator;
return sub_iter->funcs->get_current_data(sub_iter TSRMLS_CC);
static void spl_recursive_it_get_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ(iter->data);
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(&iter->data);
zend_object_iterator *sub_iter = object->iterators[object->level].iterator;
if (sub_iter->funcs->get_current_key) {
static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object, zval *zthis TSRMLS_DC)
{
- zend_object_iterator *sub_iter;
+ zend_object_iterator *sub_iter;
if (!object->iterators) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "The %s instance wasn't initialized properly", Z_OBJCE_P(zthis)->name->val);
static void spl_recursive_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
{
- spl_recursive_it_move_forward_ex((spl_recursive_it_object*)Z_OBJ(iter->data), &iter->data TSRMLS_CC);
+ spl_recursive_it_move_forward_ex(Z_SPLRECURSIVE_IT_P(&iter->data), &iter->data TSRMLS_CC);
}
static void spl_recursive_it_rewind(zend_object_iterator *iter TSRMLS_DC)
{
- spl_recursive_it_rewind_ex((spl_recursive_it_object*)Z_OBJ(iter->data), &iter->data TSRMLS_CC);
+ spl_recursive_it_rewind_ex(Z_SPLRECURSIVE_IT_P(&iter->data), &iter->data TSRMLS_CC);
}
static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, zval *zobject, int by_ref TSRMLS_DC)
zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
}
iterator = emalloc(sizeof(spl_recursive_it_iterator));
- object = (spl_recursive_it_object *)Z_OBJ_P(zobject);
+ object = Z_SPLRECURSIVE_IT_P(zobject);
if (object->iterators == NULL) {
zend_error(E_ERROR, "The object to be iterated is in an invalid state: "
"the parent constructor has not been called");
return;
}
- intern = (spl_recursive_it_object*)Z_OBJ_P(object);
+ intern = Z_SPLRECURSIVE_IT_P(object);
intern->iterators = emalloc(sizeof(spl_sub_iterator));
intern->level = 0;
intern->mode = mode;
Rewind the iterator to the first element of the top level inner iterator. */
SPL_METHOD(RecursiveIteratorIterator, rewind)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Check whether the current position is valid */
SPL_METHOD(RecursiveIteratorIterator, valid)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Access the current key */
SPL_METHOD(RecursiveIteratorIterator, key)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zend_object_iterator *iterator = object->iterators[object->level].iterator;
if (zend_parse_parameters_none() == FAILURE) {
Access the current element value */
SPL_METHOD(RecursiveIteratorIterator, current)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zend_object_iterator *iterator = object->iterators[object->level].iterator;
zval *data;
Move forward to the next element */
SPL_METHOD(RecursiveIteratorIterator, next)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Get the current depth of the recursive iteration */
SPL_METHOD(RecursiveIteratorIterator, getDepth)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
The current active sub iterator or the iterator at specified level */
SPL_METHOD(RecursiveIteratorIterator, getSubIterator)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
long level = object->level;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &level) == FAILURE) {
The current active sub iterator */
SPL_METHOD(RecursiveIteratorIterator, getInnerIterator)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
long level = object->level;
if (zend_parse_parameters_none() == FAILURE) {
Called for each element to test whether it has children */
SPL_METHOD(RecursiveIteratorIterator, callHasChildren)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zend_class_entry *ce = object->iterators[object->level].ce;
zval *zobject;
Return children of current element */
SPL_METHOD(RecursiveIteratorIterator, callGetChildren)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zend_class_entry *ce = object->iterators[object->level].ce;
zval *zobject;
Set the maximum allowed depth (or any depth if pmax_depth = -1] */
SPL_METHOD(RecursiveIteratorIterator, setMaxDepth)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
long max_depth = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_depth) == FAILURE) {
Return the maximum accepted depth or false if any depth is allowed */
SPL_METHOD(RecursiveIteratorIterator, getMaxDepth)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
static union _zend_function *spl_recursive_it_get_method(zval *object_ptr, zend_string *method, const zend_literal *key TSRMLS_DC)
{
union _zend_function *function_handler;
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(object_ptr);
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(object_ptr);
long level = object->level;
zval *zobj;
/* {{{ spl_RecursiveIteratorIterator_dtor */
static void spl_RecursiveIteratorIterator_dtor(zend_object *_object TSRMLS_DC)
{
- spl_recursive_it_object *object = (spl_recursive_it_object *)_object;
- zend_object_iterator *sub_iter;
+ spl_recursive_it_object *object = spl_recursive_it_from_obj(_object);
+ zend_object_iterator *sub_iter;
/* call standard dtor */
zend_objects_destroy_object(_object TSRMLS_CC);
/* {{{ spl_RecursiveIteratorIterator_free_storage */
static void spl_RecursiveIteratorIterator_free_storage(zend_object *_object TSRMLS_DC)
{
- spl_recursive_it_object *object = (spl_recursive_it_object *)_object;
+ spl_recursive_it_object *object = spl_recursive_it_from_obj(_object);
zend_object_std_dtor(&object->std TSRMLS_CC);
smart_str_free(&object->prefix[0]);
{
spl_recursive_it_object *intern;
- intern = emalloc(sizeof(spl_recursive_it_object));
- memset(intern, 0, sizeof(spl_recursive_it_object));
+ intern = ecalloc(1, sizeof(spl_recursive_it_object) + sizeof(zval) * (class_type->default_properties_count - 1));
if (init_prefix) {
smart_str_appendl(&intern->prefix[0], "", 0);
long part;
char* prefix;
int prefix_len;
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &part, &prefix, &prefix_len) == FAILURE) {
return;
Returns the string to place in front of current element */
SPL_METHOD(RecursiveTreeIterator, getPrefix)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Sets postfix as used in getPostfix() */
SPL_METHOD(RecursiveTreeIterator, setPostfix)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
char* postfix;
int postfix_len;
Returns the string presentation built for current element */
SPL_METHOD(RecursiveTreeIterator, getEntry)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Returns the string to place after the current element */
SPL_METHOD(RecursiveTreeIterator, getPostfix)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
Returns the current element prefixed and postfixed */
SPL_METHOD(RecursiveTreeIterator, current)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zval prefix, entry, postfix;
char *str, *ptr;
size_t str_len;
Returns the current key prefixed and postfixed */
SPL_METHOD(RecursiveTreeIterator, key)
{
- spl_recursive_it_object *object = (spl_recursive_it_object*)Z_OBJ_P(getThis());
+ spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(getThis());
zend_object_iterator *iterator = object->iterators[object->level].iterator;
zval prefix, key, postfix, key_copy;
char *str, *ptr;
union _zend_function *function_handler;
spl_dual_it_object *intern;
- intern = (spl_dual_it_object*)Z_OBJ_P(object_ptr);
+ intern = Z_SPLDUAL_IT_P(object_ptr);
function_handler = std_object_handlers.get_method(object_ptr, method, key TSRMLS_CC);
if (!function_handler && intern->inner.ce) {
void **p;
spl_dual_it_object *intern;
- intern = (spl_dual_it_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDUAL_IT_P(getThis());
ZVAL_STRING(&func, method, 0);
if (!zend_is_callable(&func, 0, &method TSRMLS_CC)) {
#define SPL_CHECK_CTOR(intern, classname) \
if (intern->dit_type == DIT_Unknown) { \
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Classes derived from %s must call %s::__construct()", \
- (spl_ce_##classname)->name, (spl_ce_##classname)->name); \
+ (spl_ce_##classname)->name->val, (spl_ce_##classname)->name->val); \
return; \
}
int inc_refcount = 1;
zend_error_handling error_handling;
- intern = (spl_dual_it_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDUAL_IT_P(getThis());
if (intern->dit_type != DIT_Unknown) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s::getIterator() must be called exactly once per instance", ce_base->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s::getIterator() must be called exactly once per instance", ce_base->name->val);
return NULL;
}
return NULL;
}
if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable TSRMLS_CC)) {
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "%s::getIterator() must return an object that implements Traversable", ce->name);
+ zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "%s::getIterator() must return an object that implements Traversable", ce->name->val);
zend_restore_error_handling(&error_handling TSRMLS_CC);
return NULL;
}
ZVAL_UNDEF(&intern->current.key);
}
if (intern->dit_type == DIT_CachingIterator || intern->dit_type == DIT_RecursiveCachingIterator) {
- if (Z_TYPE(intern->u.caching.zstr) != IS_STRING) {
+ if (Z_TYPE(intern->u.caching.zstr) != IS_UNDEF) {
zval_ptr_dtor(&intern->u.caching.zstr);
ZVAL_UNDEF(&intern->u.caching.zstr);
}
return;
}
- intern = (spl_dual_it_object*)Z_OBJ_P(getThis());
+ intern = Z_SPLDUAL_IT_P(getThis());
zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
if (!EG(exception) && Z_TYPE(retval) != IS_UNDEF) {
Calls the callback with the current value, the current key and the inner iterator as arguments */
SPL_METHOD(CallbackFilterIterator, accept)
{
- spl_dual_it_object *intern = (spl_dual_it_object*)Z_OBJ_P(getThis());
+ spl_dual_it_object *intern = Z_SPLDUAL_IT_P(getThis());
zend_fcall_info *fci = &intern->u.cbfilter->fci;
zend_fcall_info_cache *fcc = &intern->u.cbfilter->fcc;
zval params[3];
subject_ptr = &intern->current.data;
}
+ ZVAL_UNDEF(&subject_copy);
zend_make_printable_zval(subject_ptr, &subject_copy, &use_copy);
if (use_copy) {
subject = Z_STRVAL(subject_copy);
subject_len = Z_STRLEN_P(subject_ptr);
}
+ use_copy = 0;
switch (intern->u.regex.mode)
{
- case REGIT_MODE_MAX: /* won't happen but makes compiler happy */
- case REGIT_MODE_MATCH:
- count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject, subject_len, 0, 0, NULL, 0);
- RETVAL_BOOL(count >= 0);
- break;
-
- case REGIT_MODE_ALL_MATCHES:
- case REGIT_MODE_GET_MATCH:
- if (!use_copy) {
- subject = estrndup(subject, subject_len);
- use_copy = 1;
- }
- zval_ptr_dtor(&intern->current.data);
- php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount,
- &intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
- count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
- RETVAL_BOOL(count > 0);
- break;
-
- case REGIT_MODE_SPLIT:
- if (!use_copy) {
- subject = estrndup(subject, subject_len);
- use_copy = 1;
- }
- zval_ptr_dtor(&intern->current.data);
- php_pcre_split_impl(intern->u.regex.pce, subject, subject_len, &intern->current.data, -1, intern->u.regex.preg_flags TSRMLS_CC);
- count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
- RETVAL_BOOL(count > 1);
- break;
-
- case REGIT_MODE_REPLACE:
- replacement = zend_read_property(intern->std.ce, getThis(), "replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
- if (Z_TYPE_P(replacement) != IS_STRING) {
- tmp_replacement = *replacement;
- zval_copy_ctor(&tmp_replacement);
- convert_to_string(&tmp_replacement);
- replacement = &tmp_replacement;
- }
- result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);
-
- if (intern->u.regex.flags & REGIT_USE_KEY) {
- zval_ptr_dtor(&intern->current.key);
-//??? ZVAL_STRINGL(intern->current.key, result, result_len, 0);
- ZVAL_STRINGL(&intern->current.key, result, result_len);
- } else {
+ case REGIT_MODE_MAX: /* won't happen but makes compiler happy */
+ case REGIT_MODE_MATCH:
+ count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject, subject_len, 0, 0, NULL, 0);
+ RETVAL_BOOL(count >= 0);
+ break;
+
+ case REGIT_MODE_ALL_MATCHES:
+ case REGIT_MODE_GET_MATCH:
+ if (!use_copy) {
+ subject = estrndup(subject, subject_len);
+ use_copy = 1;
+ }
zval_ptr_dtor(&intern->current.data);
-//??? ZVAL_STRINGL(intern->current.data, result, result_len, 0);
- ZVAL_STRINGL(&intern->current.data, result, result_len);
- }
+ ZVAL_UNDEF(&intern->current.data);
+ php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount,
+ &intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
+ count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
+ RETVAL_BOOL(count > 0);
+ break;
- if (replacement == &tmp_replacement) {
- zval_dtor(replacement);
- }
- RETVAL_BOOL(count > 0);
+ case REGIT_MODE_SPLIT:
+ if (!use_copy) {
+ subject = estrndup(subject, subject_len);
+ use_copy = 1;
+ }
+ zval_ptr_dtor(&intern->current.data);
+ ZVAL_UNDEF(&intern->current.data);
+ php_pcre_split_impl(intern->u.regex.pce, subject, subject_len, &intern->current.data, -1, intern->u.regex.preg_flags TSRMLS_CC);
+ count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
+ RETVAL_BOOL(count > 1);
+ break;
+
+ case REGIT_MODE_REPLACE:
+ replacement = zend_read_property(intern->std.ce, getThis(), "replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+ if (Z_TYPE_P(replacement) != IS_STRING) {
+ tmp_replacement = *replacement;
+ zval_copy_ctor(&tmp_replacement);
+ convert_to_string(&tmp_replacement);
+ replacement = &tmp_replacement;
+ }
+ result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, -1, &count TSRMLS_CC);
+
+ if (intern->u.regex.flags & REGIT_USE_KEY) {
+ zval_ptr_dtor(&intern->current.key);
+ //??? ZVAL_STRINGL(intern->current.key, result, result_len, 0);
+ ZVAL_STRINGL(&intern->current.key, result, result_len);
+ } else {
+ zval_ptr_dtor(&intern->current.data);
+ //??? ZVAL_STRINGL(intern->current.data, result, result_len, 0);
+ ZVAL_STRINGL(&intern->current.data, result, result_len);
+ }
+
+ if (replacement == &tmp_replacement) {
+ zval_dtor(replacement);
+ }
+ RETVAL_BOOL(count > 0);
}
if (intern->u.regex.flags & REGIT_INVERTED) {
}
if (use_copy) {
-//??? str_efree(subject);
efree(subject);
}
+ if (!ZVAL_IS_UNDEF(&subject_copy)) {
+ zval_ptr_dtor(&subject_copy);
+ }
} /* }}} */
/* {{{ proto string RegexIterator::getRegex()
Returns current regular expression */
SPL_METHOD(RegexIterator, getRegex)
{
- spl_dual_it_object *intern = (spl_dual_it_object*)Z_OBJ_P(getThis());
+ spl_dual_it_object *intern = Z_SPLDUAL_IT_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
/* {{{ spl_dual_it_dtor */
static void spl_dual_it_dtor(zend_object *_object TSRMLS_DC)
{
- spl_dual_it_object *object = (spl_dual_it_object *)_object;
+ spl_dual_it_object *object = spl_dual_it_from_obj(_object);
/* call standard dtor */
zend_objects_destroy_object(_object TSRMLS_CC);
/* {{{ spl_dual_it_free_storage */
static void spl_dual_it_free_storage(zend_object *_object TSRMLS_DC)
{
- spl_dual_it_object *object = (spl_dual_it_object *)_object;
+ spl_dual_it_object *object = spl_dual_it_from_obj(_object);
if (!ZVAL_IS_UNDEF(&object->inner.zobject)) {
object->u.regex.pce->refcount--;
}
if (object->u.regex.regex) {
- efree(object->u.regex.regex);
+ STR_RELEASE(object->u.regex.regex);
}
}
#endif
{
spl_dual_it_object *intern;
- intern = emalloc(sizeof(spl_dual_it_object));
- memset(intern, 0, sizeof(spl_dual_it_object));
+ intern = ecalloc(1, sizeof(spl_dual_it_object) + sizeof(zval) * (class_type->default_properties_count - 1));
intern->dit_type = DIT_Unknown;
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
}
zend_make_printable_zval(&intern->u.caching.zstr, &expr_copy, &use_copy);
if (use_copy) {
- ZVAL_COPY_VALUE(&intern->u.caching.zstr, &expr_copy);
-//??? INIT_PZVAL(intern->u.caching.zstr);
- zval_copy_ctor(&intern->u.caching.zstr);
+ ZVAL_COPY(&intern->u.caching.zstr, &expr_copy);
+//??? INIT_PZVAL(intern->u.caching.zstr);
+ //zval_copy_ctor(&intern->u.caching.zstr);
zval_dtor(&expr_copy);
- } else {
-//??? INIT_PZVAL(intern->u.caching.zstr);
- zval_copy_ctor(&intern->u.caching.zstr);
+ } else if (Z_REFCOUNT(intern->u.caching.zstr)) {
+//??? INIT_PZVAL(intern->u.caching.zstr);
+ //zval_copy_ctor(&intern->u.caching.zstr);
+ Z_ADDREF(intern->u.caching.zstr);
}
}
spl_dual_it_next(intern, 0 TSRMLS_CC);
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & (CIT_CALL_TOSTRING|CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT|CIT_TOSTRING_USE_INNER))) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
if (intern->u.caching.flags & CIT_TOSTRING_USE_KEY) {
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
return;
}
- Z_ADDREF_P(value);
+ if (Z_REFCOUNTED_P(value)) {
+ Z_ADDREF_P(value);
+ }
zend_symtable_update(HASH_OF(&intern->u.caching.zcache), key, value);
}
/* }}} */
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
if (!(intern->u.caching.flags & CIT_FULL_CACHE)) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name->val);
return;
}