[redland-dev] Statement ownership of nodes

Steve Shepard steveshepard at mac.com
Tue Jul 27 23:52:01 BST 2004


On Jul 27, 2004, at 3:23 PM, Dave Beckett wrote:

> (oops, forgot to reply-all;  I bet you see this via the list also.  If
> you could reply to that one, it'd preserve the thread)
>
> On Tue, 27 Jul 2004 13:15:02 -0700
> Steve Shepard <steveshepard at mac.com> wrote:
>
>>
>> I've spent the last couple of days with librdf. Nice!  A quick
>> question:
>>
>> The librdf_statement_set_* routines carry the warning:
>>
>> "The <node> passed in becomes owned by the statement object and must
>> not be used by the caller after this call."
>>
>> I'm curious about the reason for this. If the intent is to prevent the
>>
>> deletion of the resource, a better approach would be to adopted the
>> ownership conventions used in the rest of the library and bump the
>> node->usage count. What am I missing?
>
> librdf_statement (an RDF triple) is barely more than
>   [3]librdf_node*
> so the implentation of the methods are as trivial as you'd expect;
> early on they were macros.
>
> It might even be worth moving it to inline functions at some point.
>
> But if it went to the object style, it'd be slightly more heavyweight.
> I'm unsure if it'd be good to switch the style without new method names
>
> Dave

(reply to the list this time...).

I think all you want to do is increment node->usage, perhaps as follows:

librdf_statement_set_subject(librdf_statement *statement, librdf_node  
*node)
{
   LIBRDF_ASSERT_OBJECT_POINTER_RETURN(statement, librdf_statement);

    
LIBRDF_NODE_STATEMENT_SUBJECT(statement)=librdf_new_node_from_node(node) 
;
}

That way , librdf_statement_clear won't leave dangling node references  
if you free a librdf_statement.  librdf_statement_clear already does  
the proper accounting by calling librdf_free_node.

Of course you could call new_node_from_node before you call set_subject  
(which is what I'm currently doing in my c++ wrapper), but it seems  
good form to increment the refcount when keeping a reference to a  
shared data structure.

-Steve





More information about the redland-dev mailing list