sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,715 @@
1
+ /*
2
+ * File: u.h
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #ifndef __U_H
8
+ #define __U_H
9
+
10
+
11
+ /*=============================================================================
12
+ * Config Section
13
+ * ~~~~~~~~~~~~~~
14
+ *===========================================================================*/
15
+ #if (defined(_WIN32) && !defined(WIN32))
16
+ #define WIN32
17
+ #define _WIN32_WINNT 0x0400
18
+ #endif
19
+
20
+ #if (defined(__APPLE__) && defined(__MACH__))
21
+ #define DARWIN
22
+ #endif
23
+
24
+ #if (defined(__linux__))
25
+ #define LINUX
26
+ #endif
27
+
28
+ #if (defined(__FreeBSD__))
29
+ #define FreeBSD
30
+ #endif
31
+
32
+ #if (defined(__sun__))
33
+ #define SunOS
34
+ #endif
35
+
36
+ #if (defined(FreeBSD) || defined(DARWIN) || defined(Linux))
37
+ #define HAVE_GETCWD
38
+ #else
39
+ /* don't have getcwd() */
40
+ #endif
41
+
42
+ #if (defined(FreeBSD) || defined(DARWIN))
43
+ /* don't have gcvt() */
44
+ #else
45
+ #define HAVE_GCVT
46
+ #endif
47
+
48
+
49
+ #if (defined(DARWIN) || defined(FreeBSD) || defined(LINUX) || defined(__cygwin__))
50
+ /* don't have spinlocks */
51
+ #else
52
+ #define HAVE_SPINLOCKS
53
+ #endif
54
+
55
+ #if defined(LINUX)
56
+ #define U_MAP_ANONYMOUS MAP_ANONYMOUS
57
+ #elif (defined(DARWIN) || defined(FreeBSD) || defined(SunOS))
58
+ #define U_MAP_ANONYMOUS MAP_ANON
59
+ #endif
60
+
61
+ #if (defined(LINUX) || defined(SunOS))
62
+ #define U_MAP_NORESERVE MAP_NORESERVE
63
+ #elif (defined(DARWIN) || defined(FreeBSD))
64
+ #define U_MAP_NORESERVE 0
65
+ #endif
66
+
67
+ #if defined(DARWIN) || defined(SunOS)
68
+ #define U_MSG_NOSIGNAL 0 //SO_NOSIGNAL can be used only in setsockopt() under Mac OS 10.2 and later
69
+ //The only way to block SIGPIPE under Solaris to block it with sigignore().
70
+ #else
71
+ #define U_MSG_NOSIGNAL MSG_NOSIGNAL
72
+ #endif
73
+
74
+ #if (defined(DARWIN) || defined(FreeBSD))
75
+ #define HAVE_DEFAULT_LARGEFILE_FUNCTIONS
76
+ #else
77
+ /* use system calls with suffix '64' */
78
+ #endif
79
+
80
+
81
+ #if (defined(DARWIN))
82
+ #define PREDEFINED_DISK_SECTOR_SIZE DEV_BSIZE
83
+ #else
84
+ #if (defined(FreeBSD) || defined(SunOS)) /*??? for SunOS*/
85
+ #define PREDEFINED_DISK_SECTOR_SIZE 512
86
+ #else
87
+ /* disk sector size should be obtained programmatically but if it could not
88
+ then predefined size (of 512 byts) will be used */
89
+ #define PREDEFINED_DISK_SECTOR_SIZE 512
90
+ #endif
91
+ #endif
92
+
93
+ #if (defined(__ppc__) || defined(__POWERPC__))
94
+ #define BIG_ENDIAN_ORDER
95
+ #endif
96
+
97
+ #if (defined(DARWIN) || defined(FreeBSD) || defined(__cygwin__))
98
+ /* don't have /proc */
99
+ #else
100
+ #define HAVE_PROC
101
+ #endif
102
+
103
+ #if(defined(FreeBSD) || defined(DARWIN))
104
+ /* don't have malloc.h */
105
+ #else
106
+ #define HAVE_MALLOC
107
+ #endif
108
+
109
+
110
+ #if (!defined(WIN32) && !defined(__cygwin__))
111
+ #if (defined(DARWIN) || defined(FreeBSD))
112
+ /* don't have /proc/?/exe */
113
+ #else
114
+ #define HAVE_PROC_EXE
115
+ #if (defined(LINUX))
116
+ #define PROC_EXE_SUFFIX "/exe"
117
+ #elif (defined(SunOS))
118
+ #define PROC_EXE_SUFFIX "/path/a.out"
119
+ #else
120
+ #error Define PROC_EXE_SUFFIX for your platform
121
+ #endif
122
+ #endif
123
+ #endif
124
+
125
+
126
+ // only for MSDEV 6.0
127
+ #if (_MSC_VER == 1200)
128
+ #define __SE_FUNCTION__ "<unknown>"
129
+ #else
130
+ #define __SE_FUNCTION__ __FUNCTION__
131
+ #endif
132
+
133
+ #ifdef _WIN32
134
+ #ifdef _MSC_VER
135
+ #define TLS_VAR_DECL __declspec(thread)
136
+ #else
137
+ #define TLS_VAR_DECL
138
+ #endif
139
+ #else
140
+ #define TLS_VAR_DECL
141
+ #endif
142
+
143
+
144
+ // It is better to use some proprietary declaration to not
145
+ // depend on external one which can be changed.
146
+ // EXTERN_C is defined in winnt.h.
147
+ // C_extern is defined in chicken.h
148
+ #ifndef SE_EXTERN_C
149
+ #ifdef __cplusplus
150
+ #define SE_EXTERN_C extern "C"
151
+ #else
152
+ #define SE_EXTERN_C
153
+ #endif
154
+ #endif
155
+
156
+ #define HAVE_STRINGIZE
157
+
158
+ #define ALIGNOF_SHORT 2
159
+ #define ALIGNOF_INT 4
160
+ #define ALIGNOF_LONG 4
161
+ #define ALIGNOF_DOUBLE 8
162
+ #define MAXIMUM_ALIGNOF 4
163
+
164
+
165
+
166
+ /*=============================================================================
167
+ * System File Includes Section
168
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169
+ *===========================================================================*/
170
+ #if (defined(_WIN32) && defined(__cplusplus))
171
+ /* To avod problems with dependencies generation on Cygwin environment */
172
+ #include <sstream>
173
+ #endif
174
+
175
+ #include <stdlib.h>
176
+ #include <stdio.h>
177
+ #include <string.h>
178
+ #include <stdarg.h>
179
+ #include <float.h>
180
+ #include <inttypes.h>
181
+ #include <limits.h>
182
+ #include <time.h>
183
+ #include <sys/types.h>
184
+ #include <sys/stat.h>
185
+ #include <errno.h>
186
+
187
+
188
+ #ifdef _WIN32
189
+ #include <windows.h>
190
+ #include <sys/timeb.h>
191
+ #else
192
+ #include <sys/ipc.h>
193
+ #include <sys/file.h>
194
+ #include <sys/param.h>
195
+ #include <sys/ioctl.h>
196
+ #include <sys/fcntl.h>
197
+ #include <sys/time.h>
198
+ #include <unistd.h>
199
+ #include <signal.h>
200
+
201
+ #ifndef __cygwin__
202
+
203
+ #endif
204
+
205
+ #include <setjmp.h>
206
+ #include <fcntl.h>
207
+ #include <math.h>
208
+ #endif /* _WIN32 */
209
+
210
+ /// In FreeBSD PAGE_SIZE definition can be injected from the <sys/params.h>
211
+ #if defined(FreeBSD) && defined(PAGE_SIZE)
212
+ #undef PAGE_SIZE
213
+ #endif
214
+
215
+ /*=============================================================================
216
+ * Types
217
+ * ~~~~~
218
+ *===========================================================================*/
219
+
220
+ /*
221
+ * signed integers types definition
222
+ */
223
+ #ifdef _WIN32
224
+ /*
225
+ * Already defined
226
+ */
227
+ #else
228
+ typedef int8_t __int8;
229
+ typedef int16_t __int16;
230
+ typedef int32_t __int32;
231
+ typedef int64_t __int64;
232
+ #endif
233
+
234
+
235
+ /*
236
+ * unsigned integers types definition
237
+ */
238
+ typedef uint8_t __uint8;
239
+ typedef uint16_t __uint16;
240
+ typedef uint32_t __uint32;
241
+ typedef uint64_t __uint64;
242
+
243
+ #ifdef _WIN32
244
+ /*
245
+ * Already defined
246
+ */
247
+
248
+ #else
249
+ #define _I64_MAX (((__int64)0x7FFFFFFF << 32) | 0xFFFFFFFF)
250
+ #define _I64_MIN (-_I64_MAX - 1)
251
+ #endif
252
+
253
+
254
+ /*
255
+ * usize_t
256
+ * Size of any memory resident object, as returned by sizeof
257
+ */
258
+ typedef size_t usize_t;
259
+
260
+
261
+ /*
262
+ * bool
263
+ * Boolean value, either true or false.
264
+ *
265
+ * for C++ compilers, we assume the compiler has a compatible
266
+ * built-in definition of bool
267
+ */
268
+ #ifndef __cplusplus
269
+
270
+ #ifndef bool
271
+ typedef char bool;
272
+ #endif
273
+
274
+ #ifndef true
275
+ #define true ((bool) 1)
276
+ #endif
277
+
278
+ #ifndef false
279
+ #define false ((bool) 0)
280
+ #endif
281
+ #endif /* not C++ */
282
+
283
+
284
+ /*
285
+ * global_name
286
+ * Interprocess name for IPC resources
287
+ */
288
+ typedef const char *global_name;
289
+
290
+ /*
291
+ * UHANDLE
292
+ * Handle (identifier) for resources
293
+ */
294
+ #ifdef _WIN32
295
+ typedef HANDLE UHANDLE;
296
+ #else
297
+ typedef int UHANDLE;
298
+ #endif /* _WIN32 */
299
+
300
+
301
+ /*
302
+ * LARGE_INTEGER
303
+ * Union for manipulating 64-bit integers as a whole or as 32-bit parts
304
+ */
305
+ #ifdef _WIN32
306
+ /*
307
+ * Already defined
308
+ */
309
+ #else
310
+ typedef union _LARGE_INTEGER
311
+ {
312
+ struct
313
+ {
314
+ unsigned long LowPart;
315
+ long HighPart;
316
+ };
317
+ struct
318
+ {
319
+ unsigned long LowPart;
320
+ long HighPart;
321
+ } u;
322
+ __int64 QuadPart;
323
+ } LARGE_INTEGER;
324
+ #endif /* _WIN32 */
325
+
326
+ #ifdef _WIN32
327
+ typedef DWORD UFlag;
328
+ #else
329
+ typedef int UFlag;
330
+ #endif
331
+
332
+
333
+ /*=============================================================================
334
+ * IsValid macros for system types
335
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336
+ *===========================================================================*/
337
+
338
+ /*
339
+ * BoolIsValid
340
+ * True iff bool is valid.
341
+ */
342
+ #define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
343
+
344
+ /*
345
+ * PointerIsValid
346
+ * True iff pointer is valid.
347
+ */
348
+ #define PointerIsValid(pointer) ((void*)(pointer) != NULL)
349
+
350
+ /*
351
+ * PointerIsAligned
352
+ * True iff pointer is properly aligned to point to the given type.
353
+ */
354
+ #define PointerIsAligned(pointer, type) \
355
+ (((long)(pointer) % (sizeof (type))) == 0)
356
+
357
+
358
+
359
+
360
+
361
+ /*=============================================================================
362
+ * Assert, Trap, etc. macros
363
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~
364
+ *===========================================================================*/
365
+
366
+ /*
367
+ * Trap
368
+ * Traps if the given condition is true
369
+ *
370
+ */
371
+ #define Trap(condition, errorType) \
372
+ do { \
373
+ if (condition) \
374
+ se_ExceptionalCondition(CppAsString(condition), (errorType), \
375
+ __FILE__, __LINE__); \
376
+ } while (0)
377
+
378
+ /*
379
+ * TrapMacro is the same as Trap but it's intended for use in macros:
380
+ *
381
+ * #define foo(x) (AssertMacro(x != 0) && bar(x))
382
+ *
383
+ * Isn't CPP fun?
384
+ */
385
+ #define TrapMacro(condition, errorType) \
386
+ ((bool) (!(condition) || \
387
+ (se_ExceptionalCondition(CppAsString(condition), (errorType), \
388
+ __FILE__, __LINE__))))
389
+
390
+ /*
391
+ * Define SE_ASSERT_CHECK if you want assert checking
392
+ */
393
+ #define SE_ASSERT_CHECK
394
+ /*
395
+ * Define SE_SLEEP_ON_ASSERT if you want a process to hang on on assert macro
396
+ */
397
+ #define SE_SLEEP_ON_ASSERT
398
+
399
+
400
+ #if (defined(SE_ASSERT_CHECK) && defined(EL_DEBUG) && (EL_DEBUG == 1))
401
+ #define U_ASSERT(condition) Trap(!(condition), "FailedAssertion")
402
+ #define U_ASSERT_MACRO(condition) ((void)TrapMacro(!(condition), "FailedAssertion"))
403
+ #else
404
+ #define U_ASSERT(condition)
405
+ #define U_ASSERT_MACRO(condition) ((void)true)
406
+ #endif /* defined(SE_ASSERT_CHECK) && defined(EL_DEBUG) && (EL_DEBUG == 1) */
407
+
408
+
409
+ SE_EXTERN_C
410
+ int se_ExceptionalCondition(const char *conditionName, const char *errorType,
411
+ const char *fileName, int lineNumber);
412
+
413
+
414
+
415
+
416
+ /*=============================================================================
417
+ * Other macros
418
+ * ~~~~~~~~~~~~
419
+ *===========================================================================*/
420
+
421
+ /*
422
+ * min/max macros definition
423
+ */
424
+ #define s_min(a, b) (((a) < (b)) ? (a) : (b))
425
+ #define s_max(a, b) (((a) > (b)) ? (a) : (b))
426
+
427
+
428
+ /*
429
+ * These constants define the maximum length in bytes for the path and
430
+ * for the individual fields within the path.
431
+ * U_MAX_PATH - Maximum length of full path
432
+ * U_MAX_DIR - Maximum length of directory component
433
+ * U_MAX_FNAME - Maximum length of filename component
434
+ */
435
+ #ifdef _WIN32
436
+ #define U_MAX_PATH _MAX_PATH
437
+ #define U_MAX_FNAME _MAX_FNAME
438
+ #define U_MAX_DIR _MAX_DIR
439
+ #else
440
+ #define U_MAX_PATH PATH_MAX
441
+ #define U_MAX_FNAME NAME_MAX
442
+ #define U_MAX_DIR NAME_MAX
443
+ #endif /* _WIN32 */
444
+
445
+ /*
446
+ * Designation of infinite value for some system calls
447
+ */
448
+ #ifdef _WIN32
449
+ #define U_INFINITE INFINITE
450
+ #else
451
+ #define U_INFINITE INT_MAX
452
+ #endif /* _WIN32 */
453
+
454
+
455
+ /*
456
+ * CppAsString
457
+ * Convert the argument to a string, using the C preprocessor
458
+ * CppConcat
459
+ * Concatenate two arguments together, using the C preprocessor
460
+ *
461
+ * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks
462
+ * whether #identifier works, but if we have that we likely have ## too
463
+ */
464
+ #if defined(HAVE_STRINGIZE)
465
+
466
+ #define CppAsString(identifier) #identifier
467
+ #define CppConcat(x, y) x##y
468
+ #else
469
+
470
+ #define CppAsString(identifier) "identifier"
471
+
472
+ /*
473
+ * CppIdentity -- On Reiser based cpp's this is used to concatenate
474
+ * two tokens. That is
475
+ * CppIdentity(A)B ==> AB
476
+ * We renamed it to _private_CppIdentity because it should not
477
+ * be referenced outside this file. On other cpp's it
478
+ * produces A B.
479
+ */
480
+ #define _priv_CppIdentity(x)x
481
+ #define CppConcat(x, y) _priv_CppIdentity(x)y
482
+ #endif /* HAVE_STRINGIZE */
483
+
484
+
485
+
486
+ /*
487
+ * Alignment macros: align a length or address appropriately for a given type.
488
+ *
489
+ * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2.
490
+ * That case seems extremely unlikely to occur in practice, however.
491
+ *
492
+ */
493
+ #define TYPEALIGN(ALIGNVAL,LEN) \
494
+ (((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))
495
+
496
+ #define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
497
+ #define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
498
+ #define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
499
+ #define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
500
+ #define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
501
+
502
+
503
+
504
+ /*
505
+ * StrNCpy
506
+ * Like standard library function strncpy(), except that result string
507
+ * is guaranteed to be null-terminated --- that is, at most N-1 bytes
508
+ * of the source string will be kept.
509
+ * Also, the macro returns no result (too hard to do that without
510
+ * evaluating the arguments multiple times, which seems worse).
511
+ *
512
+ * BTW: when you need to copy a non-null-terminated string (like a text
513
+ * datum) and add a null, do not do it with StrNCpy(..., len+1). That
514
+ * might seem to work, but it fetches one byte more than there is in the
515
+ * text object. One fine day you'll have a SIGSEGV because there isn't
516
+ * another byte before the end of memory. Don't laugh, we've had real
517
+ * live bug reports from real live users over exactly this mistake.
518
+ * Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead.
519
+ */
520
+ #define StrNCpy(dst,src,len) \
521
+ do \
522
+ { \
523
+ char * _dst = (dst); \
524
+ usize_t _len = (len); \
525
+ \
526
+ if (_len > 0) \
527
+ { \
528
+ strncpy(_dst, (src), _len); \
529
+ _dst[_len-1] = '\0'; \
530
+ } \
531
+ } while (0)
532
+
533
+
534
+ /* Get a bit mask of the bits set in non-int32 aligned addresses */
535
+ #define INT_ALIGN_MASK (sizeof(__int32) - 1)
536
+
537
+ /*
538
+ * MemSet
539
+ * Exactly the same as standard library function memset(), but considerably
540
+ * faster for zeroing small word-aligned structures (such as parsetree nodes).
541
+ * This has to be a macro because the main point is to avoid function-call
542
+ * overhead. However, we have also found that the loop is faster than
543
+ * native libc memset() on some platforms, even those with assembler
544
+ * memset() functions. More research needs to be done, perhaps with
545
+ * platform-specific MEMSET_LOOP_LIMIT values or tests in configure.
546
+ *
547
+ * bjm 2002-10-08
548
+ */
549
+ #define MemSet(start, val, len) \
550
+ do \
551
+ { \
552
+ /* must be void* because we don't know if it is integer aligned yet */ \
553
+ void *_vstart = (void *) (start); \
554
+ int _val = (val); \
555
+ usize_t _len = (len); \
556
+ \
557
+ if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \
558
+ (_len & INT_ALIGN_MASK) == 0 && \
559
+ _val == 0 && \
560
+ _len <= MEMSET_LOOP_LIMIT) \
561
+ { \
562
+ __int32 *_start = (__int32 *) _vstart; \
563
+ __int32 *_stop = (__int32 *) ((char *) _start + _len); \
564
+ while (_start < _stop) \
565
+ *_start++ = 0; \
566
+ } \
567
+ else \
568
+ memset(_vstart, _val, _len); \
569
+ } while (0)
570
+
571
+ #define MEMSET_LOOP_LIMIT 1024
572
+
573
+ /*
574
+ * MemSetAligned is the same as MemSet except it omits the test to see if
575
+ * "start" is word-aligned. This is okay to use if the caller knows a-priori
576
+ * that the pointer is suitably aligned (typically, because he just got it
577
+ * from palloc(), which always delivers a max-aligned pointer).
578
+ */
579
+ #define MemSetAligned(start, val, len) \
580
+ do \
581
+ { \
582
+ __int32 *_start = (__int32 *) (start); \
583
+ int _val = (val); \
584
+ usize_t _len = (len); \
585
+ \
586
+ if ((_len & INT_ALIGN_MASK) == 0 && \
587
+ _val == 0 && \
588
+ _len <= MEMSET_LOOP_LIMIT) \
589
+ { \
590
+ __int32 *_stop = (__int32 *) ((char *) _start + _len); \
591
+ while (_start < _stop) \
592
+ *_start++ = 0; \
593
+ } \
594
+ else \
595
+ memset(_start, _val, _len); \
596
+ } while (0)
597
+
598
+
599
+ /*
600
+ * MemSetTest/MemSetLoop are a variant version that allow all the tests in
601
+ * MemSet to be done at compile time in cases where "val" and "len" are
602
+ * constants *and* we know the "start" pointer must be word-aligned.
603
+ * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
604
+ * MemSetAligned. Beware of multiple evaluations of the arguments when using
605
+ * this approach.
606
+ */
607
+ #define MemSetTest(val, len) \
608
+ ( ((len) & INT_ALIGN_MASK) == 0 && \
609
+ (len) <= MEMSET_LOOP_LIMIT && \
610
+ (val) == 0 )
611
+
612
+ #define MemSetLoop(start, val, len) \
613
+ do \
614
+ { \
615
+ __int32 * _start = (__int32 *) (start); \
616
+ __int32 * _stop = (__int32 *) ((char *) _start + (usize_t) (len)); \
617
+ \
618
+ while (_start < _stop) \
619
+ *_start++ = 0; \
620
+ } while (0)
621
+
622
+
623
+ /*
624
+ * NaN, INF and -INF check functions
625
+ * Portability notes:
626
+ * 1. In Darwin isinf/isnan functions are not defined in C++ headers.
627
+ * At the moment we define C wrappers for them which can give a
628
+ * little runtime overhead though.
629
+ * 2. In FreeBSD isinf() returns 1 in both cases INF and -INF
630
+ * so we need to check value itself also.
631
+ */
632
+ #ifdef _WIN32
633
+ #define u_is_nan(d) (_isnan(d))
634
+ #define u_is_neg_inf(d) (_fpclass(d) == _FPCLASS_NINF)
635
+ #define u_is_pos_inf(d) (_fpclass(d) == _FPCLASS_PINF)
636
+ #else
637
+
638
+ #if defined(DARWIN)
639
+ SE_EXTERN_C int u_is_nan(double d);
640
+ #else
641
+ #define u_is_nan(d) (isnan(d))
642
+ #endif
643
+
644
+ #if defined(FreeBSD)
645
+ #define u_is_neg_inf(d) (isinf(d) && (d) < 0.0)
646
+ #define u_is_pos_inf(d) (isinf(d) && (d) > 0.0)
647
+ #elif defined(DARWIN)
648
+ SE_EXTERN_C bool u_is_neg_inf(double d);
649
+ SE_EXTERN_C bool u_is_pos_inf(double d);
650
+ #elif defined(SunOS)
651
+ #include <ieeefp.h>
652
+ #define u_is_neg_inf(d) (FP_NINF == fpclass(d))
653
+ #define u_is_pos_inf(d) (FP_PINF == fpclass(d))
654
+ #else /* Linux */
655
+ #define u_is_neg_inf(d) (isinf(d) == -1)
656
+ #define u_is_pos_inf(d) (isinf(d) == 1)
657
+ #endif
658
+ #endif
659
+
660
+
661
+
662
+
663
+ /*=============================================================================
664
+ * u-Calls Errors Handling
665
+ * ~~~~~~~~~~~~~~~~~~~~~~~
666
+ * sys_call_error - must be used inside u-function when it perfroms system
667
+ * call to write (e.g. using perror()) why it has been failed
668
+ * u_call_error - must be used inside u-function when it is going to return
669
+ * failed status. It allows additional error diagnostic to
670
+ * be logged.
671
+ *===========================================================================*/
672
+
673
+
674
+ #ifdef __cplusplus
675
+ extern "C" {
676
+ #endif
677
+
678
+ #define SYS_CALL_ERROR(FN, SYSCALL_STR) \
679
+ (((FN)?(FN):__sys_call_error_nop) \
680
+ (__FILE__,__LINE__,__SE_FUNCTION__, (SYSCALL_STR), NULL))
681
+
682
+ #define SYS_CALL_ERROR2(FN, SYSCALL_STR, PARAMS_STR) \
683
+ (((FN)?(FN):__sys_call_error_nop) \
684
+ (__FILE__,__LINE__,__SE_FUNCTION__, (SYSCALL_STR), (PARAMS_STR)))
685
+
686
+ #define sys_call_error(sys_call) (fun ? fun(__FILE__, __LINE__, __SE_FUNCTION__, sys_call, NULL) : (void)0)
687
+ #define sys_call_error2(sys_call, arg) (fun ? fun(__FILE__, __LINE__, __SE_FUNCTION__, sys_call, arg) : (void)0)
688
+
689
+ #define u_call_error(message) (fun ? __u_call_error(__FILE__, __LINE__, __SE_FUNCTION__, message) : (void)0)
690
+
691
+ typedef void (*sys_call_error_fun)(const char *filename, int lineno, const char *funcname, const char *sys_call, const void*);
692
+
693
+ char* ustrerror(int errnum);
694
+ int ustrerror_r(int errnum, char *buf, size_t n);
695
+ void uperror(const char *s);
696
+ void __sys_call_error(const char *filename, int lineno, const char *funcname, const char *sys_call, const void* arg);
697
+ void __sys_call_error_nop(const char *filename, int lineno, const char *funcname, const char *sys_call, const void* arg);
698
+ void __u_call_error(const char *filename, int lineno, const char *funcname, const char *message);
699
+
700
+
701
+ /*=============================================================================
702
+ * Common Functions
703
+ * ~~~~~~~~~~~~~~~~
704
+ *===========================================================================*/
705
+
706
+
707
+ void uSleep(unsigned int secs, sys_call_error_fun fun);
708
+ int uNotInheritDescriptor(UHANDLE h, sys_call_error_fun fun);
709
+ int uMakeLowLevelDescriptorNonInheritable(FILE* f, sys_call_error_fun fun);
710
+
711
+ #ifdef __cplusplus
712
+ }
713
+ #endif
714
+
715
+ #endif /* u.h */