Number: 1749
Title: gvRender() prints to stdout when it should not do so
Submitter: Martin Olsson
Date: Sun Aug 23 17:48:10 2009
Subsys: Dot
Version: 2.20.2
System: x86-Linux-Ubuntu 9.10 Karmic
Severity: major
Problem:
In this graphviz manual: http://graphviz.org/pdf/libguide.pdf

.. it says on page 16 that "the application can call the appropriate renderer, passing a NULL stream pointer to gvRender5 as in Figure 2". Also note the footnote on page 16 which clarifies that "This convention only works, and only makes sense, with the dot and xdot renderers. For other renders, a NULL stream will cause output to be written on stdout".

..anyway, the documentation is very clear. It should be possible to have libgvc attach "pos" attributes to the nodes without printing anything to the screen.

Today this is not possible using the graphviz "2.20.2-3ubuntu4" version that I'm using in ubuntu karmic.

---

This testcase program below should not print anything to stdout but it does print the whole graph in "dot" format.


// Sample program can be compiled using the command:
// gcc main.c -o main $(pkg-config --cflags --libs libgvc)
#include <graphviz/gvc.h>
int main(void)
{
        GVC_t* gvc = gvContext();
        Agraph_t* graph = agopen("", AGDIGRAPHSTRICT);
        Agnode_t* node1 = agnode(graph, "node 1");
        gvLayout(gvc, graph, "dot");
        gvRender(gvc, graph, "dot", NULL);
        gvFreeLayout(gvc, graph);
        agclose(graph);
        gvFreeContext(gvc);
        return 0;
}

----

If I put a breakpoint on "write" I can see exactly which part of graphviz it is that does the printing to stdout:


#0  0x00007ffff74ac8e0 in write () from /lib/libc.so.6
#1  0x00007ffff744c863 in _IO_new_file_write (f=0x7ffff7744780, data=0x7ffff7ea6000, n=20) at fileops.c:1275
#2  0x00007ffff744de25 in new_do_write (fp=0x7ffff7744780, data=0x7ffff7ea6000 "strict digraph "" {n", to_do=20) at fileops.c:529
#3  _IO_new_do_write (fp=0x7ffff7744780, data=0x7ffff7ea6000 "strict digraph "" {n", to_do=20) at fileops.c:502
#4  0x00007ffff744c512 in _IO_new_file_xsputn (f=0x7ffff7744780, data=0x7ffff795990e, n=3) at fileops.c:1357
#5  0x00007ffff7420375 in _IO_vfprintf_internal (s=0x7ffff7744780, format=<value optimized out>, ap=0x7fffffffdde0) at vfprintf.c:1631
#6  0x00007ffff74d0dbb in ___fprintf_chk (fp=0x7ffff7744780, flag=1, format=0x3 <Address 0x3 out of bounds>) at fprintf_chk.c:37
#7  0x00007ffff7956a1e in fprintf (g=0x611740, fp=0x7ffff7744780) at /usr/include/bits/stdio2.h:98
#8  agwrite (g=0x611740, fp=0x7ffff7744780) at graphio.c:514
#9  0x00007ffff7b7fdf8 in gvrender_end_graph (job=0x664040) at gvrender.c:299
#10 0x00007ffff7ba92c5 in emit_end_graph (job=0x664040, g=0x611740) at emit.c:2147
#11 emit_graph (job=0x664040, g=0x611740) at emit.c:2262
#12 0x00007ffff7baaa0b in gvRenderJobs (gvc=0x605d50, g=0x611740) at emit.c:2822
#13 0x00007ffff7b84dec in gvRender (gvc=0x605d50, g=0x611740, format=<value optimized out>, out=0x0) at gvc.c:111
#14 0x00000000004008e3 in main ()

----

Note that someone else already discovered this bug for choose to use a workaround instead: https://mailman.research.att.com/pipermail/graphviz-devel/2009/000972.html

I could not even get the workaround to work though because in my version of graphviz I don't have the ND_coord macro defined at all and my program needs to be compatible with both older and new versions of Ubuntu so I don't want to use any hacks or so.
Comments:
[erg] This was a bug introduced in October 2007, thus appearing in the 2.20 release. It was fixed in August 2008.

The ND_coord macro is defined in types.h which is included by gvc.h. If you just need the position information, this will give it to you, as John noted. The macro is part of the library API, so is not a hack.

[erg] For reference: changed gvrender.c, creating version 1.147
Owner: erg
Status: Fixed (14 Aug 2009)