build issues when using pcc
hello i compiled dash with pcc and found two issues:
src/output.h the outc macro is not standard c:
#define outc(c, file)<->((file)->nextc == (file)->end ? outcslow((c), (file)) : (*(file)->nextc = (c), (file)->nextc++))
type signature of the operands are int ? void : char* but the two sides of : should be compatible either use
... ? outcslow(), 0 : ...
or
... ? outcslow() : ..., (void)0otherwise a standard compliant compiler won't compile it
the other issue is in the mkbuiltins:
it assumes that the cpp does not produce empty lines with whitespace only
the following line
< $builtins sed '/^#/d; /^$/d' > $temp
should be
< $builtins sed '/^#/d; /^ *$/d' > $temp
so empty lines with spaces are dropped as well (allowed by the standard after the preprocessing pass)
(also it would be nice to include a configure script in the git repo, or don't use autoconf in the first place)
Hi,
Quoted 3 lines · Szabolcs Nagy
hello i compiled dash with pcc and found two issues:
src/output.hthe outc macro is not standard c:
Thanks. I tried and succeeded in reproducing this first one by noticing that "gcc -pedantic" produces a warning. It also produces many other warnings --- for example, one about use of statement expressions in src/error.h. It might be nice to fix more of these.
Quoted 7 lines
the following line
< $builtins sed '/^#/d; /^$/d' > $temp
should be
< $builtins sed '/^#/d; /^ *$/d' > $tempso empty lines with spaces are dropped as well (allowed by the standard after the preprocessing pass)
What cpp do you use (so others can catch similar problems in the future)?
Looking over the C standard, it seems that if cc -E were exactly carrying out translation phases 1-4 (which it isn't :)) then we would expect each comment to be transformed to a single space character. So this looks like a good fix for portability.
Quoted 2 lines
(also it would be nice to include a configure script in the git repo,
No, it would not be nice.
Quoted 1 line
or don't use autoconf in the first place)
The nice things automake offers for dash are support for cross-compilation, dependency detection using gcc -MD, and VPATH builds. I am a nobody, so my opinion does not mean much, but: I would be very happy to use a plain makefile that can do those things, too.
In that imagined scheme, the configure script would stick to what it is best at --- detecting information about the platform and configuration. The configure script output could go in a makefile fragment that the makefile uses with an "include" directive (relying on sane defaults when it is not present). The git project is an example of this (though missing features like cross-compilation and VPATH builds).
I'd be happy to help out with that (as an alternate build system at first).
Thanks and hope that helps.
-- >8 --
Subject: [OUTPUT] Make outc an inline function
As "gcc -pedantic" warns, ISO C forbids conditional expressions with only one void side. So the (needslow ? slowpath() : fastpath) code for outc in the !USE_GLIBC_STDIO case might not be portable.
More importantly, it's hard to read. Rip it out and replace it with an inline function which should generate the same code.
---
Not even compile-tested.
src/output.h | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
src/output.h +13 -2
@@ -97,10 +97,21 @@ freestdout()#define OUTPUT_ERR 01/* error occurred on output */ #ifdef USE_GLIBC_STDIO -#define outc (c, o) putc((c), (o)->stream) +static inline void outc (int ch,struct output *file) +{ +putc (ch, file->stream); +}#define doformat (d, f, a) vfprintf((d)->stream, (f), (a))#else -#define outc (c, file) ((file)->nextc == (file)->end ? outcslow((c), (file)) : (*(file)->nextc = (c), (file)->nextc++)) +static inline void outc (int ch,struct output *file) +{ +if (file->nextc != file->end) { + *file->nextc = ch; + file->nextc++; +return ; + } +outcslow (ch, file); +}#endif #define out1c (c) outc((c), out1)#define out2c (c) outcslow((c), out2)
Signature · 1 line
1.7.5.1
Quoted 6 lines · Szabolcs Nagy
Quoted 2 lines · Jonathan Nieder
What cpp do you use (so others can catch similar problems in the future)?
pcc uses its own preprocessor
Ah, sloppy me. I stupidly read pcc as "ppc" but you are talking about http://pcc.ludd.ltu.se/
Will check it out; thank you.
Quoted 7 lines · Jonathan Nieder
Subject: [OUTPUT] Make outc an inline function
As "gcc -pedantic" warns, ISO C forbids conditional expressions with only one void side. So the (needslow ?
slowpath(): fastpath) code for outc in the !USE_GLIBC_STDIO case might not be portable.
Quoted 5 lines
More importantly, it's hard to read. Rip it out and replace it with an inline function which should generate the same code.
Reported-by Szabolcs Nagy <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>
Patch applied.
I've also added this one-liner on top to eliminate an unnecessary promotion caused by this patch.
commit 155b0b518f485b8b5cb574cd2f0dc936c3fd1902
Author: Herbert Xu <[email protected]> Date: Thu Jul 7 15:22:03 2011 +0800
[BUILTIN] Eliminate unnecessary promotion in echocmd
The patch to make outc into an inline function created an unnecessary promotion in echocmd due to its use of char vs. the int used by outc. This patch changes echocmd to use int instead.
ChangeLog +1 -0
@@ -1,6 +1,7 @@ 2011-07-07 Herbert Xu <[email protected]> * Optimize dash -c "command" to avoid a fork. + * Eliminate unnecessary promotion in echocmd. 2011-05-22 Jonathan Nieder <[email protected]>
src/bltin/printf.c +1 -1
@@ -443,7 +443,7 @@ echocmd(int argc, char **argv) } do { - char c; + int c; nonl += conv_escape_str(*argv); outstr(stackblock(), outs);
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt