Skip to content

Several problems with _lsprof_Profiler_enable #126425

Closed
@sobolevn

Description

@sobolevn

Bug report

There are several problems that I see with _lsprof.Profiler.enable() method:

  • cpython/Modules/_lsprof.c

    Lines 783 to 787 in d384050

    if (PyObject_CallMethod(monitoring, "use_tool_id", "is", self->tool_id, "cProfile") == NULL) {
    PyErr_Format(PyExc_ValueError, "Another profiling tool is already active");
    Py_DECREF(monitoring);
    return NULL;
    }
    This code implictly overrides the set exception, I would prefer to have an explicit PyErr_Clear() call to show that this is intentional
  • Also, the same code does not decrement the refcount of the result, it is None right now (which is immortal), but we still prefer to do the refcount for such objects, where possible
  • This code ignores possible exceptions:

    cpython/Modules/_lsprof.c

    Lines 795 to 799 in d384050

    Py_XDECREF(PyObject_CallMethod(monitoring, "register_callback", "iiO", self->tool_id,
    (1 << callback_table[i].event),
    callback));
    Py_DECREF(callback);
    all_events |= (1 << callback_table[i].event);

I will send a PR.

Linked PRs

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions