[redland-dev] Storing statements in a Python dictionary doesn't seem to work

Carlos.Guerreiro at nokia.com Carlos.Guerreiro at nokia.com
Thu May 15 12:51:36 BST 2003


Hi Dave,

Thanks for the clarification. My bad, I should have read the docs carefully...

But anyway, shouldn't Python's reference counting semantics be enough to handle this sharing efficiently, without ever requiring a copy?

Best regards,
Carlos

> OK, I tried your program and I see the problem too.  The issue
> is the return value of stream.current().  It provides efficient
> access to a *shared* copy of a Redland statement.  If you
> want to keep it around for a while for some other purpose,
> such as storing it in a python (or other language) object,
> you will need to have your own copy.
> 
> I changed
>    d[id] = stmt
> to
>   d[id] = RDF.Statement(statement=stmt)
> 
> and it works fine.
> 
> I'm not sure how I can make this more pythonic.  Either I
> always copy the C object in returning it via current() and lose
> efficiency or try to document this better.
> 
> The pydoc says at present for the Stream class:
> 
>          # get the current Statement
>          statement=stream.current()
>          # do something with it
>          # (it is shared; you must copy it you want to keep it)
> 




More information about the redland-dev mailing list