alinta-ffi 1.9.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +49 -0
- data/LICENSE +24 -0
- data/README.md +112 -0
- data/Rakefile +243 -0
- data/ext/ffi_c/AbstractMemory.c +1109 -0
- data/ext/ffi_c/AbstractMemory.h +175 -0
- data/ext/ffi_c/ArrayType.c +162 -0
- data/ext/ffi_c/ArrayType.h +59 -0
- data/ext/ffi_c/Buffer.c +365 -0
- data/ext/ffi_c/Call.c +517 -0
- data/ext/ffi_c/Call.h +110 -0
- data/ext/ffi_c/ClosurePool.c +283 -0
- data/ext/ffi_c/ClosurePool.h +57 -0
- data/ext/ffi_c/DataConverter.c +91 -0
- data/ext/ffi_c/DynamicLibrary.c +339 -0
- data/ext/ffi_c/DynamicLibrary.h +98 -0
- data/ext/ffi_c/Function.c +998 -0
- data/ext/ffi_c/Function.h +87 -0
- data/ext/ffi_c/FunctionInfo.c +271 -0
- data/ext/ffi_c/LastError.c +184 -0
- data/ext/ffi_c/LastError.h +47 -0
- data/ext/ffi_c/LongDouble.c +63 -0
- data/ext/ffi_c/LongDouble.h +51 -0
- data/ext/ffi_c/MappedType.c +168 -0
- data/ext/ffi_c/MappedType.h +59 -0
- data/ext/ffi_c/MemoryPointer.c +197 -0
- data/ext/ffi_c/MemoryPointer.h +53 -0
- data/ext/ffi_c/MethodHandle.c +358 -0
- data/ext/ffi_c/MethodHandle.h +55 -0
- data/ext/ffi_c/Platform.c +129 -0
- data/ext/ffi_c/Platform.h +45 -0
- data/ext/ffi_c/Pointer.c +508 -0
- data/ext/ffi_c/Pointer.h +63 -0
- data/ext/ffi_c/Struct.c +829 -0
- data/ext/ffi_c/Struct.h +106 -0
- data/ext/ffi_c/StructByReference.c +190 -0
- data/ext/ffi_c/StructByReference.h +50 -0
- data/ext/ffi_c/StructByValue.c +150 -0
- data/ext/ffi_c/StructByValue.h +55 -0
- data/ext/ffi_c/StructLayout.c +698 -0
- data/ext/ffi_c/Thread.c +352 -0
- data/ext/ffi_c/Thread.h +95 -0
- data/ext/ffi_c/Type.c +397 -0
- data/ext/ffi_c/Type.h +62 -0
- data/ext/ffi_c/Types.c +139 -0
- data/ext/ffi_c/Types.h +89 -0
- data/ext/ffi_c/Variadic.c +304 -0
- data/ext/ffi_c/compat.h +78 -0
- data/ext/ffi_c/extconf.rb +71 -0
- data/ext/ffi_c/ffi.c +98 -0
- data/ext/ffi_c/libffi.bsd.mk +40 -0
- data/ext/ffi_c/libffi.darwin.mk +105 -0
- data/ext/ffi_c/libffi.gnu.mk +32 -0
- data/ext/ffi_c/libffi.mk +18 -0
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/rbffi.h +57 -0
- data/ext/ffi_c/rbffi_endian.h +59 -0
- data/ext/ffi_c/win32/stdbool.h +8 -0
- data/ext/ffi_c/win32/stdint.h +201 -0
- data/ffi.gemspec +23 -0
- data/gen/Rakefile +30 -0
- data/lib/ffi.rb +20 -0
- data/lib/ffi/autopointer.rb +203 -0
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -0
- data/lib/ffi/enum.rb +296 -0
- data/lib/ffi/errno.rb +43 -0
- data/lib/ffi/ffi.rb +44 -0
- data/lib/ffi/io.rb +62 -0
- data/lib/ffi/library.rb +590 -0
- data/lib/ffi/managedstruct.rb +84 -0
- data/lib/ffi/memorypointer.rb +1 -0
- data/lib/ffi/platform.rb +164 -0
- data/lib/ffi/platform/aarch64-linux/types.conf +104 -0
- data/lib/ffi/platform/arm-linux/types.conf +104 -0
- data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
- data/lib/ffi/platform/i386-darwin/types.conf +100 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-gnu/types.conf +107 -0
- data/lib/ffi/platform/i386-linux/types.conf +103 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
- data/lib/ffi/platform/i386-solaris/types.conf +122 -0
- data/lib/ffi/platform/i386-windows/types.conf +105 -0
- data/lib/ffi/platform/ia64-linux/types.conf +104 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
- data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
- data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
- data/lib/ffi/platform/sparc64-linux/types.conf +102 -0
- data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
- data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
- data/lib/ffi/platform/x86_64-darwin/types.conf +126 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
- data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
- data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
- data/lib/ffi/platform/x86_64-windows/types.conf +120 -0
- data/lib/ffi/pointer.rb +161 -0
- data/lib/ffi/struct.rb +371 -0
- data/lib/ffi/struct_layout_builder.rb +227 -0
- data/lib/ffi/tools/const_generator.rb +229 -0
- data/lib/ffi/tools/generator.rb +60 -0
- data/lib/ffi/tools/generator_task.rb +36 -0
- data/lib/ffi/tools/struct_generator.rb +194 -0
- data/lib/ffi/tools/types_generator.rb +134 -0
- data/lib/ffi/types.rb +194 -0
- data/lib/ffi/union.rb +43 -0
- data/lib/ffi/variadic.rb +78 -0
- data/lib/ffi/version.rb +4 -0
- data/libtest/Benchmark.c +52 -0
- data/libtest/BoolTest.c +34 -0
- data/libtest/BufferTest.c +31 -0
- data/libtest/ClosureTest.c +205 -0
- data/libtest/EnumTest.c +51 -0
- data/libtest/FunctionTest.c +70 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +62 -0
- data/libtest/LastErrorTest.c +21 -0
- data/libtest/NumberTest.c +132 -0
- data/libtest/PointerTest.c +63 -0
- data/libtest/ReferenceTest.c +23 -0
- data/libtest/StringTest.c +34 -0
- data/libtest/StructTest.c +243 -0
- data/libtest/UnionTest.c +43 -0
- data/libtest/VariadicTest.c +99 -0
- data/spec/ffi/LICENSE.SPECS +22 -0
- data/spec/ffi/async_callback_spec.rb +35 -0
- data/spec/ffi/bitmask_spec.rb +575 -0
- data/spec/ffi/bool_spec.rb +32 -0
- data/spec/ffi/buffer_spec.rb +279 -0
- data/spec/ffi/callback_spec.rb +773 -0
- data/spec/ffi/custom_param_type.rb +37 -0
- data/spec/ffi/custom_type_spec.rb +74 -0
- data/spec/ffi/dup_spec.rb +52 -0
- data/spec/ffi/enum_spec.rb +423 -0
- data/spec/ffi/errno_spec.rb +20 -0
- data/spec/ffi/ffi_spec.rb +28 -0
- data/spec/ffi/fixtures/Benchmark.c +52 -0
- data/spec/ffi/fixtures/BitmaskTest.c +51 -0
- data/spec/ffi/fixtures/BoolTest.c +34 -0
- data/spec/ffi/fixtures/BufferTest.c +31 -0
- data/spec/ffi/fixtures/ClosureTest.c +205 -0
- data/spec/ffi/fixtures/EnumTest.c +51 -0
- data/spec/ffi/fixtures/FunctionTest.c +142 -0
- data/spec/ffi/fixtures/GNUmakefile +149 -0
- data/spec/ffi/fixtures/GlobalVariable.c +62 -0
- data/spec/ffi/fixtures/LastErrorTest.c +21 -0
- data/spec/ffi/fixtures/NumberTest.c +132 -0
- data/spec/ffi/fixtures/PipeHelper.h +21 -0
- data/spec/ffi/fixtures/PipeHelperPosix.c +41 -0
- data/spec/ffi/fixtures/PipeHelperWindows.c +72 -0
- data/spec/ffi/fixtures/PointerTest.c +63 -0
- data/spec/ffi/fixtures/ReferenceTest.c +23 -0
- data/spec/ffi/fixtures/StringTest.c +34 -0
- data/spec/ffi/fixtures/StructTest.c +243 -0
- data/spec/ffi/fixtures/UnionTest.c +43 -0
- data/spec/ffi/fixtures/VariadicTest.c +99 -0
- data/spec/ffi/fixtures/classes.rb +438 -0
- data/spec/ffi/function_spec.rb +97 -0
- data/spec/ffi/io_spec.rb +16 -0
- data/spec/ffi/library_spec.rb +286 -0
- data/spec/ffi/long_double.rb +30 -0
- data/spec/ffi/managed_struct_spec.rb +68 -0
- data/spec/ffi/memorypointer_spec.rb +78 -0
- data/spec/ffi/number_spec.rb +247 -0
- data/spec/ffi/platform_spec.rb +114 -0
- data/spec/ffi/pointer_spec.rb +285 -0
- data/spec/ffi/rbx/attach_function_spec.rb +34 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +198 -0
- data/spec/ffi/rbx/spec_helper.rb +6 -0
- data/spec/ffi/rbx/struct_spec.rb +18 -0
- data/spec/ffi/spec_helper.rb +93 -0
- data/spec/ffi/string_spec.rb +118 -0
- data/spec/ffi/strptr_spec.rb +50 -0
- data/spec/ffi/struct_by_ref_spec.rb +43 -0
- data/spec/ffi/struct_callback_spec.rb +69 -0
- data/spec/ffi/struct_initialize_spec.rb +35 -0
- data/spec/ffi/struct_packed_spec.rb +50 -0
- data/spec/ffi/struct_spec.rb +882 -0
- data/spec/ffi/typedef_spec.rb +91 -0
- data/spec/ffi/union_spec.rb +67 -0
- data/spec/ffi/variadic_spec.rb +132 -0
- data/spec/spec.opts +4 -0
- metadata +309 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015 Lars Kanis. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef PIPEHELPER_H
|
8
|
+
#define PIPEHELPER_H
|
9
|
+
|
10
|
+
#ifdef _WIN32
|
11
|
+
#define FD_TYPE HANDLE
|
12
|
+
#else
|
13
|
+
#define FD_TYPE int
|
14
|
+
#endif
|
15
|
+
|
16
|
+
int pipeHelperCreatePipe(FD_TYPE pipefd[2]);
|
17
|
+
char pipeHelperReadChar(FD_TYPE fd, int timeout);
|
18
|
+
int pipeHelperWriteChar(FD_TYPE fd, char c);
|
19
|
+
void pipeHelperClosePipe(FD_TYPE fd);
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015 Lars Kanis. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef _WIN32
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <sys/time.h>
|
10
|
+
#include "PipeHelper.h"
|
11
|
+
|
12
|
+
int pipeHelperCreatePipe(FD_TYPE pipefd[2])
|
13
|
+
{
|
14
|
+
return pipe(pipefd);
|
15
|
+
}
|
16
|
+
|
17
|
+
char pipeHelperReadChar(FD_TYPE fd, int timeout)
|
18
|
+
{
|
19
|
+
char d;
|
20
|
+
struct timeval time = {timeout, 0}; // timeout after x seconds
|
21
|
+
fd_set read_fds;
|
22
|
+
FD_ZERO(&read_fds);
|
23
|
+
FD_SET(fd, &read_fds);
|
24
|
+
|
25
|
+
if(select(fd + 1, &read_fds, NULL, NULL, &time) <= 0)
|
26
|
+
return 0;
|
27
|
+
|
28
|
+
if( read(fd, &d, 1) != 1)
|
29
|
+
return 0;
|
30
|
+
return d;
|
31
|
+
}
|
32
|
+
|
33
|
+
int pipeHelperWriteChar(FD_TYPE fd, char c)
|
34
|
+
{
|
35
|
+
return write(fd, &c, 1);
|
36
|
+
}
|
37
|
+
|
38
|
+
void pipeHelperClosePipe(FD_TYPE fd) {
|
39
|
+
close(fd);
|
40
|
+
}
|
41
|
+
#endif
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifdef _WIN32
|
8
|
+
#include <windows.h>
|
9
|
+
#include "PipeHelper.h"
|
10
|
+
|
11
|
+
int pipeHelperCreatePipe(FD_TYPE pipefd[2])
|
12
|
+
{
|
13
|
+
char name[ MAX_PATH ];
|
14
|
+
static int pipe_idx = 0;
|
15
|
+
sprintf( name, "\\\\.\\Pipe\\pipeHelper-%u-%i",
|
16
|
+
(unsigned int)GetCurrentProcessId(), pipe_idx++ );
|
17
|
+
|
18
|
+
pipefd[0] = CreateNamedPipe( name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
|
19
|
+
PIPE_TYPE_BYTE | PIPE_WAIT,
|
20
|
+
1, // Number of pipes
|
21
|
+
5, // Out buffer size
|
22
|
+
5, // In buffer size
|
23
|
+
60 * 1000, // Timeout in ms
|
24
|
+
NULL );
|
25
|
+
if(pipefd[0] == INVALID_HANDLE_VALUE)
|
26
|
+
return -1;
|
27
|
+
|
28
|
+
pipefd[1] = CreateFile( name, GENERIC_WRITE, 0, NULL,
|
29
|
+
OPEN_EXISTING,
|
30
|
+
FILE_ATTRIBUTE_NORMAL,
|
31
|
+
NULL);
|
32
|
+
|
33
|
+
if(pipefd[1] == INVALID_HANDLE_VALUE) {
|
34
|
+
CloseHandle( pipefd[0] );
|
35
|
+
return -1;
|
36
|
+
}
|
37
|
+
return 0;
|
38
|
+
}
|
39
|
+
|
40
|
+
char pipeHelperReadChar(FD_TYPE fd, int timeout)
|
41
|
+
{
|
42
|
+
char d;
|
43
|
+
OVERLAPPED ovl;
|
44
|
+
ZeroMemory(&ovl, sizeof(ovl));
|
45
|
+
ovl.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
46
|
+
if( ReadFile(fd, &d, 1, NULL, &ovl) == 0) {
|
47
|
+
DWORD recvd = 0;;
|
48
|
+
DWORD res = WaitForSingleObject(ovl.hEvent, timeout * 1000);
|
49
|
+
if( res != WAIT_OBJECT_0 ) {
|
50
|
+
CloseHandle(ovl.hEvent);
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
if( GetOverlappedResult(fd, &ovl, &recvd, FALSE) == 0 ) {
|
54
|
+
CloseHandle(ovl.hEvent);
|
55
|
+
return 0;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
CloseHandle(ovl.hEvent);
|
59
|
+
return d;
|
60
|
+
}
|
61
|
+
|
62
|
+
int pipeHelperWriteChar(FD_TYPE fd, char c)
|
63
|
+
{
|
64
|
+
DWORD written;
|
65
|
+
return WriteFile(fd, &c, 1, &written, NULL) == 0 ? 0 : 1;
|
66
|
+
}
|
67
|
+
|
68
|
+
void pipeHelperClosePipe(FD_TYPE fd) {
|
69
|
+
CloseHandle(fd);
|
70
|
+
}
|
71
|
+
|
72
|
+
#endif
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <sys/types.h>
|
8
|
+
#include <sys/param.h>
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <string.h>
|
13
|
+
typedef void* ptr;
|
14
|
+
typedef void* pointer;
|
15
|
+
#ifdef _WIN32
|
16
|
+
typedef char* caddr_t;
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#define RET(T) T ptr_ret_##T(void* arg1, int offset) { \
|
20
|
+
T tmp; memcpy(&tmp, (caddr_t) arg1 + offset, sizeof(tmp)); return tmp; \
|
21
|
+
}
|
22
|
+
#define SET(T) void ptr_set_##T(void* arg1, int offset, T value) { \
|
23
|
+
memcpy((caddr_t) arg1 + offset, &value, sizeof(value)); \
|
24
|
+
}
|
25
|
+
#define TEST(T) SET(T) RET(T)
|
26
|
+
|
27
|
+
TEST(int8_t);
|
28
|
+
TEST(int16_t);
|
29
|
+
TEST(int32_t);
|
30
|
+
TEST(int64_t);
|
31
|
+
TEST(float);
|
32
|
+
TEST(double);
|
33
|
+
TEST(pointer);
|
34
|
+
|
35
|
+
void*
|
36
|
+
ptr_return_array_element(void **ptrArray, int arrayIndex)
|
37
|
+
{
|
38
|
+
return ptrArray[arrayIndex];
|
39
|
+
}
|
40
|
+
|
41
|
+
void
|
42
|
+
ptr_set_array_element(void **ptrArray, int arrayIndex, void *value)
|
43
|
+
{
|
44
|
+
ptrArray[arrayIndex] = value;
|
45
|
+
}
|
46
|
+
|
47
|
+
void*
|
48
|
+
ptr_malloc(int size)
|
49
|
+
{
|
50
|
+
return calloc(1, size);
|
51
|
+
}
|
52
|
+
void
|
53
|
+
ptr_free(void* ptr)
|
54
|
+
{
|
55
|
+
free(ptr);
|
56
|
+
}
|
57
|
+
|
58
|
+
void*
|
59
|
+
ptr_from_address(uintptr_t addr)
|
60
|
+
{
|
61
|
+
return (void *) addr;
|
62
|
+
}
|
63
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdint.h>
|
8
|
+
|
9
|
+
#define REF(T) void ref_##T(T arg, T* result) { *result = arg; }
|
10
|
+
#define ADD(T) void ref_add_##T(T arg1, T arg2, T* result) { *result = arg1 + arg2; }
|
11
|
+
#define SUB(T) void ref_sub_##T(T arg1, T arg2, T* result) { *result = arg1 - arg2; }
|
12
|
+
#define MUL(T) void ref_mul_##T(T arg1, T arg2, T* result) { *result = arg1 * arg2; }
|
13
|
+
#define DIV(T) void ref_div_##T(T arg1, T arg2, T* result) { *result = arg1 / arg2; }
|
14
|
+
#define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) REF(T)
|
15
|
+
|
16
|
+
TEST(int8_t);
|
17
|
+
TEST(int16_t);
|
18
|
+
TEST(int32_t);
|
19
|
+
TEST(int64_t);
|
20
|
+
TEST(float);
|
21
|
+
TEST(double);
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* For licensing, see LICENSE.SPECS
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <string.h>
|
8
|
+
|
9
|
+
int
|
10
|
+
string_equals(const char* s1, const char* s2)
|
11
|
+
{
|
12
|
+
return strcmp(s1, s2) == 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
void
|
16
|
+
string_set(char* s1, const char* s2)
|
17
|
+
{
|
18
|
+
strcpy(s1, s2);
|
19
|
+
}
|
20
|
+
void
|
21
|
+
string_concat(char* dst, const char* src)
|
22
|
+
{
|
23
|
+
strcat(dst, src);
|
24
|
+
}
|
25
|
+
void
|
26
|
+
string_dummy(char* dummy)
|
27
|
+
{
|
28
|
+
}
|
29
|
+
const char*
|
30
|
+
string_null(void)
|
31
|
+
{
|
32
|
+
return NULL;
|
33
|
+
}
|
34
|
+
|
@@ -0,0 +1,243 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner.
|
3
|
+
* Copyright (c) 2009 Andrea Fazzi <andrea.fazzi@alcacoop.it>.
|
4
|
+
*
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* For licensing, see LICENSE.SPECS
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <stdbool.h>
|
13
|
+
#include <stdint.h>
|
14
|
+
#include <string.h>
|
15
|
+
#include <stdarg.h>
|
16
|
+
|
17
|
+
typedef char s8;
|
18
|
+
typedef short s16;
|
19
|
+
typedef int s32;
|
20
|
+
typedef long long s64;
|
21
|
+
typedef float f32;
|
22
|
+
typedef double f64;
|
23
|
+
|
24
|
+
typedef struct bugged_struct {
|
25
|
+
unsigned char visible;
|
26
|
+
unsigned int x;
|
27
|
+
unsigned int y;
|
28
|
+
short rx;
|
29
|
+
short ry;
|
30
|
+
unsigned char order;
|
31
|
+
unsigned char size;
|
32
|
+
} bugged_struct_t;
|
33
|
+
|
34
|
+
unsigned int
|
35
|
+
bugged_struct_size() {
|
36
|
+
return sizeof(bugged_struct_t);
|
37
|
+
}
|
38
|
+
|
39
|
+
struct test1 {
|
40
|
+
char b;
|
41
|
+
short s;
|
42
|
+
int i;
|
43
|
+
long long j;
|
44
|
+
long l;
|
45
|
+
float f;
|
46
|
+
double d;
|
47
|
+
char string[32];
|
48
|
+
};
|
49
|
+
|
50
|
+
struct struct_with_array {
|
51
|
+
char c;
|
52
|
+
int a[5];
|
53
|
+
};
|
54
|
+
|
55
|
+
struct nested {
|
56
|
+
int i;
|
57
|
+
};
|
58
|
+
|
59
|
+
struct container {
|
60
|
+
char first;
|
61
|
+
struct nested s;
|
62
|
+
};
|
63
|
+
|
64
|
+
int
|
65
|
+
struct_align_nested_struct(struct container* a) { return a->s.i; }
|
66
|
+
|
67
|
+
void*
|
68
|
+
struct_field_array(struct struct_with_array* s) { return &s->a; }
|
69
|
+
|
70
|
+
struct container*
|
71
|
+
struct_make_container_struct(int i)
|
72
|
+
{
|
73
|
+
static struct container cs;
|
74
|
+
memset(&cs, 0, sizeof(cs));
|
75
|
+
cs.first = 1;
|
76
|
+
cs.s.i = i;
|
77
|
+
return &cs;
|
78
|
+
}
|
79
|
+
|
80
|
+
#define T(x, type) \
|
81
|
+
type struct_field_##type(struct test1* t) { return t->x; } \
|
82
|
+
struct type##_align { char first; type value; }; \
|
83
|
+
type struct_align_##type(struct type##_align* a) { return a->value; }
|
84
|
+
|
85
|
+
T(b, s8);
|
86
|
+
T(s, s16);
|
87
|
+
T(i, s32);
|
88
|
+
T(j, s64);
|
89
|
+
T(f, f32);
|
90
|
+
T(d, f64);
|
91
|
+
T(l, long);
|
92
|
+
|
93
|
+
void
|
94
|
+
struct_set_string(struct test1* t, char* s)
|
95
|
+
{
|
96
|
+
strcpy(t->string, s);
|
97
|
+
}
|
98
|
+
|
99
|
+
struct test1*
|
100
|
+
struct_make_struct(char b, short s, int i, long long ll, float f, double d)
|
101
|
+
{
|
102
|
+
static struct test1 t;
|
103
|
+
memset(&t, 0, sizeof(t));
|
104
|
+
t.b = b;
|
105
|
+
t.s = s;
|
106
|
+
t.i = i;
|
107
|
+
t.j = ll;
|
108
|
+
t.f = f;
|
109
|
+
t.d = d;
|
110
|
+
return &t;
|
111
|
+
}
|
112
|
+
|
113
|
+
typedef int (*add_cb)(int a1, int a2);
|
114
|
+
typedef int (*sub_cb)(int a1, int a2);
|
115
|
+
struct test2 {
|
116
|
+
add_cb add_callback;
|
117
|
+
sub_cb sub_callback;
|
118
|
+
};
|
119
|
+
|
120
|
+
int
|
121
|
+
struct_call_add_cb(struct test2* t, int a1, int a2)
|
122
|
+
{
|
123
|
+
return t->add_callback(a1, a2);
|
124
|
+
}
|
125
|
+
|
126
|
+
int
|
127
|
+
struct_call_sub_cb(struct test2* t, int a1, int a2)
|
128
|
+
{
|
129
|
+
return t->sub_callback(a1, a2);
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
struct struct_with_array*
|
134
|
+
struct_make_struct_with_array(int a_0, int a_1, int a_2, int a_3, int a_4)
|
135
|
+
{
|
136
|
+
static struct struct_with_array s;
|
137
|
+
|
138
|
+
memset(&s, 0, sizeof(s));
|
139
|
+
|
140
|
+
s.a[0] = a_0;
|
141
|
+
s.a[1] = a_1;
|
142
|
+
s.a[2] = a_2;
|
143
|
+
s.a[3] = a_3;
|
144
|
+
s.a[4] = a_4;
|
145
|
+
|
146
|
+
return &s;
|
147
|
+
|
148
|
+
}
|
149
|
+
|
150
|
+
struct s8s32 {
|
151
|
+
char s8;
|
152
|
+
int s32;
|
153
|
+
};
|
154
|
+
|
155
|
+
struct s8s32
|
156
|
+
struct_return_s8s32()
|
157
|
+
{
|
158
|
+
struct s8s32 s;
|
159
|
+
s.s8 = 0x7f;
|
160
|
+
s.s32 = 0x12345678;
|
161
|
+
|
162
|
+
return s;
|
163
|
+
}
|
164
|
+
|
165
|
+
struct s8s32
|
166
|
+
struct_s8s32_set(char s8, int s32)
|
167
|
+
{
|
168
|
+
struct s8s32 s;
|
169
|
+
|
170
|
+
s.s8 = s8;
|
171
|
+
s.s32 = s32;
|
172
|
+
|
173
|
+
return s;
|
174
|
+
}
|
175
|
+
|
176
|
+
int
|
177
|
+
struct_s8s32_get_s8(struct s8s32 s)
|
178
|
+
{
|
179
|
+
return s.s8;
|
180
|
+
}
|
181
|
+
|
182
|
+
int
|
183
|
+
struct_s8s32_get_s32(struct s8s32 s)
|
184
|
+
{
|
185
|
+
return s.s32;
|
186
|
+
}
|
187
|
+
|
188
|
+
struct s8s32
|
189
|
+
struct_s8s32_ret_s8s32(struct s8s32 s)
|
190
|
+
{
|
191
|
+
return s;
|
192
|
+
}
|
193
|
+
|
194
|
+
// Pass a struct and an int arg, ensure the int arg is passed correctly
|
195
|
+
int
|
196
|
+
struct_s8s32_s32_ret_s32(struct s8s32 s, int s32)
|
197
|
+
{
|
198
|
+
return s32;
|
199
|
+
}
|
200
|
+
|
201
|
+
// Pass a struct and a long long arg, ensure the long long arg is passed correctly
|
202
|
+
long long
|
203
|
+
struct_s8s32_s64_ret_s64(struct s8s32 s, long long s64)
|
204
|
+
{
|
205
|
+
return s64;
|
206
|
+
}
|
207
|
+
|
208
|
+
// Pass a struct and a long long arg, ensure the long long arg is passed correctly
|
209
|
+
int
|
210
|
+
struct_s32_ptr_s32_s8s32_ret_s32(int s32a, void *ptr, int s32b, struct s8s32 s)
|
211
|
+
{
|
212
|
+
if (ptr != NULL) *(struct s8s32 *) ptr = s;
|
213
|
+
return s.s32;
|
214
|
+
}
|
215
|
+
|
216
|
+
// Pass a char *, copy into buffer length struct
|
217
|
+
struct struct_string {
|
218
|
+
char *bytes;
|
219
|
+
int len;
|
220
|
+
};
|
221
|
+
|
222
|
+
struct struct_string
|
223
|
+
struct_varargs_ret_struct_string(int len, ...)
|
224
|
+
{
|
225
|
+
struct struct_string ss;
|
226
|
+
va_list vl;
|
227
|
+
char* cp = NULL;
|
228
|
+
|
229
|
+
va_start(vl, len);
|
230
|
+
|
231
|
+
ss.len = len;
|
232
|
+
ss.bytes = va_arg(vl, char *);
|
233
|
+
if (ss.bytes != NULL) {
|
234
|
+
cp = malloc(strlen(ss.bytes) + 1);
|
235
|
+
strcpy(cp, ss.bytes);
|
236
|
+
ss.bytes = cp;
|
237
|
+
}
|
238
|
+
|
239
|
+
va_end(vl);
|
240
|
+
|
241
|
+
return ss;
|
242
|
+
}
|
243
|
+
|