mbox series

[v3,0/4] remove extern from function declarations

Message ID cover.1555487380.git.liu.denton@gmail.com (mailing list archive)
Headers show
Series remove extern from function declarations | expand

Message

Denton Liu April 17, 2019, 7:58 a.m. UTC
Hi Thomas,

Thanks for the feedback.  I couldn't find a tool that could selectively
fix indentation on patches so I went through and manually realigned the
parameter lists wherever the tools mangled the alignment. I guess this
also implies that one pair of (tired) human eyes has manually inspected
the machine-generated diff.

Hopefully, patch 3/4 won't be as onerous to review as it was to write ;)

---

Changes since v1:

* Used spatch with sed instead of sed alone
* Fixed sed expression to ignore function variables

Changes since v2:

* Rebased on latest master (since last patchset hasn't been picked up
  yet)
* Manually aligned parameter lists that were mangled by the tools

Denton Liu (4):
  *.[ch]: remove extern from function declarations using spatch
  *.[ch]: remove extern from function declarations using sed
  *.[ch]: manually align parameter lists
  cocci: prevent extern function declarations

 advice.h                          |   2 +-
 archive.h                         |  24 +-
 bisect.h                          |  26 +-
 blame.h                           |   2 +-
 branch.h                          |  14 +-
 builtin.h                         | 254 ++++++++++----------
 bulk-checkin.h                    |  10 +-
 cache.h                           | 386 +++++++++++++++---------------
 checkout.h                        |   6 +-
 column.h                          |  16 +-
 commit.h                          | 116 ++++-----
 compat/mingw.c                    |   2 +-
 compat/mingw.h                    |   6 +-
 compat/nedmalloc/malloc.c.h       |   6 +-
 compat/obstack.h                  |  14 +-
 compat/poll/poll.h                |   2 +-
 compat/regex/regex.h              |  66 ++---
 compat/win32/pthread.h            |   8 +-
 config.h                          | 226 ++++++++---------
 connect.h                         |  22 +-
 contrib/coccinelle/noextern.cocci |   6 +
 csum-file.h                       |  20 +-
 decorate.h                        |   4 +-
 delta.h                           |  14 +-
 dir.h                             | 144 +++++------
 exec-cmd.h                        |  16 +-
 fmt-merge-msg.h                   |   2 +-
 fsmonitor.h                       |  14 +-
 gettext.h                         |   8 +-
 git-compat-util.h                 | 132 +++++-----
 grep.h                            |  22 +-
 hashmap.h                         |  30 +--
 help.h                            |  36 +--
 http.h                            |  62 ++---
 khash.h                           |  16 +-
 kwset.h                           |  10 +-
 line-log.h                        |  16 +-
 lockfile.h                        |  12 +-
 ls-refs.h                         |   4 +-
 mailinfo.h                        |   6 +-
 merge-blobs.h                     |   6 +-
 object-store.h                    |  32 +--
 object.h                          |  12 +-
 oidmap.h                          |  12 +-
 pack.h                            |  26 +-
 packfile.h                        |  82 +++----
 path.h                            |  42 ++--
 pkt-line.h                        |  10 +-
 ppc/sha1.c                        |   4 +-
 prio-queue.h                      |  10 +-
 protocol.h                        |   6 +-
 quote.h                           |  34 +--
 reachable.h                       |   8 +-
 reflog-walk.h                     |  28 +--
 refs.h                            |   2 +-
 remote.h                          |  24 +-
 replace-object.h                  |   4 +-
 resolve-undo.h                    |  14 +-
 run-command.h                     |   8 +-
 serve.h                           |   6 +-
 sha1-lookup.h                     |   8 +-
 streaming.h                       |   8 +-
 string-list.h                     |   4 +-
 sub-process.h                     |   8 +-
 submodule-config.h                |  22 +-
 tag.h                             |  16 +-
 tempfile.h                        |  30 +--
 trace.h                           |  44 ++--
 transport.h                       |   4 +-
 tree-walk.h                       |   4 +-
 upload-pack.h                     |   8 +-
 url.h                             |  16 +-
 urlmatch.h                        |   4 +-
 utf8.h                            |   2 +-
 varint.h                          |   4 +-
 vcs-svn/sliding_window.h          |   2 +-
 vcs-svn/svndiff.h                 |   4 +-
 worktree.h                        |  36 +--
 xdiff-interface.h                 |  12 +-
 79 files changed, 1197 insertions(+), 1191 deletions(-)
 create mode 100644 contrib/coccinelle/noextern.cocci

Comments

Jeff King April 22, 2019, 9:49 p.m. UTC | #1
On Wed, Apr 17, 2019 at 12:58:31AM -0700, Denton Liu wrote:

> Thanks for the feedback.  I couldn't find a tool that could selectively
> fix indentation on patches so I went through and manually realigned the
> parameter lists wherever the tools mangled the alignment. I guess this
> also implies that one pair of (tired) human eyes has manually inspected
> the machine-generated diff.
> 
> Hopefully, patch 3/4 won't be as onerous to review as it was to write ;)

Thanks. I looked over these manually and didn't find any problems (which
isn't to say there aren't any, but now at least two sets of tired eyes
looked at them :) ).

This kind of cleanup is painful, but at least it should be done with
after this, so I'm in favor of moving it forward. Two minor notes,
though:

>  compat/mingw.c                    |   2 +-
>  compat/mingw.h                    |   6 +-
>  compat/nedmalloc/malloc.c.h       |   6 +-
>  compat/obstack.h                  |  14 +-
>  compat/poll/poll.h                |   2 +-
>  compat/regex/regex.h              |  66 ++---
>  compat/win32/pthread.h            |   8 +-

We sometimes avoid touching compat/ code for style issues because it's
copied from elsewhere. And diverging from upstream is more evil than a
pure style issue. So potentially we could drop these hunks (though I
think maybe mingw is our own thing?).

>  contrib/coccinelle/noextern.cocci |   6 +

I have mixed feelings on this cocci script. I'm happy to _see_ it, as
it's important to show how the transformation was done. But for most of
the other scripts, we expect programmers to introduce new cases that
need converting, and we'd like to catch those automatically. Here I find
it reasonably unlikely for a lot of "extern" to slip in, with the
exception of some topics in flight.

And these coccinelle scripts are kind of expensive to run. So I wonder
if the tradeoff is worth it here (perhaps it is now, as we catch those
topics in flight, it might be worth dropping this one in a few months).

At any rate, thanks for doing all of this tedious work. :)

-Peff
SZEDER Gábor April 25, 2019, 12:07 p.m. UTC | #2
On Mon, Apr 22, 2019 at 05:49:01PM -0400, Jeff King wrote:
> On Wed, Apr 17, 2019 at 12:58:31AM -0700, Denton Liu wrote:
 
> >  compat/mingw.c                    |   2 +-
> >  compat/mingw.h                    |   6 +-
> >  compat/nedmalloc/malloc.c.h       |   6 +-
> >  compat/obstack.h                  |  14 +-
> >  compat/poll/poll.h                |   2 +-
> >  compat/regex/regex.h              |  66 ++---
> >  compat/win32/pthread.h            |   8 +-
> 
> We sometimes avoid touching compat/ code for style issues because it's
> copied from elsewhere. And diverging from upstream is more evil than a
> pure style issue. So potentially we could drop these hunks (though I
> think maybe mingw is our own thing?).
> 
> >  contrib/coccinelle/noextern.cocci |   6 +
> 
> I have mixed feelings on this cocci script.

I have actual bad experience with this :)

v4 of this patch series excluded 'compat/' from the conversion, but
the semantic patch is applied to 'compat/' all the same, resulting in
failed CI builds because of the four 'extern's in 'compat/obstack.h',
and will continue to do so.

(Coccinelle has no issues with those other header files; I guess those
are not included in the '.c' source files we analyze with Coccinelle
in a stock Linux build environment).


> I'm happy to _see_ it, as
> it's important to show how the transformation was done. But for most of
> the other scripts, we expect programmers to introduce new cases that
> need converting, and we'd like to catch those automatically. Here I find
> it reasonably unlikely for a lot of "extern" to slip in, with the
> exception of some topics in flight.
> 
> And these coccinelle scripts are kind of expensive to run. So I wonder
> if the tradeoff is worth it here (perhaps it is now, as we catch those
> topics in flight, it might be worth dropping this one in a few months).
> 
> At any rate, thanks for doing all of this tedious work. :)
> 
> -Peff
Denton Liu April 25, 2019, 6:05 p.m. UTC | #3
On Thu, Apr 25, 2019 at 02:07:58PM +0200, SZEDER Gábor wrote:
> On Mon, Apr 22, 2019 at 05:49:01PM -0400, Jeff King wrote:
> > On Wed, Apr 17, 2019 at 12:58:31AM -0700, Denton Liu wrote:
>  
> > >  compat/mingw.c                    |   2 +-
> > >  compat/mingw.h                    |   6 +-
> > >  compat/nedmalloc/malloc.c.h       |   6 +-
> > >  compat/obstack.h                  |  14 +-
> > >  compat/poll/poll.h                |   2 +-
> > >  compat/regex/regex.h              |  66 ++---
> > >  compat/win32/pthread.h            |   8 +-
> > 
> > We sometimes avoid touching compat/ code for style issues because it's
> > copied from elsewhere. And diverging from upstream is more evil than a
> > pure style issue. So potentially we could drop these hunks (though I
> > think maybe mingw is our own thing?).
> > 
> > >  contrib/coccinelle/noextern.cocci |   6 +
> > 
> > I have mixed feelings on this cocci script.
> 
> I have actual bad experience with this :)
> 
> v4 of this patch series excluded 'compat/' from the conversion, but
> the semantic patch is applied to 'compat/' all the same, resulting in
> failed CI builds because of the four 'extern's in 'compat/obstack.h',
> and will continue to do so.
> 
> (Coccinelle has no issues with those other header files; I guess those
> are not included in the '.c' source files we analyze with Coccinelle
> in a stock Linux build environment).

Since this is the case, we should drop 4/4 because it is not only
unhelpful, because it doesn't scan header files, but actively harmful.
The cocci script used is in the log for 1/4 anyway.

Thanks for checking on this,

Denton

> 
> 
> > I'm happy to _see_ it, as
> > it's important to show how the transformation was done. But for most of
> > the other scripts, we expect programmers to introduce new cases that
> > need converting, and we'd like to catch those automatically. Here I find
> > it reasonably unlikely for a lot of "extern" to slip in, with the
> > exception of some topics in flight.
> > 
> > And these coccinelle scripts are kind of expensive to run. So I wonder
> > if the tradeoff is worth it here (perhaps it is now, as we catch those
> > topics in flight, it might be worth dropping this one in a few months).
> > 
> > At any rate, thanks for doing all of this tedious work. :)
> > 
> > -Peff
Johannes Schindelin April 30, 2019, 11:21 p.m. UTC | #4
Hi,

On Thu, 25 Apr 2019, SZEDER Gábor wrote:

> On Mon, Apr 22, 2019 at 05:49:01PM -0400, Jeff King wrote:
> > On Wed, Apr 17, 2019 at 12:58:31AM -0700, Denton Liu wrote:
>
> > >  compat/mingw.c                    |   2 +-
> > >  compat/mingw.h                    |   6 +-
> > >  compat/nedmalloc/malloc.c.h       |   6 +-
> > >  compat/obstack.h                  |  14 +-
> > >  compat/poll/poll.h                |   2 +-
> > >  compat/regex/regex.h              |  66 ++---
> > >  compat/win32/pthread.h            |   8 +-
> >
> > We sometimes avoid touching compat/ code for style issues because it's
> > copied from elsewhere. And diverging from upstream is more evil than a
> > pure style issue. So potentially we could drop these hunks (though I
> > think maybe mingw is our own thing?).
> >
> > >  contrib/coccinelle/noextern.cocci |   6 +
> >
> > I have mixed feelings on this cocci script.
>
> I have actual bad experience with this :)
>
> v4 of this patch series excluded 'compat/' from the conversion, but
> the semantic patch is applied to 'compat/' all the same, resulting in
> failed CI builds because of the four 'extern's in 'compat/obstack.h',
> and will continue to do so.

Is it not possible to exclude certain directories for certain semantic
patches?

I guess we could also simply declare that *all* Coccinelle patches should
leave `compat/` alone, on the basis that those files are likely coming
from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
seem not to fall into that category...

Ciao,
Dscho
Denton Liu May 1, 2019, 10:01 a.m. UTC | #5
Hi Johannes,

On Tue, Apr 30, 2019 at 07:21:40PM -0400, Johannes Schindelin wrote:
> Hi,
> 
> On Thu, 25 Apr 2019, SZEDER Gábor wrote:
> 
> > On Mon, Apr 22, 2019 at 05:49:01PM -0400, Jeff King wrote:
> > > On Wed, Apr 17, 2019 at 12:58:31AM -0700, Denton Liu wrote:
> >
> > > >  compat/mingw.c                    |   2 +-
> > > >  compat/mingw.h                    |   6 +-
> > > >  compat/nedmalloc/malloc.c.h       |   6 +-
> > > >  compat/obstack.h                  |  14 +-
> > > >  compat/poll/poll.h                |   2 +-
> > > >  compat/regex/regex.h              |  66 ++---
> > > >  compat/win32/pthread.h            |   8 +-
> > >
> > > We sometimes avoid touching compat/ code for style issues because it's
> > > copied from elsewhere. And diverging from upstream is more evil than a
> > > pure style issue. So potentially we could drop these hunks (though I
> > > think maybe mingw is our own thing?).
> > >
> > > >  contrib/coccinelle/noextern.cocci |   6 +
> > >
> > > I have mixed feelings on this cocci script.
> >
> > I have actual bad experience with this :)
> >
> > v4 of this patch series excluded 'compat/' from the conversion, but
> > the semantic patch is applied to 'compat/' all the same, resulting in
> > failed CI builds because of the four 'extern's in 'compat/obstack.h',
> > and will continue to do so.
> 
> Is it not possible to exclude certain directories for certain semantic
> patches?
> 
> I guess we could also simply declare that *all* Coccinelle patches should
> leave `compat/` alone, on the basis that those files are likely coming
> from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
> seem not to fall into that category...
> 
> Ciao,
> Dscho

Deciding whether this is a good idea is above my paygrade ;)

However, if this is a good idea, we could use this patch to make it
happen:

-- >8 --
Subject: [PATCH] Makefile: filter out compat/ from coccicheck

Since most files in compat/ are pulled from external sources, ensure
that they do not get modified when we run coccicheck because we do not
want them to differ from upstream as much as possible.

Make exceptions for mingw.c and win32/*.c as these are files that we
have created and not pulled from upstream.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 9f1b6e8926..b083c038c3 100644
--- a/Makefile
+++ b/Makefile
@@ -2782,11 +2782,14 @@ check: command-list.h
 	fi
 
 C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
+COCCI_COMPAT_SOURCES = $(addprefix compat/,mingw.c win32/%)
 ifdef DC_SHA1_SUBMODULE
-COCCI_SOURCES = $(filter-out sha1collisiondetection/%,$(C_SOURCES))
+COCCI_SOURCES := $(filter-out sha1collisiondetection/%,$(C_SOURCES))
 else
-COCCI_SOURCES = $(filter-out sha1dc/%,$(C_SOURCES))
+COCCI_SOURCES := $(filter-out sha1dc/%,$(C_SOURCES))
 endif
+COCCI_SOURCES := $(filter-out compat/%,$(COCCI_SOURCES))
+COCCI_SOURCES += $(filter $(COCCI_COMPAT_SOURCES),$(C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
 	@echo '    ' SPATCH $<; \
Jeff King May 1, 2019, 6:56 p.m. UTC | #6
On Wed, May 01, 2019 at 06:01:08AM -0400, Denton Liu wrote:

> > I guess we could also simply declare that *all* Coccinelle patches should
> > leave `compat/` alone, on the basis that those files are likely coming
> > from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
> > seem not to fall into that category...
> 
> Deciding whether this is a good idea is above my paygrade ;)

FWIW, this seems like a good idea to me.

It's _possible_ there may be some cocci changes that we want to apply
even to compat/ (e.g., if we're mechanically fixing up a construct with
security implications). But whoever is doing that conversion should
probably apply that manually (and we don't typically change imported
stuff in the first place, so there's little need to subsequently run the
cocci patches).

> -- >8 --
> Subject: [PATCH] Makefile: filter out compat/ from coccicheck
> [...]

The patch itself looks OK to me.

-Peff
SZEDER Gábor May 2, 2019, 12:04 a.m. UTC | #7
On Wed, May 01, 2019 at 06:01:08AM -0400, Denton Liu wrote:
> > Is it not possible to exclude certain directories for certain semantic
> > patches?
> > 
> > I guess we could also simply declare that *all* Coccinelle patches should
> > leave `compat/` alone, on the basis that those files are likely coming
> > from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
> > seem not to fall into that category...
> > 
> > Ciao,
> > Dscho
> 
> Deciding whether this is a good idea is above my paygrade ;)
>
> However, if this is a good idea, we could use this patch to make it
> happen:
> 
> -- >8 --
> Subject: [PATCH] Makefile: filter out compat/ from coccicheck
> 
> Since most files in compat/ are pulled from external sources, ensure
> that they do not get modified when we run coccicheck because we do not
> want them to differ from upstream as much as possible.
> 
> Make exceptions for mingw.c and win32/*.c as these are files that we
> have created and not pulled from upstream.

I'm not sure that we really need these exceptions.

C_SOURCES comes from C_OBJ, i.e. it is basically all '*.c' source
files that we compile, taking the platform and Makefile knobs into
account.  On Linux we don't compile 'compat/mingw.c' and
'compat/win32/*.c', so when running 'make coccicheck' on Linux it
won't look into these source files anyway, so we don't need these
exceptions.  On Windows, however...  well, is it even possible to
build and run Coccinelle on Windows in the first place, with all its
OCaml dependencies?!  If not, then these exceptions won't do any good.

Anyway, if we do want these exceptions, then what about
'compat/win32mmap.c' and 'compat/winansi.c'?  They look like "ours" as
well.


FWIW, out of curiosity I've run 'make coccicheck' on Linux with
'compat/mingw.c' and its friends explicitly added to C_SOURCES, and it
seems to work...  it even found two places in 'mingw.c' where
COPY_ARRAY could replace memcpy() :)


> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  Makefile | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 9f1b6e8926..b083c038c3 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2782,11 +2782,14 @@ check: command-list.h
>  	fi
>  
>  C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
> +COCCI_COMPAT_SOURCES = $(addprefix compat/,mingw.c win32/%)


>  ifdef DC_SHA1_SUBMODULE
> -COCCI_SOURCES = $(filter-out sha1collisiondetection/%,$(C_SOURCES))
> +COCCI_SOURCES := $(filter-out sha1collisiondetection/%,$(C_SOURCES))
>  else
> -COCCI_SOURCES = $(filter-out sha1dc/%,$(C_SOURCES))
> +COCCI_SOURCES := $(filter-out sha1dc/%,$(C_SOURCES))
>  endif
> +COCCI_SOURCES := $(filter-out compat/%,$(COCCI_SOURCES))
> +COCCI_SOURCES += $(filter $(COCCI_COMPAT_SOURCES),$(C_SOURCES))
>  
>  %.cocci.patch: %.cocci $(COCCI_SOURCES)
>  	@echo '    ' SPATCH $<; \
> -- 
> 2.21.0.1033.g0e8cc1100c
>
Johannes Schindelin May 3, 2019, 9:32 a.m. UTC | #8
Hi,

On Thu, 2 May 2019, SZEDER Gábor wrote:

> On Wed, May 01, 2019 at 06:01:08AM -0400, Denton Liu wrote:
> > > Is it not possible to exclude certain directories for certain semantic
> > > patches?
> > >
> > > I guess we could also simply declare that *all* Coccinelle patches should
> > > leave `compat/` alone, on the basis that those files are likely coming
> > > from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
> > > seem not to fall into that category...
> > >
> > > Ciao,
> > > Dscho
> >
> > Deciding whether this is a good idea is above my paygrade ;)

:-)

As a software developer, you surely have an opinion, though :-D

Thank you for the patch, it is a good conversation starter in the least,
and I hope that some variation of it will even make it to `master`.

> [...] what about 'compat/win32mmap.c' and 'compat/winansi.c'?  They look
> like "ours" as well.

Indeed, this is probably a good indicator that we'd want this to be an
opt-out, rather than an opt-in list.

For example, we know that we want to exclude compat/regex/ and
compat/poll/ from the `coccicheck` target.

> FWIW, out of curiosity I've run 'make coccicheck' on Linux with
> 'compat/mingw.c' and its friends explicitly added to C_SOURCES, and it
> seems to work...  it even found two places in 'mingw.c' where
> COPY_ARRAY could replace memcpy() :)

TBH I had not even known that those files were excluded from coccicheck by
default. I had assumed that all of Git's sources (and not just the
Linux-specific ones) were included in the target.

Since you *could* include it, I now assume that Coccinelle does not need
to follow the `#include`s (otherwise, it would have complained about not
finding the `windows.h` header in your setup).

If this new assumption is true, I wonder why we cannot make my former
assumption true as well: why not include *all* of Git's `.c` files in
`coccicheck`?

Ciao,
Dscho
Denton Liu May 3, 2019, 9:40 a.m. UTC | #9
On Thu, May 02, 2019 at 02:04:22AM +0200, SZEDER Gábor wrote:
> On Wed, May 01, 2019 at 06:01:08AM -0400, Denton Liu wrote:

[snip]

> > 
> > -- >8 --
> > Subject: [PATCH] Makefile: filter out compat/ from coccicheck
> > 
> > Since most files in compat/ are pulled from external sources, ensure
> > that they do not get modified when we run coccicheck because we do not
> > want them to differ from upstream as much as possible.
> > 
> > Make exceptions for mingw.c and win32/*.c as these are files that we
> > have created and not pulled from upstream.
> 
> I'm not sure that we really need these exceptions.
> 
> C_SOURCES comes from C_OBJ, i.e. it is basically all '*.c' source
> files that we compile, taking the platform and Makefile knobs into
> account.  On Linux we don't compile 'compat/mingw.c' and
> 'compat/win32/*.c', so when running 'make coccicheck' on Linux it
> won't look into these source files anyway, so we don't need these
> exceptions.  On Windows, however...  well, is it even possible to
> build and run Coccinelle on Windows in the first place, with all its
> OCaml dependencies?!  If not, then these exceptions won't do any good.

I assumed that Coccinelle runs on Windows but now that you mention it,
Cocci's origin was as a Linux refactoring tool so I'm not really sure if
it actually does run. Unfortunately, I don't have a Windows box
available to test it out on so let's assume that it doesn't work on
Windows, unless someone says otherwise.

> 
> Anyway, if we do want these exceptions, then what about
> 'compat/win32mmap.c' and 'compat/winansi.c'?  They look like "ours" as
> well.

Good point, I wasn't really sure which ones were ours so I just went off
of what Johannes said. If we decide to keep the exceptions, I'll dig
through the log messages to find all of "our" files.

> 
> 
> FWIW, out of curiosity I've run 'make coccicheck' on Linux with
> 'compat/mingw.c' and its friends explicitly added to C_SOURCES, and it
> seems to work...  it even found two places in 'mingw.c' where
> COPY_ARRAY could replace memcpy() :)
> 

Since you mentioned this, shouldn't we run Coccinelle on all of our
source files, not just the ones that are compiled? Since the
Windows-files aren't checked, they are in a blindspot for us.

I guess a point against that would be if one were patching a file that
they couldn't even test-compile, then it could be possible that faulty
patches are sent, but I guess we have enough people on the mailing list
that could verify the patches so I don't think that's a problem.

Perhaps we could implement a 'coccicheckall' target which excludes
contrib/ but excepts mingw.c and friends?
SZEDER Gábor May 3, 2019, 2:42 p.m. UTC | #10
On Fri, May 03, 2019 at 11:32:32AM +0200, Johannes Schindelin wrote:
> Hi,
> 
> On Thu, 2 May 2019, SZEDER Gábor wrote:
> 
> > On Wed, May 01, 2019 at 06:01:08AM -0400, Denton Liu wrote:
> > > > Is it not possible to exclude certain directories for certain semantic
> > > > patches?
> > > >
> > > > I guess we could also simply declare that *all* Coccinelle patches should
> > > > leave `compat/` alone, on the basis that those files are likely coming
> > > > from some sort of upstream. But then, `compat/mingw.c` and `compat/win32/`
> > > > seem not to fall into that category...
> > > >
> > > > Ciao,
> > > > Dscho
> > >
> > > Deciding whether this is a good idea is above my paygrade ;)
> 
> :-)
> 
> As a software developer, you surely have an opinion, though :-D

I don't even have an opinion yet. :)

> > FWIW, out of curiosity I've run 'make coccicheck' on Linux with
> > 'compat/mingw.c' and its friends explicitly added to C_SOURCES, and it
> > seems to work...  it even found two places in 'mingw.c' where
> > COPY_ARRAY could replace memcpy() :)
> 
> TBH I had not even known that those files were excluded from coccicheck by
> default.

Well, there was this line in the patch context:

    C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))

> I had assumed that all of Git's sources (and not just the
> Linux-specific ones) were included in the target.
> 
> Since you *could* include it, I now assume that Coccinelle does not need
> to follow the `#include`s (otherwise, it would have complained about not
> finding the `windows.h` header in your setup).

We invoke Coccinelle/spatch with the '--all-includes' option, see the
SPATCH_FLAGS make variable.  And it does indeed include header files:
I've seen it find something to transform in 'cache.h', and then the
resulting 'contrib/coccinelle/<whatever>.cocci.patch' included the
exact same transformation as many times as the number of files
including 'cache.h'... which is a lot :)

I don't really know what can cause 'spatch' to error out (besides
unknown command line option or non-existing file specified on the
command line), and this is all that 'man spatch' has to say:

       --all-includes
              causes all available include files to be used

Since it explicitly mentions _available_ include files, I would
venture to guess that non-available include files are not used, and
since it doesn't explicitly mention that such a file causes an error,
it doesn't.


> If this new assumption is true, I wonder why we cannot make my former
> assumption true as well: why not include *all* of Git's `.c` files in
> `coccicheck`?
> 
> Ciao,
> Dscho
SZEDER Gábor May 3, 2019, 2:58 p.m. UTC | #11
On Fri, May 03, 2019 at 04:42:11PM +0200, SZEDER Gábor wrote:
> > Since you *could* include it, I now assume that Coccinelle does not need
> > to follow the `#include`s (otherwise, it would have complained about not
> > finding the `windows.h` header in your setup).

> I don't really know what can cause 'spatch' to error out (besides
> unknown command line option or non-existing file specified on the
> command line), and this is all that 'man spatch' has to say:
> 
>        --all-includes
>               causes all available include files to be used
> 
> Since it explicitly mentions _available_ include files, I would
> venture to guess that non-available include files are not used, and
> since it doesn't explicitly mention that such a file causes an error,
> it doesn't.

Actually, we record Coccinelle's output to stderr in a logfile, and
with the Windows-specific source files included it contains thing
like:

  HANDLING: compat/mingw.c
  (ONCE) TYPE: header conio.h not found
  (ONCE) TYPE: header wchar.h not found
  diff =
  init_defs_builtins: /usr/lib/coccinelle/standard.h
  HANDLING: compat/winansi.c
  (ONCE) TYPE: header wingdi.h not found
  (ONCE) TYPE: header winreg.h not found
  (ONCE) TYPE: header winternl.h not found
  (ONCE) TYPE: header ntstatus.h not found

So it seems that these missing headers are just ignored, only their
absence is noted on stderr.


(And just for the record, that log also contained these:

  HANDLING: http-push.c
  (ONCE) TYPE: header xmlparse.h not found
  (ONCE) TYPE: header expat.h not found

  HANDLING: xdiff/xutils.c
  (ONCE) TYPE: header limits.h not found
  (ONCE) TYPE: header assert.h not found

which means that even on an avarage Linux box there might be missing
include files.  This also raises the question whether Coccinelle looks
for things to transform in system headers as well (and what if it
finds something there)).
Jeff King May 3, 2019, 5:45 p.m. UTC | #12
On Fri, May 03, 2019 at 04:42:11PM +0200, SZEDER Gábor wrote:

> > Since you *could* include it, I now assume that Coccinelle does not need
> > to follow the `#include`s (otherwise, it would have complained about not
> > finding the `windows.h` header in your setup).
> 
> We invoke Coccinelle/spatch with the '--all-includes' option, see the
> SPATCH_FLAGS make variable.  And it does indeed include header files:
> I've seen it find something to transform in 'cache.h', and then the
> resulting 'contrib/coccinelle/<whatever>.cocci.patch' included the
> exact same transformation as many times as the number of files
> including 'cache.h'... which is a lot :)

I think spatch is smart enough not to hit the same header multiple
times. But the problem is that we invoke it once per file, so it
actually processes cache.h many times. That's slow, but also produces
bogus patches.

Jacob Keller's patches to collapse this to a single invocation do fix it
(and I've used them selectively in the past rather than cleaning up the
resulting patch manually ;) ).

Sort of tangential to your point, I guess, but it might be a topic to
revisit.

-Peff
SZEDER Gábor May 3, 2019, 6:44 p.m. UTC | #13
On Fri, May 03, 2019 at 01:45:03PM -0400, Jeff King wrote:
> On Fri, May 03, 2019 at 04:42:11PM +0200, SZEDER Gábor wrote:
> 
> > > Since you *could* include it, I now assume that Coccinelle does not need
> > > to follow the `#include`s (otherwise, it would have complained about not
> > > finding the `windows.h` header in your setup).
> > 
> > We invoke Coccinelle/spatch with the '--all-includes' option, see the
> > SPATCH_FLAGS make variable.  And it does indeed include header files:
> > I've seen it find something to transform in 'cache.h', and then the
> > resulting 'contrib/coccinelle/<whatever>.cocci.patch' included the
> > exact same transformation as many times as the number of files
> > including 'cache.h'... which is a lot :)
> 
> I think spatch is smart enough not to hit the same header multiple
> times. But the problem is that we invoke it once per file, so it
> actually processes cache.h many times. That's slow, but also produces
> bogus patches.
> 
> Jacob Keller's patches to collapse this to a single invocation do fix it
> (and I've used them selectively in the past rather than cleaning up the
> resulting patch manually ;) ).
> 
> Sort of tangential to your point, I guess, but it might be a topic to
> revisit.

I simply applied the changes manually to 'cache.h', and rerun 'make
contrib/coccinelle/<...>.cocci.patch'.  This approach is reliable and
has less undesirable side-effects :)  and it doesn't happen that often
to be a considerable burden.
Junio C Hamano May 5, 2019, 5:28 a.m. UTC | #14
Jeff King <peff@peff.net> writes:

> I think spatch is smart enough not to hit the same header multiple
> times. But the problem is that we invoke it once per file, so it
> actually processes cache.h many times. That's slow, but also produces
> bogus patches.

Yes, I've seen this and was a bit irritated myself, but not enough
to do something about it myself, yet.
>
> Jacob Keller's patches to collapse this to a single invocation do fix it
> (and I've used them selectively in the past rather than cleaning up the
> resulting patch manually ;) ).

Ah, that is nice to know.  Do we want to resurrect it?
Jacob Keller May 5, 2019, 6:08 p.m. UTC | #15
On Fri, May 3, 2019 at 11:09 AM Jeff King <peff@peff.net> wrote:
>
> On Fri, May 03, 2019 at 04:42:11PM +0200, SZEDER Gábor wrote:
>
> > > Since you *could* include it, I now assume that Coccinelle does not need
> > > to follow the `#include`s (otherwise, it would have complained about not
> > > finding the `windows.h` header in your setup).
> >
> > We invoke Coccinelle/spatch with the '--all-includes' option, see the
> > SPATCH_FLAGS make variable.  And it does indeed include header files:
> > I've seen it find something to transform in 'cache.h', and then the
> > resulting 'contrib/coccinelle/<whatever>.cocci.patch' included the
> > exact same transformation as many times as the number of files
> > including 'cache.h'... which is a lot :)
>
> I think spatch is smart enough not to hit the same header multiple
> times. But the problem is that we invoke it once per file, so it
> actually processes cache.h many times. That's slow, but also produces
> bogus patches.
>
> Jacob Keller's patches to collapse this to a single invocation do fix it
> (and I've used them selectively in the past rather than cleaning up the
> resulting patch manually ;) ).
>
> Sort of tangential to your point, I guess, but it might be a topic to
> revisit.
>
> -Peff


Yea, my patches are much faster. However, they trade off a huge
increase in memory consumption, and from what I remember, the failure
if you don't have enough RAM was not a good experience.

Thanks,
Jake
Jacob Keller May 5, 2019, 6:09 p.m. UTC | #16
On Sat, May 4, 2019 at 10:28 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Jeff King <peff@peff.net> writes:
>
> > I think spatch is smart enough not to hit the same header multiple
> > times. But the problem is that we invoke it once per file, so it
> > actually processes cache.h many times. That's slow, but also produces
> > bogus patches.
>
> Yes, I've seen this and was a bit irritated myself, but not enough
> to do something about it myself, yet.
> >
> > Jacob Keller's patches to collapse this to a single invocation do fix it
> > (and I've used them selectively in the past rather than cleaning up the
> > resulting patch manually ;) ).
>
> Ah, that is nice to know.  Do we want to resurrect it?

I remember deciding that the memory cost trade off was too high back then.

Thanks,
Jake