44 *
55 * Copyright (c) 2007 PostgreSQL Global Development Group
66 *
7- * $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.5 2007/11/15 22:25:14 momjian Exp $
7+ * $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.6 2007/12/31 03:55:50 alvherre Exp $
88 *
99 *-------------------------------------------------------------------------
1010 */
@@ -64,15 +64,32 @@ PG_FUNCTION_INFO_V1(uuid_generate_v3);
6464PG_FUNCTION_INFO_V1 (uuid_generate_v4 );
6565PG_FUNCTION_INFO_V1 (uuid_generate_v5 );
6666
67+ static void
68+ pguuid_complain (uuid_rc_t rc )
69+ {
70+ char * err = uuid_error (rc );
71+
72+ if (err != NULL )
73+ ereport (ERROR ,
74+ (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
75+ errmsg ("OSSP uuid library failure: %s" ,err )));
76+ else
77+ ereport (ERROR ,
78+ (errcode (ERRCODE_EXTERNAL_ROUTINE_EXCEPTION ),
79+ errmsg ("OSSP uuid library failure: error code %d" ,rc )));
80+ }
6781
6882static char *
6983uuid_to_string (const uuid_t * uuid )
7084{
7185char * buf = palloc (UUID_LEN_STR + 1 );
7286void * ptr = buf ;
7387size_t len = UUID_LEN_STR + 1 ;
88+ uuid_rc_t rc ;
7489
75- uuid_export (uuid ,UUID_FMT_STR ,& ptr ,& len );
90+ rc = uuid_export (uuid ,UUID_FMT_STR ,& ptr ,& len );
91+ if (rc != UUID_RC_OK )
92+ pguuid_complain (rc );
7693
7794return buf ;
7895}
@@ -81,7 +98,11 @@ uuid_to_string(const uuid_t * uuid)
8198static void
8299string_to_uuid (const char * str ,uuid_t * uuid )
83100{
84- uuid_import (uuid ,UUID_FMT_STR ,str ,UUID_LEN_STR + 1 );
101+ uuid_rc_t rc ;
102+
103+ rc = uuid_import (uuid ,UUID_FMT_STR ,str ,UUID_LEN_STR + 1 );
104+ if (rc != UUID_RC_OK )
105+ pguuid_complain (rc );
85106}
86107
87108
@@ -90,11 +111,18 @@ special_uuid_value(const char *name)
90111{
91112uuid_t * uuid ;
92113char * str ;
93-
94- uuid_create (& uuid );
95- uuid_load (uuid ,name );
114+ uuid_rc_t rc ;
115+
116+ rc = uuid_create (& uuid );
117+ if (rc != UUID_RC_OK )
118+ pguuid_complain (rc );
119+ rc = uuid_load (uuid ,name );
120+ if (rc != UUID_RC_OK )
121+ pguuid_complain (rc );
96122str = uuid_to_string (uuid );
97- uuid_destroy (uuid );
123+ rc = uuid_destroy (uuid );
124+ if (rc != UUID_RC_OK )
125+ pguuid_complain (rc );
98126
99127return DirectFunctionCall1 (uuid_in ,CStringGetDatum (str ));
100128}
@@ -140,11 +168,18 @@ uuid_generate_internal(int mode, const uuid_t * ns, const char *name)
140168{
141169uuid_t * uuid ;
142170char * str ;
143-
144- uuid_create (& uuid );
145- uuid_make (uuid ,mode ,ns ,name );
171+ uuid_rc_t rc ;
172+
173+ rc = uuid_create (& uuid );
174+ if (rc != UUID_RC_OK )
175+ pguuid_complain (rc );
176+ rc = uuid_make (uuid ,mode ,ns ,name );
177+ if (rc != UUID_RC_OK )
178+ pguuid_complain (rc );
146179str = uuid_to_string (uuid );
147- uuid_destroy (uuid );
180+ rc = uuid_destroy (uuid );
181+ if (rc != UUID_RC_OK )
182+ pguuid_complain (rc );
148183
149184return DirectFunctionCall1 (uuid_in ,CStringGetDatum (str ));
150185}
@@ -169,16 +204,21 @@ uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name)
169204{
170205uuid_t * ns_uuid ;
171206Datum result ;
207+ uuid_rc_t rc ;
172208
173- uuid_create (& ns_uuid );
209+ rc = uuid_create (& ns_uuid );
210+ if (rc != UUID_RC_OK )
211+ pguuid_complain (rc );
174212string_to_uuid (DatumGetCString (DirectFunctionCall1 (uuid_out ,UUIDPGetDatum (ns ))),
175213ns_uuid );
176214
177215result = uuid_generate_internal (mode ,
178216ns_uuid ,
179217DatumGetCString (DirectFunctionCall1 (textout ,PointerGetDatum (name ))));
180218
181- uuid_destroy (ns_uuid );
219+ rc = uuid_destroy (ns_uuid );
220+ if (rc != UUID_RC_OK )
221+ pguuid_complain (rc );
182222
183223return result ;
184224}