diff options
Diffstat (limited to 'dbus_bindings/unixfd.c')
-rw-r--r-- | dbus_bindings/unixfd.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/dbus_bindings/unixfd.c b/dbus_bindings/unixfd.c index ecb32d2..f39a0ce 100644 --- a/dbus_bindings/unixfd.c +++ b/dbus_bindings/unixfd.c @@ -3,6 +3,8 @@ * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/> * Copyright (C) 2010 Signove <http://www.signove.com> * + * SPDX-License-Identifier: MIT + * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without @@ -26,6 +28,9 @@ #include "dbus_bindings-internal.h" +#include <Python.h> +#include <structmember.h> + #include "types-internal.h" PyDoc_STRVAR(UnixFd_tp_doc, @@ -53,6 +58,7 @@ PyDoc_STRVAR(UnixFd_tp_doc, typedef struct { PyObject_HEAD int fd; + long variant_level; } UnixFdObject; /* Return values: @@ -92,13 +98,16 @@ make_fd(PyObject *arg, int *fd) } static PyObject * -UnixFd_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs UNUSED) +UnixFd_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { UnixFdObject *self = NULL; PyObject *arg; int status, fd, fd_original = -1; - if (!PyArg_ParseTuple(args, "O", &arg, NULL)) { + static char *argnames[] = {"fd", "variant_level", NULL}; + long variant_level = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|l", argnames, &arg, &variant_level)) { return NULL; } @@ -140,6 +149,12 @@ UnixFd_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs UNUSED) return NULL; self->fd = fd; + if (variant_level < 0) { + PyErr_Format(PyExc_ValueError, "variant_level cannot be less than 0"); + return NULL; + } + self->variant_level = variant_level; + return (PyObject *)self; } @@ -187,10 +202,21 @@ dbus_py_unix_fd_get_fd(PyObject *self) } static PyMethodDef UnixFd_methods[] = { - {"take", (PyCFunction) UnixFd_take, METH_NOARGS, UnixFd_take__doc__ }, + {"take", (PyCFunction) (void (*)(void)) UnixFd_take, METH_NOARGS, UnixFd_take__doc__ }, {NULL} }; +static struct PyMemberDef UnixFd_tp_members[] = { + {"variant_level", T_LONG, offsetof(UnixFdObject, variant_level), + READONLY, + "Indicates how many nested Variant containers this object\n" + "is contained in: if a message's wire format has a variant containing a\n" + "variant containing a file descriptor, this is represented in Python by\n" + "a UnixFd with variant_level==2.\n" + }, + {NULL}, +}; + PyTypeObject DBusPyUnixFd_Type = { PyVarObject_HEAD_INIT(NULL, 0) "dbus.UnixFd", @@ -220,7 +246,7 @@ PyTypeObject DBusPyUnixFd_Type = { 0, /* tp_iter */ 0, /* tp_iternext */ UnixFd_methods, /* tp_methods */ - 0, /* tp_members */ + UnixFd_tp_members, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ |