From 332fc3d9e06180250d960be7d77c0c441ec66434 Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Wed, 28 Feb 2018 00:55:07 -0800 Subject: [PATCH] Create Oneshot::crc32 Ruby function Due to issues in loading Zlib directly within Ruby, I decided to create a C++ binding. Boost also has a much faster and smarter CRC32 implementation, so I decided to just use it instead of working with Zlib. This also means that translations are fixed! --- binding-mri/oneshot-binding.cpp | 15 ++++++++++++++- scripts/i18n_Language.rb | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/binding-mri/oneshot-binding.cpp b/binding-mri/oneshot-binding.cpp index f1515b2..a420dec 100644 --- a/binding-mri/oneshot-binding.cpp +++ b/binding-mri/oneshot-binding.cpp @@ -6,6 +6,7 @@ #include "eventthread.h" #include +#include RB_METHOD(oneshotSetYesNo) { @@ -88,6 +89,17 @@ RB_METHOD(oneshotShake) return Qnil; } +RB_METHOD(oneshotCRC32) +{ + RB_UNUSED_PARAM; + VALUE string; + boost::crc_32_type result; + rb_get_args(argc, argv, "S", &string RB_ARG_END); + std::string str = std::string(RSTRING_PTR(string), RSTRING_LEN(string)); + result.process_bytes(str.data(), str.length()); + return UINT2NUM(result.checksum()); +} + void oneshotBindingInit() { VALUE module = rb_define_module("Oneshot"); @@ -113,5 +125,6 @@ void oneshotBindingInit() _rb_define_module_function(module, "obscured_cleared?", oneshotObscuredCleared); _rb_define_module_function(module, "allow_exit", oneshotAllowExit); _rb_define_module_function(module, "exiting", oneshotExiting); - _rb_define_module_function(module, "shake", oneshotShake); + _rb_define_module_function(module, "shake", oneshotShake); + _rb_define_module_function(module, "crc32", oneshotCRC32); } diff --git a/scripts/i18n_Language.rb b/scripts/i18n_Language.rb index 881341c..ad83990 100644 --- a/scripts/i18n_Language.rb +++ b/scripts/i18n_Language.rb @@ -52,7 +52,7 @@ class Language def tr(string) #dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"}) if @data - rv = @data[Zlib::crc32(string)] || string + rv = @data[Oneshot::crc32(string)] || string else rv = string end