|
3 | 3 |
|
4 | 4 | #include "ruby_helpers.h"
|
5 | 5 | #include "private_vm_api_access.h"
|
| 6 | +#include "extconf.h" |
6 | 7 |
|
7 | 8 | // The following global variables are initialized at startup to save expensive lookups later.
|
8 | 9 | // They are not expected to be mutated outside of init.
|
@@ -219,17 +220,26 @@ static bool ruby_is_obj_with_class(VALUE obj) {
|
219 | 220 | return false;
|
220 | 221 | }
|
221 | 222 |
|
222 |
| -// These two functions are not present in the VM headers, but are public symbols that can be invoked. |
| 223 | +// This function is not present in the VM headers, but is a public symbol that can be invoked. |
223 | 224 | int rb_objspace_internal_object_p(VALUE obj);
|
224 |
| -const char *rb_obj_info(VALUE obj); |
| 225 | + |
| 226 | +#ifdef NO_RB_OBJ_INFO |
| 227 | + const char* safe_object_info(DDTRACE_UNUSED VALUE obj) { return "(No rb_obj_info for current Ruby)"; } |
| 228 | +#else |
| 229 | + // This function is a public symbol, but not on all Rubies; `safe_object_info` below abstracts this, and |
| 230 | + // should be used instead. |
| 231 | + const char *rb_obj_info(VALUE obj); |
| 232 | + |
| 233 | + const char* safe_object_info(VALUE obj) { return rb_obj_info(obj); } |
| 234 | +#endif |
225 | 235 |
|
226 | 236 | VALUE ruby_safe_inspect(VALUE obj) {
|
227 | 237 | if (!ruby_is_obj_with_class(obj)) return rb_str_new_cstr("(Not an object)");
|
228 |
| - if (rb_objspace_internal_object_p(obj)) return rb_sprintf("(VM Internal, %s)", rb_obj_info(obj)); |
| 238 | + if (rb_objspace_internal_object_p(obj)) return rb_sprintf("(VM Internal, %s)", safe_object_info(obj)); |
229 | 239 | // @ivoanjo: I saw crashes on Ruby 3.1.4 when trying to #inspect matchdata objects. I'm not entirely sure why this
|
230 | 240 | // is needed, but since we only use this method for debug purposes I put in this alternative and decided not to
|
231 | 241 | // dig deeper.
|
232 |
| - if (rb_type(obj) == RUBY_T_MATCH) return rb_sprintf("(MatchData, %s)", rb_obj_info(obj)); |
| 242 | + if (rb_type(obj) == RUBY_T_MATCH) return rb_sprintf("(MatchData, %s)", safe_object_info(obj)); |
233 | 243 | if (rb_respond_to(obj, inspect_id)) return rb_sprintf("%+"PRIsVALUE, obj);
|
234 | 244 | if (rb_respond_to(obj, to_s_id)) return rb_sprintf("%"PRIsVALUE, obj);
|
235 | 245 |
|
|
0 commit comments