Skip to content

Commit 532677e

Browse files
author
Andi Gutmans
committed
- Fix some places which create objects. The fixes are ugly and will be
revised when things start working well
1 parent c0404f4 commit 532677e

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

Zend/zend_API.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,11 @@ ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_L
575575
class_type->constants_updated = 1;
576576
}
577577

578-
arg->value.obj = zend_objects_new(&object);
578+
arg->type = IS_OBJECT;
579+
arg->value.obj = zend_objects_new(&object, class_type);
579580

580-
ALLOC_HASHTABLE_REL(object->properties);
581-
zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
582581
zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
583-
object->ce = class_type;
584-
585-
arg->type = IS_OBJECT;
582+
586583
return SUCCESS;
587584
}
588585

Zend/zend_objects.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "zend.h"
22
#include "zend_globals.h"
3+
#include "zend_variables.h"
34

45
#define ZEND_DEBUG_OBJECTS 0
56

@@ -24,7 +25,7 @@ void zend_objects_destroy(zend_objects *objects)
2425
efree(objects->object_buckets);
2526
}
2627

27-
zend_object_value zend_objects_new(zend_object **object)
28+
zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type)
2829
{
2930
zend_object_handle handle;
3031
zend_object_value retval;
@@ -43,7 +44,14 @@ zend_object_value zend_objects_new(zend_object **object)
4344
}
4445
EG(objects).object_buckets[handle].valid = 1;
4546
EG(objects).object_buckets[handle].bucket.obj.refcount = 1;
47+
4648
*object = &EG(objects).object_buckets[handle].bucket.obj.object;
49+
50+
(*object)->ce = class_type;
51+
/* Try and change ALLOC_HASHTABLE to ALLOC_HASHTABLE_REL by also fixing this function's prototype */
52+
ALLOC_HASHTABLE((*object)->properties);
53+
zend_hash_init((*object)->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
54+
4755
retval.handle = handle;
4856
retval.handlers = zoh;
4957
#if ZEND_DEBUG_OBJECTS

Zend/zend_objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct _zend_objects {
2525

2626
void zend_objects_init(zend_objects *objects, zend_uint init_size);
2727
void zend_objects_destroy(zend_objects *objects);
28-
zend_object_value zend_objects_new(zend_object **object);
28+
zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type);
2929
zend_object *zend_objects_get_address(zend_object_handle handle);
3030
void zend_objects_add_ref(zend_object_handle handle);
3131
void zend_objects_del_ref(zend_object_handle handle);

Zend/zend_operators.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,14 @@ static void convert_scalar_to_array(zval *op, int type)
495495
zend_hash_index_update(op->value.ht, 0, (void *) &entry, sizeof(zval *), NULL);
496496
op->type = IS_ARRAY;
497497
break;
498-
/* OBJECTS_FIXME */
499498
case IS_OBJECT:
500-
ALLOC_HASHTABLE(Z_OBJPROP_P(op));
501-
zend_hash_init(Z_OBJPROP_P(op), 0, NULL, ZVAL_PTR_DTOR, 0);
502-
zend_hash_update(Z_OBJPROP_P(op), "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL);
503-
Z_OBJCE_P(op) = &zend_standard_class_def;
504-
Z_TYPE_P(op) = IS_OBJECT;
499+
{
500+
/* OBJECTS_OPTIMIZE */
501+
TSRMLS_FETCH();
502+
503+
object_init(op);
504+
zend_hash_update(Z_OBJPROP_P(op), "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL);
505+
}
505506
break;
506507
}
507508
}
@@ -533,22 +534,28 @@ ZEND_API void convert_to_array(zval *op)
533534
ZEND_API void convert_to_object(zval *op)
534535
{
535536
switch(op->type) {
536-
/* OBJECTS_FIXME */
537537
case IS_ARRAY:
538-
Z_TYPE_P(op) = IS_OBJECT;
539-
Z_OBJPROP_P(op) = op->value.ht;
540-
Z_OBJCE_P(op) = &zend_standard_class_def;
541-
return;
542-
break;
538+
{
539+
/* OBJECTS_OPTIMIZE */
540+
TSRMLS_FETCH();
541+
542+
object_init(op);
543+
zend_hash_destroy(Z_OBJPROP_P(op));
544+
FREE_HASHTABLE(Z_OBJPROP_P(op));
545+
Z_OBJPROP_P(op) = op->value.ht;
546+
return;
547+
break;
548+
}
543549
case IS_OBJECT:
544550
return;
545-
/* OBJECTS_FIXME */
546551
case IS_NULL:
547-
ALLOC_HASHTABLE(Z_OBJPROP_P(op));
548-
zend_hash_init(Z_OBJPROP_P(op), 0, NULL, ZVAL_PTR_DTOR, 0);
549-
Z_OBJCE_P(op) = &zend_standard_class_def;
550-
Z_TYPE_P(op) = IS_OBJECT;
551-
break;
552+
{
553+
/* OBJECTS_OPTIMIZE */
554+
TSRMLS_FETCH();
555+
556+
object_init(op);
557+
break;
558+
}
552559
default:
553560
convert_scalar_to_array(op, IS_OBJECT);
554561
break;

0 commit comments

Comments
 (0)