sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,70 @@
|
|
1
|
+
/*
|
2
|
+
* File: memnodes.h
|
3
|
+
* Memory context node definitions.
|
4
|
+
*
|
5
|
+
* Portions Copyright (C) 2006 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
6
|
+
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
7
|
+
* Portions Copyright (c) 1994, Regents of the University of California
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
#ifndef MEMNODES_H
|
12
|
+
#define MEMNODES_H
|
13
|
+
|
14
|
+
#ifndef SE_MEMORY_TRACK
|
15
|
+
/*
|
16
|
+
* MemoryContext
|
17
|
+
* A logical context in which memory allocations occur.
|
18
|
+
*
|
19
|
+
* MemoryContext itself is an abstract type that can have multiple
|
20
|
+
* implementations, though for now we have only AllocSetContext.
|
21
|
+
* The function pointers in MemoryContextMethods define one specific
|
22
|
+
* implementation of MemoryContext --- they are a virtual function table
|
23
|
+
* in C++ terms.
|
24
|
+
*
|
25
|
+
* Node types that are actual implementations of memory contexts must
|
26
|
+
* begin with the same fields as MemoryContext.
|
27
|
+
*
|
28
|
+
* Note: for largely historical reasons, typedef MemoryContext is a pointer
|
29
|
+
* to the context struct rather than the struct type itself.
|
30
|
+
*/
|
31
|
+
|
32
|
+
typedef struct MemoryContextMethods
|
33
|
+
{
|
34
|
+
void *(*alloc) (MemoryContext context, usize_t size);
|
35
|
+
/* call this free_p in case someone #define's free() */
|
36
|
+
void (*free_p) (MemoryContext context, void *pointer);
|
37
|
+
void *(*realloc) (MemoryContext context, void *pointer, usize_t size);
|
38
|
+
void (*init) (MemoryContext context);
|
39
|
+
void (*reset) (MemoryContext context);
|
40
|
+
void (*del) (MemoryContext context);
|
41
|
+
usize_t (*get_chunk_space) (MemoryContext context, void *pointer);
|
42
|
+
bool (*is_empty) (MemoryContext context);
|
43
|
+
void (*stats) (MemoryContext context);
|
44
|
+
#ifdef MEMORY_CONTEXT_CHECKING
|
45
|
+
void (*check) (MemoryContext context);
|
46
|
+
#endif
|
47
|
+
} MemoryContextMethods;
|
48
|
+
|
49
|
+
|
50
|
+
typedef struct MemoryContextData
|
51
|
+
{
|
52
|
+
MemoryContextMethods *methods; /* virtual function table */
|
53
|
+
MemoryContext parent; /* NULL if no parent (toplevel context) */
|
54
|
+
MemoryContext firstchild; /* head of linked list of children */
|
55
|
+
MemoryContext nextchild; /* next child of same parent */
|
56
|
+
char *name; /* context name (just for debugging) */
|
57
|
+
} MemoryContextData;
|
58
|
+
|
59
|
+
/* se_alloc.h contains typedef struct MemoryContextData *MemoryContext */
|
60
|
+
|
61
|
+
|
62
|
+
/*
|
63
|
+
* MemoryContextIsValid
|
64
|
+
* True iff memory context is valid.
|
65
|
+
*/
|
66
|
+
#define MemoryContextIsValid(context) \
|
67
|
+
((context) != NULL)
|
68
|
+
|
69
|
+
#endif /* SE_MEMORY_TRACK */
|
70
|
+
#endif /* MEMNODES_H */
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/*
|
2
|
+
* File: memutils.h
|
3
|
+
* This file contains declarations for memory allocation utility
|
4
|
+
* functions. These are functions that are not quite widely used
|
5
|
+
* enough to justify going in se_alloc.h, but are still part
|
6
|
+
* of the API of the memory management subsystem.
|
7
|
+
*
|
8
|
+
* Portions Copyright (C) 2006 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
9
|
+
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
10
|
+
* Portions Copyright (c) 1994, Regents of the University of California
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
#ifndef MEMUTILS_H
|
14
|
+
#define MEMUTILS_H
|
15
|
+
|
16
|
+
#include "common/mmgr/memnodes.h"
|
17
|
+
|
18
|
+
#ifndef SE_MEMORY_TRACK
|
19
|
+
|
20
|
+
/*
|
21
|
+
* MaxAllocSize
|
22
|
+
* Quasi-arbitrary limit on size of allocations.
|
23
|
+
*
|
24
|
+
* Note:
|
25
|
+
* There is no guarantee that allocations smaller than MaxAllocSize
|
26
|
+
* will succeed. Allocation requests larger than MaxAllocSize will
|
27
|
+
* be summarily denied.
|
28
|
+
*
|
29
|
+
* XXX This is deliberately chosen to correspond to the limiting size
|
30
|
+
* of varlena objects under TOAST. See VARATT_MASK_SIZE in postgres.h.
|
31
|
+
*
|
32
|
+
* XXX Also, various places in aset.c assume they can compute twice an
|
33
|
+
* allocation's size without overflow, so beware of raising this.
|
34
|
+
*/
|
35
|
+
#define MaxAllocSize ((usize_t) 0x3fffffff) /* 1 gigabyte - 1 */
|
36
|
+
|
37
|
+
#define AllocSizeIsValid(size) ((usize_t) (size) <= MaxAllocSize)
|
38
|
+
|
39
|
+
/*
|
40
|
+
* All chunks allocated by any memory context manager are required to be
|
41
|
+
* preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE.
|
42
|
+
* A currently-allocated chunk must contain a backpointer to its owning
|
43
|
+
* context as well as the allocated size of the chunk. The backpointer is
|
44
|
+
* used by se_free() and se_realloc() to find the context to call. The allocated
|
45
|
+
* size is not absolutely essential, but it's expected to be needed by any
|
46
|
+
* reasonable implementation.
|
47
|
+
*/
|
48
|
+
typedef struct StandardChunkHeader
|
49
|
+
{
|
50
|
+
MemoryContext context; /* owning context */
|
51
|
+
usize_t size; /* size of data space allocated in chunk */
|
52
|
+
#ifdef MEMORY_CONTEXT_CHECKING
|
53
|
+
/* when debugging memory usage, also store actual requested size */
|
54
|
+
usize_t requested_size;
|
55
|
+
#endif
|
56
|
+
} StandardChunkHeader;
|
57
|
+
|
58
|
+
#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader))
|
59
|
+
|
60
|
+
|
61
|
+
#ifdef __cplusplus
|
62
|
+
extern "C" {
|
63
|
+
#endif
|
64
|
+
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Standard top-level memory contexts.
|
68
|
+
*
|
69
|
+
* Only TopMemoryContext and ErrorContext are initialized by
|
70
|
+
* MemoryContextInit() itself.
|
71
|
+
*/
|
72
|
+
extern MemoryContext TopMemoryContext;
|
73
|
+
extern MemoryContext ErrorContext;
|
74
|
+
|
75
|
+
extern MemoryContext TransactionContext;
|
76
|
+
extern MemoryContext UserStatementContext;
|
77
|
+
extern MemoryContext KernelStatementContext;
|
78
|
+
extern MemoryContext XQParserContext;
|
79
|
+
|
80
|
+
|
81
|
+
/*
|
82
|
+
* Memory-context-type-independent functions in mcxt.c
|
83
|
+
*/
|
84
|
+
extern void MemoryContextInit(void);
|
85
|
+
extern int SafeMemoryContextInit(void);
|
86
|
+
extern void MemoryContextReset(MemoryContext context);
|
87
|
+
extern void MemoryContextDelete(MemoryContext context);
|
88
|
+
extern void MemoryContextResetChildren(MemoryContext context);
|
89
|
+
extern void MemoryContextDeleteChildren(MemoryContext context);
|
90
|
+
extern void MemoryContextResetAndDeleteChildren(MemoryContext context);
|
91
|
+
extern usize_t GetMemoryChunkSpace(void *pointer);
|
92
|
+
extern MemoryContext GetMemoryChunkContext(void *pointer);
|
93
|
+
extern bool MemoryContextIsEmpty(MemoryContext context);
|
94
|
+
extern void MemoryContextStats(MemoryContext context);
|
95
|
+
|
96
|
+
#ifdef MEMORY_CONTEXT_CHECKING
|
97
|
+
extern void MemoryContextCheck(MemoryContext context);
|
98
|
+
#endif
|
99
|
+
extern bool MemoryContextContains(MemoryContext context, void *pointer);
|
100
|
+
|
101
|
+
/*
|
102
|
+
* This routine handles the context-type-independent part of memory
|
103
|
+
* context creation. It's intended to be called from context-type-
|
104
|
+
* specific creation routines, and noplace else.
|
105
|
+
*/
|
106
|
+
extern MemoryContext MemoryContextCreate(usize_t size,
|
107
|
+
MemoryContextMethods *methods,
|
108
|
+
MemoryContext parent,
|
109
|
+
const char *name);
|
110
|
+
|
111
|
+
|
112
|
+
/*
|
113
|
+
* Memory-context-type-specific functions
|
114
|
+
*/
|
115
|
+
|
116
|
+
/* aset.c */
|
117
|
+
extern MemoryContext AllocSetContextCreate(MemoryContext parent,
|
118
|
+
const char *name,
|
119
|
+
usize_t minContextSize,
|
120
|
+
usize_t initBlockSize,
|
121
|
+
usize_t maxBlockSize);
|
122
|
+
|
123
|
+
#ifdef __cplusplus
|
124
|
+
}
|
125
|
+
#endif
|
126
|
+
|
127
|
+
/*
|
128
|
+
* Recommended default alloc parameters, suitable for "ordinary" contexts
|
129
|
+
* that might hold quite a lot of data.
|
130
|
+
*/
|
131
|
+
#define ALLOCSET_DEFAULT_MINSIZE 0
|
132
|
+
#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024)
|
133
|
+
#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024)
|
134
|
+
|
135
|
+
/*
|
136
|
+
* Recommended alloc parameters for "small" contexts that are not expected
|
137
|
+
* to contain much data (for example, a context to contain a query plan).
|
138
|
+
*/
|
139
|
+
#define ALLOCSET_SMALL_MINSIZE 0
|
140
|
+
#define ALLOCSET_SMALL_INITSIZE (1 * 1024)
|
141
|
+
#define ALLOCSET_SMALL_MAXSIZE (8 * 1024)
|
142
|
+
|
143
|
+
#endif /* SE_MEMORY_TRACK */
|
144
|
+
|
145
|
+
#endif /* MEMUTILS_H */
|
@@ -0,0 +1,321 @@
|
|
1
|
+
/*
|
2
|
+
* File: se_alloc.h
|
3
|
+
* Memory allocator definitions.
|
4
|
+
*
|
5
|
+
* Portions Copyright (C) 2006 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
6
|
+
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
7
|
+
* Portions Copyright (c) 1994, Regents of the University of California
|
8
|
+
*
|
9
|
+
* This file contains the basic memory allocation interface that is
|
10
|
+
* needed by almost every module. Keep it lean!
|
11
|
+
*
|
12
|
+
* Memory allocation occurs within "contexts". Every chunk obtained from
|
13
|
+
* se_alloc()/MemoryContextAlloc() is allocated within a specific context.
|
14
|
+
* The entire contents of a context can be freed easily and quickly by
|
15
|
+
* resetting or deleting the context --- this is both faster and less
|
16
|
+
* prone to memory-leakage bugs than releasing chunks individually.
|
17
|
+
* We organize contexts into context trees to allow fine-grain control
|
18
|
+
* over chunk lifetime while preserving the certainty that we will free
|
19
|
+
* everything that should be freed. See utils/mmgr/README for more info.
|
20
|
+
*
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef SE_ALLOC_H
|
24
|
+
#define SE_ALLOC_H
|
25
|
+
|
26
|
+
/// #define SE_MEMORY_MNG
|
27
|
+
/// #define SE_MEMORY_TRACK
|
28
|
+
|
29
|
+
#ifdef SE_MEMORY_TRACK
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
extern "C" {
|
33
|
+
#endif
|
34
|
+
|
35
|
+
extern char MT_SEDNA_DATA[];
|
36
|
+
extern void *track_malloc(usize_t size, const char* file, int line, const char* flag);
|
37
|
+
extern void track_free(void *pointer);
|
38
|
+
extern void *track_realloc(void *pointer, usize_t size, const char* file, int line, const char* flag);
|
39
|
+
extern void *track_calloc(usize_t num, usize_t size, const char* file, int line, const char* flag);
|
40
|
+
extern char *track_strdup(const char *source, const char* file, int line, const char* flag);
|
41
|
+
extern void DumpUnfreed(int component);
|
42
|
+
|
43
|
+
#ifdef __cplusplus
|
44
|
+
}
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#ifdef __cplusplus
|
48
|
+
|
49
|
+
inline void *operator new(usize_t size, const char *file, int line, const char* flag)
|
50
|
+
{
|
51
|
+
return track_malloc(size, file, line, flag);
|
52
|
+
}
|
53
|
+
inline void operator delete(void* p, const char *file, int line, const char* flag)
|
54
|
+
{
|
55
|
+
track_free(p);
|
56
|
+
}
|
57
|
+
inline void operator delete(void* p)
|
58
|
+
{
|
59
|
+
track_free(p);
|
60
|
+
}
|
61
|
+
inline void *operator new[](usize_t size, const char *file, int line, const char* flag)
|
62
|
+
{
|
63
|
+
return track_malloc(size, file, line, flag);
|
64
|
+
}
|
65
|
+
inline void operator delete[](void* p, const char *file, int line, const char* flag)
|
66
|
+
{
|
67
|
+
track_free(p);
|
68
|
+
}
|
69
|
+
inline void operator delete[](void* p)
|
70
|
+
{
|
71
|
+
track_free(p);
|
72
|
+
}
|
73
|
+
|
74
|
+
#define se_new new(__FILE__, __LINE__, "SE_NEW")
|
75
|
+
#define se_new_cxt(cxt) new(__FILE__, __LINE__, "SE_NEW_CXT")
|
76
|
+
|
77
|
+
#endif
|
78
|
+
|
79
|
+
#define se_delete(p) delete(p)
|
80
|
+
#define se_free(p) track_free(p)
|
81
|
+
#define se_alloc(size) track_malloc(size, __FILE__, __LINE__, "SE_ALLOC")
|
82
|
+
#define se_realloc(pointer, size) track_realloc(pointer, size, __FILE__, __LINE__, "SE_REALLOC")
|
83
|
+
|
84
|
+
#define malloc(size) track_malloc(size, __FILE__, __LINE__, "MALLOC")
|
85
|
+
#define free(pointer) track_free(pointer)
|
86
|
+
#define realloc(pointer, size) track_realloc(pointer, size, __FILE__, __LINE__, "REALLOC")
|
87
|
+
#define calloc(num, size) track_calloc(num, size, __FILE__, __LINE__, "CALLOC")
|
88
|
+
#define strdup(source) track_strdup(source, __FILE__, __LINE__, "STRDUP")
|
89
|
+
|
90
|
+
#else /* SE_MEMORY_TRACK */
|
91
|
+
|
92
|
+
#ifdef __cplusplus
|
93
|
+
extern "C" {
|
94
|
+
#endif
|
95
|
+
|
96
|
+
/*
|
97
|
+
* Type MemoryContextData is declared in nodes/memnodes.h. Most users
|
98
|
+
* of memory allocation should just treat it as an abstract type, so we
|
99
|
+
* do not provide the struct contents here.
|
100
|
+
*/
|
101
|
+
typedef struct MemoryContextData *MemoryContext;
|
102
|
+
|
103
|
+
/*
|
104
|
+
* CurrentMemoryContext is the default allocation context for se_alloc().
|
105
|
+
* We declare it here so that se_alloc() can be a macro. Avoid accessing it
|
106
|
+
* directly! Instead, use MemoryContextSwitchTo() to change the setting.
|
107
|
+
*/
|
108
|
+
extern MemoryContext CurrentMemoryContext;
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Fundamental memory-allocation operations (more are in utils/memutils.h)
|
112
|
+
*/
|
113
|
+
extern void *MemoryContextAlloc(MemoryContext context, usize_t size);
|
114
|
+
extern void *MemoryContextAllocZero(MemoryContext context, usize_t size);
|
115
|
+
extern void *MemoryContextAllocZeroAligned(MemoryContext context, usize_t size);
|
116
|
+
|
117
|
+
#ifdef SE_MEMORY_MNG
|
118
|
+
#define se_alloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
|
119
|
+
|
120
|
+
#define se_alloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
|
121
|
+
#else
|
122
|
+
#define se_alloc malloc
|
123
|
+
#endif
|
124
|
+
|
125
|
+
/*
|
126
|
+
* The result of se_alloc() is always word-aligned, so we can skip testing
|
127
|
+
* alignment of the pointer when deciding which MemSet variant to use.
|
128
|
+
* Note that this variant does not offer any advantage, and should not be
|
129
|
+
* used, unless its "sz" argument is a compile-time constant; therefore, the
|
130
|
+
* issue that it evaluates the argument multiple times isn't a problem in
|
131
|
+
* practice.
|
132
|
+
*/
|
133
|
+
#ifdef SE_MEMORY_MNG
|
134
|
+
#define se_alloc0fast(sz) \
|
135
|
+
( MemSetTest(0, sz) ? \
|
136
|
+
MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
|
137
|
+
MemoryContextAllocZero(CurrentMemoryContext, sz) )
|
138
|
+
#endif
|
139
|
+
|
140
|
+
|
141
|
+
extern void se_free(void *pointer);
|
142
|
+
|
143
|
+
extern void *se_realloc(void *pointer, usize_t size);
|
144
|
+
|
145
|
+
/*
|
146
|
+
* MemoryContextSwitchTo can't be a macro in standard C compilers.
|
147
|
+
* But we can make it an inline function when using GCC.
|
148
|
+
*/
|
149
|
+
#ifdef __GNUC__
|
150
|
+
static __inline__ MemoryContext
|
151
|
+
MemoryContextSwitchTo(MemoryContext context)
|
152
|
+
{
|
153
|
+
MemoryContext old = CurrentMemoryContext;
|
154
|
+
|
155
|
+
CurrentMemoryContext = context;
|
156
|
+
return old;
|
157
|
+
}
|
158
|
+
#else
|
159
|
+
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
|
160
|
+
#endif /* __GNUC__ */
|
161
|
+
|
162
|
+
/*
|
163
|
+
* These are like standard strdup() except the copied string is
|
164
|
+
* allocated in a context, not with malloc().
|
165
|
+
*/
|
166
|
+
extern char *MemoryContextStrdup(MemoryContext context, const char *string);
|
167
|
+
|
168
|
+
#ifdef SE_MEMORY_MNG
|
169
|
+
#define se_strdup(str) MemoryContextStrdup(CurrentMemoryContext, (str))
|
170
|
+
#else
|
171
|
+
#define se_strdup strdup
|
172
|
+
#endif
|
173
|
+
|
174
|
+
#ifdef __cplusplus
|
175
|
+
}
|
176
|
+
#endif
|
177
|
+
|
178
|
+
|
179
|
+
#ifdef __cplusplus
|
180
|
+
|
181
|
+
/*
|
182
|
+
* AF:
|
183
|
+
* We can overload global new and global delete to use our Context
|
184
|
+
* memory allocation routines. But for this moment we prefer not to
|
185
|
+
* do that but rather to define placement new and placement delete
|
186
|
+
* (with parameter MemoryContext). Placement delete is implemented
|
187
|
+
* by the template function se_destroy, which calls destructor
|
188
|
+
* explicitly.
|
189
|
+
* To conclude, STL routines are using default new and delete operators
|
190
|
+
* (we can count on them that they do not have memory leaks). For
|
191
|
+
* Sedna code we should use se_new and se_new_cxt macroses to allocate
|
192
|
+
* memory and se_delete to deallocate memory. Note that se_new and
|
193
|
+
* se_new_cxt call constructor and se_delete calls destructor correctly.
|
194
|
+
* Note that we still could call global new and delete operators
|
195
|
+
* that are not overloaded.
|
196
|
+
*
|
197
|
+
* Example:
|
198
|
+
* A *a = NULL;
|
199
|
+
* int *i = NULL;
|
200
|
+
*
|
201
|
+
* // our new operator in CurrentMemoryContext
|
202
|
+
* a = se_new A(some_parameters ...);
|
203
|
+
* se_delete(a); // destructor will be called
|
204
|
+
*
|
205
|
+
* // our new operator in TopMemoryContext
|
206
|
+
* a = se_new_cxt(TopMemoryContext) A(some_parameters ...);
|
207
|
+
* se_delete(a); // destructor will be called
|
208
|
+
*
|
209
|
+
* // Simple types are also supported correctly
|
210
|
+
* i = se_new int;
|
211
|
+
* se_delete(i);
|
212
|
+
*/
|
213
|
+
|
214
|
+
/* !!! Uncomment this if you want to replace global new and global
|
215
|
+
delete.
|
216
|
+
|
217
|
+
inline void *operator new(usize_t size)
|
218
|
+
{
|
219
|
+
return operator_new_global(size);
|
220
|
+
}
|
221
|
+
|
222
|
+
inline void operator delete(void* p)
|
223
|
+
{
|
224
|
+
if (p) se_free(p);
|
225
|
+
}
|
226
|
+
|
227
|
+
inline void *operator new[](usize_t size)
|
228
|
+
{
|
229
|
+
return operator_new_global(size);
|
230
|
+
}
|
231
|
+
|
232
|
+
inline void operator delete[](void* p)
|
233
|
+
{
|
234
|
+
if (p) se_free(p);
|
235
|
+
}
|
236
|
+
*/
|
237
|
+
|
238
|
+
/*
|
239
|
+
* Inline new and delete operators rely on these definitions.
|
240
|
+
*
|
241
|
+
*/
|
242
|
+
extern "C" int SafeMemoryContextInit(void);
|
243
|
+
extern "C" MemoryContext TopMemoryContext;
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
inline void *operator new(usize_t size, MemoryContext context)
|
248
|
+
{
|
249
|
+
#ifdef SE_MEMORY_MNG
|
250
|
+
if (SafeMemoryContextInit()) context = TopMemoryContext;
|
251
|
+
return MemoryContextAlloc(context, size);
|
252
|
+
#else
|
253
|
+
return malloc(size);
|
254
|
+
#endif
|
255
|
+
}
|
256
|
+
|
257
|
+
inline void operator delete(void* p, MemoryContext context)
|
258
|
+
{
|
259
|
+
#ifdef SE_MEMORY_MNG
|
260
|
+
if (p) se_free(p);
|
261
|
+
#else
|
262
|
+
if (p) free(p);
|
263
|
+
#endif
|
264
|
+
}
|
265
|
+
|
266
|
+
inline void *operator new[](usize_t size, MemoryContext context)
|
267
|
+
{
|
268
|
+
#ifdef SE_MEMORY_MNG
|
269
|
+
if (SafeMemoryContextInit()) context = TopMemoryContext;
|
270
|
+
return MemoryContextAlloc(context, size);
|
271
|
+
#else
|
272
|
+
return malloc(size);
|
273
|
+
#endif
|
274
|
+
}
|
275
|
+
|
276
|
+
inline void operator delete[](void* p, MemoryContext context)
|
277
|
+
{
|
278
|
+
#ifdef SE_MEMORY_MNG
|
279
|
+
if (p) se_free(p);
|
280
|
+
#else
|
281
|
+
if (p) free(p);
|
282
|
+
#endif
|
283
|
+
}
|
284
|
+
|
285
|
+
template<class T> void __se_delete(T* p, MemoryContext context)
|
286
|
+
{
|
287
|
+
if (p)
|
288
|
+
{
|
289
|
+
p->~T();
|
290
|
+
#ifdef SE_MEMORY_MNG
|
291
|
+
se_free(p);
|
292
|
+
#else
|
293
|
+
free(p);
|
294
|
+
#endif
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
// FIXME: remove this when Sedna memory manager will be ready (AF)
|
299
|
+
#ifdef SE_MEMORY_MNG
|
300
|
+
inline void operator delete(void* p)
|
301
|
+
{
|
302
|
+
}
|
303
|
+
inline void operator delete[](void* p)
|
304
|
+
{
|
305
|
+
}
|
306
|
+
#endif
|
307
|
+
|
308
|
+
|
309
|
+
#ifdef SE_MEMORY_MNG
|
310
|
+
#define se_new new(CurrentMemoryContext)
|
311
|
+
#define se_new_cxt(cxt) new(cxt)
|
312
|
+
#define se_delete(p) __se_delete(p, NULL)
|
313
|
+
#else
|
314
|
+
#define se_new new
|
315
|
+
#define se_new_cxt(cxt) new
|
316
|
+
#define se_delete(p) delete(p);
|
317
|
+
#endif
|
318
|
+
|
319
|
+
#endif /* __cplusplus__ */
|
320
|
+
#endif /* SE_MEMORY_TRACK */
|
321
|
+
#endif /* SE_ALLOC_H */
|