From: Paul Brossier Date: Sun, 26 Feb 2017 22:47:19 +0000 (+0100) Subject: python/ext/py-source.c: add with interface (PEP 343) X-Git-Tag: 0.4.5~89 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=f1f2e7ec62cdda1f0acc3ad929b76574b7d04066 python/ext/py-source.c: add with interface (PEP 343) --- diff --git a/python/ext/py-source.c b/python/ext/py-source.c index 8350904a..f8dd3aa9 100644 --- a/python/ext/py-source.c +++ b/python/ext/py-source.c @@ -272,6 +272,18 @@ Pyaubio_source_seek (Py_source *self, PyObject *args) Py_RETURN_NONE; } +static char Pyaubio_source_enter_doc[] = ""; +static PyObject* Pyaubio_source_enter(Py_source *self, PyObject *unused) { + Py_INCREF(self); + return (PyObject*)self; +} + +static char Pyaubio_source_exit_doc[] = ""; +static PyObject* Pyaubio_source_exit(Py_source *self, PyObject *unused) { + Pyaubio_source_close(self, unused); + return Pyaubio_source_close(self, unused); +} + static PyMethodDef Py_source_methods[] = { {"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate, METH_NOARGS, Py_source_get_samplerate_doc}, @@ -285,6 +297,10 @@ static PyMethodDef Py_source_methods[] = { METH_NOARGS, Py_source_close_doc}, {"seek", (PyCFunction) Pyaubio_source_seek, METH_VARARGS, Py_source_seek_doc}, + {"__enter__", (PyCFunction)Pyaubio_source_enter, METH_NOARGS, + Pyaubio_source_enter_doc}, + {"__exit__", (PyCFunction)Pyaubio_source_exit, METH_VARARGS, + Pyaubio_source_exit_doc}, {NULL} /* sentinel */ };