Skip to content

Commit 9a40e6b

Browse files
committed
Fix SEGV on Ruby finalization phase
1 parent 52bdcb6 commit 9a40e6b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/pycall/gc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "pycall_internal.h"
22

3+
static ID id_gcguard_table;
4+
35
struct gcguard {
46
st_table *guarded_objects;
57
};
@@ -24,6 +26,7 @@ gcguard_free(void* ptr)
2426
{
2527
struct gcguard *gg = (struct gcguard *)ptr;
2628
st_free_table(gg->guarded_objects);
29+
rb_ivar_set(mPyCall, id_gcguard_table, Qnil);
2730
}
2831

2932
static size_t
@@ -69,7 +72,6 @@ gcguard_delete(VALUE gcguard, PyObject *pyptr)
6972
}
7073
}
7174

72-
static ID id_gcguard_table;
7375
static PyObject *weakref_callback_pyobj;
7476
static PyObject *gcguard_weakref_destroyed(PyObject *self, PyObject *weakref);
7577

@@ -98,7 +100,9 @@ void
98100
pycall_gcguard_delete(PyObject *pyobj)
99101
{
100102
VALUE gcguard = rb_ivar_get(mPyCall, id_gcguard_table);
101-
gcguard_delete(gcguard, pyobj);
103+
if (!NIL_P(gcguard)) {
104+
gcguard_delete(gcguard, pyobj);
105+
}
102106
}
103107

104108
void

0 commit comments

Comments
 (0)