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

Dave Beckett dave.beckett at bristol.ac.uk
Tue May 13 14:28:57 BST 2003


On 07 May 2003 12:55:22 +0300
Carlos Guerreiro <carlos.guerreiro at nokia.com> wrote:

[Sorry for the delay, I'm catching up after XML Europe]

> Hi,
> 
> Storing statements in a Python dictionary doesn't seem to work.
> I have experienced assertions (e.g.:
> rdf_node.c:381:librdf_node_from_node: fatal error: Do not know how to
> copy node type 136357032) and segmentation faults when accessing
> statements retrieved from the dictionary. Storing statements in a list
> doesn't seem to work either. Storing nodes in both dictionaries and
> lists does seem to work.
> 
> I'm attaching a small Python program that illustrates some of this.
> I have tried it with both redland-0.9.12 and today's snapshot.
> 
> I'm using Linux 2.4.18 (RedHat 8.0) with gcc 3.2.

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)

Dave




More information about the redland-dev mailing list