summaryrefslogtreecommitdiff
path: root/src/tutorial
diff options
context:
space:
mode:
authorPavan Deolasee2017-06-14 05:42:18 +0000
committerPavan Deolasee2017-06-14 05:42:18 +0000
commit15dd5274c323fb93e4e3ea9ad2185aaaec10f79c (patch)
tree9dafb4c7f735d9429ea461dc792933af87493c33 /src/tutorial
parentdfbb88e3bbb526dcb204b456b9e5cfd9d10d0d0a (diff)
parentd5cb3bab564e0927ffac7c8729eacf181a12dd40 (diff)
Merge from PG master upto d5cb3bab564e0927ffac7c8729eacf181a12dd40
This is the result of the "git merge remotes/PGSQL/master" upto the said commit point. We have done some basic analysis, fixed compilation problems etc, but bulk of the logical problems in conflict resolution etc will be handled by subsequent commits.
Diffstat (limited to 'src/tutorial')
-rw-r--r--src/tutorial/complex.source2
-rw-r--r--src/tutorial/funcs_new.c29
-rw-r--r--src/tutorial/syscat.source2
3 files changed, 18 insertions, 15 deletions
diff --git a/src/tutorial/complex.source b/src/tutorial/complex.source
index 1d910b8b45..035c7a7d13 100644
--- a/src/tutorial/complex.source
+++ b/src/tutorial/complex.source
@@ -5,7 +5,7 @@
-- use this new type.
--
--
--- Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+-- Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
-- Portions Copyright (c) 1994, Regents of the University of California
--
-- src/tutorial/complex.source
diff --git a/src/tutorial/funcs_new.c b/src/tutorial/funcs_new.c
index f668d281bb..2e09f8de6e 100644
--- a/src/tutorial/funcs_new.c
+++ b/src/tutorial/funcs_new.c
@@ -66,21 +66,24 @@ PG_FUNCTION_INFO_V1(copytext);
Datum
copytext(PG_FUNCTION_ARGS)
{
- text *t = PG_GETARG_TEXT_P(0);
+ text *t = PG_GETARG_TEXT_PP(0);
/*
- * VARSIZE is the total size of the struct in bytes.
+ * VARSIZE_ANY_EXHDR is the size of the struct in bytes, minus the
+ * VARHDRSZ or VARHDRSZ_SHORT of its header. Construct the copy with a
+ * full-length header.
*/
- text *new_t = (text *) palloc(VARSIZE(t));
+ text *new_t = (text *) palloc(VARSIZE_ANY_EXHDR(t) + VARHDRSZ);
- SET_VARSIZE(new_t, VARSIZE(t));
+ SET_VARSIZE(new_t, VARSIZE_ANY_EXHDR(t) + VARHDRSZ);
/*
- * VARDATA is a pointer to the data region of the struct.
+ * VARDATA is a pointer to the data region of the new struct. The source
+ * could be a short datum, so retrieve its data through VARDATA_ANY.
*/
memcpy((void *) VARDATA(new_t), /* destination */
- (void *) VARDATA(t), /* source */
- VARSIZE(t) - VARHDRSZ); /* how many bytes */
+ (void *) VARDATA_ANY(t), /* source */
+ VARSIZE_ANY_EXHDR(t)); /* how many bytes */
PG_RETURN_TEXT_P(new_t);
}
@@ -89,16 +92,16 @@ PG_FUNCTION_INFO_V1(concat_text);
Datum
concat_text(PG_FUNCTION_ARGS)
{
- text *arg1 = PG_GETARG_TEXT_P(0);
- text *arg2 = PG_GETARG_TEXT_P(1);
- int32 arg1_size = VARSIZE(arg1) - VARHDRSZ;
- int32 arg2_size = VARSIZE(arg2) - VARHDRSZ;
+ text *arg1 = PG_GETARG_TEXT_PP(0);
+ text *arg2 = PG_GETARG_TEXT_PP(1);
+ int32 arg1_size = VARSIZE_ANY_EXHDR(arg1);
+ int32 arg2_size = VARSIZE_ANY_EXHDR(arg2);
int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
SET_VARSIZE(new_text, new_text_size);
- memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
- memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
+ memcpy(VARDATA(new_text), VARDATA_ANY(arg1), arg1_size);
+ memcpy(VARDATA(new_text) + arg1_size, VARDATA_ANY(arg2), arg2_size);
PG_RETURN_TEXT_P(new_text);
}
diff --git a/src/tutorial/syscat.source b/src/tutorial/syscat.source
index 926ed63b63..2f97642a39 100644
--- a/src/tutorial/syscat.source
+++ b/src/tutorial/syscat.source
@@ -4,7 +4,7 @@
-- sample queries to the system catalogs
--
--
--- Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+-- Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
-- Portions Copyright (c) 1994, Regents of the University of California
--
-- src/tutorial/syscat.source