[redland-dev] Statement ownership of nodes

Steve Shepard steveshepard at mac.com
Wed Jul 28 01:16:03 BST 2004


On Jul 27, 2004, at 3:52 PM, Steve Shepard wrote:

>
> 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 
> );
> }

For completeness, that should probably be

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

   if (LIBRDF_NODE_STATEMENT_SUBJECT(statement)) {
     librdf_free_node(LIBRDF_NODE_STATEMENT_SUBJECT(statement));
   }
    
LIBRDF_NODE_STATEMENT_SUBJECT(statement)=librdf_new_node_from_node(node) 
;
}

-Steve




More information about the redland-dev mailing list