Permalink
Browse files

Rework zend_do_declare_property and related code into one code base

  • Loading branch information...
1 parent 376c7a1 commit 134338522f524b84d8ee43bdd457486a15d5128a @zsuraski zsuraski committed Jul 7, 2003
Showing with 51 additions and 92 deletions.
  1. +31 −27 Zend/zend_API.c
  2. +17 −16 Zend/zend_API.h
  3. +2 −49 Zend/zend_compile.c
  4. +1 −0 Zend/zend_compile.h
View
@@ -1565,6 +1565,7 @@ zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callabl
return retval;
}
+
ZEND_API char *zend_get_module_version(char *module_name)
{
zend_module_entry *module;
@@ -1576,7 +1577,8 @@ 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_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type)
{
zend_property_info property_info;
HashTable *target_symbol_table;
@@ -1590,36 +1592,38 @@ ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namele
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+1, &property, sizeof(zval *), NULL);
- property_info.name = estrdup(name);
- property_info.name_length = namelen;
- break;
+ 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, name_length);
+ 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, name_length);
+ 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, name_length+1, &property, sizeof(zval *), NULL);
+ property_info.name = estrndup(name, name_length);
+ property_info.name_length = name_length;
+ 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);
+ zend_hash_update(&ce->properties_info, name, name_length + 1, &property_info, sizeof(zend_property_info), NULL);
+
+ return SUCCESS;
}
/*
* Local variables:
View
@@ -144,6 +144,8 @@ ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_
ZEND_API void zend_wrong_param_count(TSRMLS_D);
ZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callable_name);
ZEND_API char *zend_get_module_version(char *module_name);
+ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type);
+
ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC);
@@ -256,7 +258,6 @@ 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) \
@@ -412,25 +413,25 @@ ZEND_API void zend_declare_property(zend_class_entry *ce, char *name, int namele
#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_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_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 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)))
View
@@ -2384,10 +2384,7 @@ void unmangle_property_name(char *mangled_property, char **class_name, char **pr
void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_type TSRMLS_DC)
{
zval *property;
- zend_property_info property_info;
zend_property_info *existing_property_info;
- HashTable *target_symbol_table;
- zend_bool free_var_name = 0;
if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
zend_error(E_COMPILE_ERROR, "Interfaces may not include member variables");
@@ -2402,10 +2399,6 @@ void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_ty
CG(active_class_entry)->name, var_name->u.constant.value.str.val);
}
- if (!(access_type & ZEND_ACC_PPP_MASK)) {
- access_type |= ZEND_ACC_PUBLIC;
- }
-
if (zend_hash_find(&CG(active_class_entry)->properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, (void **) &existing_property_info)==SUCCESS) {
if (!(existing_property_info->flags & ZEND_ACC_IMPLICIT_PUBLIC)) {
zend_error(E_COMPILE_ERROR, "Cannot redeclare %s::$%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val);
@@ -2420,48 +2413,8 @@ void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_ty
property->type = IS_NULL;
}
- if (access_type & ZEND_ACC_STATIC) {
- target_symbol_table = CG(active_class_entry)->static_members;
- } else {
- target_symbol_table = &CG(active_class_entry)->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, CG(active_class_entry)->name, CG(active_class_entry)->name_length, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len);
- free_var_name = 1;
- 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, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len);
- free_var_name = 1;
- 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, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
- property_info.name = var_name->u.constant.value.str.val;
- property_info.name_length = var_name->u.constant.value.str.len;
- break;
- }
- property_info.flags = access_type;
- property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
-
- zend_hash_update(&CG(active_class_entry)->properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property_info, sizeof(zend_property_info), NULL);
- if (free_var_name) {
- efree(var_name->u.constant.value.str.val);
- }
+ zend_declare_property(CG(active_class_entry), var_name->u.constant.value.str.val, var_name->u.constant.value.str.len, property, access_type);
+ efree(var_name->u.constant.value.str.val);
}
View
@@ -457,6 +457,7 @@ ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
ZEND_API void destroy_zend_class(zend_class_entry **pce);
void zend_class_add_ref(zend_class_entry **ce);
+void mangle_property_name(char **dest, int *dest_length, char *src1, int src1_length, char *src2, int src2_length);
void unmangle_property_name(char *mangled_property, char **prop_name, char **class_name);
void zend_duplicate_property_info(zend_property_info *property_info);
void zend_destroy_property_info(zend_property_info *property_info);

0 comments on commit 1343385

Please sign in to comment.