]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/src/third_party/duktape-1.8.0/src-separate/duk_api_memory.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / src / third_party / duktape-1.8.0 / src-separate / duk_api_memory.c
1 /*
2 * Memory calls.
3 */
4
5 #include "duk_internal.h"
6
7 DUK_EXTERNAL void *duk_alloc_raw(duk_context *ctx, duk_size_t size) {
8 duk_hthread *thr = (duk_hthread *) ctx;
9
10 DUK_ASSERT_CTX_VALID(ctx);
11
12 return DUK_ALLOC_RAW(thr->heap, size);
13 }
14
15 DUK_EXTERNAL void duk_free_raw(duk_context *ctx, void *ptr) {
16 duk_hthread *thr = (duk_hthread *) ctx;
17
18 DUK_ASSERT_CTX_VALID(ctx);
19
20 DUK_FREE_RAW(thr->heap, ptr);
21 }
22
23 DUK_EXTERNAL void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size) {
24 duk_hthread *thr = (duk_hthread *) ctx;
25
26 DUK_ASSERT_CTX_VALID(ctx);
27
28 return DUK_REALLOC_RAW(thr->heap, ptr, size);
29 }
30
31 DUK_EXTERNAL void *duk_alloc(duk_context *ctx, duk_size_t size) {
32 duk_hthread *thr = (duk_hthread *) ctx;
33
34 DUK_ASSERT_CTX_VALID(ctx);
35
36 return DUK_ALLOC(thr->heap, size);
37 }
38
39 DUK_EXTERNAL void duk_free(duk_context *ctx, void *ptr) {
40 duk_hthread *thr = (duk_hthread *) ctx;
41
42 DUK_ASSERT_CTX_VALID(ctx);
43
44 DUK_FREE(thr->heap, ptr);
45 }
46
47 DUK_EXTERNAL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size) {
48 duk_hthread *thr = (duk_hthread *) ctx;
49
50 DUK_ASSERT_CTX_VALID(ctx);
51
52 /*
53 * Note: since this is an exposed API call, there should be
54 * no way a mark-and-sweep could have a side effect on the
55 * memory allocation behind 'ptr'; the pointer should never
56 * be something that Duktape wants to change.
57 *
58 * Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
59 * have the storage location here anyway).
60 */
61
62 return DUK_REALLOC(thr->heap, ptr, size);
63 }
64
65 DUK_EXTERNAL void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs) {
66 duk_hthread *thr = (duk_hthread *) ctx;
67 duk_heap *heap;
68
69 DUK_ASSERT_CTX_VALID(ctx);
70 DUK_ASSERT(out_funcs != NULL);
71 DUK_ASSERT(thr != NULL);
72 DUK_ASSERT(thr->heap != NULL);
73
74 heap = thr->heap;
75 out_funcs->alloc_func = heap->alloc_func;
76 out_funcs->realloc_func = heap->realloc_func;
77 out_funcs->free_func = heap->free_func;
78 out_funcs->udata = heap->heap_udata;
79 }
80
81 DUK_EXTERNAL void duk_gc(duk_context *ctx, duk_uint_t flags) {
82 #ifdef DUK_USE_MARK_AND_SWEEP
83 duk_hthread *thr = (duk_hthread *) ctx;
84 duk_heap *heap;
85
86 DUK_UNREF(flags);
87
88 /* NULL accepted */
89 if (!ctx) {
90 return;
91 }
92 DUK_ASSERT_CTX_VALID(ctx);
93 heap = thr->heap;
94 DUK_ASSERT(heap != NULL);
95
96 DUK_D(DUK_DPRINT("mark-and-sweep requested by application"));
97 duk_heap_mark_and_sweep(heap, 0);
98 #else
99 DUK_D(DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring"));
100 DUK_UNREF(ctx);
101 DUK_UNREF(flags);
102 #endif
103 }