Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitlab/python-with'
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaffione committed Apr 20, 2016
2 parents 6a5d940 + 941f07a commit 6dc8f78
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extra/python/netmap_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ NetmapDesc_dealloc(NetmapDesc* self)

if (self->nmd) {
nm_close(self->nmd);
self->nmd = NULL;
}
self->ob_type->tp_free((PyObject*)self);
}
Expand Down Expand Up @@ -170,6 +171,24 @@ static PyGetSetDef NetmapDesc_getseters[] = {

/*########################## NetmapDesc methods ########################*/

static PyObject *
NetmapDesc_enter(NetmapDesc *self)
{
Py_INCREF(self);
return (PyObject *)self;
}

static PyObject *
NetmapDesc_exit(NetmapDesc *self, PyObject *args)
{
if (self->nmd) {
nm_close(self->nmd);
self->nmd = NULL;
}

Py_RETURN_NONE;
}

static PyObject *
NetmapDesc_xxsync(NetmapDesc *self, int iocmd)
{
Expand Down Expand Up @@ -217,6 +236,12 @@ NetmapDesc_getflags(NetmapDesc *self)

/* A container for the netmap methods. */
static PyMethodDef NetmapDesc_methods[] = {
{"__enter__", (PyCFunction)NetmapDesc_enter, METH_NOARGS,
"__enter__ implementation to support with statement"
},
{"__exit__", (PyCFunction)NetmapDesc_exit, METH_VARARGS,
"__exit__ implementation to support with statement"
},
{"txsync", (PyCFunction)NetmapDesc_txsync, METH_NOARGS,
"Do a txsync on the registered rings"
},
Expand Down

0 comments on commit 6dc8f78

Please sign in to comment.