Skip to content
Merged
Changes from all commits
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
28 changes: 18 additions & 10 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2916,18 +2916,21 @@ typedef struct _PyLegacyBranchEventHandler {
int tool_id;
} _PyLegacyBranchEventHandler;

#define _PyLegacyBranchEventHandler_CAST(op) ((_PyLegacyBranchEventHandler *)(op))

static void
dealloc_branch_handler(_PyLegacyBranchEventHandler *self)
dealloc_branch_handler(PyObject *op)
{
_PyLegacyBranchEventHandler *self = _PyLegacyBranchEventHandler_CAST(op);
Py_CLEAR(self->handler);
PyObject_Free((PyObject *)self);
PyObject_Free(self);
}

static PyTypeObject _PyLegacyBranchEventHandler_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sys.monitoring.branch_event_handler",
sizeof(_PyLegacyBranchEventHandler),
.tp_dealloc = (destructor)dealloc_branch_handler,
.tp_dealloc = dealloc_branch_handler,
.tp_vectorcall_offset = offsetof(_PyLegacyBranchEventHandler, vectorcall),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_VECTORCALL | Py_TPFLAGS_DISALLOW_INSTANTIATION,
Expand All @@ -2936,10 +2939,11 @@ static PyTypeObject _PyLegacyBranchEventHandler_Type = {


static PyObject *
branch_handler(
_PyLegacyBranchEventHandler *self, PyObject *const *args,
branch_handler_vectorcall(
PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyBranchEventHandler *self = _PyLegacyBranchEventHandler_CAST(op);
// Find the other instrumented instruction and remove tool
// The spec (PEP 669) allows spurious events after a DISABLE,
// so a best effort is good enough.
Expand Down Expand Up @@ -3000,7 +3004,7 @@ static PyObject *make_branch_handler(int tool_id, PyObject *handler, bool right)
if (callback == NULL) {
return NULL;
}
callback->vectorcall = (vectorcallfunc)branch_handler;
callback->vectorcall = branch_handler_vectorcall;
callback->handler = Py_NewRef(handler);
callback->right = right;
callback->tool_id = tool_id;
Expand Down Expand Up @@ -3062,6 +3066,8 @@ typedef struct {
int bi_offset;
} branchesiterator;

#define branchesiterator_CAST(op) ((branchesiterator *)(op))

static PyObject *
int_triple(int a, int b, int c) {
PyObject *obja = PyLong_FromLong(a);
Expand All @@ -3088,8 +3094,9 @@ int_triple(int a, int b, int c) {
}

static PyObject *
branchesiter_next(branchesiterator *bi)
branchesiter_next(PyObject *op)
{
branchesiterator *bi = branchesiterator_CAST(op);
int offset = bi->bi_offset;
int oparg = 0;
while (offset < Py_SIZE(bi->bi_code)) {
Expand Down Expand Up @@ -3130,8 +3137,9 @@ branchesiter_next(branchesiterator *bi)
}

static void
branchesiter_dealloc(branchesiterator *bi)
branchesiter_dealloc(PyObject *op)
{
branchesiterator *bi = branchesiterator_CAST(op);
Py_DECREF(bi->bi_code);
PyObject_Free(bi);
}
Expand All @@ -3142,10 +3150,10 @@ static PyTypeObject _PyBranchesIterator = {
sizeof(branchesiterator), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
.tp_dealloc = (destructor)branchesiter_dealloc,
.tp_dealloc = branchesiter_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_iter = PyObject_SelfIter,
.tp_iternext = (iternextfunc)branchesiter_next,
.tp_iternext = branchesiter_next,
.tp_free = PyObject_Del,
};

Expand Down
Loading