From patchwork Thu Apr 13 09:47:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Levinson X-Patchwork-Id: 3391 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp618982vsd; Thu, 13 Apr 2017 02:47:53 -0700 (PDT) X-Received: by 10.28.128.197 with SMTP id b188mr22871368wmd.115.1492076873001; Thu, 13 Apr 2017 02:47:53 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s95si35390411wrc.222.2017.04.13.02.47.52; Thu, 13 Apr 2017 02:47:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 89E71688327; Thu, 13 Apr 2017 12:47:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from white.spiritone.com (white.spiritone.com [216.99.193.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 04C3068040B for ; Thu, 13 Apr 2017 12:47:36 +0300 (EEST) Received: from [192.168.3.100] (184-100-162-109.ptld.qwest.net [184.100.162.109]) by white.spiritone.com (Postfix) with ESMTPSA id 3722C73402D9 for ; Thu, 13 Apr 2017 02:47:41 -0700 (PDT) To: FFmpeg development discussions and patches References: <38d68a7f-23fd-d9ab-0c4c-f3bc398eb92d@aracnet.com> <857944da-aa1e-4a6a-d0aa-b751721b15b7@aracnet.com> From: Aaron Levinson Message-ID: <719306ce-2710-fbdf-15db-7a49ecb5037c@aracnet.com> Date: Thu, 13 Apr 2017 02:47:39 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] Made appropriate changes to be able to successfully build C++ files using a Visual C++ build on Windows X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 4/13/2017 2:10 AM, Hendrik Leppkes wrote: > On Thu, Apr 13, 2017 at 11:04 AM, Aaron Levinson wrote: >> static av_unused int pthread_cond_signal(pthread_cond_t *cond) >> { >> - win32_cond_t *win32_cond = cond->Ptr; >> + win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr; >> int have_waiter; >> if (cond_signal) { >> cond_signal(cond); >> @@ -400,17 +400,17 @@ static av_unused void w32thread_init(void) >> HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll")); >> /* if one is available, then they should all be available */ >> cond_init = (void (WINAPI*)(pthread_cond_t *)) >> - GetProcAddress(kernel_dll, "InitializeConditionVariable"); >> + GetProcAddress((HMODULE)kernel_dll, "InitializeConditionVariable"); >> cond_broadcast = (void (WINAPI*)(pthread_cond_t *)) >> - GetProcAddress(kernel_dll, "WakeAllConditionVariable"); >> + GetProcAddress((HMODULE)kernel_dll, "WakeAllConditionVariable"); >> cond_signal = (void (WINAPI*)(pthread_cond_t *)) >> - GetProcAddress(kernel_dll, "WakeConditionVariable"); >> + GetProcAddress((HMODULE)kernel_dll, "WakeConditionVariable"); >> cond_wait = (BOOL (WINAPI*)(pthread_cond_t *, pthread_mutex_t *, DWORD)) >> - GetProcAddress(kernel_dll, "SleepConditionVariableCS"); >> + GetProcAddress((HMODULE)kernel_dll, "SleepConditionVariableCS"); >> initonce_begin = (BOOL (WINAPI*)(pthread_once_t *, DWORD, BOOL *, void **)) >> - GetProcAddress(kernel_dll, "InitOnceBeginInitialize"); >> + GetProcAddress((HMODULE)kernel_dll, "InitOnceBeginInitialize"); >> initonce_complete = (BOOL (WINAPI*)(pthread_once_t *, DWORD, void *)) >> - GetProcAddress(kernel_dll, "InitOnceComplete"); >> + GetProcAddress((HMODULE)kernel_dll, "InitOnceComplete"); >> #endif > > One more comment that I missed earlier (sorry), GetModuleHandle > returns the type HMODULE, can't you just change the type of kernel_dll > to match that, and avoid the casts here? > > - Hendrik Yes, it is simpler and cleaner to properly set the return value of GetModuleHandle() to an HMODULE. Here is what is hopefully the final version of the patch, which is also much cleaner and simplified from the original version. Thanks, Aaron ------------------------------------------------------------------ From 56f9a4b6c281a0d9382d2b4ec2e29aff5ab69fbc Mon Sep 17 00:00:00 2001 From: Aaron Levinson Date: Thu, 13 Apr 2017 02:38:02 -0700 Subject: [PATCH] Made appropriate changes to be able to successfully build C++ files using a Visual C++ build on Windows Purpose: Made appropriate changes to be able to successfully build C++ files using a Visual C++ build on Windows. Note that this is a continuation of the "fixes w32pthreads to support C++" aspect of Kyle Schwarz's "Remove pthread dependency" patch that is available at https://patchwork.ffmpeg.org/patch/2654/ . This patch wasn't accepted, and as far as I can tell, there was no follow-up after it was rejected. Notes: Used Visual Studio 2015 (with update 3) for this. Altered approach for specifying -Fo$@ in configure based on code review from Hendrik Leppkes for first version of patch. Also simplified changes to w32pthreads.h per Hendrik's review. Comments: -- compat/w32pthreads.h: Made appropriate changes to w32pthreads.h to get it to build when it is being included in a C++ file and built with Visual C++. This is mostly a copy of Kyle Schwarz's patch as described above. -- configure: a) Now calling set_ccvars CXX to cause the various CXX_ variables to be setup properly. For example, with MSVC (Microsoft Visual C++), this causes CXX_O to be set to -Fo$@ instead of using the default value. The default value does not work with Visual C++. This change will also have the impact of correcting CXX_O (and possibly CXX_C) for other compilers, although this is really only relevant for the Intel compiler, in addition to MSVC. b) Now using cl for the C++ compiler for the MSVC toolchain. This is currently only relevant for building the Blackmagic/Decklink-related files under avdevice. --- compat/w32pthreads.h | 14 +++++++------- configure | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h index 0c9a7fa..eeead60 100644 --- a/compat/w32pthreads.h +++ b/compat/w32pthreads.h @@ -77,7 +77,7 @@ typedef struct pthread_cond_t { static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg) { - pthread_t *h = arg; + pthread_t *h = (pthread_t*)arg; h->ret = h->func(h->arg); return 0; } @@ -270,7 +270,7 @@ static av_unused int pthread_cond_init(pthread_cond_t *cond, const void *unused_ } /* non native condition variables */ - win32_cond = av_mallocz(sizeof(win32_cond_t)); + win32_cond = (win32_cond_t*)av_mallocz(sizeof(win32_cond_t)); if (!win32_cond) return ENOMEM; cond->Ptr = win32_cond; @@ -288,7 +288,7 @@ static av_unused int pthread_cond_init(pthread_cond_t *cond, const void *unused_ static av_unused int pthread_cond_destroy(pthread_cond_t *cond) { - win32_cond_t *win32_cond = cond->Ptr; + win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr; /* native condition variables do not destroy */ if (cond_init) return 0; @@ -305,7 +305,7 @@ static av_unused int pthread_cond_destroy(pthread_cond_t *cond) static av_unused int pthread_cond_broadcast(pthread_cond_t *cond) { - win32_cond_t *win32_cond = cond->Ptr; + win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr; int have_waiter; if (cond_broadcast) { @@ -337,7 +337,7 @@ static av_unused int pthread_cond_broadcast(pthread_cond_t *cond) static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { - win32_cond_t *win32_cond = cond->Ptr; + win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr; int last_waiter; if (cond_wait) { cond_wait(cond, mutex, INFINITE); @@ -369,7 +369,7 @@ static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu static av_unused int pthread_cond_signal(pthread_cond_t *cond) { - win32_cond_t *win32_cond = cond->Ptr; + win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr; int have_waiter; if (cond_signal) { cond_signal(cond); @@ -397,7 +397,7 @@ static av_unused int pthread_cond_signal(pthread_cond_t *cond) static av_unused void w32thread_init(void) { #if _WIN32_WINNT < 0x0600 - HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll")); + HMODULE kernel_dll = GetModuleHandle(TEXT("kernel32.dll")); /* if one is available, then they should all be available */ cond_init = (void (WINAPI*)(pthread_cond_t *)) GetProcAddress(kernel_dll, "InitializeConditionVariable"); diff --git a/configure b/configure index b2fc781..43f0938 100755 --- a/configure +++ b/configure @@ -3637,8 +3637,10 @@ case "$toolchain" in cl_major_ver=$(cl 2>&1 | sed -n 's/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p') if [ -z "$cl_major_ver" ] || [ $cl_major_ver -ge 18 ]; then cc_default="cl" + cxx_default="cl" else cc_default="c99wrap cl" + cxx_default="c99wrap cl" fi ld_default="$source_path/compat/windows/mslink" nm_default="dumpbin -symbols" @@ -4196,6 +4198,7 @@ cflags_noopt=$_cflags_noopt add_cflags $_flags $_cflags cc_ldflags=$_ldflags set_ccvars CC +set_ccvars CXX probe_cc hostcc "$host_cc" host_cflags_filter=$_flags_filter