From patchwork Mon Jul 1 11:02:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grigorii Nazarov X-Patchwork-Id: 1954598 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ROJeQikE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCNSr68Jcz1xpT for ; Mon, 1 Jul 2024 21:03:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2667E40A10; Mon, 1 Jul 2024 11:03:34 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id kmDGpyaKWWVR; Mon, 1 Jul 2024 11:03:32 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 6E60240ADD Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ROJeQikE Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 6E60240ADD; Mon, 1 Jul 2024 11:03:32 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 185FDC0033; Mon, 1 Jul 2024 11:03:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7B992C002A for ; Mon, 1 Jul 2024 11:03:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 72C57608F6 for ; Mon, 1 Jul 2024 11:03:31 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id zHFUSpGuiopr for ; Mon, 1 Jul 2024 11:03:30 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::1035; helo=mail-pj1-x1035.google.com; envelope-from=whitecrowbar@gmail.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org B3910608DC Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B3910608DC Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ROJeQikE Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by smtp3.osuosl.org (Postfix) with ESMTPS id B3910608DC for ; Mon, 1 Jul 2024 11:03:30 +0000 (UTC) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2c9357a2647so1229753a91.0 for ; Mon, 01 Jul 2024 04:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719831809; x=1720436609; darn=openvswitch.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M+GJDn6V7Iq9GELfJdPAmAZr0QDz7lPXBgYwfHb4U2M=; b=ROJeQikEhtuN+6eNugry3gdfWx544Ed3+KGJWpMPvMfqkL15L+QWtDM4/JVagvjhxj QI5+ufytgo+BfRmCRadU4JZ8m85lYPMIVSxxx78fsNx8ByQwJpxiO8Oa9k8u0rV8Dpmz vzxUBt2lJsOYJjsvfy3IHd0n0lnfax0nXBOs7CQNFA6J0fdvNetjBrQXua6bk5FM7hmn Fy3r3/qOhgZtvmsfxAqaK75gwVigPBPfoQl2WNm3P4mXhq7rbi0JoWtv9wzcYZQNiNLa ktIQ7mpSa4tRJNkWuqIxQEVN1j0toZYRY+vcw+C88hPNb6PbH3tNWCR64jIgecOmEphH SDJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719831809; x=1720436609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M+GJDn6V7Iq9GELfJdPAmAZr0QDz7lPXBgYwfHb4U2M=; b=DoBqs8x0V4/Bp3lWA+Q9Qk9STUJbmftzqm9P1VhWL7ZciQ5LHThILh78YL0DSrYXPR 0vdl5/mW+JfoJ+nw9Xwoq0TyHRnPhzpdDorRT0LG8R6NTa1XN6Vlc7nmdozeraBK5HAz oug5JmIVnX8zWor2kGVVXdoXgTjXlHPW7eythwrJ3g3tjQJmxjs6par4nZ67cnT8XPC+ MhqrtfpGtvif3NCOC1miYgzNfsJ1XZ9UuhhTVNDOvxr3X5ukcIXqv7k3o8UxP4ag38/n 19GbsZDIb7sECEYqMzkosBUzQAuxwO94Qy6Pu0RVKQe2SbbuQYkEOBIxHcWr160AU4jk EavA== X-Gm-Message-State: AOJu0YzdHVAC0w4PjZUquNcupuFbzoFx3tRemKrjiXQ+NExkzjzn7OBj mVumvO87yxIV8C4uSQuPSTiqRklV8z0aRPnXpkPKBKe5nilbXtHjzsKgMw== X-Google-Smtp-Source: AGHT+IE1/mducTx2YI3x9NWW2eyXoN203nVp9swLm8Y9v/qUGdqPqPccAG1PvAOfgtQ0ONjB8EDDEQ== X-Received: by 2002:a17:90a:e592:b0:2c8:6eea:7ad8 with SMTP id 98e67ed59e1d1-2c93d727a93mr2554029a91.26.1719831809319; Mon, 01 Jul 2024 04:03:29 -0700 (PDT) Received: from localhost.localdomain ([2800:a4:c085:3c00:fc5d:c1e4:e9f9:4262]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c91ce433cbsm6567603a91.18.2024.07.01.04.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 04:03:28 -0700 (PDT) From: Grigorii Nazarov To: dev@openvswitch.org Date: Mon, 1 Jul 2024 14:02:47 +0300 Message-ID: <20240701110257.1052377-3-whitecrowbar@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240701110257.1052377-1-whitecrowbar@gmail.com> References: <20240620085906.153885-1-whitecrowbar@gmail.com> <20240701110257.1052377-1-whitecrowbar@gmail.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 2/3] lib/json: Simplify string serialization code. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Grigorii Nazarov Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Grigorii Nazarov Acked-by: Eelco Chaudron --- There's an open question on whether this function should exist, or being placed in header etc. However, no decision was made yet. v2: fixed title v4: changed patch number from 3/4 to 2/3 lib/json.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/json.c b/lib/json.c index 001f6e6ab..d40e93857 100644 --- a/lib/json.c +++ b/lib/json.c @@ -127,7 +127,9 @@ static void json_parser_input(struct json_parser *, struct json_token *); static void json_error(struct json_parser *p, const char *format, ...) OVS_PRINTF_FORMAT(2, 3); - + +static void json_serialize_string(const char *, struct ds *); + const char * json_type_to_string(enum json_type type) { @@ -987,11 +989,7 @@ exit: void json_string_escape(const char *in, struct ds *out) { - struct json json = { - .type = JSON_STRING, - .string = CONST_CAST(char *, in), - }; - json_to_ds(&json, 0, out); + json_serialize_string(in, out); } static void @@ -1572,7 +1570,6 @@ static void json_serialize_object(const struct shash *object, struct json_serializer *); static void json_serialize_array(const struct json_array *, struct json_serializer *); -static void json_serialize_string(const char *, struct ds *); /* Converts 'json' to a string in JSON format, encoded in UTF-8, and returns * that string. The caller is responsible for freeing the returned string,