mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
64ef091a64
commit
412c5a96be
3 changed files with 68 additions and 11 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Jul 9 16:11:30 2012 Yuki Yugui Sonoda <yugui@google.com>
|
||||
|
||||
* 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@google.com>
|
||||
|
||||
Reverts a half of r36079. As we discussed on ruby-dev@ and IRC,
|
||||
|
|
|
@ -374,7 +374,7 @@ init_libraries(void* data)
|
|||
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 @@ pruby_init(void)
|
|||
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 @@ pruby_eval(void* data)
|
|||
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) {
|
||||
|
|
57
vm_eval.c
57
vm_eval.c
|
@ -1157,18 +1157,73 @@ rb_f_eval(int argc, VALUE *argv, VALUE self)
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue