source: git/libpolys/misc/auxiliary.h.in @ 9f7665

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