|
|
|
@ -43,27 +43,27 @@ struct obj { |
|
|
|
|
|
|
|
#define OBJ_MAGIC 0xf1eef1ee |
|
|
|
|
|
|
|
#define obj_alloc(t,a,b) __obj_alloc(a,b,t,__FILE__,__LINE__) |
|
|
|
#define obj_alloc0(t,a,b) __obj_alloc0(a,b,t,__FILE__,__LINE__) |
|
|
|
#define obj_hold(a) __obj_hold(&(a)->obj,__FILE__,__LINE__) |
|
|
|
#define obj_get(a) __obj_get(&(a)->obj,__FILE__,__LINE__) |
|
|
|
#define obj_put(a) __obj_put(&(a)->obj,__FILE__,__LINE__) |
|
|
|
#define obj_hold_o(a) __obj_hold(a,__FILE__,__LINE__) |
|
|
|
#define obj_get_o(a) __obj_get(a,__FILE__,__LINE__) |
|
|
|
#define obj_put_o(a) __obj_put(a,__FILE__,__LINE__) |
|
|
|
#define obj_alloc(t,a,b) __obj_alloc(a,b,t,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_alloc0(t,a,b) __obj_alloc0(a,b,t,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_hold(a) __obj_hold(&(a)->obj,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_get(a) __obj_get(&(a)->obj,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_put(a) __obj_put(&(a)->obj,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_hold_o(a) __obj_hold(a,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_get_o(a) __obj_get(a,__FILE__,__func__,__LINE__) |
|
|
|
#define obj_put_o(a) __obj_put(a,__FILE__,__func__,__LINE__) |
|
|
|
|
|
|
|
INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *), |
|
|
|
const char *type, const char *file, unsigned int line); |
|
|
|
const char *type, const char *file, const char *func, unsigned int line); |
|
|
|
INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *), |
|
|
|
const char *type, const char *file, unsigned int line); |
|
|
|
const char *type, const char *file, const char *func, unsigned int line); |
|
|
|
INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *), |
|
|
|
const char *type, const char *file, unsigned int line); |
|
|
|
const char *type, const char *file, const char *func, unsigned int line); |
|
|
|
INLINE struct obj *__obj_hold(struct obj *o, |
|
|
|
const char *file, unsigned int line); |
|
|
|
const char *file, const char *func, unsigned int line); |
|
|
|
INLINE void *__obj_get(struct obj *o, |
|
|
|
const char *file, unsigned int line); |
|
|
|
const char *file, const char *func, unsigned int line); |
|
|
|
INLINE void __obj_put(struct obj *o, |
|
|
|
const char *file, unsigned int line); |
|
|
|
const char *file, const char *func, unsigned int line); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
@ -93,13 +93,13 @@ INLINE void __obj_put(struct obj *o); |
|
|
|
|
|
|
|
INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *) |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *type, const char *file, unsigned int line |
|
|
|
, const char *type, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
#if OBJ_DEBUG |
|
|
|
o->magic = OBJ_MAGIC; |
|
|
|
o->type = strdup(type); |
|
|
|
write_log(LOG_DEBUG, "obj_allocX(\"%s\") -> %p [%s:%u]", type, o, file, line); |
|
|
|
write_log(LOG_DEBUG, "obj_allocX(\"%s\") -> %p [%s:%s:%u]", type, o, file, func, line); |
|
|
|
#endif |
|
|
|
o->ref = 1; |
|
|
|
o->free_func = free_func; |
|
|
|
@ -108,7 +108,7 @@ INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void |
|
|
|
|
|
|
|
INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *) |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *type, const char *file, unsigned int line |
|
|
|
, const char *type, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
struct obj *r; |
|
|
|
@ -116,7 +116,7 @@ INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *) |
|
|
|
r = g_slice_alloc(size); |
|
|
|
__obj_init(r, size, free_func |
|
|
|
#if OBJ_DEBUG |
|
|
|
, type, file, line |
|
|
|
, type, file, func, line |
|
|
|
#endif |
|
|
|
); |
|
|
|
return r; |
|
|
|
@ -124,7 +124,7 @@ INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *) |
|
|
|
|
|
|
|
INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *) |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *type, const char *file, unsigned int line |
|
|
|
, const char *type, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
struct obj *r; |
|
|
|
@ -132,7 +132,7 @@ INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *) |
|
|
|
r = g_slice_alloc0(size); |
|
|
|
__obj_init(r, size, free_func |
|
|
|
#if OBJ_DEBUG |
|
|
|
, type, file, line |
|
|
|
, type, file, func, line |
|
|
|
#endif |
|
|
|
); |
|
|
|
return r; |
|
|
|
@ -140,49 +140,49 @@ INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *) |
|
|
|
|
|
|
|
INLINE struct obj *__obj_hold(struct obj *o |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *file, unsigned int line |
|
|
|
, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
#if OBJ_DEBUG |
|
|
|
assert(o->magic == OBJ_MAGIC); |
|
|
|
write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt before %u [%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, line); |
|
|
|
write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt before=%u [%s:%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, func, line); |
|
|
|
#endif |
|
|
|
g_atomic_int_inc(&o->ref); |
|
|
|
#if OBJ_DEBUG |
|
|
|
write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt after %u [%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, line); |
|
|
|
write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt after=%u [%s:%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, func, line); |
|
|
|
#endif |
|
|
|
return o; |
|
|
|
} |
|
|
|
|
|
|
|
INLINE void *__obj_get(struct obj *o |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *file, unsigned int line |
|
|
|
, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
return __obj_hold(o |
|
|
|
#if OBJ_DEBUG |
|
|
|
, file, line |
|
|
|
, file, func, line |
|
|
|
#endif |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
INLINE void __obj_put(struct obj *o |
|
|
|
#if OBJ_DEBUG |
|
|
|
, const char *file, unsigned int line |
|
|
|
, const char *file, const char *func, unsigned int line |
|
|
|
#endif |
|
|
|
) { |
|
|
|
#if OBJ_DEBUG |
|
|
|
assert(o->magic == OBJ_MAGIC); |
|
|
|
write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt before %u [%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, line); |
|
|
|
write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt before=%u [%s:%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, func, line); |
|
|
|
#endif |
|
|
|
if (!g_atomic_int_dec_and_test(&o->ref)) |
|
|
|
return; |
|
|
|
#if OBJ_DEBUG |
|
|
|
write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt after %u [%s:%u]", |
|
|
|
o, o->type, g_atomic_int_get(&o->ref), file, line); |
|
|
|
write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), free object; [%s:%s:%u]", |
|
|
|
o, o->type, file, func, line); |
|
|
|
free(o->type); |
|
|
|
#endif |
|
|
|
if (o->free_func) |
|
|
|
|