--- uuid.c 2006/05/11 18:32:07 1.4
+++ uuid.c 2006/07/20 17:21:17 1.5
@@ -73,45 +73,35 @@
size_t len;
/* sanity check input argument */
- if ((uuid_str = PG_GETARG_CSTRING(0)) == NULL) {
+ if ((uuid_str = PG_GETARG_CSTRING(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID string")));
- PG_RETURN_NULL();
- }
- if ((len = strlen(uuid_str)) != UUID_LEN_STR) {
+ if ((len = strlen(uuid_str)) != UUID_LEN_STR)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID string length %d (expected %d)", len, UUID_LEN_STR)));
- PG_RETURN_NULL();
- }
/* import as string representation */
- if ((rc = uuid_create(&uuid)) != UUID_RC_OK) {
+ if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID object: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
if ((rc = uuid_import(uuid, UUID_FMT_STR, uuid_str, len)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to import UUID string representation: %s", uuid_error(rc))));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
/* export as binary representation */
if ((uuid_datum = (uuid_datum_t *)palloc(sizeof(uuid_datum_t))) == NULL) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to allocate UUID datum")));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
vp = &(uuid_datum->uuid_bin);
len = sizeof(uuid_datum->uuid_bin);
if ((rc = uuid_export(uuid, UUID_FMT_BIN, &vp, &len)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to export UUID binary representation: %s", uuid_error(rc))));
- uuid_destroy(uuid);
- pfree(uuid_datum);
- PG_RETURN_NULL();
}
uuid_destroy(uuid);
@@ -131,39 +121,31 @@
size_t len;
/* sanity check input argument */
- if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL) {
+ if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID datum")));
- PG_RETURN_NULL();
- }
/* import as binary representation */
- if ((rc = uuid_create(&uuid)) != UUID_RC_OK) {
+ if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID object: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
if ((rc = uuid_import(uuid, UUID_FMT_BIN, uuid_datum->uuid_bin, sizeof(uuid_datum->uuid_bin))) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to import UUID binary representation: %s", uuid_error(rc))));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
/* export as string representation */
len = UUID_LEN_STR+1;
if ((vp = uuid_str = (char *)palloc(len)) == NULL) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to allocate UUID string")));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
if ((rc = uuid_export(uuid, UUID_FMT_STR, &vp, &len)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to export UUID string representation: %s", uuid_error(rc))));
- uuid_destroy(uuid);
- pfree(uuid_datum);
- PG_RETURN_NULL();
}
uuid_destroy(uuid);
@@ -179,23 +161,17 @@
uuid_datum_t *uuid_datum;
/* sanity check input argument */
- if ((uuid_internal = (StringInfo)PG_GETARG_POINTER(0)) == NULL) {
+ if ((uuid_internal = (StringInfo)PG_GETARG_POINTER(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID StringInfo object")));
- PG_RETURN_NULL();
- }
- if (uuid_internal->len != UUID_LEN_BIN) {
+ if (uuid_internal->len != UUID_LEN_BIN)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID binary length %d (expected %d)", uuid_internal->len, UUID_LEN_BIN)));
- PG_RETURN_NULL();
- }
/* import as binary representation */
- if ((uuid_datum = (uuid_datum_t *)palloc(sizeof(uuid_datum_t))) == NULL) {
+ if ((uuid_datum = (uuid_datum_t *)palloc(sizeof(uuid_datum_t))) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to allocate UUID datum")));
- PG_RETURN_NULL();
- }
memcpy(uuid_datum->uuid_bin, uuid_internal->data, uuid_internal->len);
/* return UUID datum */
@@ -210,18 +186,14 @@
bytea *uuid_bytea;
/* sanity check input argument */
- if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL) {
+ if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID datum")));
- PG_RETURN_NULL();
- }
/* export as binary representation */
- if ((uuid_bytea = (bytea *)palloc(VARHDRSZ + UUID_LEN_BIN)) == NULL) {
+ if ((uuid_bytea = (bytea *)palloc(VARHDRSZ + UUID_LEN_BIN)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to allocate UUID bytea")));
- PG_RETURN_NULL();
- }
uuid_bytea->vl_len = VARHDRSZ + UUID_LEN_BIN;
memcpy(uuid_bytea->vl_dat, uuid_datum->uuid_bin, UUID_LEN_BIN);
@@ -237,7 +209,7 @@
uuid_t *uuid_ns;
uuid_rc_t rc;
int version;
- unsigned int mode;
+ unsigned int mode = 0;
uuid_datum_t *uuid_datum;
char *str_ns;
char *str_name;
@@ -251,80 +223,61 @@
case 3: mode = UUID_MAKE_V3; break;
case 4: mode = UUID_MAKE_V4; break;
case 5: mode = UUID_MAKE_V5; break;
- default: {
+ default:
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID version %d (expected 1, 3, 4 or 5)", version)));
- PG_RETURN_NULL();
- }
}
if ( ((mode & (UUID_MAKE_V1|UUID_MAKE_V4)) && PG_NARGS() != 1)
- || ((mode & (UUID_MAKE_V3|UUID_MAKE_V5)) && PG_NARGS() != 3)) {
+ || ((mode & (UUID_MAKE_V3|UUID_MAKE_V5)) && PG_NARGS() != 3))
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid number (%d) of arguments", PG_NARGS())));
- PG_RETURN_NULL();
- }
/* make a new UUID */
- if ((rc = uuid_create(&uuid)) != UUID_RC_OK) {
+ if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID object: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
if (version == 3 || version == 5) {
- if ((str_ns = PG_GETARG_CSTRING(1)) == NULL) {
+ if ((str_ns = PG_GETARG_CSTRING(1)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid namespace UUID string")));
- PG_RETURN_NULL();
- }
- if ((str_name = PG_GETARG_CSTRING(2)) == NULL) {
+ if ((str_name = PG_GETARG_CSTRING(2)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid name string")));
- PG_RETURN_NULL();
- }
- if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK) {
+ if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID namespace object: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
if ((rc = uuid_load(uuid_ns, str_ns)) != UUID_RC_OK) {
- if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, str_ns, strlen(str_ns))) != UUID_RC_OK) {
+ if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, str_ns, strlen(str_ns))) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to import UUID namespace: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
}
if ((rc = uuid_make(uuid, mode, uuid_ns, str_name)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to make v%d UUID: %s", version, uuid_error(rc))));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
uuid_destroy(uuid_ns);
}
else {
if ((rc = uuid_make(uuid, mode)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to make v%d UUID: %s", version, uuid_error(rc))));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
}
/* export as binary representation */
if ((uuid_datum = (uuid_datum_t *)palloc(sizeof(uuid_datum_t))) == NULL) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to allocate UUID datum")));
- uuid_destroy(uuid);
- PG_RETURN_NULL();
}
vp = &(uuid_datum->uuid_bin);
len = sizeof(uuid_datum->uuid_bin);
if ((rc = uuid_export(uuid, UUID_FMT_BIN, &vp, &len)) != UUID_RC_OK) {
+ uuid_destroy(uuid);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to export UUID binary representation: %s", uuid_error(rc))));
- uuid_destroy(uuid);
- pfree(uuid_datum);
- PG_RETURN_NULL();
}
uuid_destroy(uuid);
PG_RETURN_POINTER(uuid_datum);
@@ -337,11 +290,9 @@
uuid_datum_t *uuid_datum;
/* sanity check input argument */
- if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL) {
+ if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid UUID datum argument")));
- PG_RETURN_NULL();
- }
/* return hash value of the UUID */
PG_RETURN_INT32(hash_any(uuid_datum->uuid_bin, sizeof(uuid_datum->uuid_bin)));
@@ -358,49 +309,41 @@
int result;
/* sanity check input argument */
- if ((uuid_datum1 = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL) {
+ if ((uuid_datum1 = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid first UUID datum argument")));
- PG_RETURN_NULL();
- }
- if ((uuid_datum2 = (uuid_datum_t *)PG_GETARG_POINTER(1)) == NULL) {
+ if ((uuid_datum2 = (uuid_datum_t *)PG_GETARG_POINTER(1)) == NULL)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid second UUID datum argument")));
- PG_RETURN_NULL();
- }
/* load both UUIDs */
- if ((rc = uuid_create(&uuid1)) != UUID_RC_OK) {
+ if ((rc = uuid_create(&uuid1)) != UUID_RC_OK)
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID object: %s", uuid_error(rc))));
- PG_RETURN_NULL();
- }
if ((rc = uuid_create(&uuid2)) != UUID_RC_OK) {
+ uuid_destroy(uuid1);
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to create UUID object: %s", uuid_error(rc))));
- uuid_destroy(uuid1);
- PG_RETURN_NULL();
}
if ((rc = uuid_import(uuid1, UUID_FMT_BIN, uuid_datum1->uuid_bin, sizeof(uuid_datum1->uuid_bin))) != UUID_RC_OK) {
- ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
- errmsg("failed to import UUID: %s", uuid_error(rc))));
uuid_destroy(uuid1);
uuid_destroy(uuid2);
- PG_RETURN_NULL();
- }
- if ((rc = uuid_import(uuid2, UUID_FMT_BIN, uuid_datum2->uuid_bin, sizeof(uuid_datum2->uuid_bin))) != UUID_RC_OK) {
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
errmsg("failed to import UUID: %s", uuid_error(rc))));
+ }
+ if ((rc = uuid_import(uuid2, UUID_FMT_BIN, uuid_datum2->uuid_bin, sizeof(uuid_datum2->uuid_bin))) != UUID_RC_OK) {
uuid_destroy(uuid1);
uuid_destroy(uuid2);
- PG_RETURN_NULL();
+ ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
+ errmsg("failed to import UUID: %s", uuid_error(rc))));
}
/* compare UUIDs */
if ((rc = uuid_compare(uuid1, uuid2, &result)) != UUID_RC_OK) {
uuid_destroy(uuid1);
uuid_destroy(uuid2);
- PG_RETURN_NULL();
+ ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
+ errmsg("failed to compare UUID objects: %s", uuid_error(rc))));
}
/* cleanup */
|