Skip to content

traverse_module_state can return int, do not use (void) for it #135839

Open
@sobolevn

Description

@sobolevn

Bug report

traverse_module_state can in theory return non-zero code:

static int
traverse_module_state(module_state *state, visitproc visit, void *arg)
{
/* external types */
Py_VISIT(state->send_channel_type);
Py_VISIT(state->recv_channel_type);
/* heap types */
Py_VISIT(state->ChannelInfoType);
Py_VISIT(state->ChannelIDType);
/* exceptions */
Py_VISIT(state->ChannelError);
Py_VISIT(state->ChannelNotFoundError);
Py_VISIT(state->ChannelClosedError);
Py_VISIT(state->ChannelEmptyError);
Py_VISIT(state->ChannelNotEmptyError);
return 0;
}

because PY_VISIT can return it:

cpython/Include/objimpl.h

Lines 193 to 200 in 0d9d489

#define Py_VISIT(op) \
do { \
if (op) { \
int vret = visit(_PyObject_CAST(op), arg); \
if (vret) \
return vret; \
} \
} while (0)

So, using it like this:

// Now we clear the module state.
(void)clear_module_state(state);
return 0;

Is also not really correct. I will send a PR with the fix.

Linked PRs

Metadata

Metadata

Assignees

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions