1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

refoctoring

* mjit.c (compile_c_to_so): refactored.

* mjit.c (init_header_filename): xmalloc never returns NULL.

* mjit.c (init_header_filename): report the filename of the header if failed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2018-02-08 18:51:33 +00:00
parent 355b147f5e
commit 0c8a6c91a0

30
mjit.c
View file

@ -659,37 +659,40 @@ compile_c_to_so(const char *c_file, const char *so_file)
{ {
int exit_code; int exit_code;
const char *input[] = {NULL, NULL}; const char *input[] = {NULL, NULL};
const char *output[] = {"-o", NULL, NULL}; const char *output[] = {
#ifndef _MSC_VER
"-o",
#endif
NULL, NULL};
const char *libs[] = { const char *libs[] = {
#ifdef _MSC_VER #ifdef _WIN32
# ifdef _MSC_VER
LIBRUBYARG_SHARED, LIBRUBYARG_SHARED,
"-link", "-link",
libruby_installed, libruby_installed,
libruby_build, libruby_build,
#else # else
# ifdef _WIN32
/* Look for ruby.dll.a in build and install directories. */ /* Look for ruby.dll.a in build and install directories. */
libruby_installed, libruby_installed,
libruby_build, libruby_build,
/* Link to ruby.dll.a, because Windows DLLs don't allow unresolved symbols. */ /* Link to ruby.dll.a, because Windows DLLs don't allow unresolved symbols. */
LIBRUBYARG_SHARED, LIBRUBYARG_SHARED,
"-lmsvcrt", "-lmsvcrt",
# ifdef __GNUC__
"-lgcc", "-lgcc",
# endif
# endif # endif
#endif #endif
NULL}; NULL};
char **args; char **args;
#ifdef _MSC_VER
char *p;
#endif
input[0] = c_file; input[0] = c_file;
#ifdef _MSC_VER #ifdef _MSC_VER
{ p = (char *)output[0] = xmalloc(3 + strlen(so_file) + 1);
char *p = (char *)output[0] = xmalloc(3 + strlen(so_file) + 1); p = append_str(p, "-Fe");
p = append_str(p, "-Fe"); p = append_str(p, so_file);
p = append_str(p, so_file); *p = '\0';
*p = '\0';
}
args = form_args(4, (mjit_opts.debug ? VC_COMMON_ARGS_DEBUG : VC_COMMON_ARGS), args = form_args(4, (mjit_opts.debug ? VC_COMMON_ARGS_DEBUG : VC_COMMON_ARGS),
output, input, libs); output, input, libs);
#else #else
@ -1150,13 +1153,12 @@ init_header_filename(void)
verlen = strlen(ruby_version); verlen = strlen(ruby_version);
header_file = xmalloc(baselen + sizeof(header_name) + verlen + 2); header_file = xmalloc(baselen + sizeof(header_name) + verlen + 2);
if (header_file == NULL)
return;
p = append_str2(header_file, basedir, baselen); p = append_str2(header_file, basedir, baselen);
p = append_str2(p, header_name, sizeof(header_name)-1); p = append_str2(p, header_name, sizeof(header_name)-1);
p = append_str2(p, ruby_version, verlen); p = append_str2(p, ruby_version, verlen);
p = append_str2(p, ".h", 3); p = append_str2(p, ".h", 3);
if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) { if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) {
verbose(2, "Cannot access header file %s\n", header_file);
xfree(header_file); xfree(header_file);
header_file = NULL; header_file = NULL;
return; return;