Commit 143290ef authored by Andres Freund's avatar Andres Freund

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
parent d9dd406f
...@@ -67,9 +67,24 @@ typedef struct f_smgr ...@@ -67,9 +67,24 @@ typedef struct f_smgr
static const f_smgr smgrsw[] = { static const f_smgr smgrsw[] = {
/* magnetic disk */ /* magnetic disk */
{mdinit, NULL, mdclose, mdcreate, mdexists, mdunlink, mdextend, {
mdprefetch, mdread, mdwrite, mdwriteback, mdnblocks, mdtruncate, .smgr_init = mdinit,
mdimmedsync, mdpreckpt, mdsync, mdpostckpt .smgr_shutdown = NULL,
.smgr_close = mdclose,
.smgr_create = mdcreate,
.smgr_exists = mdexists,
.smgr_unlink = mdunlink,
.smgr_extend = mdextend,
.smgr_prefetch = mdprefetch,
.smgr_read = mdread,
.smgr_write = mdwrite,
.smgr_writeback = mdwriteback,
.smgr_nblocks = mdnblocks,
.smgr_truncate = mdtruncate,
.smgr_immedsync = mdimmedsync,
.smgr_pre_ckpt = mdpreckpt,
.smgr_sync = mdsync,
.smgr_post_ckpt = mdpostckpt
} }
}; };
......
...@@ -1310,7 +1310,6 @@ exec_parse_message(const char *query_string, /* string to execute */ ...@@ -1310,7 +1310,6 @@ exec_parse_message(const char *query_string, /* string to execute */
{ {
Query *query; Query *query;
bool snapshot_set = false; bool snapshot_set = false;
int i;
raw_parse_tree = linitial_node(RawStmt, parsetree_list); raw_parse_tree = linitial_node(RawStmt, parsetree_list);
...@@ -1366,7 +1365,7 @@ exec_parse_message(const char *query_string, /* string to execute */ ...@@ -1366,7 +1365,7 @@ exec_parse_message(const char *query_string, /* string to execute */
/* /*
* Check all parameter types got determined. * Check all parameter types got determined.
*/ */
for (i = 0; i < numParams; i++) for (int i = 0; i < numParams; i++)
{ {
Oid ptype = paramTypes[i]; Oid ptype = paramTypes[i];
...@@ -1555,10 +1554,8 @@ exec_bind_message(StringInfo input_message) ...@@ -1555,10 +1554,8 @@ exec_bind_message(StringInfo input_message)
numPFormats = pq_getmsgint(input_message, 2); numPFormats = pq_getmsgint(input_message, 2);
if (numPFormats > 0) if (numPFormats > 0)
{ {
int i;
pformats = (int16 *) palloc(numPFormats * sizeof(int16)); pformats = (int16 *) palloc(numPFormats * sizeof(int16));
for (i = 0; i < numPFormats; i++) for (int i = 0; i < numPFormats; i++)
pformats[i] = pq_getmsgint(input_message, 2); pformats[i] = pq_getmsgint(input_message, 2);
} }
...@@ -1641,8 +1638,6 @@ exec_bind_message(StringInfo input_message) ...@@ -1641,8 +1638,6 @@ exec_bind_message(StringInfo input_message)
*/ */
if (numParams > 0) if (numParams > 0)
{ {
int paramno;
params = (ParamListInfo) palloc(offsetof(ParamListInfoData, params) + params = (ParamListInfo) palloc(offsetof(ParamListInfoData, params) +
numParams * sizeof(ParamExternData)); numParams * sizeof(ParamExternData));
/* we have static list of params, so no hooks needed */ /* we have static list of params, so no hooks needed */
...@@ -1654,7 +1649,7 @@ exec_bind_message(StringInfo input_message) ...@@ -1654,7 +1649,7 @@ exec_bind_message(StringInfo input_message)
params->parserSetupArg = NULL; params->parserSetupArg = NULL;
params->numParams = numParams; params->numParams = numParams;
for (paramno = 0; paramno < numParams; paramno++) for (int paramno = 0; paramno < numParams; paramno++)
{ {
Oid ptype = psrc->param_types[paramno]; Oid ptype = psrc->param_types[paramno];
int32 plength; int32 plength;
...@@ -1782,10 +1777,8 @@ exec_bind_message(StringInfo input_message) ...@@ -1782,10 +1777,8 @@ exec_bind_message(StringInfo input_message)
numRFormats = pq_getmsgint(input_message, 2); numRFormats = pq_getmsgint(input_message, 2);
if (numRFormats > 0) if (numRFormats > 0)
{ {
int i;
rformats = (int16 *) palloc(numRFormats * sizeof(int16)); rformats = (int16 *) palloc(numRFormats * sizeof(int16));
for (i = 0; i < numRFormats; i++) for (int i = 0; i < numRFormats; i++)
rformats[i] = pq_getmsgint(input_message, 2); rformats[i] = pq_getmsgint(input_message, 2);
} }
...@@ -2212,7 +2205,6 @@ errdetail_params(ParamListInfo params) ...@@ -2212,7 +2205,6 @@ errdetail_params(ParamListInfo params)
{ {
StringInfoData param_str; StringInfoData param_str;
MemoryContext oldcontext; MemoryContext oldcontext;
int paramno;
/* This code doesn't support dynamic param lists */ /* This code doesn't support dynamic param lists */
Assert(params->paramFetch == NULL); Assert(params->paramFetch == NULL);
...@@ -2222,7 +2214,7 @@ errdetail_params(ParamListInfo params) ...@@ -2222,7 +2214,7 @@ errdetail_params(ParamListInfo params)
initStringInfo(&param_str); initStringInfo(&param_str);
for (paramno = 0; paramno < params->numParams; paramno++) for (int paramno = 0; paramno < params->numParams; paramno++)
{ {
ParamExternData *prm = &params->params[paramno]; ParamExternData *prm = &params->params[paramno];
Oid typoutput; Oid typoutput;
...@@ -2325,7 +2317,6 @@ static void ...@@ -2325,7 +2317,6 @@ static void
exec_describe_statement_message(const char *stmt_name) exec_describe_statement_message(const char *stmt_name)
{ {
CachedPlanSource *psrc; CachedPlanSource *psrc;
int i;
/* /*
* Start up a transaction command. (Note that this will normally change * Start up a transaction command. (Note that this will normally change
...@@ -2384,7 +2375,7 @@ exec_describe_statement_message(const char *stmt_name) ...@@ -2384,7 +2375,7 @@ exec_describe_statement_message(const char *stmt_name)
* message type */ * message type */
pq_sendint16(&row_description_buf, psrc->num_params); pq_sendint16(&row_description_buf, psrc->num_params);
for (i = 0; i < psrc->num_params; i++) for (int i = 0; i < psrc->num_params; i++)
{ {
Oid ptype = psrc->param_types[i]; Oid ptype = psrc->param_types[i];
...@@ -4179,10 +4170,8 @@ PostgresMain(int argc, char *argv[], ...@@ -4179,10 +4170,8 @@ PostgresMain(int argc, char *argv[],
numParams = pq_getmsgint(&input_message, 2); numParams = pq_getmsgint(&input_message, 2);
if (numParams > 0) if (numParams > 0)
{ {
int i;
paramTypes = (Oid *) palloc(numParams * sizeof(Oid)); paramTypes = (Oid *) palloc(numParams * sizeof(Oid));
for (i = 0; i < numParams; i++) for (int i = 0; i < numParams; i++)
paramTypes[i] = pq_getmsgint(&input_message, 4); paramTypes[i] = pq_getmsgint(&input_message, 4);
} }
pq_getmsgend(&input_message); pq_getmsgend(&input_message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment