Skip to content
Snippets Groups Projects
Commit 74a1a2b8 authored by Neil Conway's avatar Neil Conway
Browse files

Rename the uuid_t type to pg_uuid_t, to avoid a conflict with any

definitions of uuid_t that may be provided by the system headers. This
should hopefully fix the Win32 build problems reported by Magnus.
parent cd47d0f7
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2007, PostgreSQL Global Development Group * Copyright (c) 2007, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.1 2007/01/28 16:16:52 neilc Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/uuid.c,v 1.2 2007/01/28 20:25:38 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -35,50 +35,49 @@ ...@@ -35,50 +35,49 @@
/* uuid size in bytes */ /* uuid size in bytes */
#define UUID_LEN 16 #define UUID_LEN 16
/* The uuid_t type is declared as struct uuid_t in uuid.h */ /* pg_uuid_t is declared to be struct pg_uuid_t in uuid.h */
struct uuid_t struct pg_uuid_t
{ {
char data[UUID_LEN]; char data[UUID_LEN];
}; };
static void uuid_data_from_string(const char *source, unsigned char *data); static void string_to_uuid(const char *source, pg_uuid_t *uuid);
static void string_from_uuid_data(const char *fmt, const char *data, char *uuid_str); static void uuid_to_string(const char *fmt, const pg_uuid_t *uuid,
char *uuid_str);
static bool parse_uuid_string(const char *fmt, const char *chk_fmt, static bool parse_uuid_string(const char *fmt, const char *chk_fmt,
const char *source, unsigned char *data); const char *source, char *data);
static bool is_valid_format(const char *source, const char *fmt); static bool is_valid_format(const char *source, const char *fmt);
static int32 uuid_internal_cmp(uuid_t *arg1, uuid_t *arg2); static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2);
Datum Datum
uuid_in(PG_FUNCTION_ARGS) uuid_in(PG_FUNCTION_ARGS)
{ {
char *uuid_str = PG_GETARG_CSTRING(0); char *uuid_str = PG_GETARG_CSTRING(0);
uuid_t *uuid; pg_uuid_t *uuid;
uint8 data[UUID_LEN];
uuid_data_from_string(uuid_str, data); uuid = (pg_uuid_t *) palloc(sizeof(*uuid));
uuid = (uuid_t *) palloc(sizeof(uuid_t)); string_to_uuid(uuid_str, uuid);
memcpy(uuid->data, data, UUID_LEN);
PG_RETURN_UUID_P(uuid); PG_RETURN_UUID_P(uuid);
} }
Datum Datum
uuid_out(PG_FUNCTION_ARGS) uuid_out(PG_FUNCTION_ARGS)
{ {
uuid_t *uuid = (uuid_t *) PG_GETARG_POINTER(0); pg_uuid_t *uuid = PG_GETARG_UUID_P(0);
char *uuid_str; char *uuid_str;
uuid_str = (char *) palloc(PRINT_SIZE); uuid_str = (char *) palloc(PRINT_SIZE);
string_from_uuid_data(UUID_FMT1, uuid->data, uuid_str); uuid_to_string(UUID_FMT1, uuid, uuid_str);
PG_RETURN_CSTRING(uuid_str); PG_RETURN_CSTRING(uuid_str);
} }
/* string to uuid convertor by various format types */ /* string to uuid convertor by various format types */
static void static void
uuid_data_from_string(const char *source, unsigned char *data) string_to_uuid(const char *source, pg_uuid_t *uuid)
{ {
if (!parse_uuid_string(UUID_FMT1, UUID_CHK_FMT1, source, data) && if (!parse_uuid_string(UUID_FMT1, UUID_CHK_FMT1, source, uuid->data) &&
!parse_uuid_string(UUID_FMT2, UUID_CHK_FMT2, source, data) && !parse_uuid_string(UUID_FMT2, UUID_CHK_FMT2, source, uuid->data) &&
!parse_uuid_string(UUID_FMT3, UUID_CHK_FMT3, source, data)) !parse_uuid_string(UUID_FMT3, UUID_CHK_FMT3, source, uuid->data))
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
...@@ -126,7 +125,7 @@ is_valid_format(const char *source, const char *fmt) ...@@ -126,7 +125,7 @@ is_valid_format(const char *source, const char *fmt)
/* parse the uuid string to a format and return true if okay */ /* parse the uuid string to a format and return true if okay */
static bool static bool
parse_uuid_string(const char *fmt, const char *chk_fmt, parse_uuid_string(const char *fmt, const char *chk_fmt,
const char *source, unsigned char *data) const char *source, char *data)
{ {
int result = sscanf(source, fmt, int result = sscanf(source, fmt,
&data[0], &data[1], &data[2], &data[3], &data[4], &data[0], &data[1], &data[2], &data[3], &data[4],
...@@ -139,8 +138,9 @@ parse_uuid_string(const char *fmt, const char *chk_fmt, ...@@ -139,8 +138,9 @@ parse_uuid_string(const char *fmt, const char *chk_fmt,
/* create a string representation of the uuid */ /* create a string representation of the uuid */
static void static void
string_from_uuid_data(const char *fmt, const char *data, char *uuid_str) uuid_to_string(const char *fmt, const pg_uuid_t *uuid, char *uuid_str)
{ {
const char *data = uuid->data;
snprintf(uuid_str, PRINT_SIZE, fmt, snprintf(uuid_str, PRINT_SIZE, fmt,
data[0], data[1], data[2], data[3], data[4], data[0], data[1], data[2], data[3], data[4],
data[5], data[6], data[7], data[8], data[9], data[5], data[6], data[7], data[8], data[9],
...@@ -152,9 +152,9 @@ Datum ...@@ -152,9 +152,9 @@ Datum
uuid_recv(PG_FUNCTION_ARGS) uuid_recv(PG_FUNCTION_ARGS)
{ {
StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0); StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0);
uuid_t *uuid; pg_uuid_t *uuid;
uuid = (uuid_t *) palloc(UUID_LEN); uuid = (pg_uuid_t *) palloc(UUID_LEN);
memcpy(uuid->data, pq_getmsgbytes(buffer, UUID_LEN), UUID_LEN); memcpy(uuid->data, pq_getmsgbytes(buffer, UUID_LEN), UUID_LEN);
PG_RETURN_POINTER(uuid); PG_RETURN_POINTER(uuid);
} }
...@@ -162,7 +162,7 @@ uuid_recv(PG_FUNCTION_ARGS) ...@@ -162,7 +162,7 @@ uuid_recv(PG_FUNCTION_ARGS)
Datum Datum
uuid_send(PG_FUNCTION_ARGS) uuid_send(PG_FUNCTION_ARGS)
{ {
uuid_t *uuid = PG_GETARG_UUID_P(0); pg_uuid_t *uuid = PG_GETARG_UUID_P(0);
StringInfoData buffer; StringInfoData buffer;
pq_begintypsend(&buffer); pq_begintypsend(&buffer);
...@@ -171,8 +171,8 @@ uuid_send(PG_FUNCTION_ARGS) ...@@ -171,8 +171,8 @@ uuid_send(PG_FUNCTION_ARGS)
} }
/* internal uuid compare function */ /* internal uuid compare function */
static int32 static int
uuid_internal_cmp(uuid_t *arg1, uuid_t *arg2) uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
{ {
return memcmp(arg1->data, arg2->data, UUID_LEN); return memcmp(arg1->data, arg2->data, UUID_LEN);
} }
...@@ -180,8 +180,8 @@ uuid_internal_cmp(uuid_t *arg1, uuid_t *arg2) ...@@ -180,8 +180,8 @@ uuid_internal_cmp(uuid_t *arg1, uuid_t *arg2)
Datum Datum
uuid_lt(PG_FUNCTION_ARGS) uuid_lt(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) < 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) < 0);
} }
...@@ -189,8 +189,8 @@ uuid_lt(PG_FUNCTION_ARGS) ...@@ -189,8 +189,8 @@ uuid_lt(PG_FUNCTION_ARGS)
Datum Datum
uuid_le(PG_FUNCTION_ARGS) uuid_le(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) <= 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) <= 0);
} }
...@@ -198,8 +198,8 @@ uuid_le(PG_FUNCTION_ARGS) ...@@ -198,8 +198,8 @@ uuid_le(PG_FUNCTION_ARGS)
Datum Datum
uuid_eq(PG_FUNCTION_ARGS) uuid_eq(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) == 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) == 0);
} }
...@@ -207,8 +207,8 @@ uuid_eq(PG_FUNCTION_ARGS) ...@@ -207,8 +207,8 @@ uuid_eq(PG_FUNCTION_ARGS)
Datum Datum
uuid_ge(PG_FUNCTION_ARGS) uuid_ge(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) >= 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) >= 0);
} }
...@@ -216,8 +216,8 @@ uuid_ge(PG_FUNCTION_ARGS) ...@@ -216,8 +216,8 @@ uuid_ge(PG_FUNCTION_ARGS)
Datum Datum
uuid_gt(PG_FUNCTION_ARGS) uuid_gt(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) > 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) > 0);
} }
...@@ -225,8 +225,8 @@ uuid_gt(PG_FUNCTION_ARGS) ...@@ -225,8 +225,8 @@ uuid_gt(PG_FUNCTION_ARGS)
Datum Datum
uuid_ne(PG_FUNCTION_ARGS) uuid_ne(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) != 0); PG_RETURN_BOOL(uuid_internal_cmp(arg1, arg2) != 0);
} }
...@@ -235,8 +235,8 @@ uuid_ne(PG_FUNCTION_ARGS) ...@@ -235,8 +235,8 @@ uuid_ne(PG_FUNCTION_ARGS)
Datum Datum
uuid_cmp(PG_FUNCTION_ARGS) uuid_cmp(PG_FUNCTION_ARGS)
{ {
uuid_t *arg1 = PG_GETARG_UUID_P(0); pg_uuid_t *arg1 = PG_GETARG_UUID_P(0);
uuid_t *arg2 = PG_GETARG_UUID_P(1); pg_uuid_t *arg2 = PG_GETARG_UUID_P(1);
PG_RETURN_INT32(uuid_internal_cmp(arg1, arg2)); PG_RETURN_INT32(uuid_internal_cmp(arg1, arg2));
} }
...@@ -245,8 +245,8 @@ uuid_cmp(PG_FUNCTION_ARGS) ...@@ -245,8 +245,8 @@ uuid_cmp(PG_FUNCTION_ARGS)
Datum Datum
uuid_hash(PG_FUNCTION_ARGS) uuid_hash(PG_FUNCTION_ARGS)
{ {
uuid_t *key = PG_GETARG_UUID_P(0); pg_uuid_t *key = PG_GETARG_UUID_P(0);
return hash_any((unsigned char *) key, sizeof(uuid_t)); return hash_any((unsigned char *) key, sizeof(pg_uuid_t));
} }
/* cast text to uuid */ /* cast text to uuid */
...@@ -272,8 +272,8 @@ text_uuid(PG_FUNCTION_ARGS) ...@@ -272,8 +272,8 @@ text_uuid(PG_FUNCTION_ARGS)
Datum Datum
uuid_text(PG_FUNCTION_ARGS) uuid_text(PG_FUNCTION_ARGS)
{ {
uuid_t *uuid = PG_GETARG_UUID_P(0); pg_uuid_t *uuid = PG_GETARG_UUID_P(0);
Datum uuid_str = DirectFunctionCall1(uuid_out, UUIDPGetDatum(uuid)); Datum uuid_str = DirectFunctionCall1(uuid_out, UUIDPGetDatum(uuid));
PG_RETURN_DATUM(DirectFunctionCall1(textin, uuid_str)); PG_RETURN_DATUM(DirectFunctionCall1(textin, uuid_str));
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* uuid.h * uuid.h
* Header file for the "uuid" data type. * Header file for the "uuid" ADT. In C, we use the name pg_uuid_t,
* to avoid conflicts with any uuid_t type that might be defined by
* the system headers.
* *
* Copyright (c) 2007, PostgreSQL Global Development Group * Copyright (c) 2007, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/utils/uuid.h,v 1.1 2007/01/28 16:16:54 neilc Exp $ * $PostgreSQL: pgsql/src/include/utils/uuid.h,v 1.2 2007/01/28 20:25:38 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,12 +18,12 @@ ...@@ -16,12 +18,12 @@
#define UUID_LEN 16 #define UUID_LEN 16
/* opaque struct; defined in uuid.c */ /* opaque struct; defined in uuid.c */
typedef struct uuid_t uuid_t; typedef struct pg_uuid_t pg_uuid_t;
/* fmgr interface macros */ /* fmgr interface macros */
#define UUIDPGetDatum(X) PointerGetDatum(X) #define UUIDPGetDatum(X) PointerGetDatum(X)
#define PG_RETURN_UUID_P(X) return UUIDPGetDatum(X) #define PG_RETURN_UUID_P(X) return UUIDPGetDatum(X)
#define DatumGetUUIDP(X) ((uuid_t *) DatumGetPointer(X)) #define DatumGetUUIDP(X) ((pg_uuid_t *) DatumGetPointer(X))
#define PG_GETARG_UUID_P(X) DatumGetUUIDP(PG_GETARG_DATUM(X)) #define PG_GETARG_UUID_P(X) DatumGetUUIDP(PG_GETARG_DATUM(X))
#endif /* UUID_H */ #endif /* UUID_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment