]> granicus.if.org Git - graphviz/commitdiff
gvpr nameOf: use an agxbuf instead of SFIO stream
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 7 Aug 2022 17:05:19 +0000 (10:05 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 13 Aug 2022 16:18:53 +0000 (09:18 -0700)
This makes it clearer to both humans and the compiler that the data written to
this buffer has a much more constrained scope than was previously implied. This
also gets us closer to removing an SFIO dependency.

Gitlab: #1873

lib/gvpr/compile.c

index ee047f1a759edfbf114b3188111ac436947ec687..7058c368a9d648b95044e383b5700ffe3e2b5e4d 100644 (file)
@@ -89,8 +89,7 @@ static Agdisc_t gprDisc = { &AgMemDisc, &AgIdDisc, &gprIoDisc };
  * Return name of object. 
  * Assumes obj !=  NULL
  */
-static char *nameOf(Expr_t * ex, Agobj_t * obj, Sfio_t* tmps)
-{
+static char *nameOf(Expr_t *ex, Agobj_t *obj, agxbuf *tmps) {
     char *s;
     char *key;
     Agedge_t *e;
@@ -103,18 +102,18 @@ static char *nameOf(Expr_t * ex, Agobj_t * obj, Sfio_t* tmps)
     default:                   /* edge */
        e = (Agedge_t *) obj;
        key = agnameof(AGMKOUT(e));
-       sfputr(tmps, agnameof(AGTAIL(e)), -1);
+       agxbput(tmps, agnameof(AGTAIL(e)));
        if (agisdirected(agraphof(e)))
-           sfputr(tmps, "->", -1);
+           agxbput(tmps, "->");
        else
-           sfputr(tmps, "--", -1);
-       sfputr(tmps, agnameof(AGHEAD(e)), -1);
+           agxbput(tmps, "--");
+       agxbput(tmps, agnameof(AGHEAD(e)));
        if (key && *key) {
-           sfputc(tmps, '[');
-           sfputr(tmps, key, -1);
-           sfputc(tmps, ']');
+           agxbputc(tmps, '[');
+           agxbput(tmps, key);
+           agxbputc(tmps, ']');
        }
-       s = exstring(ex, sfstruse(tmps));
+       s = exstring(ex, agxbuse(tmps));
        break;
     }
     return s;
@@ -443,9 +442,13 @@ static int lookup(Expr_t * pgm, Agobj_t * objp, Exid_t * sym, Extype_t * v,
                return -1;
            }
            break;
-       case M_name:
-           v->string = nameOf(pgm, objp, state->tmp);
+       case M_name: {
+           agxbuf tmp = {0};
+           agxbinit(&tmp, 0, NULL);
+           v->string = nameOf(pgm, objp, &tmp);
+           agxbfree(&tmp);
            break;
+       }
        case M_indegree:
            if (AGTYPE(objp) == AGNODE)
                v->integer = agdegree(agroot(objp), (Agnode_t *) objp, 1, 0);
@@ -540,9 +543,12 @@ static int lookup(Expr_t * pgm, Agobj_t * objp, Exid_t * sym, Extype_t * v,
        Agsym_t *gsym = agattrsym(objp, sym->name);
        if (!gsym) {
            gsym = agattr(agroot(agraphof(objp)), AGTYPE(objp), sym->name, "");
+           agxbuf tmp = {0};
+           agxbinit(&tmp, 0, NULL);
            error(ERROR_WARNING,
                  "Using value of uninitialized %s attribute \"%s\" of \"%s\"",
-                 kindOf (objp), sym->name, nameOf(pgm, objp, state->tmp));
+                 kindOf (objp), sym->name, nameOf(pgm, objp, &tmp));
+           agxbfree(&tmp);
        }
        v->string = agxget(objp, gsym);
     }
@@ -1334,9 +1340,12 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref,
                else {
                    if (!gsym) {
                        gsym = agattr(agroot(agraphof(objp)), AGTYPE(objp), name, "");
+                       agxbuf tmp = {0};
+                       agxbinit(&tmp, 0, NULL);
                        error(ERROR_WARNING,
                              "Using value of %s uninitialized attribute \"%s\" of \"%s\" in aget()",
-                             kindOf (objp), name, nameOf(pgm, objp, state->tmp));
+                             kindOf (objp), name, nameOf(pgm, objp, &tmp));
+                       agxbfree(&tmp);
                    }
                    v.string = agxget(objp, gsym);
                }
@@ -2104,8 +2113,10 @@ static int stringOf(Expr_t * prog, Exnode_t * x, int arg, Exdisc_t* disc)
            rv = -1;
        }
        else {
-           Gpr_t* state = disc->user;
-           x->data.constant.value.string = nameOf(prog, objp, state->tmp);
+           agxbuf tmp = {0};
+           agxbinit(&tmp, 0, NULL);
+           x->data.constant.value.string = nameOf(prog, objp, &tmp);
+           agxbfree(&tmp);
        }
     }
     x->type = STRING;