Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_hobject_alloc.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Functions

DUK_LOCAL void duk__init_object_parts (duk_heap *heap, duk_hobject *obj, duk_uint_t hobject_flags)
 
DUK_INTERNAL duk_hobjectduk_hobject_alloc (duk_heap *heap, duk_uint_t hobject_flags)
 
DUK_INTERNAL duk_hcompiledfunctionduk_hcompiledfunction_alloc (duk_heap *heap, duk_uint_t hobject_flags)
 
DUK_INTERNAL duk_hnativefunctionduk_hnativefunction_alloc (duk_heap *heap, duk_uint_t hobject_flags)
 
DUK_INTERNAL duk_hbufferobjectduk_hbufferobject_alloc (duk_heap *heap, duk_uint_t hobject_flags)
 
DUK_INTERNAL duk_hthreadduk_hthread_alloc (duk_heap *heap, duk_uint_t hobject_flags)
 

Function Documentation

◆ duk__init_object_parts()

DUK_LOCAL void duk__init_object_parts ( duk_heap * heap,
duk_hobject * obj,
duk_uint_t hobject_flags )

Definition at line 11 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

11 {
12#ifdef DUK_USE_EXPLICIT_NULL_INIT
13 DUK_HOBJECT_SET_PROPS(heap, obj, NULL);
14#endif
15
16 /* XXX: macro? sets both heaphdr and object flags */
17 obj->hdr.h_flags = hobject_flags;
18 DUK_HEAPHDR_SET_TYPE(&obj->hdr, DUK_HTYPE_OBJECT); /* also goes into flags */
19
20#if defined(DUK_USE_HEAPPTR16)
21 /* Zero encoded pointer is required to match NULL */
22 DUK_HEAPHDR_SET_NEXT(heap, &obj->hdr, NULL);
23#if defined(DUK_USE_DOUBLE_LINKED_HEAP)
24 DUK_HEAPHDR_SET_PREV(heap, &obj->hdr, NULL);
25#endif
26#endif
27 DUK_ASSERT_HEAPHDR_LINKS(heap, &obj->hdr);
29
30 /*
31 * obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
32 * with this properly. This is intentional: empty objects consume a minimum
33 * amount of memory. Further, an initial allocation might fail and cause
34 * 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
35 */
36}
#define DUK_HEAPHDR_SET_NEXT(heap, h, val)
#define DUK_HEAPHDR_SET_PREV(heap, h, val)
#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr)
#define DUK_HOBJECT_SET_PROPS(heap, h, x)
#define DUK_HEAPHDR_SET_TYPE(h, val)
#define DUK_ASSERT_HEAPHDR_LINKS(heap, h)
#define NULL
Definition gmacros.h:924

References DUK_ASSERT_HEAPHDR_LINKS, DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED, DUK_HEAPHDR_SET_NEXT, DUK_HEAPHDR_SET_PREV, DUK_HEAPHDR_SET_TYPE, DUK_HOBJECT_SET_PROPS, DUK_HTYPE_OBJECT, duk_heaphdr::h_flags, duk_hobject::hdr, and NULL.

Referenced by duk_hbufferobject_alloc(), duk_hcompiledfunction_alloc(), duk_hnativefunction_alloc(), duk_hobject_alloc(), and duk_hthread_alloc().

◆ duk_hbufferobject_alloc()

DUK_INTERNAL duk_hbufferobject * duk_hbufferobject_alloc ( duk_heap * heap,
duk_uint_t hobject_flags )

Definition at line 112 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

112 {
114
115 res = (duk_hbufferobject *) DUK_ALLOC(heap, sizeof(duk_hbufferobject));
116 if (!res) {
117 return NULL;
118 }
119 DUK_MEMZERO(res, sizeof(duk_hbufferobject));
120
121 duk__init_object_parts(heap, &res->obj, hobject_flags);
122
123#ifdef DUK_USE_EXPLICIT_NULL_INIT
124 res->buf = NULL;
125#endif
126
128 return res;
129}
#define DUK_MEMZERO(p, n)
#define DUK_ALLOC(heap, size)
#define DUK_ASSERT_HBUFFEROBJECT_VALID(h)
DUK_LOCAL void duk__init_object_parts(duk_heap *heap, duk_hobject *obj, duk_uint_t hobject_flags)

References duk_hbufferobject::buf, duk__init_object_parts(), DUK_ALLOC, DUK_ASSERT_HBUFFEROBJECT_VALID, DUK_MEMZERO, NULL, and duk_hbufferobject::obj.

◆ duk_hcompiledfunction_alloc()

DUK_INTERNAL duk_hcompiledfunction * duk_hcompiledfunction_alloc ( duk_heap * heap,
duk_uint_t hobject_flags )

Definition at line 70 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

70 {
72
74 if (!res) {
75 return NULL;
76 }
78
79 duk__init_object_parts(heap, &res->obj, hobject_flags);
80
81#ifdef DUK_USE_EXPLICIT_NULL_INIT
82#ifdef DUK_USE_HEAPPTR16
83 /* NULL pointer is required to encode to zero, so memset is enough. */
84#else
85 res->data = NULL;
86 res->funcs = NULL;
87 res->bytecode = NULL;
88#endif
89#endif
90
91 return res;
92}

References duk_hcompiledfunction::bytecode, duk_hcompiledfunction::data, duk__init_object_parts(), DUK_ALLOC, DUK_MEMZERO, duk_hcompiledfunction::funcs, NULL, and duk_hcompiledfunction::obj.

◆ duk_hnativefunction_alloc()

DUK_INTERNAL duk_hnativefunction * duk_hnativefunction_alloc ( duk_heap * heap,
duk_uint_t hobject_flags )

Definition at line 94 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

94 {
96
97 res = (duk_hnativefunction *) DUK_ALLOC(heap, sizeof(duk_hnativefunction));
98 if (!res) {
99 return NULL;
100 }
101 DUK_MEMZERO(res, sizeof(duk_hnativefunction));
102
103 duk__init_object_parts(heap, &res->obj, hobject_flags);
104
105#ifdef DUK_USE_EXPLICIT_NULL_INIT
106 res->func = NULL;
107#endif
108
109 return res;
110}

References duk__init_object_parts(), DUK_ALLOC, DUK_MEMZERO, duk_hnativefunction::func, NULL, and duk_hnativefunction::obj.

◆ duk_hobject_alloc()

DUK_INTERNAL duk_hobject * duk_hobject_alloc ( duk_heap * heap,
duk_uint_t hobject_flags )

Definition at line 49 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

49 {
50 duk_hobject *res;
51
52 DUK_ASSERT(heap != NULL);
53
54 /* different memory layout, alloc size, and init */
55 DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_COMPILEDFUNCTION) == 0);
56 DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_NATIVEFUNCTION) == 0);
57 DUK_ASSERT((hobject_flags & DUK_HOBJECT_FLAG_THREAD) == 0);
58
59 res = (duk_hobject *) DUK_ALLOC(heap, sizeof(duk_hobject));
60 if (!res) {
61 return NULL;
62 }
63 DUK_MEMZERO(res, sizeof(duk_hobject));
64
65 duk__init_object_parts(heap, res, hobject_flags);
66
67 return res;
68}
#define DUK_HOBJECT_FLAG_COMPILEDFUNCTION
#define DUK_HOBJECT_FLAG_THREAD
#define DUK_HOBJECT_FLAG_NATIVEFUNCTION

References duk__init_object_parts(), DUK_ALLOC, DUK_ASSERT, DUK_HOBJECT_FLAG_COMPILEDFUNCTION, DUK_HOBJECT_FLAG_NATIVEFUNCTION, DUK_HOBJECT_FLAG_THREAD, DUK_MEMZERO, and NULL.

◆ duk_hthread_alloc()

DUK_INTERNAL duk_hthread * duk_hthread_alloc ( duk_heap * heap,
duk_uint_t hobject_flags )

Definition at line 139 of file duktape-1.5.2/src-separate/duk_hobject_alloc.c.

139 {
140 duk_hthread *res;
141
142 res = (duk_hthread *) DUK_ALLOC(heap, sizeof(duk_hthread));
143 if (!res) {
144 return NULL;
145 }
146 DUK_MEMZERO(res, sizeof(duk_hthread));
147
148 duk__init_object_parts(heap, &res->obj, hobject_flags);
149
150#ifdef DUK_USE_EXPLICIT_NULL_INIT
151 res->ptr_curr_pc = NULL;
152 res->heap = NULL;
153 res->valstack = NULL;
154 res->valstack_end = NULL;
155 res->valstack_bottom = NULL;
156 res->valstack_top = NULL;
157 res->callstack = NULL;
158 res->catchstack = NULL;
159 res->resumer = NULL;
160 res->compile_ctx = NULL,
161#ifdef DUK_USE_HEAPPTR16
162 res->strs16 = NULL;
163#else
164 res->strs = NULL;
165#endif
166 {
167 int i;
168 for (i = 0; i < DUK_NUM_BUILTINS; i++) {
169 res->builtins[i] = NULL;
170 }
171 }
172#endif
173 /* when nothing is running, API calls are in non-strict mode */
174 DUK_ASSERT(res->strict == 0);
175
176 res->heap = heap;
180
181 return res;
182}
#define DUK_CATCHSTACK_DEFAULT_MAX
#define DUK_CALLSTACK_DEFAULT_MAX
#define DUK_VALSTACK_DEFAULT_MAX
duk_hobject * builtins[DUK_NUM_BUILTINS]

References duk_hthread::builtins, duk_hthread::callstack, duk_hthread::callstack_max, duk_hthread::catchstack, duk_hthread::catchstack_max, duk_hthread::compile_ctx, duk__init_object_parts(), DUK_ALLOC, DUK_ASSERT, DUK_CALLSTACK_DEFAULT_MAX, DUK_CATCHSTACK_DEFAULT_MAX, DUK_MEMZERO, DUK_NUM_BUILTINS, DUK_VALSTACK_DEFAULT_MAX, duk_hthread::heap, NULL, duk_hthread::obj, duk_hthread::ptr_curr_pc, duk_hthread::resumer, duk_hthread::strict, duk_hthread::strs, duk_hthread::valstack, duk_hthread::valstack_bottom, duk_hthread::valstack_end, duk_hthread::valstack_max, and duk_hthread::valstack_top.