]>
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
5 #include "duk_internal.h"
7 DUK_EXTERNAL
void *duk_alloc_raw(duk_context
*ctx
, duk_size_t size
) {
8 duk_hthread
*thr
= (duk_hthread
*) ctx
;
10 DUK_ASSERT_CTX_VALID(ctx
);
12 return DUK_ALLOC_RAW(thr
->heap
, size
);
15 DUK_EXTERNAL
void duk_free_raw(duk_context
*ctx
, void *ptr
) {
16 duk_hthread
*thr
= (duk_hthread
*) ctx
;
18 DUK_ASSERT_CTX_VALID(ctx
);
20 DUK_FREE_RAW(thr
->heap
, ptr
);
23 DUK_EXTERNAL
void *duk_realloc_raw(duk_context
*ctx
, void *ptr
, duk_size_t size
) {
24 duk_hthread
*thr
= (duk_hthread
*) ctx
;
26 DUK_ASSERT_CTX_VALID(ctx
);
28 return DUK_REALLOC_RAW(thr
->heap
, ptr
, size
);
31 DUK_EXTERNAL
void *duk_alloc(duk_context
*ctx
, duk_size_t size
) {
32 duk_hthread
*thr
= (duk_hthread
*) ctx
;
34 DUK_ASSERT_CTX_VALID(ctx
);
36 return DUK_ALLOC(thr
->heap
, size
);
39 DUK_EXTERNAL
void duk_free(duk_context
*ctx
, void *ptr
) {
40 duk_hthread
*thr
= (duk_hthread
*) ctx
;
42 DUK_ASSERT_CTX_VALID(ctx
);
44 DUK_FREE(thr
->heap
, ptr
);
47 DUK_EXTERNAL
void *duk_realloc(duk_context
*ctx
, void *ptr
, duk_size_t size
) {
48 duk_hthread
*thr
= (duk_hthread
*) ctx
;
50 DUK_ASSERT_CTX_VALID(ctx
);
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.
58 * Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
59 * have the storage location here anyway).
62 return DUK_REALLOC(thr
->heap
, ptr
, size
);
65 DUK_EXTERNAL
void duk_get_memory_functions(duk_context
*ctx
, duk_memory_functions
*out_funcs
) {
66 duk_hthread
*thr
= (duk_hthread
*) ctx
;
69 DUK_ASSERT_CTX_VALID(ctx
);
70 DUK_ASSERT(out_funcs
!= NULL
);
71 DUK_ASSERT(thr
!= NULL
);
72 DUK_ASSERT(thr
->heap
!= NULL
);
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
;
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
;
92 DUK_ASSERT_CTX_VALID(ctx
);
94 DUK_ASSERT(heap
!= NULL
);
96 DUK_D(DUK_DPRINT("mark-and-sweep requested by application"));
97 duk_heap_mark_and_sweep(heap
, 0);
99 DUK_D(DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring"));