cvs: ZendEngine2 / zend_API.c zend_API.h

From: Date: Sun, 06 Jul 2003 19:55:20 +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-1461@lists.php.net to get a copy of this message
gschlossnagle Sun Jul 6 15:55:20 2003 EDT Modified files: /ZendEngine2 zend_API.c zend_API.h Log: add convenience functions or adding class properties. Ok'd for commit by Andi. Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.179 ZendEngine2/zend_API.c:1.180 --- ZendEngine2/zend_API.c:1.179 Thu Jul 3 05:18:40 2003 +++ ZendEngine2/zend_API.c Sun Jul 6 15:55:20 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.179 2003/07/03 09:18:40 stas Exp $ */ +/* $Id: zend_API.c,v 1.180 2003/07/06 19:55:20 gschlossnagle Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -1576,6 +1576,51 @@ return module->version; } +ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namelen, zval *property, int access_type) +{ + zend_property_info property_info; + HashTable *target_symbol_table; + + if (!(access_type & ZEND_ACC_PPP_MASK)) { + access_type |= ZEND_ACC_PUBLIC; + } + if (access_type & ZEND_ACC_STATIC) { + target_symbol_table = ce->static_members; + } else { + target_symbol_table = &ce->default_properties; + } + switch (access_type & ZEND_ACC_PPP_MASK) { + case ZEND_ACC_PRIVATE: { + char *priv_name; + int priv_name_length; + + mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, namelen); + zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL); + property_info.name = priv_name; + property_info.name_length = priv_name_length; + } + break; + case ZEND_ACC_PROTECTED: { + char *prot_name; + int prot_name_length; + + mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, namelen); + zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL); + property_info.name = prot_name; + property_info.name_length = prot_name_length; + } + break; + case ZEND_ACC_PUBLIC: + zend_hash_update(target_symbol_table, name, namelen, &property, sizeof(zval *), NULL); + property_info.name = estrdup(name); + property_info.name_length = namelen; + break; + } + property_info.flags = access_type; + property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1); + + zend_hash_update(&ce->properties_info, name, namelen + 1, &property_info, sizeof(zend_property_info), NULL); +} /* * Local variables: * tab-width: 4 Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.144 ZendEngine2/zend_API.h:1.145 --- ZendEngine2/zend_API.h:1.144 Tue Jun 10 16:03:24 2003 +++ ZendEngine2/zend_API.h Sun Jul 6 15:55:20 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.144 2003/06/10 20:03:24 imajes Exp $ */ +/* $Id: zend_API.h,v 1.145 2003/07/06 19:55:20 gschlossnagle Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -256,6 +256,7 @@ ZEND_API ZEND_FUNCTION(display_disabled_function); ZEND_API ZEND_FUNCTION(display_disabled_class); +ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namelen, zval *property, int access_type); #if ZEND_DEBUG #define CHECK_ZVAL_STRING(z) \ @@ -410,6 +411,27 @@ #define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref) \ ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref) + +#define ZEND_PRIVATE_PROPERTY(class_ptr, name, value) \ +{ \ + char *_name = (name); \ + int namelen = strlen(_name); \ + zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PRIVATE); \ +} + +#define ZEND_PROTECTED_PROPERTY(class_ptr, name, value) \ +{ \ + char *_name = (name); \ + int namelen = strlen(_name); \ + zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PROTECTED); \ +} + +#define ZEND_PUBLIC_PROPERTY(class_ptr, name, value) \ +{ \ + char *_name = (name); \ + int namelen = strlen(_name); \ + zend_declare_property(class_ptr, _name, namelen, value, ZEND_ACC_PUBLIC); \ +} #define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p) TSRMLS_CC) : NULL))) #define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)

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