Use newer APIs for ruby head/4.1 support - #109
Merged
Merged
Conversation
rwstauner
marked this pull request as ready for review
June 3, 2026 00:26
AlexaCampusano
approved these changes
Aug 5, 2026
Contributor
Author
|
@SamSaffron I would appreciate a review if you have time to look at this fix for newer ruby versions. Thanks! |
Collaborator
|
I follow, the challenge I have here is that I am not mega familiar with all the new APIs so I am stuck trusting my robot testing skills :) feedback from robot analysis:
diff --git a/ext/rbtrace.c b/ext/rbtrace.c
index 9bc259a..1e5c6c8 100644
--- a/ext/rbtrace.c
+++ b/ext/rbtrace.c
@@ -491,8 +491,9 @@ event_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
val = rb_inspect(rb_ivar_get(self, rb_intern(expr)));
} else {
- snprintf(buffer, len+150, "(begin; ObjectSpace._id2ref(%ld).instance_eval{ %s }; rescue Exception => e; e; end).inspect", NUM2LONG(rb_obj_id(self)), expr);
- val = rb_eval_string_protect(buffer, 0);
+ snprintf(buffer, len+150, "proc { |__rbtrace_receiver__| (begin; __rbtrace_receiver__.instance_eval { %s }; rescue Exception => e; e; end).inspect }", expr);
+ VALUE expr_proc = rb_eval_string_protect(buffer, 0);
+ val = rb_funcall(expr_proc, rb_intern("call"), 1, self);
}
if (RTEST(val) && TYPE(val) == T_STRING) {
diff --git a/server.rb b/server.rb
index 20b5314..05806fc 100644
--- a/server.rb
+++ b/server.rb
@@ -32,6 +32,7 @@ while true
Dir.pwd
Process.pid
'hello'.multiply_vowels(3){ :ohai }
+ 'hello'.upcase
sleep rand*0.5
ENV['blah']
diff --git a/test.sh b/test.sh
index bd735d7..ccedf51 100755
--- a/test.sh
+++ b/test.sh
@@ -51,11 +51,34 @@ assert_trace() {
echo
}
+assert_timed_trace() {
+ expected="$1"
+ shift
+ output=$(mktemp)
+
+ echo ------------------------------------------
+ echo ./bin/rbtrace -p $PID "$@"
+ echo ------------------------------------------
+ bundle exec ./bin/rbtrace -p $PID "$@" >"$output" 2>&1 &
+ tracer_pid=$!
+ sleep 2
+ kill "$tracer_pid" 2>/dev/null || true
+ wait "$tracer_pid" 2>/dev/null || true
+ cat "$output"
+ if ! grep -F "$expected" "$output" >/dev/null; then
+ rm -f "$output"
+ return 1
+ fi
+ rm -f "$output"
+ echo
+}
+
trace -m Test.run --devmode
trace -m sleep
trace -m sleep Dir.chdir Dir.pwd Process.pid "String#gsub" "String#*"
trace -m "Kernel#"
trace -m "String#gsub(self,@test)" "String#*(self,__source__)" "String#multiply_vowels(self,self.length,num)"
+assert_timed_trace 'String#upcase(self.class=String)' -m 'String#upcase(self.class)'
assert_trace '=> 2' -e 'p(1 + 1)'
trace -h
trace --gc --slow=200
|
The deprecated ones have been removed from ruby as of 2026-04-12 ruby/ruby@b66b500
Co-Authored-By: Sam <sam.saffron@gmail.com>
Contributor
Author
|
Awesome, thank you @SamSaffron!
|
Collaborator
|
Looks good ... will cut a new version! |
Contributor
Author
|
Thank you! |
Collaborator
|
Thanks Randy, if there are any other changes you feel we need happy to add them in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The deprecated ones have been removed from ruby as of 2026-04-12
ruby/ruby@b66b500
This resolves a compilation error with ruby head: