]> granicus.if.org Git - postgresql/commitdiff
Assume deconstruct_array() outputs are untoasted.
authorNoah Misch <noah@leadboat.com>
Sun, 12 Mar 2017 23:35:31 +0000 (19:35 -0400)
committerNoah Misch <noah@leadboat.com>
Sun, 12 Mar 2017 23:35:31 +0000 (19:35 -0400)
In functions that issue a deconstruct_array() call, consistently use
plain VARSIZE()/VARDATA() on the array elements.  Prior practice was
divided between those and VARSIZE_ANY_EXHDR()/VARDATA_ANY().

contrib/hstore/hstore_io.c
src/backend/access/common/reloptions.c
src/backend/utils/adt/jsonb_gin.c
src/backend/utils/adt/jsonfuncs.c
src/backend/utils/adt/pg_upgrade_support.c
src/backend/utils/adt/tsvector_op.c

index 0c1d99a0150f656088e725bc44e905c5d6fa27b0..1cecf8600489ad5b3d51a20f93b85234fe08e03c 100644 (file)
@@ -611,19 +611,22 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
 
                if (!value_nulls || value_nulls[i])
                {
-                       pairs[i].key = VARDATA_ANY(key_datums[i]);
+                       pairs[i].key = VARDATA(key_datums[i]);
                        pairs[i].val = NULL;
-                       pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(key_datums[i]));
+                       pairs[i].keylen =
+                               hstoreCheckKeyLen(VARSIZE(key_datums[i]) - VARHDRSZ);
                        pairs[i].vallen = 4;
                        pairs[i].isnull = true;
                        pairs[i].needfree = false;
                }
                else
                {
-                       pairs[i].key = VARDATA_ANY(key_datums[i]);
-                       pairs[i].val = VARDATA_ANY(value_datums[i]);
-                       pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(key_datums[i]));
-                       pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(value_datums[i]));
+                       pairs[i].key = VARDATA(key_datums[i]);
+                       pairs[i].val = VARDATA(value_datums[i]);
+                       pairs[i].keylen =
+                               hstoreCheckKeyLen(VARSIZE(key_datums[i]) - VARHDRSZ);
+                       pairs[i].vallen =
+                               hstoreCheckValLen(VARSIZE(value_datums[i]) - VARHDRSZ);
                        pairs[i].isnull = false;
                        pairs[i].needfree = false;
                }
@@ -704,19 +707,22 @@ hstore_from_array(PG_FUNCTION_ARGS)
 
                if (in_nulls[i * 2 + 1])
                {
-                       pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
+                       pairs[i].key = VARDATA(in_datums[i * 2]);
                        pairs[i].val = NULL;
-                       pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
+                       pairs[i].keylen =
+                               hstoreCheckKeyLen(VARSIZE(in_datums[i * 2]) - VARHDRSZ);
                        pairs[i].vallen = 4;
                        pairs[i].isnull = true;
                        pairs[i].needfree = false;
                }
                else
                {
-                       pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
-                       pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]);
-                       pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
-                       pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1]));
+                       pairs[i].key = VARDATA(in_datums[i * 2]);
+                       pairs[i].val = VARDATA(in_datums[i * 2 + 1]);
+                       pairs[i].keylen =
+                               hstoreCheckKeyLen(VARSIZE(in_datums[i * 2]) - VARHDRSZ);
+                       pairs[i].vallen =
+                               hstoreCheckValLen(VARSIZE(in_datums[i * 2 + 1]) - VARHDRSZ);
                        pairs[i].isnull = false;
                        pairs[i].needfree = false;
                }
index c50649135fb2e7e4d416d8c9d798ee3089bdfe65..72e12532ab2934b9e6995f5a41f1600ea5fdf547 100644 (file)
@@ -760,9 +760,8 @@ transformRelOptions(Datum oldOptions, List *defList, char *namspace,
 
                for (i = 0; i < noldoptions; i++)
                {
-                       text       *oldoption = DatumGetTextP(oldoptions[i]);
-                       char       *text_str = VARDATA(oldoption);
-                       int                     text_len = VARSIZE(oldoption) - VARHDRSZ;
+                       char       *text_str = VARDATA(oldoptions[i]);
+                       int                     text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
 
                        /* Search for a match in defList */
                        foreach(cell, defList)
@@ -1055,9 +1054,8 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
 
                for (i = 0; i < noptions; i++)
                {
-                       text       *optiontext = DatumGetTextP(optiondatums[i]);
-                       char       *text_str = VARDATA(optiontext);
-                       int                     text_len = VARSIZE(optiontext) - VARHDRSZ;
+                       char       *text_str = VARDATA(optiondatums[i]);
+                       int                     text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
                        int                     j;
 
                        /* Search for a match in reloptions */
index 16ee6a22d3b4833595fc444efca8ca5a51c659a2..8e8e8fd850a5d9d0001e33b6bbd9579f4c30f4f7 100644 (file)
@@ -172,8 +172,8 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
                        if (key_nulls[i])
                                continue;
                        entries[j++] = make_text_key(JGINFLAG_KEY,
-                                                                                VARDATA_ANY(key_datums[i]),
-                                                                                VARSIZE_ANY_EXHDR(key_datums[i]));
+                                                                                VARDATA(key_datums[i]),
+                                                                                VARSIZE(key_datums[i]) - VARHDRSZ);
                }
 
                *nentries = j;
index 6a7aab2f432e44d70520f1725bb14463f94ac293..9b46f8e8359f2a8fc9b40e3392b993bdd0a324d0 100644 (file)
@@ -1240,8 +1240,8 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
                {
                        jbvp = findJsonbValueFromContainerLen(container,
                                                                                                  JB_FOBJECT,
-                                                                                                 VARDATA_ANY(pathtext[i]),
-                                                                                        VARSIZE_ANY_EXHDR(pathtext[i]));
+                                                                                                 VARDATA(pathtext[i]),
+                                                                                       VARSIZE(pathtext[i]) - VARHDRSZ);
                }
                else if (have_array)
                {
index 282b2649ffc436e6a48b8bd002c957047fdc69b5..4b340055f0f95903e1c0825ddd7682abf6181f6e 100644 (file)
@@ -163,8 +163,7 @@ binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
                                                  &textDatums, NULL, &ndatums);
                for (i = 0; i < ndatums; i++)
                {
-                       text       *txtname = DatumGetTextPP(textDatums[i]);
-                       char       *extName = text_to_cstring(txtname);
+                       char       *extName = TextDatumGetCString(textDatums[i]);
                        Oid                     extOid = get_extension_oid(extName, false);
 
                        requiredExtensions = lappend_oid(requiredExtensions, extOid);
index b0f0ce05c591f3fc8276d2e31daaa790490341c3..3dab84a887f5327f53fc851b4e7edf42e046f663 100644 (file)
@@ -323,7 +323,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
                                         errmsg("lexeme array may not contain nulls")));
 
                lex = VARDATA(dlexemes[i]);
-               lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]);
+               lex_len = VARSIZE(dlexemes[i]) - VARHDRSZ;
                lex_pos = tsvector_bsearch(tsout, lex, lex_len);
 
                if (lex_pos >= 0 && (j = POSDATALEN(tsout, entry + lex_pos)) != 0)
@@ -609,8 +609,8 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
                                        (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                                         errmsg("lexeme array may not contain nulls")));
 
-               lex = VARDATA_ANY(dlexemes[i]);
-               lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]);
+               lex = VARDATA(dlexemes[i]);
+               lex_len = VARSIZE(dlexemes[i]) - VARHDRSZ;
                lex_pos = tsvector_bsearch(tsin, lex, lex_len);
 
                if (lex_pos >= 0)
@@ -793,7 +793,7 @@ array_to_tsvector(PG_FUNCTION_ARGS)
 
        /* Calculate space needed for surviving lexemes. */
        for (i = 0; i < nitems; i++)
-               datalen += VARSIZE_ANY_EXHDR(dlexemes[i]);
+               datalen += VARSIZE(dlexemes[i]) - VARHDRSZ;
        tslen = CALCDATASIZE(nitems, datalen);
 
        /* Allocate and fill tsvector. */
@@ -805,8 +805,8 @@ array_to_tsvector(PG_FUNCTION_ARGS)
        cur = STRPTR(tsout);
        for (i = 0; i < nitems; i++)
        {
-               char       *lex = VARDATA_ANY(dlexemes[i]);
-               int                     lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]);
+               char       *lex = VARDATA(dlexemes[i]);
+               int                     lex_len = VARSIZE(dlexemes[i]) - VARHDRSZ;
 
                memcpy(cur, lex, lex_len);
                arrout[i].haspos = 0;