Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Port audioop extension module to multiphase initialization(PEP 489)
  • Loading branch information
shihai1991 committed Feb 22, 2020
commit 42b2a610567ec6d33176bcd44fd0c3dc415809ab
38 changes: 27 additions & 11 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,25 +1909,50 @@ audioop_traverse(PyObject *m, visitproc visit, void *arg) {
Py_VISIT(state->AudioopError);
return 0;
}

static int
audioop_clear(PyObject *m) {
_audioopstate *state = _audioopstate(m);
if (state != NULL)
Py_CLEAR(state->AudioopError);
return 0;
}

static void
audioop_free(void *m) {
audioop_clear((PyObject *)m);
}

static int
audioop_exec(PyObject* m)
{
_audioopstate *state = _audioopstate(m);

state->AudioopError = PyErr_NewException("audioop.error", NULL, NULL);
if (state->AudioopError == NULL) {
return -1;
}

Py_INCREF(state->AudioopError);
if (PyModule_AddObject(m, "error", state->AudioopError) < 0) {
Py_DECREF(state->AudioopError);
return -1;
}

return 0;
}

static PyModuleDef_Slot audioop_slots[] = {
{Py_mod_exec, audioop_exec}
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
};

static struct PyModuleDef audioopmodule = {
PyModuleDef_HEAD_INIT,
"audioop",
NULL,
sizeof(_audioopstate),
audioop_methods,
NULL,
audioop_slots,
audioop_traverse,
audioop_clear,
audioop_free
Expand All @@ -1936,14 +1961,5 @@ static struct PyModuleDef audioopmodule = {
PyMODINIT_FUNC
PyInit_audioop(void)
{
PyObject *m = PyModule_Create(&audioopmodule);
if (m == NULL)
return NULL;
PyObject *AudioopError = PyErr_NewException("audioop.error", NULL, NULL);
if (AudioopError == NULL)
return NULL;
Py_INCREF(AudioopError);
PyModule_AddObject(m, "error", AudioopError);
_audioopstate(m)->AudioopError = AudioopError;
return m;
return PyModuleDef_Init(&audioopmodule);
}