ref: fcb6e8c8b48b215994d2b07d803a773643123c4d
parent: 8b7cdbad05db492a86eef2dc48bba1740b6afdf1
author: Paul Brossier <piem@piem.org>
date: Mon Feb 27 20:31:46 EST 2017
python/ext/py-sink.c: add 'with' interface (PEP 343)
--- a/python/ext/py-sink.c
+++ b/python/ext/py-sink.c
@@ -203,10 +203,25 @@
Py_RETURN_NONE;
}
+static char Pyaubio_sink_enter_doc[] = "";
+static PyObject* Pyaubio_sink_enter(Py_sink *self, PyObject *unused) {
+ Py_INCREF(self);
+ return (PyObject*)self;
+}
+
+static char Pyaubio_sink_exit_doc[] = "";
+static PyObject* Pyaubio_sink_exit(Py_sink *self, PyObject *unused) {
+ return Pyaubio_sink_close(self, unused);
+}
+
static PyMethodDef Py_sink_methods[] = {
{"do", (PyCFunction) Py_sink_do, METH_VARARGS, Py_sink_do_doc},
{"do_multi", (PyCFunction) Py_sink_do_multi, METH_VARARGS, Py_sink_do_multi_doc},
{"close", (PyCFunction) Pyaubio_sink_close, METH_NOARGS, Py_sink_close_doc},
+ {"__enter__", (PyCFunction)Pyaubio_sink_enter, METH_NOARGS,
+ Pyaubio_sink_enter_doc},
+ {"__exit__", (PyCFunction)Pyaubio_sink_exit, METH_VARARGS,
+ Pyaubio_sink_exit_doc},
{NULL} /* sentinel */
};