Skip to content

Commit 1038bc9

Browse files
committed
pgbench: Silence new compiler warnings
The original coding in 7bafffe and previous wasn't all that great anyway. Reported by Jeff Janes and Tom Lane
1 parent 78e7c44 commit 1038bc9

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,12 +2648,24 @@ read_line_from_file(FILE *fd)
26482648
return NULL;
26492649
}
26502650

2651+
/*
2652+
* Initialize a ParsedScript
2653+
*/
2654+
static void
2655+
initParsedScript(ParsedScript *ps, const char *desc, int alloc_num, int weight)
2656+
{
2657+
ps->commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num);
2658+
ps->desc = desc;
2659+
ps->weight = weight;
2660+
initStats(&ps->stats, 0.0);
2661+
}
2662+
26512663
/*
26522664
* Given a file name, read it and return its ParsedScript representation. "-"
26532665
* means to read stdin.
26542666
*/
26552667
static ParsedScript
2656-
process_file(char *filename)
2668+
process_file(char *filename, int weight)
26572669
{
26582670
#define COMMANDS_ALLOC_NUM 128
26592671
ParsedScript ps;
@@ -2673,8 +2685,7 @@ process_file(char *filename)
26732685
}
26742686

26752687
alloc_num = COMMANDS_ALLOC_NUM;
2676-
ps.commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num);
2677-
ps.desc = filename;
2688+
initParsedScript(&ps, filename, alloc_num, weight);
26782689

26792690
lineno = 0;
26802691
index = 0;
@@ -2710,7 +2721,7 @@ process_file(char *filename)
27102721

27112722
/* Parse the given builtin script and return the parsed representation */
27122723
static ParsedScript
2713-
process_builtin(BuiltinScript *bi)
2724+
process_builtin(BuiltinScript *bi, int weight)
27142725
{
27152726
int lineno,
27162727
index;
@@ -2720,8 +2731,7 @@ process_builtin(BuiltinScript *bi)
27202731
ParsedScript ps;
27212732

27222733
alloc_num = COMMANDS_ALLOC_NUM;
2723-
ps.desc = bi->desc;
2724-
ps.commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num);
2734+
initParsedScript(&ps, bi->desc, alloc_num, weight);
27252735

27262736
lineno = 0;
27272737
index = 0;
@@ -2860,7 +2870,7 @@ parseScriptWeight(const char *option, char **script)
28602870

28612871
/* append a script to the list of scripts to process */
28622872
static void
2863-
addScript(ParsedScript script, int weight)
2873+
addScript(ParsedScript script)
28642874
{
28652875
if (script.commands == NULL || script.commands[0] == NULL)
28662876
{
@@ -2875,8 +2885,6 @@ addScript(ParsedScript script, int weight)
28752885
}
28762886

28772887
sql_script[num_scripts] = script;
2878-
sql_script[num_scripts].weight = weight;
2879-
initStats(&sql_script[num_scripts].stats, 0.0);
28802888
num_scripts++;
28812889
}
28822890

@@ -3251,24 +3259,24 @@ main(int argc, char **argv)
32513259
}
32523260

32533261
weight = parseScriptWeight(optarg, &script);
3254-
addScript(process_builtin(findBuiltin(script)), weight);
3262+
addScript(process_builtin(findBuiltin(script), weight));
32553263
benchmarking_option_set = true;
32563264
internal_script_used = true;
32573265
break;
32583266

32593267
case 'S':
3260-
addScript(process_builtin(findBuiltin("select-only")), 1);
3268+
addScript(process_builtin(findBuiltin("select-only"), 1));
32613269
benchmarking_option_set = true;
32623270
internal_script_used = true;
32633271
break;
32643272
case 'N':
3265-
addScript(process_builtin(findBuiltin("simple-update")), 1);
3273+
addScript(process_builtin(findBuiltin("simple-update"), 1));
32663274
benchmarking_option_set = true;
32673275
internal_script_used = true;
32683276
break;
32693277
case 'f':
32703278
weight = parseScriptWeight(optarg, &script);
3271-
addScript(process_file(script), weight);
3279+
addScript(process_file(script, weight));
32723280
benchmarking_option_set = true;
32733281
break;
32743282
case 'D':
@@ -3406,7 +3414,7 @@ main(int argc, char **argv)
34063414
/* set default script if none */
34073415
if (num_scripts == 0 && !is_init_mode)
34083416
{
3409-
addScript(process_builtin(findBuiltin("tpcb-like")), 1);
3417+
addScript(process_builtin(findBuiltin("tpcb-like"), 1));
34103418
benchmarking_option_set = true;
34113419
internal_script_used = true;
34123420
}

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