[2/3] Use LoadLibraryW in the generic dynamic library loading

Message ID 1468579396-35501-2-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö July 15, 2016, 10:43 a.m.
This allows loading libraries from arbitrary, non-ascii paths.
---
 configure                |  6 +++---
 libavutil/dyn_lib_open.h | 19 +++++++++++++++++--
 2 files changed, 20 insertions(+), 5 deletions(-)

Comments

Luca Barbato July 15, 2016, 1:21 p.m. | #1
On 15/07/16 12:43, Martin Storsjö wrote:
> This allows loading libraries from arbitrary, non-ascii paths.
> ---
>  configure                |  6 +++---
>  libavutil/dyn_lib_open.h | 19 +++++++++++++++++--
>  2 files changed, 20 insertions(+), 5 deletions(-)
> 

Sure.
Diego Biurrun July 25, 2016, 11:03 a.m. | #2
On Fri, Jul 15, 2016 at 01:43:15PM +0300, Martin Storsjö wrote:
> --- a/configure
> +++ b/configure
> --- a/libavutil/dyn_lib_open.h
> +++ b/libavutil/dyn_lib_open.h
> @@ -21,10 +21,25 @@
>  
>  #include "config.h"
>  
> -#if HAVE_LOADLIBRARY
> +#if HAVE_LOADLIBRARYW
>  #include <windows.h>
> +#include "wchar_filename.h"

Add an empty line between system and libavutil headers.

Diego
Martin Storsjö July 25, 2016, 11:13 a.m. | #3
On Mon, 25 Jul 2016, Diego Biurrun wrote:

> On Fri, Jul 15, 2016 at 01:43:15PM +0300, Martin Storsjö wrote:
>> --- a/configure
>> +++ b/configure
>> --- a/libavutil/dyn_lib_open.h
>> +++ b/libavutil/dyn_lib_open.h
>> @@ -21,10 +21,25 @@
>>
>>  #include "config.h"
>> 
>> -#if HAVE_LOADLIBRARY
>> +#if HAVE_LOADLIBRARYW
>>  #include <windows.h>
>> +#include "wchar_filename.h"
>
> Add an empty line between system and libavutil headers.

Amended locally.

// Martin

Patch

diff --git a/configure b/configure
index a7671b7..ed32341 100755
--- a/configure
+++ b/configure
@@ -1573,7 +1573,7 @@  SYSTEM_FUNCS="
     inet_aton
     isatty
     jack_port_get_latency_range
-    LoadLibrary
+    LoadLibraryW
     localtime_r
     mach_absolute_time
     MapViewOfFile
@@ -4478,7 +4478,7 @@  check_func_headers windows.h CoTaskMemFree -lole32
 check_func_headers windows.h GetProcessAffinityMask
 check_func_headers windows.h GetProcessTimes
 check_func_headers windows.h GetSystemTimeAsFileTime
-check_func_headers windows.h LoadLibrary
+check_func_headers windows.h LoadLibraryW
 check_func_headers windows.h MapViewOfFile
 check_func_headers windows.h SetConsoleTextAttribute
 check_func_headers windows.h Sleep
@@ -4568,7 +4568,7 @@  done
 
 # This needs to be evaluated here instead of via the generic mechanism
 # (setting dyn_lib_open_deps_any) since we want it set here
-enabled_any dlopen LoadLibrary && enable dyn_lib_open || disable dyn_lib_open
+enabled_any dlopen LoadLibraryW && enable dyn_lib_open || disable dyn_lib_open
 
 # these are off by default, so fail if requested and not available
 enabled avisynth          && { { check_header "avisynth/avisynth_c.h" && enabled dyn_lib_open; } ||
diff --git a/libavutil/dyn_lib_open.h b/libavutil/dyn_lib_open.h
index d69d169..c81646c 100644
--- a/libavutil/dyn_lib_open.h
+++ b/libavutil/dyn_lib_open.h
@@ -21,10 +21,25 @@ 
 
 #include "config.h"
 
-#if HAVE_LOADLIBRARY
+#if HAVE_LOADLIBRARYW
 #include <windows.h>
+#include "wchar_filename.h"
+
+static void* load_library(const char *filename_utf8)
+{
+    wchar_t *filename_w;
+    void *ret;
+
+    if (utf8towchar(filename_utf8, &filename_w))
+        return NULL;
+    /* Not trying to fall back to ACP */
+    if (!filename_w)
+        return NULL;
+    ret = LoadLibraryW(filename_w);
+    av_free(filename_w);
+    return ret;
+}
 
-#define load_library LoadLibrary
 #define get_function GetProcAddress
 #define free_library FreeLibrary