ffi 1.2.0.pre1 → 1.2.0.pre2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright (c) 2009 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <sys/types.h>
22
+ #include <stdint.h>
23
+
24
+ typedef int8_t s8;
25
+ typedef uint8_t u8;
26
+ typedef int16_t s16;
27
+ typedef uint16_t u16;
28
+ typedef int32_t s32;
29
+ typedef uint32_t u32;
30
+ typedef int64_t s64;
31
+ typedef uint64_t u64;
32
+ typedef signed long sL;
33
+ typedef unsigned long uL;
34
+ typedef float f32;
35
+ typedef double f64;
36
+ #if !defined(__OpenBSD__)
37
+ typedef unsigned long ulong;
38
+ #endif
39
+ typedef void* pointer;
40
+ typedef void* P;
41
+
42
+ #define GVAR(T) \
43
+ extern T gvar_##T; \
44
+ T gvar_##T = (T) -1; \
45
+ T gvar_##T##_get() { return gvar_##T; }; \
46
+ void gvar_##T##_set(T v) { gvar_##T = v; }
47
+
48
+ GVAR(s8);
49
+ GVAR(u8);
50
+ GVAR(s16);
51
+ GVAR(u16);
52
+ GVAR(s32);
53
+ GVAR(u32);
54
+ GVAR(s64);
55
+ GVAR(u64);
56
+ GVAR(long);
57
+ GVAR(ulong);
58
+ GVAR(pointer);
59
+
60
+ struct gstruct {
61
+ long data;
62
+ };
63
+
64
+ struct gstruct gvar_gstruct = { -1 };
65
+
66
+ struct gstruct*
67
+ gvar_gstruct_get(void)
68
+ {
69
+ return &gvar_gstruct;
70
+ }
71
+
72
+ void
73
+ gvar_gstruct_set(const struct gstruct* val)
74
+ {
75
+ gvar_gstruct = *val;
76
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2008 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #if defined(_WIN32) || defined(__WIN32__)
22
+ # include <windows.h>
23
+ #else
24
+ # include <errno.h>
25
+ #endif
26
+
27
+ int setLastError(int error) {
28
+ #if defined(_WIN32) || defined(__WIN32__)
29
+ SetLastError(error);
30
+ #else
31
+ errno = error;
32
+ #endif
33
+ return -1;
34
+ }
35
+
@@ -0,0 +1,146 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <sys/types.h>
22
+ #include <stdio.h>
23
+ #include <string.h>
24
+ #include <stdint.h>
25
+
26
+ #if defined(__sparc) && defined(__sun__)
27
+ #define fix_mem_access __asm("ta 6")
28
+ #else
29
+ #define fix_mem_access
30
+ #endif
31
+
32
+ typedef int8_t s8;
33
+ typedef uint8_t u8;
34
+ typedef int16_t s16;
35
+ typedef uint16_t u16;
36
+ typedef int32_t s32;
37
+ typedef uint32_t u32;
38
+ typedef int64_t s64;
39
+ typedef uint64_t u64;
40
+ typedef signed long sL;
41
+ typedef unsigned long uL;
42
+ typedef float f32;
43
+ typedef double f64;
44
+ typedef long double f128;
45
+ #if !defined(__OpenBSD__)
46
+ typedef unsigned long ulong;
47
+ #endif
48
+
49
+ #define ADD(T) T add_##T(T arg1, T arg2) { return arg1 + arg2; }
50
+ #define SUB(T) T sub_##T(T arg1, T arg2) { return arg1 - arg2; }
51
+ #define MUL(T) T mul_##T(T arg1, T arg2) { return arg1 * arg2; }
52
+ #define DIV(T) T div_##T(T arg1, T arg2) { return arg1 / arg2; }
53
+ #define RET(T) T ret_##T(T arg1) { return arg1; }
54
+ #define SET(T) static T T##_;void set_##T(T arg1) { T##_ = arg1; }
55
+ #define GET(T) T get_##T() { return T##_; }
56
+ typedef char* ptr;
57
+ #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) RET(T) SET(T) GET(T)
58
+ TEST(s8);
59
+ TEST(u8);
60
+ TEST(s16);
61
+ TEST(u16);
62
+ TEST(s32);
63
+ TEST(u32);
64
+ TEST(s64);
65
+ TEST(u64);
66
+ TEST(float);
67
+ TEST(double);
68
+ TEST(long);
69
+ TEST(ulong);
70
+ TEST(f128);
71
+
72
+ #define ADD2(R, T1, T2) R add_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 + arg2; }
73
+ #define SUB2(R, T1, T2) R sub_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 - arg2; }
74
+ #define MUL2(R, T1, T2) R mul_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 * arg2; }
75
+ #define DIV2(R, T1, T2) R div_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 / arg2; }
76
+
77
+ #define T2__(R, T1, T2) ADD2(R, T1, T2) SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2)
78
+ #define T2_(R, T1) \
79
+ T2__(R, T1, s8) T2__(R, T1, u8) \
80
+ T2__(R, T1, s16) T2__(R, T1, u16) \
81
+ T2__(R, T1, s32) T2__(R, T1, u32) \
82
+ T2__(R, T1, sL) T2__(R, T1, uL) \
83
+ T2__(R, T1, s64) T2__(R, T1, u64) \
84
+
85
+ #define TEST2(R) \
86
+ T2_(R, s8) T2_(R, u8) T2_(R, s16) T2_(R, u16) T2_(R, s32) T2_(R, u32) \
87
+ T2_(R, sL) T2_(R, uL) T2_(R, s64) T2_(R, u64)
88
+
89
+ #ifdef notyet
90
+ TEST2(s32)
91
+ TEST2(u32)
92
+ TEST2(s64)
93
+ TEST2(u64)
94
+ #endif
95
+
96
+ #define ADD3(R, T1, T2, T3) R add_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3) { return arg1 + arg2 + arg3; }
97
+ #define pack_f32(buf, v) do { float f = v; memcpy((buf), &f, sizeof(f)); } while(0)
98
+ #define pack_f64(buf, v) do { double f = v; memcpy((buf), &f, sizeof(f)); } while(0)
99
+ #define pack_int(buf, v) do { *(buf) = v; } while(0)
100
+ #define pack_s8 pack_int
101
+ #define pack_u8 pack_int
102
+ #define pack_s16 pack_int
103
+ #define pack_u16 pack_int
104
+ #define pack_s32 pack_int
105
+ #define pack_u32 pack_int
106
+ #define pack_s64 pack_int
107
+ #define pack_u64 pack_int
108
+ #define pack_sL pack_int
109
+ #define pack_uL pack_int
110
+
111
+ #define PACK3(R, T1, T2, T3) void pack_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3, R* r) { \
112
+ fix_mem_access; \
113
+ pack_##T1(&r[0], arg1); \
114
+ pack_##T2(&r[1], arg2); \
115
+ pack_##T3(&r[2], arg3); \
116
+ }
117
+
118
+ #define T3___(R, T1, T2, T3) PACK3(R, T1, T2, T3) /* SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) */
119
+ #define T3__(R, T1, T2) \
120
+ T3___(R, T1, T2, s8) T3___(R, T1, T2, u8) \
121
+ T3___(R, T1, T2, s16) T3___(R, T1, T2, u16) \
122
+ T3___(R, T1, T2, s32) T3___(R, T1, T2, u32) \
123
+ T3___(R, T1, T2, sL) T3___(R, T1, T2, uL) \
124
+ T3___(R, T1, T2, s64) T3___(R, T1, T2, u64) \
125
+ T3___(R, T1, T2, f32) T3___(R, T1, T2, f64) \
126
+
127
+ #define T3_(R, T1) \
128
+ T3__(R, T1, s8) T3__(R, T1, u8) \
129
+ T3__(R, T1, s16) T3__(R, T1, u16) \
130
+ T3__(R, T1, s32) T3__(R, T1, u32) \
131
+ T3__(R, T1, sL) T3__(R, T1, uL) \
132
+ T3__(R, T1, s64) T3__(R, T1, u64) \
133
+ T3__(R, T1, f32) T3__(R, T1, f64) \
134
+
135
+ #define TEST3(R) \
136
+ T3_(R, s8) T3_(R, u8) T3_(R, s16) T3_(R, u16) T3_(R, s32) T3_(R, u32) \
137
+ T3_(R, sL) T3_(R, uL) T3_(R, s64) T3_(R, u64) T3_(R, f32) T3_(R, f64)
138
+
139
+ TEST3(s64)
140
+
141
+ void
142
+ foo6(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5, intptr_t i6) { }
143
+
144
+ void
145
+ foo5(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5) { }
146
+
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <sys/types.h>
22
+ #include <sys/param.h>
23
+ #include <stdint.h>
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ typedef void* ptr;
28
+ typedef void* pointer;
29
+ #ifdef _WIN32
30
+ typedef char* caddr_t;
31
+ #endif
32
+
33
+ #define RET(T) T ptr_ret_##T(void* arg1, int offset) { \
34
+ T tmp; memcpy(&tmp, (caddr_t) arg1 + offset, sizeof(tmp)); return tmp; \
35
+ }
36
+ #define SET(T) void ptr_set_##T(void* arg1, int offset, T value) { \
37
+ memcpy((caddr_t) arg1 + offset, &value, sizeof(value)); \
38
+ }
39
+ #define TEST(T) SET(T) RET(T)
40
+
41
+ TEST(int8_t);
42
+ TEST(int16_t);
43
+ TEST(int32_t);
44
+ TEST(int64_t);
45
+ TEST(float);
46
+ TEST(double);
47
+ TEST(pointer);
48
+
49
+ void*
50
+ ptr_return_array_element(void **ptrArray, int arrayIndex)
51
+ {
52
+ return ptrArray[arrayIndex];
53
+ }
54
+
55
+ void
56
+ ptr_set_array_element(void **ptrArray, int arrayIndex, void *value)
57
+ {
58
+ ptrArray[arrayIndex] = value;
59
+ }
60
+
61
+ void*
62
+ ptr_malloc(int size)
63
+ {
64
+ return calloc(1, size);
65
+ }
66
+ void
67
+ ptr_free(void* ptr)
68
+ {
69
+ free(ptr);
70
+ }
71
+
72
+ void*
73
+ ptr_from_address(uintptr_t addr)
74
+ {
75
+ return (void *) addr;
76
+ }
77
+
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <stdint.h>
22
+
23
+ #define REF(T) void ref_##T(T arg, T* result) { *result = arg; }
24
+ #define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; }
25
+ #define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; }
26
+ #define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; }
27
+ #define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; }
28
+ #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T)
29
+
30
+ TEST(int8_t);
31
+ TEST(int16_t);
32
+ TEST(int32_t);
33
+ TEST(int64_t);
34
+ TEST(float);
35
+ TEST(double);
36
+
37
+
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <string.h>
22
+
23
+ int
24
+ string_equals(const char* s1, const char* s2)
25
+ {
26
+ return strcmp(s1, s2) == 0;
27
+ }
28
+
29
+ void
30
+ string_set(char* s1, const char* s2)
31
+ {
32
+ strcpy(s1, s2);
33
+ }
34
+ void
35
+ string_concat(char* dst, const char* src)
36
+ {
37
+ strcat(dst, src);
38
+ }
39
+ void
40
+ string_dummy(char* dummy)
41
+ {
42
+ }
43
+ const char*
44
+ string_null(void)
45
+ {
46
+ return NULL;
47
+ }
48
+
@@ -0,0 +1,254 @@
1
+ /*
2
+ * Copyright (c) 2007 Wayne Meissner. All rights reserved.
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of ruby-ffi.
7
+ *
8
+ * This code is free software: you can redistribute it and/or modify it under
9
+ * the terms of the GNU Lesser General Public License version 3 only, as
10
+ * published by the Free Software Foundation.
11
+ *
12
+ * This code is distributed in the hope that it will be useful, but WITHOUT
13
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
+ * version 3 for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+ #include <stdio.h>
22
+ #include <stdlib.h>
23
+ #include <stdbool.h>
24
+ #include <stdint.h>
25
+ #include <string.h>
26
+ #include <stdarg.h>
27
+
28
+ typedef char s8;
29
+ typedef short s16;
30
+ typedef int s32;
31
+ typedef long long s64;
32
+ typedef float f32;
33
+ typedef double f64;
34
+
35
+ typedef struct bugged_struct {
36
+ unsigned char visible;
37
+ unsigned int x;
38
+ unsigned int y;
39
+ short rx;
40
+ short ry;
41
+ unsigned char order;
42
+ unsigned char size;
43
+ } bugged_struct_t;
44
+
45
+ unsigned int
46
+ bugged_struct_size() {
47
+ return sizeof(bugged_struct_t);
48
+ }
49
+
50
+ struct test1 {
51
+ char b;
52
+ short s;
53
+ int i;
54
+ long long j;
55
+ long l;
56
+ float f;
57
+ double d;
58
+ char string[32];
59
+ };
60
+
61
+ struct struct_with_array {
62
+ char c;
63
+ int a[5];
64
+ };
65
+
66
+ struct nested {
67
+ int i;
68
+ };
69
+
70
+ struct container {
71
+ char first;
72
+ struct nested s;
73
+ };
74
+
75
+ int
76
+ struct_align_nested_struct(struct container* a) { return a->s.i; }
77
+
78
+ void*
79
+ struct_field_array(struct struct_with_array* s) { return &s->a; }
80
+
81
+ struct container*
82
+ struct_make_container_struct(int i)
83
+ {
84
+ static struct container cs;
85
+ memset(&cs, 0, sizeof(cs));
86
+ cs.first = 1;
87
+ cs.s.i = i;
88
+ return &cs;
89
+ }
90
+
91
+ #define T(x, type) \
92
+ type struct_field_##type(struct test1* t) { return t->x; } \
93
+ struct type##_align { char first; type value; }; \
94
+ type struct_align_##type(struct type##_align* a) { return a->value; }
95
+
96
+ T(b, s8);
97
+ T(s, s16);
98
+ T(i, s32);
99
+ T(j, s64);
100
+ T(f, f32);
101
+ T(d, f64);
102
+ T(l, long);
103
+
104
+ void
105
+ struct_set_string(struct test1* t, char* s)
106
+ {
107
+ strcpy(t->string, s);
108
+ }
109
+
110
+ struct test1*
111
+ struct_make_struct(char b, short s, int i, long long ll, float f, double d)
112
+ {
113
+ static struct test1 t;
114
+ memset(&t, 0, sizeof(t));
115
+ t.b = b;
116
+ t.s = s;
117
+ t.i = i;
118
+ t.j = ll;
119
+ t.f = f;
120
+ t.d = d;
121
+ return &t;
122
+ }
123
+
124
+ typedef int (*add_cb)(int a1, int a2);
125
+ typedef int (*sub_cb)(int a1, int a2);
126
+ struct test2 {
127
+ add_cb add_callback;
128
+ sub_cb sub_callback;
129
+ };
130
+
131
+ int
132
+ struct_call_add_cb(struct test2* t, int a1, int a2)
133
+ {
134
+ return t->add_callback(a1, a2);
135
+ }
136
+
137
+ int
138
+ struct_call_sub_cb(struct test2* t, int a1, int a2)
139
+ {
140
+ return t->sub_callback(a1, a2);
141
+ }
142
+
143
+
144
+ struct struct_with_array*
145
+ struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4)
146
+ {
147
+ static struct struct_with_array s;
148
+
149
+ memset(&s, 0, sizeof(s));
150
+
151
+ s.a[0] = a_0;
152
+ s.a[1] = a_1;
153
+ s.a[2] = a_2;
154
+ s.a[3] = a_3;
155
+ s.a[4] = a_4;
156
+
157
+ return &s;
158
+
159
+ }
160
+
161
+ struct s8s32 {
162
+ char s8;
163
+ int s32;
164
+ };
165
+
166
+ struct s8s32
167
+ struct_return_s8s32()
168
+ {
169
+ struct s8s32 s;
170
+ s.s8 = 0x7f;
171
+ s.s32 = 0x12345678;
172
+
173
+ return s;
174
+ }
175
+
176
+ struct s8s32
177
+ struct_s8s32_set(char s8, int s32)
178
+ {
179
+ struct s8s32 s;
180
+
181
+ s.s8 = s8;
182
+ s.s32 = s32;
183
+
184
+ return s;
185
+ }
186
+
187
+ int
188
+ struct_s8s32_get_s8(struct s8s32 s)
189
+ {
190
+ return s.s8;
191
+ }
192
+
193
+ int
194
+ struct_s8s32_get_s32(struct s8s32 s)
195
+ {
196
+ return s.s32;
197
+ }
198
+
199
+ struct s8s32
200
+ struct_s8s32_ret_s8s32(struct s8s32 s)
201
+ {
202
+ return s;
203
+ }
204
+
205
+ // Pass a struct and an int arg, ensure the int arg is passed correctly
206
+ int
207
+ struct_s8s32_s32_ret_s32(struct s8s32 s, int s32)
208
+ {
209
+ return s32;
210
+ }
211
+
212
+ // Pass a struct and a long long arg, ensure the long long arg is passed correctly
213
+ long long
214
+ struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64)
215
+ {
216
+ return s64;
217
+ }
218
+
219
+ // Pass a struct and a long long arg, ensure the long long arg is passed correctly
220
+ int
221
+ struct_s32_ptr_s32_s8s32_ret_s32(int s32a, void *ptr, int s32b, struct s8s32 s)
222
+ {
223
+ if (ptr != NULL) *(struct s8s32 *) ptr = s;
224
+ return s.s32;
225
+ }
226
+
227
+ // Pass a char *, copy into buffer length struct
228
+ struct struct_string {
229
+ char *bytes;
230
+ int len;
231
+ };
232
+
233
+ struct struct_string
234
+ struct_varargs_ret_struct_string(int len, ...)
235
+ {
236
+ struct struct_string ss;
237
+ va_list vl;
238
+ char* cp = NULL;
239
+
240
+ va_start(vl, len);
241
+
242
+ ss.len = len;
243
+ ss.bytes = va_arg(vl, char *);
244
+ if (ss.bytes != NULL) {
245
+ cp = malloc(strlen(ss.bytes) + 1);
246
+ strcpy(cp, ss.bytes);
247
+ ss.bytes = cp;
248
+ }
249
+
250
+ va_end(vl);
251
+
252
+ return ss;
253
+ }
254
+