return;
}
- if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
+ if (intern->u.dir.dirp && php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) {
RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
} else {
/* should not happen */
zend_fcall_info fci;
zend_fcall_info_cache fcic;
zval z_fname;
- zval * zresource_ptr = &intern->u.file.zresource, *retval;
+ zval * zresource_ptr = &intern->u.file.zresource, *retval = NULL;
int result;
int num_args = pass_num_args + (arg2 ? 2 : 1);
result = zend_call_function(&fci, &fcic TSRMLS_CC);
- if (result == FAILURE) {
+ if (result == FAILURE || retval == NULL) {
RETVAL_FALSE;
} else {
ZVAL_ZVAL(return_value, retval, 1, 1);
static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
{
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
if (-1 == php_stream_rewind(intern->u.file.stream)) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot rewind file %s", intern->file_name);
} else {
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_BOOL(php_stream_eof(intern->u.file.stream));
} /* }}} */
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
RETURN_BOOL(intern->u.file.current_line || intern->u.file.current_zval);
} else {
+ if(!intern->u.file.stream) {
+ RETURN_FALSE;
+ }
RETVAL_BOOL(!php_stream_eof(intern->u.file.stream));
}
} /* }}} */
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (spl_filesystem_file_read(intern, 0 TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
}
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (!intern->u.file.current_line && !intern->u.file.current_zval) {
spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
}
int d_len = 0, e_len = 0, esc_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
+
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
switch(ZEND_NUM_ARGS())
{
case 3:
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_BOOL(!php_stream_flush(intern->u.file.stream));
} /* }}} */
SPL_METHOD(SplFileObject, ftell)
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long ret = php_stream_tell(intern->u.file.stream);
+ long ret;
+
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
+ ret = php_stream_tell(intern->u.file.stream);
if (ret == -1) {
RETURN_FALSE;
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, whence));
} /* }}} */
char buf[2];
int result;
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
result = php_stream_getc(intern->u.file.stream);
zval *arg2 = NULL;
MAKE_STD_ZVAL(arg2);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (intern->u.file.max_line_len > 0) {
ZVAL_LONG(arg2, intern->u.file.max_line_len);
} else {
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
RETURN_LONG(php_stream_passthru(intern->u.file.stream));
} /* }}} */
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
spl_filesystem_file_free_line(intern TSRMLS_CC);
intern->u.file.current_line_num++;
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (ZEND_NUM_ARGS() > 1) {
str_len = MAX(0, MIN(length, str_len));
}
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (length <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (!php_stream_truncate_supported(intern->u.file.stream)) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name);
RETURN_FALSE;
{
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
long line_pos;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) {
return;
}
+ if(!intern->u.file.stream) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ return;
+ }
+
if (line_pos < 0) {
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos);
RETURN_FALSE;
}
-
+
spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
while(intern->u.file.current_line_num < line_pos) {
(var) = it; \
} while (0)
+#define SPL_FETCH_SUB_ELEMENT(var, object, element) \
+ do { \
+ if(!(object)->iterators) { \
+ 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) = (object)->iterators[(object)->level].element; \
+ } while (0)
+
+#define SPL_FETCH_SUB_ITERATOR(var, object) SPL_FETCH_SUB_ELEMENT(var, object, iterator)
+
+
static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
{
spl_recursive_it_iterator *iter = (spl_recursive_it_iterator*)_iter;
{
zend_object_iterator *sub_iter;
int level = object->level;
-
+
+ if(!object->iterators) {
+ return FAILURE;
+ }
while (level >=0) {
sub_iter = object->iterators[level].iterator;
if (sub_iter->funcs->valid(sub_iter TSRMLS_CC) == SUCCESS) {
zend_object_iterator *sub_iter;
int has_children;
+ SPL_FETCH_SUB_ITERATOR(iterator, object);
+
while (!EG(exception)) {
next_step:
iterator = object->iterators[object->level].iterator;
{
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);
- }
+ SPL_FETCH_SUB_ITERATOR(sub_iter, object);
while (object->level) {
sub_iter = object->iterators[object->level].iterator;
SPL_METHOD(RecursiveIteratorIterator, valid)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
SPL_METHOD(RecursiveIteratorIterator, key)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_object_iterator *iterator = object->iterators[object->level].iterator;
-
+ zend_object_iterator *iterator;
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+ SPL_FETCH_SUB_ITERATOR(iterator, object);
+
if (iterator->funcs->get_current_key) {
iterator->funcs->get_current_key(iterator, return_value TSRMLS_CC);
} else {
SPL_METHOD(RecursiveIteratorIterator, current)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_object_iterator *iterator = object->iterators[object->level].iterator;
+ zend_object_iterator *iterator;
zval **data;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+ SPL_FETCH_SUB_ITERATOR(iterator, object);
+
iterator->funcs->get_current_data(iterator, &data TSRMLS_CC);
if (data && *data) {
RETURN_ZVAL(*data, 1, 0);
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
long level = object->level;
+ zval *zobject;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &level) == FAILURE) {
return;
if (level < 0 || level > object->level) {
RETURN_NULL();
}
+
+ if(!object->iterators) {
+ 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;
+ }
+
RETURN_ZVAL(object->iterators[level].zobject, 1, 0);
} /* }}} */
SPL_METHOD(RecursiveIteratorIterator, getInnerIterator)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long level = object->level;
+ zval *zobject;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- RETURN_ZVAL(object->iterators[level].zobject, 1, 0);
+
+ SPL_FETCH_SUB_ELEMENT(zobject, object, zobject);
+
+ RETURN_ZVAL(zobject, 1, 0);
} /* }}} */
/* {{{ proto RecursiveIterator RecursiveIteratorIterator::beginIteration()
SPL_METHOD(RecursiveIteratorIterator, callHasChildren)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_class_entry *ce = object->iterators[object->level].ce;
+ zend_class_entry *ce;
zval *retval, *zobject;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+ if (!object->iterators) {
+ RETURN_NULL();
+ }
+
+ SPL_FETCH_SUB_ELEMENT(ce, object, ce);
+
zobject = object->iterators[object->level].zobject;
if (!zobject) {
RETURN_FALSE;
SPL_METHOD(RecursiveIteratorIterator, callGetChildren)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_class_entry *ce = object->iterators[object->level].ce;
+ zend_class_entry *ce;
zval *retval, *zobject;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+ SPL_FETCH_SUB_ELEMENT(ce, object, ce);
+
zobject = object->iterators[object->level].zobject;
if (!zobject) {
return;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+
+ if(!object->iterators) {
+ 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;
+ }
+
spl_recursive_tree_iterator_get_prefix(object, return_value TSRMLS_CC);
} /* }}} */
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+
+ if(!object->iterators) {
+ 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;
+ }
spl_recursive_tree_iterator_get_entry(object, return_value TSRMLS_CC);
} /* }}} */
if (zend_parse_parameters_none() == FAILURE) {
return;
}
+
+ if(!object->iterators) {
+ 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;
+ }
spl_recursive_tree_iterator_get_postfix(object, return_value TSRMLS_CC);
} /* }}} */
return;
}
+ if(!object->iterators) {
+ 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;
+ }
+
if (object->flags & RTIT_BYPASS_CURRENT) {
- zend_object_iterator *iterator = object->iterators[object->level].iterator;
+ zend_object_iterator *iterator;
zval **data;
+ SPL_FETCH_SUB_ITERATOR(iterator, object);
iterator->funcs->get_current_data(iterator, &data TSRMLS_CC);
if (data && *data) {
RETURN_ZVAL(*data, 1, 0);
SPL_METHOD(RecursiveTreeIterator, key)
{
spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_object_iterator *iterator = object->iterators[object->level].iterator;
+ zend_object_iterator *iterator;
zval prefix, key, postfix, key_copy;
char *str, *ptr;
size_t str_len;
return;
}
+ SPL_FETCH_SUB_ITERATOR(iterator, object);
+
if (iterator->funcs->get_current_key) {
iterator->funcs->get_current_key(iterator, &key TSRMLS_CC);
} else {
return;
}
- intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
if (!EG(exception) && retval) {