mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-24 01:17:26 +08:00
fix py gc edge case (#2079)
This commit is contained in:
parent
b529515eb1
commit
55935ccae7
@ -98,9 +98,12 @@ int py_function_exporter_tp_traverse(
|
||||
PyObject* self,
|
||||
visitproc visit,
|
||||
void* arg) {
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
if (!nb::inst_ready(self)) {
|
||||
return 0;
|
||||
}
|
||||
auto* p = nb::inst_ptr<PyFunctionExporter>(self);
|
||||
Py_VISIT(p->dep_.ptr());
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,12 @@ struct gc_func {
|
||||
};
|
||||
|
||||
int gc_func_tp_traverse(PyObject* self, visitproc visit, void* arg) {
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
gc_func* w = (gc_func*)self;
|
||||
Py_VISIT(w->func);
|
||||
for (auto d : w->deps) {
|
||||
Py_VISIT(d);
|
||||
}
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
@ -960,6 +960,11 @@ class PyCustomFunction {
|
||||
};
|
||||
|
||||
int py_custom_function_tp_traverse(PyObject* self, visitproc visit, void* arg) {
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
if (!nb::inst_ready(self)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto* p = nb::inst_ptr<PyCustomFunction>(self);
|
||||
nb::handle v = nb::find(p->fun_);
|
||||
Py_VISIT(v.ptr());
|
||||
@ -975,7 +980,6 @@ int py_custom_function_tp_traverse(PyObject* self, visitproc visit, void* arg) {
|
||||
nb::handle v = nb::find(*(p->vmap_fun_));
|
||||
Py_VISIT(v.ptr());
|
||||
}
|
||||
Py_VISIT(Py_TYPE(self));
|
||||
return 0;
|
||||
}
|
||||
int py_custom_function_tp_clear(PyObject* self) {
|
||||
|
Loading…
Reference in New Issue
Block a user