-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C-ext "win32/dll_directory" as an alternative to fiddle
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
mingw-w64-ruby-head/0001-Add-C-ext-win32-dll_directory-as-an-alternative-to-f.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
From fd61aba54664f3374e950e260876a64369b5c839 Mon Sep 17 00:00:00 2001 | ||
From: Lars Kanis <[email protected]> | ||
Date: Tue, 28 Dec 2021 11:11:42 +0100 | ||
Subject: [PATCH] Add C-ext "win32/dll_directory" as an alternative to fiddle | ||
|
||
--- | ||
ext/win32/dll_directory/depend | 2 ++ | ||
ext/win32/dll_directory/dll_directory.c | 42 +++++++++++++++++++++++++ | ||
ext/win32/dll_directory/extconf.rb | 3 ++ | ||
3 files changed, 47 insertions(+) | ||
create mode 100644 ext/win32/dll_directory/depend | ||
create mode 100644 ext/win32/dll_directory/dll_directory.c | ||
create mode 100644 ext/win32/dll_directory/extconf.rb | ||
|
||
diff --git a/ext/win32/dll_directory/depend b/ext/win32/dll_directory/depend | ||
new file mode 100644 | ||
index 0000000000..0301ce074c | ||
--- /dev/null | ||
+++ b/ext/win32/dll_directory/depend | ||
@@ -0,0 +1,2 @@ | ||
+# AUTOGENERATED DEPENDENCIES START | ||
+# AUTOGENERATED DEPENDENCIES END | ||
diff --git a/ext/win32/dll_directory/dll_directory.c b/ext/win32/dll_directory/dll_directory.c | ||
new file mode 100644 | ||
index 0000000000..d44b8f2cb3 | ||
--- /dev/null | ||
+++ b/ext/win32/dll_directory/dll_directory.c | ||
@@ -0,0 +1,42 @@ | ||
+#include <ruby.h> | ||
+#include <ruby/encoding.h> | ||
+#include <windows.h> | ||
+#include <libloaderapi.h> | ||
+ | ||
+#define PTR2NUM(x) (ULL2NUM((LONG_LONG)(x))) | ||
+#define NUM2PTR(x) ((void*)(NUM2ULL(x))) | ||
+ | ||
+static VALUE | ||
+s_SetDefaultDllDirectories(VALUE self, VALUE flags) | ||
+{ | ||
+ int ret = SetDefaultDllDirectories(RB_NUM2LONG(flags)); | ||
+ return RB_INT2NUM(ret); | ||
+} | ||
+ | ||
+static VALUE | ||
+s_AddDllDirectory(VALUE self, VALUE dir) | ||
+{ | ||
+ void *handle; | ||
+ int encidx = rb_enc_find_index("utf-16le"); | ||
+ StringValueCStr(dir); | ||
+ dir = rb_str_export_to_enc(dir, rb_enc_from_index(encidx)); | ||
+ handle = AddDllDirectory((PCWSTR)RSTRING_PTR(dir)); | ||
+ return PTR2NUM(handle); | ||
+} | ||
+ | ||
+static VALUE | ||
+s_RemoveDllDirectory(VALUE self, VALUE handle) | ||
+{ | ||
+ int ret = RemoveDllDirectory(NUM2PTR(handle)); | ||
+ return RB_INT2NUM(ret); | ||
+} | ||
+ | ||
+void | ||
+Init_dll_directory(void) | ||
+{ | ||
+ VALUE mWin32 = rb_define_module("Win32"); | ||
+ VALUE mDD = rb_define_module_under(mWin32, "DllDirectory"); | ||
+ rb_define_singleton_method(mDD, "SetDefaultDllDirectories", s_SetDefaultDllDirectories, 1); | ||
+ rb_define_singleton_method(mDD, "AddDllDirectory", s_AddDllDirectory, 1); | ||
+ rb_define_singleton_method(mDD, "RemoveDllDirectory", s_RemoveDllDirectory, 1); | ||
+} | ||
diff --git a/ext/win32/dll_directory/extconf.rb b/ext/win32/dll_directory/extconf.rb | ||
new file mode 100644 | ||
index 0000000000..cfdeafacaf | ||
--- /dev/null | ||
+++ b/ext/win32/dll_directory/extconf.rb | ||
@@ -0,0 +1,3 @@ | ||
+if have_library('kernel32', 'AddDllDirectory') | ||
+ create_makefile('win32/dll_directory') | ||
+end | ||
-- | ||
2.30.0.windows.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters