2010-05-06 02:59:24 -04:00
|
|
|
#include <fiddle.h>
|
|
|
|
|
|
|
|
VALUE mFiddle;
|
2020-08-02 17:26:40 -04:00
|
|
|
VALUE rb_eFiddleDLError;
|
2012-11-27 14:54:50 -05:00
|
|
|
VALUE rb_eFiddleError;
|
2010-05-06 02:59:24 -04:00
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
void Init_fiddle_pointer(void);
|
2020-08-02 17:26:40 -04:00
|
|
|
void Init_fiddle_pinned(void);
|
2012-11-27 14:54:50 -05:00
|
|
|
|
2021-07-14 02:38:55 -04:00
|
|
|
#ifdef HAVE_RUBY_MEMORY_VIEW_H
|
2020-12-10 19:41:12 -05:00
|
|
|
void Init_fiddle_memory_view(void);
|
|
|
|
#endif
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
/*
|
|
|
|
* call-seq: Fiddle.malloc(size)
|
|
|
|
*
|
|
|
|
* Allocate +size+ bytes of memory and return the integer memory address
|
|
|
|
* for the allocated memory.
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_fiddle_malloc(VALUE self, VALUE size)
|
|
|
|
{
|
|
|
|
void *ptr;
|
2020-11-16 16:04:00 -05:00
|
|
|
ptr = (void*)ruby_xcalloc(1, NUM2SIZET(size));
|
2012-11-27 14:54:50 -05:00
|
|
|
return PTR2NUM(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: Fiddle.realloc(addr, size)
|
|
|
|
*
|
|
|
|
* Change the size of the memory allocated at the memory location +addr+ to
|
|
|
|
* +size+ bytes. Returns the memory address of the reallocated memory, which
|
|
|
|
* may be different than the address passed in.
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_fiddle_realloc(VALUE self, VALUE addr, VALUE size)
|
|
|
|
{
|
|
|
|
void *ptr = NUM2PTR(addr);
|
|
|
|
|
2014-02-25 09:18:13 -05:00
|
|
|
ptr = (void*)ruby_xrealloc(ptr, NUM2SIZET(size));
|
2012-11-27 14:54:50 -05:00
|
|
|
return PTR2NUM(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: Fiddle.free(addr)
|
|
|
|
*
|
|
|
|
* Free the memory at address +addr+
|
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_fiddle_free(VALUE self, VALUE addr)
|
|
|
|
{
|
|
|
|
void *ptr = NUM2PTR(addr);
|
|
|
|
|
|
|
|
ruby_xfree(ptr);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: Fiddle.dlunwrap(addr)
|
|
|
|
*
|
|
|
|
* Returns the hexadecimal representation of a memory pointer address +addr+
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* lib = Fiddle.dlopen('/lib64/libc-2.15.so')
|
|
|
|
* => #<Fiddle::Handle:0x00000001342460>
|
|
|
|
*
|
|
|
|
* lib['strcpy'].to_s(16)
|
|
|
|
* => "7f59de6dd240"
|
|
|
|
*
|
|
|
|
* Fiddle.dlunwrap(Fiddle.dlwrap(lib['strcpy'].to_s(16)))
|
|
|
|
* => "7f59de6dd240"
|
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_fiddle_ptr2value(VALUE self, VALUE addr)
|
|
|
|
{
|
|
|
|
return (VALUE)NUM2PTR(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: Fiddle.dlwrap(val)
|
|
|
|
*
|
|
|
|
* Returns a memory pointer of a function's hexadecimal address location +val+
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* lib = Fiddle.dlopen('/lib64/libc-2.15.so')
|
|
|
|
* => #<Fiddle::Handle:0x00000001342460>
|
|
|
|
*
|
|
|
|
* Fiddle.dlwrap(lib['strcpy'].to_s(16))
|
|
|
|
* => 25522520
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_fiddle_value2ptr(VALUE self, VALUE val)
|
|
|
|
{
|
|
|
|
return PTR2NUM((void*)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init_fiddle_handle(void);
|
|
|
|
|
2012-02-09 10:15:57 -05:00
|
|
|
void
|
|
|
|
Init_fiddle(void)
|
2010-05-06 02:59:24 -04:00
|
|
|
{
|
2011-08-15 19:48:59 -04:00
|
|
|
/*
|
|
|
|
* Document-module: Fiddle
|
|
|
|
*
|
2012-11-27 18:26:07 -05:00
|
|
|
* A libffi wrapper for Ruby.
|
|
|
|
*
|
2011-08-15 19:48:59 -04:00
|
|
|
* == Description
|
|
|
|
*
|
2012-11-27 18:26:07 -05:00
|
|
|
* Fiddle is an extension to translate a foreign function interface (FFI)
|
|
|
|
* with ruby.
|
|
|
|
*
|
|
|
|
* It wraps {libffi}[http://sourceware.org/libffi/], a popular C library
|
|
|
|
* which provides a portable interface that allows code written in one
|
2013-05-24 08:27:12 -04:00
|
|
|
* language to call code written in another language.
|
2012-11-27 18:26:07 -05:00
|
|
|
*
|
|
|
|
* == Example
|
|
|
|
*
|
|
|
|
* Here we will use Fiddle::Function to wrap {floor(3) from
|
|
|
|
* libm}[http://linux.die.net/man/3/floor]
|
|
|
|
*
|
|
|
|
* require 'fiddle'
|
|
|
|
*
|
|
|
|
* libm = Fiddle.dlopen('/lib/libm.so.6')
|
|
|
|
*
|
|
|
|
* floor = Fiddle::Function.new(
|
|
|
|
* libm['floor'],
|
|
|
|
* [Fiddle::TYPE_DOUBLE],
|
|
|
|
* Fiddle::TYPE_DOUBLE
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* puts floor.call(3.14159) #=> 3.0
|
|
|
|
*
|
2011-08-15 19:48:59 -04:00
|
|
|
*
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
mFiddle = rb_define_module("Fiddle");
|
|
|
|
|
2020-08-02 17:26:40 -04:00
|
|
|
/*
|
|
|
|
* Document-class: Fiddle::Error
|
|
|
|
*
|
|
|
|
* Generic error class for Fiddle
|
|
|
|
*/
|
|
|
|
rb_eFiddleError = rb_define_class_under(mFiddle, "Error", rb_eStandardError);
|
|
|
|
|
2020-08-15 00:19:23 -04:00
|
|
|
/*
|
|
|
|
* Ruby installed by RubyInstaller for Windows always require
|
|
|
|
* bundled Fiddle because ruby_installer/runtime/dll_directory.rb
|
|
|
|
* requires Fiddle. It's used by
|
|
|
|
* rubygems/defaults/operating_system.rb. It means that the
|
|
|
|
* bundled Fiddle is always required on initialization.
|
|
|
|
*
|
|
|
|
* We just remove existing Fiddle::DLError here to override
|
|
|
|
* the bundled Fiddle.
|
|
|
|
*/
|
|
|
|
if (rb_const_defined(mFiddle, rb_intern("DLError"))) {
|
|
|
|
rb_const_remove(mFiddle, rb_intern("DLError"));
|
|
|
|
}
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
/*
|
|
|
|
* Document-class: Fiddle::DLError
|
|
|
|
*
|
|
|
|
* standard dynamic load exception
|
|
|
|
*/
|
2020-08-02 17:26:40 -04:00
|
|
|
rb_eFiddleDLError = rb_define_class_under(mFiddle, "DLError", rb_eFiddleError);
|
2012-11-27 14:54:50 -05:00
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
/* Document-const: TYPE_VOID
|
|
|
|
*
|
|
|
|
* C type - void
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_VOID", INT2NUM(TYPE_VOID));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_VOIDP
|
|
|
|
*
|
|
|
|
* C type - void*
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_VOIDP", INT2NUM(TYPE_VOIDP));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_CHAR
|
|
|
|
*
|
|
|
|
* C type - char
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_CHAR", INT2NUM(TYPE_CHAR));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_SHORT
|
|
|
|
*
|
|
|
|
* C type - short
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_SHORT", INT2NUM(TYPE_SHORT));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_INT
|
|
|
|
*
|
|
|
|
* C type - int
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_INT", INT2NUM(TYPE_INT));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_LONG
|
|
|
|
*
|
|
|
|
* C type - long
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_LONG", INT2NUM(TYPE_LONG));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
2010-05-06 02:59:24 -04:00
|
|
|
#if HAVE_LONG_LONG
|
2011-08-15 19:48:59 -04:00
|
|
|
/* Document-const: TYPE_LONG_LONG
|
|
|
|
*
|
|
|
|
* C type - long long
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_LONG_LONG", INT2NUM(TYPE_LONG_LONG));
|
|
|
|
#endif
|
2011-08-15 19:48:59 -04:00
|
|
|
|
2020-12-10 19:41:12 -05:00
|
|
|
#ifdef TYPE_INT8_T
|
|
|
|
/* Document-const: TYPE_INT8_T
|
|
|
|
*
|
|
|
|
* C type - int8_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_INT8_T", INT2NUM(TYPE_INT8_T));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TYPE_INT16_T
|
|
|
|
/* Document-const: TYPE_INT16_T
|
|
|
|
*
|
|
|
|
* C type - int16_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_INT16_T", INT2NUM(TYPE_INT16_T));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TYPE_INT32_T
|
|
|
|
/* Document-const: TYPE_INT32_T
|
|
|
|
*
|
|
|
|
* C type - int32_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_INT32_T", INT2NUM(TYPE_INT32_T));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TYPE_INT64_T
|
|
|
|
/* Document-const: TYPE_INT64_T
|
|
|
|
*
|
|
|
|
* C type - int64_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_INT64_T", INT2NUM(TYPE_INT64_T));
|
|
|
|
#endif
|
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
/* Document-const: TYPE_FLOAT
|
|
|
|
*
|
|
|
|
* C type - float
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_FLOAT", INT2NUM(TYPE_FLOAT));
|
2011-08-15 19:48:59 -04:00
|
|
|
|
|
|
|
/* Document-const: TYPE_DOUBLE
|
|
|
|
*
|
|
|
|
* C type - double
|
|
|
|
*/
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "TYPE_DOUBLE", INT2NUM(TYPE_DOUBLE));
|
|
|
|
|
2020-06-27 21:34:01 -04:00
|
|
|
#ifdef HAVE_FFI_PREP_CIF_VAR
|
2020-06-26 18:25:47 -04:00
|
|
|
/* Document-const: TYPE_VARIADIC
|
|
|
|
*
|
|
|
|
* C type - ...
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_VARIADIC", INT2NUM(TYPE_VARIADIC));
|
2020-06-27 21:34:01 -04:00
|
|
|
#endif
|
2020-06-26 18:25:47 -04:00
|
|
|
|
2020-07-09 07:19:20 -04:00
|
|
|
/* Document-const: TYPE_CONST_STRING
|
|
|
|
*
|
|
|
|
* C type - const char* ('\0' terminated const char*)
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_CONST_STRING", INT2NUM(TYPE_CONST_STRING));
|
|
|
|
|
2012-02-25 00:47:16 -05:00
|
|
|
/* Document-const: TYPE_SIZE_T
|
|
|
|
*
|
|
|
|
* C type - size_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_SIZE_T", INT2NUM(TYPE_SIZE_T));
|
|
|
|
|
|
|
|
/* Document-const: TYPE_SSIZE_T
|
|
|
|
*
|
|
|
|
* C type - ssize_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_SSIZE_T", INT2NUM(TYPE_SSIZE_T));
|
|
|
|
|
|
|
|
/* Document-const: TYPE_PTRDIFF_T
|
|
|
|
*
|
|
|
|
* C type - ptrdiff_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_PTRDIFF_T", INT2NUM(TYPE_PTRDIFF_T));
|
|
|
|
|
|
|
|
/* Document-const: TYPE_INTPTR_T
|
|
|
|
*
|
|
|
|
* C type - intptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_INTPTR_T", INT2NUM(TYPE_INTPTR_T));
|
|
|
|
|
|
|
|
/* Document-const: TYPE_UINTPTR_T
|
|
|
|
*
|
|
|
|
* C type - uintptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "TYPE_UINTPTR_T", INT2NUM(TYPE_UINTPTR_T));
|
|
|
|
|
2012-11-27 19:02:49 -05:00
|
|
|
/* Document-const: ALIGN_VOIDP
|
|
|
|
*
|
|
|
|
* The alignment size of a void*
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_CHAR
|
|
|
|
*
|
|
|
|
* The alignment size of a char
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_CHAR", INT2NUM(ALIGN_CHAR));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_SHORT
|
|
|
|
*
|
|
|
|
* The alignment size of a short
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_SHORT", INT2NUM(ALIGN_SHORT));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_INT
|
|
|
|
*
|
|
|
|
* The alignment size of an int
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INT", INT2NUM(ALIGN_INT));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_LONG
|
|
|
|
*
|
|
|
|
* The alignment size of a long
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_LONG", INT2NUM(ALIGN_LONG));
|
|
|
|
|
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
/* Document-const: ALIGN_LONG_LONG
|
|
|
|
*
|
|
|
|
* The alignment size of a long long
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_LONG_LONG", INT2NUM(ALIGN_LONG_LONG));
|
|
|
|
#endif
|
|
|
|
|
2020-12-10 19:41:12 -05:00
|
|
|
/* Document-const: ALIGN_INT8_T
|
|
|
|
*
|
|
|
|
* The alignment size of a int8_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INT8_T", INT2NUM(ALIGN_INT8_T));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_INT16_T
|
|
|
|
*
|
|
|
|
* The alignment size of a int16_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INT16_T", INT2NUM(ALIGN_INT16_T));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_INT32_T
|
|
|
|
*
|
|
|
|
* The alignment size of a int32_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INT32_T", INT2NUM(ALIGN_INT32_T));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_INT64_T
|
|
|
|
*
|
|
|
|
* The alignment size of a int64_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INT64_T", INT2NUM(ALIGN_INT64_T));
|
|
|
|
|
2012-11-27 19:02:49 -05:00
|
|
|
/* Document-const: ALIGN_FLOAT
|
|
|
|
*
|
|
|
|
* The alignment size of a float
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_FLOAT", INT2NUM(ALIGN_FLOAT));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_DOUBLE
|
|
|
|
*
|
|
|
|
* The alignment size of a double
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_SIZE_T
|
|
|
|
*
|
|
|
|
* The alignment size of a size_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_SIZE_T", INT2NUM(ALIGN_OF(size_t)));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_SSIZE_T
|
|
|
|
*
|
|
|
|
* The alignment size of a ssize_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_SSIZE_T", INT2NUM(ALIGN_OF(size_t))); /* same as size_t */
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_PTRDIFF_T
|
|
|
|
*
|
|
|
|
* The alignment size of a ptrdiff_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_PTRDIFF_T", INT2NUM(ALIGN_OF(ptrdiff_t)));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_INTPTR_T
|
|
|
|
*
|
|
|
|
* The alignment size of a intptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_INTPTR_T", INT2NUM(ALIGN_OF(intptr_t)));
|
|
|
|
|
|
|
|
/* Document-const: ALIGN_UINTPTR_T
|
|
|
|
*
|
|
|
|
* The alignment size of a uintptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "ALIGN_UINTPTR_T", INT2NUM(ALIGN_OF(uintptr_t)));
|
|
|
|
|
2011-08-15 19:48:59 -04:00
|
|
|
/* Document-const: WINDOWS
|
|
|
|
*
|
|
|
|
* Returns a boolean regarding whether the host is WIN32
|
|
|
|
*/
|
2011-01-04 22:13:18 -05:00
|
|
|
#if defined(_WIN32)
|
2010-05-06 02:59:24 -04:00
|
|
|
rb_define_const(mFiddle, "WINDOWS", Qtrue);
|
|
|
|
#else
|
|
|
|
rb_define_const(mFiddle, "WINDOWS", Qfalse);
|
|
|
|
#endif
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
/* Document-const: SIZEOF_VOIDP
|
|
|
|
*
|
|
|
|
* size of a void*
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_VOIDP", INT2NUM(sizeof(void*)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_CHAR
|
|
|
|
*
|
|
|
|
* size of a char
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_CHAR", INT2NUM(sizeof(char)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_SHORT
|
|
|
|
*
|
|
|
|
* size of a short
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_SHORT", INT2NUM(sizeof(short)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_INT
|
|
|
|
*
|
|
|
|
* size of an int
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INT", INT2NUM(sizeof(int)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_LONG
|
|
|
|
*
|
|
|
|
* size of a long
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_LONG", INT2NUM(sizeof(long)));
|
|
|
|
|
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
/* Document-const: SIZEOF_LONG_LONG
|
|
|
|
*
|
|
|
|
* size of a long long
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_LONG_LONG", INT2NUM(sizeof(LONG_LONG)));
|
|
|
|
#endif
|
|
|
|
|
2020-12-10 19:41:12 -05:00
|
|
|
/* Document-const: SIZEOF_INT8_T
|
|
|
|
*
|
|
|
|
* size of a int8_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INT8_T", INT2NUM(sizeof(int8_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_INT16_T
|
|
|
|
*
|
|
|
|
* size of a int16_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INT16_T", INT2NUM(sizeof(int16_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_INT32_T
|
|
|
|
*
|
|
|
|
* size of a int32_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INT32_T", INT2NUM(sizeof(int32_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_INT64_T
|
|
|
|
*
|
|
|
|
* size of a int64_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INT64_T", INT2NUM(sizeof(int64_t)));
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
/* Document-const: SIZEOF_FLOAT
|
|
|
|
*
|
|
|
|
* size of a float
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_FLOAT", INT2NUM(sizeof(float)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_DOUBLE
|
|
|
|
*
|
|
|
|
* size of a double
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_SIZE_T
|
|
|
|
*
|
|
|
|
* size of a size_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_SIZE_T", INT2NUM(sizeof(size_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_SSIZE_T
|
|
|
|
*
|
|
|
|
* size of a ssize_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_SSIZE_T", INT2NUM(sizeof(size_t))); /* same as size_t */
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_PTRDIFF_T
|
|
|
|
*
|
|
|
|
* size of a ptrdiff_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_PTRDIFF_T", INT2NUM(sizeof(ptrdiff_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_INTPTR_T
|
|
|
|
*
|
|
|
|
* size of a intptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_INTPTR_T", INT2NUM(sizeof(intptr_t)));
|
|
|
|
|
|
|
|
/* Document-const: SIZEOF_UINTPTR_T
|
|
|
|
*
|
|
|
|
* size of a uintptr_t
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_UINTPTR_T", INT2NUM(sizeof(uintptr_t)));
|
|
|
|
|
2020-07-09 07:19:20 -04:00
|
|
|
/* Document-const: SIZEOF_CONST_STRING
|
|
|
|
*
|
|
|
|
* size of a const char*
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "SIZEOF_CONST_STRING", INT2NUM(sizeof(const char*)));
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
/* Document-const: RUBY_FREE
|
|
|
|
*
|
|
|
|
* Address of the ruby_xfree() function
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "RUBY_FREE", PTR2NUM(ruby_xfree));
|
|
|
|
|
2012-11-27 19:02:49 -05:00
|
|
|
/* Document-const: BUILD_RUBY_PLATFORM
|
|
|
|
*
|
|
|
|
* Platform built against (i.e. "x86_64-linux", etc.)
|
|
|
|
*
|
|
|
|
* See also RUBY_PLATFORM
|
|
|
|
*/
|
|
|
|
rb_define_const(mFiddle, "BUILD_RUBY_PLATFORM", rb_str_new2(RUBY_PLATFORM));
|
|
|
|
|
2012-11-27 14:54:50 -05:00
|
|
|
rb_define_module_function(mFiddle, "dlwrap", rb_fiddle_value2ptr, 1);
|
|
|
|
rb_define_module_function(mFiddle, "dlunwrap", rb_fiddle_ptr2value, 1);
|
|
|
|
rb_define_module_function(mFiddle, "malloc", rb_fiddle_malloc, 1);
|
|
|
|
rb_define_module_function(mFiddle, "realloc", rb_fiddle_realloc, 2);
|
|
|
|
rb_define_module_function(mFiddle, "free", rb_fiddle_free, 1);
|
|
|
|
|
2010-05-06 02:59:24 -04:00
|
|
|
Init_fiddle_function();
|
|
|
|
Init_fiddle_closure();
|
2012-11-27 14:54:50 -05:00
|
|
|
Init_fiddle_handle();
|
|
|
|
Init_fiddle_pointer();
|
2020-08-02 17:26:40 -04:00
|
|
|
Init_fiddle_pinned();
|
2020-12-10 19:41:12 -05:00
|
|
|
|
2021-07-14 02:38:55 -04:00
|
|
|
#ifdef HAVE_RUBY_MEMORY_VIEW_H
|
2020-12-10 19:41:12 -05:00
|
|
|
Init_fiddle_memory_view();
|
|
|
|
#endif
|
2010-05-06 02:59:24 -04:00
|
|
|
}
|
|
|
|
/* vim: set noet sws=4 sw=4: */
|