Get rid of implicit type casting in GC_*() macros in Zend/zend_types.h.

This prevented compilation warnings and disclosed few incorrect usages in Zend/zend_vm_def.h and ext/dom/xpath.c.
Now explicit type casting may be required on call site.
This may break some C extension code, but it shoulfn't be a problem to add explicit casting.
This commit is contained in:
Dmitry Stogov 2015-08-13 13:56:29 +03:00
parent e5813fedf8
commit 715d5d2855
11 changed files with 84 additions and 60 deletions

View File

@ -843,8 +843,8 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
EG(scope) = func->common.scope;
call->symbol_table = fci->symbol_table;
if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
ZEND_ASSERT(GC_TYPE(func->op_array.prototype) == IS_OBJECT);
GC_REFCOUNT(func->op_array.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)func->op_array.prototype)++;
ZEND_ADD_CALL_FLAG(call, ZEND_CALL_CLOSURE);
}
if (EXPECTED((func->op_array.fn_flags & ZEND_ACC_GENERATOR) == 0)) {

View File

@ -469,7 +469,7 @@ void zend_generator_yield_from(zend_generator *generator, zend_generator *from)
generator->node.parent = from;
zend_generator_get_current(generator);
--GC_REFCOUNT(from);
--GC_REFCOUNT(&from->std);
}
ZEND_API zend_generator *zend_generator_get_current(zend_generator *generator)

View File

@ -81,7 +81,7 @@ ZEND_API void zend_iterator_init(zend_object_iterator *iter)
ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
{
if (--GC_REFCOUNT(iter) > 0) {
if (--GC_REFCOUNT(&iter->std) > 0) {
return;
}

View File

@ -77,7 +77,7 @@ static zend_always_inline void zend_object_release(zend_object *obj)
if (--GC_REFCOUNT(obj) == 0) {
zend_objects_store_del(obj);
} else if (UNEXPECTED(!GC_INFO(obj))) {
gc_possible_root(&obj->gc);
gc_possible_root((zend_refcounted*)obj);
}
}

View File

@ -140,7 +140,7 @@ struct _zval_struct {
} u2;
};
struct _zend_refcounted {
typedef struct _zend_refcounted_h {
uint32_t refcount; /* reference counter 32-bit */
union {
struct {
@ -151,10 +151,14 @@ struct _zend_refcounted {
} v;
uint32_t type_info;
} u;
} zend_refcounted_h;
struct _zend_refcounted {
zend_refcounted_h gc;
};
struct _zend_string {
zend_refcounted gc;
zend_refcounted_h gc;
zend_ulong h; /* hash value */
size_t len;
char val[1];
@ -169,7 +173,7 @@ typedef struct _Bucket {
typedef struct _zend_array HashTable;
struct _zend_array {
zend_refcounted gc;
zend_refcounted_h gc;
union {
struct {
ZEND_ENDIAN_LOHI_4(
@ -270,7 +274,7 @@ typedef struct _HashTableIterator {
} HashTableIterator;
struct _zend_object {
zend_refcounted gc;
zend_refcounted_h gc;
uint32_t handle; // TODO: may be removed ???
zend_class_entry *ce;
const zend_object_handlers *handlers;
@ -279,19 +283,19 @@ struct _zend_object {
};
struct _zend_resource {
zend_refcounted gc;
zend_refcounted_h gc;
int handle; // TODO: may be removed ???
int type;
void *ptr;
};
struct _zend_reference {
zend_refcounted gc;
zend_refcounted_h gc;
zval val;
};
struct _zend_ast_ref {
zend_refcounted gc;
zend_refcounted_h gc;
zend_ast *ast;
};
@ -365,11 +369,11 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define Z_TYPE_FLAGS_SHIFT 8
#define Z_CONST_FLAGS_SHIFT 16
#define GC_REFCOUNT(p) ((zend_refcounted*)(p))->refcount
#define GC_TYPE(p) ((zend_refcounted*)(p))->u.v.type
#define GC_FLAGS(p) ((zend_refcounted*)(p))->u.v.flags
#define GC_INFO(p) ((zend_refcounted*)(p))->u.v.gc_info
#define GC_TYPE_INFO(p) ((zend_refcounted*)(p))->u.type_info
#define GC_REFCOUNT(p) (p)->gc.refcount
#define GC_TYPE(p) (p)->gc.u.v.type
#define GC_FLAGS(p) (p)->gc.u.v.flags
#define GC_INFO(p) (p)->gc.u.v.gc_info
#define GC_TYPE_INFO(p) (p)->gc.u.type_info
#define Z_GC_TYPE(zval) GC_TYPE(Z_COUNTED(zval))
#define Z_GC_TYPE_P(zval_p) Z_GC_TYPE(*(zval_p))

View File

@ -3241,8 +3241,8 @@ ZEND_VM_C_LABEL(try_function_name):
Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &called_scope, &fbc, &object) == SUCCESS) {
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
/* Delay closure destruction until its invocation */
ZEND_ASSERT(GC_TYPE(fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT(fbc->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)fbc->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
} else if (object) {
call_info |= ZEND_CALL_RELEASE_THIS;
@ -3377,8 +3377,8 @@ ZEND_VM_HANDLER(118, ZEND_INIT_USER_CALL, CONST, CONST|TMPVAR|CV)
if (OP2_TYPE & (IS_VAR|IS_CV)) {
ZVAL_DEREF(function_name);
}
ZEND_ASSERT(GC_TYPE(func->common.prototype) == IS_OBJECT);
GC_REFCOUNT(func->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)func->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)func->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
}
called_scope = fcc.called_scope;
@ -6727,9 +6727,11 @@ ZEND_VM_HANDLER(152, ZEND_JMP_SET, CONST|TMP|VAR|CV, ANY)
} else if (OP1_TYPE == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (OP1_TYPE == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -6765,9 +6767,11 @@ ZEND_VM_HANDLER(169, ZEND_COALESCE, CONST|TMP|VAR|CV, ANY)
} else if (OP1_TYPE == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (OP1_TYPE == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));

View File

@ -2016,8 +2016,8 @@ try_function_name:
Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &called_scope, &fbc, &object) == SUCCESS) {
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
/* Delay closure destruction until its invocation */
ZEND_ASSERT(GC_TYPE(fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT(fbc->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)fbc->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
} else if (object) {
call_info |= ZEND_CALL_RELEASE_THIS;
@ -2438,8 +2438,8 @@ try_function_name:
Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &called_scope, &fbc, &object) == SUCCESS) {
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
/* Delay closure destruction until its invocation */
ZEND_ASSERT(GC_TYPE(fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT(fbc->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)fbc->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
} else if (object) {
call_info |= ZEND_CALL_RELEASE_THIS;
@ -2693,8 +2693,8 @@ try_function_name:
Z_OBJ_HANDLER_P(function_name, get_closure)(function_name, &called_scope, &fbc, &object) == SUCCESS) {
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
/* Delay closure destruction until its invocation */
ZEND_ASSERT(GC_TYPE(fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT(fbc->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)fbc->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)fbc->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
} else if (object) {
call_info |= ZEND_CALL_RELEASE_THIS;
@ -4011,9 +4011,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_SET_SPEC_CONST_HANDLER(ZEN
} else if (IS_CONST == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_CONST == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -4048,9 +4050,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COALESCE_SPEC_CONST_HANDLER(ZE
} else if (IS_CONST == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_CONST == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -5735,8 +5739,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_CONS
if (IS_CONST & (IS_VAR|IS_CV)) {
ZVAL_DEREF(function_name);
}
ZEND_ASSERT(GC_TYPE(func->common.prototype) == IS_OBJECT);
GC_REFCOUNT(func->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)func->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)func->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
}
called_scope = fcc.called_scope;
@ -9485,8 +9489,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_CV_H
if (IS_CV & (IS_VAR|IS_CV)) {
ZVAL_DEREF(function_name);
}
ZEND_ASSERT(GC_TYPE(func->common.prototype) == IS_OBJECT);
GC_REFCOUNT(func->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)func->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)func->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
}
called_scope = fcc.called_scope;
@ -11295,8 +11299,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_USER_CALL_SPEC_CONST_TMPV
if ((IS_TMP_VAR|IS_VAR) & (IS_VAR|IS_CV)) {
ZVAL_DEREF(function_name);
}
ZEND_ASSERT(GC_TYPE(func->common.prototype) == IS_OBJECT);
GC_REFCOUNT(func->common.prototype)++;
ZEND_ASSERT(GC_TYPE((zend_object*)func->common.prototype) == IS_OBJECT);
GC_REFCOUNT((zend_object*)func->common.prototype)++;
call_info |= ZEND_CALL_CLOSURE;
}
called_scope = fcc.called_scope;
@ -12371,9 +12375,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_SET_SPEC_TMP_HANDLER(ZEND_
} else if (IS_TMP_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_TMP_VAR == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -12409,9 +12415,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COALESCE_SPEC_TMP_HANDLER(ZEND
} else if (IS_TMP_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_TMP_VAR == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -16203,9 +16211,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_SET_SPEC_VAR_HANDLER(ZEND_
} else if (IS_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_VAR == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -16241,9 +16251,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COALESCE_SPEC_VAR_HANDLER(ZEND
} else if (IS_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_VAR == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -29412,9 +29424,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_SET_SPEC_CV_HANDLER(ZEND_O
} else if (IS_CV == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_CV == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
@ -29449,9 +29463,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COALESCE_SPEC_CV_HANDLER(ZEND_
} else if (IS_CV == IS_CV) {
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
} else if (IS_CV == IS_VAR && ref) {
zend_reference *r = Z_REF_P(ref);
if (Z_OPT_REFCOUNTED_P(value)) Z_ADDREF_P(value);
if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
efree_size(ref, sizeof(zend_reference));
if (UNEXPECTED(--GC_REFCOUNT(r) == 0)) {
efree_size(r, sizeof(zend_reference));
}
}
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));

View File

@ -209,7 +209,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
ALLOC_HASHTABLE(intern->node_list);
zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0);
}
GC_REFCOUNT(&retval)++;
Z_ADDREF(retval);
zend_hash_next_index_insert(intern->node_list, &retval);
obj = Z_DOMOBJ_P(&retval);
nodep = dom_object_get_node(obj);

View File

@ -183,7 +183,7 @@ static zend_object_iterator *IntlIterator_get_iterator(
return NULL;
}
++GC_REFCOUNT(ii->iterator);
++GC_REFCOUNT(&ii->iterator->std);
return ii->iterator;
}

View File

@ -2314,7 +2314,7 @@ ZEND_METHOD(reflection_generator, getExecutingGenerator)
REFLECTION_CHECK_VALID_GENERATOR(ex)
current = zend_generator_get_current(generator);
++GC_REFCOUNT(current);
++GC_REFCOUNT(&current->std);
ZVAL_OBJ(return_value, (zend_object *) current);
}

View File

@ -185,7 +185,7 @@ static phpdbg_watchpoint_t *phpdbg_create_refcounted_watchpoint(phpdbg_watchpoin
watch->parent = parent;
watch->str = parent->str;
++GC_REFCOUNT(parent->str);
phpdbg_create_addr_watchpoint(&ref->refcount, sizeof(uint32_t), watch);
phpdbg_create_addr_watchpoint(&GC_REFCOUNT(ref), sizeof(uint32_t), watch);
watch->type = WATCH_ON_REFCOUNTED;
return watch;
@ -1047,7 +1047,7 @@ static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump) {
}
if (Z_REFCOUNTED_P(watch->addr.zv)) {
if ((watch->flags & PHPDBG_WATCH_NORMAL) && (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS)) {
phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", Z_COUNTED_P(watch->addr.zv)->refcount);
phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", Z_REFCOUNT_P(watch->addr.zv));
}
if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
phpdbg_create_recursive_watchpoint(watch);
@ -1079,8 +1079,8 @@ static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump) {
break;
case WATCH_ON_REFCOUNTED: {
if ((watch->flags & PHPDBG_WATCH_NORMAL) && (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS)) {
phpdbg_writeln("watchrefcount", "type=\"old\" refcount=\"%d\"", "Old refcount: %d", ((zend_refcounted *) oldPtr)->refcount);
phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", watch->addr.ref->refcount);
phpdbg_writeln("watchrefcount", "type=\"old\" refcount=\"%d\"", "Old refcount: %d", GC_REFCOUNT((zend_refcounted *) oldPtr));
phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", GC_REFCOUNT(watch->addr.ref));
}
break;
}