new improved resource-API

This commit is contained in:
Thies C. Arntzen 1999-10-12 14:51:17 +00:00
parent fc48083437
commit 6d7c18c1f5
2 changed files with 25 additions and 11 deletions

View File

@ -138,13 +138,22 @@ ZEND_API void *zend_plist_find(int id, int *type)
}
ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int resource_type)
{
return zend_fetch_resource_ex(passed_id, default_id, resource_type_name, 1, resource_type);
ZEND_API int zend_register_resource(zval *rsrc_result, void *rsrc_pointer, int rsrc_type)
{
int rsrc_id;
rsrc_id = zend_list_insert(rsrc_pointer, rsrc_type);
if (rsrc_result) {
rsrc_result->value.lval = rsrc_id;
rsrc_result->type = IS_RESOURCE;
}
return rsrc_id;
}
ZEND_API void *zend_fetch_resource_ex(zval **passed_id, int default_id, char *resource_type_name, int num_resource_types, ...)
ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int *found_resource_type, int num_resource_types, ...)
{
int id;
int actual_resource_type;
@ -180,6 +189,9 @@ ZEND_API void *zend_fetch_resource_ex(zval **passed_id, int default_id, char *re
for (i=0; i<num_resource_types; i++) {
if (actual_resource_type == va_arg(resource_types, int)) {
va_end(resource_types);
if (found_resource_type) {
*found_resource_type = actual_resource_type;
}
return resource;
}
}

View File

@ -62,8 +62,9 @@ ZEND_API int zend_list_delete(int id);
ZEND_API int zend_plist_delete(int id);
ZEND_API void *zend_list_find(int id, int *type);
ZEND_API void *zend_plist_find(int id, int *type);
ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int resource_type);
ZEND_API void *zend_fetch_resource_ex(zval **passed_id, int default_id, char *resource_type_name, int num_resource_types, ...);
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, ...);
extern ZEND_API int le_index_ptr; /* list entry type for index pointers */
@ -72,14 +73,15 @@ extern ZEND_API int le_index_ptr; /* list entry type for index pointers */
RETURN_FALSE; \
}
#define ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \
rsrc = (rsrc_type) zend_fetch_resource(passed_id, default_id, resource_type_name, resource_type); \
rsrc = (rsrc_type) zend_fetch_resource(passed_id, default_id, resource_type_name, NULL, 1, resource_type); \
ZEND_VERIFY_RESOURCE(rsrc);
#define ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1,resource_type2) \
rsrc = (rsrc_type) zend_fetch_resource(passed_id, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2); \
ZEND_VERIFY_RESOURCE(rsrc);
#define ZEND_REGISTER_RESOURCE(rsrc_result, rsrc_pointer, rsrc_type) \
rsrc_result->value.lval = zend_list_insert(rsrc_pointer, rsrc_type); \
rsrc_result->type = IS_RESOURCE
#define ZEND_REGISTER_RESOURCE(rsrc_result, rsrc_pointer, rsrc_type) \
zend_register_resource(rsrc_result, rsrc_pointer, rsrc_type);
#endif