Commit d408790a authored by Simon Morlat's avatar Simon Morlat

allow inhibition of leak detector

optimize belle_sip_object_t (size field moved to vptr)
fix Makefile warning.
parent a0352e56
......@@ -65,6 +65,7 @@ typedef unsigned int belle_sip_type_id_t;
#define BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned) \
BELLE_SIP_TYPE_ID(object_type), \
sizeof(object_type), \
#object_type,\
unowned,\
(belle_sip_object_get_vptr_t)BELLE_SIP_OBJECT_GET_VPTR_FUNC(parent_type), \
......@@ -131,6 +132,7 @@ typedef struct _belle_sip_object_vptr *(*belle_sip_object_get_vptr_t)(void);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
size_t size; /*the size of the object - not the vptr size*/
const char *type_name;
int initially_unowned;
belle_sip_object_get_vptr_t get_parent;
......@@ -145,7 +147,6 @@ typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t;
struct _belle_sip_object{
belle_sip_object_vptr_t *vptr;
size_t size;
int ref;
char* name;
struct weak_ref *weak_refs;
......@@ -184,6 +185,12 @@ BELLESIP_EXPORT int belle_sip_object_get_object_count(void);
BELLESIP_EXPORT void belle_sip_object_dump_active_objects(void);
/**
* Suspend leak detector from this point. If the leak detector wasn't activated, this function does nothing.
* This can be useful to make object allocation that have to remain active beyond the scope of a test.
**/
BELLESIP_EXPORT void belle_sip_object_inhibit_leak_detector(int yes);
int belle_sip_object_is_unowed(const belle_sip_object_t *obj);
/**
......
......@@ -249,7 +249,7 @@ void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t fun
void belle_sip_source_uninit(belle_sip_source_t *s);
void belle_sip_source_set_notify(belle_sip_source_t *s, belle_sip_source_func_t func);
#define belle_list_next(elem) ((elem)->next)
/* include private headers */
#include "channel.h"
......@@ -260,9 +260,11 @@ void belle_sip_source_set_notify(belle_sip_source_t *s, belle_sip_source_func_t
#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
#define belle_list_next(elem) ((elem)->next)
belle_sip_list_t *belle_sip_list_new(void *data);
belle_sip_list_t* belle_sip_list_append_link(belle_sip_list_t* elem,belle_sip_list_t *new_elem);
belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip_compare_func compare_func, const void *user_data);
belle_sip_list_t* _belle_sip_list_remove(belle_sip_list_t* first, void *data, int warn_if_not_found);
#define belle_sip_list_next(elem) ((elem)->next)
......
......@@ -43,19 +43,24 @@ void belle_sip_object_enable_marshal_check(int enable) {
static belle_sip_list_t *all_objects=NULL;
static int belle_sip_leak_detector_enabled=FALSE;
static int belle_sip_leak_detector_inhibited=FALSE;
static void add_new_object(belle_sip_object_t *obj){
if (belle_sip_leak_detector_enabled){
if (belle_sip_leak_detector_enabled && !belle_sip_leak_detector_inhibited){
all_objects=belle_sip_list_prepend(all_objects,obj);
}
}
static void remove_free_object(belle_sip_object_t *obj){
if (belle_sip_leak_detector_enabled){
all_objects=belle_sip_list_remove(all_objects,obj);
if (belle_sip_leak_detector_enabled && !belle_sip_leak_detector_inhibited){
all_objects=_belle_sip_list_remove(all_objects,obj,FALSE); /*it may fail if the leak detector was inhibitted at the time the object was created*/
}
}
void belle_sip_object_inhibit_leak_detector(int yes){
belle_sip_leak_detector_inhibited=yes ? TRUE : FALSE;
}
void belle_sip_object_enable_leak_detector(int enable){
belle_sip_leak_detector_enabled=enable;
}
......@@ -77,11 +82,10 @@ void belle_sip_object_dump_active_objects(void){
}
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr){
belle_sip_object_t *obj=(belle_sip_object_t *)belle_sip_malloc0(objsize);
belle_sip_object_t *obj=(belle_sip_object_t *)belle_sip_malloc0(vptr->size);
obj->ref=vptr->initially_unowned ? 0 : 1;
obj->vptr=vptr;
obj->size=objsize;
if (obj->ref==0){
belle_sip_object_pool_t *pool=belle_sip_object_pool_get_current();
if (pool) belle_sip_object_pool_add(pool,obj);
......@@ -191,6 +195,7 @@ static belle_sip_object_vptr_t *no_parent(void){
belle_sip_object_vptr_t belle_sip_object_t_vptr={
BELLE_SIP_TYPE_ID(belle_sip_object_t),
sizeof(belle_sip_object_t),
"belle_sip_object_t",
FALSE,
no_parent, /*no parent, it's god*/
......@@ -251,10 +256,9 @@ void _belle_sip_object_copy(belle_sip_object_t *newobj, const belle_sip_object_t
belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_object_t *newobj;
newobj=belle_sip_malloc0(obj->size);
newobj=belle_sip_malloc0(obj->vptr->size);
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
newobj->size=obj->size;
_belle_sip_object_copy(newobj,obj);
if (newobj->ref==0){
belle_sip_object_pool_t *pool=belle_sip_object_pool_get_current();
......
......@@ -307,14 +307,18 @@ belle_sip_list_t * belle_sip_list_free_with_data(belle_sip_list_t *list, void (*
}
belle_sip_list_t* belle_sip_list_remove(belle_sip_list_t* first, void *data){
belle_sip_list_t* _belle_sip_list_remove(belle_sip_list_t* first, void *data, int warn_if_not_found){
belle_sip_list_t* it;
it=belle_sip_list_find(first,data);
if (it) return belle_sip_list_delete_link(first,it);
else {
else if (warn_if_not_found){
belle_sip_warning("belle_sip_list_remove: no element with %p data was in the list", data);
return first;
}
return first;
}
belle_sip_list_t* belle_sip_list_remove(belle_sip_list_t* first, void *data){
return _belle_sip_list_remove(first, data, TRUE);
}
int belle_sip_list_size(const belle_sip_list_t* first){
......
......@@ -10,11 +10,11 @@ nodist_libbellesip_generated_la_SOURCES= \
belle_sdpParser.c belle_sdpParser.h \
belle_sdpLexer.c belle_sdpLexer.h
.NOTPARALLEL $(builddir)/belle_sip_messageParser.c $(builddir)/belle_sip_messageParser.h \
$(builddir)/belle_sip_messageParser.c $(builddir)/belle_sip_messageParser.h \
$(builddir)/belle_sip_messageLexer.c $(builddir)/belle_sip_messageLexer.h : belle_sip_message.g
$(ANTLR) -make -Xmultithreaded -fo $(builddir) $(srcdir)/belle_sip_message.g
.NOTPARALLEL $(builddir)/belle_sdpLexer.c \
$(builddir)/belle_sdpLexer.c \
$(builddir)/belle_sdpParser.c \
$(builddir)/belle_sdpLexer.h \
$(builddir)/belle_sdpParser.h : $(srcdir)/belle_sdp.g
......@@ -27,3 +27,5 @@ EXTRA_DIST= belle_sdp.g belle_sip_message.g
CLEANFILES=$(nodist_libbellesip_generated_la_SOURCES) *.tokens
.NOTPARALLEL:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment