11#include <stddef.h>
2+ #include <stdint.h>
23
34// See comments in build_native_lib()
45#define EXPORT __attribute__((visibility("default")))
56
67/* Test: test_increment_int */
78
8- EXPORT void increment_int (int * ptr ) {
9+ EXPORT void increment_int (int32_t * ptr ) {
910 * ptr += 1 ;
1011}
1112
1213/* Test: test_init_int */
1314
14- EXPORT void init_int (int * ptr , int val ) {
15+ EXPORT void init_int (int32_t * ptr , int32_t val ) {
1516 * ptr = val ;
1617}
1718
1819/* Test: test_init_array */
1920
20- EXPORT void init_array (int * array , size_t len , int val ) {
21+ EXPORT void init_array (int32_t * array , size_t len , int32_t val ) {
2122 for (size_t i = 0 ; i < len ; i ++ ) {
2223 array [i ] = val ;
2324 }
@@ -26,65 +27,83 @@ EXPORT void init_array(int *array, size_t len, int val) {
2627/* Test: test_init_static_inner */
2728
2829typedef struct SyncPtr {
29- int * ptr ;
30+ int32_t * ptr ;
3031} SyncPtr ;
3132
32- EXPORT void init_static_inner (const SyncPtr * s_ptr , int val ) {
33+ EXPORT void init_static_inner (const SyncPtr * s_ptr , int32_t val ) {
3334 * (s_ptr -> ptr ) = val ;
3435}
3536
3637/* Tests: test_exposed, test_pass_dangling */
3738
38- EXPORT void ignore_ptr (__attribute__((unused )) const int * ptr ) {
39+ EXPORT void ignore_ptr (__attribute__((unused )) const int32_t * ptr ) {
3940 return ;
4041}
4142
4243/* Test: test_expose_int */
43- EXPORT void expose_int (const int * int_ptr , const int * * pptr ) {
44+ EXPORT void expose_int (const int32_t * int_ptr , const int32_t * * pptr ) {
4445 * pptr = int_ptr ;
4546}
4647
4748/* Test: test_swap_ptr */
4849
49- EXPORT void swap_ptr (const int * * pptr0 , const int * * pptr1 ) {
50- const int * tmp = * pptr0 ;
50+ EXPORT void swap_ptr (const int32_t * * pptr0 , const int32_t * * pptr1 ) {
51+ const int32_t * tmp = * pptr0 ;
5152 * pptr0 = * pptr1 ;
5253 * pptr1 = tmp ;
5354}
5455
5556/* Test: test_swap_ptr_tuple */
5657
5758typedef struct Tuple {
58- int * ptr0 ;
59- int * ptr1 ;
59+ int32_t * ptr0 ;
60+ int32_t * ptr1 ;
6061} Tuple ;
6162
6263EXPORT void swap_ptr_tuple (Tuple * t_ptr ) {
63- int * tmp = t_ptr -> ptr0 ;
64+ int32_t * tmp = t_ptr -> ptr0 ;
6465 t_ptr -> ptr0 = t_ptr -> ptr1 ;
6566 t_ptr -> ptr1 = tmp ;
6667}
6768
6869/* Test: test_overwrite_dangling */
6970
70- EXPORT void overwrite_ptr (const int * * pptr ) {
71+ EXPORT void overwrite_ptr (const int32_t * * pptr ) {
7172 * pptr = NULL ;
7273}
7374
7475/* Test: test_swap_ptr_triple_dangling */
7576
7677typedef struct Triple {
77- int * ptr0 ;
78- int * ptr1 ;
79- int * ptr2 ;
78+ int32_t * ptr0 ;
79+ int32_t * ptr1 ;
80+ int32_t * ptr2 ;
8081} Triple ;
8182
8283EXPORT void swap_ptr_triple_dangling (Triple * t_ptr ) {
83- int * tmp = t_ptr -> ptr0 ;
84+ int32_t * tmp = t_ptr -> ptr0 ;
8485 t_ptr -> ptr0 = t_ptr -> ptr2 ;
8586 t_ptr -> ptr2 = tmp ;
8687}
8788
88- EXPORT const int * return_ptr (const int * ptr ) {
89+ EXPORT const int32_t * return_ptr (const int32_t * ptr ) {
8990 return ptr ;
9091}
92+
93+ /* Test: test_pass_ptr_as_int */
94+
95+ EXPORT void pass_ptr_as_int (uintptr_t ptr , int32_t set_to_val ) {
96+ * (int32_t * )ptr = set_to_val ;
97+ }
98+
99+ /* Test: test_pass_ptr_via_previously_shared_mem */
100+
101+ int32_t * * shared_place ;
102+
103+ EXPORT void set_shared_mem (int32_t * * ptr ) {
104+ shared_place = ptr ;
105+ }
106+
107+ EXPORT void init_ptr_stored_in_shared_mem (int32_t val ) {
108+ * * shared_place = val ;
109+ }
0 commit comments