]> granicus.if.org Git - php/commitdiff
Improve register_resource_ex() infrastructure
authorZeev Suraski <zeev@php.net>
Fri, 14 Jul 2000 20:00:24 +0000 (20:00 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 14 Jul 2000 20:00:24 +0000 (20:00 +0000)
Zend/zend_builtin_functions.c
Zend/zend_list.c
Zend/zend_list.h

index a4ff6ad6c7b5fc070dd300ce634950d0ce8d7c8a..5ffa1311fcf386295b014b83e1670a90deeac460 100644 (file)
@@ -57,6 +57,7 @@ static ZEND_FUNCTION(set_error_handler);
 static ZEND_FUNCTION(restore_error_handler);
 static ZEND_FUNCTION(get_declared_classes);
 static ZEND_FUNCTION(create_function);
+static ZEND_FUNCTION(get_resource_type);
 #if ZEND_DEBUG
 static ZEND_FUNCTION(zend_test_func);
 #endif
@@ -219,7 +220,7 @@ ZEND_FUNCTION(strlen)
        zval **str;
        
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(str);
        RETVAL_LONG((*str)->value.str.len);
@@ -233,7 +234,7 @@ ZEND_FUNCTION(strcmp)
        zval **s1, **s2;
        
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(s1);
        convert_to_string_ex(s2);
@@ -248,7 +249,7 @@ ZEND_FUNCTION(strncmp)
        zval **s1, **s2, **s3;
        
        if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(s1);
        convert_to_string_ex(s2);
@@ -264,7 +265,7 @@ ZEND_FUNCTION(strcasecmp)
        zval **s1, **s2;
        
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(s1);
        convert_to_string_ex(s2);
@@ -281,7 +282,7 @@ ZEND_FUNCTION(each)
        HashTable *target_hash;
        
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        target_hash = HASH_OF(*array);
        if (!target_hash) {
@@ -339,7 +340,7 @@ ZEND_FUNCTION(error_reporting)
                        EG(error_reporting)=(*arg)->value.lval;
                        break;
                default:
-                       WRONG_PARAM_COUNT;
+                       ZEND_WRONG_PARAM_COUNT();
                        break;
        }
 
@@ -371,7 +372,7 @@ ZEND_FUNCTION(define)
                        }
                        break;
                default:
-                       WRONG_PARAM_COUNT;
+                       ZEND_WRONG_PARAM_COUNT();
                        break;
        }
        switch((*val)->type) {
@@ -405,7 +406,7 @@ ZEND_FUNCTION(defined)
        zval c;
                
        if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &var)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        
        convert_to_string_ex(var);
@@ -424,7 +425,7 @@ ZEND_FUNCTION(get_class)
        zval **arg;
        
        if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        if ((*arg)->type != IS_OBJECT) {
                RETURN_FALSE;
@@ -440,7 +441,7 @@ ZEND_FUNCTION(get_parent_class)
        zval **arg;
        
        if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        if (((*arg)->type != IS_OBJECT) || !(*arg)->value.obj.ce->parent) {
                RETURN_FALSE;
@@ -458,7 +459,7 @@ ZEND_FUNCTION(is_subclass_of)
        zend_class_entry *parent_ce = NULL;
 
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &obj, &class_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        if ((*obj)->type != IS_OBJECT) {
@@ -491,7 +492,7 @@ ZEND_FUNCTION(get_class_vars)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        convert_to_string_ex(class_name);
@@ -517,7 +518,7 @@ ZEND_FUNCTION(get_object_vars)
        zval *tmp;
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &obj) == FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        if ((*obj)->type != IS_OBJECT) {
@@ -544,7 +545,7 @@ ZEND_FUNCTION(get_class_methods)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        convert_to_string_ex(class_name);
@@ -578,7 +579,7 @@ ZEND_FUNCTION(method_exists)
        char *lcname;
        
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &klass, &method_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        if ((*klass)->type != IS_OBJECT) {
                RETURN_FALSE;
@@ -605,7 +606,7 @@ ZEND_FUNCTION(class_exists)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(class_name);
        lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
@@ -629,7 +630,7 @@ ZEND_FUNCTION(function_exists)
        int retval;
        
        if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &function_name)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
        convert_to_string_ex(function_name);
        lcname = estrndup((*function_name)->value.str.val, (*function_name)->value.str.len);
@@ -696,7 +697,7 @@ ZEND_FUNCTION(get_required_files)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS() != 0) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        array_init(return_value);
@@ -710,7 +711,7 @@ ZEND_FUNCTION(get_required_files)
 ZEND_FUNCTION(get_included_files)
 {
        if (ZEND_NUM_ARGS() != 0) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        array_init(return_value);
@@ -827,7 +828,7 @@ ZEND_FUNCTION(get_declared_classes)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS() != 0) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        array_init(return_value);
@@ -849,7 +850,7 @@ ZEND_FUNCTION(create_function)
        CLS_FETCH();
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &z_function_args, &z_function_code)==FAILURE) {
-               WRONG_PARAM_COUNT;
+               ZEND_WRONG_PARAM_COUNT();
        }
 
        convert_to_string_ex(z_function_args);
@@ -897,3 +898,26 @@ ZEND_FUNCTION(zend_test_func)
 
        zend_get_parameters(ht, 2, &arg1, &arg2);
 }
+
+
+ZEND_FUNCTION(get_resource_type)
+{
+       char *resource_type;
+       zval **z_resource_type;
+
+       if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &z_resource_type)==FAILURE) {
+               ZEND_WRONG_PARAM_COUNT();
+       }
+
+       if (Z_TYPE_PP(z_resource_type) != IS_RESOURCE) {
+               zend_error(E_WARNING, "Supplied argument is not a valid resource handle");
+               RETURN_FALSE;
+       }
+
+       resource_type = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(z_resource_type));
+       if (resource_type) {
+               RETURN_STRING(resource_type, 1);
+       } else {
+               RETURN_STRING("Unknown", 1);
+       }
+}
index 88410a9891895d49e767efbb766833fb13a894c1..9b16e8c0a1381f56cfbbba444c7ba702e267fc6f 100644 (file)
@@ -349,6 +349,7 @@ ZEND_API int zend_register_list_destructors(void (*ld)(void *), void (*pld)(void
        lde.module_number = module_number;
        lde.resource_id = list_destructors.nNextFreeElement;
        lde.type = ZEND_RESOURCE_LIST_TYPE_STD;
+       lde.type_name = NULL;
        
        if (zend_hash_next_index_insert(&list_destructors, (void *) &lde, sizeof(zend_rsrc_list_dtors_entry), NULL)==FAILURE) {
                return FAILURE;
@@ -357,7 +358,7 @@ ZEND_API int zend_register_list_destructors(void (*ld)(void *), void (*pld)(void
 }
 
 
-ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, int module_number)
+ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, char *type_name, int module_number)
 {
        zend_rsrc_list_dtors_entry lde;
        
@@ -372,6 +373,7 @@ ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_fu
        lde.module_number = module_number;
        lde.resource_id = list_destructors.nNextFreeElement;
        lde.type = ZEND_RESOURCE_LIST_TYPE_EX;
+       lde.type_name = type_name;
        
        if (zend_hash_next_index_insert(&list_destructors,(void *) &lde, sizeof(zend_rsrc_list_dtors_entry),NULL)==FAILURE) {
                return FAILURE;
@@ -392,6 +394,18 @@ void zend_destroy_rsrc_list_dtors()
 }
 
 
+char *zend_rsrc_list_get_rsrc_type(int resource)
+{
+       zend_rsrc_list_dtors_entry *lde;
+
+       if (zend_hash_index_find(&list_destructors, resource, (void **) &lde)==SUCCESS) {
+               return lde->type_name;
+       } else {
+               return NULL;
+       }
+}
+
+
 /*
  * Local variables:
  * tab-width: 4
index 10006265db53987b8a5baa4cc346b679fba99d06..6e92b014f5517d4ec446cbb7ff54d530f724fc97 100644 (file)
@@ -35,7 +35,8 @@ typedef struct _zend_rsrc_list_entry {
        zend_bool valid;
 } zend_rsrc_list_entry;
 
-typedef void (*rsrc_dtor_func_t)(zend_rsrc_list_entry *le);
+typedef void (*rsrc_dtor_func_t)(zend_rsrc_list_entry *rsrc);
+#define ZEND_RSRC_DTOR_FUNC(name)              void name(zend_rsrc_list_entry *rsrc)
 
 typedef struct _zend_rsrc_list_dtors_entry {
        /* old style destructors */
@@ -46,6 +47,8 @@ typedef struct _zend_rsrc_list_dtors_entry {
        rsrc_dtor_func_t list_dtor_ex;
        rsrc_dtor_func_t plist_dtor_ex;
 
+       char *type_name;
+
        int module_number;
        int resource_id;
        unsigned char type;
@@ -54,7 +57,7 @@ typedef struct _zend_rsrc_list_dtors_entry {
 
 #define register_list_destructors(ld, pld) zend_register_list_destructors((void (*)(void *))ld, (void (*)(void *))pld, module_number);
 ZEND_API int zend_register_list_destructors(void (*ld)(void *), void (*pld)(void *), int module_number);
-ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, int module_number);
+ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, char *type_name, int module_number);
 
 enum list_entry_type {
        LE_DB=1000
@@ -83,6 +86,8 @@ ZEND_API void *zend_plist_find(int id, int *type);
 ZEND_API int zend_register_resource(zval *rsrc_result, void *rsrc_pointer, int rsrc_type);
 ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int *found_resource_type, int num_resource_types, ...);
 
+ZEND_API char *zend_rsrc_list_get_rsrc_type(int resource);
+
 extern ZEND_API int le_index_ptr;  /* list entry type for index pointers */
 
 #define ZEND_VERIFY_RESOURCE(rsrc)             \