pg_bsd_indent - improvements around offsetof and sizeof
Hello,
I think I've managed to improve pg_bsd_indent's handling of two types of
cases.
The first are like in this example:
- hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) +1);
+ hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
Pristine pg_bsd_indent is inconsistent in masking parentheses as those
that are part of a cast and those that "are part of sizeof": seeing a
type name following an lparen it always masks that lparen as a part of a
cast; seeing an rparen it only removes the bit if it doesn't overlap
with sizeof_mask. In the example above, "(HTAB" started both "cast
parens" and "sizeof parens" at the same time, and the immediately
following rparen ended only the "sizeof parens". According to indent,
the cast-to type then ends at "tabname)" and what follows is the cast's
operand, including the + operator; in that case it's assumed to be unary
and not binary, which is why indent doesn't add the space after it.
The fix was to make it consistent about masking parens:
- ps.cast_mask |= 1 << ps.p_l_follow;
+ ps.cast_mask |= (1 << ps.p_l_follow & ~ps.sizeof_mask);
The second type of cases are like this:
- nse = palloc(offsetof(PLpgSQL_nsitem, name) +strlen(name) + 1);
+ nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
pg_bsd_indent simply hasn't been taught that a parenthesized type name
following the offsetof macro and then an lparen is another exception to
the rule of thumb that a construction like that generally means a cast.
You'll also notice other, seemingly unrelated changes, most notably the
rearrangement in numbers assigned to keywords. I've done it that way so
that it was easier and simpler to keep the -bs option functioning as
designed.
I've also renamed "sizeof_mask" to "not_cast_mask", because I think the
latter is a better description of what the mask does (it prevents
interpreting parenthesized type names as a cast where they aren't,
namely where they follow sizeof or offsetof; I haven't done any support
for function declarators and I don't plan to - the fact that
pg_bsd_indent thinks that "(int" in "char func(int);" begins a cast is
amusing but it seems harmless for now).
I'm attaching the patch for pg_bsd_indent and also a full diff that
shows the change in its behavior when run against PG's sources.
Attachments:
pg_bsd_indent-sizeof-offsetof-fix.difftext/x-patch; name=pg_bsd_indent-sizeof-offsetof-fix.diffDownload
diff -Burw indent.c indent.c
--- indent.c 2014-01-31 04:06:43.000000000 +0100
+++ indent.c 2016-05-22 19:24:01.666077311 +0200
@@ -568,7 +568,9 @@
* happy */
if (ps.want_blank && *token != '[' &&
(ps.last_token != ident || proc_calls_space
- || (ps.its_a_keyword && (!ps.sizeof_keyword || Bill_Shannon))))
+ /* offsetof (1) is never allowed a space; sizeof (2) iff -bs;
+ * all other keywords (>2) always get a space before lparen */
+ || (ps.keyword + Bill_Shannon > 2)))
*e_code++ = ' ';
if (ps.in_decl && !ps.block_init) {
if (troff && !ps.dumped_decl_indent && !is_procname && ps.last_token == decl) {
@@ -601,17 +603,19 @@
* structure decl or
* initialization */
}
- if (ps.sizeof_keyword)
- ps.sizeof_mask |= 1 << ps.p_l_follow;
+ /* a parenthesized type name following sizeof or offsetof is not
+ * a cast */
+ if (ps.keyword == 1 || ps.keyword == 2)
+ ps.not_cast_mask |= 1 << ps.p_l_follow;
break;
case rparen: /* got a ')' or ']' */
rparen_count--;
- if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) {
+ if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) {
ps.last_u_d = true;
ps.cast_mask &= (1 << ps.p_l_follow) - 1;
}
- ps.sizeof_mask &= (1 << ps.p_l_follow) - 1;
+ ps.not_cast_mask &= (1 << ps.p_l_follow) - 1;
if (--ps.p_l_follow < 0) {
ps.p_l_follow = 0;
diag(0, "Extra %c", *token);
@@ -780,7 +784,7 @@
if (ps.last_token == rparen && rparen_count == 0)
ps.in_parameter_declaration = 0;
ps.cast_mask = 0;
- ps.sizeof_mask = 0;
+ ps.not_cast_mask = 0;
ps.block_init = 0;
ps.block_init_level = 0;
ps.just_saw_decl--;
@@ -1042,7 +1046,7 @@
copy_id:
if (ps.want_blank)
*e_code++ = ' ';
- if (troff && ps.its_a_keyword) {
+ if (troff && ps.keyword) {
e_code = chfont(&bodyf, &keywordf, e_code);
for (t_ptr = token; *t_ptr; ++t_ptr) {
CHECK_SIZE_CODE;
diff -Burw indent_globs.h indent_globs.h
--- indent_globs.h 2005-11-15 01:30:24.000000000 +0100
+++ indent_globs.h 2016-05-22 19:23:45.067093287 +0200
@@ -255,10 +255,10 @@
* comment. In that case, the first non-blank
* char should be lined up with the comment / */
int comment_delta, n_comment_delta;
- int cast_mask; /* indicates which close parens close off
- * casts */
- int sizeof_mask; /* indicates which close parens close off
- * sizeof''s */
+ int cast_mask; /* indicates which close parens potentially
+ * close off casts */
+ int not_cast_mask; /* indicates which close parens definitely
+ * close off something else than casts */
int block_init; /* true iff inside a block initialization */
int block_init_level; /* The level of brace nesting in an
* initialization */
@@ -327,8 +327,7 @@
int else_if; /* True iff else if pairs should be handled
* specially */
int decl_indent; /* column to indent declared identifiers to */
- int its_a_keyword;
- int sizeof_keyword;
+ int keyword; /* the type of a keyword or 0 */
int dumped_decl_indent;
float case_indent; /* The distance to indent case labels from the
* switch statement */
Binary files indent.o and indent.o differ
Binary files io.o and io.o differ
diff -Burw lexi.c lexi.c
--- lexi.c 2005-11-15 01:30:24.000000000 +0100
+++ lexi.c 2016-05-22 19:24:06.591072566 +0200
@@ -95,13 +95,13 @@
struct templ specials[16384] =
{
- {"switch", 1},
- {"case", 2},
- {"break", 0},
+ {"switch", 7},
+ {"case", 8},
+ {"break", 9},
{"struct", 3},
{"union", 3},
{"enum", 3},
- {"default", 2},
+ {"default", 8},
{"int", 4},
{"char", 4},
{"float", 4},
@@ -115,14 +115,15 @@
{"global", 4},
{"extern", 4},
{"void", 4},
- {"goto", 0},
- {"return", 0},
+ {"goto", 9},
+ {"return", 9},
{"if", 5},
{"while", 5},
{"for", 5},
{"else", 6},
{"do", 6},
- {"sizeof", 7},
+ {"sizeof", 2},
+ {"offsetof", 1},
{0, 0}
};
@@ -262,8 +263,7 @@
if (++buf_ptr >= buf_end)
fill_buffer();
}
- ps.its_a_keyword = false;
- ps.sizeof_keyword = false;
+ ps.keyword = 0;
if (l_struct) { /* if last token was 'struct', then this token
* should be treated as a declaration */
l_struct = false;
@@ -297,12 +297,12 @@
}
if (p->rwd) { /* we have a keyword */
found_keyword:
- ps.its_a_keyword = true;
+ ps.keyword = p->rwcode;
ps.last_u_d = true;
switch (p->rwcode) {
- case 1:/* it is a switch */
+ case 7:/* it is a switch */
return (swstmt);
- case 2:/* a case or default */
+ case 8:/* a case or default */
return (casestmt);
case 3:/* a "struct" */
@@ -316,7 +316,11 @@
*/
case 4:/* one of the declaration keywords */
if (ps.p_l_follow) {
- ps.cast_mask |= 1 << ps.p_l_follow;
+ /* A type name following an lparen is a cast unless it's
+ * a part of a function declarator, or an operand of the
+ * sizeof operator, or an argument of the offsetof macro
+ */
+ ps.cast_mask |= (1 << ps.p_l_follow & ~ps.not_cast_mask);
break; /* inside parens: cast */
}
last_code = decl;
@@ -328,8 +332,6 @@
case 6:/* do, else */
return (sp_nparen);
- case 7:
- ps.sizeof_keyword = true;
default: /* all others are treated like any
* other identifier */
return (ident);
@@ -357,7 +359,7 @@
&& (ps.last_token == rparen || ps.last_token == semicolon ||
ps.last_token == decl ||
ps.last_token == lbrace || ps.last_token == rbrace)) {
- ps.its_a_keyword = true;
+ ps.keyword = 4; /* a type name */
ps.last_u_d = true;
last_code = decl;
return decl;
effect_on_pg.difftext/x-patch; name=effect_on_pg.diffDownload
diff -ur 2/contrib/fuzzystrmatch/fuzzystrmatch.c 3/contrib/fuzzystrmatch/fuzzystrmatch.c
--- 2/contrib/fuzzystrmatch/fuzzystrmatch.c 2016-05-22 09:47:04.223053228 +0200
+++ 3/contrib/fuzzystrmatch/fuzzystrmatch.c 2016-05-22 19:31:41.150634978 +0200
@@ -388,7 +388,7 @@
/*-- Allocate memory for our phoned_phrase --*/
if (max_phonemes == 0)
{ /* Assume largest possible */
- *phoned_word = palloc(sizeof(char) * strlen(word) +1);
+ *phoned_word = palloc(sizeof(char) * strlen(word) + 1);
}
else
{
diff -ur 2/contrib/pg_trgm/trgm_op.c 3/contrib/pg_trgm/trgm_op.c
--- 2/contrib/pg_trgm/trgm_op.c 2016-05-22 09:47:03.424053922 +0200
+++ 3/contrib/pg_trgm/trgm_op.c 2016-05-22 19:31:40.328635769 +0200
@@ -325,7 +325,7 @@
protect_out_of_mem(slen);
- trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) *3);
+ trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) * 3);
trg->flag = ARRKEY;
len = generate_trgm_only(GETARR(trg), str, slen);
@@ -572,8 +572,8 @@
protect_out_of_mem(slen1 + slen2);
/* Make positional trigrams */
- trg1 = (trgm *) palloc(sizeof(trgm) * (slen1 / 2 + 1) *3);
- trg2 = (trgm *) palloc(sizeof(trgm) * (slen2 / 2 + 1) *3);
+ trg1 = (trgm *) palloc(sizeof(trgm) * (slen1 / 2 + 1) * 3);
+ trg2 = (trgm *) palloc(sizeof(trgm) * (slen2 / 2 + 1) * 3);
len1 = generate_trgm_only(trg1, str1, slen1);
len2 = generate_trgm_only(trg2, str2, slen2);
@@ -806,7 +806,7 @@
protect_out_of_mem(slen);
- trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) *3);
+ trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) * 3);
trg->flag = ARRKEY;
SET_VARSIZE(trg, TRGMHDRSIZE);
diff -ur 2/contrib/pg_visibility/pg_visibility.c 3/contrib/pg_visibility/pg_visibility.c
--- 2/contrib/pg_visibility/pg_visibility.c 2016-05-22 09:47:03.371053968 +0200
+++ 3/contrib/pg_visibility/pg_visibility.c 2016-05-22 19:31:40.276635820 +0200
@@ -301,7 +301,7 @@
rel = relation_open(relid, AccessShareLock);
nblocks = RelationGetNumberOfBlocks(rel);
- info = palloc0(offsetof(vbits, bits) +nblocks);
+ info = palloc0(offsetof(vbits, bits) + nblocks);
info->next = 0;
info->count = nblocks;
diff -ur 2/contrib/spi/timetravel.c 3/contrib/spi/timetravel.c
--- 2/contrib/spi/timetravel.c 2016-05-22 09:47:02.096055076 +0200
+++ 3/contrib/spi/timetravel.c 2016-05-22 19:31:39.046637004 +0200
@@ -460,7 +460,7 @@
s = rname = DatumGetCString(DirectFunctionCall1(nameout, NameGetDatum(relname)));
if (s)
{
- pp = malloc(offsetof(TTOffList, name) +strlen(rname) + 1);
+ pp = malloc(offsetof(TTOffList, name) + strlen(rname) + 1);
if (pp)
{
pp->next = NULL;
diff -ur 2/src/backend/access/common/reloptions.c 3/src/backend/access/common/reloptions.c
--- 2/src/backend/access/common/reloptions.c 2016-05-22 09:47:01.656055458 +0200
+++ 3/src/backend/access/common/reloptions.c 2016-05-22 19:31:38.634637400 +0200
@@ -1277,33 +1277,33 @@
static const relopt_parse_elt tab[] = {
{"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
{"autovacuum_enabled", RELOPT_TYPE_BOOL,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, enabled)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
{"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_threshold)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
{"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_threshold)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
{"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_delay)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
{"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_cost_limit)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
{"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_min_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
{"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_max_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
{"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, freeze_table_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
{"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_min_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
{"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_max_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
{"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, multixact_freeze_table_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
{"log_autovacuum_min_duration", RELOPT_TYPE_INT,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, log_min_duration)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
{"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
{"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
- offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
{"user_catalog_table", RELOPT_TYPE_BOOL,
offsetof(StdRdOptions, user_catalog_table)},
{"parallel_degree", RELOPT_TYPE_INT,
diff -ur 2/src/backend/access/gin/gindatapage.c 3/src/backend/access/gin/gindatapage.c
--- 2/src/backend/access/gin/gindatapage.c 2016-05-22 09:47:01.544055555 +0200
+++ 3/src/backend/access/gin/gindatapage.c 2016-05-22 19:31:38.493637536 +0200
@@ -390,7 +390,7 @@
if (offset != maxoff + 1)
memmove(ptr + sizeof(PostingItem),
ptr,
- (maxoff - offset + 1) *sizeof(PostingItem));
+ (maxoff - offset + 1) * sizeof(PostingItem));
}
memcpy(ptr, data, sizeof(PostingItem));
diff -ur 2/src/backend/access/transam/xlog.c 3/src/backend/access/transam/xlog.c
--- 2/src/backend/access/transam/xlog.c 2016-05-22 09:46:59.522057311 +0200
+++ 3/src/backend/access/transam/xlog.c 2016-05-22 19:31:36.446639506 +0200
@@ -4703,7 +4703,7 @@
/* WAL insertion locks. Ensure they're aligned to the full padded size */
allocptr += sizeof(WALInsertLockPadded) -
- ((uintptr_t) allocptr) %sizeof(WALInsertLockPadded);
+ ((uintptr_t) allocptr) % sizeof(WALInsertLockPadded);
WALInsertLocks = XLogCtl->Insert.WALInsertLocks =
(WALInsertLockPadded *) allocptr;
allocptr += sizeof(WALInsertLockPadded) * NUM_XLOGINSERT_LOCKS;
diff -ur 2/src/backend/lib/binaryheap.c 3/src/backend/lib/binaryheap.c
--- 2/src/backend/lib/binaryheap.c 2016-05-22 09:46:56.162060229 +0200
+++ 3/src/backend/lib/binaryheap.c 2016-05-22 19:31:32.874642945 +0200
@@ -35,7 +35,7 @@
int sz;
binaryheap *heap;
- sz = offsetof(binaryheap, bh_nodes) +sizeof(Datum) * capacity;
+ sz = offsetof(binaryheap, bh_nodes) + sizeof(Datum) * capacity;
heap = (binaryheap *) palloc(sz);
heap->bh_space = capacity;
heap->bh_compare = compare;
diff -ur 2/src/backend/postmaster/pgstat.c 3/src/backend/postmaster/pgstat.c
--- 2/src/backend/postmaster/pgstat.c 2016-05-22 09:46:53.037062944 +0200
+++ 3/src/backend/postmaster/pgstat.c 2016-05-22 19:31:29.862645845 +0200
@@ -1027,7 +1027,7 @@
if (msg.m_nentries >= PGSTAT_NUM_TABPURGE)
{
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
- +msg.m_nentries * sizeof(Oid);
+ + msg.m_nentries * sizeof(Oid);
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
msg.m_databaseid = MyDatabaseId;
@@ -1043,7 +1043,7 @@
if (msg.m_nentries > 0)
{
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
- +msg.m_nentries * sizeof(Oid);
+ + msg.m_nentries * sizeof(Oid);
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
msg.m_databaseid = MyDatabaseId;
@@ -1087,7 +1087,7 @@
if (f_msg.m_nentries >= PGSTAT_NUM_FUNCPURGE)
{
len = offsetof(PgStat_MsgFuncpurge, m_functionid[0])
- +f_msg.m_nentries * sizeof(Oid);
+ + f_msg.m_nentries * sizeof(Oid);
pgstat_send(&f_msg, len);
@@ -1101,7 +1101,7 @@
if (f_msg.m_nentries > 0)
{
len = offsetof(PgStat_MsgFuncpurge, m_functionid[0])
- +f_msg.m_nentries * sizeof(Oid);
+ + f_msg.m_nentries * sizeof(Oid);
pgstat_send(&f_msg, len);
}
@@ -1204,7 +1204,7 @@
msg.m_tableid[0] = relid;
msg.m_nentries = 1;
- len = offsetof(PgStat_MsgTabpurge, m_tableid[0]) +sizeof(Oid);
+ len = offsetof(PgStat_MsgTabpurge, m_tableid[0]) + sizeof(Oid);
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
msg.m_databaseid = MyDatabaseId;
diff -ur 2/src/backend/postmaster/syslogger.c 3/src/backend/postmaster/syslogger.c
--- 2/src/backend/postmaster/syslogger.c 2016-05-22 09:46:52.823063130 +0200
+++ 3/src/backend/postmaster/syslogger.c 2016-05-22 19:31:29.656646043 +0200
@@ -785,7 +785,7 @@
int dest = LOG_DESTINATION_STDERR;
/* While we have enough for a header, process data... */
- while (count >= (int) (offsetof(PipeProtoHeader, data) +1))
+ while (count >= (int) (offsetof(PipeProtoHeader, data) + 1))
{
PipeProtoHeader p;
int chunklen;
diff -ur 2/src/backend/replication/slot.c 3/src/backend/replication/slot.c
--- 2/src/backend/replication/slot.c 2016-05-22 09:46:52.303063581 +0200
+++ 3/src/backend/replication/slot.c 2016-05-22 19:31:29.062646615 +0200
@@ -140,7 +140,7 @@
ReplSlotIOLWLockTranche.name = "replication_slot_io";
ReplSlotIOLWLockTranche.array_base =
- ((char *) ReplicationSlotCtl) + offsetof(ReplicationSlotCtlData, replication_slots) +offsetof(ReplicationSlot, io_in_progress_lock);
+ ((char *) ReplicationSlotCtl) + offsetof(ReplicationSlotCtlData, replication_slots) + offsetof(ReplicationSlot, io_in_progress_lock);
ReplSlotIOLWLockTranche.array_stride = sizeof(ReplicationSlot);
LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
&ReplSlotIOLWLockTranche);
diff -ur 2/src/backend/storage/ipc/dsm.c 3/src/backend/storage/ipc/dsm.c
--- 2/src/backend/storage/ipc/dsm.c 2016-05-22 09:46:51.781064035 +0200
+++ 3/src/backend/storage/ipc/dsm.c 2016-05-22 19:31:28.561647097 +0200
@@ -1040,5 +1040,5 @@
dsm_control_bytes_needed(uint32 nitems)
{
return offsetof(dsm_control_header, item)
- +sizeof(dsm_control_item) * (uint64) nitems;
+ + sizeof(dsm_control_item) * (uint64) nitems;
}
diff -ur 2/src/backend/storage/ipc/shm_mq.c 3/src/backend/storage/ipc/shm_mq.c
--- 2/src/backend/storage/ipc/shm_mq.c 2016-05-22 09:46:51.531064252 +0200
+++ 3/src/backend/storage/ipc/shm_mq.c 2016-05-22 19:31:28.395647257 +0200
@@ -364,7 +364,7 @@
{
Assert(mqh->mqh_partial_bytes < sizeof(Size));
res = shm_mq_send_bytes(mqh, sizeof(Size) - mqh->mqh_partial_bytes,
- ((char *) &nbytes) +mqh->mqh_partial_bytes,
+ ((char *) &nbytes) + mqh->mqh_partial_bytes,
nowait, &bytes_written);
mqh->mqh_partial_bytes += bytes_written;
if (res != SHM_MQ_SUCCESS)
diff -ur 2/src/backend/storage/ipc/shm_toc.c 3/src/backend/storage/ipc/shm_toc.c
--- 2/src/backend/storage/ipc/shm_toc.c 2016-05-22 09:46:51.509064271 +0200
+++ 3/src/backend/storage/ipc/shm_toc.c 2016-05-22 19:31:28.373647278 +0200
@@ -96,7 +96,7 @@
total_bytes = vtoc->toc_total_bytes;
allocated_bytes = vtoc->toc_allocated_bytes;
nentry = vtoc->toc_nentry;
- toc_bytes = offsetof(shm_toc, toc_entry) +nentry * sizeof(shm_toc_entry)
+ toc_bytes = offsetof(shm_toc, toc_entry) + nentry * sizeof(shm_toc_entry)
+ allocated_bytes;
/* Check for memory exhaustion and overflow. */
@@ -132,7 +132,7 @@
nentry = vtoc->toc_nentry;
SpinLockRelease(&toc->toc_mutex);
- toc_bytes = offsetof(shm_toc, toc_entry) +nentry * sizeof(shm_toc_entry);
+ toc_bytes = offsetof(shm_toc, toc_entry) + nentry * sizeof(shm_toc_entry);
Assert(allocated_bytes + BUFFERALIGN(toc_bytes) <= total_bytes);
return total_bytes - (allocated_bytes + BUFFERALIGN(toc_bytes));
}
@@ -176,7 +176,7 @@
total_bytes = vtoc->toc_total_bytes;
allocated_bytes = vtoc->toc_allocated_bytes;
nentry = vtoc->toc_nentry;
- toc_bytes = offsetof(shm_toc, toc_entry) +nentry * sizeof(shm_toc_entry)
+ toc_bytes = offsetof(shm_toc, toc_entry) + nentry * sizeof(shm_toc_entry)
+ allocated_bytes;
/* Check for memory exhaustion and overflow. */
diff -ur 2/src/backend/utils/adt/geo_ops.c 3/src/backend/utils/adt/geo_ops.c
--- 2/src/backend/utils/adt/geo_ops.c 2016-05-22 09:46:49.753065796 +0200
+++ 3/src/backend/utils/adt/geo_ops.c 2016-05-22 19:31:26.697648892 +0200
@@ -1333,7 +1333,7 @@
}
base_size = sizeof(path->p[0]) * npts;
- size = offsetof(PATH, p) +base_size;
+ size = offsetof(PATH, p) + base_size;
/* Check for integer overflow */
if (base_size / npts != sizeof(path->p[0]) || size <= base_size)
@@ -1403,7 +1403,7 @@
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid number of points in external \"path\" value")));
- size = offsetof(PATH, p) +sizeof(path->p[0]) * npts;
+ size = offsetof(PATH, p) + sizeof(path->p[0]) * npts;
path = (PATH *) palloc(size);
SET_VARSIZE(path, size);
@@ -3423,7 +3423,7 @@
"polygon", str)));
base_size = sizeof(poly->p[0]) * npts;
- size = offsetof(POLYGON, p) +base_size;
+ size = offsetof(POLYGON, p) + base_size;
/* Check for integer overflow */
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
@@ -3478,7 +3478,7 @@
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid number of points in external \"polygon\" value")));
- size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * npts;
+ size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * npts;
poly = (POLYGON *) palloc0(size); /* zero any holes */
SET_VARSIZE(poly, size);
@@ -4235,7 +4235,7 @@
PG_RETURN_NULL();
base_size = sizeof(p1->p[0]) * (p1->npts + p2->npts);
- size = offsetof(PATH, p) +base_size;
+ size = offsetof(PATH, p) + base_size;
/* Check for integer overflow */
if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) ||
@@ -4377,7 +4377,7 @@
* Never overflows: the old size fit in MaxAllocSize, and the new size is
* just a small constant larger.
*/
- size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * path->npts;
+ size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * path->npts;
poly = (POLYGON *) palloc(size);
SET_VARSIZE(poly, size);
@@ -4452,7 +4452,7 @@
int size;
/* map four corners of the box to a polygon */
- size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * 4;
+ size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * 4;
poly = (POLYGON *) palloc(size);
SET_VARSIZE(poly, size);
@@ -4486,7 +4486,7 @@
* Never overflows: the old size fit in MaxAllocSize, and the new size is
* smaller by a small constant.
*/
- size = offsetof(PATH, p) +sizeof(path->p[0]) * poly->npts;
+ size = offsetof(PATH, p) + sizeof(path->p[0]) * poly->npts;
path = (PATH *) palloc(size);
SET_VARSIZE(path, size);
@@ -5164,7 +5164,7 @@
errmsg("must request at least 2 points")));
base_size = sizeof(poly->p[0]) * npts;
- size = offsetof(POLYGON, p) +base_size;
+ size = offsetof(POLYGON, p) + base_size;
/* Check for integer overflow */
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
diff -ur 2/src/backend/utils/cache/catcache.c 3/src/backend/utils/cache/catcache.c
--- 2/src/backend/utils/cache/catcache.c 2016-05-22 09:46:46.925068252 +0200
+++ 3/src/backend/utils/cache/catcache.c 2016-05-22 19:31:23.932651553 +0200
@@ -1592,7 +1592,7 @@
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
nmembers = list_length(ctlist);
cl = (CatCList *)
- palloc(offsetof(CatCList, members) +nmembers * sizeof(CatCTup *));
+ palloc(offsetof(CatCList, members) + nmembers * sizeof(CatCTup *));
heap_copytuple_with_tuple(ntp, &cl->tuple);
MemoryContextSwitchTo(oldcxt);
heap_freetuple(ntp);
diff -ur 2/src/backend/utils/fmgr/dfmgr.c 3/src/backend/utils/fmgr/dfmgr.c
--- 2/src/backend/utils/fmgr/dfmgr.c 2016-05-22 09:46:46.511068612 +0200
+++ 3/src/backend/utils/fmgr/dfmgr.c 2016-05-22 19:31:23.584651888 +0200
@@ -209,7 +209,7 @@
* File not loaded yet.
*/
file_scanner = (DynamicFileList *)
- malloc(offsetof(DynamicFileList, filename) +strlen(libname) + 1);
+ malloc(offsetof(DynamicFileList, filename) + strlen(libname) + 1);
if (file_scanner == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
diff -ur 2/src/backend/utils/hash/dynahash.c 3/src/backend/utils/hash/dynahash.c
--- 2/src/backend/utils/hash/dynahash.c 2016-05-22 09:46:46.432068680 +0200
+++ 3/src/backend/utils/hash/dynahash.c 2016-05-22 19:31:23.508651962 +0200
@@ -333,7 +333,7 @@
}
/* Initialize the hash header, plus a copy of the table name */
- hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) +1);
+ hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
MemSet(hashp, 0, sizeof(HTAB));
hashp->tabname = (char *) (hashp + 1);
diff -ur 2/src/common/exec.c 3/src/common/exec.c
--- 2/src/common/exec.c 2016-05-22 09:46:42.860071783 +0200
+++ 3/src/common/exec.c 2016-05-22 19:31:19.763655567 +0200
@@ -678,7 +678,7 @@
/* Figure out the size of the new ACL */
dwNewAclSize = asi.AclBytesInUse + sizeof(ACCESS_ALLOWED_ACE) +
- GetLengthSid(pTokenUser->User.Sid) -sizeof(DWORD);
+ GetLengthSid(pTokenUser->User.Sid) - sizeof(DWORD);
/* Allocate the ACL buffer & initialize it */
pacl = (PACL) LocalAlloc(LPTR, dwNewAclSize);
diff -ur 2/src/fe_utils/simple_list.c 3/src/fe_utils/simple_list.c
--- 2/src/fe_utils/simple_list.c 2016-05-22 09:46:42.651071964 +0200
+++ 3/src/fe_utils/simple_list.c 2016-05-22 19:31:19.541655780 +0200
@@ -65,7 +65,7 @@
SimpleStringListCell *cell;
cell = (SimpleStringListCell *)
- pg_malloc(offsetof(SimpleStringListCell, val) +strlen(val) + 1);
+ pg_malloc(offsetof(SimpleStringListCell, val) + strlen(val) + 1);
cell->next = NULL;
cell->touched = false;
diff -ur 2/src/interfaces/ecpg/preproc/output.c 3/src/interfaces/ecpg/preproc/output.c
--- 2/src/interfaces/ecpg/preproc/output.c 2016-05-22 09:46:34.437079098 +0200
+++ 3/src/interfaces/ecpg/preproc/output.c 2016-05-22 19:31:11.317663697 +0200
@@ -96,7 +96,7 @@
)
{
/* "* 2" here is for escaping '\' and '"' below */
- char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) *2);
+ char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2);
char *src,
*dest;
diff -ur 2/src/interfaces/libpq/fe-exec.c 3/src/interfaces/libpq/fe-exec.c
--- 2/src/interfaces/libpq/fe-exec.c 2016-05-22 09:46:34.144079353 +0200
+++ 3/src/interfaces/libpq/fe-exec.c 2016-05-22 19:31:11.004663999 +0200
@@ -939,7 +939,7 @@
* Store new info as a single malloc block
*/
pstatus = (pgParameterStatus *) malloc(sizeof(pgParameterStatus) +
- strlen(name) +strlen(value) + 2);
+ strlen(name) + strlen(value) + 2);
if (pstatus)
{
char *ptr;
diff -ur 2/src/pl/plpgsql/src/pl_funcs.c 3/src/pl/plpgsql/src/pl_funcs.c
--- 2/src/pl/plpgsql/src/pl_funcs.c 2016-05-22 09:46:33.621079807 +0200
+++ 3/src/pl/plpgsql/src/pl_funcs.c 2016-05-22 19:31:10.275664700 +0200
@@ -97,7 +97,7 @@
/* first item added must be a label */
Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
- nse = palloc(offsetof(PLpgSQL_nsitem, name) +strlen(name) + 1);
+ nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
nse->itemtype = itemtype;
nse->itemno = itemno;
nse->prev = ns_top;
On Sun, May 22, 2016 at 4:16 PM, Piotr Stefaniak
<postgres@piotr-stefaniak.me> wrote:
I think I've managed to improve pg_bsd_indent's handling of two types of
cases.
Wow, that seems pretty great. I haven't scrutinized your changes to
pg_bsd_indent, but effect_on_pg.diff looks like a large improvement.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
On Sun, May 22, 2016 at 4:16 PM, Piotr Stefaniak
<postgres@piotr-stefaniak.me> wrote:I think I've managed to improve pg_bsd_indent's handling of two types of
cases.
Wow, that seems pretty great. I haven't scrutinized your changes to
pg_bsd_indent, but effect_on_pg.diff looks like a large improvement.
I'm excited about this too, not least because it suggests that maybe
bsdindent isn't quite as opaque as it appears. I'd love to see a fix
for its brain damage around function pointer typedef formatting, too.
Assuming this patch withstands more careful review, we will need to think
about project policy for how/when to apply such fixes. The last time
we made any real change to pgindent's behavior was when we changed its
wrapping of comment blocks back around 8.1 ... and I cursed that decision
at least weekly for the next five years, because it caused constant
back-patching pain. If we make a change like this, I think we should
*strongly* consider reindenting all the live back branches along with
HEAD.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2016-05-25 21:13, Tom Lane wrote:
I'd love to see a fix for its brain damage around function pointer typedef formatting, too.
Show me a few examples and I'll look into it.
I'm excited about this too, not least because it suggests that maybe bsdindent isn't quite as opaque as it appears.
It's old, hacked on many times over the past few decades and
historically just a band-aid rather than something designed from the
ground up, so it's not easy to work with. Which is why I think that a
newer tool (like ClangFormat) should be considered as a replacement for
pg_bsd_indent.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2016-05-25 22:01:53 +0200, Piotr Stefaniak wrote:
On 2016-05-25 21:13, Tom Lane wrote:
I'd love to see a fix for its brain damage around function pointer typedef formatting, too.
Show me a few examples and I'll look into it.
I'm excited about this too, not least because it suggests that maybe bsdindent isn't quite as opaque as it appears.
It's old, hacked on many times over the past few decades and historically
just a band-aid rather than something designed from the ground up, so it's
not easy to work with. Which is why I think that a newer tool (like
ClangFormat) should be considered as a replacement for pg_bsd_indent.
FWIW, I looked at using clang-format at some point, and it looked like
it'd be a number of additional options to make it work for our case
without changing the code layout too much. There seemed limited
enthusiasm from the authors about accepting relevant options.
Andres
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andres Freund wrote:
On 2016-05-25 22:01:53 +0200, Piotr Stefaniak wrote:
On 2016-05-25 21:13, Tom Lane wrote:
I'd love to see a fix for its brain damage around function pointer typedef formatting, too.
Show me a few examples and I'll look into it.
See src/include/replication/logical.h; the problem there is pretty
obvious.
For another broken construct, see tupleLockExtraInfo in
src/backend/access/heap/heapam.c.
Also, see pre_indent and post_indent in src/tools/pgindent/pgindent.
A few bugs in pg_bsd_indent are worked around there.
I'm excited about this too, not least because it suggests that maybe bsdindent isn't quite as opaque as it appears.
It's old, hacked on many times over the past few decades and historically
just a band-aid rather than something designed from the ground up, so it's
not easy to work with. Which is why I think that a newer tool (like
ClangFormat) should be considered as a replacement for pg_bsd_indent.FWIW, I looked at using clang-format at some point, and it looked like
it'd be a number of additional options to make it work for our case
without changing the code layout too much. There seemed limited
enthusiasm from the authors about accepting relevant options.
FWIW I looked at GNU indent a year ago or so, and there were a few
things about our style that they simply did not have options for. I
don't recall the details but my conclusion was that it was a dead end.
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2016-05-25 18:17:51 -0400, Alvaro Herrera wrote:
Andres Freund wrote:
On 2016-05-25 22:01:53 +0200, Piotr Stefaniak wrote:
FWIW, I looked at using clang-format at some point, and it looked like
it'd be a number of additional options to make it work for our case
without changing the code layout too much. There seemed limited
enthusiasm from the authors about accepting relevant options.FWIW I looked at GNU indent a year ago or so, and there were a few
things about our style that they simply did not have options for. I
don't recall the details but my conclusion was that it was a dead end.
Might be worthwhile to look into 'uncrustify'. It's fairly
customizable. A colleague at citus made all citus code be formatted by
it; and while there's some minor details I dislike, it seems to work
ok.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
Andres Freund wrote:
On 2016-05-25 22:01:53 +0200, Piotr Stefaniak wrote:
On 2016-05-25 21:13, Tom Lane wrote:
I'd love to see a fix for its brain damage around function pointer typedef formatting, too.
Show me a few examples and I'll look into it.
See src/include/replication/logical.h; the problem there is pretty
obvious.
More examples are in, eg, src/include/access/amapi.h. It's aligning the
additional lines of a multiline function-pointer typedef to *something*,
but it's not very clear what exactly, and in any case it's indenting them
much too far to have any hope of readability.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
Might be worthwhile to look into 'uncrustify'. It's fairly
customizable. A colleague at citus made all citus code be formatted by
it; and while there's some minor details I dislike, it seems to work
ok.
Hmm ... a quick look says that it's been around for awhile and it's
actively maintained, which seem like positive things. Would be worth
seeing if it can be configured to match our style.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2016-05-25 21:13, Tom Lane wrote:
Assuming this patch withstands more careful review, we will need to think
about project policy for how/when to apply such fixes.
I discovered yesterday that Bruce Evans had done the fix for sizeof in
their fork of indent(1) in 2004 (r125623 [1]https://svnweb.freebsd.org/base/head/usr.bin/indent/lexi.c?r1=125619&r2=125623). The core fix is exactly
the same as mine, he just did more fixes around it, which I haven't
analyzed.
I'm trying to see if FreeBSD indent can successfully do pg_bsd_indent's
job. So far I had to fix one thing, which is not adding a space after a
cast operator, for which they added no option to turn it off. Currently
I'm fighting one other bug, but I think that'll be it.
I took interest in FreeBSD's fork of indent(1) because they've fixed
more things than NetBSD people have in their fork, it seems. I'm also
hoping it'll be easier to reinvent GNU indent's -tsn ("set tabsize to n
spaces") option for FreeBSD indent than it would be for any other of the
forks that aren't GNU. I envision that to be the first step to getting
rid of some of the work-arounds pgindent does, mainly running entab and
detab as pre- and post-processing steps.
If porting FreeBSD indent to PostgreSQL's sources turns out to be
successful, there will be a choice between rebasing pg_bsd_indent on
that and picking specific patches and applying it on PG's fork of indent(1).
[1]: https://svnweb.freebsd.org/base/head/usr.bin/indent/lexi.c?r1=125619&r2=125623
https://svnweb.freebsd.org/base/head/usr.bin/indent/lexi.c?r1=125619&r2=125623
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, May 25, 2016 at 03:13:23PM -0400, Tom Lane wrote:
Robert Haas <robertmhaas@gmail.com> writes:
On Sun, May 22, 2016 at 4:16 PM, Piotr Stefaniak
<postgres@piotr-stefaniak.me> wrote:I think I've managed to improve pg_bsd_indent's handling of two types of
cases.Wow, that seems pretty great. I haven't scrutinized your changes to
pg_bsd_indent, but effect_on_pg.diff looks like a large improvement.I'm excited about this too, not least because it suggests that maybe
bsdindent isn't quite as opaque as it appears. I'd love to see a fix
for its brain damage around function pointer typedef formatting, too.Assuming this patch withstands more careful review, we will need to think
about project policy for how/when to apply such fixes. The last time
we made any real change to pgindent's behavior was when we changed its
wrapping of comment blocks back around 8.1 ... and I cursed that decision
at least weekly for the next five years, because it caused constant
back-patching pain. If we make a change like this, I think we should
*strongly* consider reindenting all the live back branches along with
HEAD.
Uh, we have been running on back branches anytime the pgindent rules
change as part of policy, e.g.:
commit 2616a5d300e5bb5a2838d2a065afa3740e08727f
Author: Bruce Momjian <bruce@momjian.us>
Date: Tue May 6 11:26:26 2014 -0400
Remove tabs after spaces in C comments
This was not changed in HEAD, but will be done later as part of a
pgindent run. Future pgindent runs will also do this.
Report by Tom Lane
Backpatch through all supported branches, but not HEAD
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Bruce Momjian <bruce@momjian.us> writes:
On Wed, May 25, 2016 at 03:13:23PM -0400, Tom Lane wrote:
... If we make a change like this, I think we should
*strongly* consider reindenting all the live back branches along with
HEAD.
Uh, we have been running on back branches anytime the pgindent rules
change as part of policy, e.g.:
commit 2616a5d300e5bb5a2838d2a065afa3740e08727f
That was not actually a pgindent run, but a one-time application of a very
limited filter.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Tue, Jun 21, 2016 at 03:22:09PM -0400, Tom Lane wrote:
Bruce Momjian <bruce@momjian.us> writes:
On Wed, May 25, 2016 at 03:13:23PM -0400, Tom Lane wrote:
... If we make a change like this, I think we should
*strongly* consider reindenting all the live back branches along with
HEAD.Uh, we have been running on back branches anytime the pgindent rules
change as part of policy, e.g.:
commit 2616a5d300e5bb5a2838d2a065afa3740e08727fThat was not actually a pgindent run, but a one-time application of a very
limited filter.
Ah, yes, entab -m (only C comment periods).
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2016-05-27 08:13, Piotr Stefaniak wrote:
I'm trying to see if FreeBSD indent can successfully do pg_bsd_indent's
job. So far I had to fix one thing, which is not adding a space after a
cast operator, for which they added no option to turn it off. Currently
I'm fighting one other bug, but I think that'll be it.
So... after fixing 12 times more bugs that I had anticipated (see the
list at the end of this email; also see attached patches.tgz if you want
to apply the patches yourself), my "fork" of FreeBSD indent(1) can do
pg_bsd_indent's job if you pass it three additional parameters (-nut
-cli1 -sac), producing a 6600-line unified diff, mostly of desired
changes (see freebsd-indent.diff.gz for details).
I'm in the process of pushing my changes upstream, but I was already
told that it's too late to get them into 11.0-RELEASE. Personally, I
don't mind that, hoping that the upstream will accept them eventually.
I'm also hoping it'll be easier to reinvent GNU indent's -tsn ("set
tabsize to n spaces") option for FreeBSD indent than it would be for
any other of the forks that aren't GNU. I envision that to be the
first step to getting rid of some of the work-arounds pgindent does,
mainly running entab and detab as pre- and post-processing steps.
That and more I'll probably do later.
If porting FreeBSD indent to PostgreSQL's sources turns out to be
successful, there will be a choice between rebasing pg_bsd_indent on
that and picking specific patches and applying it on PG's fork of
indent(1).
At this point I think it wouldn't make any sense to port any changes to
current pg_bsd_indent.
The full list of changes I made to FreeBSD's indent(1) as of r289677:
[bugfix] Fix typo in keyword "typedef".
[bugfix] Avoid out of bound access of array codebuf pointed into
by s_code.
[bugfix] Avoid out of bound access of array ps.paren_indents.
[bugfix] Avoid out of bound access of array in_buffer.
[bugfix] Avoid potential use-after-free.
[bugfix] Semicolons inside struct declarations don't end the
declarations.
[bugfix] Support "f" and "F" floating constant suffixes.
[bugfix] Removed whitespace shouldn't be considered in column
calculations.
[bugfix] Don't add surplus space on empty lines in comments.
[bugfix] Bail out if there's no more space on the parser stack.
[bugfix] Consistently indent declarations.
[bugfix] Don't ignore the fact that offsetof is a keyword.
[cleanup] Make definition of opchar conditional.
[cleanup] Remove dead code relating to unix-style comments.
[cleanup] Simplify pr_comment().
[cleanup] Deduplicate code that decided if a comment needs a
blank line at the top.
[bugfix] Fix wrapping of some lines in comments.
[bugfix] Untangle the connection between pr_comment.c and io.c,
fixing at least two bugs
[feature] Add -sac (space after cast) and -nsac options.
[bugfix] Don't newline on cpp lines like #endif unless -bacc is on.
[feature] Add -U option for providing a file containing list of
types.
[optimization] Use bsearch() for looking up type keywords.
Attachments:
freebsd-indent.diff.gzapplication/gzip; name=freebsd-indent.diff.gzDownload
� ��oW �<is�8���_����+[��Cg\I�b+�k�e)��7���HH��"9<|�����@��@Iv�����E��n��F7 �v�s�JB��X����d��'��m;nd����E���Z���k��v[J��u������j�q[�
4��WHC����h��s���VA�����]���~ ���������B��YH�������(��Hb�D�R�x$^���M2� F��p)97�du�4N ���\|�_��?��I�Z�Y���������(u(�#L��@�K=IO� ���9^�k�����0r���&��7�'�� ��*<=�7�?O�������Z����d���R���6��������^� J�
���9��}� ~A���C��-��]��s?$>�(X���`�%�����I}e>�qE#��Q��?k���FQ���5��~93� �����{?��\�����x��n-���C���4T0e�Y�De^��Q7����|��<sE����%�%{K 6������@S�vGj�]T�m{��>���(9�v:hZ���= `�y�Y��{8�3#Z�jez6q�?����kI�o����K"sA
C?��� ��`T�� �����y�&A���#�r�L�iJ���<�'�f��8����< p� ���S�����_2-��3��� ��Q��{'^0�|�Kxs�����]��[���)����DJ�a���A`F�p��/WW\�����"��y�
8{�0��L��� DltE��o _���0�����i��&D����Q{�S��Sb���O��)�I]�}��EU���@\^���e���h85�D��F���z|���!L]kkn��|��{!ozm~���um��M�:v�pB~}3v�_�4���������Q`��f��������o��A|��Q �,�;�e��4�E���������PE����~OL���Q�G=�����������T�\������%�N���� �O����F��4�����
L
0�t�]�d��D:�tt�H�/�E�]UoB^)�<��]���_n������hmX�S�����������bn��R~�4��mm����a��ZH�$�HH�S��V-{1
=��Pt�Z��B�nU����`���TR��=�xO��y�:`y�d^.�n�w�
3 �wAAN��HLY�8���!��oo�-�2_6i�8����w�������`��{x8K��=$^�]���O��Q��w��`�l���mS �2OHb��������kB��T�����������Tie[�,c�����?��}H�PO�,w��C(f���k��-�6��<���T����Rf��I����6V\fcM�z��C��{��V�J���m���A_��P2@��w����Y�0�4U�E��[ ��y*���E����ud@M����80w ���
m��N��'�s�u+��I\���B�a��E�����m�%�5��L��Z4o�D:��=�}��{0���CY��0���x��J �0';��2�%�$T�Jm:K���P���X�6S��� 1CP��r*$���?j��?������������%zIV����\�g�;�&��!Ko6�)����L���������u� ��1Lw��a�5D�7.��J�U����r������^"������nW ��V��q������{L����!+���H��$��-w �(���V�g�f�3����Y��c�zG����]Rm����T^��e���#pI�[Q:��LNd�C!o�]�o'h�04D1a�����p�+����*S��*B�Vip�,p�A8ioN
i\�:
��A>��3C�S;��@���4H�
{ ���7��6p�����p�l��%X� _���{���X��c������<������
��0YC�@?�)P�k�e�C64>A�a����;���i|�������H!0�]��Ar�"cx8 bv��Y��
�x�%��1���is�`�0��Y��/2F]��t�&��n"^9^��BaF�;m#�'
�6�NsB-��%H,�*|E[�W��:q+%���+�J*C%���*���Q�����??(��R�F�)�K�P}�e�]{��H��/��������Z�_�<PB?�8l� ��
N�H�$��/����g�B�z=~�t��h01�#���{�NN�������V�_��������k"��-n�e~G���S�k�s��)�!�C6��-?�4\ ��pU(DE���U���o�F\>2]�Y��*��$���"##9�eB�%u1dmOdM����L2��t������
�|1��|c��������T�&Q�ML�����k���d�� �$9��Y�q�D��q��������6�T5�<fa����ZU���^����Y��h:��i���O� DC����c7���hM �W��Mx�7�}���V ]��:Y�h8�`mH�
B����&�R��s�4��w3'�l?ICPd��Y���z�a�,�B��� �
�G�U�'�9��B��R�o�U�kJ2`]�K-��BjC���+m�_8���3�zo�2c��d|y^:��� ����>pb��
�F6�S���4=�����CR-(_��<����R�A�c��1�X�wN#�D�IVR�AG��<H���U�+k�24XO>���LE:����L������-���+���0����=���%��'
��q�
�.�Kb�5�������7��Z)|\��^XMY���s�g��5�3d��JB:�~��a3� ���S�U�L��m�u�f;<�id6S��z�-M���&M�@�4�D��_���� -X��x������B/�Xf��9���C��AKMe�����U�h�v�i��$�u���.QU��S�*����+����`b;�@?��~�@��?��$g0=�u�l�I��`�}�p���;,�{�p�'7n@+��d�t:���\�f��!���+QS���Od�}�� �<��6�l�'1$�N�n�Q��
����.����w�`4�t���n:���}��E������s2p9pt�������a.���-_k`c������&�`��Ti���B>r]+x�i��XP�=a���o<��DU�9��������������JP�����M�����������i'�
�D,.����1N2�����������>��YH�;��OCuS6=�m+�F������m�Bx�}SG&�\#]���#G�F�B�R"�������, ��L���v�I���i%�����������B>:{�����7�wQ��fOgc3�����������{��{��,���rpq��I�����������I����ifhB�N���wJ���)�������
+�;�uB?]:�LD�jN|����]���,��M$JX��$-��M�MBZ���w(���|�T���k���
YFZ'3��F=��d���M�;�yV;b�������n�m���{�b���� R0�^�^P�^�������q l�U��|_������&o��|���s.~��InGW���1�������6I�6Lb��s�d�t�W��1���67��g������Z+h� @����W�( ����~t�NBe��%^��-}�,j���(w����(��2=�}�=�W�k���LJ��`��P����kYl�����Hr�dl&{U�X/+YF�,�<���r<f��H��e��W%����q�/'��^�@�4�k��u�bB(��ZA��<����.X�������nq_�A�:z
q��v������Wy��]a����������W���PF�b��,D�&�����&��N^l,���^WBY//��IeL"b'���� �l�hc����eg�h��}{U�p<��J4�UUn�UW���z��+P����zp;����P
�Z���[�����+�\��o�� _�
/[.J�_q��M������1]�����(6��HK���k� g[(��P�5\�dk���f�s/���I�f����`��� ������v�����������4�mr����x�_6��F�S�zx����M�uA��sn1�?���y�U���k�P���%��[��F�[R�f��r��
����}p�8Z���=e%��%"�Ts�lC�B��Xf��kNck)���3���P0"����N3[�|:#��� T�������� a�|�3��#~�r��6�=G�������N2�Jn�S8:�f1���?�rB��g?~���Y?�0���[=�w.l�v�[�]��V\�L�0$pje�@�+tr�������&�����W�lU�_��s�q����V��8�}��S�rb�~��n��W����r�c���8�o������c�`|Va���T��H!������������W.�I1��jhjd/��I�i�!�Y*!go��+�������������g8}����_��j/"�V/�v���6������=K)�:��{Y��R���NL��R����l��?��)6��}������f� fW���������?U�j�:U-�I���q[�
�v[Uv��[h�$�s�U�}��j���=E���J:V�����W�/P�1G`'/�������.<���u�����<q]|���G����8;��*�wi� �/i<�z�I�Y���� ��I�yH�w"KW������^x���~��g��z��p^�Q�3�i��O���\�l�|5�����n��0��*'�y����Z����2���$�w5��NO�Vz�NR������/�j���Oy�kz��Y,c����&�z���{>S��U!�G�O����LrG����a��7�ScB�I��P���_���]�|i�R6�Jp�V�4�@���[z:1=�(Q�0=�R�8���Q<�F���r���cg�O�T���P`j�@~�j��(S�$��6��1cuF ;z����G&����4���<��3�MV�[v>jiz�!�-N����4�C�6���_z��<�
�#��r�S{��0�����}��Gl�y�����m�R���� �Bh����4� ������VC�E�g������!���PW4~��_�
L��HXg�K=~�zv�o�-h�~�g�sn<��g�3d�c�re�KQn�1�sTy��R0�����6����b��(���J*�����%��Iw�L6��G��j~RP�W� ��3<��0)o���/ |mC�u
t�Fxeh������2��k?���VP��C�
)f 3e�>���55n���1<?7�����m�4h��BCW���������� �M"G�������b���8{�?�Y����t��jD���?�oG����8�
do�� ��[xG��N|m$a�`�D�Dw{(�>X4� �H'd�!_�w���������\���6��p��0y������gV��b��x=����F�/��d����7)�LU4�C������G&�U8!���B�� 6��.�~�=HlB�����t#�,����q�_�L���<���%8��[�� y6�������k�E�j���sj�����T�6�r���A����'�)��r� _���TW'2p�D��Bh�^}�|
c���E�`�
�!Y�����8�\�c��������������N��7Be�|����OCg��!7"����������?�}k{����g�W���F�%[��f7}�����]���v��%Q6�������~�� R��m�K�}Z0��`0������}qn_���s�����|�p�`b<�&&`[�ggY�L7��=aT�������� |����sr���{8f��id7z�x
����yH�S�"�����Z���P�p:5�2N;���x�t��V�� ��ik8��A*�xL�@<E�a���h��5lj� �`��\�&���Ek=���*c!]R���)i���� ��rz~�������i�9h5�����I���E��������r�oX��;��T����\�����`��4-�j�qqW����| ��A���)��7��^��P<K��?�������G�%��������}i��������U r-0���;�#^s���l�A��V1HZ����=�[���������� f
z��;�+�|�.���O Z��/�Y� ����:
krg#�1���v��:��X9S8k��Q% V1k����U�;���T�u�({g��*���B������Z��B�0����Y���EE�)V����=��� �W ��Z�^��k{�uL����N������������w6�[�?=:����(��3�/��thv�{pFn��\�C-4�8|���y�!<���V�B`Q+�WF�DsU��LS��<����Y�T4�h��*�I������?$V_�q�J��ZXAX_�5`0+hEU�����:+TH:�*e2����^�����V�&[b�.�OvK��������(�:?��K�s����g{�&gB�r^&vi0��Z<�����O�H=u�����������������}xNQ���H%� �z,��������9Fz�K���B��VG��������h[T�������.Vn�����P��0���O��b�-��]���O�_���k������6��/��
���2�]|����X����Z�{��������� {�l�{`�~��
�co
����|�a}�� �����v������DT�^K7���S��PI��B���e0���2�n�Y������acvt���#�~dc������������T��� �qI��f��E����|�[��Z��[��_�p�<y����8��~`����A����
[5��"{J��#c0~%1����5_9
F��sg�-�o����H�96X7��n� ��FZP�+���*$d�e���V�F�?Zg�}�p��Qq���!�����
L�eUC�����'�-�2xV_-C�z��L�G)�0=�K�qT>+��:��(�������
T��n�t����.8����]�0�u��2s,�*z��Uh�J�
^3 e��3�4
��W_�Ntk�h�aK���4,o
�s�[cB�y ������:��0�m��f`u��������g/�?�w(�SV�9�X�h
A�X�)@/[B�oX������� �dIf�k:��J��?B�d�S�[3��-��iw���0����e�[�G��f�REo��uR�*�0���1��\>��$��6��l\���W4Y���E�K���|k)
���TU$�=���9`�L&B���O�?=�M���3
Z�S_���&>������*V�^�����Z]X^��6��N�k�#�J_�Q#
e/�Hg3������t��P�W���W*l)�l�C��NG�*�t����s��9�D���iNf�=/�5#�i��k�����\��=�BJ?�:W��\\p3:�d�SV1��Mu+���{�%WR/��
U%:�W�u��������8����u����?�����}L�r�;�{���lh�C��U�C')'
0_�lY G��+ ���tg��g����9��9��e�i`2P�v�����
�Xtw�G�����V ���X$�����y�<�inm}�`_NM�]���H�
���b��� ]5JfR�Q!�B ����g���h��t�*������">X@���(�a*�^��y:&�����P�h��
������=�9���!S+���4q@�zuS�D�vGs��];�qb���������I������*������QQ��HQ}BEY����_����H�t]����j������"s���R�ZF�6B�fn��|�r*?�#�d��KS��� ��L��� �XN:E'