| 1 |
#include <ruby.h> |
| 2 |
#include "ruby/internal/intern/load.h" |
| 3 |
#include "ruby/util.h" |
| 4 |
|
| 5 |
#if SIZEOF_INTPTR_T == SIZEOF_LONG_LONG |
| 6 |
# define UINTPTR2NUM ULL2NUM |
| 7 |
#elif SIZEOF_INTPTR_T == SIZEOF_LONG |
| 8 |
# define UINTPTR2NUM ULONG2NUM |
| 9 |
#else |
| 10 |
# define UINTPTR2NUM UINT2NUM |
| 11 |
#endif |
| 12 |
|
| 13 |
static VALUE |
| 14 |
stringify_symbol(VALUE klass, VALUE fname, VALUE sname) |
| 15 |
{ |
| 16 |
void *ptr = rb_ext_resolve_symbol(StringValueCStr(fname), StringValueCStr(sname)); |
| 17 |
if (ptr == NULL) { |
| 18 |
return Qnil; |
| 19 |
} |
| 20 |
uintptr_t uintptr = (uintptr_t)ptr; |
| 21 |
return UINTPTR2NUM(uintptr); |
| 22 |
} |
| 23 |
|
| 24 |
void |
| 25 |
Init_stringify_symbols(void) |
| 26 |
{ |
| 27 |
VALUE mod = rb_define_module("StringifySymbols"); |
| 28 |
rb_define_singleton_method(mod, "stringify_symbol", stringify_symbol, 2); |
| 29 |
} |