aboutsummaryrefslogtreecommitdiffstats
path: root/vm_eval.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-24 23:41:01 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-24 23:41:01 +0900
commit1780ad37483592d7752d314fbdb3bfd01966c229 (patch)
treec4a06884272f745f30d2fb0f413748fcec1d9894 /vm_eval.c
parent43a5c191358699fe8b19314763998cb8ca77ed90 (diff)
downloadruby-1780ad37483592d7752d314fbdb3bfd01966c229.tar.gz
Extract magic numbers
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/vm_eval.c b/vm_eval.c
index 8e57ad4f43..6ee958b659 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1615,13 +1615,17 @@ rb_each(VALUE obj)
static VALUE eval_default_path = Qfalse;
+#define EVAL_LOCATION_MARK "eval at "
+#define EVAL_LOCATION_MARK_LEN (int)rb_strlen_lit(EVAL_LOCATION_MARK)
+
static VALUE
get_eval_default_path(void)
{
int location_lineno;
VALUE location_path = rb_source_location(&location_lineno);
if (!NIL_P(location_path)) {
- return rb_fstring(rb_sprintf("(eval at %"PRIsVALUE":%d)", location_path, location_lineno));
+ return rb_fstring(rb_sprintf("("EVAL_LOCATION_MARK"%"PRIsVALUE":%d)",
+ location_path, location_lineno));
}
if (!eval_default_path) {
@@ -2527,9 +2531,11 @@ rb_current_realfilepath(void)
}
// [Feature #19755] implicit eval location is "(eval at #{__FILE__}:#{__LINE__})"
- if (RSTRING_LEN(path) > 9) {
- if (RSTRING_PTR(path)[RSTRING_LEN(path) - 1] == ')' &&
- memcmp(RSTRING_PTR(path), "(eval at ", 9) == 0) {
+ const long len = RSTRING_LEN(path);
+ if (len > EVAL_LOCATION_MARK_LEN+1) {
+ const char *const ptr = RSTRING_PTR(path);
+ if (ptr[len - 1] == ')' &&
+ memcmp(ptr, "("EVAL_LOCATION_MARK, EVAL_LOCATION_MARK_LEN+1) == 0) {
return Qnil;
}
}