vsql-node 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +203 -2
  3. package/binding.gyp +61 -0
  4. package/index.d.ts +133 -0
  5. package/internal/amalgamation/LICENSE +21 -0
  6. package/internal/amalgamation/LICENSE-V +21 -0
  7. package/internal/amalgamation/afunix.h +26 -0
  8. package/internal/amalgamation/atomic.h +571 -0
  9. package/internal/amalgamation/core_windows.c +25 -0
  10. package/internal/amalgamation/core_windows.h +9 -0
  11. package/internal/amalgamation/execute_capture_nix.c +7 -0
  12. package/internal/amalgamation/execute_capture_nix.h +266 -0
  13. package/internal/amalgamation/gc/cord.h +426 -0
  14. package/internal/amalgamation/gc/cord_pos.h +151 -0
  15. package/internal/amalgamation/gc/ec.h +91 -0
  16. package/internal/amalgamation/gc/gc.h +2826 -0
  17. package/internal/amalgamation/gc/gc_allocator.h +480 -0
  18. package/internal/amalgamation/gc/gc_backptr.h +109 -0
  19. package/internal/amalgamation/gc/gc_config_macros.h +548 -0
  20. package/internal/amalgamation/gc/gc_disclaim.h +85 -0
  21. package/internal/amalgamation/gc/gc_gcj.h +123 -0
  22. package/internal/amalgamation/gc/gc_inline.h +261 -0
  23. package/internal/amalgamation/gc/gc_mark.h +516 -0
  24. package/internal/amalgamation/gc/gc_pthread_redirects.h +140 -0
  25. package/internal/amalgamation/gc/gc_tiny_fl.h +107 -0
  26. package/internal/amalgamation/gc/gc_typed.h +196 -0
  27. package/internal/amalgamation/gc/gc_version.h +55 -0
  28. package/internal/amalgamation/gc/javaxfc.h +76 -0
  29. package/internal/amalgamation/gc/leak_detector.h +120 -0
  30. package/internal/amalgamation/gc.c +45932 -0
  31. package/internal/amalgamation/gc.h +4 -0
  32. package/internal/amalgamation/gc_boehm_helpers.c +64 -0
  33. package/internal/amalgamation/gc_debugger_linux.h +61 -0
  34. package/internal/amalgamation/getrandom_linux.h +33 -0
  35. package/internal/amalgamation/ipv6_v6only.h +5 -0
  36. package/internal/amalgamation/libvsql.c +27 -0
  37. package/internal/amalgamation/libvsql.h +1772 -0
  38. package/internal/amalgamation/libvsql_linux_amd64.c +106591 -0
  39. package/internal/amalgamation/libvsql_linux_arm64.c +106571 -0
  40. package/internal/amalgamation/libvsql_macos_amd64.c +106728 -0
  41. package/internal/amalgamation/libvsql_macos_arm64.c +106708 -0
  42. package/internal/amalgamation/libvsql_windows_amd64.c +108235 -0
  43. package/internal/amalgamation/segfault_handler_nix.c +56 -0
  44. package/internal/amalgamation/segfault_handler_nix.h +449 -0
  45. package/internal/amalgamation/segfault_handler_windows.h +52 -0
  46. package/internal/amalgamation/thread_helper.c +12 -0
  47. package/internal/amalgamation/thread_helper.h +96 -0
  48. package/internal/amalgamation/ticks_windows.c +3 -0
  49. package/internal/amalgamation/ticks_windows.h +31 -0
  50. package/internal/amalgamation/ticks_windows_api.h +6 -0
  51. package/internal/amalgamation/vsql_runtime.c +14 -0
  52. package/internal/amalgamation/vsql_runtime_linux.c +6 -0
  53. package/internal/amalgamation/vsql_runtime_macos.c +6 -0
  54. package/internal/amalgamation/vsql_runtime_windows.c +6 -0
  55. package/lib/binding.js +13 -0
  56. package/lib/connection.js +492 -0
  57. package/lib/convert.js +213 -0
  58. package/lib/errors.js +17 -0
  59. package/lib/index.js +41 -0
  60. package/libvsql_flags.gypi +30 -0
  61. package/package.json +45 -4
  62. package/prebuilds/darwin-arm64/vsql-node.glibc.node +0 -0
  63. package/prebuilds/darwin-x64/vsql-node.glibc.node +0 -0
  64. package/prebuilds/linux-arm64/vsql-node.glibc.node +0 -0
  65. package/prebuilds/linux-x64/vsql-node.glibc.node +0 -0
  66. package/prebuilds/win32-x64/vsql-node.glibc.node +0 -0
  67. package/src/binding.c +773 -0
  68. package/src/runtime.c +20 -0
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright (c) 1999-2005 Hewlett-Packard Development Company, L.P.
3
+ *
4
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6
+ *
7
+ * Permission is hereby granted to use or copy this program
8
+ * for any purpose, provided the above notices are retained on all copies.
9
+ * Permission to modify the code and to distribute modified code is granted,
10
+ * provided the above notices are retained, and a notice that the code was
11
+ * modified is included with the above copyright notice.
12
+ */
13
+
14
+ #ifndef GC_TINY_FL_H
15
+ #define GC_TINY_FL_H
16
+
17
+ /*
18
+ * Constants and data structures for "tiny" free lists.
19
+ * These are used for thread-local allocation and inlined allocators.
20
+ * Each global free list also essentially starts with one of these.
21
+ * However, global free lists are known to the collector.
22
+ * "Tiny" free lists are basically private to the client.
23
+ * Their contents are viewed as "in use" and marked accordingly by the
24
+ * core of the collector. Note that inlined code might know about the
25
+ * layout of these and the constants involved. Thus any change here
26
+ * may invalidate clients, and such changes should be avoided.
27
+ * Hence we keep this as simple as possible.
28
+ */
29
+
30
+ /*
31
+ * We always set `GC_GRANULE_BYTES` to twice the length of a pointer.
32
+ * This means that all allocation requests are rounded up to the next
33
+ * multiple of 16 on 64-bit architectures or 8 on 32-bit architectures.
34
+ * This appears to be a reasonable compromise between fragmentation
35
+ * overhead and space usage for mark bits (usually mark bytes).
36
+ * On many 64-bit architectures some memory references require 16-byte
37
+ * alignment, making this necessary anyway. For a few 32-bit
38
+ * architectures (e.g. i686), we may also need 16-byte alignment for
39
+ * certain memory references. But currently that does not seem to be
40
+ * the default for all conventional `malloc` implementations, so we
41
+ * ignore that problem.
42
+ * It would always be safe, and often useful, to be able to allocate
43
+ * very small objects with smaller alignment. But that would cost us
44
+ * mark bit space, so we no longer do so.
45
+ * `GC_GRANULE_BYTES` should not be overridden in any instances of the
46
+ * collector library that may be shared between applications, since it
47
+ * affects the ABI (application binary interface) to the library.
48
+ */
49
+ #if defined(CPPCHECK) && GC_GRANULE_BYTES == 1
50
+ # undef GC_GRANULE_BYTES
51
+ #endif
52
+ #ifdef GC_GRANULE_BYTES
53
+ # define GC_GRANULE_PTRS (GC_GRANULE_BYTES / GC_SIZEOF_PTR)
54
+ #else
55
+ # define GC_GRANULE_PTRS 2 /*< in pointers */
56
+ # define GC_GRANULE_BYTES (GC_GRANULE_PTRS * GC_SIZEOF_PTR)
57
+ #endif /* !GC_GRANULE_BYTES */
58
+
59
+ /** Convert size in pointers to that in granules. */
60
+ #define GC_PTRS_TO_GRANULES(n) ((n) / GC_GRANULE_PTRS)
61
+
62
+ /**
63
+ * Convert size in pointers to that in granules, but rounding up the
64
+ * result.
65
+ */
66
+ #define GC_PTRS_TO_WHOLE_GRANULES(n) \
67
+ GC_PTRS_TO_GRANULES((n) + GC_GRANULE_PTRS - 1)
68
+
69
+ /*
70
+ * A "tiny" free-list header contains `GC_TINY_FREELISTS` pointers to
71
+ * singly-linked lists of objects of different sizes, the `i`-th one
72
+ * containing objects of `i` granules in size. Note that there is
73
+ * a list of size zero objects.
74
+ */
75
+ #ifndef GC_TINY_FREELISTS
76
+ # if GC_GRANULE_BYTES >= 16
77
+ # define GC_TINY_FREELISTS 25
78
+ # else
79
+ # define GC_TINY_FREELISTS 33 /*< up to and including 256 bytes */
80
+ # endif
81
+ #endif /* !GC_TINY_FREELISTS */
82
+
83
+ /*
84
+ * The `i`-th free list corresponds to size `i * GC_GRANULE_BYTES`.
85
+ * Internally to the collector, the index `i` can be computed with
86
+ * `ALLOC_REQUEST_GRANS()`. The latter also depends on the values
87
+ * returned by `GC_get_dont_add_byte_at_end()` and
88
+ * `GC_get_all_interior_pointers()`.
89
+ */
90
+
91
+ /**
92
+ * Convert a free-list index to the actual size of objects on that list,
93
+ * including extra space we added. Not an inverse of the above.
94
+ */
95
+ #define GC_RAW_BYTES_FROM_INDEX(i) (GC_GRANULE_BYTES * (i))
96
+
97
+ /* Deprecated. Use `GC_GRANULE_PTRS` instead. */
98
+ #undef GC_GRANULE_WORDS
99
+ #define GC_GRANULE_WORDS GC_GRANULE_PTRS
100
+
101
+ /* Deprecated. Use `GC_PTRS_TO_GRANULES()` instead. */
102
+ #define GC_WORDS_TO_GRANULES(n) GC_PTRS_TO_GRANULES(n)
103
+
104
+ /* Deprecated. */
105
+ #define GC_WORDS_TO_WHOLE_GRANULES(n) GC_PTRS_TO_WHOLE_GRANULES(n)
106
+
107
+ #endif /* GC_TINY_FL_H */
@@ -0,0 +1,196 @@
1
+ /*
2
+ * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3
+ * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4
+ * Copyright 1996 Silicon Graphics. All rights reserved.
5
+ *
6
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
7
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8
+ *
9
+ * Permission is hereby granted to use or copy this program
10
+ * for any purpose, provided the above notices are retained on all copies.
11
+ * Permission to modify the code and to distribute modified code is granted,
12
+ * provided the above notices are retained, and a notice that the code was
13
+ * modified is included with the above copyright notice.
14
+ */
15
+
16
+ /*
17
+ * Some simple primitives for allocation with explicit type information.
18
+ * Facilities for dynamic type inference may be added later.
19
+ * Should be used only for extremely performance critical applications,
20
+ * or if conservative collector leakage is otherwise a problem (unlikely).
21
+ * Note that this is implemented completely separately from the rest
22
+ * of the collector, and is not linked in unless referenced.
23
+ * This does not currently support `GC_DEBUG` in any interesting way.
24
+ *
25
+ * Note for cris and m68k architectures (and for bcc and wcc compilers):
26
+ * this API expects all pointers in the type (`T`) are aligned by the size
27
+ * of a pointer (which might differ from `ALIGNMENT`).
28
+ */
29
+
30
+ #ifndef GC_TYPED_H
31
+ #define GC_TYPED_H
32
+
33
+ #ifndef GC_H
34
+ # include "gc.h"
35
+ #endif
36
+
37
+ #ifdef __cplusplus
38
+ extern "C" {
39
+ #endif
40
+
41
+ /** The size of `GC_word` (not a pointer) type in bits. */
42
+ #define GC_WORDSZ (8 * sizeof(GC_word))
43
+
44
+ /** The size of a type `t` in pointers. The value is rounded down. */
45
+ #define GC_SIZEOF_IN_PTRS(t) (sizeof(t) / sizeof(void *))
46
+
47
+ /** The offset of a field in pointers. */
48
+ #define GC_OFFSETOF_IN_PTRS(t, f) (offsetof(t, f) / sizeof(void *))
49
+
50
+ /**
51
+ * The bitmap type. The least significant bit of the first `GC_word` is one
52
+ * if the first "pointer-sized" word in the object may be a pointer.
53
+ */
54
+ typedef GC_word *GC_bitmap;
55
+
56
+ /**
57
+ * The number of elements (of `GC_word` type) of a bitmap array to
58
+ * create for a given type `t`. The bitmap is intended to be passed to
59
+ * `GC_make_descriptor()`.
60
+ */
61
+ #define GC_BITMAP_SIZE(t) ((GC_SIZEOF_IN_PTRS(t) + GC_WORDSZ - 1) / GC_WORDSZ)
62
+
63
+ /**
64
+ * The setter and getter of the bitmap. The `bm` argument should be of
65
+ * `GC_bitmap` type; `i` argument should be of some `unsigned` type and
66
+ * should not have side effects.
67
+ */
68
+ #define GC_set_bit(bm, i) \
69
+ ((bm)[(i) / GC_WORDSZ] |= (GC_word)1 << ((i) % GC_WORDSZ))
70
+ #define GC_get_bit(bm, i) (((bm)[(i) / GC_WORDSZ] >> ((i) % GC_WORDSZ)) & 1)
71
+
72
+ typedef GC_word GC_descr;
73
+
74
+ /**
75
+ * Return a type descriptor for the object whose layout is described
76
+ * by the first argument. The least significant bit of the first
77
+ * `GC_word` is one if the first "pointer-sized" word in the object may
78
+ * be a pointer. The second argument (`number_of_bits_in_bitmap`)
79
+ * specifies the number of meaningful bits in the bitmap.
80
+ * The actual object may be larger (but not smaller); any additional
81
+ * "pointer-sized" words in the object are assumed not to contain
82
+ * pointers. Returns a conservative approximation in the (unlikely)
83
+ * case of insufficient memory to build the descriptor. Calls to
84
+ * `GC_make_descriptor()` may consume some amount of a finite resource.
85
+ * This is intended to be called once per a type, not once per an
86
+ * allocation.
87
+ *
88
+ * It is possible to generate a descriptor for a client type `T` with
89
+ * aligned pointer fields `f1`, `f2`, ... as follows:
90
+ * ```
91
+ * GC_descr t_descr;
92
+ * {
93
+ * GC_word bm[GC_BITMAP_SIZE(T)] = { 0 };
94
+ * GC_set_bit(bm, GC_OFFSETOF_IN_PTRS(T, f1));
95
+ * GC_set_bit(bm, GC_OFFSETOF_IN_PTRS(T, f2));
96
+ * ...
97
+ * t_descr = GC_make_descriptor(bm, GC_SIZEOF_IN_PTRS(T));
98
+ * }
99
+ * ```
100
+ */
101
+ GC_API GC_descr GC_CALL
102
+ GC_make_descriptor(const GC_word * /* `GC_bitmap` `bm` */,
103
+ size_t /* `number_of_bits_in_bitmap` */);
104
+
105
+ /**
106
+ * Allocate an object whose layout is described by `d`. The size
107
+ * (`size_in_bytes`) may *not* be less than the number of meaningful
108
+ * bits in the bitmap of `d` multiplied by the size of a pointer.
109
+ * The returned object is cleared. The returned object may *not* be
110
+ * passed to `GC_realloc()`.
111
+ */
112
+ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
113
+ GC_malloc_explicitly_typed(size_t /* `size_in_bytes` */,
114
+ GC_descr /* `d` */);
115
+
116
+ /** The ignore-off-page variant of `GC_malloc_explicitly_typed()`. */
117
+ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
118
+ GC_malloc_explicitly_typed_ignore_off_page(size_t /* `size_in_bytes` */,
119
+ GC_descr /* `d` */);
120
+
121
+ /**
122
+ * Allocate an array of `nelements` elements, each of the given size
123
+ * (`element_size_in_bytes`), and with the given descriptor (`d`).
124
+ * The element size must be a multiple of the byte alignment required
125
+ * for pointers. (E.g. on a 32-bit machine with 16-bit aligned
126
+ * pointers, `element_size_in_bytes` must be a multiple of 2.)
127
+ * The element size may *not* be less than the number of meaningful
128
+ * bits in the bitmap of `d` multiplied by the size of a pointer.
129
+ * The returned object is cleared.
130
+ */
131
+ GC_API GC_ATTR_MALLOC GC_ATTR_CALLOC_SIZE(1, 2) void *GC_CALL
132
+ GC_calloc_explicitly_typed(size_t /* `nelements` */,
133
+ size_t /* `element_size_in_bytes` */,
134
+ GC_descr /* d */);
135
+
136
+ #define GC_CALLOC_TYPED_DESCR_PTRS 1
137
+ #define GC_CALLOC_TYPED_DESCR_WORDS 8 /*< includes space for pointers */
138
+
139
+ #ifdef GC_BUILD
140
+ struct GC_calloc_typed_descr_s;
141
+ # define GC_calloc_typed_descr_s GC_calloc_typed_descr_opaque_s
142
+ #endif
143
+
144
+ struct GC_calloc_typed_descr_s {
145
+ GC_uintptr_t opaque_p[GC_CALLOC_TYPED_DESCR_PTRS];
146
+ GC_word opaque[GC_CALLOC_TYPED_DESCR_WORDS - GC_CALLOC_TYPED_DESCR_PTRS];
147
+ };
148
+ #undef GC_calloc_typed_descr_s
149
+
150
+ /**
151
+ * This is same as `GC_calloc_explicitly_typed` but more optimal in
152
+ * terms of the performance and memory usage if the client needs to
153
+ * allocate multiple typed object arrays with the same layout and
154
+ * number of elements. The client should call it to be prepared for
155
+ * the subsequent allocations by `GC_calloc_do_explicitly_typed()`, one
156
+ * or many. The result of the preparation is stored to `*pctd`, even
157
+ * in case of a failure. The prepared structure could be just dropped
158
+ * when no longer needed. Returns 0 on failure, 1 on success; the
159
+ * result could be ignored (as it is also stored to `*pctd` and checked
160
+ * later by `GC_calloc_do_explicitly_typed()`).
161
+ */
162
+ GC_API int GC_CALL GC_calloc_prepare_explicitly_typed(
163
+ struct GC_calloc_typed_descr_s * /* `pctd` */, size_t /* `sizeof_ctd` */,
164
+ size_t /* `nelements` */, size_t /* `element_size_in_bytes` */, GC_descr);
165
+
166
+ /** The actual object allocation for the prepared description. */
167
+ GC_API GC_ATTR_MALLOC void *GC_CALL GC_calloc_do_explicitly_typed(
168
+ const struct GC_calloc_typed_descr_s * /* `pctd` */,
169
+ size_t /* `sizeof_ctd` */);
170
+
171
+ #ifdef GC_DEBUG
172
+ # define GC_MALLOC_EXPLICITLY_TYPED(bytes, d) ((void)(d), GC_MALLOC(bytes))
173
+ # define GC_MALLOC_EXPLICITLY_TYPED_IGNORE_OFF_PAGE(bytes, d) \
174
+ GC_MALLOC_EXPLICITLY_TYPED(bytes, d)
175
+ # define GC_CALLOC_EXPLICITLY_TYPED(n, bytes, d) \
176
+ ((void)(d), GC_MALLOC((n) * (bytes)))
177
+ #else
178
+ # define GC_MALLOC_EXPLICITLY_TYPED(bytes, d) \
179
+ GC_malloc_explicitly_typed(bytes, d)
180
+ # define GC_MALLOC_EXPLICITLY_TYPED_IGNORE_OFF_PAGE(bytes, d) \
181
+ GC_malloc_explicitly_typed_ignore_off_page(bytes, d)
182
+ # define GC_CALLOC_EXPLICITLY_TYPED(n, bytes, d) \
183
+ GC_calloc_explicitly_typed(n, bytes, d)
184
+ #endif
185
+
186
+ /* Deprecated. Use `GC_SIZEOF_IN_PTRS()` instead. */
187
+ #define GC_WORD_LEN(t) GC_SIZEOF_IN_PTRS(t)
188
+
189
+ /* Deprecated. Use `GC_OFFSETOF_IN_PTRS()` instead. */
190
+ #define GC_WORD_OFFSET(t, f) GC_OFFSETOF_IN_PTRS(t, f)
191
+
192
+ #ifdef __cplusplus
193
+ } /* extern "C" */
194
+ #endif
195
+
196
+ #endif /* GC_TYPED_H */
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3
+ * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4
+ * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5
+ * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6
+ * All rights reserved.
7
+ *
8
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10
+ *
11
+ * Permission is hereby granted to use or copy this program
12
+ * for any purpose, provided the above notices are retained on all copies.
13
+ * Permission to modify the code and to distribute modified code is granted,
14
+ * provided the above notices are retained, and a notice that the code was
15
+ * modified is included with the above copyright notice.
16
+ */
17
+
18
+ /*
19
+ * This should never be included directly; it is included only from
20
+ * `gc.h` file.
21
+ */
22
+ #if defined(GC_H)
23
+
24
+ /*
25
+ * The policy regarding version numbers: development code has odd
26
+ * `minor` number (and `micro` part is 0); when development is finished
27
+ * and a release is prepared, `minor` number is incremented (keeping
28
+ * `micro` number still zero), whenever a defect is fixed a new release
29
+ * is prepared incrementing `micro` part to odd value (the most stable
30
+ * release has the biggest `micro` number).
31
+ */
32
+
33
+ /*
34
+ * The version here should match that in files `CMakeLists.txt`,
35
+ * `build.zig.zon` and `configure.ac`. Eventually this one may become
36
+ * unnecessary. For now we need it to keep the old-style build process
37
+ * working.
38
+ */
39
+ # define GC_TMP_VERSION_MAJOR 8
40
+ # define GC_TMP_VERSION_MINOR 3
41
+ # define GC_TMP_VERSION_MICRO 0 /*< 8.3.0 */
42
+
43
+ # ifdef GC_VERSION_MAJOR
44
+ # if GC_TMP_VERSION_MAJOR != GC_VERSION_MAJOR \
45
+ || GC_TMP_VERSION_MINOR != GC_VERSION_MINOR \
46
+ || GC_TMP_VERSION_MICRO != GC_VERSION_MICRO
47
+ # error Inconsistent version info. Check README.md, include/gc_version.h and configure.ac.
48
+ # endif
49
+ # else
50
+ # define GC_VERSION_MAJOR GC_TMP_VERSION_MAJOR
51
+ # define GC_VERSION_MINOR GC_TMP_VERSION_MINOR
52
+ # define GC_VERSION_MICRO GC_TMP_VERSION_MICRO
53
+ # endif /* !GC_VERSION_MAJOR */
54
+
55
+ #endif
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3
+ * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4
+ * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5
+ * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6
+ * All rights reserved.
7
+ *
8
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10
+ *
11
+ * Permission is hereby granted to use or copy this program
12
+ * for any purpose, provided the above notices are retained on all copies.
13
+ * Permission to modify the code and to distribute modified code is granted,
14
+ * provided the above notices are retained, and a notice that the code was
15
+ * modified is included with the above copyright notice.
16
+ */
17
+
18
+ #ifndef GC_JAVAXFC_H
19
+ #define GC_JAVAXFC_H
20
+
21
+ #ifndef GC_H
22
+ # include "gc.h"
23
+ #endif
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /**
30
+ * Invoke all remaining finalizers that have not yet been run. (Since the
31
+ * notifier is not called, this should be called from a separate thread.)
32
+ * This function is needed for strict compliance with the Java standard,
33
+ * which can make the runtime guarantee that all finalizers are run.
34
+ * This is problematic for several reasons:
35
+ * 1. It means that finalizers, and all methods called by them, must be
36
+ * prepared to deal with objects that have been finalized in spite of
37
+ * the fact that they are still referenced by statically allocated
38
+ * pointer variables (i.e. finalizers run at this point must be
39
+ * prepared to deal with a mostly broken world);
40
+ * 2. The Java standard implies we have to keep running finalizers until
41
+ * there are no more left, thus it may mean that we get stuck in
42
+ * an infinite loop running finalizers that create new finalizable
43
+ * objects, though that is probably unlikely.
44
+ * Thus this is not recommended for general use.
45
+ * Acquires the allocator lock (to enqueue all finalizers).
46
+ */
47
+ GC_API void GC_CALL GC_finalize_all(void);
48
+
49
+ #ifdef GC_THREADS
50
+ /**
51
+ * External thread suspension support. No thread suspension count
52
+ * (so a thread which has been suspended numerous times will be resumed
53
+ * with the very first call to `GC_resume_thread()`). Acquires the
54
+ * allocator lock. Thread should be registered in the collector.
55
+ * Unimplemented on some platforms. Not recommended for general use.
56
+ */
57
+ # ifndef GC_SUSPEND_THREAD_ID
58
+ # define GC_SUSPEND_THREAD_ID void *
59
+ # endif
60
+ GC_API void GC_CALL GC_suspend_thread(GC_SUSPEND_THREAD_ID);
61
+ GC_API void GC_CALL GC_resume_thread(GC_SUSPEND_THREAD_ID);
62
+
63
+ /**
64
+ * Is the given thread suspended externally? The result is either
65
+ * 1 (true) or 0. Acquires the allocator lock in the reader mode.
66
+ * Note: returns 0 (false) if the thread is not registered in the collector.
67
+ * Unimplemented on some platforms (same as `GC_suspend_thread()`).
68
+ */
69
+ GC_API int GC_CALL GC_is_thread_suspended(GC_SUSPEND_THREAD_ID);
70
+ #endif /* GC_THREADS */
71
+
72
+ #ifdef __cplusplus
73
+ } /* extern "C" */
74
+ #endif
75
+
76
+ #endif /* GC_JAVAXFC_H */
@@ -0,0 +1,120 @@
1
+ /*
2
+ * Copyright (c) 2000-2011 by Hewlett-Packard Development Company.
3
+ * All rights reserved.
4
+ *
5
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7
+ *
8
+ * Permission is hereby granted to use or copy this program
9
+ * for any purpose, provided the above notices are retained on all copies.
10
+ * Permission to modify the code and to distribute modified code is granted,
11
+ * provided the above notices are retained, and a notice that the code was
12
+ * modified is included with the above copyright notice.
13
+ */
14
+
15
+ #ifndef GC_LEAK_DETECTOR_H
16
+ #define GC_LEAK_DETECTOR_H
17
+
18
+ /*
19
+ * Include this header file (e.g., via gcc `--include` option) to turn
20
+ * the collector into a leak detector.
21
+ */
22
+
23
+ #ifndef GC_DEBUG
24
+ # define GC_DEBUG
25
+ #endif
26
+ #include "gc.h"
27
+
28
+ #ifndef GC_DONT_INCLUDE_STDLIB
29
+ /*
30
+ * We ensure the platform `stdlib.h` and `string.h` files are included
31
+ * before redirecting `malloc` and the accompanying functions.
32
+ */
33
+ # include <stdlib.h>
34
+ # include <string.h>
35
+ #endif
36
+
37
+ #undef malloc
38
+ #define malloc(n) GC_MALLOC(n)
39
+ #undef calloc
40
+ #define calloc(m, n) GC_MALLOC((m) * (n))
41
+ #undef free
42
+ #define free(p) GC_FREE(p)
43
+ #undef realloc
44
+ #define realloc(p, n) GC_REALLOC(p, n)
45
+ #undef reallocarray
46
+ #define reallocarray(p, m, n) GC_REALLOC(p, (m) * (n))
47
+
48
+ #undef strdup
49
+ #define strdup(s) GC_STRDUP(s)
50
+ #undef strndup
51
+ #define strndup(s, n) GC_STRNDUP(s, n)
52
+
53
+ #ifdef GC_REQUIRE_WCSDUP
54
+ /*
55
+ * The collector should be built with `GC_REQUIRE_WCSDUP` macro defined
56
+ * as well to redirect `wcsdup`.
57
+ */
58
+ # include <wchar.h>
59
+ # undef wcsdup
60
+ # define wcsdup(s) GC_WCSDUP(s)
61
+ #endif
62
+
63
+ /*
64
+ * The following routines for the aligned objects allocation
65
+ * (`aligned_alloc`, `valloc`, etc.) do not have their debugging
66
+ * counterparts. Note that `free()` called for such objects may output
67
+ * a warning that the pointer has no debugging info.
68
+ */
69
+
70
+ #undef aligned_alloc
71
+ #define aligned_alloc(a, n) GC_memalign(a, n) /*< identical to `memalign` */
72
+ #undef memalign
73
+ #define memalign(a, n) GC_memalign(a, n)
74
+ #undef posix_memalign
75
+ #define posix_memalign(p, a, n) GC_posix_memalign(p, a, n)
76
+
77
+ /* These are defined in the C23 standard. */
78
+ #undef free_sized
79
+ #define free_sized(p, n) (free(p), (void)(n))
80
+ #undef free_aligned_sized
81
+ #define free_aligned_sized(p, a, n) \
82
+ (GC_free(p) /* non-debug */, (void)(a), (void)(n))
83
+
84
+ #undef cfree /*< obsolete */
85
+ #if defined(sun) || defined(__sun)
86
+ # define cfree(p, m, n) ((void)(m), (void)(n), free(p))
87
+ #else
88
+ # define cfree(p) free(p)
89
+ #endif
90
+
91
+ #undef _aligned_malloc
92
+ #define _aligned_malloc(n, a) GC_memalign(a, n) /*< reverse args order */
93
+ #undef _aligned_free
94
+ #define _aligned_free(p) GC_free(p) /*< non-debug */
95
+
96
+ #ifndef GC_NO_VALLOC
97
+ # undef valloc
98
+ # define valloc(n) GC_valloc(n)
99
+ # undef pvalloc
100
+ # define pvalloc(n) GC_pvalloc(n) /*< obsolete */
101
+ #endif
102
+
103
+ #undef malloc_usable_size /*< available in `glibc` */
104
+ #define malloc_usable_size(p) GC_size(p)
105
+ #undef malloc_size /*< available in Darwin */
106
+ #define malloc_size(p) GC_size(p)
107
+ #undef _msize /*< available in Windows CRT */
108
+ #define _msize(p) GC_size(p)
109
+
110
+ #ifndef CHECK_LEAKS
111
+ /**
112
+ * Note 1: `CHECK_LEAKS` does not have `GC_` prefix (preserved for
113
+ * backward compatibility).
114
+ * Note 2: `GC_gcollect()` is also called automatically in the
115
+ * find-leak mode at program exit.
116
+ */
117
+ # define CHECK_LEAKS() GC_gcollect()
118
+ #endif
119
+
120
+ #endif /* GC_LEAK_DETECTOR_H */