mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Reverts a half of r36079. As we discussed on ruby-dev@ and IRC,
we do not need to disclose intermediate representation of program. The program embedding CRuby should use rb_eval_string family. * include/ruby/ruby.h (ruby_opaque_t): removed. (ruby_compile_main_from_file, ruby_compile_main_from_string, ruby_eval_main): removed. * eval.c (ruby_eval_main_internal): became ruby_exec_internal() again. (ruby_eval_main): removed. * ruby.c (PREPARE_PARSE_MAIN) reverted. (parse_and_compile_main, ruby_compile_main_from_file, ruby_compile_main_from_string): removed git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7bca2f031a
commit
64ef091a64
4 changed files with 58 additions and 170 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
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,
|
||||||
|
we do not need to disclose intermediate representation of program.
|
||||||
|
The program embedding CRuby should use rb_eval_string family.
|
||||||
|
* include/ruby/ruby.h (ruby_opaque_t): removed.
|
||||||
|
(ruby_compile_main_from_file, ruby_compile_main_from_string,
|
||||||
|
ruby_eval_main): removed.
|
||||||
|
|
||||||
|
* eval.c (ruby_eval_main_internal): became ruby_exec_internal() again.
|
||||||
|
(ruby_eval_main): removed.
|
||||||
|
|
||||||
|
* ruby.c (PREPARE_PARSE_MAIN) reverted.
|
||||||
|
(parse_and_compile_main, ruby_compile_main_from_file,
|
||||||
|
ruby_compile_main_from_string): removed
|
||||||
|
|
||||||
Wed Jul 11 10:16:38 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Jul 11 10:16:38 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* include/ruby.h (HAVE_RUBY_THREAD_H): to show ruby/thread.h to be
|
* include/ruby.h (HAVE_RUBY_THREAD_H): to show ruby/thread.h to be
|
||||||
|
|
71
eval.c
71
eval.c
|
@ -84,7 +84,7 @@ ruby_init(void)
|
||||||
* @return an opaque pointer to the compiled source or an internal special value.
|
* @return an opaque pointer to the compiled source or an internal special value.
|
||||||
* @sa ruby_executable_node().
|
* @sa ruby_executable_node().
|
||||||
*/
|
*/
|
||||||
ruby_opaque_t
|
void *
|
||||||
ruby_options(int argc, char **argv)
|
ruby_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
|
@ -230,6 +230,26 @@ ruby_cleanup(volatile int ex)
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ruby_exec_internal(void *n)
|
||||||
|
{
|
||||||
|
volatile int state;
|
||||||
|
VALUE iseq = (VALUE)n;
|
||||||
|
rb_thread_t *th = GET_THREAD();
|
||||||
|
|
||||||
|
if (!n) return 0;
|
||||||
|
|
||||||
|
PUSH_TAG();
|
||||||
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
|
SAVE_ROOT_JMPBUF(th, {
|
||||||
|
th->base_block = 0;
|
||||||
|
rb_iseq_eval_main(iseq);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
POP_TAG();
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Calls ruby_cleanup() and exits the process */
|
/*! Calls ruby_cleanup() and exits the process */
|
||||||
void
|
void
|
||||||
ruby_stop(int ex)
|
ruby_stop(int ex)
|
||||||
|
@ -250,7 +270,7 @@ ruby_stop(int ex)
|
||||||
* @retval 0 if the given value is such a special value.
|
* @retval 0 if the given value is such a special value.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ruby_executable_node(ruby_opaque_t n, int *status)
|
ruby_executable_node(void *n, int *status)
|
||||||
{
|
{
|
||||||
VALUE v = (VALUE)n;
|
VALUE v = (VALUE)n;
|
||||||
int s;
|
int s;
|
||||||
|
@ -266,36 +286,12 @@ ruby_executable_node(ruby_opaque_t n, int *status)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
ruby_eval_main_internal(VALUE iseqval, VALUE* result)
|
|
||||||
{
|
|
||||||
volatile int state;
|
|
||||||
volatile VALUE retval;
|
|
||||||
rb_thread_t *th = GET_THREAD();
|
|
||||||
|
|
||||||
if (!iseqval) {
|
|
||||||
*result = Qnil;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PUSH_TAG();
|
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
|
||||||
SAVE_ROOT_JMPBUF(th, {
|
|
||||||
th->base_block = 0;
|
|
||||||
retval = rb_iseq_eval_main(iseqval);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
POP_TAG();
|
|
||||||
*result = state ? th->errinfo : retval;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Runs the given compiled source and exits this process.
|
/*! Runs the given compiled source and exits this process.
|
||||||
* @retval 0 if successfully run thhe source
|
* @retval 0 if successfully run thhe source
|
||||||
* @retval non-zero if an error occurred.
|
* @retval non-zero if an error occurred.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ruby_run_node(ruby_opaque_t n)
|
ruby_run_node(void *n)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
if (!ruby_executable_node(n, &status)) {
|
if (!ruby_executable_node(n, &status)) {
|
||||||
|
@ -307,27 +303,10 @@ ruby_run_node(ruby_opaque_t n)
|
||||||
|
|
||||||
/*! Runs the given compiled source */
|
/*! Runs the given compiled source */
|
||||||
int
|
int
|
||||||
ruby_exec_node(ruby_opaque_t n)
|
ruby_exec_node(void *n)
|
||||||
{
|
{
|
||||||
VALUE dummy;
|
|
||||||
ruby_init_stack((void *)&n);
|
ruby_init_stack((void *)&n);
|
||||||
return ruby_eval_main_internal((VALUE)n, &dummy);
|
return ruby_exec_internal(n);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Evaluates the given iseq in the main (toplevel) context.
|
|
||||||
*
|
|
||||||
* @param iseqval a VALUE that wraps an iseq.
|
|
||||||
* @param result Stores the evaluated value if succeeded,
|
|
||||||
* or an exception if failed.
|
|
||||||
* @retval 0 if succeeded
|
|
||||||
* @retval non-zero if failed.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
ruby_eval_main(ruby_opaque_t n, VALUE *result)
|
|
||||||
{
|
|
||||||
return !!ruby_eval_main_internal((VALUE)n, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1478,13 +1478,6 @@ int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! Opaque pointer to an inner data structure.
|
|
||||||
*
|
|
||||||
* You do not have to know what the actual data type this pointer points.
|
|
||||||
* It often changes for internal improvements.
|
|
||||||
*/
|
|
||||||
typedef void *ruby_opaque_t;
|
|
||||||
|
|
||||||
/** @defgroup ruby1 ruby(1) implementation
|
/** @defgroup ruby1 ruby(1) implementation
|
||||||
* A part of the implementation of ruby(1) command.
|
* A part of the implementation of ruby(1) command.
|
||||||
* Other programs that embed Ruby interpreter do not always need to use these
|
* Other programs that embed Ruby interpreter do not always need to use these
|
||||||
|
@ -1494,9 +1487,9 @@ typedef void *ruby_opaque_t;
|
||||||
|
|
||||||
void ruby_sysinit(int *argc, char ***argv);
|
void ruby_sysinit(int *argc, char ***argv);
|
||||||
void ruby_init(void);
|
void ruby_init(void);
|
||||||
ruby_opaque_t ruby_options(int argc, char** argv);
|
void* ruby_options(int argc, char** argv);
|
||||||
int ruby_executable_node(ruby_opaque_t n, int *status);
|
int ruby_executable_node(void *n, int *status);
|
||||||
int ruby_run_node(ruby_opaque_t n);
|
int ruby_run_node(void *n);
|
||||||
|
|
||||||
/* version.c */
|
/* version.c */
|
||||||
void ruby_show_version(void);
|
void ruby_show_version(void);
|
||||||
|
@ -1528,10 +1521,7 @@ void ruby_set_stack_size(size_t);
|
||||||
int ruby_stack_check(void);
|
int ruby_stack_check(void);
|
||||||
size_t ruby_stack_length(VALUE**);
|
size_t ruby_stack_length(VALUE**);
|
||||||
|
|
||||||
ruby_opaque_t ruby_compile_main_from_file(VALUE fname, const char* path, VALUE* error);
|
int ruby_exec_node(void *n);
|
||||||
ruby_opaque_t ruby_compile_main_from_string(VALUE fname, VALUE string, VALUE* error);
|
|
||||||
int ruby_exec_node(ruby_opaque_t n);
|
|
||||||
int ruby_eval_main(ruby_opaque_t n, VALUE *result);
|
|
||||||
|
|
||||||
void ruby_script(const char* name);
|
void ruby_script(const char* name);
|
||||||
void ruby_set_script_name(VALUE name);
|
void ruby_set_script_name(VALUE name);
|
||||||
|
|
123
ruby.c
123
ruby.c
|
@ -505,14 +505,6 @@ toplevel_context(void)
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PREPARE_PARSE_MAIN(th, env, expr) do { \
|
|
||||||
(th)->parse_in_eval--; \
|
|
||||||
(th)->base_block = &(env)->block; \
|
|
||||||
expr; \
|
|
||||||
(th)->parse_in_eval++; \
|
|
||||||
(th)->base_block = 0; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
process_sflag(int *sflag)
|
process_sflag(int *sflag)
|
||||||
{
|
{
|
||||||
|
@ -1381,6 +1373,14 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
|
|
||||||
env = toplevel_context();
|
env = toplevel_context();
|
||||||
|
|
||||||
|
#define PREPARE_PARSE_MAIN(expr) do { \
|
||||||
|
th->parse_in_eval--; \
|
||||||
|
th->base_block = &env->block; \
|
||||||
|
expr; \
|
||||||
|
th->parse_in_eval++; \
|
||||||
|
th->base_block = 0; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
if (opt->e_script) {
|
if (opt->e_script) {
|
||||||
VALUE progname = rb_progname;
|
VALUE progname = rb_progname;
|
||||||
rb_encoding *eenc;
|
rb_encoding *eenc;
|
||||||
|
@ -1395,7 +1395,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
require_libraries(&opt->req_list);
|
require_libraries(&opt->req_list);
|
||||||
ruby_set_script_name(progname);
|
ruby_set_script_name(progname);
|
||||||
|
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
PREPARE_PARSE_MAIN({
|
||||||
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
|
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1404,7 +1404,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
forbid_setid("program input from stdin");
|
forbid_setid("program input from stdin");
|
||||||
}
|
}
|
||||||
|
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
PREPARE_PARSE_MAIN({
|
||||||
tree = load_file(parser, opt->script_name, 1, opt);
|
tree = load_file(parser, opt->script_name, 1, opt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1444,12 +1444,12 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt->do_print) {
|
if (opt->do_print) {
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
PREPARE_PARSE_MAIN({
|
||||||
tree = rb_parser_append_print(parser, tree);
|
tree = rb_parser_append_print(parser, tree);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (opt->do_loop) {
|
if (opt->do_loop) {
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
PREPARE_PARSE_MAIN({
|
||||||
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
|
tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split);
|
||||||
});
|
});
|
||||||
rb_define_global_function("sub", rb_f_sub, -1);
|
rb_define_global_function("sub", rb_f_sub, -1);
|
||||||
|
@ -1464,7 +1464,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt)
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
PREPARE_PARSE_MAIN({
|
||||||
VALUE path = Qnil;
|
VALUE path = Qnil;
|
||||||
if (!opt->e_script && strcmp(opt->script, "-"))
|
if (!opt->e_script && strcmp(opt->script, "-"))
|
||||||
path = rb_realpath_internal(Qnil, opt->script_name, 1);
|
path = rb_realpath_internal(Qnil, opt->script_name, 1);
|
||||||
|
@ -1687,103 +1687,6 @@ rb_load_file(const char *fname)
|
||||||
return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
|
return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ruby_compile_main_arg {
|
|
||||||
int is_string;
|
|
||||||
union {
|
|
||||||
VALUE path;
|
|
||||||
VALUE string;
|
|
||||||
} source;
|
|
||||||
};
|
|
||||||
|
|
||||||
static ruby_opaque_t
|
|
||||||
parse_and_compile_main(VALUE fname, const struct ruby_compile_main_arg* arg, VALUE* error)
|
|
||||||
{
|
|
||||||
rb_env_t *const env = toplevel_context();
|
|
||||||
rb_thread_t *const th = GET_THREAD();
|
|
||||||
NODE* tree;
|
|
||||||
VALUE iseq;
|
|
||||||
VALUE path;
|
|
||||||
int state;
|
|
||||||
|
|
||||||
PUSH_TAG();
|
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
|
||||||
VALUE parser = rb_parser_new();
|
|
||||||
th->mild_compile_error++;
|
|
||||||
if (arg->is_string) {
|
|
||||||
FilePathValue(fname);
|
|
||||||
path = fname;
|
|
||||||
tree = rb_parser_compile_string(parser, RSTRING_PTR(fname), arg->source.string, 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
struct cmdline_options opt;
|
|
||||||
path = arg->source.path;
|
|
||||||
tree = load_file(parser, path, 0, cmdline_options_init(&opt));
|
|
||||||
}
|
|
||||||
th->mild_compile_error--;
|
|
||||||
});
|
|
||||||
if (!tree) rb_exc_raise(th->errinfo);
|
|
||||||
|
|
||||||
ruby_set_script_name(fname);
|
|
||||||
|
|
||||||
PREPARE_PARSE_MAIN(th, env, {
|
|
||||||
iseq = rb_iseq_new_main(tree, fname, path);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
POP_TAG();
|
|
||||||
if (state) {
|
|
||||||
*error = th->errinfo;
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
*error = Qnil;
|
|
||||||
return (ruby_opaque_t)iseq;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles a main Ruby script file into the internal a data structure.
|
|
||||||
*
|
|
||||||
* This function:
|
|
||||||
* @li loads the file specified by path.
|
|
||||||
* @li parses the source and compiles it
|
|
||||||
*
|
|
||||||
* @param fname <code>$0</code> is set to this value.
|
|
||||||
* If nil,
|
|
||||||
* uses the given path instead.
|
|
||||||
* @param path path to the source
|
|
||||||
* @param error where to store the exception if an error occured.
|
|
||||||
* @return The compiled source code. Or NULL if an error occured.
|
|
||||||
*/
|
|
||||||
ruby_opaque_t
|
|
||||||
ruby_compile_main_from_file(VALUE fname, const char* path, VALUE* error)
|
|
||||||
{
|
|
||||||
struct ruby_compile_main_arg arg;
|
|
||||||
arg.is_string = FALSE;
|
|
||||||
arg.source.path = rb_str_new_cstr(path);
|
|
||||||
|
|
||||||
if (NIL_P(fname)) fname = arg.source.path;
|
|
||||||
return parse_and_compile_main(fname, &arg, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles a main Ruby script in a string into the internal a data structure.
|
|
||||||
*
|
|
||||||
* This function parses the given source and compiles it
|
|
||||||
*
|
|
||||||
* @param fname <code>$0</code> is set to this value.
|
|
||||||
* @param source Ruby source string
|
|
||||||
* @param error where to store the exception if an error occured.
|
|
||||||
* @return The compiled source code. Or NULL if an error occured.
|
|
||||||
*/
|
|
||||||
ruby_opaque_t
|
|
||||||
ruby_compile_main_from_string(VALUE fname, VALUE source, VALUE* error)
|
|
||||||
{
|
|
||||||
struct ruby_compile_main_arg arg;
|
|
||||||
arg.is_string = TRUE;
|
|
||||||
arg.source.string = source;
|
|
||||||
return parse_and_compile_main(fname, &arg, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_arg0(VALUE val, ID id)
|
set_arg0(VALUE val, ID id)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue