From patchwork Mon Oct 24 10:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 8299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp357962wru; Mon, 24 Oct 2022 03:07:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qV7yJGB5W+DACgAkYyuzafOI4sxUC12gWEQsxtlJobhLbSiuXw9s/84jozLhPHh2Wfunm X-Received: by 2002:a17:902:7897:b0:178:9292:57b9 with SMTP id q23-20020a170902789700b00178929257b9mr33391883pll.102.1666606048277; Mon, 24 Oct 2022 03:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666606048; cv=none; d=google.com; s=arc-20160816; b=Oj2ClboFlF9cridhBpu9bhP725268/ZO4NwBOM0/ETe6mCDFUtTWzdD/EibBBViLV3 WYxe+JL4stocYwcwjvqil4PcyezAJM2V4kESd4JlhEiuoFB9NjVGw416aDX9hTK4v1Vg IbpxsQz4F2e81hwZjdIUXuMtGOCYxoOJS/X0Y+t6LL71D6DpITMB8Aa69LLnE4PxsNku NYyemU+AfcYG/7ASSeoc4zcFnApIBmOM0nvXc1XOrGM1U/Rl36kdRBbmNdEcXU0j9VhE ekAhM4V7UlDh7hBvjW7Huq/m/3Z1udGsob2j+uBxzcUvxepTzlK88pGu5LiqlIinhbZr kh4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=UwH2GbVflkhZx795XAOstJRk5yzctJzdhpA5PUGt2PQ=; b=Aq+cd/uRNOxJiFBBh+ppWUm0e6ab3PqWl4j+NpDtDXvX0qIjY/PjUw/dcWYACMTAfA scgC4EUNPZJXYbyqcirbILX9XpCrMH0LCrpgr2pUQGG4IK0QIbXUlOXXT0jp6j4g1s5o ix0qnaJlXLQv6r/BwZLxQMGd1ljaay+Zr67dE3vG+lfQTOjHRkK6v9ufeP42S7uqaL/2 UXtvVaeDZFbefcOwpILOrBEWeu7MOQgiq98KiU+ZETBtktd/REEM9rBqmpm07oFVKoCf dLGj3dxSWQK9sUMaojC38vUpz1HSPrartxeMXuBB4/plW/k97LhAuW7p0dxM/XvxzWPC 5aog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx5-20020a17090b4b0500b00212e4f65e71si8835593pjb.31.2022.10.24.03.07.15; Mon, 24 Oct 2022 03:07:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbiJXKDW (ORCPT + 99 others); Mon, 24 Oct 2022 06:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbiJXKDA (ORCPT ); Mon, 24 Oct 2022 06:03:00 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F24F57266; Mon, 24 Oct 2022 03:02:52 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 8E59A1E80D74; Mon, 24 Oct 2022 18:01:34 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U1Q5bK8zPeXr; Mon, 24 Oct 2022 18:01:31 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id CD0E91E80CA5; Mon, 24 Oct 2022 18:01:31 +0800 (CST) From: Li kunyu To: krisman@collabora.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] unicode: mkutf8data: Add unicode_data_remalloc function Date: Mon, 24 Oct 2022 18:02:46 +0800 Message-Id: <20221024100246.180280-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747563103760919874?= X-GMAIL-MSGID: =?utf-8?q?1747563103760919874?= Add unicode_data_remalloc function, used to simplify unicode_data member assignment use. Signed-off-by: Li kunyu --- fs/unicode/mkutf8data.c | 58 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c index bc1a7c8b5c8d..366de944fed3 100644 --- a/fs/unicode/mkutf8data.c +++ b/fs/unicode/mkutf8data.c @@ -2230,13 +2230,25 @@ static void nfdicf_init(void) file_fail(fold_name); } +static void unicode_data_remalloc(void **dst, size_t len, int free) +{ + unsigned int *um = malloc(len); + + if (free == 1) + free(*dst); + + if (um) + *um = 0 + + *dst = um; +} + static void ignore_init(void) { FILE *file; unsigned int unichar; unsigned int first; unsigned int last; - unsigned int *um; int count; int ret; @@ -2255,14 +2267,10 @@ static void ignore_init(void) if (!utf32valid(first) || !utf32valid(last)) line_fail(prop_name, line); for (unichar = first; unichar <= last; unichar++) { - free(unicode_data[unichar].utf32nfdi); - um = malloc(sizeof(unsigned int)); - *um = 0; - unicode_data[unichar].utf32nfdi = um; - free(unicode_data[unichar].utf32nfdicf); - um = malloc(sizeof(unsigned int)); - *um = 0; - unicode_data[unichar].utf32nfdicf = um; + unicode_data_remalloc(&unicode_data[unichar].utf32nfdi, + sizeof(unsigned int), 1); + unicode_data_remalloc(&unicode_data[unichar].utf32nfdicf, + sizeof(unsigned int), 1); count++; } if (verbose > 1) @@ -2276,14 +2284,11 @@ static void ignore_init(void) continue; if (!utf32valid(unichar)) line_fail(prop_name, line); - free(unicode_data[unichar].utf32nfdi); - um = malloc(sizeof(unsigned int)); - *um = 0; - unicode_data[unichar].utf32nfdi = um; - free(unicode_data[unichar].utf32nfdicf); - um = malloc(sizeof(unsigned int)); - *um = 0; - unicode_data[unichar].utf32nfdicf = um; + + unicode_data_remalloc(&unicode_data[unichar].utf32nfdi, + sizeof(unsigned int), 1); + unicode_data_remalloc(&unicode_data[unichar].utf32nfdicf, + sizeof(unsigned int), 1); if (verbose > 1) printf(" %X Default_Ignorable_Code_Point\n", unichar); @@ -2490,7 +2495,6 @@ static void nfdi_decompose(void) { unsigned int unichar; unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */ - unsigned int *um; unsigned int *dc; int count; int i; @@ -2522,16 +2526,13 @@ static void nfdi_decompose(void) mapping[i++] = 0; if (ret) break; - free(unicode_data[unichar].utf32nfdi); - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdi = um; + unicode_data_remalloc(&unicode_data[unichar].utf32nfdi, + i * sizeof(unsigned int), 1); } /* Add this decomposition to nfdicf if there is no entry. */ if (!unicode_data[unichar].utf32nfdicf) { - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdicf = um; + unicode_data_remalloc(&unicode_data[unichar].utf32nfdicf, + i * sizeof(unsigned int), 0); } if (verbose > 1) print_utf32nfdi(unichar); @@ -2545,7 +2546,6 @@ static void nfdicf_decompose(void) { unsigned int unichar; unsigned int mapping[19]; /* Magic - guaranteed not to be exceeded. */ - unsigned int *um; unsigned int *dc; int count; int i; @@ -2576,10 +2576,8 @@ static void nfdicf_decompose(void) mapping[i++] = 0; if (ret) break; - free(unicode_data[unichar].utf32nfdicf); - um = malloc(i * sizeof(unsigned int)); - memcpy(um, mapping, i * sizeof(unsigned int)); - unicode_data[unichar].utf32nfdicf = um; + unicode_data_remalloc(&unicode_data[unichar].utf32nfdicf, + i * sizeof(unsigned int), 1); } if (verbose > 1) print_utf32nfdicf(unichar);