if (Z_OBJ_HANDLER_P(expr, cast_object)) {
zval val;
-//??? ALLOC_ZVAL(val);
-//??? INIT_PZVAL_COPY(val, expr);
-//??? zval_copy_ctor(val);
- if (Z_ISREF_P(expr)) {
- ZVAL_COPY_VALUE(&val, Z_REFVAL_P(expr));
- } else {
- ZVAL_COPY_VALUE(&val, expr);
- }
- zval_copy_ctor(&val);
+ ZVAL_DUP_DEREF(&val, expr);
if (Z_OBJ_HANDLER_P(expr, cast_object)(&val, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
zval_ptr_dtor(&val);
break;
{
zval globals;
-//??? ALLOC_ZVAL(globals);
-//??? Z_SET_REFCOUNT_P(globals, 1);
-//??? Z_SET_ISREF_P(globals);
ZVAL_ARR(&globals, &EG(symbol_table));
ZVAL_NEW_REF(&globals, &globals);
zend_hash_update(&EG(symbol_table).ht, name, &globals);
if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
zval_ptr_dtor(&retval2);
if (EG(exception)) {
-//??? zval_ptr_dtor(&EG(exception));
+ OBJ_RELEASE(EG(exception));
EG(exception) = NULL;
}
-//??? zval_ptr_dtor(&old_exception);
+ OBJ_RELEASE(old_exception);
} else {
EG(exception) = old_exception;
zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
zval_copy_ctor(z); \
} while (0)
+#define ZVAL_DUP_DEREF(z, v) \
+ do { \
+ if (Z_ISREF_P(v)) { \
+ ZVAL_COPY_VALUE(z, Z_REFVAL_P(v)); \
+ } else { \
+ ZVAL_COPY_VALUE(z, v); \
+ } \
+ zval_copy_ctor(z); \
+ } while (0)
+
#define INIT_PZVAL_COPY(z, v) \
do { \
ZVAL_COPY_VALUE(z, v); \
ZVAL_COPY_VALUE(property, value);
if (Z_REFCOUNT_P(value) > 0) {
zval_copy_ctor(property);
-//??? } else {
-//??? efree(value);
}
} else {
zval garbage;
}
/* copy: enforce read only access */
- ZVAL_DUP(&prop_copy, prop);
-//??? INIT_PZVAL(prop_copy);
+ ZVAL_DUP_DEREF(&prop_copy, prop);
/* this is necessary to make it able to work with default array
* properties, returned to user */
add_assoc_zval(return_value, module_names[module_number], &modules[module_number]);
}
- ZVAL_DUP(&const_val, &val->value);
-//??? INIT_PZVAL(const_val);
+ ZVAL_DUP_DEREF(&const_val, &val->value);
add_assoc_zval_ex(&modules[module_number], val->name->val, val->name->len, &const_val);
next_constant:
ptr = ptr->prev_execute_data;
while (ptr && (limit == 0 || frameno < limit)) {
-//??? const char *free_class_name = NULL;
-
frameno++;
class_name = NULL;
call_type = NULL;
include_filename = filename;
ptr = skip->prev_execute_data;
++indent;
-//??? if (free_class_name) {
-//??? efree((char*)free_class_name);
-//??? }
}
}
{
if (EG(prev_exception)) {
-//??? zval_ptr_dtor(&EG(prev_exception));
+ OBJ_RELEASE(EG(prev_exception));
EG(prev_exception) = NULL;
}
if (!EG(exception)) {
return;
}
-//??? zval_ptr_dtor(&EG(exception));
+ OBJ_RELEASE(EG(exception));
EG(exception) = NULL;
EG(current_execute_data)->opline = EG(opline_before_exception);
#if ZEND_DEBUG
value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC);
- ZVAL_DUP(return_value, value);
-//??? INIT_PZVAL(return_value);
+ ZVAL_DUP_DEREF(return_value, value);
}
/* }}} */
Obtain the string representation of the Exception object */
ZEND_METHOD(exception, __toString)
{
- zval message, file, line, *trace, *exception;
+ zval message, file, line, trace, *exception;
char *str, *prev_str;
int len = 0;
zend_fcall_info fci;
ZVAL_COPY_VALUE(&fci.function_name, &fname);
fci.symbol_table = NULL;
fci.object_ptr = exception;
-//??? fci.retval_ptr_ptr = &trace;
+ fci.retval = &trace;
fci.param_count = 0;
fci.params = NULL;
fci.no_separation = 1;
zend_call_function(&fci, NULL TSRMLS_CC);
-//??? if (Z_TYPE_P(trace) != IS_STRING) {
-//??? zval_ptr_dtor(&trace);
-//??? trace = NULL;
-//??? }
+ if (Z_TYPE(trace) != IS_STRING) {
+ zval_ptr_dtor(&trace);
+ ZVAL_UNDEF(&trace);
+ }
if (Z_STRLEN(message) > 0) {
len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s",
Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line),
- (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
+ (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
len ? "\n\nNext " : "", prev_str);
} else {
len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s",
Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line),
- (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
+ (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
len ? "\n\nNext " : "", prev_str);
}
efree(prev_str);
exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC);
-//??? if (trace) {
-//??? zval_ptr_dtor(&trace);
-//??? }
+ zval_ptr_dtor(&trace);
}
zval_dtor(&fname);
Z_DELREF_P(zval_ptr);
if (Z_REFCOUNT_P(zval_ptr) == 0) {
zval_internal_dtor(zval_ptr);
- } else if (Z_REFCOUNT_P(zval_ptr) == 1) {
+ } else if (Z_REFCOUNT_P(zval_ptr) == 1) {
//??? Z_UNSET_ISREF_P(zval_ptr);
- zend_reference *ref = Z_REF_P(zval_ptr);
- ZVAL_COPY_VALUE(zval_ptr, Z_REFVAL_P(zval_ptr));
- efree(ref);
+ if (Z_ISREF_P(zval_ptr)) {
+ zend_reference *ref = Z_REF_P(zval_ptr);
+ ZVAL_COPY_VALUE(zval_ptr, Z_REFVAL_P(zval_ptr));
+ efree(ref);
+ }
}
}
/* }}} */
zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
} else if ((Z_TYPE_P(p) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
int refcount;
-//??? zend_uchar is_ref;
+ zend_uchar is_ref;
SEPARATE_ZVAL_IF_NOT_REF(p);
char *actual = Z_STRVAL_P(p);
if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
+ int len;
+
zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
- Z_STRLEN_P(p) -= ((colon - Z_STRVAL_P(p)) + 1);
-//??? if (inline_change) {
- zend_string *tmp = STR_INIT(colon, Z_STRLEN_P(p), 0);
+ len = Z_STRLEN_P(p) - ((colon - Z_STRVAL_P(p)) + 1);
+ if (inline_change) {
+ zend_string *tmp = STR_INIT(colon + 1, len, 0);
STR_RELEASE(Z_STR_P(p));
Z_STR_P(p) = tmp;
-//??? } else {
+ } else {
//??? Z_STRVAL_P(p) = colon + 1;
-//??? }
+ Z_STR_P(p) = STR_INIT(colon + 1, len, 0);
+ }
} else {
- char *save = actual, *slash;
+ zend_string *save = Z_STR_P(p);
+ char *slash;
int actual_len = Z_STRLEN_P(p);
if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
actual = slash + 1;
--actual_len;
}
if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
- int fix_save = 0;
- if (save[0] == '\\') {
- save++;
- fix_save = 1;
+ if (save->val[0] == '\\') {
+ zend_error(E_ERROR, "Undefined constant '%s'", save->val + 1);
+ } else {
+ zend_error(E_ERROR, "Undefined constant '%s'", save->val);
}
- zend_error(E_ERROR, "Undefined constant '%s'", save);
- if (fix_save) {
- save--;
+ if (inline_change) {
+ STR_RELEASE(save);
}
-//??? if (inline_change) {
-//??? str_efree(save);
-//??? }
save = NULL;
}
-//??? if (inline_change && save && save != actual) {
-//??? str_efree(save);
-//??? }
+ if (inline_change && save && save->val != actual) {
+ STR_RELEASE(save);
+ }
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", actual, actual);
p->type = IS_STRING;
if (!inline_change) {
}
}
} else {
-//??? if (inline_change) {
-//??? str_efree(Z_STRVAL_P(p));
-//??? }
+ if (inline_change) {
+ STR_RELEASE(Z_STR_P(p));
+ }
*p = const_value;
}
}
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index);
}
- ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1);
+ ZVAL_STRINGL(&const_value, str_index, str_index_len-3);
}
#endif
if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
ZVAL_UNDEF(&EG(This));
} else {
- ZVAL_COPY_VALUE(&EG(This), fci->object_ptr);
-
- if (!Z_ISREF(EG(This))) {
- Z_ADDREF(EG(This)); /* For $this pointer */
- } else {
-//??? zval *this_ptr;
-//???
-//??? ALLOC_ZVAL(this_ptr);
-//??? *this_ptr = *EG(This);
-//??? INIT_PZVAL(this_ptr);
-//??? zval_copy_ctor(this_ptr);
-//??? EG(This) = this_ptr;
- }
+ ZVAL_COPY(&EG(This), fci->object_ptr);
}
} else {
ZVAL_UNDEF(&EG(This));
int i;
for (i = 0; i < old_object->ce->default_properties_count; i++) {
-//??? if (!new_object->properties) {
- zval_ptr_dtor(&new_object->properties_table[i]);
-//??? }
-//??? if (!old_object->properties) {
- ZVAL_COPY(&new_object->properties_table[i], &old_object->properties_table[i]);
-//??? }
+ zval_ptr_dtor(&new_object->properties_table[i]);
+ ZVAL_COPY(&new_object->properties_table[i], &old_object->properties_table[i]);
}
if (old_object->properties) {
if (!new_object->properties) {
(o) = (zend_object*)((((zend_uintptr_t)(n)) << 1) | FREE_BUCKET); \
} while (0)
+
+#define OBJ_RELEASE(obj) do { \
+ zend_object *_obj = (obj); \
+ if (--_obj->gc.refcount == 0) { \
+ zend_objects_store_del(_obj TSRMLS_CC); \
+ } \
+ } while (0)
+
typedef struct _zend_objects_store {
zend_object **object_buckets;
zend_uint top;
{
TSRMLS_FETCH();
- if (Z_DELREF_P(zvalue) == 0) {
- zend_objects_store_del(Z_OBJ_P(zvalue) TSRMLS_CC);
- }
+ OBJ_RELEASE(Z_OBJ_P(zvalue));
}
break;
case IS_RESOURCE:
varname = GET_OP1_ZVAL_PTR(BP_VAR_R);
if (OP1_TYPE != IS_CONST && UNEXPECTED(Z_TYPE_P(varname) != IS_STRING)) {
- ZVAL_DUP(&tmp_varname, varname);
-//??? Z_SET_REFCOUNT(tmp_varname, 1);
-//??? Z_UNSET_ISREF(tmp_varname);
+ ZVAL_DUP_DEREF(&tmp_varname, varname);
convert_to_string(&tmp_varname);
varname = &tmp_varname;
}