ruby-changes:36002
From: yugui <ko1@a...>
Date: Wed, 22 Oct 2014 10:27:17 +0900 (JST)
Subject: [ruby-changes:36002] yugui:r48078 (trunk): Enable nacl_io in pepper-ruby.
yugui 2014-10-22 00:23:21 +0900 (Wed, 22 Oct 2014) New Revision: 48078 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48078 Log: Enable nacl_io in pepper-ruby. * configure.in (XCFLAGS): Add include path for NaCl libraries. (XLDFLAGS): ditto. (NACL_LIB_PATH): new stubstitution * nacl/nacl-config.rb: support NACL_LIB_PATH * nacl/package.rb: ditto. * nacl/pepper_main.c: replace old implementations with nacl_io. * nacl/GNUmakefile.in: link nacl_io to pepper_ruby * ruby.c (rb_load_file): remove __attribute__((weak)) because the old override hack was replaced with nacl_io. * file.c (rb_file_load_ok): ditto. Modified files: trunk/ChangeLog trunk/configure.in trunk/file.c trunk/nacl/GNUmakefile.in trunk/nacl/nacl-config.rb trunk/nacl/package.rb trunk/nacl/pepper_main.c trunk/ruby.c Index: configure.in =================================================================== --- configure.in (revision 48077) +++ configure.in (revision 48078) @@ -96,8 +96,12 @@ AC_DEFUN([RUBY_NACL], https://github.com/ruby/ruby/blob/trunk/configure.in#L96 [yes], [nacl_cv_build_variant=newlib])]) AS_CASE(["$target_cpu"], - [x86_64|i?86], [nacl_cv_cpu_nick=x86], + [x86_64], [nacl_cv_cpu_nick=x86 + nacl_cv_cpu_nick2=x86_64], + [i?86], [nacl_cv_cpu_nick=x86 + nacl_cv_cpu_nick2=x86_32], [le32], [nacl_cv_cpu_nick=pnacl + nacl_cv_cpu_nick2=pnacl, ac_cv_exeext=.pexe], [nacl_cv_cpu_nick=$target_cpu]) AS_CASE(["$build_os"], @@ -148,9 +152,22 @@ AC_DEFUN([RUBY_NACL], https://github.com/ruby/ruby/blob/trunk/configure.in#L152 fi AC_MSG_RESULT(${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/bin) + RUBY_APPEND_OPTIONS(XCFLAGS, '-I$(NACL_SDK_ROOT)/include') + AC_MSG_CHECKING([nacl library path]) + if test -d "${NACL_SDK_ROOT}/lib/${nacl_cv_build_variant}_${nacl_cv_cpu_nick2}/Release"; then + nacl_cv_libpath="${nacl_cv_build_variant}_${nacl_cv_cpu_nick2}" + elif test -d "${NACL_SDK_ROOT}/lib/${nacl_cv_cpu_nick2}/Release"; then + nacl_cv_libpath="${nacl_cv_cpu_nick2}" + else + AC_MSG_ERROR("not found") + fi + AC_MSG_RESULT([${nacl_cv_libpath}]) + RUBY_APPEND_OPTIONS(XLDFLAGS, '-L$(NACL_SDK_ROOT)/'"lib/${nacl_cv_libpath}/Release") + AC_SUBST(NACL_TOOLCHAIN) AC_SUBST(NACL_SDK_ROOT) - AC_SUBST(NACL_SDK_VARIANT, nacl_cv_build_variant) + AC_SUBST(NACL_SDK_VARIANT, "${nacl_cv_build_variant}") + AC_SUBST(NACL_LIB_PATH, "${nacl_cv_libpath}") AC_CHECK_TOOLS(CC, [clang gcc]) ])]) Index: ChangeLog =================================================================== --- ChangeLog (revision 48077) +++ ChangeLog (revision 48078) @@ -1,3 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Oct 22 00:01:09 2014 Yuki Yugui Sonoda <yugui@y...> + + * configure.in (XCFLAGS): Add include path for NaCl libraries. + (XLDFLAGS): ditto. + (NACL_LIB_PATH): new stubstitution + + * nacl/nacl-config.rb: support NACL_LIB_PATH + + * nacl/package.rb: ditto. + + * nacl/pepper_main.c: replace old implementations with nacl_io. + + * nacl/GNUmakefile.in: link nacl_io to pepper_ruby + + * ruby.c (rb_load_file): remove __attribute__((weak)) because the old + override hack was replaced with nacl_io. + + * file.c (rb_file_load_ok): ditto. + Tue Oct 21 17:32:32 2014 Martin Duerst <duerst@i...> * common.mk: Adding explicit creation of directory Index: nacl/pepper_main.c =================================================================== --- nacl/pepper_main.c (revision 48077) +++ nacl/pepper_main.c (revision 48078) @@ -8,6 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L8 #include <string.h> #include <pthread.h> #include <sys/stat.h> +#include <sys/mount.h> #include <fcntl.h> #include <pthread.h> #include "ppapi/c/pp_errors.h" @@ -25,6 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L26 #include "ppapi/c/ppp.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/ppp_messaging.h" +#include "nacl_io/nacl_io.h" #include "verconf.h" #include "ruby/ruby.h" @@ -54,6 +56,7 @@ typedef struct PPP_Instance PPP_Instance https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L56 #endif static PP_Module module_id = 0; +static PPB_GetInterface get_browser_interface = NULL; static PPB_Core* core_interface = NULL; static PPB_Messaging* messaging_interface = NULL; static PPB_Var* var_interface = NULL; @@ -487,8 +490,20 @@ static PP_Bool https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L490 Instance_DidCreate(PP_Instance instance, uint32_t argc, const char* argn[], const char* argv[]) { + int ret; struct PepperInstance* data = pruby_register_instance(instance); current_instance = instance; + + nacl_io_init_ppapi(instance, get_browser_interface); + + // TODO(yugui) Mount devfs + + if (mount("/lib", "/lib", "httpfs", + 0, "allow_cross_origin_requests=false")) { + perror("mount httpfs"); + return PP_FALSE; + } + return init_libraries_if_necessary() ? PP_FALSE : PP_TRUE; } @@ -618,9 +633,10 @@ Messaging_HandleMessage(PP_Instance inst https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L633 * @return PP_OK on success, any other value on failure. */ PP_EXPORT int32_t -PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface get_browser_interface) +PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface a_get_browser_interface) { module_id = a_module_id; + get_browser_interface = a_get_browser_interface; core_interface = (PPB_Core*)(get_browser_interface(PPB_CORE_INTERFACE)); if (core_interface == NULL) return PP_ERROR_NOINTERFACE; @@ -680,191 +696,3 @@ PPP_ShutdownModule(void) https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L696 { ruby_cleanup(0); } - -/****************************************************************************** - * Overwrites rb_file_load_ok - ******************************************************************************/ - -static void -load_ok_internal(void* data, int32_t unused) -{ - /* PPAPI main thread */ - struct PepperInstance* const instance = (struct PepperInstance*)data; - const char *const path = (const char*)instance->async_call_args; - PP_Resource req; - int result; - - instance->url_loader = loader_interface->Create(instance->instance); - req = request_interface->Create(instance->instance); - request_interface->SetProperty( - req, PP_URLREQUESTPROPERTY_METHOD, pruby_cstr_to_var("HEAD")); - request_interface->SetProperty( - req, PP_URLREQUESTPROPERTY_URL, pruby_cstr_to_var(path)); - - result = loader_interface->Open( - instance->url_loader, req, - PP_MakeCompletionCallback(pruby_async_return_int, instance)); - if (result != PP_OK_COMPLETIONPENDING) { - pruby_async_return_int(instance, result); - } -} - -static void -pruby_file_fetch_check_response(void* data, int32_t unused) -{ - /* PPAPI main thread */ - PP_Resource res; - struct PepperInstance* const instance = (struct PepperInstance*)data; - - res = loader_interface->GetResponseInfo(instance->url_loader); - if (res) { - struct PP_Var status = - response_interface->GetProperty(res, PP_URLRESPONSEPROPERTY_STATUSCODE); - if (status.type == PP_VARTYPE_INT32) { - pruby_async_return_int(instance, status.value.as_int / 100 == 2 ? PP_OK : PP_ERROR_FAILED); - return; - } - else { - messaging_interface->PostMessage( - instance->instance, pruby_cstr_to_var("Unexpected type: ResponseInfoInterface::GetProperty")); - } - } - else { - messaging_interface->PostMessage( - instance->instance, pruby_cstr_to_var("Failed to open URL: URLLoaderInterface::GetResponseInfo")); - } - pruby_async_return_int(instance, PP_ERROR_FAILED); -} - - -int -rb_file_load_ok(const char *path) -{ - struct PepperInstance* const instance = GET_PEPPER_INSTANCE(); - if (path[0] == '.' && path[1] == '/') path += 2; - - instance->async_call_args = (void*)path; - core_interface->CallOnMainThread( - 0, PP_MakeCompletionCallback(load_ok_internal, instance), 0); - if (pthread_cond_wait(&instance->cond, &instance->mutex)) { - perror("pepper-ruby:pthread_cond_wait"); - return 0; - } - if (instance->async_call_result.as_int != PP_OK) { - fprintf(stderr, "Failed to open URL: %d: %s\n", - instance->async_call_result.as_int, path); - return 0; - } - - core_interface->CallOnMainThread( - 0, PP_MakeCompletionCallback(pruby_file_fetch_check_response, instance), 0); - if (pthread_cond_wait(&instance->cond, &instance->mutex)) { - perror("pepper-ruby:pthread_cond_wait"); - return 0; - } - return instance->async_call_result.as_int == PP_OK; -} - -/****************************************************************************** - * Overwrites rb_load_file - ******************************************************************************/ - -static void -load_file_internal(void* data, int32_t unused) -{ - /* PPAPI main thread */ - struct PepperInstance* const instance = (struct PepperInstance*)data; - const char *const path = (const char*)instance->async_call_args; - PP_Resource req; - int result; - - instance->url_loader = loader_interface->Create(instance->instance); - req = request_interface->Create(instance->instance); - request_interface->SetProperty( - req, PP_URLREQUESTPROPERTY_METHOD, pruby_cstr_to_var("GET")); - request_interface->SetProperty( - req, PP_URLREQUESTPROPERTY_URL, pruby_cstr_to_var(path)); - - result = loader_interface->Open( - instance->url_loader, req, - PP_MakeCompletionCallback(pruby_async_return_int, instance)); - if (result != PP_OK_COMPLETIONPENDING) { - pruby_async_return_int(instance, result); - } -} - -static void -load_file_read_contents_callback(void *data, int result) -{ - struct PepperInstance* const instance = (struct PepperInstance*)data; - if (result > 0) { - rb_str_buf_cat(instance->async_call_result.as_value, - instance->buf, result); - loader_interface->ReadResponseBody( - instance->url_loader, instance->buf, 1000, PP_MakeCompletionCallback(load_file_read_contents_callback, instance)); - } - else if (result == 0) { - pruby_async_return_value(data, instance->async_call_result.as_value); - } - else { - pruby_async_return_value(data, INT2FIX(result)); - } -} - -static void -load_file_read_contents(void *data, int result) -{ - struct PepperInstance* const instance = (struct PepperInstance*)data; - instance->async_call_result.as_value = rb_str_new(0, 0); - loader_interface->ReadResponseBody( - instance->url_loader, instance->buf, 1000, PP_MakeCompletionCallback(load_file_read_contents_callback, instance)); -} - -void* -rb_load_file(const char *path) -{ - const char *real_path; - struct PepperInstance* instance; - if (path[0] != '.' || path[1] != '/') path += 2; - - instance = GET_PEPPER_INSTANCE(); - - instance->async_call_args = (void*)path; - core_interface->CallOnMainThread( - 0, PP_MakeCompletionCallback(load_file_internal, instance), 0); - if (pthread_cond_wait(&instance->cond, &instance->mutex)) { - perror("pepper-ruby:pthread_cond_wait"); - return 0; - } - if (instance->async_call_result.as_int != PP_OK) { - fprintf(stderr, "Failed to open URL: %d: %s\n", - instance->async_call_result.as_int, path); - return 0; - } - - core_interface->CallOnMainThread( - 0, PP_MakeCompletionCallback(pruby_file_fetch_check_response, instance), 0); - if (pthread_cond_wait(&instance->cond, &instance->mutex)) { - perror("pepper-ruby:pthread_cond_wait"); - return 0; - } - if (instance->async_call_result.as_int != PP_OK) return 0; - - core_interface->CallOnMainThread( - 0, PP_MakeCompletionCallback(load_file_read_contents, instance), 0); - if (pthread_cond_wait(&instance->cond, &instance->mutex)) { - perror("pepper-ruby:pthread_cond_wait"); - return 0; - } - if (FIXNUM_P(instance->async_call_result.as_value)) { - return 0; - } - else if (RB_TYPE_P(instance->async_call_result.as_value, T_STRING)) { - VALUE str = instance->async_call_result.as_value; - extern void* rb_compile_cstr(const char *f, const char *s, int len, int line); - return rb_compile_cstr(path, RSTRING_PTR(str), RSTRING_LEN(str), 0); - } - else { - return 0; - } -} Index: nacl/nacl-config.rb =================================================================== --- nacl/nacl-config.rb (revision 48077) +++ nacl/nacl-config.rb (revision 48078) @@ -24,6 +24,8 @@ module NaClConfig https://github.com/ruby/ruby/blob/trunk/nacl/nacl-config.rb#L24 ].find{|path| File.exist?(path) } or raise "No create_nmf found" HOST_LIB = File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], HOST, "lib#{lib_suffix}") + NACL_LIB = File.join(SDK_ROOT, 'lib', config['NACL_LIB_PATH'], 'Release') + INSTALL_PROGRAM = config['INSTALL_PROGRAM'] INSTALL_LIBRARY = config['INSTALL_DATA'] Index: nacl/GNUmakefile.in =================================================================== --- nacl/GNUmakefile.in (revision 48077) +++ nacl/GNUmakefile.in (revision 48078) @@ -37,7 +37,7 @@ endif https://github.com/ruby/ruby/blob/trunk/nacl/GNUmakefile.in#L37 PYTHON=@PYTHON@ PPROGRAM=pepper-$(PROGRAM) -PEPPER_LIBS=-lppapi +PEPPER_LIBS=-lppapi -lnacl_io PROGRAM_NMF=$(PROGRAM:$(EXEEXT)=.nmf) PPROGRAM_NMF=$(PPROGRAM:$(EXEEXT)=.nmf) Index: nacl/package.rb =================================================================== --- nacl/package.rb (revision 48077) +++ nacl/package.rb (revision 48078) @@ -15,7 +15,11 @@ include NaClConfig https://github.com/ruby/ruby/blob/trunk/nacl/package.rb#L15 class Installation include NaClConfig - SRC_DIRS = [ Dir.pwd, HOST_LIB ] + SRC_DIRS = [ + Dir.pwd, + HOST_LIB, + NACL_LIB, + ] def initialize(destdir) @destdir = destdir Index: ruby.c =================================================================== --- ruby.c (revision 48077) +++ ruby.c (revision 48078) @@ -1729,9 +1729,6 @@ load_file(VALUE parser, VALUE fname, int https://github.com/ruby/ruby/blob/trunk/ruby.c#L1729 return (NODE *)rb_ensure(load_file_internal, (VALUE)&arg, restore_lineno, rb_gv_get("$.")); } -#ifdef __native_client__ -__attribute__((weak)) -#endif void * rb_load_file(const char *fname) { Index: file.c =================================================================== --- file.c (revision 48077) +++ file.c (revision 48078) @@ -5517,9 +5517,6 @@ rb_path_check(const char *path) https://github.com/ruby/ruby/blob/trunk/file.c#L5517 } #ifndef _WIN32 -#ifdef __native_client__ -__attribute__((noinline,weak)) -#endif int rb_file_load_ok(const char *path) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/