OSSP CVS Repository

ossp - Check-in [5659]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 5659
Date: 2006-Oct-06 10:32:40 (local)
2006-Oct-06 08:32:40 (UTC)
User:rse
Branch:
Comment: Change type of "data_ptr" argument in uuid_export() API signature from "void **" to "void " as there is unfortunately no "generic pointer to pointer type" in ISO C (see also ¤http://c-faq.com/ptrs/genericpp.html) and "void **" is just a "pointer to a 'void *'".

The "void **" especially had the nasty side-effect that it breaks strict pointer aliasing rules of ISO C and hence would require fiddling with temporary variables on all uuid_export() calls if one would be 100% correct and avoid aliasing related compiler warnings. Instead, as uuid_export() internally has to cast the "data_ptr" to the particular expected type anyway, it is better to have "data_ptr" just be a really generic "void *" in the API signature.

Keep in mind that although this is an API change, it doesn't cause any incompatibilities as the function still expects the same "pointer to a pointer of a particular type". This expected pointer is just now passed the more correct although less intuitive way.

Submitted by: Hrvoje Niksic <hniksic@xemacs.org>

Tickets:
Inspections:
Files:
ossp-pkg/uuid/ChangeLog      1.132 -> 1.133     22 inserted, 1 deleted
ossp-pkg/uuid/THANKS      1.11 -> 1.12     1 inserted, 0 deleted
ossp-pkg/uuid/uuid.c      1.62 -> 1.63     23 inserted, 7 deleted
ossp-pkg/uuid/uuid.h.in      1.12 -> 1.13     1 inserted, 1 deleted
ossp-pkg/uuid/uuid.pod      1.40 -> 1.41     29 inserted, 16 deleted

ossp-pkg/uuid/ChangeLog 1.132 -> 1.133

--- ChangeLog    2006/08/02 13:11:09     1.132
+++ ChangeLog    2006/10/06 08:32:40     1.133
@@ -11,7 +11,28 @@
   This is a list of all changes to OSSP uuid.
   For a more brief summary please have a look at the NEWS file.
 
-  Changes between 1.5.1 and 1.5.2 (31-Jul-2006 to xx-Aug-2006)
+  Changes between 1.5.1 and 1.6.0 (31-Jul-2006 to 05-Oct-2006)
+
+   o Change type of "data_ptr" argument in uuid_export() API signature
+     from "void **" to "void *" as there is unfortunately no
+     "generic pointer to pointer type" in ISO C (see also
+     http://c-faq.com/ptrs/genericpp.html) and "void **" is just a
+     "pointer to a 'void *'".
+     
+     The "void **" especially had the nasty side-effect that it breaks
+     strict pointer aliasing rules of ISO C and hence would require
+     fiddling with temporary variables on all uuid_export() calls if
+     one would be 100% correct and avoid aliasing related compiler
+     warnings. Instead, as uuid_export() internally has to cast the
+     "data_ptr" to the particular expected type anyway, it is better
+     to have "data_ptr" just be a really generic "void *" in the API
+     signature.
+     
+     Keep in mind that although this is an API change, it doesn't cause
+     any incompatibilities as the function still expects the same
+     "pointer to a pointer of a particular type". This expected pointer
+     is just now passed the more correct although less intuitive way.
+     [Hrvoje Niksic <hniksic@xemacs.org>, Ralf S. Engelschall]
 
    o Optional DMALLOC based memory debugging support.
      [Ralf S. Engelschall]


ossp-pkg/uuid/THANKS 1.11 -> 1.12

--- THANKS       2006/07/31 12:44:03     1.11
+++ THANKS       2006/10/06 08:32:40     1.12
@@ -18,6 +18,7 @@
     o  Fuyuki                      <fuyuki@nigredo.org>
     o  Thomas Lotterer             <thomas@lotterer.net>
     o  Roman Neuhauser             <neuhauser@sigpipe.cz>
+    o  Hrvoje Niksic               <hniksic@xemacs.org>
     o  Piotr Roszatycki            <dexter@debian.org>
     o  Michael Schloh              <michael@schloh.com>
     o  Guerry Semones              <guerry@tsunamiresearch.com>


ossp-pkg/uuid/uuid.c 1.62 -> 1.63

--- uuid.c       2006/08/02 13:11:09     1.62
+++ uuid.c       2006/10/06 08:32:40     1.63
@@ -328,20 +328,24 @@
 
 /* INTERNAL: pack UUID object into binary representation
    (allows in-place operation for internal efficiency!) */
-static uuid_rc_t uuid_export_bin(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+static uuid_rc_t uuid_export_bin(const uuid_t *uuid, void *_data_ptr, size_t *data_len)
 {
+    uuid_uint8_t **data_ptr;
     uuid_uint8_t *out;
     uuid_uint32_t tmp32;
     uuid_uint16_t tmp16;
     unsigned int i;
 
+    /* cast generic data pointer to particular pointer to pointer type */
+    data_ptr = (uuid_uint8_t **)_data_ptr;
+
     /* sanity check argument(s) */
     if (uuid == NULL || data_ptr == NULL)
         return UUID_RC_ARG;
 
     /* optionally allocate octet data buffer */
     if (*data_ptr == NULL) {
-        if ((*data_ptr = malloc(sizeof(uuid_t))) == NULL)
+        if ((*data_ptr = (uuid_uint8_t *)malloc(sizeof(uuid_t))) == NULL)
             return UUID_RC_MEM;
         if (data_len != NULL)
             *data_len = UUID_LEN_BIN;
@@ -355,7 +359,7 @@
     }
 
     /* treat output data buffer as octet stream */
-    out = (uuid_uint8_t *)(*data_ptr);
+    out = *data_ptr;
 
     /* pack "time_low" field */
     tmp32 = uuid->obj.time_low;
@@ -492,10 +496,14 @@
 }
 
 /* INTERNAL: export UUID object to string representation */
-static uuid_rc_t uuid_export_str(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+static uuid_rc_t uuid_export_str(const uuid_t *uuid, void *_data_ptr, size_t *data_len)
 {
+    char **data_ptr;
     char *data_buf;
 
+    /* cast generic data pointer to particular pointer to pointer type */
+    data_ptr = (char **)_data_ptr;
+
     /* sanity check argument(s) */
     if (uuid == NULL || data_ptr == NULL)
         return UUID_RC_ARG;
@@ -543,8 +551,9 @@
 }
 
 /* INTERNAL: export UUID object to single integer value representation */
-static uuid_rc_t uuid_export_siv(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+static uuid_rc_t uuid_export_siv(const uuid_t *uuid, void *_data_ptr, size_t *data_len)
 {
+    char **data_ptr;
     char *data_buf;
     void *tmp_ptr;
     size_t tmp_len;
@@ -553,6 +562,9 @@
     uuid_rc_t rc;
     int i;
 
+    /* cast generic data pointer to particular pointer to pointer type */
+    data_ptr = (char **)_data_ptr;
+
     /* sanity check argument(s) */
     if (uuid == NULL || data_ptr == NULL)
         return UUID_RC_ARG;
@@ -621,8 +633,9 @@
 };
 
 /* INTERNAL: dump UUID object as descriptive text */
-static uuid_rc_t uuid_export_txt(const uuid_t *uuid, void **data_ptr, size_t *data_len)
+static uuid_rc_t uuid_export_txt(const uuid_t *uuid, void *_data_ptr, size_t *data_len)
 {
+    char **data_ptr;
     uuid_rc_t rc;
     char **out;
     char *out_ptr;
@@ -648,6 +661,9 @@
     struct tm *tm;
     int i;
 
+    /* cast generic data pointer to particular pointer to pointer type */
+    data_ptr = (char **)_data_ptr;
+
     /* sanity check argument(s) */
     if (uuid == NULL || data_ptr == NULL)
         return UUID_RC_ARG;
@@ -820,7 +836,7 @@
 }
 
 /* UUID exporting */
-uuid_rc_t uuid_export(const uuid_t *uuid, uuid_fmt_t fmt, void **data_ptr, size_t *data_len)
+uuid_rc_t uuid_export(const uuid_t *uuid, uuid_fmt_t fmt, void *data_ptr, size_t *data_len)
 {
     uuid_rc_t rc;
 


ossp-pkg/uuid/uuid.h.in 1.12 -> 1.13

--- uuid.h.in    2006/05/11 09:37:28     1.12
+++ uuid.h.in    2006/10/06 08:32:40     1.13
@@ -108,7 +108,7 @@
 
 /* UUID import/export */
 extern uuid_rc_t     uuid_import   (      uuid_t  *_uuid, uuid_fmt_t _fmt, const void  *_data_ptr, size_t  _data_len);
-extern uuid_rc_t     uuid_export   (const uuid_t  *_uuid, uuid_fmt_t _fmt,       void **_data_ptr, size_t *_data_len);
+extern uuid_rc_t     uuid_export   (const uuid_t  *_uuid, uuid_fmt_t _fmt,       void  *_data_ptr, size_t *_data_len);
 
 /* library utilities */
 extern char         *uuid_error    (uuid_rc_t _rc);


ossp-pkg/uuid/uuid.pod 1.40 -> 1.41

--- uuid.pod     2006/08/01 19:35:07     1.40
+++ uuid.pod     2006/10/06 08:32:40     1.41
@@ -328,21 +328,34 @@
 minimum expected length in I<data_len> depends on it. Valid values for
 I<fmt> are B<UUID_FMT_BIN>, B<UUID_FMT_STR> and B<UUID_FMT_SIV>.
 
-=item uuid_rc_t B<uuid_export>(const uuid_t *I<uuid>, uuid_fmt_t I<fmt>, void **I<data_ptr>, size_t *I<data_len>);
+=item uuid_rc_t B<uuid_export>(const uuid_t *I<uuid>, uuid_fmt_t I<fmt>, void *I<data_ptr>, size_t *I<data_len>);
 
-Exports a UUID I<uuid> into an external representation of format I<fmt>.
-The data is written to the buffer at C<*>I<data_ptr> which has to
-be room for at least C<*>I<data_len> bytes. If C<*>I<data_ptr> is
-C<NULL>, I<data_len> is ignored as input and a new buffer is allocated
-and returned in C<*>I<data_ptr> (the caller has to free(3) it later
-on). If I<data_len> is not C<NULL>, the number of available bytes at
-C<*>I<data_ptr> has to be provided in C<*>I<data_len> and the number of
-actually written bytes are returned in C<*>I<data_len> again.
-
-The format of the external representation is specified by I<fmt> and the
-minimum required length in C<*>I<data_len> depends on it. Valid values
-for I<fmt> are B<UUID_FMT_BIN>, B<UUID_FMT_STR>, B<UUID_FMT_SIV> and
-B<UUID_FMT_TXT>.
+Exports a UUID I<uuid> into an external representation of format
+I<fmt>. Valid values for I<fmt> are B<UUID_FMT_BIN>, B<UUID_FMT_STR>,
+B<UUID_FMT_SIV> and B<UUID_FMT_TXT>.
+
+The data is written to the buffer whose location is obtained
+by dereferencing I<data_ptr> after a "cast" to the appropriate
+pointer-to-pointer type. Hence the generic pointer argument I<data_ptr>
+is expected to be a pointer to a "pointer of a particular type", i.e.,
+it has to be of type "C<unsigned char **>" for B<UUID_FMT_BIN> and
+"C<char **>" for B<UUID_FMT_STR>, B<UUID_FMT_SIV> and B<UUID_FMT_TXT>.
+
+The buffer has to be room for at least C<*>I<data_len> bytes. If the
+value of the pointer after "casting" and dereferencing I<data_ptr>
+is C<NULL>, I<data_len> is ignored as input and a new buffer is
+allocated and returned in the pointer after "casting" and dereferencing
+I<data_ptr> (the caller has to free(3) it later on).
+
+If I<data_len> is not C<NULL>, the number of available bytes in the
+buffer has to be provided in C<*>I<data_len> and the number of actually
+written bytes are returned in C<*>I<data_len> again. The minimum
+required buffer length depends on the external representation as
+specified by I<fmt> and is at least B<UUID_LEN_BIN> for B<UUID_FMT_BIN>,
+B<UUID_LEN_STR> for B<UUID_FMT_STR> and B<UUID_LEN_SIV> for
+B<UUID_FMT_SIV>. For B<UUID_FMT_TXT> a buffer of unspecified length is
+required and hence it is recommended to allow B<OSSP uuid> to allocate
+the buffer as necessary.
 
 =item uuid_rc_t B<uuid_load>(uuid_t *I<uuid>, const char *I<name>);
 
@@ -418,7 +431,7 @@
      uuid_create(&uuid);
      uuid_make(uuid, UUID_MAKE_V1);
      str = NULL;
-     uuid_export(uuid, UUID_FMT_STR, (void **)&str, NULL);
+     uuid_export(uuid, UUID_FMT_STR, &str, NULL);
      uuid_destroy(uuid);
      return str;
  }
@@ -435,7 +448,7 @@
      uuid_load(uuid_ns, "ns:URL");
      uuid_make(uuid, UUID_MAKE_V3, uuid_ns, url);
      str = NULL;
-     uuid_export(uuid, UUID_FMT_STR, (void **)&str, NULL);
+     uuid_export(uuid, UUID_FMT_STR, &str, NULL);
      uuid_destroy(uuid_ns);
      uuid_destroy(uuid);
      return str;

CVSTrac 2.0.1