Skip to content

Commit 844618c

Browse files
committed
ensure there is a unique gcc.CallgraphEdge for each underlying edge
1 parent 9b950b4 commit 844618c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

gcc-python-callgraph.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,43 @@ PyGccCallgraphNode_get_callers(struct PyGccCallgraphNode * self)
7676
add_cgraph_edge_to_list)
7777
}
7878

79+
union gcc_cgraph_edge_as_ptr {
80+
gcc_cgraph_edge edge;
81+
void *ptr;
82+
};
83+
7984
PyObject *
80-
PyGccCallgraphEdge_New(gcc_cgraph_edge edge)
85+
real_make_cgraph_edge_wrapper(void *ptr)
8186
{
8287
struct PyGccCallgraphEdge *obj = NULL;
88+
union gcc_cgraph_edge_as_ptr u;
89+
u.ptr = ptr;
8390

84-
obj = PyGccWrapper_New(struct PyGccCallgraphEdge, &PyGccCallgraphEdge_TypeObj);
91+
obj = PyGccWrapper_New(struct PyGccCallgraphEdge,
92+
&PyGccCallgraphEdge_TypeObj);
8593
if (!obj) {
8694
goto error;
8795
}
8896

89-
obj->edge = edge;
97+
obj->edge = u.edge;
9098

9199
return (PyObject*)obj;
92100

93101
error:
94102
return NULL;
95103
}
96104

105+
static PyObject *cgraph_edge_wrapper_cache = NULL;
106+
PyObject *
107+
PyGccCallgraphEdge_New(gcc_cgraph_edge edge)
108+
{
109+
union gcc_cgraph_edge_as_ptr u;
110+
u.edge = edge;
111+
return PyGcc_LazilyCreateWrapper(&cgraph_edge_wrapper_cache,
112+
u.ptr,
113+
real_make_cgraph_edge_wrapper);
114+
}
115+
97116
void
98117
PyGcc_WrtpMarkForPyGccCallgraphEdge(PyGccCallgraphEdge *wrapper)
99118
{

0 commit comments

Comments
 (0)