diff options
Diffstat (limited to 'ext/-test-/load/stringify_symbols')
-rw-r--r-- | ext/-test-/load/stringify_symbols/extconf.rb | 1 | ||||
-rw-r--r-- | ext/-test-/load/stringify_symbols/stringify_symbols.c | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ext/-test-/load/stringify_symbols/extconf.rb b/ext/-test-/load/stringify_symbols/extconf.rb new file mode 100644 index 0000000000..ac39c15f09 --- /dev/null +++ b/ext/-test-/load/stringify_symbols/extconf.rb @@ -0,0 +1 @@ +create_makefile('-test-/load/stringify_symbols') diff --git a/ext/-test-/load/stringify_symbols/stringify_symbols.c b/ext/-test-/load/stringify_symbols/stringify_symbols.c new file mode 100644 index 0000000000..11a5ee3bc5 --- /dev/null +++ b/ext/-test-/load/stringify_symbols/stringify_symbols.c @@ -0,0 +1,29 @@ +#include <ruby.h> +#include "ruby/internal/intern/load.h" +#include "ruby/util.h" + +#if SIZEOF_INTPTR_T == SIZEOF_LONG_LONG +# define UINTPTR2NUM ULL2NUM +#elif SIZEOF_INTPTR_T == SIZEOF_LONG +# define UINTPTR2NUM ULONG2NUM +#else +# define UINTPTR2NUM UINT2NUM +#endif + +static VALUE +stringify_symbol(VALUE klass, VALUE fname, VALUE sname) +{ + void *ptr = rb_ext_resolve_symbol(StringValueCStr(fname), StringValueCStr(sname)); + if (ptr == NULL) { + return Qnil; + } + uintptr_t uintptr = (uintptr_t)ptr; + return UINTPTR2NUM(uintptr); +} + +void +Init_stringify_symbols(void) +{ + VALUE mod = rb_define_module("StringifySymbols"); + rb_define_singleton_method(mod, "stringify_symbol", stringify_symbol, 2); +} |