Created
July 9, 2010 22:05
-
-
Save pcapriotti/470139 to your computer and use it in GitHub Desktop.
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
From e604de446c3b2a4a18b7fd8bbd8189f7d117bd3e Mon Sep 17 00:00:00 2001 | |
From: Paolo Capriotti <[email protected]> | |
Date: Fri, 9 Jul 2010 22:59:50 +0100 | |
Subject: [PATCH 2/2] Add rb_throw to the C API. | |
--- | |
vm/capi/include/ruby.h | 7 +++++++ | |
vm/capi/kernel.cpp | 7 +++++++ | |
2 files changed, 14 insertions(+), 0 deletions(-) | |
diff --git a/vm/capi/include/ruby.h b/vm/capi/include/ruby.h | |
index dbbaf1a..cfe452c 100644 | |
--- a/vm/capi/include/ruby.h | |
+++ b/vm/capi/include/ruby.h | |
@@ -1253,6 +1253,13 @@ VALUE rb_uint2big(unsigned long number); | |
NORETURN(void rb_raise(VALUE error_handle, const char* format_string, ...)); | |
/** | |
+ * Transfer control to the end of the innermost catch block | |
+ * waiting for the given symbol. | |
+ * The given value is returned by the catch block. | |
+ */ | |
+ NORETURN(void rb_throw(const char* symbol, VALUE result)); | |
+ | |
+ /** | |
* Calls the function 'func', with arg1 as the argument. If an exception | |
* occurs during 'func', it calls 'raise_func' with arg2 as the argument. The | |
* return value of rb_rescue() is the return value from 'func' if no | |
diff --git a/vm/capi/kernel.cpp b/vm/capi/kernel.cpp | |
index e3f8478..f31e9ae 100644 | |
--- a/vm/capi/kernel.cpp | |
+++ b/vm/capi/kernel.cpp | |
@@ -85,6 +85,13 @@ extern "C" { | |
exit(1); | |
} | |
+ void rb_throw(const char* symbol, VALUE result) { | |
+ rb_funcall(rb_mKernel, rb_intern("throw"), 2, ID2SYM(rb_intern(symbol)), result); | |
+ | |
+ printf("rb_throw broken!\n"); | |
+ exit(1); | |
+ } | |
+ | |
VALUE rb_rescue2(VALUE (*func)(ANYARGS), VALUE arg1, | |
VALUE (*raise_func)(ANYARGS), VALUE arg2, ...) | |
{ | |
-- | |
1.7.0.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment