[PHP-DEV] Bug #1600: flex-generated parsers don't use const if __STDC__ is not true From: alanc <email protected>
Date: 06/25/99

From: alanc <email protected>
Operating system: Solaris 2.6
PHP version: 3.0.9
PHP Bug Type: Feature/Change Request
Bug description: flex-generated parsers don't use const if __STDC__ is not true

language-scanner.c & configuration parser.c contain the following code (generated by flex):

#if __STDC__
#define YY_USE_CONST
#endif /* __STDC__ */

#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif

Unfortunately, not all compilers that support the const keyword define __STDC__ to a true value.
For instance, Sun's C compiler only defines __STDC__ to be true if the compiler is invoked with
-Xc (strict ANSI compliance mode, no non-ANSI features allowed). The following patch works around
this behavior, and generates a libmodphp.a that makes the large parser tables read-only so they
can be shared between http processes and lowers the per-process memory requirements:
diff -crwb php-3.0.9/configure.in php-3.0.9-mine/configure.in
*** php-3.0.9/configure.in Thu Jun 3 05:03:05 1999
--- php-3.0.9-mine/configure.in Fri Jun 25 18:20:00 1999
***************
*** 36,41 ****
--- 36,50 ----
        CFLAGS=`echo $CFLAGS | sed -e 's/-g//'`
  fi
  
+ dnl Make flex scanners use const if they can, even if __STDC__ is not
+ dnl true, for compilers like Sun's that only set __STDC__ true in
+ dnl "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
+ AC_C_CONST
+ if test $ac_cv_c_const = yes; then
+ LEX_CFLAGS="-DYY_USE_CONST"
+ fi
+ AC_SUBST(LEX_CFLAGS)
+
  dnl check for -R, etc. switch
  AC_MSG_CHECKING(if compiler supports -R)
  AC_CACHE_VAL(php_cv_cc_dashr,[

diff -crwb php-3.0.9/Makefile.in php-3.0.9-mine/Makefile.in
*** php-3.0.9/Makefile.in Thu Jun 3 07:05:10 1999
--- php-3.0.9-mine/Makefile.in Fri Jun 25 18:23:27 1999
***************
*** 52,57 ****
--- 52,58 ----
  APXS =  <email protected>@
  APXS_LDFLAGS =  <email protected>@  <email protected>@  <email protected>@
  WARNING_LEVEL =  <email protected>@
+ LEX_CFLAGS = -w$(WARNING_LEVEL)  <email protected>@
  
  SOURCE = language-parser.tab.c language-scanner.c main.c php3_hash.c operators
.c \
         variables.c token_cache.c stack.c internal_functions.c \
***************
*** 141,147 ****
        bison -p php -v -d $(srcdir)/language-parser.y -o language-parser.tab.c
  
  language-scanner.o:
! $(CC) $(CFLAGS) -w$(WARNING_LEVEL) -c language-scanner.c
  
  language-scanner.c: $(srcdir)/language-scanner.lex
        flex -Pphp -olanguage-scanner.c -i $(srcdir)/language-scanner.lex
--- 142,148 ----
        bison -p php -v -d $(srcdir)/language-parser.y -o language-parser.tab.c
  
  language-scanner.o:
! $(CC) $(CFLAGS) $(LEX_CFLAGS) -c language-scanner.c
  
  language-scanner.c: $(srcdir)/language-scanner.lex
        flex -Pphp -olanguage-scanner.c -i $(srcdir)/language-scanner.lex
***************
*** 150,156 ****
        bison -p cfg -v -d $(srcdir)/configuration-parser.y -o configuration-par
ser.tab.c
  
  configuration-scanner.o:
! $(CC) $(CFLAGS) -w$(WARNING_LEVEL) -c configuration-scanner.c
  
  configuration-scanner.c: $(srcdir)/configuration-scanner.lex
        flex -Pcfg -oconfiguration-scanner.c -i $(srcdir)/configuration-scanner.
lex
--- 151,157 ----
        bison -p cfg -v -d $(srcdir)/configuration-parser.y -o configuration-par
ser.tab.c
  
  configuration-scanner.o:
! $(CC) $(CFLAGS) $(LEX_CFLAGS) -c configuration-scanner.c
  
  configuration-scanner.c: $(srcdir)/configuration-scanner.lex
        flex -Pcfg -oconfiguration-scanner.c -i $(srcdir)/configuration-scanner.
lex

-- 
PHP Development Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>