From: Emden Gansner Date: Thu, 2 Aug 2012 18:28:22 +0000 (-0400) Subject: Make sure all Agsym_t values are copied when cloning a dictionary; X-Git-Tag: LAST_LIBGRAPH~32^2~360 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=555353e189974ad2c0d919613f4f9175260c5d74;p=graphviz Make sure all Agsym_t values are copied when cloning a dictionary; fix use of fixed Agsym_t field. The current implementation was using fixed for individual object attribute assignment, which is wrong. Individual assignment should always dominate. The code now correctly fixes an attribute value only for default or graph values, and only in the root graph. --- diff --git a/lib/cgraph/attr.c b/lib/cgraph/attr.c index 894002822..3e2202196 100644 --- a/lib/cgraph/attr.c +++ b/lib/cgraph/attr.c @@ -95,6 +95,8 @@ static void agcopydict(Dict_t * src, Dict_t * dest, Agraph_t * g, int kind) for (sym = (Agsym_t *) dtfirst(src); sym; sym = (Agsym_t *) dtnext(src, sym)) { newsym = agnewsym(g, sym->name, sym->defval, sym->id, kind); + newsym->print = sym->print; + newsym->fixed = sym->fixed; dtinsert(dest, newsym); } } diff --git a/lib/cgraph/grammar.y b/lib/cgraph/grammar.y index aa372a814..0bde9e07f 100644 --- a/lib/cgraph/grammar.y +++ b/lib/cgraph/grammar.y @@ -281,13 +281,14 @@ static void bindattrs(int kind) } } +/* attach node/edge specific attributes */ static void applyattrs(void *obj) { item *aptr; for (aptr = Attrlist.first; aptr; aptr = aptr->next) { if (aptr->tag == T_attr) { - if (aptr->u.asym && !aptr->u.asym->fixed) { + if (aptr->u.asym) { agxset(obj,aptr->u.asym,aptr->str); } } @@ -306,6 +307,7 @@ static void nomacros(void) /* attrstmt: * First argument is always attrtype, so switch covers all cases. + * This function is used to handle default attribute value assignment. */ static void attrstmt(int tkind, char *macroname) { @@ -326,7 +328,8 @@ static void attrstmt(int tkind, char *macroname) } bindattrs(kind); /* set up defaults for new attributes */ for (aptr = Attrlist.first; aptr; aptr = aptr->next) { - sym = agattr(G,kind,aptr->u.asym->name,aptr->str); + if (!(aptr->u.asym->fixed) || (G->root != G)) + sym = agattr(G,kind,aptr->u.asym->name,aptr->str); if (G->root == G) sym->print = TRUE; } @@ -472,8 +475,7 @@ static void mkport(Agedge_t *e, char *name, char *val) if (val) { if ((attr = agattr(G,AGEDGE,name,NIL(char*))) == NILsym) attr = agattr(G,AGEDGE,name,""); - if (!attr->fixed) - agxset(e,attr,val); + agxset(e,attr,val); } }