diff options
| -rw-r--r-- | .github/workflows/main.yml | 24 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | appveyor.yml | 8 | ||||
| -rw-r--r-- | examples/targets/build_config_dreamcast_shelf.rb | 108 | ||||
| -rw-r--r-- | include/mrbconf.h | 7 | ||||
| -rw-r--r-- | mrbgems/mruby-io/src/file.c | 9 | ||||
| -rw-r--r-- | mrbgems/mruby-io/src/io.c | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 2 | ||||
| -rw-r--r-- | src/string.c | 48 |
9 files changed, 192 insertions, 17 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..3c1a7e07e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,24 @@ +name: CIFuzz +on: [pull_request] +jobs: + Fuzzing: + runs-on: ubuntu-latest + steps: + - name: Build Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master + with: + oss-fuzz-project-name: 'mruby' + dry-run: false + - name: Run Fuzzers + uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master + with: + oss-fuzz-project-name: 'mruby' + fuzz-seconds: 600 + dry-run: false + - name: Upload Crash + uses: actions/upload-artifact@v1 + if: failure() + with: + name: artifacts + path: ./out/artifacts + @@ -34,7 +34,7 @@ The URL of the mruby home-page is: https://mruby.org. ## Mailing list -We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby). +We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby/issues). ## How to compile and install (mruby and gems) diff --git a/appveyor.yml b/appveyor.yml index a91834cef..bf4fb3f17 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,10 +14,18 @@ environment: # Visual Studio 2017 64bit - visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat + # Visual Studio 2017 32bit + - visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat + machine: x86 + # Visual Studio 2015 64bit - visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat machine: amd64 + # Visual Studio 2015 32bit + - visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + machine: x86 + # Visual Studio 2013 64bit - visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat machine: amd64 diff --git a/examples/targets/build_config_dreamcast_shelf.rb b/examples/targets/build_config_dreamcast_shelf.rb new file mode 100644 index 000000000..fd6915acb --- /dev/null +++ b/examples/targets/build_config_dreamcast_shelf.rb @@ -0,0 +1,108 @@ +MRuby::Build.new do |conf| + # Gets set by the VS command prompts + if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] + toolchain :visualcpp + else + toolchain :gcc + end + + enable_debug + + # Include the default GEMs + conf.gembox 'default' +end + +# Cross Compiling configuration for the Sega Dreamcast +# This configuration requires KallistiOS (KOS) +# https://dreamcast.wiki +# +# Tested on GNU/Linux, MinGW-w64/MSYS2, Cygwin, macOS and MinGW/MSYS (see below) +# +MRuby::CrossBuild.new("dreamcast") do |conf| + toolchain :gcc + + # Support for DreamSDK (based on MinGW/MSYS) + # To compile mruby with DreamSDK, RubyInstaller for Windows should be installed + DREAMSDK_HOME = ENV["DREAMSDK_HOME"] + MSYS_ROOT = !(DREAMSDK_HOME.nil? || DREAMSDK_HOME.empty?) ? "#{DREAMSDK_HOME}/msys/1.0" : "" + + # Setting paths + DREAMCAST_PATH = "#{MSYS_ROOT}/opt/toolchains/dc" + KOS_PATH = "#{DREAMCAST_PATH}/kos" + BIN_PATH = "#{DREAMCAST_PATH}/sh-elf/bin" + + # C compiler + # Flags were extracted from KallistiOS environment files + conf.cc do |cc| + cc.command = "#{BIN_PATH}/sh-elf-gcc" + cc.include_paths << ["#{KOS_PATH}/include", "#{KOS_PATH}/kernel/arch/dreamcast/include", "#{KOS_PATH}/addons/include", "#{KOS_PATH}/../kos-ports/include"] + cc.flags << ["-O2", "-fomit-frame-pointer", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-Wall", "-g", "-fno-builtin", "-ml", "-m4-single-only", "-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_PATH}/utils/ldscripts/shlelf.xc", "-nodefaultlibs"] + cc.compile_options = "%{flags} -o %{outfile} -c %{infile}" + cc.defines << %w(_arch_dreamcast) + cc.defines << %w(_arch_sub_pristine) + end + + # C++ compiler + conf.cxx do |cxx| + cxx.command = conf.cc.command.dup + cxx.include_paths = conf.cc.include_paths.dup + cxx.flags = conf.cc.flags.dup + cxx.flags << %w(-fno-rtti -fno-exceptions) + cxx.defines = conf.cc.defines.dup + cxx.compile_options = conf.cc.compile_options.dup + end + + # Linker + # There is an issue when making the mruby library with KallistiOS: + # 'newlib_kill.o' and 'newlib_getpid.o' aren't found so they are explicitly + # specified here at least for now. + conf.linker do |linker| + linker.command="#{BIN_PATH}/sh-elf-gcc" + linker.flags << ["#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_kill.o", "#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_getpid.o", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"] + linker.library_paths << ["#{KOS_PATH}/lib/dreamcast", "#{KOS_PATH}/addons/lib/dreamcast", "#{KOS_PATH}/../kos-ports/lib"] + end + + # Archiver + conf.archiver do |archiver| + archiver.command = "#{BIN_PATH}/sh-elf-ar" + archiver.archive_options = 'rcs %{outfile} %{objs}' + end + + # No executables + conf.bins = [] + + # Do not build executable test + conf.build_mrbtest_lib_only + + # Disable C++ exception + conf.disable_cxx_exception + + # Gems from core + # removing mruby-io + conf.gem :core => "mruby-metaprog" + conf.gem :core => "mruby-pack" + conf.gem :core => "mruby-sprintf" + conf.gem :core => "mruby-print" + conf.gem :core => "mruby-math" + conf.gem :core => "mruby-time" + conf.gem :core => "mruby-struct" + conf.gem :core => "mruby-compar-ext" + conf.gem :core => "mruby-enum-ext" + conf.gem :core => "mruby-string-ext" + conf.gem :core => "mruby-numeric-ext" + conf.gem :core => "mruby-array-ext" + conf.gem :core => "mruby-hash-ext" + conf.gem :core => "mruby-range-ext" + conf.gem :core => "mruby-proc-ext" + conf.gem :core => "mruby-symbol-ext" + conf.gem :core => "mruby-random" + conf.gem :core => "mruby-object-ext" + conf.gem :core => "mruby-objectspace" + conf.gem :core => "mruby-fiber" + conf.gem :core => "mruby-enumerator" + conf.gem :core => "mruby-enum-lazy" + conf.gem :core => "mruby-toplevel-ext" + conf.gem :core => "mruby-kernel-ext" + conf.gem :core => "mruby-class-ext" + conf.gem :core => "mruby-compiler" +end diff --git a/include/mrbconf.h b/include/mrbconf.h index 3a574c7d2..35762a8f0 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -38,7 +38,12 @@ /* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */ /* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ -//#define MRB_METHOD_T_STRUCT +#ifndef MRB_METHOD_T_STRUCT + // can't use highest 2 bits of function pointers on 32bit Windows. +# if defined(_WIN32) && !defined(_WIN64) +# define MRB_METHOD_T_STRUCT +# endif +#endif /* add -DMRB_INT32 to use 32bit integer for mrb_int; conflict with MRB_INT64; Default for 32-bit CPU mode. */ diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c index 8cd9cba0d..ffce0ddcb 100644 --- a/mrbgems/mruby-io/src/file.c +++ b/mrbgems/mruby-io/src/file.c @@ -282,7 +282,16 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass) static int mrb_file_is_absolute_path(const char *path) { +#ifdef _WIN32 +#define IS_PATHSEP(x) (x == '/' || x == '\\') + if (isalpha(path[0])) + return (strlen(path) > 2 && path[1] == ':' && IS_PATHSEP(path[2])); + else + return (IS_PATHSEP(path[0]) && IS_PATHSEP(path[1])); +#undef IS_PATHSEP +#else return (path[0] == '/'); +#endif } static mrb_value diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c index b7f70a5f8..0ddb04325 100644 --- a/mrbgems/mruby-io/src/io.c +++ b/mrbgems/mruby-io/src/io.c @@ -39,6 +39,7 @@ #else #include <sys/wait.h> + #include <sys/time.h> #include <unistd.h> typedef size_t fsize_t; typedef time_t ftime_t; diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 7197b634c..5ce43e465 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -238,7 +238,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) mrb_float f = mrb_float(obj); mrb_check_num_exact(mrb, f); - if (f > (mrb_float)MRB_TIME_MAX || (mrb_float)MRB_TIME_MIN > f) { + if (f >= ((mrb_float)MRB_TIME_MAX-1.0) || f < ((mrb_float)MRB_TIME_MIN+1.0)) { goto out_of_range; } diff --git a/src/string.c b/src/string.c index c7b9db17a..9ea19d107 100644 --- a/src/string.c +++ b/src/string.c @@ -504,25 +504,45 @@ str_index_str_by_char(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos) #define str_index_str_by_char(mrb, str, sub, pos) str_index_str(mrb, str, sub, pos) #endif +#ifndef MRB_QS_SHORT_STRING_LENGTH +#define MRB_QS_SHORT_STRING_LENGTH 2048 +#endif + static inline mrb_int mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mrb_int n) { - const unsigned char *x = xs, *xe = xs + m; - const unsigned char *y = ys; - int i; - ptrdiff_t qstable[256]; + if (n + m < MRB_QS_SHORT_STRING_LENGTH) { + const unsigned char *y = ys; + const unsigned char *ye = ys+n-m+1; - /* Preprocessing */ - for (i = 0; i < 256; ++i) - qstable[i] = m + 1; - for (; x < xe; ++x) - qstable[*x] = xe - x; - /* Searching */ - for (; y + m <= ys + n; y += *(qstable + y[m])) { - if (*xs == *y && memcmp(xs, y, m) == 0) - return (mrb_int)(y - ys); + for (;;) { + y = (const unsigned char*)memchr(y, xs[0], (size_t)(ye-y)); + if (y == NULL) return -1; + if (memcmp(xs, y, m) == 0) { + return (mrb_int)(y - ys); + } + y++; + } + return -1; + } + else { + const unsigned char *x = xs, *xe = xs + m; + const unsigned char *y = ys; + int i; + ptrdiff_t qstable[256]; + + /* Preprocessing */ + for (i = 0; i < 256; ++i) + qstable[i] = m + 1; + for (; x < xe; ++x) + qstable[*x] = xe - x; + /* Searching */ + for (; y + m <= ys + n; y += *(qstable + y[m])) { + if (*xs == *y && memcmp(xs, y, m) == 0) + return (mrb_int)(y - ys); + } + return -1; } - return -1; } static mrb_int |
