Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a file-like object to send data to attached process #77

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Provide a file-like object to send data to attached process
  • Loading branch information
danielwaterworth committed Mar 10, 2020
commit e0bcba4f1a675307db7de9b849a0052455b82a58
17 changes: 17 additions & 0 deletions ext/rbtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,26 @@ signal_handler_wrapper(VALUE arg, VALUE ctx)
}
#endif

static VALUE
send_write(VALUE klass, VALUE val) {
if (TYPE(val) == T_STRING) {
rbtrace__send_event(1,
"write",
's', RSTRING_PTR(val)
);
}

return Qnil;
}

void
Init_rbtrace()
{
VALUE mod = rb_define_module("RBTrace");
VALUE output = rb_define_module_under(mod, "OUT");

rb_define_singleton_method(output, "write", send_write, 1);

// hook into the gc
gc_hook = Data_Wrap_Struct(rb_cObject, rbtrace_gc_mark, NULL, NULL);
rb_global_variable(&gc_hook);
Expand Down
4 changes: 4 additions & 0 deletions lib/rbtrace/rbtracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ def process_line(line)
puts if @watch_slow
end

when 'write'
data, = *cmd
STDOUT.write(data)

else
puts "unknown event #{event}: #{cmd.inspect}"

Expand Down