From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH v5 21/24] libxlu: nested list support Date: Thu, 12 Feb 2015 19:44:51 +0000 Message-ID: <1423770294-9779-22-git-send-email-wei.liu2@citrix.com> References: <1423770294-9779-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1423770294-9779-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Wei Liu , ian.campbell@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, JBeulich@suse.com, ufimtseva@gmail.com List-Id: xen-devel@lists.xenproject.org 1. Extend grammar of parser. 2. Adjust internal functions to accept XLU_ConfigValue instead of char *. Signed-off-by: Wei Liu Cc: Ian Jackson Cc: Ian Campbell Acked-by: Ian Jackson --- tools/libxl/libxlu_cfg.c | 30 +++++++----------------------- tools/libxl/libxlu_cfg_i.h | 5 +++-- tools/libxl/libxlu_cfg_y.c | 26 +++++++++++++------------- tools/libxl/libxlu_cfg_y.y | 4 ++-- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/tools/libxl/libxlu_cfg.c b/tools/libxl/libxlu_cfg.c index f000eed..611f5ec 100644 --- a/tools/libxl/libxlu_cfg.c +++ b/tools/libxl/libxlu_cfg.c @@ -332,19 +332,14 @@ XLU_ConfigValue *xlu__cfg_string_mk(CfgParseContext *ctx, char *atom) return NULL; } -XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom) +XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, + XLU_ConfigValue *val) { XLU_ConfigValue *value = NULL; XLU_ConfigValue **values = NULL; - XLU_ConfigValue *val = NULL; if (ctx->err) goto x; - val = malloc(sizeof(*val)); - if (!val) goto xe; - val->type = XLU_STRING; - val->u.string = atom; - values = malloc(sizeof(*values)); if (!values) goto xe; values[0] = val; @@ -363,19 +358,17 @@ XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom) x: free(value); free(values); - free(val); - free(atom); + xlu__cfg_value_free(val); return NULL; } void xlu__cfg_list_append(CfgParseContext *ctx, XLU_ConfigValue *list, - char *atom) + XLU_ConfigValue *val) { - XLU_ConfigValue *val = NULL; if (ctx->err) return; - assert(atom); + assert(val); assert(list->type == XLU_LIST); if (list->u.list.nvalues >= list->u.list.avalues) { @@ -384,7 +377,7 @@ void xlu__cfg_list_append(CfgParseContext *ctx, if (list->u.list.avalues > INT_MAX / 100) { ctx->err = ERANGE; - free(atom); + xlu__cfg_value_free(val); return; } @@ -393,7 +386,7 @@ void xlu__cfg_list_append(CfgParseContext *ctx, sizeof(*new_values) * new_avalues); if (!new_values) { ctx->err = errno; - free(atom); + xlu__cfg_value_free(val); return; } @@ -401,15 +394,6 @@ void xlu__cfg_list_append(CfgParseContext *ctx, list->u.list.values = new_values; } - val = malloc(sizeof(*val)); - if (!val) { - ctx->err = errno; - free(atom); - return; - } - - val->type = XLU_STRING; - val->u.string = atom; list->u.list.values[list->u.list.nvalues] = val; list->u.list.nvalues++; } diff --git a/tools/libxl/libxlu_cfg_i.h b/tools/libxl/libxlu_cfg_i.h index b71e9fd..11dc33f 100644 --- a/tools/libxl/libxlu_cfg_i.h +++ b/tools/libxl/libxlu_cfg_i.h @@ -27,10 +27,11 @@ void xlu__cfg_set_store(CfgParseContext*, char *name, XLU_ConfigValue *val, int lineno); XLU_ConfigValue *xlu__cfg_string_mk(CfgParseContext *ctx, char *atom); -XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, char *atom); +XLU_ConfigValue *xlu__cfg_list_mk(CfgParseContext *ctx, + XLU_ConfigValue *val); void xlu__cfg_list_append(CfgParseContext *ctx, XLU_ConfigValue *list, - char *atom); + XLU_ConfigValue *val); void xlu__cfg_value_free(XLU_ConfigValue *value); char *xlu__cfgl_strdup(CfgParseContext*, const char *src); char *xlu__cfgl_dequote(CfgParseContext*, const char *src); diff --git a/tools/libxl/libxlu_cfg_y.c b/tools/libxl/libxlu_cfg_y.c index eb3884f..b05e48b 100644 --- a/tools/libxl/libxlu_cfg_y.c +++ b/tools/libxl/libxlu_cfg_y.c @@ -377,7 +377,7 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 3 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 24 +#define YYLAST 25 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 12 @@ -444,8 +444,8 @@ static const yytype_int8 yyrhs[] = 15, -1, 16, 17, -1, 17, -1, 1, 6, -1, 3, 7, 18, -1, 6, -1, 8, -1, 19, -1, 9, 22, 20, 10, -1, 4, -1, 5, -1, -1, - 21, -1, 21, 11, 22, -1, 19, 22, -1, 21, - 11, 22, 19, 22, -1, -1, 22, 6, -1 + 21, -1, 21, 11, 22, -1, 18, 22, -1, 21, + 11, 22, 18, 22, -1, -1, 22, 6, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ @@ -517,14 +517,14 @@ static const yytype_int8 yydefgoto[] = static const yytype_int8 yypact[] = { -18, 4, 0, -18, -1, 6, -18, -18, -18, 3, - -18, -18, 11, -18, -18, -18, -18, -18, -18, 13, - -18, -18, 12, 10, 17, -18, -18, 13, -18, 17 + -18, -18, 14, -18, -18, -18, -18, -18, -18, 11, + -18, -18, 12, 10, 18, -18, -18, 11, -18, 18 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -18, -18, -18, -18, -18, 15, -18, -17, -18, -18, + -18, -18, -18, -18, -18, 16, -17, -18, -18, -18, -14 }; @@ -535,8 +535,8 @@ static const yytype_int8 yypgoto[] = static const yytype_int8 yytable[] = { -2, 4, 21, 5, 3, 11, 6, 24, 7, 6, - 28, 7, 27, 12, 29, 14, 15, 14, 15, 20, - 16, 26, 25, 20, 13 + 28, 7, 27, 12, 29, 14, 15, 20, 14, 15, + 16, 26, 25, 16, 20, 13 }; #define yypact_value_is_default(yystate) \ @@ -548,8 +548,8 @@ static const yytype_int8 yytable[] = static const yytype_uint8 yycheck[] = { 0, 1, 19, 3, 0, 6, 6, 21, 8, 6, - 27, 8, 26, 7, 28, 4, 5, 4, 5, 6, - 9, 11, 10, 6, 9 + 27, 8, 26, 7, 28, 4, 5, 6, 4, 5, + 9, 11, 10, 9, 6, 9 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -558,7 +558,7 @@ static const yytype_uint8 yystos[] = { 0, 13, 14, 0, 1, 3, 6, 8, 15, 16, 17, 6, 7, 17, 4, 5, 9, 18, 19, 22, - 6, 19, 20, 21, 22, 10, 11, 22, 19, 22 + 6, 18, 20, 21, 22, 10, 11, 22, 18, 22 }; #define yyerrok (yyerrstatus = 0) @@ -1564,14 +1564,14 @@ yyreduce: /* Line 1806 of yacc.c */ #line 72 "libxlu_cfg_y.y" - { (yyval.value)= xlu__cfg_list_mk(ctx,(yyvsp[(1) - (2)].string)); } + { (yyval.value)= xlu__cfg_list_mk(ctx,(yyvsp[(1) - (2)].value)); } break; case 20: /* Line 1806 of yacc.c */ #line 73 "libxlu_cfg_y.y" - { xlu__cfg_list_append(ctx,(yyvsp[(1) - (5)].value),(yyvsp[(4) - (5)].string)); (yyval.value)= (yyvsp[(1) - (5)].value); } + { xlu__cfg_list_append(ctx,(yyvsp[(1) - (5)].value),(yyvsp[(4) - (5)].value)); (yyval.value)= (yyvsp[(1) - (5)].value); } break; diff --git a/tools/libxl/libxlu_cfg_y.y b/tools/libxl/libxlu_cfg_y.y index 6848686..4a5ca3a 100644 --- a/tools/libxl/libxlu_cfg_y.y +++ b/tools/libxl/libxlu_cfg_y.y @@ -69,8 +69,8 @@ valuelist: /* empty */ { $$= xlu__cfg_list_mk(ctx,NULL); } | values { $$= $1; } | values ',' nlok { $$= $1; } -values: atom nlok { $$= xlu__cfg_list_mk(ctx,$1); } - | values ',' nlok atom nlok { xlu__cfg_list_append(ctx,$1,$4); $$= $1; } +values: value nlok { $$= xlu__cfg_list_mk(ctx,$1); } + | values ',' nlok value nlok { xlu__cfg_list_append(ctx,$1,$4); $$= $1; } nlok: /* nothing */ -- 1.9.1