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

Commit37d9916

Browse files
committed
More unconstify use
Replace casts whose only purpose is to cast away const with theunconstify() macro.Discussion:https://www.postgresql.org/message-id/flat/53a28052-f9f3-1808-fed9-460fd43035ab%402ndquadrant.com
1 parentcf40dc6 commit37d9916

File tree

25 files changed

+57
-55
lines changed

25 files changed

+57
-55
lines changed

‎contrib/btree_gist/btree_utils_num.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
185185
c.upper=&cur[tinfo->size];
186186
/* if out->lower > cur->lower, adopt cur as lower */
187187
if (tinfo->f_gt(o.lower,c.lower,flinfo))
188-
memcpy((void*)o.lower,c.lower,tinfo->size);
188+
memcpy(unconstify(GBT_NUMKEY*,o.lower),c.lower,tinfo->size);
189189
/* if out->upper < cur->upper, adopt cur as upper */
190190
if (tinfo->f_lt(o.upper,c.upper,flinfo))
191-
memcpy((void*)o.upper,c.upper,tinfo->size);
191+
memcpy(unconstify(GBT_NUMKEY*,o.upper),c.upper,tinfo->size);
192192
}
193193

194194
returnout;
@@ -237,9 +237,9 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *
237237
ur.lower=&(((GBT_NUMKEY*)DatumGetPointer(*u))[0]);
238238
ur.upper=&(((GBT_NUMKEY*)DatumGetPointer(*u))[tinfo->size]);
239239
if (tinfo->f_gt(ur.lower,rd.lower,flinfo))
240-
memcpy((void*)ur.lower,rd.lower,tinfo->size);
240+
memcpy(unconstify(GBT_NUMKEY*,ur.lower),rd.lower,tinfo->size);
241241
if (tinfo->f_lt(ur.upper,rd.upper,flinfo))
242-
memcpy((void*)ur.upper,rd.upper,tinfo->size);
242+
memcpy(unconstify(GBT_NUMKEY*,ur.upper),rd.upper,tinfo->size);
243243
}
244244
}
245245

‎contrib/pgcrypto/imath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end)
20502050
MP_SIGN(z)=MP_ZPOS;
20512051

20522052
if (end!=NULL)
2053-
*end= (char*)str;
2053+
*end=unconstify(char*,str);
20542054

20552055
/*
20562056
* Return a truncation error if the string has unprocessed characters

‎contrib/pgcrypto/md5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len)
161161
md5_calc(ctxt->md5_buf,ctxt);
162162

163163
for (i=gap;i+MD5_BUFLEN <=len;i+=MD5_BUFLEN)
164-
md5_calc((uint8*) (input+i),ctxt);
164+
md5_calc(unconstify(uint8*, (input+i)),ctxt);
165165

166166
ctxt->md5_i=len-i;
167167
memmove(ctxt->md5_buf,input+i,ctxt->md5_i);

‎contrib/pgcrypto/pgp-compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len)
117117
*/
118118
while (len>0)
119119
{
120-
st->stream.next_in=(void*)data;
120+
st->stream.next_in=unconstify(uint8*,data);
121121
st->stream.avail_in=len;
122122
st->stream.next_out=st->buf;
123123
st->stream.avail_out=st->buf_len;

‎src/backend/access/brin/brin_pageops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
178178
brin_can_do_samepage_update(oldbuf,origsz,newsz))
179179
{
180180
START_CRIT_SECTION();
181-
if (!PageIndexTupleOverwrite(oldpage,oldoff, (Item)newtup,newsz))
181+
if (!PageIndexTupleOverwrite(oldpage,oldoff, (Item)unconstify(BrinTuple*,newtup),newsz))
182182
elog(ERROR,"failed to replace BRIN tuple");
183183
MarkBufferDirty(oldbuf);
184184

@@ -195,7 +195,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
195195
XLogRegisterData((char*)&xlrec,SizeOfBrinSamepageUpdate);
196196

197197
XLogRegisterBuffer(0,oldbuf,REGBUF_STANDARD);
198-
XLogRegisterBufData(0, (char*)newtup,newsz);
198+
XLogRegisterBufData(0, (char*)unconstify(BrinTuple*,newtup),newsz);
199199

200200
recptr=XLogInsert(RM_BRIN_ID,info);
201201

@@ -252,7 +252,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
252252
brin_page_init(newpage,BRIN_PAGETYPE_REGULAR);
253253

254254
PageIndexTupleDeleteNoCompact(oldpage,oldoff);
255-
newoff=PageAddItem(newpage, (Item)newtup,newsz,
255+
newoff=PageAddItem(newpage, (Item)unconstify(BrinTuple*,newtup),newsz,
256256
InvalidOffsetNumber, false, false);
257257
if (newoff==InvalidOffsetNumber)
258258
elog(ERROR,"failed to add BRIN tuple to new page");
@@ -287,7 +287,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
287287
XLogRegisterData((char*)&xlrec,SizeOfBrinUpdate);
288288

289289
XLogRegisterBuffer(0,newbuf,REGBUF_STANDARD | (extended ?REGBUF_WILL_INIT :0));
290-
XLogRegisterBufData(0, (char*)newtup,newsz);
290+
XLogRegisterBufData(0, (char*)unconstify(BrinTuple*,newtup),newsz);
291291

292292
/* revmap page */
293293
XLogRegisterBuffer(1,revmapbuf,0);

‎src/backend/access/transam/xact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5409,7 +5409,7 @@ XactLogCommitRecord(TimestampTz commit_time,
54095409
{
54105410
XLogRegisterData((char*) (&xl_twophase),sizeof(xl_xact_twophase));
54115411
if (xl_xinfo.xinfo&XACT_XINFO_HAS_GID)
5412-
XLogRegisterData((char*)twophase_gid,strlen(twophase_gid)+1);
5412+
XLogRegisterData(unconstify(char*,twophase_gid),strlen(twophase_gid)+1);
54135413
}
54145414

54155415
if (xl_xinfo.xinfo&XACT_XINFO_HAS_ORIGIN)
@@ -5537,7 +5537,7 @@ XactLogAbortRecord(TimestampTz abort_time,
55375537
{
55385538
XLogRegisterData((char*) (&xl_twophase),sizeof(xl_xact_twophase));
55395539
if (xl_xinfo.xinfo&XACT_XINFO_HAS_GID)
5540-
XLogRegisterData((char*)twophase_gid,strlen(twophase_gid)+1);
5540+
XLogRegisterData(unconstify(char*,twophase_gid),strlen(twophase_gid)+1);
55415541
}
55425542

55435543
if (xl_xinfo.xinfo&XACT_XINFO_HAS_ORIGIN)

‎src/backend/executor/spi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
13141314
* throws an error.
13151315
*/
13161316
spierrcontext.callback=_SPI_error_callback;
1317-
spierrcontext.arg=(void*)plansource->query_string;
1317+
spierrcontext.arg=unconstify(char*,plansource->query_string);
13181318
spierrcontext.previous=error_context_stack;
13191319
error_context_stack=&spierrcontext;
13201320

@@ -1753,7 +1753,7 @@ SPI_plan_get_cached_plan(SPIPlanPtr plan)
17531753

17541754
/* Setup error traceback support for ereport() */
17551755
spierrcontext.callback=_SPI_error_callback;
1756-
spierrcontext.arg=(void*)plansource->query_string;
1756+
spierrcontext.arg=unconstify(char*,plansource->query_string);
17571757
spierrcontext.previous=error_context_stack;
17581758
error_context_stack=&spierrcontext;
17591759

@@ -1884,7 +1884,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
18841884
* Setup error traceback support for ereport()
18851885
*/
18861886
spierrcontext.callback=_SPI_error_callback;
1887-
spierrcontext.arg=(void*)src;
1887+
spierrcontext.arg=unconstify(char*,src);
18881888
spierrcontext.previous=error_context_stack;
18891889
error_context_stack=&spierrcontext;
18901890

@@ -1989,7 +1989,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan)
19891989
* Setup error traceback support for ereport()
19901990
*/
19911991
spierrcontext.callback=_SPI_error_callback;
1992-
spierrcontext.arg=(void*)src;
1992+
spierrcontext.arg=unconstify(char*,src);
19931993
spierrcontext.previous=error_context_stack;
19941994
error_context_stack=&spierrcontext;
19951995

@@ -2100,7 +2100,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
21002100
List*stmt_list;
21012101
ListCell*lc2;
21022102

2103-
spierrcontext.arg=(void*)plansource->query_string;
2103+
spierrcontext.arg=unconstify(char*,plansource->query_string);
21042104

21052105
/*
21062106
* If this is a one-shot plan, we still need to do parse analysis.

‎src/backend/libpq/auth.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
867867
void*scram_opaq=NULL;
868868
char*output=NULL;
869869
intoutputlen=0;
870-
char*input;
870+
constchar*input;
871871
intinputlen;
872872
intresult;
873873
boolinitial;
@@ -964,14 +964,14 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
964964
if (inputlen==-1)
965965
input=NULL;
966966
else
967-
input=(char*)pq_getmsgbytes(&buf,inputlen);
967+
input=pq_getmsgbytes(&buf,inputlen);
968968

969969
initial= false;
970970
}
971971
else
972972
{
973973
inputlen=buf.len;
974-
input=(char*)pq_getmsgbytes(&buf,buf.len);
974+
input=pq_getmsgbytes(&buf,buf.len);
975975
}
976976
pq_getmsgend(&buf);
977977

@@ -985,7 +985,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
985985
* we pass 'logdetail' as NULL when doing a mock authentication,
986986
* because we should already have a better error message in that case
987987
*/
988-
result=pg_be_scram_exchange(scram_opaq,input,inputlen,
988+
result=pg_be_scram_exchange(scram_opaq,unconstify(char*,input),inputlen,
989989
&output,&outputlen,
990990
logdetail);
991991

@@ -2175,7 +2175,7 @@ CheckPAMAuth(Port *port, const char *user, const char *password)
21752175
* later used inside the PAM conversation to pass the password to the
21762176
* authentication module.
21772177
*/
2178-
pam_passw_conv.appdata_ptr= (char*)password;/* from password above,
2178+
pam_passw_conv.appdata_ptr=unconstify(char*,password);/* from password above,
21792179
* not allocated */
21802180

21812181
/* Optionally, one can set the service name in pg_hba.conf */

‎src/backend/libpq/be-secure-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ load_dh_buffer(const char *buffer, size_t len)
866866
BIO*bio;
867867
DH*dh=NULL;
868868

869-
bio=BIO_new_mem_buf((char*)buffer,len);
869+
bio=BIO_new_mem_buf(unconstify(char*,buffer),len);
870870
if (bio==NULL)
871871
returnNULL;
872872
dh=PEM_read_bio_DHparams(bio,NULL,NULL,NULL);

‎src/backend/parser/parse_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ typeStringToTypeName(const char *str)
739739
* Setup error traceback support in case of ereport() during parse
740740
*/
741741
ptserrcontext.callback=pts_error_callback;
742-
ptserrcontext.arg=(void*)str;
742+
ptserrcontext.arg=unconstify(char*,str);
743743
ptserrcontext.previous=error_context_stack;
744744
error_context_stack=&ptserrcontext;
745745

‎src/backend/replication/logical/message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
6969

7070
XLogBeginInsert();
7171
XLogRegisterData((char*)&xlrec,SizeOfLogicalMessage);
72-
XLogRegisterData((char*)prefix,xlrec.prefix_size);
73-
XLogRegisterData((char*)message,size);
72+
XLogRegisterData(unconstify(char*,prefix),xlrec.prefix_size);
73+
XLogRegisterData(unconstify(char*,message),size);
7474

7575
/* allow origin filtering */
7676
XLogSetRecordFlags(XLOG_INCLUDE_ORIGIN);

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ exec_bind_message(StringInfo input_message)
17671767
* trailing null. This is grotty but is a big win when
17681768
* dealing with very large parameter strings.
17691769
*/
1770-
pbuf.data= (char*)pvalue;
1770+
pbuf.data=unconstify(char*,pvalue);
17711771
pbuf.maxlen=plength+1;
17721772
pbuf.len=plength;
17731773
pbuf.cursor=0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ to_timestamp(PG_FUNCTION_ARGS)
36883688
/* Use the specified time zone, if any. */
36893689
if (tm.tm_zone)
36903690
{
3691-
intdterr=DecodeTimezone((char*)tm.tm_zone,&tz);
3691+
intdterr=DecodeTimezone(unconstify(char*,tm.tm_zone),&tz);
36923692

36933693
if (dterr)
36943694
DateTimeParseError(dterr,text_to_cstring(date_txt),"timestamptz");

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pg_convert(PG_FUNCTION_ARGS)
464464
pg_verify_mbstr_len(src_encoding,src_str,len, false);
465465

466466
/* perform conversion */
467-
dest_str= (char*)pg_do_encoding_conversion((unsignedchar*)src_str,
467+
dest_str= (char*)pg_do_encoding_conversion((unsignedchar*)unconstify(char*,src_str),
468468
len,
469469
src_encoding,
470470
dest_encoding);
@@ -561,7 +561,7 @@ char *
561561
pg_any_to_server(constchar*s,intlen,intencoding)
562562
{
563563
if (len <=0)
564-
return (char*)s;/* empty string is always valid */
564+
returnunconstify(char*,s);/* empty string is always valid */
565565

566566
if (encoding==DatabaseEncoding->encoding||
567567
encoding==PG_SQL_ASCII)
@@ -570,7 +570,7 @@ pg_any_to_server(const char *s, int len, int encoding)
570570
* No conversion is needed, but we must still validate the data.
571571
*/
572572
(void)pg_verify_mbstr(DatabaseEncoding->encoding,s,len, false);
573-
return (char*)s;
573+
returnunconstify(char*,s);
574574
}
575575

576576
if (DatabaseEncoding->encoding==PG_SQL_ASCII)
@@ -600,15 +600,15 @@ pg_any_to_server(const char *s, int len, int encoding)
600600
(unsignedchar)s[i])));
601601
}
602602
}
603-
return (char*)s;
603+
returnunconstify(char*,s);
604604
}
605605

606606
/* Fast path if we can use cached conversion function */
607607
if (encoding==ClientEncoding->encoding)
608608
returnperform_default_encoding_conversion(s,len, true);
609609

610610
/* General case ... will not work outside transactions */
611-
return (char*)pg_do_encoding_conversion((unsignedchar*)s,
611+
return (char*)pg_do_encoding_conversion((unsignedchar*)unconstify(char*,s),
612612
len,
613613
encoding,
614614
DatabaseEncoding->encoding);
@@ -634,25 +634,25 @@ char *
634634
pg_server_to_any(constchar*s,intlen,intencoding)
635635
{
636636
if (len <=0)
637-
return (char*)s;/* empty string is always valid */
637+
returnunconstify(char*,s);/* empty string is always valid */
638638

639639
if (encoding==DatabaseEncoding->encoding||
640640
encoding==PG_SQL_ASCII)
641-
return (char*)s;/* assume data is valid */
641+
returnunconstify(char*,s);/* assume data is valid */
642642

643643
if (DatabaseEncoding->encoding==PG_SQL_ASCII)
644644
{
645645
/* No conversion is possible, but we must validate the result */
646646
(void)pg_verify_mbstr(encoding,s,len, false);
647-
return (char*)s;
647+
returnunconstify(char*,s);
648648
}
649649

650650
/* Fast path if we can use cached conversion function */
651651
if (encoding==ClientEncoding->encoding)
652652
returnperform_default_encoding_conversion(s,len, false);
653653

654654
/* General case ... will not work outside transactions */
655-
return (char*)pg_do_encoding_conversion((unsignedchar*)s,
655+
return (char*)pg_do_encoding_conversion((unsignedchar*)unconstify(char*,s),
656656
len,
657657
DatabaseEncoding->encoding,
658658
encoding);
@@ -687,7 +687,7 @@ perform_default_encoding_conversion(const char *src, int len,
687687
}
688688

689689
if (flinfo==NULL)
690-
return (char*)src;
690+
returnunconstify(char*,src);
691691

692692
/*
693693
* Allocate space for conversion result, being wary of integer overflow

‎src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4897,7 +4897,7 @@ add_placeholder_variable(const char *name, int elevel)
48974897

48984898
if (!add_guc_variable((structconfig_generic*)var,elevel))
48994899
{
4900-
free((void*)gen->name);
4900+
free(unconstify(char*,gen->name));
49014901
free(var);
49024902
returnNULL;
49034903
}

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ BaseBackup(void)
19701970
*/
19711971
if (format=='p'&& !PQgetisnull(res,i,1))
19721972
{
1973-
char*path= (char*)get_tablespace_mapping(PQgetvalue(res,i,1));
1973+
char*path=unconstify(char*,get_tablespace_mapping(PQgetvalue(res,i,1)));
19741974

19751975
verify_dir_is_empty_or_create(path,&made_tablespace_dirs,&found_tablespace_dirs);
19761976
}

‎src/bin/pg_basebackup/walmethods.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ tar_write(Walfile f, const void *buf, size_t count)
496496
#ifdefHAVE_LIBZ
497497
else
498498
{
499-
if (!tar_write_compressed_data((void*)buf,count, false))
499+
if (!tar_write_compressed_data(unconstify(void*,buf),count, false))
500500
return-1;
501501
((TarMethodFile*)f)->currpos+=count;
502502
returncount;

‎src/bin/pg_dump/compress_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void
312312
WriteDataToArchiveZlib(ArchiveHandle*AH,CompressorState*cs,
313313
constchar*data,size_tdLen)
314314
{
315-
cs->zp->next_in= (void*)data;
315+
cs->zp->next_in= (void*)unconstify(char*,data);
316316
cs->zp->avail_in=dLen;
317317
DeflateCompressorZlib(AH,cs, false);
318318

‎src/bin/psql/prompt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
181181
case'5':
182182
case'6':
183183
case'7':
184-
*buf= (char)strtol(p, (char**)&p,8);
184+
*buf= (char)strtol(p,unconstify(char**,&p),8);
185185
--p;
186186
break;
187187
case'R':

‎src/fe_utils/print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3250,7 +3250,7 @@ printTableCleanup(printTableContent *const content)
32503250
for (i=0;i<content->nrows*content->ncolumns;i++)
32513251
{
32523252
if (content->cellmustfree[i])
3253-
free((char*)content->cells[i]);
3253+
free(unconstify(char*,content->cells[i]));
32543254
}
32553255
free(content->cellmustfree);
32563256
content->cellmustfree=NULL;

‎src/interfaces/libpq/fe-lobj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
341341

342342
argv[1].isint=0;
343343
argv[1].len= (int)len;
344-
argv[1].u.ptr= (int*)buf;
344+
argv[1].u.ptr= (int*)unconstify(char*,buf);
345345

346346
res=PQfn(conn,conn->lobjfuncs->fn_lo_write,
347347
&retval,&result_len,1,argv,2);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp