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 8482043493 for ; Mon, 13 Jun 2022 18:55:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6462968B596; Mon, 13 Jun 2022 21:55:31 +0300 (EEST) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87D2368B18C for ; Mon, 13 Jun 2022 21:55:24 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id a15so10294939lfb.9 for ; Mon, 13 Jun 2022 11:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=y0RtKwmJDXWYlnM8hmnxBBOLsEO8VayIv46c3GXtspU=; b=Wjy6ZX2swtzHvpslDLukrLIQZlBI21u4WjJ1OJdhibb5ikN1bOlnQ3aCYt3DEmx5uA VHoQk4hRxu5ab4E1sW8MPoFFdhVfG4GLLYla6lPlsTlUrUcHmsfbon86TsX5WUgmHcKy g4by08z7t6gE7HFA/3h58rxli02022rN42hEZP/gpjjv7NRskggxRh8rtAdNMkgq2WCe qQd2wsx4dOHozb9r3GNMpi73AxRMc1OTPQReGkfF/ebfOiMA3vTkl5SH5TtY8+AVWBq2 Zbw0eaJ8aJkEGdaLoFgShXbcCAs1tqhHS5qiaK3/zx2chdhQv3ZPxe6mkWVVfevAu9b3 vC5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=y0RtKwmJDXWYlnM8hmnxBBOLsEO8VayIv46c3GXtspU=; b=TVLS552ZNCfIXj7ArnLPTouLpJXk+RMdHjVX/SwRKDnW053Kp1FPRNDhns39NhRwFZ wMRtamgZQhUTPz2aoj5Zo0dK25avFeA76QoUfYOluf1JmyWtLJSmldBcTCR9uoAyXxgG RmMOLxHamyBfXZfN0o/sGxpr6x0nJ8qvAq09Bct/KrcH75W68n6NP3d8+VzCwMjZAYne V+fdU9XBGJLgo7HTDLV8RokKpSMBoTBB5jvfyi8B8gAJGvIkQxQscMDzRpokrnlhpkA+ FtbRDIEqkYiz3gFbqn/mRun/l/r37BUhjvUAHdeP4gc+uTd+eeD/GzEw0Em66HSm3EZl fZ8Q== X-Gm-Message-State: AJIora+hSpww8Uy24E4oMCPPAlLiAKbgvn7uwLLeJEooCdPO0afX/fA8 Dg5s7Z7F+Vw3iEnGymTJEL8c42W37dL+JrxHwkwuVmq9 X-Google-Smtp-Source: AGRyM1uZez/Ro6M87X02uRljTD3lDNYsK4C4tgcIeZCAf/qEQjpkor/5j5Qp94f/DbLat3o9IqRO4+wEOxfeZ2OqWj0= X-Received: by 2002:a05:6512:e99:b0:479:a04:a12e with SMTP id bi25-20020a0565120e9900b004790a04a12emr754963lfb.500.1655146522561; Mon, 13 Jun 2022 11:55:22 -0700 (PDT) MIME-Version: 1.0 References: <20220613162626.11541-1-nil-admirari@mailo.com> <20220613162626.11541-4-nil-admirari@mailo.com> In-Reply-To: From: Hendrik Leppkes Date: Mon, 13 Jun 2022 20:55:10 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH v14 4/5] libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv() 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Mon, Jun 13, 2022 at 7:47 PM Soft Works wrote: > > > > > -----Original Message----- > > From: ffmpeg-devel On Behalf Of Nil > > Admirari > > Sent: Monday, June 13, 2022 6:26 PM > > To: ffmpeg-devel@ffmpeg.org > > Subject: [FFmpeg-devel] [PATCH v14 4/5] libavformat: Remove MAX_PATH > > limit and use UTF-8 version of getenv() > > > > 1. getenv() is replaced with getenv_utf8() across libavformat. > > 2. New versions of AviSynth+ are now called with UTF-8 filenames. > > 3. Old versions of AviSynth are still using ANSI strings, > > but MAX_PATH limit on filename is removed. > > --- > > libavformat/avisynth.c | 39 +++++++++++++++++++++++++++---------- > > -- > > libavformat/http.c | 20 +++++++++++++------- > > libavformat/ipfsgateway.c | 35 +++++++++++++++++++++++------------ > > libavformat/tls.c | 11 +++++++++-- > > 4 files changed, 72 insertions(+), 33 deletions(-) > > > > diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c > > index 8ba2bdead2..a97d12b6b6 100644 > > --- a/libavformat/avisynth.c > > +++ b/libavformat/avisynth.c > > @@ -34,6 +34,7 @@ > > /* Platform-specific directives. */ > > #ifdef _WIN32 > > #include "compat/w32dlfcn.h" > > + #include "libavutil/wchar_filename.h" > > #undef EXTERN_C > > #define AVISYNTH_LIB "avisynth" > > #else > > @@ -56,6 +57,7 @@ typedef struct AviSynthLibrary { > > #define AVSC_DECLARE_FUNC(name) name ## _func name > > AVSC_DECLARE_FUNC(avs_bit_blt); > > AVSC_DECLARE_FUNC(avs_clip_get_error); > > + AVSC_DECLARE_FUNC(avs_check_version); > > AVSC_DECLARE_FUNC(avs_create_script_environment); > > AVSC_DECLARE_FUNC(avs_delete_script_environment); > > AVSC_DECLARE_FUNC(avs_get_audio); > > @@ -137,6 +139,7 @@ static av_cold int avisynth_load_library(void) > > > > LOAD_AVS_FUNC(avs_bit_blt, 0); > > LOAD_AVS_FUNC(avs_clip_get_error, 0); > > + LOAD_AVS_FUNC(avs_check_version, 0); > > LOAD_AVS_FUNC(avs_create_script_environment, 0); > > LOAD_AVS_FUNC(avs_delete_script_environment, 0); > > LOAD_AVS_FUNC(avs_get_audio, 0); > > @@ -807,26 +810,38 @@ static int > > avisynth_create_stream(AVFormatContext *s) > > static int avisynth_open_file(AVFormatContext *s) > > { > > AviSynthContext *avs = s->priv_data; > > - AVS_Value arg, val; > > + AVS_Value val; > > int ret; > > -#ifdef _WIN32 > > - char filename_ansi[MAX_PATH * 4]; > > - wchar_t filename_wc[MAX_PATH * 4]; > > -#endif > > > > if (ret = avisynth_context_create(s)) > > return ret; > > > > + if (!avs_library.avs_check_version(avs->env, 7)) { > > I like the version check. I don't know about all the derivatives > of AviSynth, but I assume you have checked that it's valid for > the common ones (or at least the original non-Plus variant)? > > > + AVS_Value args[] = { > > + avs_new_value_string(s->url), > > + avs_new_value_bool(1) // filename is in UTF-8 > > + }; > > + val = avs_library.avs_invoke(avs->env, "Import", > > + avs_new_value_array(args, 2), > > 0); > > + } else { > > + AVS_Value arg; > > #ifdef _WIN32 > > - /* Convert UTF-8 to ANSI code page */ > > - MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, > > MAX_PATH * 4); > > - WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, > > filename_ansi, > > - MAX_PATH * 4, NULL, NULL); > > - arg = avs_new_value_string(filename_ansi); > > + char *filename_ansi; > > + /* Convert UTF-8 to ANSI code page */ > > + if (utf8toansi(s->url, &filename_ansi)) { > > Two ideas came to my mind how this could be done better. > What's actually needed here is not a string conversion, we need > a valid and usable filename, and the function could be more > something like "get_ansi_filename()". > > The first thing that this function could do is to convert the > the filename to ANSI and right back to UTF-8, then compare the > UTF-8 result with the original UTF-8 string. When both are equal, > we know that the conversion is safe, otherwise we know that it > won't work. > > Then, we can use the win32 API GetShortFileName(). Which returns > file and directory names in 8.3 notation which (IIRC) contains > only letters which are valid in the ANSI code page. > This seems unrelated to this patch, which is about removing the MAX_PATH limit. The code previously converted UTF-8 to ANSI, and still does so now, just without the MAX_PATH limit. Further improvements tangential to this topic can, and should, be applied independently, and not hold up this patch in discussion-hell for longer than necessary. - Hendrik _______________________________________________ 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".