From b7f6e8189c599c31c7f937f6b95d0bdeb6cd95f8 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 4 Jul 2025 23:15:34 -0700 Subject: [PATCH] Declare functions as Ractor-safe As far as I can tell this should be thread-safe in C land, so we should be okay declaring the extension as Ractor-safe. Note that this doesn't allow sharing of Parser objects between Ractors --- mri/ext/llhttp/extconf.rb | 4 ++++ mri/ext/llhttp/llhttp_ext.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mri/ext/llhttp/extconf.rb b/mri/ext/llhttp/extconf.rb index 3f82f7a..a58db9f 100644 --- a/mri/ext/llhttp/extconf.rb +++ b/mri/ext/llhttp/extconf.rb @@ -3,4 +3,8 @@ require "mkmf" dir_config("llhttp_ext") + +# Check for Ractor support +have_func("rb_ext_ractor_safe", "ruby.h") + create_makefile("llhttp_ext") diff --git a/mri/ext/llhttp/llhttp_ext.c b/mri/ext/llhttp/llhttp_ext.c index cf38e36..f6bee8c 100644 --- a/mri/ext/llhttp/llhttp_ext.c +++ b/mri/ext/llhttp/llhttp_ext.c @@ -341,6 +341,10 @@ static VALUE rb_llhttp_init(VALUE self, VALUE type) { } void Init_llhttp_ext(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif + mLLHttp = rb_const_get(rb_cObject, rb_intern("LLHttp")); cParser = rb_const_get(mLLHttp, rb_intern("Parser")); eError = rb_const_get(mLLHttp, rb_intern("Error"));