Skip to content

Commit

Permalink
Merge branch 'fix-module-cleanup' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
congma committed Mar 17, 2021
2 parents 5715bc3 + 93c6a67 commit a5d6506
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/lrudict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,12 +1892,24 @@ static PyTypeObject LRUDictType = {
};


static void
lru_ng_module_free_safe_types(void *mself)
{
if (mself == NULL) {
return;
}
ts_destroy(lru_safe_types);
return;
}


/* Module structure */
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
.m_name = "lru_ng",
.m_doc = lru_doc,
.m_size = -1,
.m_free = lru_ng_module_free_safe_types,
};


Expand All @@ -1916,7 +1928,7 @@ moduleinit(void)
return NULL;
}

/* Pull in the heap-allocated types */
/* Pull in the types */
if (PyType_Ready(&NodeType) < 0) {
return NULL;
}
Expand Down Expand Up @@ -1949,17 +1961,11 @@ moduleinit(void)
/* Make types available to module, or fail and cleanup */
Py_INCREF(&NodeType);
Py_INCREF(&LRUDictType);
#ifdef LRUDICT_STRUCT_SEQUENCE_NOT_BROKEN
Py_INCREF(LRUDictStatsType);
#endif
if (PyModule_AddObject(m, "LRUDict", (PyObject *)(&LRUDictType)) < 0 ||
PyModule_AddObject(m, "LRUDictBusyError", LRUDictExc_BusyErr) < 0)
{
Py_DECREF(&LRUDictType);
Py_DECREF(&NodeType);
#ifdef LRUDICT_STRUCT_SEQUENCE_NOT_BROKEN
Py_DECREF(LRUDictStatsType);
#endif
Py_DECREF(m);
m = NULL;
}
Expand Down

0 comments on commit a5d6506

Please sign in to comment.