Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- More work on making objects work

  • Loading branch information...
commit 76a7a5bc18deadd5d4aa4e9cc3fdd72bcd54b764 1 parent 532677e
@andigutmans andigutmans authored
View
15 Zend/zend_API.c
@@ -565,7 +565,7 @@ ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC)
}
-ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC TSRMLS_DC)
+ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC)
{
zval *tmp;
zend_object *object;
@@ -578,11 +578,20 @@ ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_L
arg->type = IS_OBJECT;
arg->value.obj = zend_objects_new(&object, class_type);
- zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
-
+ if (properties) {
+ object->properties = properties;
+ } else {
+ ALLOC_HASHTABLE_REL(object->properties);
+ zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+ }
return SUCCESS;
}
+ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC TSRMLS_DC)
+{
+ return _object_and_properties_init(arg, class_type, 0 ZEND_FILE_LINE_CC TSRMLS_CC);
+}
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC)
{
View
2  Zend/zend_API.h
@@ -156,9 +156,11 @@ ZEND_API int zend_startup_module(zend_module_entry *module);
#define array_init(arg) _array_init((arg) ZEND_FILE_LINE_CC)
#define object_init(arg) _object_init((arg) ZEND_FILE_LINE_CC TSRMLS_CC)
#define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC TSRMLS_CC)
+#define object_and_properties_init(arg, ce, properties) _object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC TSRMLS_CC)
ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC);
ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC TSRMLS_DC);
+ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC);
/* no longer supported */
ZEND_API int add_assoc_function(zval *arg, char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
View
3  Zend/zend_objects.c
@@ -48,9 +48,6 @@ zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class
*object = &EG(objects).object_buckets[handle].bucket.obj.object;
(*object)->ce = class_type;
- /* Try and change ALLOC_HASHTABLE to ALLOC_HASHTABLE_REL by also fixing this function's prototype */
- ALLOC_HASHTABLE((*object)->properties);
- zend_hash_init((*object)->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
retval.handle = handle;
retval.handlers = zoh;
View
5 Zend/zend_operators.c
@@ -539,10 +539,7 @@ ZEND_API void convert_to_object(zval *op)
/* OBJECTS_OPTIMIZE */
TSRMLS_FETCH();
- object_init(op);
- zend_hash_destroy(Z_OBJPROP_P(op));
- FREE_HASHTABLE(Z_OBJPROP_P(op));
- Z_OBJPROP_P(op) = op->value.ht;
+ object_and_properties_init(op, &zend_standard_class_def, op->value.ht);
return;
break;
}

0 comments on commit 76a7a5b

Please sign in to comment.
Something went wrong with that request. Please try again.