public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Simon Marchi <simark@simark.ca>
Cc: Tom Tromey <tromey@adacore.com>,  gdb-patches@sourceware.org
Subject: Re: [PATCH 2/4] Add an include-checking script
Date: Thu, 18 Apr 2024 09:40:11 -0600	[thread overview]
Message-ID: <877cguznl0.fsf@tromey.com> (raw)
In-Reply-To: <c0c5c7d0-6f99-4cab-8932-7d10adc9629a@simark.ca> (Simon Marchi's message of "Thu, 18 Apr 2024 11:29:30 -0400")

>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> +def failure(filename, ndx, text):
>> +    print(filename + ":" + str(ndx + 1) + ": " + text)

Simon> Should this print to stderr?

Done.

>> +    global status
>> +    status = 1

Simon> I would prefer if failure returned 1 (or the callers could return 1
Simon> themselves).

I ended up having it just call sys.exit (which really just throws).
The approach in the patch was from an earlier version that was run by
hand, before I figured out it could be run from pre-commit; and there
working on multiple files was more important.

>> +def headers(dirname):
>> +    return glob.iglob(dirname + "/*.h")

Simon> This function appears to be unused.

Removed.

Simon> You could do:
Simon>   contents = [line.strip('\n') for line in f]
Simon> and then no longer have to deal with \n everywhere.

>> +    if force_rewrite:
>> +        contents[i] = "#ifndef " + expected + "\n"

Simon> You don't need to add a \n here (and at other spots where you write a
Simon> line), writelines will do it.

The Python docs seem to say otherwise:

https://docs.python.org/3/library/io.html#io.IOBase.writelines

I left all the \n stuff alone.

>> +    if contents[i] != "#endif /* " + expected + " */\n":
>> +        failure(filename, i, "incorrect endif")
>> +        contents[i] = "#endif /* " + expected + " */\n"
>> +        updated = True

Simon> You could access the last line with contents[-1].

I figured we needed the line number for a possible error message anyway.

Tom

  reply	other threads:[~2024-04-18 15:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 22:05 [PATCH 0/4] Add include guard checker and reformatter Tom Tromey
2024-04-17 22:05 ` [PATCH 1/4] Fix some minor header file irregularities Tom Tromey
2024-04-17 22:05 ` [PATCH 2/4] Add an include-checking script Tom Tromey
2024-04-18 12:54   ` Tom de Vries
2024-04-18 15:31     ` Tom Tromey
2024-04-18 15:29   ` Simon Marchi
2024-04-18 15:40     ` Tom Tromey [this message]
2024-04-18 15:42       ` Simon Marchi
2024-04-17 22:05 ` [PATCH 3/4] Add check-include-guards.py to pre-commit Tom Tromey
2024-04-18 15:33   ` Simon Marchi
2024-04-18 15:45     ` Tom Tromey
2024-04-17 22:05 ` [PATCH 4/4] Run check-include-guards.py Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cguznl0.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).