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
51 changes: 32 additions & 19 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -5824,25 +5824,6 @@ - (int)index
return (PyObject*) self;
}

static void
Timer_dealloc(Timer* self)
{
if (self->timer) {
PyObject* attribute;
CFRunLoopTimerContext context;
CFRunLoopTimerGetContext(self->timer, &context);
attribute = context.info;
Py_DECREF(attribute);
CFRunLoopRef runloop = CFRunLoopGetCurrent();
if (runloop) {
CFRunLoopRemoveTimer(runloop, self->timer, kCFRunLoopCommonModes);
}
CFRelease(self->timer);
self->timer = NULL;
}
Py_TYPE(self)->tp_free((PyObject*)self);
}

static PyObject*
Timer_repr(Timer* self)
{
Expand Down Expand Up @@ -5953,12 +5934,44 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
return Py_None;
}

static PyObject*
Timer__timer_stop(Timer* self)
{
if (self->timer) {
PyObject* attribute;
CFRunLoopTimerContext context;
CFRunLoopTimerGetContext(self->timer, &context);
attribute = context.info;
Py_DECREF(attribute);
CFRunLoopRef runloop = CFRunLoopGetCurrent();
if (runloop) {
CFRunLoopRemoveTimer(runloop, self->timer, kCFRunLoopCommonModes);
}
CFRelease(self->timer);
self->timer = NULL;
}
Py_INCREF(Py_None);
return Py_None;
}

static void
Timer_dealloc(Timer* self)
{
Timer__timer_stop(self);
Py_TYPE(self)->tp_free((PyObject*)self);
}

static PyMethodDef Timer_methods[] = {
{"_timer_start",
(PyCFunction)Timer__timer_start,
METH_VARARGS,
"Initialize and start the timer."
},
{"_timer_stop",
(PyCFunction)Timer__timer_stop,
METH_NOARGS,
"Stop the timer."
},
{NULL} /* Sentinel */
};

Expand Down