source: git/libpolys/misc/auxiliary.h.in @ af223b0

spielwiese
Last change on this file since af223b0 was af223b0, checked in by Burcin Erocal <burcin@…>, 13 years ago
Fix Singular/fehelp.cc.
  • Property mode set to 100644
File size: 11.3 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR   
3\*****************************************************************************/
4/** @file auxiliary.h
5 *
6 * All the auxiliary stuff.
7 *
8 * ABSTRACT: we shall put here everything that does not have its own place.
9 *
10 * @author Oleksandr Motsak
11 *
12 * @internal @version \$Id$
13 *
14 **/
15/*****************************************************************************/
16
17#ifndef MISC_AUXILIARY_H
18#define MISC_AUXILIARY_H
19
20// ----------------- which parts/extensions of Singular to build
21#ifndef HAVE_RINGS
22#undef HAVE_RINGS
23#endif
24
25#ifndef HAVE_PLURAL
26#undef HAVE_PLURAL
27#endif
28
29#ifndef HAVE_DL
30#undef HAVE_DL
31#endif
32
33#ifndef HAVE_FACTORY
34#undef HAVE_FACTORY
35#endif
36
37#ifndef HAVE_NTL
38#undef HAVE_NTL
39#endif
40
41#ifndef HAVE_POLYEXTENSIONS
42#undef HAVE_POLYEXTENSIONS
43#endif
44// ----------------  end of parts/extensions
45// -----------------  configure stuff
46
47// TODO: the following should go to some config.h... no?
48
49/* Define version as a string */
50#ifndef S_VERSION1
51#define S_VERSION1 "spielwiese"
52#endif
53
54/* Absolute pathname of root directory of Singular source */
55#ifndef S_ROOT_DIR
56#define S_ROOT_DIR ""
57#endif
58
59/* Singular\'s own uname\ */
60#ifndef S_UNAME
61#undef S_UNAME ""
62#endif
63// ----------------- end of configure stuff
64
65// ---------------- Singular standard types etc.
66// BOOLEAN
67
68#ifndef SIZEOF_LONG
69
70#include <misc/mylimits.h>
71
72#ifndef LONG_BIT
73#if ULONG_MAX == 0xffffffffUL
74#define LONG_BIT 32
75#elif ULONG_MAX == 0xffffffffffffffffULL
76#define LONG_BIT 64
77#else
78#error "Unexpected max for unsigned long"
79#endif
80#endif
81
82
83
84#define SIZEOF_LONG (LONG_BIT/CHAR_BIT)
85// another option for SIZEOF_LONG: use omConfig included in <omalloc/omalloc.h>...
86
87#endif
88
89#include <sys/types.h>
90#if SIZEOF_LONG == 4
91typedef long long int64;
92#elif SIZEOF_LONG == 8
93typedef long int64;
94#else
95#error "Unexpected SIZEOF_LONG"
96#endif
97
98
99
100
101#if (SIZEOF_LONG == 8)
102typedef int BOOLEAN;
103/* testet on x86_64, gcc 3.4.6: 2 % */
104/* testet on IA64, gcc 3.4.6: 1 % */
105#else
106/* testet on athlon, gcc 2.95.4: 1 % */
107typedef short BOOLEAN;
108#endif
109
110#ifndef FALSE
111#define FALSE       0
112#endif
113
114#ifndef TRUE
115#define TRUE        1
116#endif
117
118#ifndef NULL
119#define NULL        (0)
120#endif
121
122#ifndef NULLp
123#define NULLp        ((void*)NULL)
124#endif
125
126// #ifdef _TRY
127#ifndef ABS
128#define ABS(x) ((x)<0?(-(x)):(x))
129#endif
130// #endif
131
132static const int MAX_INT_LEN= 11;
133typedef void* ADDRESS;
134
135#define loop for(;;)
136
137#if defined(__cplusplus)
138static inline int si_max(const int a, const int b)  { return (a>b) ? a : b; }
139static inline int si_min(const int a, const int b)  { return (a<b) ? a : b; }
140static inline long si_max(const long a, const long b)  { return (a>b) ? a : b; }
141static inline unsigned long si_max(const unsigned long a, const unsigned long b)  { return (a>b) ? a : b; }
142static inline long si_min(const long a, const long b)  { return (a<b) ? a : b; }
143static inline unsigned long si_min(const unsigned long a, const unsigned long b)  { return (a<b) ? a : b; }
144#else
145#define si_max(A,B) ((A) > (B) ? (A) : (B))
146#define si_min(A,B) ((A) < (B) ? (A) : (B))
147#endif
148
149
150// ---------------- end of Singular standard types etc.
151// ---------------- defines which depend on the settings above
152
153#ifndef HAVE_MULT_MOD
154#undef HAVE_MULT_MOD
155#endif
156
157#ifndef HAVE_DIV_MOD
158#undef HAVE_DIV_MOD
159#endif
160
161#ifndef HAVE_GENERIC_ADD
162#undef HAVE_GENERIC_ADD
163#endif
164
165/*******************************************************************
166 * DEBUG OPTIONS
167 * -- only significant for for compiling without -DNDEBUG
168 * -- you better know what your are doing, if you touch this
169 ******************************************************************/
170#ifndef NDEBUG
171
172/* undefine to enable inline */
173#define NO_INLINE
174
175/* undefine to disable assume -- should normally be defined for NDEBUG */
176#define HAVE_ASSUME
177
178/* undef PDEBUG to disable checks of polys
179
180 define PDEBUG to
181  0 for enabling pTest
182  1 plus tests in Level 1 poly routines (operations on monomials)
183  2 plus tests in Level 2 poly routines (operations on single exponents)
184 -- see also polys.h for more info
185
186 NOTE: you can set the value of PDEBUG on a per-file basis, before
187       including mod2.h, provided ! PDEBUG is defined in mod2.h E.g.:
188
189       #define PDEBUG 2
190       #include "auxiliary.h"
191       ...
192
193       makes sure that all poly operations in your file are done with
194       PDEBUG == 2
195 To break after an error occured, set a debugger breakpoint on
196 dErrorBreak.
197*/
198#ifndef PDEBUG
199#define PDEBUG 0
200#endif
201
202/* define MDEBUG to enable memory checks */
203#define MDEBUG 0
204
205#ifdef MDEBUG
206/* If ! defined(OM_NDEBUG) and (defined(OM_TRACK) or defined(OM_CHECK)
207   then omDebug routines are used for memory allocation/free:
208
209   The omDebug routines are controlled by the values of OM_TRACK, OM_CHECK
210   and OM_KEEP.  There meaning is roughly as follows:
211   OM_TRACK: strored with address                              : extra space
212     0     : no additional info is stored                      : 0
213     1     : file:line of location where address was allocated : 1 word
214     2     : plus backtrace of stack where adress was allocated: 6 words
215     3     : plus size/bin info and front-, and back padding   : 9 words
216     4     : plus file:line of location where adress was freed : 10 words
217     5     : plus backtrace of stack where adress was allocated: 15 words
218   OM_CHECK: checks done
219     0     : no checks
220     1     : constant-time checks: i.e. addr checks only
221     2     : plus linear-time checks and constant related bin check
222     3     : plus quadratic-time checks and linear-time related bin checks and
223             constant time all memory checks
224     4     : and so on
225     ==> for OM_CHECK >= 3 it gets rather slow
226   OM_KEEP:  determines whether addresses are really freed  (
227     0     : addresses are really freed
228     1     : addresses are only marked as free and not really freed.
229
230   OM_CHECK, OM_TRACK, and OM_KEEP can be set on a per-file basis
231   (as can OM_NDEBUG),  e.g.:
232     #define OM_CHECK 3
233     #define OM_TRACK 5
234     #define OM_KEEP  1
235     #include "mod2.h"
236     #include "omalloc.h"
237   ensures that all memory allocs/free in this file are done with
238   OM_CHECK==3 and OM_TRACK==5, and that all addresses allocated/freed
239   in this file are only marked as free and never really freed.
240 
241   To set OM_CHECK, OM_TRACK and OM_KEEP under dynamic scope, set
242   om_Opts.MinCheck, om_Opts.MinTrack to the respectiv values and
243   om_Opts.Keep to the number of addresses which are kept before they are
244   actually freed. E.g.:
245     int check=om_Opts.MinCheck, track=om_Opts.MinTrack, keep= m_OPts.Keep;
246     om_Opts.MinCheck = 3; om_Opts.MinTrack = 5; omOpts.Keep = LONG_MAX;
247     ExternalRoutine();
248     om_Opts.MinCheck = check; omOpts.MinTrack = track; omOpts.Keep = keep;
249   ensures that all calls omDebug routines  occuring during the computation of
250   ExternalRoutine() are done with OM_CHECK==3 and OM_TRACK==5, and
251   calls to omFree only mark addresses as free and not really free them.
252
253   Furthermore, the value of OM_SING_KEEP (resp. om_Opts.Keep) specifies
254   how many addresses are kept before they are actually freed, independently
255   of the value of OM_KEEP.
256
257   Some tips on possible values of OM_TRACK, OM_CHECK, OM_KEEP:
258   + To find out about an address that has been freed twice, first locate the
259     file(s) where the error occured, and then at the beginning of these files:
260       #define OM_CHECK 3
261       #define OM_TRACK 5
262       #define OM_KEEP  1
263       #include "mod2.h"
264       #include "omalloc.h"
265     Under dynamic scope, do (e.g., from within the debugger):
266       om_Opts.MinCheck = 3; om_Opts.MinTrack = 5; omOpts.Keep = LONG_MAX;
267   + to find out where "memory corruption" occured, increase value of
268     OM_CHECK - the higher this value is, the more consistency checks are
269     done (However a value > 3 checks the entire memory each time an omalloc
270     routine is used!)
271   
272   Some more tips on the usage of omalloc:
273   + omAlloc*, omRealloc*, omFree*, omCheck* omDebug* omTest* rotuines
274     assume that sizes are > 0 and pointers are != NULL
275   + omalloc*, omrealloc*, omfree* omcheck*, omdebug* omtest* routines allow
276     NULL pointers and sizes == 0
277   + You can safely use any free/realloc routine in combination with any alloc
278     routine (including the debug versions): E.g., an address allocated with
279     omAllocBin can be freed with omfree, or an adress allocated with
280     om(Debug)Alloc can be freed with omfree, or omFree, or omFreeSize, etc.
281     However, keep in mind that the efficiency decreases from
282     Bin over Size to General routines (i.e., omFreeBin is more efficient than
283     omFreeSize which is more efficient than omFree, likewise with the alloc
284     routines).
285   + if OM_CHECK is undefined or 0, then all omCheck routines do nothing
286   + if OM_CHECK and OM_TRACK are both undefined (or 0), or if OM_NDEBUG is
287     defined, then the "real" alloc/realloc/free macros are used, and all
288     omTest, omDebug and omCheck routines are undefined
289   + to break after an omError occured within a debugger,
290     set a breakpoint on dErrorBreak
291   + to do checks from within the debugger, or to do checks with explicit
292     check level, use omTest routines.
293*/
294
295/* by default, store alloc info and file/line where addr was freed */
296#ifndef OM_TRACK
297#define OM_TRACK 4
298#endif
299/* only do constant-time memory checks */
300#ifndef OM_CHECK
301#define OM_CHECK 1
302#endif
303/* Do actually free memory:
304   (be careful: if this is set, memory is never really freed,
305    but only marked as free) */
306#ifndef OM_KEEP
307#define OM_KEEP 0
308#endif
309/* but only after you have freed 1000 more addresses
310   (this is actually independent of the value of OM_KEEP and used
311   to initialize om_Opts.Keep) */
312#ifndef OM_SING_KEEP
313#define OM_SING_KEEP 1000
314#endif
315
316#endif /* MDEBUG */
317
318
319/* undef KDEBUG for check of data during std computations
320 *
321 * define KDEBUG to
322 * 0 for basic tests
323 * 1 for tests in kSpoly
324 * NOTE: You can locally enable tests in kspoly by setting the
325 *       define at the beginning of kspoly.cc
326 */
327#define KDEBUG 0
328
329/* define LDEBUG checking numbers, undefine otherwise */
330#define LDEBUG
331/* define RDEBUG checking rings (together with TRACE=9) */
332#define RDEBUG
333/* define TEST for non time critical tests, undefine otherwise */
334#define TEST
335
336/* define YYDEBUG 1 for debugging bison texts, 0 otherwise */
337#define YYDEBUG 1
338
339#endif
340/* end of debugging option (ifndef NDEBUG) */
341
342
343
344#ifdef _DEBUG
345#      define FORCE_INLINE inline
346#else
347#ifdef NDEBUG
348#if   defined(_MSC_VER)
349#      define FORCE_INLINE __forceinline
350#elif defined(__GNUC__) && __GNUC__ > 3
351#      define FORCE_INLINE inline __attribute__ ((always_inline))
352#else
353#      define FORCE_INLINE inline
354#endif
355#else
356#      define FORCE_INLINE inline
357#endif
358/* NDEBUG */
359#endif
360/* _DEBUG */
361
362
363#define DO_PRAGMA(x) _Pragma (#x)
364#define TODO(who, msg) DO_PRAGMA(message ("TODO [for " #who "]: " #msg))
365
366
367
368#if defined(__GNUC__) && defined(__GNUC_MINOR__)
369#define _GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
370#else
371#define _GNUC_PREREQ(maj, min) 0
372#endif
373
374#if _GNUC_PREREQ(3,3) && defined(__ELF__)
375#define FORCE_INTERNAL __attribute__ ((visibility ("internal")))
376#else
377#define FORCE_INTERNAL
378#endif
379
380#if _GNUC_PREREQ(3,3)
381#define FORCE_DEPRECATED __attribute__ ((deprecated))
382#else
383#define FORCE_DEPRECATED
384#endif
385
386#ifdef __cplusplus
387# define  BEGIN_CDECL extern "C" {
388# define  END_CDECL   }
389#else
390# define  BEGIN_CDECL
391# define  END_CDECL
392#endif
393
394
395
396#endif
397/* MISC_AUXILIARY_H */
398
Note: See TracBrowser for help on using the repository browser.