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