From 19e74ebe8089eff93941746f57a28b6515be158b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 2 Nov 2026 19:51:51 +0900 Subject: [PATCH 1/2] Update extensions for `rb_len_t` --- ext/openssl/ossl.h | 2 ++ ext/openssl/ossl_bn.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h index 7762ad237..11d27ece5 100644 --- a/ext/openssl/ossl.h +++ b/ext/openssl/ossl.h @@ -102,9 +102,11 @@ void ossl_want_uninitialized(VALUE self, const rb_data_type_t *type); */ #ifndef HAVE_RB_LEN_T /* Ruby 4.1 */ typedef long rb_len_t; +typedef unsigned long rb_ulen_t; # define SIZEOF_RB_LEN_T SIZEOF_LONG # define RB_LEN_MAX LONG_MAX # define PRIdLEN "ld" +# define FIX2LEN FIX2LONG # define NUM2LEN NUM2LONG # define LEN2NUM LONG2NUM static inline long diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index ff5d3a538..56d7e00d2 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -75,12 +75,12 @@ integer_to_bnptr(VALUE obj, BIGNUM *orig) BIGNUM *bn; if (FIXNUM_P(obj)) { - long i; - unsigned char bin[sizeof(long)]; - long n = FIX2LONG(obj); - unsigned long un = labs(n); + size_t i; + unsigned char bin[sizeof(rb_ulen_t)]; + rb_len_t n = FIX2LEN(obj); + rb_ulen_t un = n < 0 ? 0 - (rb_ulen_t)n : (rb_ulen_t)n; - for (i = sizeof(long) - 1; 0 <= i; i--) { + for (i = sizeof(bin); 0 < i--;) { bin[i] = un & 0xff; un >>= 8; } From 02034aa71771655f160a868df02621842f88d88d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 10 Nov 2026 19:46:19 +0900 Subject: [PATCH 2/2] Split the conditions for each definition of the `rb_len_t` macro Since the update to the Windows binaries used by `setup-ruby` has stalled at an incomplete stage, temporarily split the conditions. --- ext/openssl/ossl.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h index 11d27ece5..d16be868f 100644 --- a/ext/openssl/ossl.h +++ b/ext/openssl/ossl.h @@ -103,12 +103,26 @@ void ossl_want_uninitialized(VALUE self, const rb_data_type_t *type); #ifndef HAVE_RB_LEN_T /* Ruby 4.1 */ typedef long rb_len_t; typedef unsigned long rb_ulen_t; +#endif +#ifndef SIZEOF_RB_LEN_T # define SIZEOF_RB_LEN_T SIZEOF_LONG +#endif +#ifndef RB_LEN_MAX # define RB_LEN_MAX LONG_MAX +#endif +#ifndef PRIdLEN # define PRIdLEN "ld" +#endif +#ifndef FIX2LEN # define FIX2LEN FIX2LONG +#endif +#ifndef NUM2LEN # define NUM2LEN NUM2LONG +#endif +#ifndef LEN2NUM # define LEN2NUM LONG2NUM +#endif +#ifndef HAVE_RB_LEN_T static inline long rb_len2long(rb_len_t n) {