[前][次][番号順一覧][スレッド一覧]

ruby-changes:24312

From: yugui <ko1@a...>
Date: Wed, 11 Jul 2012 12:25:49 +0900 (JST)
Subject: [ruby-changes:24312] yugui:r36363 (trunk): * vm_eval.c (rb_eval_string_from_file,

yugui	2012-07-11 12:25:26 +0900 (Wed, 11 Jul 2012)

  New Revision: 36363

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36363

  Log:
    * vm_eval.c (rb_eval_string_from_file,
      rb_eval_string_from_file_protect): new functions to replace
      rb_compile_main_from_string() and ruby_eval_main().
    
    * nacl/pepper_ruby.c: Follows the change in vm_eval.c

  Modified files:
    trunk/ChangeLog
    trunk/nacl/pepper_main.c
    trunk/vm_eval.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36362)
+++ ChangeLog	(revision 36363)
@@ -1,3 +1,11 @@
+Mon Jul  9 16:11:30 2012  Yuki Yugui Sonoda  <yugui@g...>
+
+	* vm_eval.c (rb_eval_string_from_file,
+	  rb_eval_string_from_file_protect): new functions to replace
+	  rb_compile_main_from_string() and ruby_eval_main().
+
+	* nacl/pepper_ruby.c: Follows the change in vm_eval.c
+
 Mon Jul  9 14:05:42 2012  Yuki Yugui Sonoda  <yugui@g...>
 
 	Reverts a half of r36079. As we discussed on ruby-dev@ and IRC,
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 36362)
+++ vm_eval.c	(revision 36363)
@@ -1157,18 +1157,73 @@
     return eval_string(self, src, scope, file, line);
 }
 
+/** @note This function name is not stable. */
 VALUE
+ruby_eval_string_from_file(const char *str, const char *filename) {
+    return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, filename, 1);
+}
+
+struct eval_string_from_file_arg {
+    const char *str;
+    const char *filename;
+};
+static VALUE
+eval_string_from_file_helper(void *data) {
+    const struct eval_string_from_file_arg *const arg = (struct eval_string_from_file_arg*)data;
+    return eval_string(rb_vm_top_self(), rb_str_new2(arg->str), Qnil, arg->filename, 1);
+}
+
+VALUE
+ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state) {
+    struct eval_string_from_file_arg arg = { str, filename };
+    return rb_protect((VALUE (*)(VALUE))eval_string_from_file_helper, (VALUE)&arg, state);
+}
+
+/**
+ * Evaluates the given string in an isolated binding.
+ *
+ * Here "isolated" means the binding does not inherit any other binding. This
+ * behaves same as the binding for required libraries.
+ *
+ * __FILE__ will be "(eval)", and __LINE__ starts from 1 in the evaluation.
+ *
+ * @param str Ruby code to evaluate.
+ * @return The evaluated result.
+ * @throw Exception   Raises an exception on error.
+ */
+VALUE
 rb_eval_string(const char *str)
 {
-    return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1);
+    return ruby_eval_string_from_file(str, "eval");
 }
 
+/**
+ * Evaluates the given string in an isolated binding.
+ *
+ * __FILE__ will be "(eval)", and __LINE__ starts from 1 in the evaluation.
+ *
+ * @sa rb_eval_string
+ * @param str Ruby code to evaluate.
+ * @param state Being set to zero if succeeded. Nonzero if an error occurred.
+ * @return The evaluated result if succeeded, an undefined value if otherwise.
+ */
 VALUE
 rb_eval_string_protect(const char *str, int *state)
 {
     return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
 }
 
+/**
+ * Evaluates the given string under a module binding in an isolated binding.
+ * This is same as the binding for required libraries on "require('foo', true)".
+ *
+ * __FILE__ will be "(eval)", and __LINE__ starts from 1 in the evaluation.
+ *
+ * @sa rb_eval_string
+ * @param str Ruby code to evaluate.
+ * @param state Being set to zero if succeeded. Nonzero if an error occurred.
+ * @return The evaluated result if succeeded, an undefined value if otherwise.
+ */
 VALUE
 rb_eval_string_wrap(const char *str, int *state)
 {
Index: nacl/pepper_main.c
===================================================================
--- nacl/pepper_main.c	(revision 36362)
+++ nacl/pepper_main.c	(revision 36363)
@@ -374,7 +374,7 @@
     volatile VALUE err = rb_errinfo();
     err = rb_obj_as_string(err);
   } else {
-    instance->async_call_args = "rubyReady";
+    instance->async_call_args = (void*)"rubyReady";
     core_interface->CallOnMainThread(
         0, PP_MakeCompletionCallback(pruby_post_cstr, instance), 0);
   }
@@ -419,11 +419,10 @@
 static void*
 pruby_eval(void* data)
 {
+  extern VALUE ruby_eval_string_from_file_protect(const char* src, const char* path, int* state);
   struct PepperInstance* const instance = (struct PepperInstance*)data;
-  volatile VALUE path;
   volatile VALUE src = (VALUE)instance->async_call_args;
   volatile VALUE result = Qnil;
-  ruby_opaque_t prog;
   volatile int state;
 
   RUBY_INIT_STACK;
@@ -432,13 +431,8 @@
     perror("pepper-ruby:pthread_mutex_lock");
     return 0;
   }
-
-  path = rb_usascii_str_new_cstr("(pepper-ruby)");
-  prog = ruby_compile_main_from_string(path, src, (VALUE*)&result);
-  if (prog) {
-    state = ruby_eval_main(prog, (VALUE*)&result);
-  }
-
+  result = ruby_eval_string_from_file_protect(
+      RSTRING_PTR(src), "(pepper-ruby)", &state);
   pthread_mutex_unlock(&instance->mutex);
 
   if (!state) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]