Commit 99832d3a authored by Ronan's avatar Ronan

fix(object): call on_first_ref cb correctly

parent 2cf1fe0f
......@@ -94,12 +94,15 @@ 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(vptr->size);
obj->ref=vptr->initially_unowned ? 0 : 1;
obj->vptr=vptr;
if (obj->ref==0){
obj->vptr = vptr;
obj->ref = vptr->initially_unowned ? 0 : 1;
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);
}
} else if (obj->ref == 1 && obj->vptr->on_first_ref)
obj->vptr->on_first_ref(obj);
add_new_object(obj);
return obj;
}
......@@ -110,15 +113,14 @@ int belle_sip_object_is_initially_unowned(const belle_sip_object_t *obj){
belle_sip_object_t * belle_sip_object_ref(void *obj){
belle_sip_object_t *o=BELLE_SIP_OBJECT(obj);
if (o->ref==0 && o->pool){
if (o->ref == 0 && o->pool) {
belle_sip_object_pool_remove(o->pool,obj);
}
if (o->vptr->on_first_ref){
if (o->ref == 0 || (o->vptr->initially_unowned && o->ref == 1)){
o->vptr->on_first_ref(o);
}
}
o->ref++;
if (o->vptr->on_first_ref && o->ref == 1)
o->vptr->on_first_ref(o);
return obj;
}
......@@ -131,7 +133,7 @@ void belle_sip_object_unref(void *ptr){
belle_sip_fatal("Fatal object error encountered, aborting.");
return;
}
if (obj->vptr->initially_unowned && obj->ref==0){
if (obj->pool)
belle_sip_object_pool_remove(obj->pool,obj);
......@@ -139,9 +141,9 @@ void belle_sip_object_unref(void *ptr){
belle_sip_object_delete(obj);
return;
}
obj->ref--;
if (obj->vptr->on_last_ref){
if ((obj->vptr->initially_unowned && obj->ref==0)
|| (!obj->vptr->initially_unowned && obj->ref == 1)){
......@@ -522,7 +524,7 @@ static belle_sip_error_code checked_marshal(belle_sip_object_vptr_t *vptr, belle
}else{
belle_sip_error("Object of type %s produced an error during marshalling: %i",
vptr->type_name,error);
}
}
belle_sip_free(p);
return error;
}
......@@ -821,5 +823,3 @@ belle_sip_object_pool_t *belle_sip_object_pool_get_current(void){
}
return (belle_sip_object_pool_t*)(*pools)->data;
}
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