summaryrefslogtreecommitdiff
path: root/src/scan.l
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2017-09-04 08:28:53 +0800
committerWill Estes <westes575@gmail.com>2017-09-03 21:17:59 -0400
commit4b5111d9772b5c160340ca96f08d30d7f6db5cda (patch)
tree6ad05a90e2966c706b364c6517736b15e379efea /src/scan.l
parentf2943389fd3ca776d25735c06ef94512a2bb5c20 (diff)
scanner: Include flexdef.h at %top block of scan.l
config.h may define macros that alter the API of the standard library funtions, and so it should be included before any other standard header, even before the skeleton's standard header inclusion. For example: config.h may #define _GNU_SOURCE that would expose the reallocarray() prototype from <stdlib.h> on glibc 2.26+ systems. If we include <stdlib.h> before config.h, reallocarray() would not be available for use in lex file since the second include doesn't help due to header guard. For now our config.h might `#define malloc rpl_malloc` -- this substitution must work before including stdlib.h, or else the compiler will complain about missing prototypes, and may result in incorrect code in scan.l (gcc warning: return makes pointer from integer without a cast [-Wint-conversion]). Fixes #247.
Diffstat (limited to 'src/scan.l')
-rw-r--r--src/scan.l7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/scan.l b/src/scan.l
index 3995bcf..4f497ac 100644
--- a/src/scan.l
+++ b/src/scan.l
@@ -1,5 +1,11 @@
/* scan.l - scanner for flex input -*-C-*- */
+%top{
+/* flexdef.h includes config.h, which may contain macros that alter the API */
+/* of libc functions. Must include first before any libc header. */
+#include "flexdef.h"
+}
+
%{
/* Copyright (c) 1990 The Regents of the University of California. */
/* All rights reserved. */
@@ -32,7 +38,6 @@
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
/* PURPOSE. */
-#include "flexdef.h"
#include "parse.h"
extern bool tablesverify, tablesext;
extern int trlcontxt; /* Set in parse.y for each rule. */