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

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