Skip to content

Commit

Permalink
Fix SEGV on Ruby finalization phase
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed May 24, 2024
1 parent 52bdcb6 commit 9a40e6b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/pycall/gc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pycall_internal.h"

static ID id_gcguard_table;

struct gcguard {
st_table *guarded_objects;
};
Expand All @@ -24,6 +26,7 @@ gcguard_free(void* ptr)
{
struct gcguard *gg = (struct gcguard *)ptr;
st_free_table(gg->guarded_objects);
rb_ivar_set(mPyCall, id_gcguard_table, Qnil);
}

static size_t
Expand Down Expand Up @@ -69,7 +72,6 @@ gcguard_delete(VALUE gcguard, PyObject *pyptr)
}
}

static ID id_gcguard_table;
static PyObject *weakref_callback_pyobj;
static PyObject *gcguard_weakref_destroyed(PyObject *self, PyObject *weakref);

Expand Down Expand Up @@ -98,7 +100,9 @@ void
pycall_gcguard_delete(PyObject *pyobj)
{
VALUE gcguard = rb_ivar_get(mPyCall, id_gcguard_table);
gcguard_delete(gcguard, pyobj);
if (!NIL_P(gcguard)) {
gcguard_delete(gcguard, pyobj);
}
}

void
Expand Down

0 comments on commit 9a40e6b

Please sign in to comment.