diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-25 22:42:46 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-25 22:42:46 +0000 |
commit | 220db7ccd8c88aafea4629f00e8be6f9f073ed00 (patch) | |
tree | 772c9dca19736eb9d417cb665a281686c3570b4c /src/backend/utils/adt/acl.c | |
parent | f948197b4055bb0e22e508e9d6966217b7dbea3d (diff) | |
download | postgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.tar.gz postgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.zip |
Simplify and standardize conversions between TEXT datums and ordinary C
strings. This patch introduces four support functions cstring_to_text,
cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and
two macros CStringGetTextDatum and TextDatumGetCString. A number of
existing macros that provided variants on these themes were removed.
Most of the places that need to make such conversions now require just one
function or macro call, in place of the multiple notational layers that used
to be needed. There are no longer any direct calls of textout or textin,
and we got most of the places that were using handmade conversions via
memcpy (there may be a few still lurking, though).
This commit doesn't make any serious effort to eliminate transient memory
leaks caused by detoasting toasted text objects before they reach
text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few
places where it was easy, but much more could be done.
Brendan Jurd and Tom Lane
Diffstat (limited to 'src/backend/utils/adt/acl.c')
-rw-r--r-- | src/backend/utils/adt/acl.c | 66 |
1 files changed, 14 insertions, 52 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 65d7794b4e4..3cf54e58750 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.139 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.140 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1313,10 +1313,7 @@ makeaclitem(PG_FUNCTION_ARGS) static AclMode convert_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); if (pg_strcasecmp(priv_type, "SELECT") == 0) return ACL_SELECT; @@ -1526,10 +1523,7 @@ convert_table_name(text *tablename) static AclMode convert_table_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -1736,12 +1730,9 @@ has_database_privilege_id_id(PG_FUNCTION_ARGS) static Oid convert_database_name(text *databasename) { - char *dbname; + char *dbname = text_to_cstring(databasename); Oid oid; - dbname = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(databasename))); - oid = get_database_oid(dbname); if (!OidIsValid(oid)) ereport(ERROR, @@ -1758,10 +1749,7 @@ convert_database_name(text *databasename) static AclMode convert_database_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -1953,12 +1941,9 @@ has_function_privilege_id_id(PG_FUNCTION_ARGS) static Oid convert_function_name(text *functionname) { - char *funcname; + char *funcname = text_to_cstring(functionname); Oid oid; - funcname = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(functionname))); - oid = DatumGetObjectId(DirectFunctionCall1(regprocedurein, CStringGetDatum(funcname))); @@ -1977,10 +1962,7 @@ convert_function_name(text *functionname) static AclMode convert_function_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -2157,12 +2139,9 @@ has_language_privilege_id_id(PG_FUNCTION_ARGS) static Oid convert_language_name(text *languagename) { - char *langname; + char *langname = text_to_cstring(languagename); Oid oid; - langname = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(languagename))); - oid = GetSysCacheOid(LANGNAME, CStringGetDatum(langname), 0, 0, 0); @@ -2181,10 +2160,7 @@ convert_language_name(text *languagename) static AclMode convert_language_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -2361,12 +2337,9 @@ has_schema_privilege_id_id(PG_FUNCTION_ARGS) static Oid convert_schema_name(text *schemaname) { - char *nspname; + char *nspname = text_to_cstring(schemaname); Oid oid; - nspname = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(schemaname))); - oid = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(nspname), 0, 0, 0); @@ -2385,10 +2358,7 @@ convert_schema_name(text *schemaname) static AclMode convert_schema_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -2569,11 +2539,9 @@ has_tablespace_privilege_id_id(PG_FUNCTION_ARGS) static Oid convert_tablespace_name(text *tablespacename) { - char *spcname; + char *spcname = text_to_cstring(tablespacename); Oid oid; - spcname = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(tablespacename))); oid = get_tablespace_oid(spcname); if (!OidIsValid(oid)) @@ -2591,10 +2559,7 @@ convert_tablespace_name(text *tablespacename) static AclMode convert_tablespace_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string @@ -2777,10 +2742,7 @@ pg_has_role_id_id(PG_FUNCTION_ARGS) static AclMode convert_role_priv_string(text *priv_type_text) { - char *priv_type; - - priv_type = DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(priv_type_text))); + char *priv_type = text_to_cstring(priv_type_text); /* * Return mode from priv_type string |