Skip to content

Commit 143290e

Browse files
committed
Introduce minimal C99 usage to verify compiler support.
This just converts a few for loops in postgres.c to declare variables in the loop initializer, and uses designated initializers in smgr.c's definition of smgr callbacks. Author: Andres Freund Discussion: https://postgr.es/m/97d4b165-192d-3605-749c-f614a0c4e783@2ndquadrant.com
1 parent d9dd406 commit 143290e

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/backend/storage/smgr/smgr.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,24 @@ typedef struct f_smgr
6767

6868
static const f_smgr smgrsw[] = {
6969
/* magnetic disk */
70-
{mdinit, NULL, mdclose, mdcreate, mdexists, mdunlink, mdextend,
71-
mdprefetch, mdread, mdwrite, mdwriteback, mdnblocks, mdtruncate,
72-
mdimmedsync, mdpreckpt, mdsync, mdpostckpt
70+
{
71+
.smgr_init = mdinit,
72+
.smgr_shutdown = NULL,
73+
.smgr_close = mdclose,
74+
.smgr_create = mdcreate,
75+
.smgr_exists = mdexists,
76+
.smgr_unlink = mdunlink,
77+
.smgr_extend = mdextend,
78+
.smgr_prefetch = mdprefetch,
79+
.smgr_read = mdread,
80+
.smgr_write = mdwrite,
81+
.smgr_writeback = mdwriteback,
82+
.smgr_nblocks = mdnblocks,
83+
.smgr_truncate = mdtruncate,
84+
.smgr_immedsync = mdimmedsync,
85+
.smgr_pre_ckpt = mdpreckpt,
86+
.smgr_sync = mdsync,
87+
.smgr_post_ckpt = mdpostckpt
7388
}
7489
};
7590

src/backend/tcop/postgres.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,6 @@ exec_parse_message(const char *query_string, /* string to execute */
13101310
{
13111311
Query *query;
13121312
bool snapshot_set = false;
1313-
int i;
13141313

13151314
raw_parse_tree = linitial_node(RawStmt, parsetree_list);
13161315

@@ -1366,7 +1365,7 @@ exec_parse_message(const char *query_string, /* string to execute */
13661365
/*
13671366
* Check all parameter types got determined.
13681367
*/
1369-
for (i = 0; i < numParams; i++)
1368+
for (int i = 0; i < numParams; i++)
13701369
{
13711370
Oid ptype = paramTypes[i];
13721371

@@ -1555,10 +1554,8 @@ exec_bind_message(StringInfo input_message)
15551554
numPFormats = pq_getmsgint(input_message, 2);
15561555
if (numPFormats > 0)
15571556
{
1558-
int i;
1559-
15601557
pformats = (int16 *) palloc(numPFormats * sizeof(int16));
1561-
for (i = 0; i < numPFormats; i++)
1558+
for (int i = 0; i < numPFormats; i++)
15621559
pformats[i] = pq_getmsgint(input_message, 2);
15631560
}
15641561

@@ -1641,8 +1638,6 @@ exec_bind_message(StringInfo input_message)
16411638
*/
16421639
if (numParams > 0)
16431640
{
1644-
int paramno;
1645-
16461641
params = (ParamListInfo) palloc(offsetof(ParamListInfoData, params) +
16471642
numParams * sizeof(ParamExternData));
16481643
/* we have static list of params, so no hooks needed */
@@ -1654,7 +1649,7 @@ exec_bind_message(StringInfo input_message)
16541649
params->parserSetupArg = NULL;
16551650
params->numParams = numParams;
16561651

1657-
for (paramno = 0; paramno < numParams; paramno++)
1652+
for (int paramno = 0; paramno < numParams; paramno++)
16581653
{
16591654
Oid ptype = psrc->param_types[paramno];
16601655
int32 plength;
@@ -1782,10 +1777,8 @@ exec_bind_message(StringInfo input_message)
17821777
numRFormats = pq_getmsgint(input_message, 2);
17831778
if (numRFormats > 0)
17841779
{
1785-
int i;
1786-
17871780
rformats = (int16 *) palloc(numRFormats * sizeof(int16));
1788-
for (i = 0; i < numRFormats; i++)
1781+
for (int i = 0; i < numRFormats; i++)
17891782
rformats[i] = pq_getmsgint(input_message, 2);
17901783
}
17911784

@@ -2212,7 +2205,6 @@ errdetail_params(ParamListInfo params)
22122205
{
22132206
StringInfoData param_str;
22142207
MemoryContext oldcontext;
2215-
int paramno;
22162208

22172209
/* This code doesn't support dynamic param lists */
22182210
Assert(params->paramFetch == NULL);
@@ -2222,7 +2214,7 @@ errdetail_params(ParamListInfo params)
22222214

22232215
initStringInfo(&param_str);
22242216

2225-
for (paramno = 0; paramno < params->numParams; paramno++)
2217+
for (int paramno = 0; paramno < params->numParams; paramno++)
22262218
{
22272219
ParamExternData *prm = &params->params[paramno];
22282220
Oid typoutput;
@@ -2325,7 +2317,6 @@ static void
23252317
exec_describe_statement_message(const char *stmt_name)
23262318
{
23272319
CachedPlanSource *psrc;
2328-
int i;
23292320

23302321
/*
23312322
* Start up a transaction command. (Note that this will normally change
@@ -2384,7 +2375,7 @@ exec_describe_statement_message(const char *stmt_name)
23842375
* message type */
23852376
pq_sendint16(&row_description_buf, psrc->num_params);
23862377

2387-
for (i = 0; i < psrc->num_params; i++)
2378+
for (int i = 0; i < psrc->num_params; i++)
23882379
{
23892380
Oid ptype = psrc->param_types[i];
23902381

@@ -4179,10 +4170,8 @@ PostgresMain(int argc, char *argv[],
41794170
numParams = pq_getmsgint(&input_message, 2);
41804171
if (numParams > 0)
41814172
{
4182-
int i;
4183-
41844173
paramTypes = (Oid *) palloc(numParams * sizeof(Oid));
4185-
for (i = 0; i < numParams; i++)
4174+
for (int i = 0; i < numParams; i++)
41864175
paramTypes[i] = pq_getmsgint(&input_message, 4);
41874176
}
41884177
pq_getmsgend(&input_message);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy