Subject: Re: bug#14495: unistd.h problem in t/lex-header.sh

From: Peter Rosin <[email-masked]>
Date: Wed, 29 May 2013 11:43:38 +0200

On 2013-05-29 11:06, Stefano Lattarini wrote:
> On 05/29/2013 10:39 AM, Peter Rosin wrote:
>> On 2013-05-29 02:08, Peter Rosin wrote:
>>> Hi!
>>>
>>> When t/lex-header.sh tries to compile main.c on the master branch, it fails
>>> like this snippet below, since MSVC does not have unistd.h. I suppose main.c
>>> should add
>>>
>>> 	#define YY_NO_UNISTD_H 1
>>>
>>> before it includes mylex.h? Or is this something else? I know very little
>>> about lexers...
>>
>> The problem is the same on the micro branch (87e49f4f040c8ab).
>>
> We had already solved a similar issue one, in the very Automake test suite.
> Let me see if I can find the reference ...  Oh wait, no need to, we have
> registered the learned lesson in t/README already:
> 
> * When writing input for lex, include the following in the definitions
>   section:
> 
>     %{
>     #define YY_NO_UNISTD_H 1
>     %}
> 
>   to accommodate non-ANSI systems, since GNU flex generates code that
>   includes unistd.h otherwise.
> 
> And peeking in the Git history, I see you already fixed a similar
> problem about an year ago, in commit v1.11-2058-g6f4b08d.
> 
> Can you try a fix on those lines?

That %{ ... %}-block is causes the #define to be added to the generated
foo-lexer.c file, and the block is in fact already present so adding it
a second time will probably not help :-) The new problem in this
testcase is that the main.c file includes the generated mylex.h without
defining YY_NO_UNISTD_H file.

The below one-liner makes the test pass. Ok to push such a change?

Cheers,
Peter

diff --git a/t/lex-header.sh b/t/lex-header.sh
index 005ae86..0789af4 100644
--- a/t/lex-header.sh
+++ b/t/lex-header.sh
@@ -55,6 +55,7 @@ cat > lexer.l << 'END'
 END

 cat > main.c <<'END'
+#define YY_NO_UNISTD_H 1
 #include "mylex.h"
 int main (void)
 {