cvs: ZendEngine2 / zend_API.c zend_API.h

From: Date: Fri, 29 Aug 2003 23:27:23 +0000
Subject: cvs: ZendEngine2 / zend_API.c zend_API.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1739@lists.php.net to get a copy of this message
helly Fri Aug 29 19:27:23 2003 EDT Modified files: /ZendEngine2 zend_API.c zend_API.h Log: - Add zend_merge_properties() which is designed to serve *_fetch_object(). - Explain drawbacks of object_and_properties_init and zend_merge_properties. # # I guess we can live with the purity problem of potentially calling __set() # of an object which wasn't already ctored. # Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.211 ZendEngine2/zend_API.c:1.212 --- ZendEngine2/zend_API.c:1.211 Sun Aug 24 18:45:59 2003 +++ ZendEngine2/zend_API.c Fri Aug 29 19:27:22 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.211 2003/08/24 22:45:59 helly Exp $ */ +/* $Id: zend_API.c,v 1.212 2003/08/29 23:27:22 helly Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -655,6 +655,44 @@ } +static int zend_merge_property(zval **value, int num_args, va_list args, zend_hash_key *hash_key) +{ + /* which name should a numeric property have ? */ + if (hash_key->nKeyLength) { + zval *obj = va_arg(args, zval *); + zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *); + zval member; + TSRMLS_FETCH(); + + ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0); + obj_ht->write_property(obj, &member, *value TSRMLS_CC); + } + return ZEND_HASH_APPLY_KEEP; +} + + +/* This function should be called after the constructor has been called + * because it may call __set from the uninitialized object otherwise. */ +ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC) +{ + zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj); + zend_class_entry *old_scope = EG(scope); + + EG(scope) = Z_OBJCE_P(obj); + zend_hash_apply_with_arguments(properties, (apply_func_args_t)zend_merge_property, 2, obj, obj_ht); + EG(scope) = old_scope; + + if (destroy_ht) { + zend_hash_destroy(properties); + FREE_HASHTABLE(properties); + } +} + + +/* This function requires 'properties' to contain all props declared in the + * class and all props being public. If only a subset is given or the class + * has protected members then you need to merge the properties seperately by + * calling zend_merge_properties(). */ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC) { zval *tmp; Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.159 ZendEngine2/zend_API.h:1.160 --- ZendEngine2/zend_API.h:1.159 Sun Aug 24 13:32:47 2003 +++ ZendEngine2/zend_API.h Fri Aug 29 19:27:22 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.159 2003/08/24 17:32:47 helly Exp $ */ +/* $Id: zend_API.h,v 1.160 2003/08/29 23:27:22 helly Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -202,6 +202,8 @@ 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); + +ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC); /* no longer supported */ ZEND_API int add_assoc_function(zval *arg, char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));

« previous php.zend-engine.cvs (#1739) next »