Skip to content

Commit 56f7eca

Browse files
author
Andi Gutmans
committed
- new operator fixes
1 parent 79b3d34 commit 56f7eca

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

Zend/zend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ typedef struct _zend_function_entry {
113113

114114
typedef struct _zend_property_reference {
115115
int type; /* read, write or r/w */
116-
zval **object;
116+
zval *object;
117117
zend_llist elements_list;
118118
} zend_property_reference;
119119

Zend/zend_execute.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ static inline zval *_get_zval_ptr(znode *node, temp_variable *Ts, int *should_fr
136136
return NULL;
137137
}
138138

139+
static inline zval *_get_object_zval_ptr(znode *node, temp_variable *Ts, int *should_free ELS_DC)
140+
{
141+
switch(node->op_type) {
142+
case IS_TMP_VAR:
143+
*should_free = 1;
144+
return &Ts[node->u.var].tmp_var;
145+
break;
146+
case IS_VAR:
147+
if (Ts[node->u.var].var) {
148+
PZVAL_UNLOCK(*Ts[node->u.var].var);
149+
*should_free = 0;
150+
return *Ts[node->u.var].var;
151+
} else {
152+
*should_free = 1;
153+
return NULL;
154+
}
155+
break;
156+
case IS_UNUSED:
157+
return NULL;
158+
break;
159+
#if DEBUG_ZEND
160+
default:
161+
zend_error(E_ERROR, "Unknown temporary variable type");
162+
break;
163+
#endif
164+
}
165+
return NULL;
166+
}
139167

140168
static inline zval **_get_zval_ptr_ptr(znode *node, temp_variable *Ts ELS_DC)
141169
{
@@ -720,7 +748,7 @@ static inline void zend_fetch_property_address(znode *result, znode *op1, znode
720748
zend_property_reference property_reference;
721749
zend_overloaded_element overloaded_element;
722750

723-
property_reference.object = container_ptr;
751+
property_reference.object = container;
724752
property_reference.type = type;
725753
zend_llist_init(&property_reference.elements_list, sizeof(zend_overloaded_element), NULL, 0);
726754
overloaded_element.element = *get_zval_ptr(op2, Ts, &free_op2, type);
@@ -791,7 +819,7 @@ static zval get_overloaded_property(ELS_D)
791819
zval result;
792820

793821
zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference);
794-
result = (*(property_reference->object))->value.obj.ce->handle_property_get(property_reference);
822+
result = (property_reference->object)->value.obj.ce->handle_property_get(property_reference);
795823

796824
zend_llist_destroy(&property_reference->elements_list);
797825

@@ -805,7 +833,7 @@ static void set_overloaded_property(zval *value ELS_DC)
805833
zend_property_reference *property_reference;
806834

807835
zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference);
808-
(*(property_reference->object))->value.obj.ce->handle_property_set(property_reference, value);
836+
(property_reference->object)->value.obj.ce->handle_property_set(property_reference, value);
809837

810838
zend_llist_destroy(&property_reference->elements_list);
811839

@@ -818,7 +846,7 @@ static void call_overloaded_function(int arg_count, zval *return_value, HashTabl
818846
zend_property_reference *property_reference;
819847

820848
zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference);
821-
(*(property_reference->object))->value.obj.ce->handle_function_call(arg_count, return_value, list, plist, *property_reference->object, property_reference);
849+
(property_reference->object)->value.obj.ce->handle_function_call(arg_count, return_value, list, plist, property_reference->object, property_reference);
822850
zend_llist_destroy(&property_reference->elements_list);
823851

824852
zend_stack_del_top(&EG(overloaded_objects_stack));
@@ -1297,7 +1325,7 @@ binary_assign_op_addr: {
12971325
object_ptr=NULL;
12981326
}
12991327
} else { /* used for member function calls */
1300-
object_ptr = get_zval_ptr(&opline->op1, Ts, &free_op1, BP_VAR_R);
1328+
object_ptr = _get_object_zval_ptr(&opline->op1, Ts, &free_op1, BP_VAR_R);
13011329

13021330

13031331
if (!object_ptr
@@ -1376,13 +1404,23 @@ binary_assign_op_addr: {
13761404
if (opline->opcode==ZEND_DO_FCALL_BY_NAME
13771405
&& object_ptr
13781406
&& function_being_called->type!=ZEND_OVERLOADED_FUNCTION) {
1379-
/*zval *dummy = (zval *) emalloc(sizeof(zval)), **this_ptr;
1407+
/*
1408+
zval *dummy = (zval *) emalloc(sizeof(zval)), **this_ptr;
13801409
13811410
var_uninit(dummy);
13821411
INIT_PZVAL(dummy);
13831412
zend_hash_update_ptr(function_state.function_symbol_table, "this", sizeof("this"), dummy, sizeof(zval *), (void **) &this_ptr);
13841413
zend_assign_to_variable_reference(NULL, this_ptr, object_ptr, NULL ELS_CC);
13851414
*/
1415+
//zval *dummy = (zval *) emalloc(sizeof(zval));
1416+
zval **this_ptr;
1417+
1418+
//var_uninit(dummy);
1419+
//INIT_PZVAL(dummy);
1420+
zend_hash_update_ptr(function_state.function_symbol_table, "this", sizeof("this"), NULL, sizeof(zval *), (void **) &this_ptr);
1421+
*this_ptr = object_ptr;
1422+
object_ptr->refcount++;
1423+
//zend_assign_to_variable_reference(NULL, this_ptr, object_ptr, NULL ELS_CC);
13861424
object_ptr = NULL;
13871425
}
13881426
original_return_value = EG(return_value);

0 commit comments

Comments
 (0)