mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Sam Ravnborg <sam@ravnborg.org>, Brian King <brking@us.ibm.com>,
	akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: Question on MODULE_VERSION macro
Date: Wed, 25 Feb 2004 22:36:59 +0100	[thread overview]
Message-ID: <20040225213659.GA9985@mars.ravnborg.org> (raw)
In-Reply-To: <20040224110724.0FA0D2C0CE@lists.samba.org>

Hi Rusty.

I have not yet fully understood why you want to parse every source file.
I can see in the implemntation that you only calculate the sum of
code-lines, and not comments.
But why do we want to add this complexity - compared to just
calculating the sum of the whole file?
If the calculated sum is being presented as based on the source code
I assume people can understand that the sum does not match even after
updating a comment.

The current implementation fails to locate include files in the local
directory when compiled using "make O=...".
This is due to the fact that some files are present in the _deps
file with full path, others with relative path.

Example:
  /home/sam/bk/v2.6/drivers/scsi/aic7xxx/aiclib.h \
  /home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx.h \
    $(wildcard include/config/used.h) \
  drivers/scsi/aic7xxx/aic7xxx_reg.h \
  /home/sam/bk/v2.6/drivers/scsi/aic7xxx/aic7xxx_inline.h \


I took a quick look and cannot explain why gcc spits out include files
with different paths.

My next question. Since we only parse a subset of the headers, is it
really needed to parse any of them?
My thinking is that we should either:
a) parse all header files (except those marked with $(wildcard))
b) parse no header files.

See also a few specific comments below.

	Sam

> +/* We have dir/file.o.  Open dir/.file.o.cmd, look for deps_ line to
> + * figure out source file. */
> +static int parse_source_files(const char *objfile, struct md4_ctx *md)
> +{
> +	char *cmd, *file, *p, *end;
> +	const char *base;
> +	unsigned long flen;
> +	int dirlen, ret = 0;
> +
> +	cmd = malloc(strlen(objfile) + sizeof("..cmd"));

You miss a "+ 1" to count for trailing '\0'.

> +
> +	base = strrchr(objfile, '/');
> +	if (base) {
> +		base++;
> +		dirlen = base - objfile;
> +		sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base);
> +	} else {
> +		dirlen = 0;
> +		sprintf(cmd, ".%s.cmd", objfile);
> +	}
> +
> +	file = grab_file(cmd, &flen);
> +	if (!file) {
> +		fprintf(stderr, "Warning: could not find %s for %s\n",
> +			cmd, objfile);
> +		goto out;
> +	}
> +
> +	/* There will be a line like so:
> +		deps_drivers/net/dummy.o := \
> +		  drivers/net/dummy.c \
> +		    $(wildcard include/config/net/fastroute.h) \
> +		  include/linux/config.h \
> +		    $(wildcard include/config/h.h) \
> +		  include/linux/module.h \
> +
> +	   Sum all files in the same dir or subdirs.
> +	*/
> +	/* Strictly illegal: file is not nul terminated. */
> +	p = strstr(file, "\ndeps_");
> +	if (!p) {
> +		fprintf(stderr, "Warning: could not find deps_ line in %s\n",
> +			cmd);
> +		goto out_file;
> +	}
> +	p = strstr(p, ":=");
> +	if (!p) {
> +		fprintf(stderr, "Warning: could not find := line in %s\n",
> +			cmd);
> +		goto out_file;
> +	}
> +	p += strlen(":=");
> +	p += strspn(p, " \\\n");
> +
> +	end = strstr(p, "\n\n");
> +	if (!end) {
> +		fprintf(stderr, "Warning: could not find end line in %s\n",
> +			cmd);
> +		goto out_file;
> +	}
> +
> +	while (p < end) {
> +		unsigned int len;
> +
> +		len = strcspn(p, " \\\n");
> +		if (memcmp(objfile, p, dirlen) == 0) {
> +			char source[len + 1];
gcc extension, you do not want to use malloc here?

> +
> +			memcpy(source, p, len);
> +			source[len] = '\0';
> +			printf("parsing %s\n", source);
Debug printf - to be deleted.

> +			if (!parse_file(source, md)) {
> +				fprintf(stderr,
> +					"Warning: could not open %s: %s\n",
> +					source, strerror(errno));
> +				goto out_file;
> +			}
> +		}
> +		p += len;
> +		p += strspn(p, " \\\n");
> +	}
> +
> +	/* Everyone parsed OK */
> +	ret = 1;
> +out_file:
> +	release_file(file, flen);
> +out:
> +	free(cmd);
> +	return ret;
> +}

  reply	other threads:[~2004-02-25 20:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040119214233.GF967@beaverton.ibm.com>
2004-01-20  0:57 ` Rusty Russell
2004-01-20  1:17   ` Greg KH
2004-01-20  7:47     ` Rusty Russell
2004-02-20 21:44       ` Brian King
2004-02-21  1:07         ` Rusty Russell
2004-02-22 23:23           ` Sam Ravnborg
2004-02-23  3:51             ` Rusty Russell
2004-02-23 21:17               ` Sam Ravnborg
2004-02-24  6:13                 ` Rusty Russell
2004-02-25 21:36                   ` Sam Ravnborg [this message]
2004-02-26  1:50                     ` Rusty Russell
2004-02-26  7:12                       ` Sam Ravnborg
2004-03-10 20:49     ` Brian King
2004-03-10 21:08       ` Greg KH

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=20040225213659.GA9985@mars.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=akpm@osdl.org \
    --cc=brking@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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

all inboxes | Powered by JetHome®