Commit 52fe287a authored by Jeff Trull's avatar Jeff Trull
Browse files

Adjust use of libgvc to fix two graphviz_draw issues

One issue was reported to the mailing list on 2020-08-17 by Rolf
Sander; the testcase is:

import graph_tool.all as gt
g = gt.Graph()
v0 = g.add_vertex()
v1 = g.add_vertex()
e01 = g.add_edge(v0,v1)
e11 = g.add_edge(v1,v1) # loop

The other is issue #597 "Graphviz_draw core dumping when using HTML labels"

Basically these changes add extra type information for interacting
with libgvc.
parent 682b4f46
Pipeline #701 passed with stage
in 113 minutes and 54 seconds
......@@ -66,14 +66,17 @@ try:
libgv.agedge.restype = ptype
libgv.agget.restype = ptype
libgv.agstrdup_html.restype = ptype
libgv.agstrdup_html.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
libgv.agraphof.restype = ctypes.c_void_p
libgv.agraphof.argtypes = [ctypes.c_void_p]
# create a context to use the whole time (if we keep freeing and recreating
# it, we will hit a memory leak in graphviz)
gvc = libgv.gvContext()
gv_new_api = True
libgv_directed = libgv.Agdirected
libgv_undirected = libgv.Agundirected
libgv_directed = ctypes.c_int.in_dll(libgv, "Agdirected")
libgv_undirected = ctypes.c_int.in_dll(libgv, "Agundirected")
except AttributeError:
gv_new_api = False
libgv_directed = 1
......@@ -85,14 +88,15 @@ except OSError:
warnings.warn(msg, ImportWarning)
def htmlize(val):
def htmlize(elem, val):
if len(val) >= 2 and val[0] == "<" and val[-1] == ">":
return ctypes.string_at(libgv.agstrdup_html(val[1:-1]))
g = libgv.agraphof(elem)
return ctypes.string_at(libgv.agstrdup_html(g, str(val[1:-1]).encode("utf8")))
return val
def aset(elem, attr, value):
v = htmlize(str(value)).encode("utf8")
v = htmlize(elem, str(value))
libgv.agsafeset(elem, str(attr).encode("utf8"), v, v)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment