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

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