From: Julia Lawall <julia.lawall-L2FTfq7BK8M@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 4/5] annotations: shorten file names
Date: Wed, 10 Jan 2018 07:28:37 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1801100728110.2157@hadrien> (raw)
In-Reply-To: <20180110054410.GF19773-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
On Wed, 10 Jan 2018, David Gibson wrote:
> On Mon, Jan 08, 2018 at 02:36:46PM +0100, Julia Lawall wrote:
> 1;5002;0c> The file name provided on the command line is represented by its
> > basename only. Other names are represented as relative offsets from the
> > directory of the starting one.
> >
> > This has to be adapted in the case of files on which cpp has been run
> > first. In that case, at least when using scripts/dtc/dtx_diff from the
> > Linux kernel, the command line file name is -, representing standard
> > input. The starting file name is then taken from the first line
> > beginning with #, as detected by a call to srcpos_set_line.
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
> > ---
> > srcpos.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
> > 1 file changed, 55 insertions(+), 5 deletions(-)
> >
> > diff --git a/srcpos.c b/srcpos.c
> > index 85657c6..fe756a7 100644
> > --- a/srcpos.c
> > +++ b/srcpos.c
> > @@ -33,6 +33,9 @@ struct search_path {
> > /* This is the list of directories that we search for source files */
> > static struct search_path *search_path_head, **search_path_tail;
> >
> > +/* Detect infinite include recursion. */
> > +#define MAX_SRCFILE_DEPTH (100)
> > +static int srcfile_depth; /* = 0 */
> >
> > static char *get_dirname(const char *path)
> > {
> > @@ -51,11 +54,50 @@ static char *get_dirname(const char *path)
> >
> > FILE *depfile; /* = NULL */
> > struct srcfile_state *current_srcfile; /* = NULL */
> > +static char *initial_path; /* = NULL */
> > +static int initial_pathlen; /* = NULL */
> > +static bool initial_cpp = true;
> > +
> > +static void set_initial_path(char *fname) {
> > + int i, len = strlen(fname);
> > +
> > + initial_path = fname;
>
> This is setting an indefinite lifetime global to a pointer, which
> AFAICT is dynamically allocated elswhere. That doesn't seem very
> safe.
Yes. I will fix this, and the format issue noted below.
thanks,
julia
>
> > + initial_pathlen = 0;
> > + for (i = 0; i != len; i++)
> > + if (initial_path[i] == '/')
> > + initial_pathlen++;
> > +}
> >
> > -/* Detect infinite include recursion. */
> > -#define MAX_SRCFILE_DEPTH (100)
> > -static int srcfile_depth; /* = 0 */
> > -
> > +static char *
> > +shorten_to_initial_path(char *fname) {
>
> Return type on same line, { on separate line, please (for function
> definitions only; Linux coding style).
>
> > + char *p1, *p2, *prevslash1 = NULL;
> > + int slashes = 0;
> > +
> > + for (p1 = fname, p2 = initial_path; *p1 && *p2; p1++, p2++) {
> > + if (*p1 != *p2)
> > + break;
> > + if (*p1 == '/') {
> > + prevslash1 = p1;
> > + slashes++;
> > + }
> > + }
> > + p1 = prevslash1 + 1;
> > + if (prevslash1) {
> > + int diff = initial_pathlen - slashes, i, j;
> > + int restlen = strlen(fname) - (p1 - fname);
> > + char *res;
> > +
> > + res = xmalloc((3 * diff) + restlen + 1);
> > + for (i = 0, j = 0; i != diff; i++) {
> > + res[j++] = '.';
> > + res[j++] = '.';
> > + res[j++] = '/';
> > + }
> > + strcpy(res + j, p1);
> > + return res;
> > + }
> > + return fname;
> > +}
> >
> > /**
> > * Try to open a file in a given directory.
> > @@ -157,6 +199,9 @@ void srcfile_push(const char *fname)
> > srcfile->colno = 1;
> >
> > current_srcfile = srcfile;
> > +
> > + if (srcfile_depth == 1)
> > + set_initial_path(srcfile->name);
> > }
> >
> > bool srcfile_pop(void)
> > @@ -325,7 +370,7 @@ srcpos_string_short(struct srcpos *pos, bool first_line)
> > int rc;
> >
> > if (pos) {
> > - fname = pos->file->name;
> > + fname = shorten_to_initial_path(pos->file->name);
> > rc = asprintf(&pos_str, "%s:%d", fname,
> > (first_line) ? pos->first_line: pos->last_line);
> > }
> > @@ -379,4 +424,9 @@ void srcpos_set_line(char *f, int l)
> > {
> > current_srcfile->name = f;
> > current_srcfile->lineno = l;
> > +
> > + if (initial_cpp) {
> > + initial_cpp = false;
> > + set_initial_path(f);
> > + }
> > }
>
> --
> David Gibson | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
> | _way_ _around_!
> http://www.ozlabs.org/~dgibson
>
next prev parent reply other threads:[~2018-01-10 6:28 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 13:36 [PATCH 0/5] annotations Julia Lawall
[not found] ` <1515418607-26764-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-08 13:36 ` [PATCH 1/5] annotations: Check for NULL pos Julia Lawall
[not found] ` <1515418607-26764-2-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-09 10:04 ` David Gibson
[not found] ` <20180109100400.GK2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 10:32 ` Julia Lawall
2018-01-10 6:08 ` Frank Rowand
[not found] ` <d7cae26a-a92f-6a39-61ca-05fee9509722-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10 6:29 ` Julia Lawall
2018-01-08 13:36 ` [PATCH 2/5] annotations: Add position information to various calls Julia Lawall
[not found] ` <1515418607-26764-3-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-08 22:29 ` Rob Herring
[not found] ` <CAL_JsqKaXY+K9LKH1qL1i-OhTjX1Kqvb6F3FJywwrPNZzLCz4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-09 0:58 ` Frank Rowand
2018-01-09 6:16 ` Julia Lawall
2018-01-09 14:19 ` Rob Herring
2018-01-09 11:16 ` David Gibson
[not found] ` <20180109111614.GL2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 12:27 ` Julia Lawall
2018-01-10 5:32 ` David Gibson
[not found] ` <20180110053255.GE19773-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-10 6:26 ` Julia Lawall
2018-01-10 6:34 ` Julia Lawall
2018-01-11 15:21 ` Julia Lawall
2018-01-15 7:36 ` David Gibson
[not found] ` <20180115073609.GA26066-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-15 9:28 ` Julia Lawall
2018-01-16 8:33 ` David Gibson
[not found] ` <20180116083334.GI30352-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-16 8:37 ` Julia Lawall
2018-01-10 6:25 ` Frank Rowand
[not found] ` <a0d1314a-8c1f-e553-dacc-62274c6b4cca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10 6:29 ` Frank Rowand
[not found] ` <bd068783-e34a-293c-ff03-d6dd37bff219-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10 6:31 ` Julia Lawall
2018-01-10 6:30 ` Julia Lawall
2018-01-08 13:36 ` [PATCH 3/5] annotations: short annotations Julia Lawall
[not found] ` <1515418607-26764-4-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-09 11:21 ` David Gibson
[not found] ` <20180109112130.GM2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 21:01 ` Frank Rowand
2018-01-08 13:36 ` [PATCH 4/5] annotations: shorten file names Julia Lawall
[not found] ` <1515418607-26764-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-10 5:44 ` David Gibson
[not found] ` <20180110054410.GF19773-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-10 6:28 ` Julia Lawall [this message]
2018-01-08 13:36 ` [PATCH 5/5] annotations: add --annotate-full option Julia Lawall
[not found] ` <1515418607-26764-6-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-10 6:32 ` Frank Rowand
[not found] ` <e249131c-5a60-f17c-a0ad-3a9aa3db8570-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10 6:36 ` Julia Lawall
2018-01-10 8:50 ` David Gibson
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=alpine.DEB.2.20.1801100728110.2157@hadrien \
--to=julia.lawall-l2ftfq7bk8m@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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 NNTP newsgroup(s).