Win32: Do not use GetProcAddress when compiled for Vista+

Message ID alpine.DEB.2.02.1305152357371.4486@cone.martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö May 15, 2013, 9:05 p.m.
On Tue, 14 May 2013, Martin Storsjö wrote:

> On Tue, 14 May 2013, Hendrik Leppkes wrote:
>
>> On Tue, May 14, 2013 at 1:15 PM, Martin Storsjö <martin@martin.st> wrote:
>>> On Tue, 14 May 2013, Martin Storsjö wrote:
>>> 
>>>> On Tue, 14 May 2013, Jean-Baptiste Kempf wrote:
>>>> 
>>>>> ---
>>>>> libavcodec/w32pthreads.h |    8 ++++++++
>>>>> 1 file changed, 8 insertions(+)
>>>>> 
>>>>> diff --git a/libavcodec/w32pthreads.h b/libavcodec/w32pthreads.h
>>>>> index 91e7353..c58da49 100644
>>>>> --- a/libavcodec/w32pthreads.h
>>>>> +++ b/libavcodec/w32pthreads.h
>>>>> @@ -256,6 +256,7 @@ static void pthread_cond_signal(pthread_cond_t 
>>>>> *cond)
>>>>> 
>>>>> static void w32thread_init(void)
>>>>> {
>>>>> +#if _WIN32_WINNT < 0x0600
>>>>>     HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
>>>>>     /* if one is available, then they should all be available */
>>>>>     cond_init      =
>>>>> @@ -266,6 +267,13 @@ static void w32thread_init(void)
>>>>>         (void*)GetProcAddress(kernel_dll, "WakeConditionVariable");
>>>>>     cond_wait      =
>>>>>         (void*)GetProcAddress(kernel_dll, "SleepConditionVariableCS");
>>>>> +#else
>>>>> +    cond_init      = InitializeConditionVariable;
>>>>> +    cond_broadcast = WakeAllConditionVariable;
>>>>> +    cond_signal    = WakeConditionVariable;
>>>>> +    cond_wait      = SleepConditionVariableCS;
>>>>> +#endif
>>>>> +
>>>>> }
>>>>> 
>>>>> #endif /* AVCODEC_W32PTHREADS_H */
>>>>> --
>>>>> 1.7.10.4
>>>> 
>>>> 
>>>> Ok with me
>>> 
>>> 
>>> For the record - this is enabled by default in MSVC 2010, but not in mingw
>>> or mingw-w64. If this isn't desired in MSVC, one can always add
>>> --extra-cflags='-D_WIN32_WINNT=0x510'.
>>> 
>>> I'll push the patch later today.
>>> 
>>> // Martin
>> 
>> Changing the default for MSVC might be risky if people are not aware of 
>> this.
>> Last night on IRC it sounded like 2010 would still target XP by
>> default, which would be fine, but changing the default to include
>> Vista+ functions may not be a good course of action yet.

What would you think of a patch like this, then?



This would allow users to set whatever windows version as baseline they 
like, but make sure people don't accidentally produce vista-only binaries 
(since that's probably not desireable).

That would keep j-b's patch in a pretty simple form. (Ideally, an even 
better version of j-b's patch would be to check for the 
InitializeConditionVariable function using normal function checks, but it 
seems to be widely visible in the msvc/winsdk headers regardless of the 
_WIN32_WINNT version - dunno why. So due to that we can't really rely on 
such a check...)

// Martin

Patch

diff --git a/configure b/configure
index 7bcaac3..49ad0c4 100755
--- a/configure
+++ b/configure
@@ -3196,6 +3196,7 @@  elif check_func_headers stdlib.h _get_doserrno; then
      add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf   \
                                   _snprintf=avpriv_snprintf  \
                                   vsnprintf=avpriv_vsnprintf
+    check_cpp_condition "" "defined(_WIN32_WINNT)" || add_cppflags -D_WIN32_WINNT=0x0502
  elif check_cpp_condition stddef.h "defined __KLIBC__"; then
      libc_type=klibc
  fi