10 #define BIG_BLOB_SIZE (1 << 12) /* 4KB. */
12 static signed char test_blob1
[] = { 0xc, 0xa, 0xf, 0xf, 0xe };
13 static unsigned test_blob2
[] = { 0x3, 0x2, 0x1, 0x0, 0x1, 0x2, 0x3 };
14 static unsigned char test_blob3
[BIG_BLOB_SIZE
];
17 create_code (gcc_jit_context
*ctxt
, void *user_data
)
19 /* Let's try to inject the equivalent of:
21 signed char bin_blob1[] = { 0xc, 0xa, 0xf, 0xf, 0xe };
22 unsigned bin_blob2[] = { 0x3, 0x2, 0x1, 0x0, 0x1, 0x2, 0x3 };
23 unsigned char bin_blob3[4096]...
25 gcc_jit_type
*unsigned_char_type
=
26 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_UNSIGNED_CHAR
);
27 gcc_jit_type
*signed_char_type
=
28 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_SIGNED_CHAR
);
29 gcc_jit_type
*unsigned_type
=
30 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_UNSIGNED_INT
);
32 gcc_jit_lvalue
*glob
=
33 gcc_jit_context_new_global (
34 ctxt
, NULL
, GCC_JIT_GLOBAL_EXPORTED
,
35 gcc_jit_context_new_array_type (ctxt
, NULL
, signed_char_type
,
38 gcc_jit_global_set_initializer (glob
, test_blob1
, sizeof (test_blob1
));
41 gcc_jit_context_new_global (
42 ctxt
, NULL
, GCC_JIT_GLOBAL_EXPORTED
,
43 gcc_jit_context_new_array_type (
44 ctxt
, NULL
, unsigned_type
,
45 sizeof (test_blob2
) / sizeof (*test_blob2
)),
47 gcc_jit_global_set_initializer (glob
, test_blob2
,
50 for (size_t i
= 0; i
< BIG_BLOB_SIZE
; i
++)
51 test_blob3
[i
] = i
* i
+ i
;
53 gcc_jit_context_new_global (
54 ctxt
, NULL
, GCC_JIT_GLOBAL_EXPORTED
,
55 gcc_jit_context_new_array_type (ctxt
, NULL
, unsigned_char_type
,
58 gcc_jit_global_set_initializer (glob
, test_blob3
, sizeof (test_blob3
));
62 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
64 CHECK_NON_NULL (result
);
65 void *glob
= gcc_jit_result_get_global (result
, "bin_blob1");
66 CHECK_NON_NULL (glob
);
67 CHECK_VALUE (memcmp (test_blob1
, glob
, sizeof (test_blob1
)), 0);
69 glob
= gcc_jit_result_get_global (result
, "bin_blob2");
70 CHECK_NON_NULL (glob
);
71 CHECK_VALUE (memcmp (test_blob2
, glob
,
72 sizeof (test_blob2
)), 0);
74 glob
= gcc_jit_result_get_global (result
, "bin_blob3");
75 CHECK_NON_NULL (glob
);
76 CHECK_VALUE (memcmp (test_blob3
, glob
, sizeof (test_blob3
)), 0);