From daf3ac65eaf1e47d915b4ae4c08f6cfa59deacc0 Mon Sep 17 00:00:00 2001 From: George Schlossnagle Date: Sun, 6 Jul 2003 19:55:20 +0000 Subject: [PATCH] add convenience functions or adding class properties. Ok'd for commit by Andi. --- Zend/zend_API.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ Zend/zend_API.h | 22 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 52e32af03d..213262fd35 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1576,6 +1576,51 @@ ZEND_API char *zend_get_module_version(char *module_name) 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 diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 5a6169ea1f..edccc9ae9b 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -256,6 +256,7 @@ ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length, 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) \ @@ -411,6 +412,27 @@ ZEND_API ZEND_FUNCTION(display_disabled_class); #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) -- 2.50.1