On Mon, 21 Jun 2010, Alexander Kabaev wrote:

On Tue, 22 Jun 2010 03:22:40 +1000 (EST)
Bruce Evans <b...@optusnet.com.au> wrote:

On Sun, 20 Jun 2010, Marcel Moolenaar wrote:
...
#undef  unput
-#define unput(c) \
-       if (c != EOF) yyunput( c, yytext_ptr )
+#define unput(c)                                       \
+       do {                                            \
+               int _c = c;                             \
+               if (_c != EOF)                          \
+                       yyunput(_c, yytext_ptr);        \
+       } while(0)
#endif

...
This problem is handled by ungetc() by always converting the value to
unsigned char.  Thus the value can never equal EOF, and the character
set is effectively represented by unsigned char's, not the plain chars
that stdio returns in some other interfaces (but not getc()).

There seems to be no reason to break the warning about this instead of
using the same approach as stdio.  This depends on yyunput() not
having similar bugs (it must take an arg of type int and convert to
an unsigned cgar like ungetc()):

#define unput(c)        yyunput((unsigned char)(c), yytext_ptr)

This also fixes the missing parantheses for 'c' and some style bugs.

Bruce

DTrace _does_ try to unput EOF though and apparently gets away with it
on Solaris, so while yor version is correct, it is also useless.

Do you mean that it tries to unput EOF as an int (not obtained from a
char), and that that must fail and not unput ((unsigned char)EOF)?  Then
the current version is still broken on platforms with chars signed,
since when it tries to unput a char with value EOF, that will fail
and not unput ((unsigned char)<char's value>).

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to