[2/6] libcpu: Include config.h before standard headers in lexer source

Message ID 20241010102559.9162-3-mcpratt@pm.me
State Committed
Headers
Series Various portability fixes and organization |

Commit Message

Michael Pratt Oct. 10, 2024, 10:27 a.m. UTC
  As part of the processing of flex, definitions and headers
are added to output source before any literal text or generated code.

This causes standard headers to come before config.h
unless config.h is included in a %top block instead
as specified in the flex manual, section 5.1 "Format of the Definitions".

The %top block is non-POSIX, so using it reinforces
the requirement of "flex" over a standardized "lex" even more.

      * libcpu/i386_lex.l (%top): add flex %top block
      and move config.h header inclusion to it.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
---
 libcpu/i386_lex.l | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Comments

Mark Wielaard Oct. 14, 2024, 8:51 p.m. UTC | #1
Hi Michael,

On Thu, Oct 10, 2024 at 10:27:02AM +0000, Michael Pratt wrote:
> As part of the processing of flex, definitions and headers
> are added to output source before any literal text or generated code.
> 
> This causes standard headers to come before config.h
> unless config.h is included in a %top block instead
> as specified in the flex manual, section 5.1 "Format of the Definitions".
> 
> The %top block is non-POSIX, so using it reinforces
> the requirement of "flex" over a standardized "lex" even more.
> 
>       * libcpu/i386_lex.l (%top): add flex %top block
>       and move config.h header inclusion to it.

configure already checks we have flex, so this is fine.

Pushed,

Mark
  

Patch

diff --git a/libcpu/i386_lex.l b/libcpu/i386_lex.l
index 9b33ed95..9c1e14db 100644
--- a/libcpu/i386_lex.l
+++ b/libcpu/i386_lex.l
@@ -1,3 +1,9 @@ 
+%top{
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+}
+
 %{
 /* Copyright (C) 2004, 2005, 2007, 2008 Red Hat, Inc.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
@@ -26,10 +32,6 @@ 
    the GNU Lesser General Public License along with this program.  If
    not, see <http://www.gnu.org/licenses/>.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
 #include <ctype.h>
 
 #include <libeu.h>