[Linux-ha-dev] uuid_t weirdness...
Guochun Shi
gshi at ncsa.uiuc.edu
Mon Oct 18 23:17:37 MDT 2004
At 04:20 PM 10/18/2004 -0600, you wrote:
>Hi Gouchun,
>
>I've been looking at the uuid_t code, and decided there was something I didn't like about it. Not particularly your fault, but
>
>The problem is that the uuid_t type is an array, and an array isn't a first class type in 'C'. You can't return it as a value (for example), and it has an implicit & in the the type for various reasons.
>
>The result of this is that in lots of places your code uses a char * instead of a uuid_t. So, we aren't getting any type checking, or size checking.
>
>I think it would be better if we did something like this for our use of uuid.
>
>
>/* new header file clplumbing/uuid.h */
>
>typedef struct {
> uuid_t u;
>}cl_uuid_t;
>
>Then we would get better type checking, and various other weirdnesses associated with uuid_t would go away. We could also provide cl_xxx wrapper functions for using the 'standard' wrapper functions which would more easily permit us to use another uuid library - since the header file name would only have to be known by clplumbing/uuid.h and what functions we were actually using would be hidden by our wrappers?
>
>Does this make sense to you?
That sounds a good reason for implementing the wrapper functions :)
-Guochun
>--
> Alan Robertson <alanr at unix.sh>
>
>"Openness is the foundation and preservative of friendship... Let me claim from you at all times your undisguised opinions." - William Wilberforce
>
>
>/* Heartbeat: Linux-HA uuid header file
> *
> * Copyright (C) 2004 Guochun Shi <gshi at ncsa.uiuc.edu>
> *
> * This library is free software; you can redistribute it and/or
> * modify it under the terms of the GNU Lesser General Public
> * License as published by the Free Software Foundation; either
> * version 2.1 of the License, or (at your option) any later version.
> *
> * This library is distributed in the hope that it will be useful,
> * but WITHOUT ANY WARRANTY; without even the implied warranty of
> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> * Lesser General Public License for more details.
> *
> * You should have received a copy of the GNU Lesser General Public
> * License along with this library; if not, write to the Free Software
> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> *
> */
>
>#ifndef _CLPLUMBING_UUID_H
>#define _CLPLUMBING_UUID_H
>
>#include <uuid/uuid.h>
>
>/* The advantage that this type has over uuid_t is that we can return it,
> * or a pointer to it
> * and both work quite nicely. Not so for uuid_t as normally defined
> * because C doesn't treat arrays as first-class types...
> */
>typedef struct{
> uuid_t u;
>}cl_uuid_t;
>/*
> * Since uuid_t is 16 bytes long, there are no known platforms in which this
> * structure is distinguishable in storage from the uuid_t array.
> * It won't pad at the beginning or at the end.
> *
> * It's just a way of getting 'C' to like it better - because structs *are*
> * first class types in 'C'. (sigh)
> */
>
>gboolean cl_uuid_equal(cl_uuid_t* lhs, cl_uuid_t*rhs);
>
>#endif
>_______________________________________________________
>Linux-HA-Dev: Linux-HA-Dev at lists.linux-ha.org
>http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
>Home Page: http://linux-ha.org/
More information about the Linux-HA-Dev
mailing list