Lauri Aalto wrote:
Thank you for the question and patch.

On Fri, May 2, 2008 at 1:58 PM, Michael Stahl <[EMAIL PROTECTED]> wrote:
 so, i noticed that librdf_stream_get_context returns a void*... why?

I don't really know.

I'd guess it comes from the fact that the underlying stream callback
get_method returns a void* as it will return librdf_statement* or
librdf_node*, depending on the flags passed in. That makes it easy to
use void*s internally and transfer the burden of type casting to
caller.

librdf_stream inherits its core design from librdf_iterator. According
to svn logs, latest significant changes to that design are from 2002.

 imho it should return librdf_node* instead.
 patch is attached.

Agree, returing librdf_node* makes sense. However, it would introduce
a slight API break and would not bring much benefit as such. I'd like
to hear dajobe's take on this issue.

The patch itself is not sufficient:

- prototypes in rdf_stream.h are not changed

- should keep rdf_stream consistent with rdf_iterator -> patch
rdf_iterator.[ch] as well

Lauri

oops, sorry, i was in a hurry when i wrote that, so i forgot about trivial things, like checking whether the patch even builds :)
so i've made a new patch, and it actually compiles...

i would assume that this change would only break programs that cast the returned pointer to something other than either void* or librdf_node*, which would be incorrect anyway...

--
"Most programming environments are meta-engineered to make typical
 software easier to write. They should instead be meta-engineered to
 make incorrect software harder to write." -- Daniel J. Bernstein
--- redland-1.0.7/librdf/rdf_stream.h	Mon Dec 17 08:09:51 2007
+++ redland-1.0.7-contextdup/librdf/rdf_stream.h	Mon May  5 11:05:08 2008
@@ -82,7 +82,7 @@
 REDLAND_API
 librdf_statement* librdf_stream_get_object(librdf_stream* stream);
 REDLAND_API
-void* librdf_stream_get_context(librdf_stream* stream);
+librdf_node* librdf_stream_get_context(librdf_stream* stream);
 
 REDLAND_API
 int librdf_stream_add_map(librdf_stream* stream, librdf_stream_map_handler map_function, librdf_stream_map_free_context_handler free_context, void *map_context);
--- redland-1.0.7/librdf/rdf_stream.c	Mon Dec 24 00:23:10 2007
+++ redland-1.0.7-contextdup/librdf/rdf_stream.c	Fri May  2 12:45:21 2008
@@ -288,8 +288,8 @@
  * 
  * Return value: The context node or NULL if the stream has finished.
  **/
-void*
-librdf_stream_get_context(librdf_stream* stream) 
+librdf_node*
+librdf_stream_get_context(librdf_stream* stream)
 {
   if(stream->is_finished)
     return NULL;
@@ -297,7 +297,7 @@
   if(!librdf_stream_update_current_statement(stream))
     return NULL;
 
-  return stream->get_method(stream->context, 
+  return (librdf_node*) stream->get_method(stream->context,
                             LIBRDF_STREAM_GET_METHOD_GET_CONTEXT);
 }
 
--- redland-1.0.7/librdf/rdf_iterator.h	Mon Dec 17 08:09:51 2007
+++ redland-1.0.7-contextdup/librdf/rdf_iterator.h	Mon May  5 11:12:24 2008
@@ -78,7 +78,7 @@
 REDLAND_API
 void* librdf_iterator_get_object(librdf_iterator* iterator);
 REDLAND_API
-void* librdf_iterator_get_context(librdf_iterator* iterator);
+librdf_node* librdf_iterator_get_context(librdf_iterator* iterator);
 REDLAND_API
 void* librdf_iterator_get_key(librdf_iterator* iterator);
 REDLAND_API
--- redland-1.0.7/librdf/rdf_iterator.c	Thu Dec 20 22:39:42 2007
+++ redland-1.0.7-contextdup/librdf/rdf_iterator.c	Mon May  5 11:12:00 2008
@@ -294,7 +294,7 @@
  * 
  * Return value: The context or NULL if the iterator has finished.
  **/
-void*
+librdf_node*
 librdf_iterator_get_context(librdf_iterator* iterator) 
 {
   if(iterator->is_finished)
@@ -303,7 +303,7 @@
   if(!librdf_iterator_update_current_element(iterator))
     return NULL;
 
-  return iterator->get_method(iterator->context, 
+  return (librdf_node*) iterator->get_method(iterator->context, 
                               LIBRDF_ITERATOR_GET_METHOD_GET_CONTEXT);
 }
 
_______________________________________________
redland-dev mailing list
[email protected]
http://lists.librdf.org/mailman/listinfo/redland-dev

Reply via email to