1
1

Removed NEW/DELETE as OBJ_CREATE/OBJ_RELEASE will do the same thing. Moved free() statement from lam_obj_destroy() to lam_obj_release() so that statically declared objects can be initialized/cleaned up. Added STATIC_DESTROY to free resources for statically declared objects.

This commit was SVN r528.
Этот коммит содержится в:
Rob Awles 2004-01-22 19:26:38 +00:00
родитель 21bc9ef220
Коммит 924ca42d6f
2 изменённых файлов: 12 добавлений и 19 удалений

Просмотреть файл

@ -13,6 +13,6 @@ void lam_obj_init(lam_object_t *obj)
void lam_obj_destroy(lam_object_t *obj)
{
free(obj);
/* Move along, nothing to see here! */
}

Просмотреть файл

@ -54,6 +54,13 @@ extern lam_class_info_t lam_object_cls;
OBJECT(&(obj))->obj_class->cls_init(OBJECT(&(obj))); \
} while (0)
/* Use STATIC_DESTROY to destroy an object that is not
dynamically allocated. */
#define STATIC_DESTROY(obj) \
do { \
OBJECT(&(obj))->obj_class->cls_destroy(OBJECT(&(obj))); \
} while (0)
/* super_cls should be the pointer to the obj's parent
class info struct. */
#define SUPER_INIT(obj, super_cls) \
@ -65,8 +72,9 @@ extern lam_class_info_t lam_object_cls;
#define OBJECT(obj) ((lam_object_t *)(obj))
#define OBJ_RETAIN(obj) if ( obj ) lam_obj_retain(OBJECT(obj))
#define OBJ_RELEASE(obj) if ( obj ) lam_obj_release(OBJECT(obj))
#define CREATE_OBJECT(obj, obj_type, class_info) \
(obj = (obj_type*)lam_create_object(sizeof(obj_type, class_info)))
#define OBJ_CREATE(obj_type, class_info) \
((obj_type*)lam_create_object(sizeof(obj_type), class_info))
typedef struct lam_object
@ -89,22 +97,6 @@ static inline lam_object_t* lam_create_object(size_t size, lam_class_info_t* cla
return obj;
}
/*
* C++ Style new/delete macros to allocate/initialize and
* cleanup/free resources.
*/
#define NEW(obj_type, class_info) \
((obj_type*)lam_create_object(sizeof(obj_type), class_info))
#define DELETE(obj) \
do { \
if(NULL != obj) { \
OBJECT(obj)->obj_class->cls_destroy(OBJECT(obj)); \
LAM_FREE(obj); \
} \
} while(0)
/*
* This function is used by inline functions later in this file, and
* it must be defined by other header files later (eg., one of the
@ -132,6 +124,7 @@ static inline void lam_obj_release(lam_object_t *obj)
if ( fetchNadd(&obj->obj_refcnt, -1) == 1 )
{
obj->obj_class->cls_destroy(obj);
LAM_FREE(obj);
}
}