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

Commit5229db6

Browse files
committed
Rely on sizeof(typename) rather than sizeof(variable) in pqformat.h.
In each of the pq_writeintN functions, the three uses of sizeof() shouldsurely all be consistent. I started out to make them all sizeof(ni),but on reflection let's make them sizeof(typename) instead. That's morelike our usual style elsewhere, and it's just barely possible that thefailures buildfarm member hornet has shown since4c119fb went in arecaused by the compiler getting confused about sizeof() a parameter thatit's optimizing away.In passing, improve a couple of comments.Discussion:https://postgr.es/m/E1e2RML-0002do-Lc@gemulon.postgresql.org
1 parent7d1b8e7 commit5229db6

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

‎src/include/libpq/pqformat.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ extern void pq_sendfloat4(StringInfo buf, float4 f);
3535
externvoidpq_sendfloat8(StringInfobuf,float8f);
3636

3737
/*
38-
* Appenda int8 to a StringInfo buffer, which already has enough space
38+
* Appendan int8 to a StringInfo buffer, which already has enough space
3939
* preallocated.
4040
*
4141
* The use of pg_restrict allows the compiler to optimize the code based on
4242
* the assumption that buf, buf->len, buf->data and *buf->data don't
4343
* overlap. Without the annotation buf->len etc cannot be kept in a register
44-
* over subsequentpq_writeint* calls.
44+
* over subsequentpq_writeintN calls.
4545
*
4646
* The use of StringInfoData * rather than StringInfo is due to MSVC being
4747
* overly picky and demanding a * before a restrict.
@@ -51,51 +51,51 @@ pq_writeint8(StringInfoData *pg_restrict buf, int8 i)
5151
{
5252
int8ni=i;
5353

54-
Assert(buf->len+sizeof(i) <=buf->maxlen);
55-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(ni));
56-
buf->len+=sizeof(i);
54+
Assert(buf->len+sizeof(int8) <=buf->maxlen);
55+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int8));
56+
buf->len+=sizeof(int8);
5757
}
5858

5959
/*
60-
* Appenda int16 to a StringInfo buffer, which already has enough space
60+
* Appendan int16 to a StringInfo buffer, which already has enough space
6161
* preallocated.
6262
*/
6363
staticinlinevoid
6464
pq_writeint16(StringInfoData*pg_restrictbuf,int16i)
6565
{
6666
int16ni=pg_hton16(i);
6767

68-
Assert(buf->len+sizeof(ni) <=buf->maxlen);
69-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(i));
70-
buf->len+=sizeof(i);
68+
Assert(buf->len+sizeof(int16) <=buf->maxlen);
69+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int16));
70+
buf->len+=sizeof(int16);
7171
}
7272

7373
/*
74-
* Appenda int32 to a StringInfo buffer, which already has enough space
74+
* Appendan int32 to a StringInfo buffer, which already has enough space
7575
* preallocated.
7676
*/
7777
staticinlinevoid
7878
pq_writeint32(StringInfoData*pg_restrictbuf,int32i)
7979
{
8080
int32ni=pg_hton32(i);
8181

82-
Assert(buf->len+sizeof(i) <=buf->maxlen);
83-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(i));
84-
buf->len+=sizeof(i);
82+
Assert(buf->len+sizeof(int32) <=buf->maxlen);
83+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int32));
84+
buf->len+=sizeof(int32);
8585
}
8686

8787
/*
88-
* Appenda int64 to a StringInfo buffer, which already has enough space
88+
* Appendan int64 to a StringInfo buffer, which already has enough space
8989
* preallocated.
9090
*/
9191
staticinlinevoid
9292
pq_writeint64(StringInfoData*pg_restrictbuf,int64i)
9393
{
9494
int64ni=pg_hton64(i);
9595

96-
Assert(buf->len+sizeof(i) <=buf->maxlen);
97-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(i));
98-
buf->len+=sizeof(i);
96+
Assert(buf->len+sizeof(int64) <=buf->maxlen);
97+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int64));
98+
buf->len+=sizeof(int64);
9999
}
100100

101101
/*
@@ -131,31 +131,31 @@ pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
131131
staticinlinevoid
132132
pq_sendint8(StringInfobuf,int8i)
133133
{
134-
enlargeStringInfo(buf,sizeof(i));
134+
enlargeStringInfo(buf,sizeof(int8));
135135
pq_writeint8(buf,i);
136136
}
137137

138138
/* append a binary int16 to a StringInfo buffer */
139139
staticinlinevoid
140140
pq_sendint16(StringInfobuf,int16i)
141141
{
142-
enlargeStringInfo(buf,sizeof(i));
142+
enlargeStringInfo(buf,sizeof(int16));
143143
pq_writeint16(buf,i);
144144
}
145145

146146
/* append a binary int32 to a StringInfo buffer */
147147
staticinlinevoid
148148
pq_sendint32(StringInfobuf,int32i)
149149
{
150-
enlargeStringInfo(buf,sizeof(i));
150+
enlargeStringInfo(buf,sizeof(int32));
151151
pq_writeint32(buf,i);
152152
}
153153

154154
/* append a binary int64 to a StringInfo buffer */
155155
staticinlinevoid
156156
pq_sendint64(StringInfobuf,int64i)
157157
{
158-
enlargeStringInfo(buf,sizeof(i));
158+
enlargeStringInfo(buf,sizeof(int64));
159159
pq_writeint64(buf,i);
160160
}
161161

@@ -169,7 +169,7 @@ pq_sendbyte(StringInfo buf, int8 byt)
169169
/*
170170
* Append a binary integer to a StringInfo buffer
171171
*
172-
* This function is deprecated.
172+
* This function is deprecated; prefer use of the functions above.
173173
*/
174174
staticinlinevoid
175175
pq_sendint(StringInfobuf,inti,intb)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp