[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

svn_temp_serializer.c - void ** and casts

From: Julian Foad <julian.foad_at_wandisco.com>
Date: Wed, 18 May 2011 14:24:08 +0100

I'm posting this here so Daniel can carry on with it and others can
comment.

Daniel and I were just looking at some caching functions and trying to
reduce the use of 'void *', 'void **' and casts, and we came up with
this patch for svn_temp_deserializer__resolve(). Before it could be
committed it would need similar changes of the 'offset' integer data
type (from apr_size_t to apr_uintptr_t) throughout the other functions
that interact with it.

The 'ptr' parameter is an in/out parameter, which on input points to an
integer (of whatever type the implementation has decided to use, but no
larger than a pointer), and on output points to a pointer. The doc
strings could do with being updated to state this.

- Julian

[[[
Index: subversion/libsvn_subr/svn_temp_serializer.c
===================================================================
--- subversion/libsvn_subr/svn_temp_serializer.c (revision 1124118)
+++ subversion/libsvn_subr/svn_temp_serializer.c (working copy)
@@ -321,36 +321,30 @@ svn_temp_serializer__get(svn_temp_serial
 }
 
 /* Replace the deserialized pointer value at PTR inside BUFFER with a
  * proper pointer value.
  */
 void
-svn_temp_deserializer__resolve(void *buffer, void **ptr)
+svn_temp_deserializer__resolve(void *buffer, apr_uintptr_t *ptr)
 {
   /* All pointers are stored as offsets to the buffer start
    * (of the respective serialized sub-struct). */
- apr_size_t ptr_offset = *(apr_size_t *)ptr;
+ apr_uintptr_t ptr_offset = *ptr;
   if (ptr_offset)
     {
       /* Reconstruct the original pointer value */
- const char *target = (const char *)buffer + ptr_offset;
+ apr_uintptr_t target = (apr_uintptr_t)buffer + ptr_offset;
 
       /* All sub-structs are written _after_ their respective parent.
        * Thus, all offsets are > 0. If the following assertion is not met,
        * the data is either corrupt or you tried to resolve the pointer
        * more than once. */
- assert(target > (const char *)buffer);
+ assert(target > (apr_uintptr_t)buffer);
 
       /* replace the PTR_OFFSET in *ptr with the pointer to TARGET */
- (*(const char **)ptr) = target;
- }
- else
- {
- /* NULL pointers are stored as 0 which might have a different
- * binary representation. */
- *ptr = NULL;
+ *ptr = target;
     }
 }
 
 const void *
 svn_temp_deserializer__ptr(const void *buffer, const void **ptr)
 {
]]]
Received on 2011-05-18 15:24:45 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.