100
107
rbdl_id_cdecl = rb_intern_const("cdecl");
101
108
rbdl_id_stdcall = rb_intern_const("stdcall");
110
/* Document-module: DL
112
* A bridge to the dlopen() or dynamic library linker function.
116
* bash $> cat > sum.c <<EOF
117
* double sum(double *arry, int len)
121
* for(i = 0; i < len; i++){
122
* ret = ret + arry[i];
127
* double split(double num)
134
* bash $> gcc -o libsum.so -shared sum.c
135
* bash $> cat > sum.rb <<EOF
137
* require 'dl/import'
140
* extend DL::Importer
141
* dlload './libsum.so'
142
* extern 'double sum(double*, int)'
143
* extern 'double split(double)'
146
* a = [2.0, 3.0, 4.0]
148
* sum = LibSum.sum(a.pack("d*"), a.count)
149
* p LibSum.split(sum)
151
* bash $> ruby sum.rb
103
156
rb_mDL = rb_define_module("DL");
159
* Document-class: DL::DLError
161
* standard dynamic load exception
104
163
rb_eDLError = rb_define_class_under(rb_mDL, "DLError", rb_eStandardError);
166
* Document-class: DL::DLTypeError
168
* dynamic load incorrect type exception
105
170
rb_eDLTypeError = rb_define_class_under(rb_mDL, "DLTypeError", rb_eDLError);
172
/* Document-const: MAX_CALLBACK
174
* Maximum number of callbacks
107
176
rb_define_const(rb_mDL, "MAX_CALLBACK", INT2NUM(MAX_CALLBACK));
178
/* Document-const: DLSTACK_SIZE
180
* Dynamic linker stack size
108
182
rb_define_const(rb_mDL, "DLSTACK_SIZE", INT2NUM(DLSTACK_SIZE));
110
184
rb_dl_init_callbacks(rb_mDL);
186
/* Document-const: RTLD_GLOBAL
188
* rtld DL::Handle flag.
190
* The symbols defined by this library will be made available for symbol
191
* resolution of subsequently loaded libraries.
112
193
rb_define_const(rb_mDL, "RTLD_GLOBAL", INT2NUM(RTLD_GLOBAL));
195
/* Document-const: RTLD_LAZY
197
* rtld DL::Handle flag.
199
* Perform lazy binding. Only resolve symbols as the code that references
200
* them is executed. If the symbol is never referenced, then it is never
201
* resolved. (Lazy binding is only performed for function references;
202
* references to variables are always immediately bound when the library
113
205
rb_define_const(rb_mDL, "RTLD_LAZY", INT2NUM(RTLD_LAZY));
207
/* Document-const: RTLD_NOW
209
* rtld DL::Handle flag.
211
* If this value is specified or the environment variable LD_BIND_NOW is
212
* set to a nonempty string, all undefined symbols in the library are
213
* resolved before dlopen() returns. If this cannot be done an error is
114
216
rb_define_const(rb_mDL, "RTLD_NOW", INT2NUM(RTLD_NOW));
218
/* Document-const: TYPE_VOID
220
* DL::CFunc type - void
116
222
rb_define_const(rb_mDL, "TYPE_VOID", INT2NUM(DLTYPE_VOID));
224
/* Document-const: TYPE_VOIDP
226
* DL::CFunc type - void*
117
228
rb_define_const(rb_mDL, "TYPE_VOIDP", INT2NUM(DLTYPE_VOIDP));
230
/* Document-const: TYPE_CHAR
232
* DL::CFunc type - char
118
234
rb_define_const(rb_mDL, "TYPE_CHAR", INT2NUM(DLTYPE_CHAR));
236
/* Document-const: TYPE_SHORT
238
* DL::CFunc type - short
119
240
rb_define_const(rb_mDL, "TYPE_SHORT", INT2NUM(DLTYPE_SHORT));
242
/* Document-const: TYPE_INT
244
* DL::CFunc type - int
120
246
rb_define_const(rb_mDL, "TYPE_INT", INT2NUM(DLTYPE_INT));
248
/* Document-const: TYPE_LONG
250
* DL::CFunc type - long
121
252
rb_define_const(rb_mDL, "TYPE_LONG", INT2NUM(DLTYPE_LONG));
122
254
#if HAVE_LONG_LONG
255
/* Document-const: TYPE_LONG_LONG
257
* DL::CFunc type - long long
123
259
rb_define_const(rb_mDL, "TYPE_LONG_LONG", INT2NUM(DLTYPE_LONG_LONG));
262
/* Document-const: TYPE_FLOAT
264
* DL::CFunc type - float
125
266
rb_define_const(rb_mDL, "TYPE_FLOAT", INT2NUM(DLTYPE_FLOAT));
268
/* Document-const: TYPE_DOUBLE
270
* DL::CFunc type - double
126
272
rb_define_const(rb_mDL, "TYPE_DOUBLE", INT2NUM(DLTYPE_DOUBLE));
274
/* Document-const: ALIGN_VOIDP
276
* The Offset of a struct void* and a void*
128
278
rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));
280
/* Document-const: ALIGN_CHAR
282
* The Offset of a struct char and a char
129
284
rb_define_const(rb_mDL, "ALIGN_CHAR", INT2NUM(ALIGN_CHAR));
286
/* Document-const: ALIGN_SHORT
288
* The Offset of a struct short and a short
130
290
rb_define_const(rb_mDL, "ALIGN_SHORT", INT2NUM(ALIGN_SHORT));
292
/* Document-const: ALIGN_INT
294
* The Offset of a struct int and a int
131
296
rb_define_const(rb_mDL, "ALIGN_INT", INT2NUM(ALIGN_INT));
298
/* Document-const: ALIGN_LONG
300
* The Offset of a struct long and a long
132
302
rb_define_const(rb_mDL, "ALIGN_LONG", INT2NUM(ALIGN_LONG));
133
304
#if HAVE_LONG_LONG
305
/* Document-const: ALIGN_LONG_LONG
307
* The Offset of a struct long long and a long long
134
309
rb_define_const(rb_mDL, "ALIGN_LONG_LONG", INT2NUM(ALIGN_LONG_LONG));
312
/* Document-const: ALIGN_FLOAT
314
* The Offset of a struct float and a float
136
316
rb_define_const(rb_mDL, "ALIGN_FLOAT", INT2NUM(ALIGN_FLOAT));
318
/* Document-const: ALIGN_DOUBLE
320
* The Offset of a struct double and a double
137
322
rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
324
/* Document-const: SIZEOF_VOIDP
326
* OS Dependent - sizeof(void*)
139
328
rb_define_const(rb_mDL, "SIZEOF_VOIDP", INT2NUM(sizeof(void*)));
330
/* Document-const: SIZEOF_CHAR
332
* OS Dependent - sizeof(char)
140
334
rb_define_const(rb_mDL, "SIZEOF_CHAR", INT2NUM(sizeof(char)));
336
/* Document-const: SIZEOF_SHORT
338
* OS Dependent - sizeof(short)
141
340
rb_define_const(rb_mDL, "SIZEOF_SHORT", INT2NUM(sizeof(short)));
342
/* Document-const: SIZEOF_INT
344
* OS Dependent - sizeof(int)
142
346
rb_define_const(rb_mDL, "SIZEOF_INT", INT2NUM(sizeof(int)));
348
/* Document-const: SIZEOF_LONG
350
* OS Dependent - sizeof(long)
143
352
rb_define_const(rb_mDL, "SIZEOF_LONG", INT2NUM(sizeof(long)));
144
354
#if HAVE_LONG_LONG
355
/* Document-const: SIZEOF_LONG_LONG
357
* OS Dependent - sizeof(long long)
145
359
rb_define_const(rb_mDL, "SIZEOF_LONG_LONG", INT2NUM(sizeof(LONG_LONG)));
362
/* Document-const: SIZEOF_FLOAT
364
* OS Dependent - sizeof(float)
147
366
rb_define_const(rb_mDL, "SIZEOF_FLOAT", INT2NUM(sizeof(float)));
368
/* Document-const: SIZEOF_DOUBLE
370
* OS Dependent - sizeof(double)
148
372
rb_define_const(rb_mDL, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));
150
374
rb_define_module_function(rb_mDL, "dlwrap", rb_dl_value2ptr, 1);