Skip to content

Commit 5229db6

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() should surely all be consistent. I started out to make them all sizeof(ni), but on reflection let's make them sizeof(typename) instead. That's more like our usual style elsewhere, and it's just barely possible that the failures buildfarm member hornet has shown since 4c119fb went in are caused by the compiler getting confused about sizeof() a parameter that it's optimizing away. In passing, improve a couple of comments. Discussion: https://postgr.es/m/E1e2RML-0002do-Lc@gemulon.postgresql.org
1 parent 7d1b8e7 commit 5229db6

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
extern void pq_sendfloat8(StringInfo buf, float8 f);
3636

3737
/*
38-
* Append a int8 to a StringInfo buffer, which already has enough space
38+
* Append an 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 subsequent pq_writeint* calls.
44+
* over subsequent pq_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
int8 ni = 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-
* Append a int16 to a StringInfo buffer, which already has enough space
60+
* Append an int16 to a StringInfo buffer, which already has enough space
6161
* preallocated.
6262
*/
6363
static inline void
6464
pq_writeint16(StringInfoData *pg_restrict buf, int16 i)
6565
{
6666
int16 ni = 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-
* Append a int32 to a StringInfo buffer, which already has enough space
74+
* Append an int32 to a StringInfo buffer, which already has enough space
7575
* preallocated.
7676
*/
7777
static inline void
7878
pq_writeint32(StringInfoData *pg_restrict buf, int32 i)
7979
{
8080
int32 ni = 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-
* Append a int64 to a StringInfo buffer, which already has enough space
88+
* Append an int64 to a StringInfo buffer, which already has enough space
8989
* preallocated.
9090
*/
9191
static inline void
9292
pq_writeint64(StringInfoData *pg_restrict buf, int64 i)
9393
{
9494
int64 ni = 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
static inline void
132132
pq_sendint8(StringInfo buf, int8 i)
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
static inline void
140140
pq_sendint16(StringInfo buf, int16 i)
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
static inline void
148148
pq_sendint32(StringInfo buf, int32 i)
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
static inline void
156156
pq_sendint64(StringInfo buf, int64 i)
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
static inline void
175175
pq_sendint(StringInfo buf, int i, int b)

0 commit comments

Comments
 (0)