Changeset: 16ba56829483 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=16ba56829483
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
clients/Tests/exports.stable.out
gdk/gdk.h
gdk/gdk_atoms.c
gdk/gdk_atoms.h
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_calc.c
gdk/gdk_group.c
gdk/gdk_hash.c
gdk/gdk_hash.h
gdk/gdk_project.c
gdk/gdk_utils.c
gdk/gdk_value.c
monetdb5/mal/mal_type.c
monetdb5/modules/atoms/uuid.c
Branch: default
Log Message:
Move uuid type into GDK.
diffs (truncated from 995 to 300 lines):
diff --git a/clients/Tests/MAL-signatures.stable.out
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -9690,7 +9690,6 @@ stdout of test 'MAL-signatures` in direc
[ "uuid", "isaUUID", "command uuid.isaUUID(X_0:str):bit ",
"UUIDisaUUID;", "" ]
[ "uuid", "new", "unsafe command uuid.new():uuid ",
"UUIDgenerateUuid;", "" ]
[ "uuid", "new", "unsafe command uuid.new(X_0:int):uuid ",
"UUIDgenerateUuidInt;", "" ]
-[ "uuid", "prelude", "command uuid.prelude():void ", "UUIDprelude;",
"" ]
[ "uuid", "str", "command uuid.str(X_0:uuid):str ",
"UUIDuuid2str;", "" ]
[ "uuid", "uuid", "command uuid.uuid(X_0:str):uuid ",
"UUIDstr2uuid;", "" ]
[ "wlc", "action", "pattern wlc.action(X_0:str):void ",
"WLCaction;", "" ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -859,7 +859,7 @@ stdout of test 'MAL-signatures` in direc
[ "bat", "isaKey", "command bat.isaKey(X_0:bat[:any_1]):bit ",
"BKCgetKey;", "" ]
[ "bat", "mergecand", "command bat.mergecand(X_0:bat[:oid],
X_1:bat[:oid]):bat[:oid] ", "BKCmergecand;", "" ]
[ "bat", "mirror", "command bat.mirror(X_0:bat[:any_2]):bat[:oid]
", "BKCmirror;", "" ]
-[ "bat", "new", "pattern bat.new(X_0:any_1,
X_1:bat[:any_2]):bat[:any_1] ", "CMDBATdup;", "" ]
+[ "bat", "new", "pattern bat.new(X_0:any_1,
X_1:bat[:any_2]):bat[:any_1] ", "CMDBATdup;", "" ]
[ "bat", "new", "pattern bat.new(X_0:any_1):bat[:any_1] ",
"CMDBATnew;", "" ]
[ "bat", "new", "pattern bat.new(X_0:any_1, X_1:int):bat[:any_1] ",
"CMDBATnew;", "" ]
[ "bat", "new", "pattern bat.new(X_0:any_1, X_1:int,
X_2:bit):bat[:any_1] ", "CMDBATnew;", "" ]
@@ -13017,7 +13017,6 @@ stdout of test 'MAL-signatures` in direc
[ "uuid", "isaUUID", "command uuid.isaUUID(X_0:str):bit ",
"UUIDisaUUID;", "" ]
[ "uuid", "new", "unsafe command uuid.new():uuid ",
"UUIDgenerateUuid;", "" ]
[ "uuid", "new", "unsafe command uuid.new(X_0:int):uuid ",
"UUIDgenerateUuidInt;", "" ]
-[ "uuid", "prelude", "command uuid.prelude():void ", "UUIDprelude;",
"" ]
[ "uuid", "str", "command uuid.str(X_0:uuid):str ",
"UUIDuuid2str;", "" ]
[ "uuid", "uuid", "command uuid.uuid(X_0:str):uuid ",
"UUIDstr2uuid;", "" ]
[ "wlc", "action", "pattern wlc.action(X_0:str):void ",
"WLCaction;", "" ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -580,6 +580,7 @@ ssize_t timestamp_tostr(str *buf, size_t
ssize_t timestamp_tz_fromstr(const char *buf, size_t *len, timestamp **ret,
bool external);
const timestamp unixepoch;
wchar_t *utf8towchar(const char *src);
+const uuid uuid_nil;
gdk_return void_inplace(BAT *b, oid id, const void *val, bool force)
__attribute__((__warn_unused_result__));
char *wchartoutf8(const wchar_t *src);
int winerror(int);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -441,6 +441,7 @@ enum {
TYPE_date,
TYPE_daytime,
TYPE_timestamp,
+ TYPE_uuid,
TYPE_str,
TYPE_any = 255, /* limit types to <255! */
};
@@ -464,6 +465,30 @@ typedef float flt;
typedef double dbl;
typedef char *str;
+#ifdef HAVE_UUID_UUID_H
+#include <uuid/uuid.h>
+#endif
+
+#ifdef HAVE_UUID
+#define UUID_SIZE ((int) sizeof(uuid_t)) /* size of a UUID */
+#else
+#define UUID_SIZE 16 /* size of a UUID */
+#endif
+#define UUID_STRLEN 36 /* length of string representation */
+
+typedef union {
+#ifdef HAVE_HGE
+ hge h; /* force alignment, not otherwise used */
+#else
+ lng l[2]; /* force alignment, not otherwise used */
+#endif
+#ifdef HAVE_UUID
+ uuid_t u;
+#else
+ uint8_t u[UUID_SIZE];
+#endif
+} uuid;
+
#define SIZEOF_LNG 8
#define LL_CONSTANT(val) INT64_C(val)
#define LLFMT "%" PRId64
@@ -614,6 +639,7 @@ typedef struct {
#ifdef HAVE_HGE
hge hval;
#endif
+ uuid uval;
} val;
size_t len;
int vtype;
@@ -1751,6 +1777,7 @@ VALptr(const ValRecord *v)
#ifdef HAVE_HGE
case TYPE_hge: return (const void *) &v->val.hval;
#endif
+ case TYPE_uuid: return (const void *) &v->val.uval;
case TYPE_ptr: return (const void *) &v->val.pval;
case TYPE_str: return (const void *) v->val.sval;
default: return (const void *) v->val.pval;
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -273,6 +273,7 @@ const hge hge_nil = GDK_hge_min-1;
#endif
const oid oid_nil = (oid) 1 << (sizeof(oid) * 8 - 1);
const ptr ptr_nil = NULL;
+const uuid uuid_nil = {0};
ptr
ATOMnil(int t)
@@ -1242,6 +1243,142 @@ OIDtoStr(char **dst, size_t *len, const
return snprintf(*dst, *len, OIDFMT "@0", *src);
}
+static int
+UUIDcompare(const void *L, const void *R)
+{
+ const uuid *l = L, *r = R;
+ if (is_uuid_nil(*r))
+ return !is_uuid_nil(*l);
+ if (is_uuid_nil(*l))
+ return -1;
+#ifdef HAVE_UUID
+ return uuid_compare(l->u, r->u);
+#else
+ return memcmp(l->u, r->u, UUID_SIZE);
+#endif
+}
+
+static ssize_t
+UUIDfromString(const char *svalue, size_t *len, void **RETVAL, bool external)
+{
+ uuid **retval = (uuid **) RETVAL;
+ const char *s = svalue;
+
+ if (*len < UUID_SIZE || *retval == NULL) {
+ GDKfree(*retval);
+ if ((*retval = GDKmalloc(UUID_SIZE)) == NULL)
+ return -1;
+ *len = UUID_SIZE;
+ }
+ if (external && strcmp(svalue, "nil") == 0) {
+ **retval = uuid_nil;
+ return 3;
+ }
+ if (strNil(svalue)) {
+ **retval = uuid_nil;
+ return 1;
+ }
+ /* we don't use uuid_parse since we accept UUIDs without hyphens */
+ uuid u;
+ for (int i = 0, j = 0; i < UUID_SIZE; i++) {
+ /* on select locations we allow a '-' in the source string */
+ if (j == 8 || j == 12 || j == 16 || j == 20) {
+ if (*s == '-')
+ s++;
+ }
+ if (isdigit((unsigned char) *s))
+ u.u[i] = *s - '0';
+ else if ('a' <= *s && *s <= 'f')
+ u.u[i] = *s - 'a' + 10;
+ else if ('A' <= *s && *s <= 'F')
+ u.u[i] = *s - 'A' + 10;
+ else
+ goto bailout;
+ s++;
+ j++;
+ u.u[i] <<= 4;
+ if (isdigit((unsigned char) *s))
+ u.u[i] |= *s - '0';
+ else if ('a' <= *s && *s <= 'f')
+ u.u[i] |= *s - 'a' + 10;
+ else if ('A' <= *s && *s <= 'F')
+ u.u[i] |= *s - 'A' + 10;
+ else
+ goto bailout;
+ s++;
+ j++;
+ }
+ if (*s != 0)
+ goto bailout;
+ **retval = u;
+ return (ssize_t) (s - svalue);
+
+ bailout:
+ **retval = uuid_nil;
+ return -1;
+}
+
+static BUN
+UUIDhash(const void *v)
+{
+ return mix_uuid(*(const uuid *) v);
+}
+
+static void *
+UUIDread(void *U, size_t *dstlen, stream *s, size_t cnt)
+{
+ uuid *u = U;
+ if (u == NULL || *dstlen < cnt * sizeof(uuid)) {
+ if ((u = GDKrealloc(u, cnt * sizeof(uuid))) == NULL)
+ return NULL;
+ *dstlen = cnt * sizeof(uuid);
+ }
+ if (mnstr_read(s, u, UUID_SIZE, cnt) < (ssize_t) cnt) {
+ if (u != U)
+ GDKfree(u);
+ return NULL;
+ }
+ return u;
+}
+
+static gdk_return
+UUIDwrite(const void *u, stream *s, size_t cnt)
+{
+ return mnstr_write(s, u, UUID_SIZE, cnt) ? GDK_SUCCEED : GDK_FAIL;
+}
+
+static ssize_t
+UUIDtoString(str *retval, size_t *len, const void *VALUE, bool external)
+{
+ const uuid *value = VALUE;
+ if (*len <= UUID_STRLEN || *retval == NULL) {
+ if (*retval)
+ GDKfree(*retval);
+ if ((*retval = GDKmalloc(UUID_STRLEN + 1)) == NULL)
+ return -1;
+ *len = UUID_STRLEN + 1;
+ }
+ if (is_uuid_nil(*value)) {
+ if (external) {
+ return (ssize_t) strcpy_len(*retval, "nil", 4);
+ }
+ return (ssize_t) strcpy_len(*retval, str_nil, 2);
+ }
+#ifdef HAVE_UUID
+ uuid_unparse_lower(value->u, *retval);
+#else
+ snprintf(*retval, *len,
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x"
+ "-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ value->u[0], value->u[1], value->u[2], value->u[3],
+ value->u[4], value->u[5], value->u[6], value->u[7],
+ value->u[8], value->u[9], value->u[10], value->u[11],
+ value->u[12], value->u[13], value->u[14],
value->u[15]);
+#endif
+ assert(strlen(*retval) == UUID_STRLEN);
+ return UUID_STRLEN;
+}
+
atomDesc BATatoms[MAXATOMS] = {
[TYPE_void] = {
.name = "void",
@@ -1472,6 +1609,19 @@ atomDesc BATatoms[MAXATOMS] = {
.atomCmp = (int (*)(const void *, const void *)) lngCmp,
.atomHash = (BUN (*)(const void *)) lngHash,
},
+ [TYPE_uuid] = {
+ .name = "uuid",
+ .storage = TYPE_uuid,
+ .linear = true,
+ .size = sizeof(uuid),
+ .atomNull = (void *) &uuid_nil,
+ .atomFromStr = UUIDfromString,
+ .atomToStr = UUIDtoString,
+ .atomRead = UUIDread,
+ .atomWrite = UUIDwrite,
+ .atomCmp = UUIDcompare,
+ .atomHash = UUIDhash,
+ },
[TYPE_str] = {
.name = "str",
.storage = TYPE_str,
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -194,6 +194,7 @@ gdk_export const hge hge_nil;
gdk_export const oid oid_nil;
gdk_export const char str_nil[2];
gdk_export const ptr ptr_nil;
+gdk_export const uuid uuid_nil;
/* derived NIL values - OIDDEPEND */
#define bit_nil ((bit) bte_nil)
@@ -223,6 +224,12 @@ gdk_export const ptr ptr_nil;
#define isfinite(x) _finite(x)
#endif
+#ifdef HAVE_UUID
+#define is_uuid_nil(x) uuid_is_null((x).u)
+#else
+#define is_uuid_nil(x) (memcmp((x).u, uuid_nil.u, UUID_SIZE) == 0)
+#endif
+
/*
* @- Derived types
* In all algorithms across GDK, you will find switches on the types
@@ -321,11 +328,13 @@ ATOMputFIX(int type, void *dst, const vo
case 8:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list