Skip to content

bpo-1635741: Port audioop extension module to multiphase initialization(PEP 489) #18608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2020
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
Prev Previous commit
Next Next commit
using the var name module to replace m
  • Loading branch information
shihai1991 committed Mar 1, 2020
commit cfa67a7b9385f7cffcfd54f63c92f30f928c7ccf
18 changes: 9 additions & 9 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,42 +1923,42 @@ static PyMethodDef audioop_methods[] = {
};

static int
audioop_traverse(PyObject *m, visitproc visit, void *arg)
audioop_traverse(PyObject *module, visitproc visit, void *arg)
{
audioop_state *state = (audioop_state *)PyModule_GetState(m);
audioop_state *state = (audioop_state *)PyModule_GetState(module);
if (state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really possible that state can be NULL when this function is called?

Py_VISIT(state->AudioopError);
}
return 0;
}

static int
audioop_clear(PyObject *m)
audioop_clear(PyObject *module)
{
audioop_state *state = (audioop_state *)PyModule_GetState(m);
audioop_state *state = (audioop_state *)PyModule_GetState(module);
if (state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really possible that state can be NULL when this function is called?

module_clear() doesn't touch module->md_state value. Only module_dealloc() calls PyMem_FREE(m->md_state). But audioop_clear() must not be called on a deallocated module object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see this question answered before approving the PR.

Copy link
Member

@encukou encukou Mar 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth us to change this logic as victor said?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created https://bugs.python.org/issue39824 to propose to change the Python behavior, so modules would not have to handle md_state=NULL anymore.

Py_CLEAR(state->AudioopError);
}
return 0;
}

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

static int
audioop_exec(PyObject* m)
audioop_exec(PyObject* module)
{
audioop_state *state = get_audioop_state(m);
audioop_state *state = get_audioop_state(module);

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) {
if (PyModule_AddObject(module, "error", state->AudioopError) < 0) {
Py_DECREF(state->AudioopError);
return -1;
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy