Ruby
2.5.0dev(2017-10-22revision60238)
ext
fiddle
fiddle.h
Go to the documentation of this file.
1
#ifndef FIDDLE_H
2
#define FIDDLE_H
3
4
#include <
ruby.h
>
5
#include <errno.h>
6
7
#if defined(_WIN32)
8
#include <windows.h>
9
#endif
10
11
#ifdef HAVE_SYS_MMAN_H
12
#include <sys/mman.h>
13
#endif
14
15
#if defined(HAVE_DLFCN_H)
16
# include <dlfcn.h>
17
#
/* some stranger systems may not define all of these */
18
#ifndef RTLD_LAZY
19
#define RTLD_LAZY 0
20
#endif
21
#ifndef RTLD_GLOBAL
22
#define RTLD_GLOBAL 0
23
#endif
24
#ifndef RTLD_NOW
25
#define RTLD_NOW 0
26
#endif
27
#else
28
# if defined(_WIN32)
29
# include <windows.h>
30
# define dlopen(name,flag) ((void*)LoadLibrary(name))
31
# define dlerror() strerror(rb_w32_map_errno(GetLastError()))
32
# define dlsym(handle,name) ((void*)GetProcAddress((handle),(name)))
33
# define RTLD_LAZY -1
34
# define RTLD_NOW -1
35
# define RTLD_GLOBAL -1
36
# endif
37
#endif
38
39
#ifdef USE_HEADER_HACKS
40
#include <ffi/ffi.h>
41
#else
42
#include <ffi.h>
43
#endif
44
45
#undef ffi_type_uchar
46
#undef ffi_type_schar
47
#undef ffi_type_ushort
48
#undef ffi_type_sshort
49
#undef ffi_type_uint
50
#undef ffi_type_sint
51
#undef ffi_type_ulong
52
#undef ffi_type_slong
53
54
#if CHAR_BIT == 8
55
# define ffi_type_uchar ffi_type_uint8
56
# define ffi_type_schar ffi_type_sint8
57
#else
58
# error "CHAR_BIT not supported"
59
#endif
60
61
# if SIZEOF_SHORT == 2
62
# define ffi_type_ushort ffi_type_uint16
63
# define ffi_type_sshort ffi_type_sint16
64
# elif SIZEOF_SHORT == 4
65
# define ffi_type_ushort ffi_type_uint32
66
# define ffi_type_sshort ffi_type_sint32
67
# else
68
# error "short size not supported"
69
# endif
70
71
# if SIZEOF_INT == 2
72
# define ffi_type_uint ffi_type_uint16
73
# define ffi_type_sint ffi_type_sint16
74
# elif SIZEOF_INT == 4
75
# define ffi_type_uint ffi_type_uint32
76
# define ffi_type_sint ffi_type_sint32
77
# elif SIZEOF_INT == 8
78
# define ffi_type_uint ffi_type_uint64
79
# define ffi_type_sint ffi_type_sint64
80
# else
81
# error "int size not supported"
82
# endif
83
84
# if SIZEOF_LONG == 4
85
# define ffi_type_ulong ffi_type_uint32
86
# define ffi_type_slong ffi_type_sint32
87
# elif SIZEOF_LONG == 8
88
# define ffi_type_ulong ffi_type_uint64
89
# define ffi_type_slong ffi_type_sint64
90
# else
91
# error "long size not supported"
92
# endif
93
94
#if HAVE_LONG_LONG
95
# if SIZEOF_LONG_LONG == 8
96
# define ffi_type_slong_long ffi_type_sint64
97
# define ffi_type_ulong_long ffi_type_uint64
98
# else
99
# error "long long size not supported"
100
# endif
101
#endif
102
103
#include <
closure.h
>
104
#include <
conversions.h
>
105
#include <
function.h
>
106
107
#define TYPE_VOID 0
108
#define TYPE_VOIDP 1
109
#define TYPE_CHAR 2
110
#define TYPE_SHORT 3
111
#define TYPE_INT 4
112
#define TYPE_LONG 5
113
#if HAVE_LONG_LONG
114
#define TYPE_LONG_LONG 6
115
#endif
116
#define TYPE_FLOAT 7
117
#define TYPE_DOUBLE 8
118
119
#define ALIGN_OF(type) offsetof(struct {char align_c; type align_x;}, align_x)
120
121
#define ALIGN_VOIDP ALIGN_OF(void*)
122
#define ALIGN_SHORT ALIGN_OF(short)
123
#define ALIGN_CHAR ALIGN_OF(char)
124
#define ALIGN_INT ALIGN_OF(int)
125
#define ALIGN_LONG ALIGN_OF(long)
126
#if HAVE_LONG_LONG
127
#define ALIGN_LONG_LONG ALIGN_OF(LONG_LONG)
128
#endif
129
#define ALIGN_FLOAT ALIGN_OF(float)
130
#define ALIGN_DOUBLE ALIGN_OF(double)
131
132
extern
VALUE
mFiddle
;
133
extern
VALUE
rb_eFiddleError
;
134
135
VALUE
rb_fiddle_new_function
(
VALUE
address,
VALUE
arg_types,
VALUE
ret_type);
136
137
#endif
138
/* vim: set noet sws=4 sw=4: */
rb_eFiddleError
VALUE rb_eFiddleError
Definition:
fiddle.c:4
function.h
ruby.h
closure.h
conversions.h
mFiddle
VALUE mFiddle
Definition:
fiddle.c:3
VALUE
unsigned long VALUE
Definition:
ruby.h:85
rb_fiddle_new_function
VALUE rb_fiddle_new_function(VALUE address, VALUE arg_types, VALUE ret_type)
Definition:
function.c:67
Generated by
1.8.13