Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/86466/?format=api
https://patches.dpdk.org/api/patches/86466/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210113134422.15723-9-xuemingl@nvidia.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20210113134422.15723-9-xuemingl@nvidia.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20210113134422.15723-9-xuemingl@nvidia.com", "date": "2021-01-13T13:44:21", "name": "[v3,8/9] kvargs: update parser for new representor syntax", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "dc286b9ed7fd0ae8214cb91843fa2196720aaf10", "submitter": { "id": 1904, "url": "https://patches.dpdk.org/api/people/1904/?format=api", "name": "Xueming Li", "email": "xuemingl@nvidia.com" }, "delegate": { "id": 1, "url": "https://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210113134422.15723-9-xuemingl@nvidia.com/mbox/", "series": [ { "id": 14697, "url": "https://patches.dpdk.org/api/series/14697/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=14697", "date": "2021-01-13T13:44:21", "name": null, "version": 3, "mbox": "https://patches.dpdk.org/series/14697/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/86466/comments/", "check": "success", "checks": "https://patches.dpdk.org/api/patches/86466/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id C8351A04B5;\n\tWed, 13 Jan 2021 14:45:52 +0100 (CET)", "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 37F9A140D63;\n\tWed, 13 Jan 2021 14:45:18 +0100 (CET)", "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n by mails.dpdk.org (Postfix) with ESMTP id 57C47140D64\n for <dev@dpdk.org>; Wed, 13 Jan 2021 14:45:15 +0100 (CET)", "from Internal Mail-Server by MTLPINE1 (envelope-from\n xuemingl@nvidia.com) with SMTP; 13 Jan 2021 15:45:12 +0200", "from nvidia.com ([172.27.8.145])\n by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10DDinBE024044;\n Wed, 13 Jan 2021 15:45:10 +0200" ], "From": "Xueming Li <xuemingl@nvidia.com>", "To": "Thomas Monjalon <thomas@monjalon.net>,\n Ferruh Yigit <ferruh.yigit@intel.com>,\n Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,\n Olivier Matz <olivier.matz@6wind.com>", "Cc": "dev@dpdk.org, Viacheslav Ovsiienko <viacheslavo@nvidia.com>,\n xuemingl@nvidia.com, Asaf Penso <asafp@nvidia.com>", "Date": "Wed, 13 Jan 2021 21:44:21 +0800", "Message-Id": "<20210113134422.15723-9-xuemingl@nvidia.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<1608303356-13089-2-git-send-email-xuemingl@nvidia.com>", "References": "<1608303356-13089-2-git-send-email-xuemingl@nvidia.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[dpdk-dev] [PATCH v3 8/9] kvargs: update parser for new representor\n syntax", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "This patch updates kvargs parser to allow comma in list value:\n k1=a[1,2]b[3-5]\n\nSigned-off-by: Xueming Li <xuemingl@nvidia.com>\n---\n app/test/test_kvargs.c | 51 +++++++++++++++--\n lib/librte_kvargs/rte_kvargs.c | 101 +++++++++++++++++++++++----------\n 2 files changed, 117 insertions(+), 35 deletions(-)", "diff": "diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c\nindex 2a2dae43a0..b42cdcb9f5 100644\n--- a/app/test/test_kvargs.c\n+++ b/app/test/test_kvargs.c\n@@ -35,6 +35,25 @@ static int check_handler(const char *key, const char *value,\n \treturn 0;\n }\n \n+/* test parsing. */\n+static int test_kvargs_parsing(const char *args, unsigned int n)\n+{\n+\tstruct rte_kvargs *kvlist;\n+\n+\tkvlist = rte_kvargs_parse(args, NULL);\n+\tif (kvlist == NULL) {\n+\t\tprintf(\"rte_kvargs_parse() error: %s\\n\", args);\n+\t\treturn -1;\n+\t}\n+\tif (kvlist->count != n) {\n+\t\tprintf(\"invalid count value %d: %s\\n\", kvlist->count, args);\n+\t\trte_kvargs_free(kvlist);\n+\t\treturn -1;\n+\t}\n+\trte_kvargs_free(kvlist);\n+\treturn 0;\n+}\n+\n /* test a valid case */\n static int test_valid_kvargs(void)\n {\n@@ -191,6 +210,32 @@ static int test_valid_kvargs(void)\n \t}\n \trte_kvargs_free(kvlist);\n \n+\tvalid_keys = NULL;\n+\n+\targs = \"foo=1,foo=\";\n+\tif (test_kvargs_parsing(args, 2))\n+\t\tgoto fail;\n+\n+\targs = \"foo=1,foo\";\n+\tif (test_kvargs_parsing(args, 2))\n+\t\tgoto fail;\n+\n+\targs = \"foo=1,=2\";\n+\tif (test_kvargs_parsing(args, 2))\n+\t\tgoto fail;\n+\n+\targs = \"foo=[1,2\";\n+\tif (test_kvargs_parsing(args, 1))\n+\t\tgoto fail;\n+\n+\targs = \",=\";\n+\tif (test_kvargs_parsing(args, 1))\n+\t\tgoto fail;\n+\n+\targs = \"foo=[\";\n+\tif (test_kvargs_parsing(args, 1))\n+\t\tgoto fail;\n+\n \treturn 0;\n \n fail:\n@@ -212,12 +257,6 @@ static int test_invalid_kvargs(void)\n \t/* list of argument that should fail */\n \tconst char *args_list[] = {\n \t\t\"wrong-key=x\", /* key not in valid_keys_list */\n-\t\t\"foo=1,foo=\", /* empty value */\n-\t\t\"foo=1,foo\", /* no value */\n-\t\t\"foo=1,=2\", /* no key */\n-\t\t\"foo=[1,2\", /* no closing bracket in value */\n-\t\t\",=\", /* also test with a smiley */\n-\t\t\"foo=[\", /* no value in list and no closing bracket */\n \t\tNULL };\n \tconst char **args;\n \tconst char *valid_keys_list[] = { \"foo\", \"check\", NULL };\ndiff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c\nindex 285081c86c..ffae8914cf 100644\n--- a/lib/librte_kvargs/rte_kvargs.c\n+++ b/lib/librte_kvargs/rte_kvargs.c\n@@ -5,6 +5,7 @@\n \n #include <string.h>\n #include <stdlib.h>\n+#include <stdbool.h>\n \n #include <rte_string_fns.h>\n \n@@ -13,15 +14,19 @@\n /*\n * Receive a string with a list of arguments following the pattern\n * key=value,key=value,... and insert them into the list.\n- * strtok() is used so the params string will be copied to be modified.\n+ * Params string will be copied to be modified.\n+ * list \"[]\" and list element splitter \",\", \"-\" is treated as value.\n+ * Supported examples:\n+ * k1=v1,k2=v2\n+ * k1\n+ * k1=x[0-1]y[1,3-5,9]z\n */\n static int\n rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)\n {\n-\tunsigned i;\n-\tchar *str;\n-\tchar *ctx1 = NULL;\n-\tchar *ctx2 = NULL;\n+\tchar *str, *start;\n+\tbool in_list = false, end_key = false, end_value = false;\n+\tbool save = false, end_pair = false;\n \n \t/* Copy the const char *params to a modifiable string\n \t * to pass to rte_strsplit\n@@ -32,36 +37,74 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)\n \n \t/* browse each key/value pair and add it in kvlist */\n \tstr = kvlist->str;\n-\twhile ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {\n+\tstart = str; /* start of current key or value */\n+\twhile (1) {\n+\t\tswitch (*str) {\n+\t\tcase '=': /* End of key. */\n+\t\t\tend_key = true;\n+\t\t\tsave = true;\n+\t\t\tbreak;\n+\t\tcase ',':\n+\t\t\t/* End of value, skip comma in middle of range */\n+\t\t\tif (!in_list) {\n+\t\t\t\tif (end_key)\n+\t\t\t\t\tend_value = true;\n+\t\t\t\telse\n+\t\t\t\t\tend_key = true;\n+\t\t\t\tsave = true;\n+\t\t\t\tend_pair = true;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tcase '[': /* Start of list. */\n+\t\t\tin_list = true;\n+\t\t\tbreak;\n+\t\tcase ']': /* End of list. */\n+\t\t\tif (in_list)\n+\t\t\t\tin_list = false;\n+\t\t\tbreak;\n+\t\tcase '\\0': /* End of string */\n+\t\t\tif (end_key)\n+\t\t\t\tend_value = true;\n+\t\t\telse\n+\t\t\t\tend_key = true;\n+\t\t\tsave = true;\n+\t\t\tend_pair = true;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n \n-\t\ti = kvlist->count;\n-\t\tif (i >= RTE_KVARGS_MAX)\n-\t\t\treturn -1;\n+\t\tif (!save) {\n+\t\t\t/* Continue if not end of key or value. */\n+\t\t\tstr++;\n+\t\t\tcontinue;\n+\t\t}\n \n-\t\tkvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);\n-\t\tkvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);\n-\t\tif (kvlist->pairs[i].key == NULL ||\n-\t\t kvlist->pairs[i].value == NULL)\n+\t\tif (kvlist->count >= RTE_KVARGS_MAX)\n \t\t\treturn -1;\n \n-\t\t/* Detect list [a,b] to skip comma delimiter in list. */\n-\t\tstr = kvlist->pairs[i].value;\n-\t\tif (str[0] == '[') {\n-\t\t\t/* Find the end of the list. */\n-\t\t\twhile (str[strlen(str) - 1] != ']') {\n-\t\t\t\t/* Restore the comma erased by strtok_r(). */\n-\t\t\t\tif (ctx1 == NULL || ctx1[0] == '\\0')\n-\t\t\t\t\treturn -1; /* no closing bracket */\n-\t\t\t\tstr[strlen(str)] = ',';\n-\t\t\t\t/* Parse until next comma. */\n-\t\t\t\tstr = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);\n-\t\t\t\tif (str == NULL)\n-\t\t\t\t\treturn -1; /* no closing bracket */\n-\t\t\t}\n+\t\tif (end_value)\n+\t\t\t/* Value parsed */\n+\t\t\tkvlist->pairs[kvlist->count].value = start;\n+\t\telse if (end_key)\n+\t\t\t/* Key parsed. */\n+\t\t\tkvlist->pairs[kvlist->count].key = start;\n+\n+\t\tif (end_pair) {\n+\t\t\tif (end_value || str != start)\n+\t\t\t\t/* Ignore empty pair. */\n+\t\t\t\tkvlist->count++;\n+\t\t\tend_key = false;\n+\t\t\tend_value = false;\n+\t\t\tend_pair = false;\n \t\t}\n \n-\t\tkvlist->count++;\n-\t\tstr = NULL;\n+\t\tif (*str == '\\0') /* End of string. */\n+\t\t\tbreak;\n+\t\t*str = '\\0';\n+\t\tstr++;\n+\t\tstart = str;\n+\t\tsave = false;\n \t}\n \n \treturn 0;\n", "prefixes": [ "v3", "8/9" ] }{ "id": 86466, "url": "