Skip to content

Commit 68c5d66

Browse files
committed
ensure uniqueness of gcc.Cfg for an underlying gcc_cfg
1 parent 3cef7c8 commit 68c5d66

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

gcc-python-cfg.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,19 @@ PyGccCfg_get_block_for_label(PyObject *s, PyObject *args)
452452
return PyGccBasicBlock_New(gcc_private_make_cfg_block(bb));
453453
}
454454

455+
union gcc_cfg_as_ptr {
456+
gcc_cfg cfg;
457+
void *ptr;
458+
};
459+
455460
PyObject *
456-
PyGccCfg_New(gcc_cfg cfg)
461+
real_make_cfg_wrapper(void *ptr)
457462
{
458463
struct PyGccCfg *obj;
464+
union gcc_cfg_as_ptr u;
465+
u.ptr = ptr;
459466

460-
if (!cfg.inner) {
467+
if (!u.cfg.inner) {
461468
Py_RETURN_NONE;
462469
}
463470

@@ -466,14 +473,25 @@ PyGccCfg_New(gcc_cfg cfg)
466473
goto error;
467474
}
468475

469-
obj->cfg = cfg;
476+
obj->cfg = u.cfg;
470477

471478
return (PyObject*)obj;
472479

473480
error:
474481
return NULL;
475482
}
476483

484+
static PyObject *cfg_wrapper_cache = NULL;
485+
PyObject *
486+
PyGccCfg_New(gcc_cfg cfg)
487+
{
488+
union gcc_cfg_as_ptr u;
489+
u.cfg = cfg;
490+
return PyGcc_LazilyCreateWrapper(&cfg_wrapper_cache,
491+
u.ptr,
492+
real_make_cfg_wrapper);
493+
}
494+
477495
void
478496
PyGcc_WrtpMarkForPyGccCfg(PyGccCfg *wrapper)
479497
{

0 commit comments

Comments
 (0)