Skip to content
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

Added a _timer_stop method to the Timer in MacOSX backend #2233

Merged
merged 1 commit into from Jul 23, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/_macosx.m
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