summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-22 22:34:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-22 22:34:18 +0000
commitbd2e1034d5b71fd1810b2e29a198d6d7e7780e8c (patch)
tree334d39b22e089948677b2fea010f9122afb22d2e
parentd124fa3a35c3f9261484ba4311cb14f60a598cce (diff)
time.c: inquire suspicious values
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--time.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/time.c b/time.c
index 3f29e465256..0af2560ec03 100644
--- a/time.c
+++ b/time.c
@@ -53,6 +53,30 @@ eq(VALUE x, VALUE y)
return RTEST(rb_funcall(x, id_eq, 1, y));
}
+#ifdef _MSC_VER
+static VALUE
+inquire_value(VALUE x, const char *mesg)
+{
+ VALUE klass;
+ LPEXCEPTION_POINTERS info;
+ if (SPECIAL_CONST_P(x)) return Qnil;
+ __try {
+ klass = CLASS_OF(x);
+ }
+ __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
+ (info = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER) :
+ EXCEPTION_CONTINUE_SEARCH) {
+ PEXCEPTION_RECORD rec = info->ExceptionRecord;
+ rb_fatal("Access violation at %p: class of %p: %s",
+ (void *)rec->ExceptionInformation[1],
+ (void *)x, mesg);
+ }
+ return klass;
+}
+#else
+# define inquire_value(x, mesg) (void)(x)
+#endif
+
static int
cmp(VALUE x, VALUE y)
{
@@ -63,11 +87,8 @@ cmp(VALUE x, VALUE y)
return 1;
return 0;
}
-#ifdef _WIN32
- if (rb_objspace_garbage_object_p(x)) {
- rb_fatal("cmp(%p, %p)", (void *)x, (void *)y);
- }
-#endif
+ inquire_value(x, "cmp(x)");
+ inquire_value(y, "cmp(y)");
return rb_cmpint(rb_funcall(x, id_cmp, 1, y), x, y);
}