blob: b54c5d86b210dde9164578ae7f3459063af57ce2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <stddef.h>
// See comments in build_native_lib()
#define EXPORT __attribute__((visibility("default")))
/* Test: test_increment_int */
EXPORT void increment_int(int *ptr) {
*ptr += 1;
}
/* Test: test_init_int */
EXPORT void init_int(int *ptr, int val) {
*ptr = val;
}
/* Test: test_init_array */
EXPORT void init_array(int *array, size_t len, int val) {
for (size_t i = 0; i < len; i++) {
array[i] = val;
}
}
/* Test: test_init_static_inner */
typedef struct SyncPtr {
int *ptr;
} SyncPtr;
EXPORT void init_static_inner(const SyncPtr *s_ptr, int val) {
*(s_ptr->ptr) = val;
}
/* Tests: test_exposed, test_pass_dangling */
EXPORT void ignore_ptr(__attribute__((unused)) const int *ptr) {
return;
}
/* Test: test_expose_int */
EXPORT void expose_int(const int *int_ptr, const int **pptr) {
*pptr = int_ptr;
}
/* Test: test_swap_ptr */
EXPORT void swap_ptr(const int **pptr0, const int **pptr1) {
const int *tmp = *pptr0;
*pptr0 = *pptr1;
*pptr1 = tmp;
}
/* Test: test_swap_ptr_tuple */
typedef struct Tuple {
int *ptr0;
int *ptr1;
} Tuple;
EXPORT void swap_ptr_tuple(Tuple *t_ptr) {
int *tmp = t_ptr->ptr0;
t_ptr->ptr0 = t_ptr->ptr1;
t_ptr->ptr1 = tmp;
}
/* Test: test_overwrite_dangling */
EXPORT void overwrite_ptr(const int **pptr) {
*pptr = NULL;
}
/* Test: test_swap_ptr_triple_dangling */
typedef struct Triple {
int *ptr0;
int *ptr1;
int *ptr2;
} Triple;
EXPORT void swap_ptr_triple_dangling(Triple *t_ptr) {
int *tmp = t_ptr->ptr0;
t_ptr->ptr0 = t_ptr->ptr2;
t_ptr->ptr2 = tmp;
}
EXPORT const int *return_ptr(const int *ptr) {
return ptr;
}
|