Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9789e80

Browse files
peterepull[bot]
authored andcommitted
Convert *GetDatum() and DatumGet*() macros to inline functions
The previous macro implementations just cast the argument to a targettype but did not check whether the input type was appropriate. Thefunction implementation can do better type checking of the input type.Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>Discussion:https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
1 parent9aad205 commit9789e80

File tree

27 files changed

+659
-190
lines changed

27 files changed

+659
-190
lines changed

‎contrib/intarray/_int_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
5151

5252
/* Oidsubtype = PG_GETARG_OID(3); */
5353
bool*recheck= (bool*)PG_GETARG_POINTER(4);
54-
boolretval;
54+
boolretval= false;/* silence compiler warning */
5555

5656
/* this is exact except for RTSameStrategyNumber */
5757
*recheck= (strategy==RTSameStrategyNumber);

‎doc/src/sgml/xfunc.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,7 @@ c_overpaid(PG_FUNCTION_ARGS)
27632763
is null. <function>GetAttributeByName</function> returns a <type>Datum</type>
27642764
value that you can convert to the proper data type by using the
27652765
appropriate <function>DatumGet<replaceable>XXX</replaceable>()</function>
2766-
macro. Note that the return value is meaningless if the null flag is
2766+
function. Note that the return value is meaningless if the null flag is
27672767
set; always check the null flag before trying to do anything with the
27682768
result.
27692769
</para>

‎src/backend/access/gist/gistutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ gistMakeUnionKey(GISTSTATE *giststate, int attno,
280280
bool
281281
gistKeyIsEQ(GISTSTATE*giststate,intattno,Datuma,Datumb)
282282
{
283-
boolresult;
283+
boolresult= false;/* silence compiler warning */
284284

285285
FunctionCall3Coll(&giststate->equalFn[attno],
286286
giststate->supportCollation[attno],

‎src/backend/tsearch/ts_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void
354354
parsetext(OidcfgId,ParsedText*prs,char*buf,intbuflen)
355355
{
356356
inttype,
357-
lenlemm;
357+
lenlemm=0;/* silence compiler warning */
358358
char*lemm=NULL;
359359
LexizeDataldata;
360360
TSLexeme*norms;
@@ -529,7 +529,7 @@ void
529529
hlparsetext(OidcfgId,HeadlineParsedText*prs,TSQueryquery,char*buf,intbuflen)
530530
{
531531
inttype,
532-
lenlemm;
532+
lenlemm=0;/* silence compiler warning */
533533
char*lemm=NULL;
534534
LexizeDataldata;
535535
TSLexeme*norms;

‎src/backend/utils/mb/mbutils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ pg_do_encoding_conversion(unsigned char *src, int len,
409409
(void)OidFunctionCall6(proc,
410410
Int32GetDatum(src_encoding),
411411
Int32GetDatum(dest_encoding),
412-
CStringGetDatum(src),
413-
CStringGetDatum(result),
412+
CStringGetDatum((char*)src),
413+
CStringGetDatum((char*)result),
414414
Int32GetDatum(len),
415415
BoolGetDatum(false));
416416

@@ -485,8 +485,8 @@ pg_do_encoding_conversion_buf(Oid proc,
485485
result=OidFunctionCall6(proc,
486486
Int32GetDatum(src_encoding),
487487
Int32GetDatum(dest_encoding),
488-
CStringGetDatum(src),
489-
CStringGetDatum(dest),
488+
CStringGetDatum((char*)src),
489+
CStringGetDatum((char*)dest),
490490
Int32GetDatum(srclen),
491491
BoolGetDatum(noError));
492492
returnDatumGetInt32(result);
@@ -910,8 +910,8 @@ pg_unicode_to_server(pg_wchar c, unsigned char *s)
910910
FunctionCall6(Utf8ToServerConvProc,
911911
Int32GetDatum(PG_UTF8),
912912
Int32GetDatum(server_encoding),
913-
CStringGetDatum(c_as_utf8),
914-
CStringGetDatum(s),
913+
CStringGetDatum((char*)c_as_utf8),
914+
CStringGetDatum((char*)s),
915915
Int32GetDatum(c_as_utf8_len),
916916
BoolGetDatum(false));
917917
}

‎src/include/access/gin.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,18 @@ typedef char GinTernaryValue;
6262
#defineGIN_MAYBE2/* don't know if item is present / don't know
6363
* if matches */
6464

65-
#defineDatumGetGinTernaryValue(X) ((GinTernaryValue)(X))
66-
#defineGinTernaryValueGetDatum(X) ((Datum)(X))
65+
staticinlineGinTernaryValue
66+
DatumGetGinTernaryValue(DatumX)
67+
{
68+
return (GinTernaryValue)X;
69+
}
70+
71+
staticinlineDatum
72+
GinTernaryValueGetDatum(GinTernaryValueX)
73+
{
74+
return (Datum)X;
75+
}
76+
6777
#definePG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x)
6878

6979
/* GUC parameters */

‎src/include/funcapi.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ extern TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple);
204204
* Datum HeapTupleHeaderGetDatum(HeapTupleHeader tuple) - convert a
205205
*HeapTupleHeader to a Datum.
206206
*
207-
*Macro declarations:
207+
*Inline declarations:
208208
* HeapTupleGetDatum(HeapTuple tuple) - convert a HeapTuple to a Datum.
209209
*
210210
* Obsolete routines and macros:
@@ -217,10 +217,6 @@ extern TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple);
217217
*----------
218218
*/
219219

220-
#defineHeapTupleGetDatum(tuple)HeapTupleHeaderGetDatum((tuple)->t_data)
221-
/* obsolete version of above */
222-
#defineTupleGetDatum(_slot,_tuple)HeapTupleGetDatum(_tuple)
223-
224220
externTupleDescRelationNameGetTupleDesc(constchar*relname);
225221
externTupleDescTypeGetTupleDesc(Oidtypeoid,List*colaliases);
226222

@@ -230,6 +226,14 @@ extern AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc);
230226
externHeapTupleBuildTupleFromCStrings(AttInMetadata*attinmeta,char**values);
231227
externDatumHeapTupleHeaderGetDatum(HeapTupleHeadertuple);
232228

229+
staticinlineDatum
230+
HeapTupleGetDatum(constHeapTupleData*tuple)
231+
{
232+
returnHeapTupleHeaderGetDatum(tuple->t_data);
233+
}
234+
/* obsolete version of above */
235+
#defineTupleGetDatum(_slot,_tuple)HeapTupleGetDatum(_tuple)
236+
233237

234238
/*----------
235239
*Support for Set Returning Functions (SRFs)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp