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

Go to the source code of this file.

Functions

DUK_INTERNAL void duk_hbuffer_resize (duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size)
 
DUK_INTERNAL void duk_hbuffer_reset (duk_hthread *thr, duk_hbuffer_dynamic *buf)
 

Function Documentation

◆ duk_hbuffer_reset()

DUK_INTERNAL void duk_hbuffer_reset ( duk_hthread * thr,
duk_hbuffer_dynamic * buf )

Definition at line 75 of file duktape-1.5.2/src-separate/duk_hbuffer_ops.c.

75 {
76 DUK_ASSERT(thr != NULL);
77 DUK_ASSERT(buf != NULL);
80
81 duk_hbuffer_resize(thr, buf, 0);
82}
#define DUK_HBUFFER_HAS_EXTERNAL(x)
#define DUK_HBUFFER_HAS_DYNAMIC(x)
DUK_INTERNAL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic *buf, duk_size_t new_size)
#define NULL
Definition gmacros.h:924

References DUK_ASSERT, DUK_HBUFFER_HAS_DYNAMIC, DUK_HBUFFER_HAS_EXTERNAL, duk_hbuffer_resize(), and NULL.

◆ duk_hbuffer_resize()

DUK_INTERNAL void duk_hbuffer_resize ( duk_hthread * thr,
duk_hbuffer_dynamic * buf,
duk_size_t new_size )

Definition at line 18 of file duktape-1.5.2/src-separate/duk_hbuffer_ops.c.

18 {
19 void *res;
20 duk_size_t prev_size;
21
22 DUK_ASSERT(thr != NULL);
23 DUK_ASSERT(buf != NULL);
26
27 /*
28 * Maximum size check
29 */
30
31 if (new_size > DUK_HBUFFER_MAX_BYTELEN) {
32 DUK_ERROR_RANGE(thr, "buffer too long");
33 }
34
35 /*
36 * Note: use indirect realloc variant just in case mark-and-sweep
37 * (finalizers) might resize this same buffer during garbage
38 * collection.
39 */
40
41 res = DUK_REALLOC_INDIRECT(thr->heap, duk_hbuffer_get_dynalloc_ptr, (void *) buf, new_size);
42 if (res != NULL || new_size == 0) {
43 /* 'res' may be NULL if new allocation size is 0. */
44
45 DUK_DDD(DUK_DDDPRINT("resized dynamic buffer %p:%ld -> %p:%ld",
46 (void *) DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, buf),
48 (void *) res,
49 (long) new_size));
50
51 /*
52 * The entire allocated buffer area, regardless of actual used
53 * size, is kept zeroed in resizes for simplicity. If the buffer
54 * is grown, zero the new part.
55 */
56
57 prev_size = DUK_HBUFFER_DYNAMIC_GET_SIZE(buf);
58 if (new_size > prev_size) {
59 DUK_ASSERT(new_size - prev_size > 0);
60#ifdef DUK_USE_ZERO_BUFFER_DATA
61 DUK_MEMZERO((void *) ((char *) res + prev_size),
62 (duk_size_t) (new_size - prev_size));
63#endif
64 }
65
66 DUK_HBUFFER_DYNAMIC_SET_SIZE(buf, new_size);
68 } else {
70 }
71
72 DUK_ASSERT(res != NULL || new_size == 0);
73}
#define DUK_MEMZERO(p, n)
#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x)
#define DUK_ERROR_RANGE(thr, msg)
#define DUK_HBUFFER_DYNAMIC_GET_SIZE(x)
#define DUK_HBUFFER_MAX_BYTELEN
#define DUK_REALLOC_INDIRECT(heap, cb, ud, newsize)
#define DUK_ERROR_ALLOC_DEFMSG(thr)
#define DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, x, v)
DUK_INTERNAL_DECL void * duk_hbuffer_get_dynalloc_ptr(duk_heap *heap, void *ud)
#define DUK_HBUFFER_DYNAMIC_SET_SIZE(x, v)

References DUK_ASSERT, DUK_DDD, DUK_DDDPRINT, DUK_ERROR_ALLOC_DEFMSG, DUK_ERROR_RANGE, DUK_HBUFFER_DYNAMIC_GET_DATA_PTR, DUK_HBUFFER_DYNAMIC_GET_SIZE, DUK_HBUFFER_DYNAMIC_SET_DATA_PTR, DUK_HBUFFER_DYNAMIC_SET_SIZE, duk_hbuffer_get_dynalloc_ptr(), DUK_HBUFFER_HAS_DYNAMIC, DUK_HBUFFER_HAS_EXTERNAL, DUK_HBUFFER_MAX_BYTELEN, DUK_MEMZERO, DUK_REALLOC_INDIRECT, duk_hthread::heap, and NULL.

Referenced by duk_hbuffer_reset().