From 3636277dc5837bcedcd5ef43d49423194064a676 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 10 Dec 2025 12:09:50 +0900 Subject: Add `NUM2PTR` and `PTR2NUM` macros These macros have been defined here and there, so collect them. --- include/ruby/internal/arithmetic/intptr_t.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/ruby/internal') diff --git a/include/ruby/internal/arithmetic/intptr_t.h b/include/ruby/internal/arithmetic/intptr_t.h index a354f4469c..70090f88e6 100644 --- a/include/ruby/internal/arithmetic/intptr_t.h +++ b/include/ruby/internal/arithmetic/intptr_t.h @@ -32,6 +32,18 @@ #define rb_int_new rb_int2inum /**< @alias{rb_int2inum} */ #define rb_uint_new rb_uint2inum /**< @alias{rb_uint2inum} */ +// These definitions are same as fiddle/conversions.h +#if SIZEOF_VOIDP <= SIZEOF_LONG +# define PTR2NUM(x) (LONG2NUM((long)(x))) +# define NUM2PTR(x) ((void*)(NUM2ULONG(x))) +#elif SIZEOF_VOIDP <= SIZEOF_LONG_LONG +# define PTR2NUM(x) (LL2NUM((LONG_LONG)(x))) +# define NUM2PTR(x) ((void*)(NUM2ULL(x))) +#else +// should have been an error in ruby/internal/value.h +# error Need integer for VALUE +#endif + RBIMPL_SYMBOL_EXPORT_BEGIN() /** -- cgit v1.2.3