Browse files

added get_class_entry callback handler to the

object handlers structure
  • Loading branch information...
1 parent 6c491a5 commit 6ac6cb1040c6ccf1157cf8d8384be1cb074c9281 Harald Radi committed Apr 22, 2002
Showing with 56 additions and 44 deletions.
  1. +21 −6 Zend/zend_API.c
  2. +2 −0 Zend/zend_API.h
  3. +18 −4 Zend/zend_builtin_functions.c
  4. +12 −31 Zend/zend_object_handlers.c
  5. +2 −0 Zend/zend_object_handlers.h
  6. +0 −2 Zend/zend_objects.h
  7. +1 −1 Zend/zend_operators.h
View
27 Zend/zend_API.c
@@ -198,6 +198,25 @@ ZEND_API char *zend_zval_type_name(zval *arg)
}
}
+ZEND_API zend_class_entry **zend_get_class_entry(zval *zobject)
+{
+ zend_class_entry **ce;
+
+ if (Z_OBJ_HT_P(zobject)->get_class_entry) {
+ TSRMLS_FETCH();
+ ce = Z_OBJ_HT_P(zobject)->get_class_entry(zobject TSRMLS_CC);
+ } else {
+ if(!IS_ZEND_STD_OBJECT(*zobject)) {
+ zend_error(E_ERROR, "Class entry required for an object without class");
+ return NULL;
+ }
+
+ ce = &(Z_OBJ_P(zobject)->ce);
+ }
+
+ return ce;
+}
+
static int zend_check_class(zval *obj, zend_class_entry *expected_ce)
{
zend_class_entry *ce;
@@ -206,16 +225,12 @@ static int zend_check_class(zval *obj, zend_class_entry *expected_ce)
return 0;
}
- /* TBI!! new object handlers */
- if(!IS_ZEND_STD_OBJECT(*obj)) {
- return 0;
- }
-
for (ce = Z_OBJCE_P(obj); ce != NULL; ce = ce->parent) {
if (ce == expected_ce) {
return 1;
}
}
+
return 0;
}
@@ -402,7 +417,7 @@ static char *zend_parse_arg_impl(zval **arg, va_list *va, char **spec)
{
zval **p = va_arg(*va, zval **);
zend_class_entry *ce = va_arg(*va, zend_class_entry *);
- if (Z_TYPE_PP(arg) != IS_OBJECT || !zend_check_class(*arg, ce)) {
+ if (!zend_check_class(*arg, ce)) {
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
*p = NULL;
} else {
View
2 Zend/zend_API.h
@@ -148,6 +148,8 @@ 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 zend_class_entry **zend_get_class_entry(zval *zobject);
+
#define getThis() (this_ptr)
#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
View
22 Zend/zend_builtin_functions.c
@@ -501,9 +501,16 @@ ZEND_FUNCTION(get_class)
RETURN_FALSE;
}
- if(Z_OBJ_HT_PP(arg)->get_class_name == NULL ||
+ if (Z_OBJ_HT_PP(arg)->get_class_name == NULL ||
Z_OBJ_HT_PP(arg)->get_class_name(*arg, &name, &name_len, 0 TSRMLS_CC) != SUCCESS) {
- RETURN_FALSE;
+ zend_class_entry *ce, **_ce;
+
+ if (((_ce = zend_get_class_entry(*arg)) == NULL) || ((ce = *_ce) == NULL)) {
+ RETURN_FALSE;
+ }
+
+ name = ce->name;
+ name_len = ce->name_length;
}
RETURN_STRINGL(name, name_len, 1);
@@ -526,9 +533,16 @@ ZEND_FUNCTION(get_parent_class)
char *name;
zend_uint name_length;
- if(Z_OBJ_HT_PP(arg)->get_class_name == NULL ||
+ if (Z_OBJ_HT_PP(arg)->get_class_name == NULL ||
Z_OBJ_HT_PP(arg)->get_class_name(*arg, &name, &name_length, 1 TSRMLS_CC) != SUCCESS) {
- RETURN_FALSE;
+ zend_class_entry *ce, **_ce;
+
+ if (!(_ce = zend_get_class_entry(*arg)) || !(ce = *_ce) || !(ce = ce->parent)) {
+ RETURN_FALSE;
+ }
+
+ name = ce->name;
+ name_length = ce->name_length;
}
RETURN_STRINGL(name, name_length, 1);
} else if (Z_TYPE_PP(arg) == IS_STRING) {
View
43 Zend/zend_object_handlers.c
@@ -10,7 +10,7 @@
static HashTable *zend_std_get_properties(zval *object TSRMLS_DC)
{
zend_object *zobj;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
return zobj->properties;
}
@@ -20,7 +20,7 @@ zval *zend_std_read_property(zval *object, zval *member, int type TSRMLS_DC)
zval tmp_member;
zval **retval;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
@@ -67,7 +67,7 @@ static void zend_std_write_property(zval *object, zval *member, zval *value TSRM
zval tmp_member;
zval **variable_ptr;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
@@ -102,7 +102,7 @@ static zval **zend_std_get_property_ptr(zval *object, zval *member TSRMLS_DC)
zval tmp_member;
zval **retval;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
@@ -133,7 +133,7 @@ static void zend_std_unset_property(zval *object, zval *member TSRMLS_DC)
zend_object *zobj;
zval tmp_member;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
@@ -152,7 +152,7 @@ static union _zend_function *zend_std_get_method(zval *object, char *method_name
zend_object *zobj;
zend_function *func_method;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if(zend_hash_find(&zobj->ce->function_table, method_name, method_len+1, (void **)&func_method) == FAILURE) {
zend_error(E_ERROR, "Call to undefined function %s()", method_name);
}
@@ -164,38 +164,18 @@ static union _zend_function *zend_std_get_constructor(zval *object TSRMLS_DC)
{
zend_object *zobj;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
return zobj->ce->constructor;
}
-static int zend_std_get_class(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC)
-{
- zend_object *zobj;
- zend_class_entry *ce;
-
- zobj = Z_GET_OBJ(object);
- if(parent) {
- ce = zobj->ce->parent;
- } else {
- ce = zobj->ce;
- }
- if(!ce) {
- return FAILURE;
- }
-
- *class_name = zobj->ce->name;
- *class_name_len = zobj->ce->name_length;
- return SUCCESS;
-}
-
int zend_compare_symbol_tables_i(HashTable *ht1, HashTable *ht2 TSRMLS_DC);
static int zend_std_compare_objects(zval *o1, zval *o2 TSRMLS_DC)
{
zend_object *zobj1, *zobj2;
- zobj1 = Z_GET_OBJ(o1);
- zobj2 = Z_GET_OBJ(o2);
+ zobj1 = Z_OBJ_P(o1);
+ zobj2 = Z_OBJ_P(o2);
if(zobj1->ce != zobj2->ce) {
return 1; /* different classes */
@@ -210,7 +190,7 @@ static int zend_std_has_property(zval *object, zval *member, int check_empty TSR
zval **value;
zval tmp_member;
- zobj = Z_GET_OBJ(object);
+ zobj = Z_OBJ_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
@@ -253,7 +233,8 @@ zend_object_handlers std_object_handlers = {
zend_std_get_method, /* get_method */
NULL, /* call_method */
zend_std_get_constructor, /* get_constructor */
- zend_std_get_class, /* get_class */
+ NULL, /* get_class_entry */
+ NULL, /* get_class */
zend_std_compare_objects /* compare_objects */
};
View
2 Zend/zend_object_handlers.h
@@ -43,6 +43,7 @@ typedef void (*zend_object_del_ref_t)(zval *object TSRMLS_DC);
typedef void (*zend_object_delete_obj_t)(zval *object TSRMLS_DC);
typedef zend_object_value (*zend_object_clone_obj_t)(zval *object TSRMLS_DC);
+typedef zend_class_entry **(*zend_object_get_class_entry_t)(zval *object TSRMLS_DC);
typedef int (*zend_object_get_class_name_t)(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC);
typedef int (*zend_object_compare_t)(zval *object1, zval *object2 TSRMLS_DC);
@@ -65,6 +66,7 @@ typedef struct _zend_object_handlers {
zend_object_get_method_t get_method;
zend_object_call_method_t call_method;
zend_object_get_constructor_t get_constructor;
+ zend_object_get_class_entry_t get_class_entry;
zend_object_get_class_name_t get_class_name;
zend_object_compare_t compare_objects;
} zend_object_handlers;
View
2 Zend/zend_objects.h
@@ -36,6 +36,4 @@ void zend_objects_del_ref(zval *object TSRMLS_DC);
void zend_objects_delete_obj(zval *object TSRMLS_DC);
zend_object_value zend_objects_clone_obj(zval *object TSRMLS_DC);
-#define Z_GET_OBJ(object_zval) zend_objects_get_address(object_zval)
-
#endif /* ZEND_OBJECTS_H */
View
2 Zend/zend_operators.h
@@ -235,8 +235,8 @@ ZEND_API int zend_atoi(const char *str, int str_len);
#define Z_OBJ_HANDLE(zval) (zval).value.obj.handle
#define Z_OBJ_HT(zval) (zval).value.obj.handlers
#define Z_OBJ(zval) zend_objects_get_address(&(zval))
+#define Z_OBJCE(zval) (*zend_get_class_entry(&(zval)))
#define Z_OBJPROP(zval) Z_OBJ(zval)->properties
-#define Z_OBJCE(zval) Z_OBJ(zval)->ce
#define Z_RESVAL(zval) (zval).value.lval
#define Z_LVAL_P(zval_p) Z_LVAL(*zval_p)

0 comments on commit 6ac6cb1

Please sign in to comment.