Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_hbufferobject.h File Reference

Go to the source code of this file.

Data Structures

struct  duk_hbufferobject
 

Macros

#define DUK_HBUFFEROBJECT_ELEM_UINT8   0
 
#define DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED   1
 
#define DUK_HBUFFEROBJECT_ELEM_INT8   2
 
#define DUK_HBUFFEROBJECT_ELEM_UINT16   3
 
#define DUK_HBUFFEROBJECT_ELEM_INT16   4
 
#define DUK_HBUFFEROBJECT_ELEM_UINT32   5
 
#define DUK_HBUFFEROBJECT_ELEM_INT32   6
 
#define DUK_HBUFFEROBJECT_ELEM_FLOAT32   7
 
#define DUK_HBUFFEROBJECT_ELEM_FLOAT64   8
 
#define DUK_HBUFFEROBJECT_ELEM_MAX   8
 
#define DUK_ASSERT_HBUFFEROBJECT_VALID(h)
 
#define DUK_HBUFFEROBJECT_GET_SLICE_BASE(heap, h)
 
#define DUK_HBUFFEROBJECT_FULL_SLICE(h)
 
#define DUK_HBUFFEROBJECT_VALID_SLICE(h)
 
#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_INCL(h, off)
 
#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL(h, off)
 
#define DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH(h, len)
 

Functions

DUK_INTERNAL_DECL void duk_hbufferobject_push_validated_read (duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size)
 
DUK_INTERNAL_DECL void duk_hbufferobject_validated_write (duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size)
 

Macro Definition Documentation

◆ DUK_ASSERT_HBUFFEROBJECT_VALID

#define DUK_ASSERT_HBUFFEROBJECT_VALID ( h)
Value:
do { \
DUK_ASSERT((h) != NULL); \
DUK_ASSERT((h)->shift <= 3); \
DUK_ASSERT((h)->elem_type <= DUK_HBUFFEROBJECT_ELEM_MAX); \
DUK_ASSERT(((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8) || \
((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED) || \
((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT8) || \
((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT16) || \
((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT16) || \
((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT32) || \
((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT32) || \
((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT32) || \
((h)->shift == 3 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT64)); \
DUK_ASSERT((h)->is_view == 0 || (h)->is_view == 1); \
DUK_ASSERT(DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) (h))); \
if ((h)->buf == NULL) { \
DUK_ASSERT((h)->offset == 0); \
DUK_ASSERT((h)->length == 0); \
} else { \
/* No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
*/ \
DUK_ASSERT((h)->offset + (h)->length >= (h)->offset); \
} \
} while (0)
#define DUK_HOBJECT_IS_BUFFEROBJECT(h)
#define NULL
Definition gmacros.h:924

Definition at line 20 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

20#define DUK_ASSERT_HBUFFEROBJECT_VALID(h) do { \
21 DUK_ASSERT((h) != NULL); \
22 DUK_ASSERT((h)->shift <= 3); \
23 DUK_ASSERT((h)->elem_type <= DUK_HBUFFEROBJECT_ELEM_MAX); \
24 DUK_ASSERT(((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8) || \
25 ((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED) || \
26 ((h)->shift == 0 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT8) || \
27 ((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT16) || \
28 ((h)->shift == 1 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT16) || \
29 ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_UINT32) || \
30 ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_INT32) || \
31 ((h)->shift == 2 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT32) || \
32 ((h)->shift == 3 && (h)->elem_type == DUK_HBUFFEROBJECT_ELEM_FLOAT64)); \
33 DUK_ASSERT((h)->is_view == 0 || (h)->is_view == 1); \
34 DUK_ASSERT(DUK_HOBJECT_IS_BUFFEROBJECT((duk_hobject *) (h))); \
35 if ((h)->buf == NULL) { \
36 DUK_ASSERT((h)->offset == 0); \
37 DUK_ASSERT((h)->length == 0); \
38 } else { \
39 /* No assertions for offset or length; in particular, \
40 * it's OK for length to be longer than underlying \
41 * buffer. Just ensure they don't wrap when added. \
42 */ \

◆ DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH

#define DUK_HBUFFEROBJECT_CLAMP_BYTELENGTH ( h,
len )
Value:
(DUK_ASSERT_EXPR((h) != NULL), \
duk_hbufferobject_clamp_bytelength((h), (len)))
#define DUK_ASSERT_EXPR(x)

Definition at line 88 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

88 * can be invalidated by any side effect because it may trigger a user
89 * callback that resizes the underlying buffer.
90 */

◆ DUK_HBUFFEROBJECT_ELEM_FLOAT32

#define DUK_HBUFFEROBJECT_ELEM_FLOAT32   7

◆ DUK_HBUFFEROBJECT_ELEM_FLOAT64

#define DUK_HBUFFEROBJECT_ELEM_FLOAT64   8

◆ DUK_HBUFFEROBJECT_ELEM_INT16

#define DUK_HBUFFEROBJECT_ELEM_INT16   4

◆ DUK_HBUFFEROBJECT_ELEM_INT32

#define DUK_HBUFFEROBJECT_ELEM_INT32   6

◆ DUK_HBUFFEROBJECT_ELEM_INT8

#define DUK_HBUFFEROBJECT_ELEM_INT8   2

◆ DUK_HBUFFEROBJECT_ELEM_MAX

#define DUK_HBUFFEROBJECT_ELEM_MAX   8

◆ DUK_HBUFFEROBJECT_ELEM_UINT16

#define DUK_HBUFFEROBJECT_ELEM_UINT16   3

◆ DUK_HBUFFEROBJECT_ELEM_UINT32

#define DUK_HBUFFEROBJECT_ELEM_UINT32   5

◆ DUK_HBUFFEROBJECT_ELEM_UINT8

#define DUK_HBUFFEROBJECT_ELEM_UINT8   0

◆ DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED

#define DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED   1

◆ DUK_HBUFFEROBJECT_FULL_SLICE

#define DUK_HBUFFEROBJECT_FULL_SLICE ( h)
Value:
(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
((h)->offset == 0 && (h)->length == DUK_HBUFFER_GET_SIZE((h)->buf)))
#define DUK_HBUFFER_GET_SIZE(x)

Definition at line 56 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

56 * the underlying buffer is dynamic and changes without the hbufferobject
57 * being changed.
58 */
static void changes(sqlite3_context *context, int NotUsed, sqlite3_value **NotUsed2)
Definition sqlite3.c:117622

◆ DUK_HBUFFEROBJECT_GET_SLICE_BASE

#define DUK_HBUFFEROBJECT_GET_SLICE_BASE ( heap,
h )
Value:
(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
(((duk_uint8_t *) DUK_HBUFFER_GET_DATA_PTR((heap), (h)->buf)) + (h)->offset))
#define DUK_HBUFFER_GET_DATA_PTR(heap, x)

Definition at line 47 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

47/* Get the current data pointer (caller must ensure buf != NULL) as a
48 * duk_uint8_t ptr.
49 */

◆ DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL

#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_EXCL ( h,
off )
Value:
(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
((h)->offset + (off) <= DUK_HBUFFER_GET_SIZE((h)->buf)))

Definition at line 78 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

78 (DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
79 ((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf)))
80

◆ DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_INCL

#define DUK_HBUFFEROBJECT_VALID_BYTEOFFSET_INCL ( h,
off )
Value:
(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
((h)->offset + (off) < DUK_HBUFFER_GET_SIZE((h)->buf)))

Definition at line 74 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

74 * unsafe behavior (e.g. if an underlying dynamic buffer changes
75 * after being setup). Caller must ensure 'buf' != NULL.
76 */

◆ DUK_HBUFFEROBJECT_VALID_SLICE

#define DUK_HBUFFEROBJECT_VALID_SLICE ( h)
Value:
(DUK_ASSERT_EXPR((h) != NULL), DUK_ASSERT_EXPR((h)->buf != NULL), \
((h)->offset + (h)->length <= DUK_HBUFFER_GET_SIZE((h)->buf)))

Definition at line 63 of file duktape-1.5.2/src-separate/duk_hbufferobject.h.

63/* Validate that the whole slice [0,length[ is contained in the underlying
64 * buffer. Caller must ensure 'buf' != NULL.
65 */

Function Documentation

◆ duk_hbufferobject_push_validated_read()

DUK_INTERNAL_DECL void duk_hbufferobject_push_validated_read ( duk_context * ctx,
duk_hbufferobject * h_bufobj,
duk_uint8_t * p,
duk_small_uint_t elem_size )

Definition at line 21855 of file duktape-1.5.2/src-noline/duktape.c.

21872 {
21874
21875 DUK_MEMCPY((void *) du.uc, (const void *) p, (size_t) elem_size);
21876
21877 switch (h_bufobj->elem_type) {
21879#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
21881#endif
21882 duk_push_uint(ctx, (duk_uint_t) du.uc[0]);
21883 break;
21884#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
21885 /* These are not needed when only Duktape.Buffer is supported. */
21887 duk_push_int(ctx, (duk_int_t) (duk_int8_t) du.uc[0]);
21888 break;
21890 duk_push_uint(ctx, (duk_uint_t) du.us[0]);
21891 break;
21893 duk_push_int(ctx, (duk_int_t) (duk_int16_t) du.us[0]);
21894 break;
duk_int_fast32_t duk_int_t
duk_uint_fast32_t duk_uint_t
#define DUK_HBUFFEROBJECT_ELEM_INT16
DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val)
#define DUK_HBUFFEROBJECT_ELEM_UINT16
DUK_EXTERNAL void duk_push_uint(duk_context *ctx, duk_uint_t val)
#define DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
#define DUK_HBUFFEROBJECT_ELEM_INT8
#define DUK_HBUFFEROBJECT_ELEM_UINT8

◆ duk_hbufferobject_validated_write()

DUK_INTERNAL_DECL void duk_hbufferobject_validated_write ( duk_context * ctx,
duk_hbufferobject * h_bufobj,
duk_uint8_t * p,
duk_small_uint_t elem_size )

Definition at line 21896 of file duktape-1.5.2/src-noline/duktape.c.

21898 :
21899 duk_push_int(ctx, (duk_int_t) (duk_int32_t) du.ui[0]);
21900 break;
21902 duk_push_number(ctx, (duk_double_t) du.f[0]);
21903 break;
21905 duk_push_number(ctx, (duk_double_t) du.d);
21906 break;
21907#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
21908 default:
21910 }
21911}
21912
21913DUK_INTERNAL void duk_hbufferobject_validated_write(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size) {
21915
21916 /* NOTE! Caller must ensure that any side effects from the
21917 * coercions below are safe. If that cannot be guaranteed
21918 * (which is normally the case), caller must coerce the
21919 * argument using duk_to_number() before any pointer
21920 * validations; the result of duk_to_number() always coerces
21921 * without side effects here.
21922 */
21923
21924 switch (h_bufobj->elem_type) {
21926 du.uc[0] = (duk_uint8_t) duk_to_uint32(ctx, -1);
21927 break;
21928#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
21929 /* These are not needed when only Duktape.Buffer is supported. */
21931 du.uc[0] = (duk_uint8_t) duk_to_uint8clamped(ctx, -1);
21932 break;
21934 du.uc[0] = (duk_uint8_t) duk_to_int32(ctx, -1);
21935 break;
21937 du.us[0] = (duk_uint16_t) duk_to_uint32(ctx, -1);
21938 break;
21940 du.us[0] = (duk_uint16_t) duk_to_int32(ctx, -1);
21941 break;
21943 du.ui[0] = (duk_uint32_t) duk_to_uint32(ctx, -1);
unsigned int duk_small_uint_t
DUK_INTERNAL_DECL void duk_hbufferobject_validated_write(duk_context *ctx, duk_hbufferobject *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size)
DUK_INTERNAL_DECL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t index)
#define DUK_HBUFFEROBJECT_ELEM_FLOAT64
#define DUK_HBUFFEROBJECT_ELEM_UINT32
DUK_EXTERNAL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_push_number(duk_context *ctx, duk_double_t val)
#define DUK_HBUFFEROBJECT_ELEM_FLOAT32