]> git.saurik.com Git - bison.git/blob - src/system.h
Use unlocked I/O for a minor performance improvement on hosts like
[bison.git] / src / system.h
1 /* System-dependent definitions for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 #ifndef BISON_SYSTEM_H
21 #define BISON_SYSTEM_H
22
23 #if HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <limits.h>
28 #include <stddef.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "unlocked-io.h"
33
34 #if HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #if HAVE_UNISTD_H
39 # include <unistd.h>
40 #endif
41
42 #if HAVE_INTTYPES_H
43 # include <inttypes.h>
44 #endif
45 #if HAVE_STDINT_H
46 # include <stdint.h>
47 #endif
48
49 #if ! HAVE_UINTPTR_T
50 /* This isn't perfect, but it's good enough for Bison, which needs
51 only to hash pointers. */
52 typedef size_t uintptr_t;
53 #endif
54
55 #include <verify.h>
56 #include <xalloc.h>
57
58
59 /*---------------------.
60 | Missing prototypes. |
61 `---------------------*/
62
63 #include <stpcpy.h>
64
65
66 /*-----------------.
67 | GCC extensions. |
68 `-----------------*/
69
70 /* Use this to suppress gcc's `...may be used before initialized'
71 warnings. */
72 #ifdef lint
73 # define IF_LINT(Code) Code
74 #else
75 # define IF_LINT(Code) /* empty */
76 #endif
77
78 #ifndef __attribute__
79 /* This feature is available in gcc versions 2.5 and later. */
80 # if !defined (__GNUC__) || __GNUC__ < 2 || \
81 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
82 # define __attribute__(Spec) /* empty */
83 # endif
84 #endif
85
86 /* The __-protected variants of `format' and `printf' attributes
87 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
88 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
89 # define __format__ format
90 # define __printf__ printf
91 #endif
92
93 #ifndef ATTRIBUTE_NORETURN
94 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
95 #endif
96
97 #ifndef ATTRIBUTE_UNUSED
98 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
99 #endif
100
101 /*------.
102 | NLS. |
103 `------*/
104
105 #include <locale.h>
106
107 #include <gettext.h>
108 #define _(Msgid) gettext (Msgid)
109 #define N_(Msgid) (Msgid)
110
111
112 /*-------------------------------.
113 | Fix broken compilation flags. |
114 `-------------------------------*/
115
116 #ifndef LOCALEDIR
117 # define LOCALEDIR "/usr/local/share/locale"
118 #endif
119
120
121 /*-----------.
122 | Booleans. |
123 `-----------*/
124
125 #include <stdbool.h>
126
127
128 /*-----------.
129 | Obstacks. |
130 `-----------*/
131
132 #define obstack_chunk_alloc xmalloc
133 #define obstack_chunk_free free
134 #include <obstack.h>
135
136 #define obstack_sgrow(Obs, Str) \
137 obstack_grow (Obs, Str, strlen (Str))
138
139 #define obstack_fgrow1(Obs, Format, Arg1) \
140 do { \
141 char buf[4096]; \
142 sprintf (buf, Format, Arg1); \
143 obstack_grow (Obs, buf, strlen (buf)); \
144 } while (0)
145
146 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
147 do { \
148 char buf[4096]; \
149 sprintf (buf, Format, Arg1, Arg2); \
150 obstack_grow (Obs, buf, strlen (buf)); \
151 } while (0)
152
153 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
154 do { \
155 char buf[4096]; \
156 sprintf (buf, Format, Arg1, Arg2, Arg3); \
157 obstack_grow (Obs, buf, strlen (buf)); \
158 } while (0)
159
160 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
161 do { \
162 char buf[4096]; \
163 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
164 obstack_grow (Obs, buf, strlen (buf)); \
165 } while (0)
166
167
168
169 /*-----------------------------------------.
170 | Extensions to use for the output files. |
171 `-----------------------------------------*/
172
173 #ifndef OUTPUT_EXT
174 # define OUTPUT_EXT ".output"
175 #endif
176
177 #ifndef TAB_EXT
178 # define TAB_EXT ".tab"
179 #endif
180
181 #ifndef DEFAULT_TMPDIR
182 # define DEFAULT_TMPDIR "/tmp"
183 #endif
184
185
186
187 /*---------------------.
188 | Free a linked list. |
189 `---------------------*/
190
191 #define LIST_FREE(Type, List) \
192 do { \
193 Type *_node, *_next; \
194 for (_node = List; _node; _node = _next) \
195 { \
196 _next = _node->next; \
197 free (_node); \
198 } \
199 } while (0)
200
201
202 /*---------------------------------------------.
203 | Debugging memory allocation (must be last). |
204 `---------------------------------------------*/
205
206 # if WITH_DMALLOC
207 # define DMALLOC_FUNC_CHECK
208 # include <dmalloc.h>
209 # endif /* WITH_DMALLOC */
210
211 #endif /* ! BISON_SYSTEM_H */