From aac0e5be49760599c22ce4914df3c46a94cebb7a Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 1 Aug 2024 11:54:41 +0200 Subject: [PATCH 1/4] Update to more recent ruby versions and bump minimum ruby version to 2.5 --- Rakefile | 2 +- ext/wdm/extconf.rb | 11 ++++------- ext/wdm/rb_change.c | 4 +--- ext/wdm/rb_monitor.c | 24 +++++++++--------------- ext/wdm/wdm.h | 7 ++++--- spec/support/fixture_helper.rb | 4 ++-- spec/wdm/monitor_spec.rb | 10 +--------- wdm.gemspec | 2 +- 8 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Rakefile b/Rakefile index 17971a0..f32c5fc 100644 --- a/Rakefile +++ b/Rakefile @@ -13,5 +13,5 @@ end desc "Open an irb session preloaded with WDM" task :console do - sh "irb -rubygems -I lib -r wdm" + sh "irb -I lib -r wdm" end diff --git a/ext/wdm/extconf.rb b/ext/wdm/extconf.rb index 26a6d59..533e85a 100644 --- a/ext/wdm/extconf.rb +++ b/ext/wdm/extconf.rb @@ -16,13 +16,10 @@ def windows? end if windows? and - have_library("kernel32") and - have_header("windows.h") and - have_header("ruby.h") and - have_const('HAVE_RUBY_ENCODING_H') + have_library("kernel32") and + have_header("windows.h") then - have_func('rb_thread_call_without_gvl') - generate_makefile() + generate_makefile() else - generate_dummy_makefile() + generate_dummy_makefile() end diff --git a/ext/wdm/rb_change.c b/ext/wdm/rb_change.c index fe0df64..a91100d 100644 --- a/ext/wdm/rb_change.c +++ b/ext/wdm/rb_change.c @@ -136,8 +136,6 @@ extract_absolute_path_from_notification(const LPWSTR base_dir, const PFILE_NOTIF multibyte_filepath_buffer_size - 1, // -1 because this func takes the chars count, not bytes count wdm_rb_enc_utf8); - OBJ_TAINT(path); - return path; } @@ -196,4 +194,4 @@ wdm_rb_change_init() rb_define_attr(cWDM_Change, "path", 1, 0); rb_define_attr(cWDM_Change, "type", 1, 0); -} \ No newline at end of file +} diff --git a/ext/wdm/rb_monitor.c b/ext/wdm/rb_monitor.c index 3026295..72929b4 100644 --- a/ext/wdm/rb_monitor.c +++ b/ext/wdm/rb_monitor.c @@ -50,7 +50,7 @@ static void CALLBACK handle_entry_change(DWORD, DWORD, LPOVERLAPPED); static BOOL register_monitoring_entry(WDM_PEntry); static DWORD WINAPI start_monitoring(LPVOID); -static VALUE wait_for_changes(LPVOID); +static void *wait_for_changes(void *); static void process_changes(WDM_PQueue); static void stop_monitoring(LPVOID); static VALUE rb_monitor_run_bang(VALUE); @@ -367,14 +367,14 @@ start_monitoring(LPVOID param) return 0; } -static VALUE -wait_for_changes(LPVOID param) +static void * +wait_for_changes(void *param) { - HANDLE process_event; - - process_event = (HANDLE)param; + HANDLE process_event = (HANDLE)param; + VALUE rb_res; - return WaitForSingleObject(process_event, INFINITE) == WAIT_OBJECT_0 ? Qtrue : Qfalse; + rb_res = WaitForSingleObject(process_event, INFINITE) == WAIT_OBJECT_0 ? Qtrue : Qfalse; + return (void *)rb_res; } static void @@ -503,13 +503,7 @@ rb_monitor_run_bang(VALUE self) while ( monitor->running ) { - // Ruby 2.2 removed the 'rb_thread_blocking_region' function. Hence, we now need - // to check if the replacement function is defined and use it if it's available. - #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL - waiting_succeeded = rb_thread_call_without_gvl(wait_for_changes, monitor->process_event, stop_monitoring, monitor); - #else - waiting_succeeded = rb_thread_blocking_region(wait_for_changes, monitor->process_event, stop_monitoring, monitor); - #endif + waiting_succeeded = (VALUE)rb_thread_call_without_gvl(wait_for_changes, monitor->process_event, stop_monitoring, monitor); if ( waiting_succeeded == Qfalse ) { rb_raise(eWDM_Error, "Failed while waiting for a change in the watched directories!"); @@ -572,4 +566,4 @@ wdm_rb_monitor_init() rb_define_method(cWDM_Monitor, "watch_recursively", RUBY_METHOD_FUNC(rb_monitor_watch_recursively), -1); rb_define_method(cWDM_Monitor, "run!", RUBY_METHOD_FUNC(rb_monitor_run_bang), 0); rb_define_method(cWDM_Monitor, "stop", RUBY_METHOD_FUNC(rb_monitor_stop), 0); -} \ No newline at end of file +} diff --git a/ext/wdm/wdm.h b/ext/wdm/wdm.h index f13c182..dec1f17 100644 --- a/ext/wdm/wdm.h +++ b/ext/wdm/wdm.h @@ -3,7 +3,7 @@ // Support Windows 2000 and later, // this is needed for 'GetLongPathNameW' (both of the following defines) #ifndef WINVER -#define WINVER 0x0500 +#define WINVER 0x0500 #endif #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 @@ -14,13 +14,14 @@ #define WIN32_LEAN_AND_MEAN #endif #ifndef VC_EXTRALEAN -#define VC_EXTRALEAN +#define VC_EXTRALEAN #endif #include #include #include +#include #ifndef WDM_H #define WDM_H @@ -79,4 +80,4 @@ void Init_wdm_ext(); } #endif // __cplusplus -#endif // WDM_H \ No newline at end of file +#endif // WDM_H diff --git a/spec/support/fixture_helper.rb b/spec/support/fixture_helper.rb index d311953..be41c5f 100644 --- a/spec/support/fixture_helper.rb +++ b/spec/support/fixture_helper.rb @@ -21,7 +21,7 @@ def fixture ensure FileUtils.cd pwd - FileUtils.rm_rf(path) if File.exists?(path) + FileUtils.rm_rf(path) if File.exist?(path) end end -end \ No newline at end of file +end diff --git a/spec/wdm/monitor_spec.rb b/spec/wdm/monitor_spec.rb index 2352b7f..975ff2a 100644 --- a/spec/wdm/monitor_spec.rb +++ b/spec/wdm/monitor_spec.rb @@ -170,14 +170,6 @@ end end - it 'marks changed paths as tainted' do - result = run_with_fixture(subject) do - touch 'file.txt' - end - - expect(result.change.path).to be_tainted - end - it 'reports changes with absolute paths even when passed relative directory to watch' do fixture do |dir| relative_dir = Pathname.new(dir).relative_path_from(Pathname.new(Dir.pwd)).to_s @@ -227,4 +219,4 @@ expect(result.change.path.encoding.name).to be == "UTF-8" end end -end \ No newline at end of file +end diff --git a/wdm.gemspec b/wdm.gemspec index fd58ac2..e47cb66 100644 --- a/wdm.gemspec +++ b/wdm.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gem| gem.require_paths = ['lib'] gem.version = '0.1.1' - gem.required_ruby_version = '>= 1.9.2' + gem.required_ruby_version = '>= 2.5' gem.add_development_dependency 'rake-compiler' gem.add_development_dependency 'rspec' From 4440c29c6311ea1084d9931252186d6319120053 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 1 Aug 2024 11:57:13 +0200 Subject: [PATCH 2/4] CI: Adjust to run the specs on more recent ruby version --- appveyor.yml | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e29ce9d..14a1156 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,29 +1,32 @@ --- +image: Visual Studio 2022 version: '{build}' skip_tags: true environment: matrix: - - ruby_version: "193" - devkit: C:\Ruby193\DevKit - - ruby_version: "200" - devkit: C:\Ruby21\DevKit - - ruby_version: "200-x64" - devkit: C:\Ruby21-x64\DevKit - - ruby_version: "21" - devkit: C:\Ruby21\DevKit - - ruby_version: "21-x64" - devkit: C:\Ruby21-x64\DevKit - - ruby_version: "22" - devkit: C:\Ruby21\DevKit - - ruby_version: "22-x64" - devkit: C:\Ruby21-x64\DevKit + - ruby_version: "head-x64" + - ruby_version: "25" + - ruby_version: "30" + - ruby_version: "33-x64" -install: +init: - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - - "%devkit%\\devkitvars.bat" - - gem install bundler --no-rdoc --no-ri + +install: + - ps: | + if ($env:ruby_version -like "*head*") { + $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-$env:ruby_version.exe", "$pwd/ruby-setup.exe") + cmd /c ruby-setup.exe /verysilent /currentuser /dir=C:/Ruby$env:ruby_version + } + - ruby --version + - gem --version + - ridk version + - ridk enable + - c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-gcc" + - gcc -v + - gem install bundler:2.3.27 --conservative --no-doc - bundler env - bundle install --retry=3 From 97e83c5ac0b7f40242ac6f05cb11481456215e83 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 1 Aug 2024 13:26:32 +0200 Subject: [PATCH 3/4] development dependencies are better suited into the Gemfile ... and pry and devkit gems are not very useful these days. --- Gemfile | 7 +++++++ wdm.gemspec | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 7f7f23f..55d66fb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,10 @@ source 'https://rubygems.org' # Specify your gem's dependencies in wdm.gemspec gemspec + +group :development do + gem 'rake-compiler' + gem 'rspec' + gem 'guard-rspec' + gem 'guard-shell' +end diff --git a/wdm.gemspec b/wdm.gemspec index e47cb66..c3a8718 100644 --- a/wdm.gemspec +++ b/wdm.gemspec @@ -17,11 +17,4 @@ Gem::Specification.new do |gem| gem.version = '0.1.1' gem.required_ruby_version = '>= 2.5' - - gem.add_development_dependency 'rake-compiler' - gem.add_development_dependency 'rspec' - gem.add_development_dependency 'guard-rspec' - gem.add_development_dependency 'guard-shell' - gem.add_development_dependency 'pry' - gem.add_development_dependency 'devkit' end From 6bf22ce3efd1b6a6dc464634b48686a68ce47167 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Fri, 2 Aug 2024 13:21:02 +0200 Subject: [PATCH 4/4] Fix deprecation in ruby-3.4 Kind of: ext/wdm/rb_monitor.c: In function 'rb_monitor_alloc': ext/wdm/rb_monitor.c:109:5: warning: 'rb_data_object_wrap_warning' is deprecated: by TypedData [-Wdeprecated-declarations] 109 | return Data_Wrap_Struct(self, monitor_mark, monitor_free, wdm_monitor_new()); | ^~~~~~ In file included from C:/Ruby34-x64/include/ruby-3.4.0+0/ruby/internal/core.h:27, from C:/Ruby34-x64/include/ruby-3.4.0+0/ruby/ruby.h:29, from C:/Ruby34-x64/include/ruby-3.4.0+0/ruby.h:38, from ../../../../ext/wdm/wdm.h:22, from ../../../../ext/wdm/rb_monitor.c:1: --- ext/wdm/rb_monitor.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ext/wdm/rb_monitor.c b/ext/wdm/rb_monitor.c index 72929b4..05893e5 100644 --- a/ext/wdm/rb_monitor.c +++ b/ext/wdm/rb_monitor.c @@ -99,6 +99,16 @@ monitor_free(LPVOID param) wdm_monitor_free(monitor); } +static const rb_data_type_t monitor_data_type = { + .wrap_struct_name = "WDM::Monitor", + .function = { + .dmark = monitor_mark, + .dfree = monitor_free, + .dsize = NULL, + }, + .flags = 0 +}; + static VALUE rb_monitor_alloc(VALUE self) { @@ -106,7 +116,7 @@ rb_monitor_alloc(VALUE self) WDM_DEBUG("Allocating a new monitor object!"); WDM_DEBUG("--------------------------------"); - return Data_Wrap_Struct(self, monitor_mark, monitor_free, wdm_monitor_new()); + return TypedData_Wrap_Struct(self, &monitor_data_type, wdm_monitor_new()); } static DWORD @@ -156,7 +166,7 @@ combined_watch(BOOL recursively, int argc, VALUE *argv, VALUE self) // TODO: Maybe raise a more user-friendly error? rb_need_block(); - Data_Get_Struct(self, WDM_Monitor, monitor); + TypedData_Get_Struct(self, WDM_Monitor, &monitor_data_type, monitor); EnterCriticalSection(&monitor->lock); running = monitor->running; @@ -467,7 +477,7 @@ rb_monitor_run_bang(VALUE self) WDM_DEBUG("Running the monitor!"); - Data_Get_Struct(self, WDM_Monitor, monitor); + TypedData_Get_Struct(self, WDM_Monitor, &monitor_data_type, monitor); already_running = FALSE; EnterCriticalSection(&monitor->lock); @@ -529,7 +539,7 @@ rb_monitor_stop(VALUE self) { WDM_PMonitor monitor; - Data_Get_Struct(self, WDM_Monitor, monitor); + TypedData_Get_Struct(self, WDM_Monitor, &monitor_data_type, monitor); stop_monitoring(monitor);