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

Commit2c66f99

Browse files
committed
Replace pg_asprintf() with psprintf().
This eliminates an awkward coding pattern that's also unnecessarilyinconsistent with backend coding. psprintf() is now the thing touse everywhere.
1 parent09a89cb commit2c66f99

File tree

19 files changed

+57
-125
lines changed

19 files changed

+57
-125
lines changed

‎contrib/oid2name/oid2name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ sql_exec_searchtables(PGconn *conn, struct options * opts)
508508
free(comma_filenodes);
509509

510510
/* now build the query */
511-
pg_asprintf(&todo,
511+
todo=psprintf(
512512
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n"
513513
"FROM pg_catalog.pg_class c \n"
514514
"LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"

‎contrib/pg_upgrade/check.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,9 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
458458
prep_status("Creating script to analyze new cluster");
459459

460460
if (os_info.user_specified)
461-
pg_asprintf(&user_specification,"-U \"%s\" ",os_info.user);
461+
user_specification=psprintf("-U \"%s\" ",os_info.user);
462462

463-
pg_asprintf(analyze_script_file_name,"analyze_new_cluster.%s",
464-
SCRIPT_EXT);
463+
*analyze_script_file_name=psprintf("analyze_new_cluster.%s",SCRIPT_EXT);
465464

466465
if ((script=fopen_priv(*analyze_script_file_name,"w"))==NULL)
467466
pg_fatal("Could not open file \"%s\": %s\n",
@@ -592,8 +591,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
592591
inttblnum;
593592
charold_cluster_pgdata[MAXPGPATH];
594593

595-
pg_asprintf(deletion_script_file_name,"delete_old_cluster.%s",
596-
SCRIPT_EXT);
594+
*deletion_script_file_name=psprintf("delete_old_cluster.%s",SCRIPT_EXT);
597595

598596
/*
599597
* Some users (oddly) create tablespaces inside the cluster data

‎contrib/pg_upgrade/tablespace.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ set_tablespace_directory_suffix(ClusterInfo *cluster)
8686
/* This cluster has a version-specific subdirectory */
8787

8888
/* The leading slash is needed to start a new directory. */
89-
pg_asprintf(&cluster->tablespace_suffix,"/PG_%s_%d",
90-
cluster->major_version_str,cluster->controldata.cat_ver);
89+
cluster->tablespace_suffix=psprintf("/PG_%s_%d",
90+
cluster->major_version_str,
91+
cluster->controldata.cat_ver);
9192
}
9293
}

‎contrib/pg_upgrade/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pg_putenv(const char *var, const char *val)
278278
#ifndefWIN32
279279
char*envstr;
280280

281-
pg_asprintf(&envstr,"%s=%s",var,val);
281+
envstr=psprintf("%s=%s",var,val);
282282
putenv(envstr);
283283

284284
/*

‎src/backend/utils/adt/format_type.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ static char *format_type_internal(Oid type_oid, int32 typemod,
3232
booltypemod_given,boolallow_invalid,
3333
boolforce_qualify);
3434
staticchar*printTypmod(constchar*typname,int32typmod,Oidtypmodout);
35-
staticchar*
36-
psnprintf(size_tlen,constchar*fmt,...)
37-
/* This lets gcc check the format string for consistency. */
38-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
3935

4036

4137
/*
@@ -320,7 +316,7 @@ format_type_internal(Oid type_oid, int32 typemod,
320316
}
321317

322318
if (is_array)
323-
buf=psnprintf(strlen(buf)+3,"%s[]",buf);
319+
buf=psprintf("%s[]",buf);
324320

325321
ReleaseSysCache(tuple);
326322

@@ -342,8 +338,7 @@ printTypmod(const char *typname, int32 typmod, Oid typmodout)
342338
if (typmodout==InvalidOid)
343339
{
344340
/* Default behavior: just print the integer typmod with parens */
345-
res=psnprintf(strlen(typname)+MAX_INT32_LEN+3,"%s(%d)",
346-
typname, (int)typmod);
341+
res=psprintf("%s(%d)",typname, (int)typmod);
347342
}
348343
else
349344
{
@@ -352,8 +347,7 @@ printTypmod(const char *typname, int32 typmod, Oid typmodout)
352347

353348
tmstr=DatumGetCString(OidFunctionCall1(typmodout,
354349
Int32GetDatum(typmod)));
355-
res=psnprintf(strlen(typname)+strlen(tmstr)+1,"%s%s",
356-
typname,tmstr);
350+
res=psprintf("%s%s",typname,tmstr);
357351
}
358352

359353
returnres;
@@ -448,20 +442,3 @@ oidvectortypes(PG_FUNCTION_ARGS)
448442

449443
PG_RETURN_TEXT_P(cstring_to_text(result));
450444
}
451-
452-
453-
/* snprintf into a palloc'd string */
454-
staticchar*
455-
psnprintf(size_tlen,constchar*fmt,...)
456-
{
457-
va_listap;
458-
char*buf;
459-
460-
buf=palloc(len);
461-
462-
va_start(ap,fmt);
463-
vsnprintf(buf,len,fmt,ap);
464-
va_end(ap);
465-
466-
returnbuf;
467-
}

‎src/bin/initdb/initdb.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ mkdatadir(const char *subdir)
949949
char*path;
950950

951951
if (subdir)
952-
pg_asprintf(&path,"%s/%s",pg_data,subdir);
952+
path=psprintf("%s/%s",pg_data,subdir);
953953
else
954954
path=pg_strdup(pg_data);
955955

@@ -969,7 +969,7 @@ mkdatadir(const char *subdir)
969969
staticvoid
970970
set_input(char**dest,char*filename)
971971
{
972-
pg_asprintf(dest,"%s/%s",share_path,filename);
972+
*dest=psprintf("%s/%s",share_path,filename);
973973
}
974974

975975
/*
@@ -1023,9 +1023,9 @@ write_version_file(char *extrapath)
10231023
char*path;
10241024

10251025
if (extrapath==NULL)
1026-
pg_asprintf(&path,"%s/PG_VERSION",pg_data);
1026+
path=psprintf("%s/PG_VERSION",pg_data);
10271027
else
1028-
pg_asprintf(&path,"%s/%s/PG_VERSION",pg_data,extrapath);
1028+
path=psprintf("%s/%s/PG_VERSION",pg_data,extrapath);
10291029

10301030
if ((version_file=fopen(path,PG_BINARY_W))==NULL)
10311031
{
@@ -1053,7 +1053,7 @@ set_null_conf(void)
10531053
FILE*conf_file;
10541054
char*path;
10551055

1056-
pg_asprintf(&path,"%s/postgresql.conf",pg_data);
1056+
path=psprintf("%s/postgresql.conf",pg_data);
10571057
conf_file=fopen(path,PG_BINARY_W);
10581058
if (conf_file==NULL)
10591059
{
@@ -2951,7 +2951,7 @@ setup_pgdata(void)
29512951
* need quotes otherwise on Windows because paths there are most likely to
29522952
* have embedded spaces.
29532953
*/
2954-
pg_asprintf(&pgdata_set_env,"PGDATA=%s",pg_data);
2954+
pgdata_set_env=psprintf("PGDATA=%s",pg_data);
29552955
putenv(pgdata_set_env);
29562956
}
29572957

@@ -3345,7 +3345,7 @@ create_xlog_symlink(void)
33453345
}
33463346

33473347
/* form name of the place where the symlink must go */
3348-
pg_asprintf(&linkloc,"%s/pg_xlog",pg_data);
3348+
linkloc=psprintf("%s/pg_xlog",pg_data);
33493349

33503350
#ifdefHAVE_SYMLINK
33513351
if (symlink(xlog_dir,linkloc)!=0)

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,15 +2049,15 @@ main(int argc, char **argv)
20492049

20502050
pgdata_D=pg_strdup(optarg);
20512051
canonicalize_path(pgdata_D);
2052-
pg_asprintf(&env_var,"PGDATA=%s",pgdata_D);
2052+
env_var=psprintf("PGDATA=%s",pgdata_D);
20532053
putenv(env_var);
20542054

20552055
/*
20562056
* We could pass PGDATA just in an environment
20572057
* variable but we do -D too for clearer postmaster
20582058
* 'ps' display
20592059
*/
2060-
pg_asprintf(&pgdata_opt,"-D \"%s\" ",pgdata_D);
2060+
pgdata_opt=psprintf("-D \"%s\" ",pgdata_D);
20612061
break;
20622062
}
20632063
case'l':
@@ -2098,7 +2098,7 @@ main(int argc, char **argv)
20982098
register_username=pg_strdup(optarg);
20992099
else
21002100
/* Prepend .\ for local accounts */
2101-
pg_asprintf(&register_username,".\\%s",optarg);
2101+
register_username=psprintf(".\\%s",optarg);
21022102
break;
21032103
case'w':
21042104
do_wait= true;

‎src/bin/pg_dump/compress_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ cfopen_read(const char *path, const char *mode)
489489
{
490490
char*fname;
491491

492-
pg_asprintf(&fname,"%s.gz",path);
492+
fname=psprintf("%s.gz",path);
493493
fp=cfopen(fname,mode,1);
494494
free(fname);
495495
}
@@ -519,7 +519,7 @@ cfopen_write(const char *path, const char *mode, int compression)
519519
#ifdefHAVE_LIBZ
520520
char*fname;
521521

522-
pg_asprintf(&fname,"%s.gz",path);
522+
fname=psprintf("%s.gz",path);
523523
fp=cfopen(fname,mode,1);
524524
free(fname);
525525
#else

‎src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10439,7 +10439,7 @@ convertOperatorReference(Archive *fout, const char *opr)
1043910439
/* If not schema-qualified, don't need to add OPERATOR() */
1044010440
if (!sawdot)
1044110441
returnname;
10442-
pg_asprintf(&oname,"OPERATOR(%s)",name);
10442+
oname=psprintf("OPERATOR(%s)",name);
1044310443
free(name);
1044410444
returnoname;
1044510445
}
@@ -12753,7 +12753,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo)
1275312753
char*acltag;
1275412754

1275512755
attnamecopy=pg_strdup(fmtId(attname));
12756-
pg_asprintf(&acltag,"%s.%s",tbinfo->dobj.name,attname);
12756+
acltag=psprintf("%s.%s",tbinfo->dobj.name,attname);
1275712757
/* Column's GRANT type is always TABLE */
1275812758
dumpACL(fout,tbinfo->dobj.catId,tbinfo->dobj.dumpId,"TABLE",
1275912759
namecopy,attnamecopy,acltag,

‎src/bin/psql/command.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ exec_command(const char *cmd,
11881188
/* Set variable to the value of the next argument */
11891189
char*newval;
11901190

1191-
pg_asprintf(&newval,"%s=%s",envvar,envval);
1191+
newval=psprintf("%s=%s",envvar,envval);
11921192
putenv(newval);
11931193
success= true;
11941194

@@ -1549,7 +1549,7 @@ prompt_for_password(const char *username)
15491549
{
15501550
char*prompt_text;
15511551

1552-
pg_asprintf(&prompt_text,_("Password for user %s: "),username);
1552+
prompt_text=psprintf(_("Password for user %s: "),username);
15531553
result=simple_prompt(prompt_text,100, false);
15541554
free(prompt_text);
15551555
}
@@ -1929,17 +1929,17 @@ editFile(const char *fname, int lineno)
19291929
*/
19301930
#ifndefWIN32
19311931
if (lineno>0)
1932-
pg_asprintf(&sys,"exec %s %s%d '%s'",
1932+
sys=psprintf("exec %s %s%d '%s'",
19331933
editorName,editor_lineno_arg,lineno,fname);
19341934
else
1935-
pg_asprintf(&sys,"exec %s '%s'",
1935+
sys=psprintf("exec %s '%s'",
19361936
editorName,fname);
19371937
#else
19381938
if (lineno>0)
1939-
pg_asprintf(&sys,SYSTEMQUOTE"\"%s\" %s%d \"%s\""SYSTEMQUOTE,
1939+
sys=psprintf(SYSTEMQUOTE"\"%s\" %s%d \"%s\""SYSTEMQUOTE,
19401940
editorName,editor_lineno_arg,lineno,fname);
19411941
else
1942-
pg_asprintf(&sys,SYSTEMQUOTE"\"%s\" \"%s\""SYSTEMQUOTE,
1942+
sys=psprintf(SYSTEMQUOTE"\"%s\" \"%s\""SYSTEMQUOTE,
19431943
editorName,fname);
19441944
#endif
19451945
result=system(sys);
@@ -2635,9 +2635,9 @@ do_shell(const char *command)
26352635

26362636
/* See EDITOR handling comment for an explanation */
26372637
#ifndefWIN32
2638-
pg_asprintf(&sys,"exec %s",shellName);
2638+
sys=psprintf("exec %s",shellName);
26392639
#else
2640-
pg_asprintf(&sys,SYSTEMQUOTE"\"%s\""SYSTEMQUOTE,shellName);
2640+
sys=psprintf(SYSTEMQUOTE"\"%s\""SYSTEMQUOTE,shellName);
26412641
#endif
26422642
result=system(sys);
26432643
free(sys);

‎src/bin/psql/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ StoreQueryTuple(const PGresult *result)
594594
char*value;
595595

596596
/* concate prefix and column name */
597-
pg_asprintf(&varname,"%s%s",pset.gset_prefix,colname);
597+
varname=psprintf("%s%s",pset.gset_prefix,colname);
598598

599599
if (!PQgetisnull(result,0,i))
600600
value=PQgetvalue(result,0,i);
@@ -1685,7 +1685,7 @@ expand_tilde(char **filename)
16851685
{
16861686
char*newfn;
16871687

1688-
pg_asprintf(&newfn,"%s%s",home,p);
1688+
newfn=psprintf("%s%s",home,p);
16891689
free(fn);
16901690
*filename=newfn;
16911691
}

‎src/bin/psql/copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ xstrcat(char **var, const char *more)
7979
{
8080
char*newvar;
8181

82-
pg_asprintf(&newvar,"%s%s",*var,more);
82+
newvar=psprintf("%s%s",*var,more);
8383
free(*var);
8484
*var=newvar;
8585
}

‎src/bin/psql/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ initializeInput(int flags)
298298
if (histfile==NULL)
299299
{
300300
if (get_home_path(home))
301-
pg_asprintf(&psql_history,"%s/%s",home,PSQLHISTORY);
301+
psql_history=psprintf("%s/%s",home,PSQLHISTORY);
302302
}
303303
else
304304
{

‎src/bin/psql/startup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ main(int argc, char *argv[])
182182
if (options.username==NULL)
183183
password_prompt=pg_strdup(_("Password: "));
184184
else
185-
pg_asprintf(&password_prompt,_("Password for user %s: "),
186-
options.username);
185+
password_prompt=psprintf(_("Password for user %s: "),
186+
options.username);
187187

188188
if (pset.getPassword==TRI_YES)
189189
password=simple_prompt(password_prompt,100, false);
@@ -638,8 +638,8 @@ process_psqlrc_file(char *filename)
638638
#defineR_OK 4
639639
#endif
640640

641-
pg_asprintf(&psqlrc_minor,"%s-%s",filename,PG_VERSION);
642-
pg_asprintf(&psqlrc_major,"%s-%s",filename,PG_MAJORVERSION);
641+
psqlrc_minor=psprintf("%s-%s",filename,PG_VERSION);
642+
psqlrc_major=psprintf("%s-%s",filename,PG_MAJORVERSION);
643643

644644
/* check for minor version first, then major, then no version */
645645
if (access(psqlrc_minor,R_OK)==0)

‎src/bin/psql/tab-complete.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,8 +3832,6 @@ complete_from_variables(char *text, const char *prefix, const char *suffix)
38323832

38333833
for (ptr=pset.vars->next;ptr;ptr=ptr->next)
38343834
{
3835-
char*buffer;
3836-
38373835
if (nvars >=maxvars)
38383836
{
38393837
maxvars *=2;
@@ -3846,8 +3844,7 @@ complete_from_variables(char *text, const char *prefix, const char *suffix)
38463844
}
38473845
}
38483846

3849-
pg_asprintf(&buffer,"%s%s%s",prefix,ptr->name,suffix);
3850-
varnames[nvars++]=buffer;
3847+
varnames[nvars++]=psprintf("%s%s%s",prefix,ptr->name,suffix);
38513848
}
38523849

38533850
varnames[nvars]=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp