tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

constification ?



Hi,

What is the feeling about constification of libc?  I have seen problems
sometimes where FreeBSD has already done these (eg passing const strings
to dirname(3) and basename(3) breaks on NetBSD) and wonder if we should
follow..

now I was writing something using uuid(3) and find that comparing against
a const value won't build, are there objections to the patch below that
constifies uuid(3) ?

so far as I understand, this sort of thing doesn't actually change the ABI
at all (just makes the API more liberal) so doesn't require a version
bump?

iain

--- /usr/src/lib/libc/uuid/uuid.3       2007-01-27 23:36:23.000000000 +0000
+++ uuid.3      2008-04-19 19:33:51.000000000 +0100
@@ -74,21 +74,21 @@
 .Sh SYNOPSIS
 .In uuid.h
 .Ft int32_t
-.Fn uuid_compare "uuid_t *uuid1" "uuid_t *uuid2" "uint32_t *status"
+.Fn uuid_compare "const uuid_t *uuid1" "const uuid_t *uuid2" "uint32_t *status"
 .Ft void
 .Fn uuid_create "uuid_t *uuid" "uint32_t *status"
 .Ft void
 .Fn uuid_create_nil "uuid_t *uuid" "uint32_t *status"
 .Ft int32_t
-.Fn uuid_equal "uuid_t *uuid1" "uuid_t *uuid2" "uint32_t *status"
+.Fn uuid_equal "const uuid_t *uuid1" "const uuid_t *uuid2" "uint32_t *status"
 .Ft void
 .Fn uuid_from_string "const char *str" "uuid_t *uuid" "uint32_t *status"
 .Ft uint16_t
-.Fn uuid_hash "uuid_t *uuid" "uint32_t *status"
+.Fn uuid_hash "const uuid_t *uuid" "uint32_t *status"
 .Ft int32_t
-.Fn uuid_is_nil "uuid_t *uuid" "uint32_t *status"
+.Fn uuid_is_nil "const uuid_t *uuid" "uint32_t *status"
 .Ft void
-.Fn uuid_to_string "uuid_t *uuid" "char **str" "uint32_t *status"
+.Fn uuid_to_string "const uuid_t *uuid" "char **str" "uint32_t *status"
 .Ft void
 .Fn uuid_enc_le "void *buf" "const uuid_t *uuid"
 .Ft void
--- /usr/src/lib/libc/uuid/uuid_compare.c       2004-09-13 22:44:54.000000000 
+0100
+++ uuid_compare.c      2008-04-19 19:26:37.000000000 +0100
@@ -48,7 +48,7 @@
  *      than any non-nil UUID.
  */
 int32_t
-uuid_compare(uuid_t *a, uuid_t *b, uint32_t *status)
+uuid_compare(const uuid_t *a, const uuid_t *b, uint32_t *status)
 {
        int res;

--- /usr/src/lib/libc/uuid/uuid_equal.c 2004-09-13 22:44:54.000000000 +0100
+++ uuid_equal.c        2008-04-19 19:23:44.000000000 +0100
@@ -45,7 +45,7 @@
  *     http://www.opengroup.org/onlinepubs/009629399/uuid_equal.htm
  */
 int32_t
-uuid_equal(uuid_t *a, uuid_t *b, uint32_t *status)
+uuid_equal(const uuid_t *a, const uuid_t *b, uint32_t *status)
 {

        if (status != NULL)
--- /usr/src/lib/libc/uuid/uuid_hash.c  2004-09-13 22:44:54.000000000 +0100
+++ uuid_hash.c 2008-04-19 19:30:26.000000000 +0100
@@ -44,7 +44,7 @@
  *     http://www.opengroup.org/onlinepubs/009629399/uuid_hash.htm
  */
 uint16_t
-uuid_hash(uuid_t *u, uint32_t *status)
+uuid_hash(const uuid_t *u, uint32_t *status)
 {

        if (status)
--- /usr/src/lib/libc/uuid/uuid_is_nil.c        2007-01-27 23:36:23.000000000 
+0000
+++ uuid_is_nil.c       2008-04-19 19:26:53.000000000 +0100
@@ -49,7 +49,7 @@
  *     http://www.opengroup.org/onlinepubs/009629399/uuid_is_nil.htm
  */
 int32_t
-uuid_is_nil(uuid_t *u, uint32_t *status)
+uuid_is_nil(const uuid_t *u, uint32_t *status)
 {
        static const uuid_t nil = { .time_low = 0 };

--- /usr/src/lib/libc/uuid/uuid_to_string.c     2004-09-13 22:44:54.000000000 
+0100
+++ uuid_to_string.c    2008-04-20 18:56:30.000000000 +0100
@@ -50,9 +50,9 @@
  *      taken from the Hewlett-Packard implementation.
  */
 void
-uuid_to_string(uuid_t *u, char **s, uint32_t *status)
+uuid_to_string(const uuid_t *u, char **s, uint32_t *status)
 {
-       uuid_t nil;
+       static const uuid_t nil = { .time_low = 0 };

        if (status != NULL)
                *status = uuid_s_ok;
@@ -61,10 +61,8 @@
        if (s == 0)
                return;

-       if (u == NULL) {
+       if (u == NULL)
                u = &nil;
-               uuid_create_nil(u, NULL);
-       }

        asprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
            u->time_low, u->time_mid, u->time_hi_and_version,
--- /usr/src/lib/libc/uuid/../../../include/uuid.h      2004-09-13 
22:44:54.000000000 +0100
+++ ../../../include/uuid.h     2008-04-19 19:33:32.000000000 +0100
@@ -42,14 +42,14 @@
 #define        uuid_s_no_memory                3

 __BEGIN_DECLS
-int32_t        uuid_compare(uuid_t *, uuid_t *, uint32_t *);
+int32_t        uuid_compare(const uuid_t *, const uuid_t *, uint32_t *);
 void   uuid_create(uuid_t *, uint32_t *);
 void   uuid_create_nil(uuid_t *, uint32_t *);
-int32_t        uuid_equal(uuid_t *, uuid_t *, uint32_t *);
+int32_t        uuid_equal(const uuid_t *, const uuid_t *, uint32_t *);
 void   uuid_from_string(const char *, uuid_t *, uint32_t *);
-uint16_t uuid_hash(uuid_t *, uint32_t *);
-int32_t        uuid_is_nil(uuid_t *, uint32_t *);
-void   uuid_to_string(uuid_t *, char **, uint32_t *);
+uint16_t uuid_hash(const uuid_t *, uint32_t *);
+int32_t        uuid_is_nil(const uuid_t *, uint32_t *);
+void   uuid_to_string(const uuid_t *, char **, uint32_t *);

 void   uuid_enc_le(void *, const uuid_t *);
 void   uuid_dec_le(const void *, uuid_t *);


Home | Main Index | Thread Index | Old Index