From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0B7E5401B2 for ; Wed, 20 Apr 2022 11:31:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D65BF68B3B4; Wed, 20 Apr 2022 14:31:30 +0300 (EEST) Received: from mail8.parnet.fi (mail8.parnet.fi [77.234.108.134]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 463A668B31D for ; Wed, 20 Apr 2022 14:31:29 +0300 (EEST) Received: from mail9.parnet.fi (mail9.parnet.fi [77.234.108.21]) by mail8.parnet.fi with ESMTP id 23KBVS8U026828-23KBVS8V026828 for ; Wed, 20 Apr 2022 14:31:28 +0300 Received: from foo.martin.st (host-97-187.parnet.fi [77.234.97.187]) by mail9.parnet.fi (Postfix) with ESMTPS id D8FB8A1513 for ; Wed, 20 Apr 2022 14:31:28 +0300 (EEST) Date: Wed, 20 Apr 2022 14:31:28 +0300 (EEST) From: =?ISO-8859-15?Q?Martin_Storsj=F6?= To: FFmpeg development discussions and patches In-Reply-To: <20220415080748.18517-1-nil-admirari@mailo.com> Message-ID: <0fbd157-156f-d03a-a5d6-2fbd3c38dc78@martin.st> References: <20220415080748.18517-1-nil-admirari@mailo.com> MIME-Version: 1.0 X-FE-Policy-ID: 3:14:2:SYSTEM Subject: Re: [FFmpeg-devel] [PATCH v9 1/6] libavutil/wchar_filename.h: Add whcartoutf8, wchartoansi and utf8toansi X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 15 Apr 2022, Nil Admirari wrote: > These functions are going to be used in libavformat/avisynth.c > and fftools/cmdutils.c remove MAX_PATH limit. > --- > libavutil/wchar_filename.h | 51 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) I looked through this patchset now, and I think it overall looks acceptable - with a couple minor things I'd like touched up and clarified. However while reviewing this, I noticed a preexisting issue regarding the av_fopen_utf8 function. This patchset extends the use of that function into fftools, which isn't great given the issue... The use is fairly marginal (the preset files) so I guess it can be tolerated, as it's a preexisting orthogonal issue. The other question is whether it's tolerable to use more non-installed headers (like libavutil/wchar_filename.h) in fftools. (I'd like to have this point confirmed with Anton before landing the patchset.) A couple comments on the patch below: > diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h > index 90f08245..e22ffa8a 100644 > --- a/libavutil/wchar_filename.h > +++ b/libavutil/wchar_filename.h > @@ -40,6 +40,57 @@ static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w) > MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars); > return 0; > } > + > +av_warn_unused_result > +static inline int wchartocp(const unsigned int code_page, const wchar_t *filename_w, > + char **filename) > +{ > + const DWORD flags = code_page == CP_UTF8 ? MB_ERR_INVALID_CHARS : 0; > + const int num_chars = WideCharToMultiByte(code_page, flags, filename_w, -1, > + NULL, 0, NULL, NULL); We don't generally use 'const' like this in ffmpeg; we use 'const' where it makes a functional difference (i.e. on the type that pointers point at), but not for plain scalar values (neither parameters nor local variables). > + if (num_chars <= 0) { > + *filename = NULL; > + return 0; > + } > + *filename = av_calloc(num_chars, sizeof(char)); > + if (!*filename) { > + errno = ENOMEM; > + return -1; > + } > + WideCharToMultiByte(code_page, flags, filename_w, -1, > + *filename, num_chars, NULL, NULL); > + return 0; > +} > + > +av_warn_unused_result > +static inline int wchartoutf8(const wchar_t *filename_w, char **filename) > +{ > + return wchartocp(CP_UTF8, filename_w, filename); > +} > + > +av_warn_unused_result > +static inline int wchartoansi(const wchar_t *filename_w, char **filename) > +{ > + return wchartocp(CP_THREAD_ACP, filename_w, filename); > +} I think this actually would be more correct to use CP_ACP, not CP_THREAD_ACP. A bit of googling led me to https://github.com/ocaml/ocaml/issues/7854 which indicates that CP_ACP is used for ansi file functions, regardless of the current thread specific codepage. (But I see that this already is used in libavformat/avisynth.c, so it's in one sense a preexisting issue, but I think it'd be more correct to use CP_ACP here.) // Martin _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".