/[ascend]/trunk/base/generic/utilities/ascConfig.h
ViewVC logotype

Contents of /trunk/base/generic/utilities/ascConfig.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 500 - (show annotations) (download) (as text)
Tue Apr 18 11:55:12 2006 UTC (14 years, 9 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13788 byte(s)
Reduced some runtime debug messages from Python and C++ and base/generic/compiler/type_descio.c.
Fixed up support for GCC Visibility and add SCons 'sniffer' for this.
Fixed a bug with 'fileopenpath' in PyGTK interface (File->Open location is remembered from last time).
Fixed a bug with missing includes in C++.
1 /* ASCEND modelling environment
2 Copyright (C) 1997 Carnegie Mellon University
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 @file
21 Global configuration parameters.
22
23 This module defines the fundamental constants used by the rest of
24 Ascend and pulls in system headers.
25 There is not corresponding compiler.c. The variables
26 declared in this header are defined in ascParse.y.
27
28 This header and tcl/tk headers are known to conflict. This header
29 should be included AFTER tcl.h or tk.h, not before.
30
31 If including the file, you should also include utilities/error.h
32 *//*
33 by Mark Thomas
34 Version: $Revision: 1.12 $
35 Version control file: $RCSfile: ascConfig.h,v $
36 Date last modified: $Date: 2003/08/23 18:43:13 $
37 Last modified by: $Author: ballan $
38 */
39
40 #ifndef ASC_ASCCONFIG_H
41 #define ASC_ASCCONFIG_H
42
43 #ifndef ASC_BUILDING_INTERFACE
44 # define ASC_BUILDING_LIBASCEND
45 #endif
46
47 /*
48 *
49 * Determine the Operating System we are building on
50 *
51 */
52
53 /* windows */
54 #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
55 # ifndef __WIN32__
56 # define __WIN32__
57 # endif
58 #endif
59
60 #ifdef __alpha
61 /** DEC Alpha running OSF */
62 # define __ALPHA_OSF__
63 #endif /* __alpha */
64
65 #ifdef __hpux
66 /** HP running HP-UX */
67 # define __HPUX__
68 #endif /* __hpux */
69
70 #ifdef _AIX
71 /** IBM RS6000 or PowerPC running AIX */
72 # define __IBM_AIX__
73 #endif /* _AIX */
74
75 #ifdef __sgi
76 /** SGI running IRIX */
77 # define __SGI_IRIX__
78 #endif /* __sgi */
79
80 #if defined(__sun) || defined(sun)
81 # ifdef __SVR4
82 /** Sparc running Solaris 2.x (SunOS 5.x) */
83 # define __SUN_SOLARIS__
84 # else /* __SVR4 */
85 /** Sparc running SunOS 4.x (Solaris 1.x) */
86 # define __SUN_SUNOS__
87 # endif /* __SVR4 */
88 #endif /* __sun || sun */
89
90 /*
91 ASCEND code in base/generic only EXPORTS symbols, no imports.
92 The ASC_DLLSPEC macro will, depending on whether we are
93 ASC_BUILDING_LIBASCEND (building libascend.so aka ascend.dll)
94 or ASC_BUILDING_INTERFACE (building for example _ascpy.dll or
95 ascendtcl.dll), act respectively to declare symbols as being
96 *exported* or *imported*.
97
98 New versions of GCC are able to make use of these declarations
99 as well.
100 */
101 #ifdef __WIN32__
102 # define ASC_EXPORT(TYPE) extern __declspec(dllexport) TYPE
103 # define ASC_IMPORT(TYPE) extern __declspec(dllimport) TYPE
104 #else
105 # ifdef HAVE_GCCVISIBILITY
106 # define ASC_EXPORT(TYPE) extern __attribute__ ((visibility("default"))) TYPE
107 # define ASC_IMPORT(TYPE) extern TYPE
108 # else
109 # define ASC_EXPORT(TYPE) extern TYPE
110 # define ASC_IMPORT(TYPE) extern TYPE
111 # endif
112 #endif
113
114 #ifdef ASC_BUILDING_LIBASCEND
115 # define ASC_DLLSPEC(TYPE) ASC_EXPORT(TYPE)
116 #else
117 # define ASC_DLLSPEC(TYPE) ASC_IMPORT(TYPE)
118 #endif
119
120 #if !defined(ASC_DLLSPEC) || !defined(ASC_EXPORT) || !defined(ASC_IMPORT)
121 # error "NO ASC_DLLSPEC DEFINED"
122 #endif
123
124 /*
125 An attempt to prevent unexported symbols from slipping through
126 the net when developing with GCC on linux:
127 */
128 #ifdef HAVE_GCCVISIBILITY
129 # pragma GCC visibility push(hidden)
130 #endif
131
132 /**
133 What kind of C compiler do we have?
134
135 Use compiler flag -DDISABLE_C99 to force older ISO C
136 This means no variadic macros, maybe other things too.
137 */
138 #if defined(__STDC__) && defined(__STDC_VERSION__)
139 # if __STDC_VERSION__>=199901L
140 # ifndef DISABLE_C99
141 # define HAVE_C99
142 # endif
143 # endif
144 #endif
145
146 /*
147 * If we are in a tcl-infested file, define
148 * CONST84 to be empty for back-compatibility with
149 * tcl8.3
150 */
151 #ifdef TCL_VERSION
152 # ifndef CONST84
153 # define CONST84
154 # define QUIET(x) x
155 # define QUIET2(x) x
156 # else
157 /** use this macro to shut up const when const
158 from tcl-land would be going into non-tcl C.
159 */
160 # define QUIET(x) ((char *)x)
161 # define QUIET2(v) ((char **)v)
162 # endif
163 #endif
164
165 /*
166 * Make certain we have proper limits defined
167 */
168 #include <stdlib.h>
169 #include <limits.h>
170 #include <float.h>
171 #include <sys/types.h>
172 #ifdef _OSF_SOURCE
173 # include <sys/syslimits.h>
174 #endif
175 /* for use practically everywhere */
176 #include<stdio.h>
177
178
179 #if 0 /* there seems to be some confusion about the interaction of comment blocks and the preprocessor. there isn't any..., which means everything in this
180 if 0 block is broken. */
181
182 /* trying without this... */
183 #if defined(__WIN32__) && !defined(__MINGW32__)
184 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
185 # define WIN32_LEAN_AND_MEAN
186 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
187 # undef WIN32_LEAN_AND_MEAN
188 #endif
189 */
190 #endif /* 0 block needs fixing above */
191 #ifndef PATH_MAX
192 /** Normally will come from stdio.h or limits.h
193 * POSIX values of PATH_MAX is 255, traditional is 1023
194 */
195 # define PATH_MAX 1023
196 #endif
197
198 /* the following numbers should have come through limits.h */
199 #ifndef SHRT_MAX
200 # define SHRT_MAX 32767
201 #endif
202 #ifndef INT_MAX
203 # define INT_MAX 2147483647
204 /* 32 bit machines */
205 #endif
206 #ifndef LONG_MAX
207 # ifdef __alpha
208 # define LONG_MAX 9223372036854775807 /* 64 bit machines */
209 # else /* __alpha */
210 # define LONG_MAX 2147483647 /* 32 bit machines */
211 # endif /* __alpha */
212 #endif /* LONG_MAX */
213
214 #ifndef MAXDOUBLE
215 # define MAXDOUBLE DBL_MAX
216 #endif
217 #ifndef MAXINT
218 # define MAXINT INT_MAX
219 #endif
220 #ifndef MAXUINT
221 # define MAXUINT UINT_MAX
222 #endif
223 #ifndef MAXLONG
224 # define MAXLONG LONG_MAX
225 #endif
226 #ifndef MAXULONG
227 # define MAXULONG UILONG_MAX
228 #endif
229
230 /**
231 * The largest number of digits we'd ever expect to see in a single
232 * numeric value, * 3 or so for good measure.
233 */
234 #define MAXIMUM_NUMERIC_LENGTH 80
235
236 /*
237 * Useful Headers
238 */
239
240 /* for use by ascmalloc, which is also practically everywhere */
241 #include <stdio.h>
242 #include <assert.h>
243 #include <string.h>
244 /*
245 * #include <malloc.h>
246 *
247 * malloc() is defined in <stdlib.h> in ANSI-C
248 */
249
250 #define MAXTOKENLENGTH 1024 /**< Maximum token size.
251 Most significant for identifiers and strings */
252 #ifndef FALSE
253 # define FALSE 0
254 # define TRUE 1
255 #endif
256
257 #ifndef CONST
258 # define CONST const
259 #endif
260
261 #define VOIDPTR void *
262
263 /* Updated the following to use new Wiki URLS */
264 #define ASC_MILD_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
265 #define ASC_BIG_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
266
267 ASC_DLLSPEC(FILE*) g_ascend_errors; /**< File stream to receive error messages. */
268 ASC_DLLSPEC(FILE*) g_ascend_warnings; /**< File stream to receive warning messages. */
269 ASC_DLLSPEC(FILE*) g_ascend_information; /**< File stream to receive general messages. */
270
271 /* NB For error messages to be correctly captured, all output needs to go to stderr in error.h */
272 #ifndef ASCERR
273 # define ASCERR g_ascend_errors
274 # define ASCWAR g_ascend_warnings
275 # define ASCINF g_ascend_information
276 #endif
277 /*
278 * file pointers for whine. they default to stderr. if you change
279 * them, be sure to change them to valid files.
280 */
281
282 #define BYTESIZE 8
283 #define WORDSIZE (sizeof(unsigned)*BYTESIZE)
284 #ifndef TRUE
285 # define TRUE 1
286 #endif
287 #ifndef FALSE
288 # define FALSE 0
289 #endif
290 typedef char *POINTER; /**< Generic pointer. */
291 typedef char boolean; /**< Boolean type. */
292 typedef int ALIGN; /**< Data alignment. */
293 /**
294 * real64:
295 * change this typedef and all the solver code should change
296 * precision automatically. The code is predicated on 64bit ieee math.
297 * change the typedef as needed to get 64bit numbers. In particular
298 * crays may change this to float.
299 * int32:
300 * uint32;
301 * a 32bit int. change this typedef and all the solver code changes
302 * with it. may be of use for compiler which default int to 16bits
303 * equivalent to -i4 on most f77 compilers.
304 */
305 typedef double real64; /* a value */
306 typedef int int32; /**< a row/col/var/rel index number */
307 typedef unsigned uint32;
308
309
310 /**
311 * MAXREFCOUNT should always be defined to be the maximum value
312 * that the reference count attribute of reference count objects
313 * can take. It is unreasonable that a refcount be 64 bits, so
314 * it is 32.
315 */
316 #define MAXREFCOUNT UINT_MAX
317 #define REFCOUNT_T unsigned int
318
319 /*
320 * A bit of header magic to address the question of NULL being implementation
321 * defined, though virtually all systems of interest define it as 0 or 0L,
322 * if we are to claim ANSI conformance.
323 *
324 * IEEE 754 arithmetic implies all 0 bits <--> 0.0, so there isn't
325 * a problem where this is concerned. We have assumed ieee math.
326 *
327 * Notes to myself:
328 * Put this in base.h and suggest its insertion in
329 * compiler.h and perhaps interface1.h.
330 * Any place that calloc is being used to allocate arrays of NULL pointers,
331 * put a proper #if to replace it with a call to malloc and an appropriate
332 * NULLing function.
333 *
334 * Ben Allan, Jan 6, 1994.
335 */
336
337 /*
338 * NOTE: The below if works for 0 or 0L, which is to say I assume it
339 * works for 0 and I have tested that it works for 0L. Next we define
340 * the cheap versions of null testing for machine with 0 == NULL
341 *
342 * These are the proper ANSI C tests for NULL on 0!=NULL machines, should
343 * we ever run into them.
344 */
345 #ifdef NULL
346 /* ok, so the machine has a NULL defined. */
347 # ifndef ISNULL
348 /* and we've not got an ISNULL function */
349 # define ISNULL(a) ((a) == NULL)
350 # define NOTNULL(a) ((a) != NULL)
351 # endif /* ISNULL */
352 # endif /* NULL */
353
354 #ifndef NULL
355 # error "Null not defined by the time ascConfig.h seen"
356 #endif
357
358 #ifndef UNUSED_PARAMETER
359 /** Standardize the treatment of unreferenced function parameters. */
360 # define UNUSED_PARAMETER(p) (void)(p)
361 #endif
362
363 /* ASCEND assertion defines */
364 /** Exit status code for failed assertion. */
365 #define ASCERR_ASSERTION_FAILED 100
366 /*
367 * For now, asc_assert tied to NDEBUG just like regular assert.
368 * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
369 * gives us the ability to decouple from NDEBUG and leave
370 * assertions active in release code if desired.
371 */
372 #ifdef NDEBUG
373 /** If defined, asc_assert() will be removed from code. */
374 # define ASC_NO_ASSERTIONS
375 #endif
376
377 /*
378 *
379 * Platform specific fixes
380 *
381 */
382
383 #if defined(__WIN32__) && !defined(__MINGW32__)
384
385 /*
386 * use the ASCEND printf substitutes
387 */
388 # ifndef USE_ASC_PRINTF
389 # define USE_ASC_PRINTF
390 # endif /* USE_ASC_PRINTF */
391
392 /*
393 * build the Tk Console
394 */
395 # ifndef ASC_USE_TK_CONSOLE
396 # define ASC_USE_TK_CONSOLE
397 # endif /* ASC_USE_TK_CONSOLE */
398
399 #endif
400
401 /* use signals by default, but disable with configure. */
402 #ifdef ASC_NO_TRAPS
403 /** Don't use signals. */
404 # define NO_SIGNAL_TRAPS 1
405 #else
406 /** Use signals. */
407 # undef NO_SIGNAL_TRAPS
408 #endif
409
410 /*------------------------------------*
411 OUTPUT FILE* MAPPINGS
412
413 On Windows, we have to use these special Asc_Printf (etc)
414 routines in order that output can be captured correctly by the GUI.
415
416 On non-Windows platforms, allow error.h to
417 */
418 #ifdef USE_ASC_PRINTF
419 # define ASC_PRINTF Asc_Printf
420 # define ASC_FPRINTF Asc_FPrintf
421 # define ASC_VFPRINTF Asc_VFPrintf
422 # define ASC_FFLUSH Asc_FFlush
423 # define ASC_PUTC Asc_FPutc
424 # define ASC_FPUTC Asc_FPutc
425 # define ASC_PUTCHAR Asc_Putchar
426 # include <stdarg.h>
427 # include "utilities/ascPrint.h"
428 #else
429 # define ASC_PRINTF printf
430 # define ASC_FPRINTF fprintf
431 # define ASC_VFPRINTF vfprintf
432 # define ASC_FFLUSH fflush
433 # define ASC_PUTC putc
434 # define ASC_FPUTC fputc
435 # define ASC_PUTCHAR putchar
436 #endif
437
438 /* error.h will define handlers for
439 FPRINTF
440 FPUTC
441 FFLUSH
442 */
443 #ifdef IS_BINTOKEN_COMPILE
444 # define FPRINTF ASC_FPRINTF
445 # define FPUTC ASC_FPUTC
446 # define FFLUSH ASC_FFLUSH
447 #else
448 # include "utilities/error.h"
449 #endif
450
451 /* These are the remaining output macros that need to be mapped
452 */
453 #define PRINTF ASC_PRINTF
454 #define PUTCHAR ASC_PUTCHAR
455 /*------------------------------------*/
456
457
458 #ifndef __SUN_SUNOS__
459 /* do this for non-sun machines and for sun-solaris machines */
460 # ifndef roundup
461 # define rounddown(num,mod) ((num)-(num)%(mod))
462 # define roundup(num,mod) rounddown((num)+(mod)-1,(mod))
463 # define roundoff(num,mod) rounddown((num)+((mod)/2),(mod))
464 # endif /* roundup */
465 #endif /* __SUN_SUNOS__ */
466
467
468 /* These define integer divide and modulus mathematically correctly */
469 #define imod(num,den) ((num)%(den) + ((num)%(den)<0 ? (den) : 0))
470 #define idiv(num,den) ((num)/(den) + ((num)%(den)<0))
471 #define array_length(a) (sizeof(a)/sizeof((a)[0]))
472
473 /*
474 * the following patch up IEEE754isms that some systems can't seem to
475 * get right.
476 */
477 #define FPRESET (void)0
478 #ifdef __WIN32__
479 /* renamed in some __WIN32__ compiler systems */
480 # ifndef NO_RENAME_IEEE_FUNCTIONS
481 # undef finite
482 # define finite(x) _finite(x)
483 # undef isnan
484 # define isnan(x) _isnan(x)
485 # undef isinf
486 # define isinf(x) _isinf(x)
487 # endif
488 # undef FPRESET
489 # define FPRESET _fpreset()
490 /* MSVC peculiarities */
491 # ifdef _MSC_VER
492 # undef snprintf
493 # define snprintf _snprintf
494 # undef vsnprintf
495 # define vsnprintf _vsnprintf
496 # undef tempnam
497 # define tempnam _tempnam
498 # undef fdopen
499 # define fdopen _fdopen
500 # undef fileno
501 # define fileno _fileno
502 # undef getpid
503 # define getpid _getpid
504 # undef dup
505 # define dup _dup
506 # undef dup2
507 # define dup2 _dup2
508 # undef putenv
509 # define putenv _putenv
510 # endif
511 #endif /* __WIN32__ */
512
513 #ifdef __SUN_SUNOS__
514 /** not properly headered in math.h or ieee*.h */
515 extern int finite(double);
516 #endif
517
518 #endif /* ASC_ASCCONFIG_H */
519

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22