Changeset: 24cfde8f843c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=24cfde8f843c
Removed Files:
monetdb5/modules/atoms/uuid.h
Modified Files:
monetdb5/modules/atoms/Makefile.ag
monetdb5/modules/atoms/uuid.c
monetdb5/modules/mal/json_util.c
Branch: default
Log Message:
Fixes to uuid atom code.
Properly allocate and free memory.
Properly indent.
Note that the uuid atom should use a fixed-sized atom and not a string
for its implementation.
Also note that the uuid atom will be removed form the Jan2014 branch.
diffs (243 lines):
diff --git a/monetdb5/modules/atoms/Makefile.ag
b/monetdb5/modules/atoms/Makefile.ag
--- a/monetdb5/modules/atoms/Makefile.ag
+++ b/monetdb5/modules/atoms/Makefile.ag
@@ -36,7 +36,7 @@ lib_atoms = {
str.c str.h \
url.c url.h \
json_atom.c json_atom.h \
- uuid.c uuid.h \
+ uuid.c \
mcurl.c \
xml.c xml.h
}
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -3,14 +3,14 @@
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.monetdb.org/Legal/MonetDBLicense
- *
+ *
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
- *
+ *
* The Original Code is the MonetDB Database System.
- *
+ *
* The Initial Developer of the Original Code is CWI.
* Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
* Copyright August 2008-2013 MonetDB B.V.
@@ -25,11 +25,26 @@
*/
#include "monetdb_config.h"
-#include "uuid.h"
#include "mal.h"
#include "mal_exception.h"
#include "muuid.h"
+typedef str uuid;
+
+#ifdef WIN32
+#define uuid_export extern __declspec(dllexport)
+#else
+#define uuid_export extern
+#endif
+
+uuid_export int UUIDtoString(str *retval, int *len, str handle);
+uuid_export int UUIDfromString(char *svalue, int *len, str *retval);
+uuid_export str UUIDgenerateUuid(str *retval);
+uuid_export str UUIDstr2uuid(str *retval, str *s);
+uuid_export str UUIDuuid2str(str *retval, str *s);
+uuid_export str UUIDisaUUID(bit *retval, str *s);
+uuid_export str UUIDequal(bit *retval, str *l, str *r);
+
#define UUID_LEN 36
/**
* Returns the string representation of the given uuid value.
@@ -39,17 +54,18 @@
int
UUIDtoString(str *retval, int *len, str value)
{
- if (*len < UUID_LEN) {
+ if (*len <= UUID_LEN) {
if (*retval != NULL)
GDKfree(*retval);
- *retval = GDKmalloc(sizeof(str) * (*len = UUID_LEN));
+ *len = UUID_LEN + 1;
+ *retval = GDKmalloc(*len + 1);
}
- if (value == str_nil) {
- *len = snprintf(*retval, *len, "(nil)");
+ if (strcmp(value, str_nil) == 0) {
+ snprintf(*retval, *len, "nil");
} else {
strncpy(*retval, value, UUID_LEN);
(*retval)[UUID_LEN] = 0;
- *len = UUID_LEN;
+ *len = UUID_LEN + 1;
}
return(*len);
}
@@ -73,50 +89,61 @@ UUIDfromString(char *svalue, int *len, s
}
static str
-uuid_GenerateUuid(str *retval) {
- str d;
- char * s;
+uuid_GenerateUuid(str *retval)
+{
+ str d;
+ char * s;
- s = generateUUID();
- if ( s == NULL)
- throw(MAL, "uuid.generateUuid", "Allocation failed");
- d = GDKstrdup(s);
+ s = generateUUID();
+ if (s == NULL)
+ throw(MAL, "uuid.generateUuid", "Allocation failed");
+ d = GDKstrdup(s);
+ free(s);
- if (d == NULL)
- throw(MAL, "uuid.generateUuid", "Allocation failed");
+ if (d == NULL)
+ throw(MAL, "uuid.generateUuid", "Allocation failed");
- *retval = d;
- free(s);
- return MAL_SUCCEED;
+ *retval = d;
+ return MAL_SUCCEED;
}
str
-UUIDgenerateUuid(str *retval) {
- return uuid_GenerateUuid(retval);
+UUIDgenerateUuid(str *retval)
+{
+ return uuid_GenerateUuid(retval);
}
str
-UUIDisaUUID(bit *retval, str *s) {
- *retval = strlen(*s) == UUID_LEN;
- return MAL_SUCCEED;
+UUIDisaUUID(bit *retval, str *s)
+{
+ *retval = strlen(*s) == UUID_LEN;
+ return MAL_SUCCEED;
}
str
-UUIDstr2uuid(str *retval, str *s) {
- bit b=0;
- str msg = UUIDisaUUID(&b, s);
- if ( msg != MAL_SUCCEED)
- return msg;
- if ( b== 0)
- throw(MAL,"uuid.uuid","Inconsistent UUID length");
- *retval = GDKstrdup(*s);
- return MAL_SUCCEED;
+UUIDstr2uuid(str *retval, str *s)
+{
+ bit b=0;
+ str msg;
+
+ if (strcmp(*s, "nil") == 0) {
+ *retval = GDKstrdup(str_nil);
+ return MAL_SUCCEED;
+ }
+ msg = UUIDisaUUID(&b, s);
+ if (msg != MAL_SUCCEED)
+ return msg;
+ if (b == 0)
+ throw(MAL,"uuid.uuid","Inconsistent UUID length");
+ *retval = GDKstrdup(*s);
+ return MAL_SUCCEED;
}
str
-UUIDuuid2str(str *retval, str *s) {
- *retval = GDKstrdup(*s);
- return MAL_SUCCEED;
+UUIDuuid2str(str *retval, str *s)
+{
+ *retval = GDKstrdup(*s);
+ return MAL_SUCCEED;
}
str
diff --git a/monetdb5/modules/atoms/uuid.h b/monetdb5/modules/atoms/uuid.h
deleted file mode 100644
--- a/monetdb5/modules/atoms/uuid.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The contents of this file are subject to the MonetDB Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.monetdb.org/Legal/MonetDBLicense
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is the MonetDB Database System.
- *
- * The Initial Developer of the Original Code is CWI.
- * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
- * Copyright August 2008-2013 MonetDB B.V.
- * All Rights Reserved.
-*/
-/*
- * @-
- * Wrapper around uuid library
- */
-#ifndef AUUID_H
-#define AUUID_H
-
-#include <gdk.h>
-#include <ctype.h>
-
-typedef str uuid;
-
-#ifdef WIN32
-#if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) &&
!defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) &&
!defined(LIBMONETDB5)
-#define uuid_export extern __declspec(dllimport)
-#else
-#define uuid_export extern __declspec(dllexport)
-#endif
-#else
-#define uuid_export extern
-#endif
-
-uuid_export int UUIDtoString(str *retval, int *len, str handle);
-uuid_export int UUIDfromString(char *svalue, int *len, str *retval);
-uuid_export str UUIDgenerateUuid(str *retval);
-uuid_export str UUIDstr2uuid(str *retval, str *s);
-uuid_export str UUIDuuid2str(str *retval, str *s);
-uuid_export str UUIDisaUUID(bit *retval, str *s);
-uuid_export str UUIDequal(bit *retval, str *l, str *r);
-
-#endif /* AUUID_H */
diff --git a/monetdb5/modules/mal/json_util.c b/monetdb5/modules/mal/json_util.c
--- a/monetdb5/modules/mal/json_util.c
+++ b/monetdb5/modules/mal/json_util.c
@@ -58,8 +58,7 @@ JSONresultSet(str *res, bat *uuid, bat *
BBPreleaseref(bj->batCacheid);
throw(MAL, "json.resultset", MAL_MALLOC_FAIL);
}
- snprintf(result,sz,"[");
- len += strlen(result);
+ len += snprintf(result,sz,"[");
/* here the dirty work follows */
/* loop over the triple store */
snprintf(result+len,sz-len,"]");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list