Commit 5f5a7781 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-34740: Get rid of tp_getattro in ossaudiodev.oss_audio_device. (GH-9421)

Use tp_members and tp_getset instead.
parent b2953fa3
...@@ -921,46 +921,43 @@ static PyMethodDef oss_mixer_methods[] = { ...@@ -921,46 +921,43 @@ static PyMethodDef oss_mixer_methods[] = {
{ NULL, NULL} { NULL, NULL}
}; };
static PyMemberDef oss_members[] = {
{"name", T_STRING, offsetof(oss_audio_t, devicename), READONLY, NULL},
{NULL}
};
static PyObject * static PyObject *
oss_getattro(oss_audio_t *self, PyObject *nameobj) oss_closed_getter(oss_audio_t *self, void *closure)
{ {
const char *name = ""; return PyBool_FromLong(self->fd == -1);
PyObject * rval = NULL; }
if (PyUnicode_Check(nameobj)) {
name = PyUnicode_AsUTF8(nameobj);
if (name == NULL)
return NULL;
}
if (strcmp(name, "closed") == 0) { static PyObject *
rval = (self->fd == -1) ? Py_True : Py_False; oss_mode_getter(oss_audio_t *self, void *closure)
Py_INCREF(rval); {
} switch(self->mode) {
else if (strcmp(name, "name") == 0) { case O_RDONLY:
rval = PyUnicode_FromString(self->devicename); return PyUnicode_FromString("r");
} break;
else if (strcmp(name, "mode") == 0) { case O_RDWR:
/* No need for a "default" in this switch: from newossobject(), return PyUnicode_FromString("rw");
self->mode can only be one of these three values. */ break;
switch(self->mode) { case O_WRONLY:
case O_RDONLY: return PyUnicode_FromString("w");
rval = PyUnicode_FromString("r"); break;
break; default:
case O_RDWR: /* From newossobject(), self->mode can only be one
rval = PyUnicode_FromString("rw"); of these three values. */
break; Py_UNREACHABLE();
case O_WRONLY:
rval = PyUnicode_FromString("w");
break;
}
}
else {
rval = PyObject_GenericGetAttr((PyObject *)self, nameobj);
} }
return rval;
} }
static PyGetSetDef oss_getsetlist[] = {
{"closed", (getter)oss_closed_getter, (setter)NULL, NULL},
{"mode", (getter)oss_mode_getter, (setter)NULL, NULL},
{NULL},
};
static PyTypeObject OSSAudioType = { static PyTypeObject OSSAudioType = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
"ossaudiodev.oss_audio_device", /*tp_name*/ "ossaudiodev.oss_audio_device", /*tp_name*/
...@@ -979,7 +976,7 @@ static PyTypeObject OSSAudioType = { ...@@ -979,7 +976,7 @@ static PyTypeObject OSSAudioType = {
0, /*tp_hash*/ 0, /*tp_hash*/
0, /*tp_call*/ 0, /*tp_call*/
0, /*tp_str*/ 0, /*tp_str*/
(getattrofunc)oss_getattro, /*tp_getattro*/ 0, /*tp_getattro*/
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/
...@@ -991,6 +988,8 @@ static PyTypeObject OSSAudioType = { ...@@ -991,6 +988,8 @@ static PyTypeObject OSSAudioType = {
0, /*tp_iter*/ 0, /*tp_iter*/
0, /*tp_iternext*/ 0, /*tp_iternext*/
oss_methods, /*tp_methods*/ oss_methods, /*tp_methods*/
oss_members, /*tp_members*/
oss_getsetlist, /*tp_getset*/
}; };
static PyTypeObject OSSMixerType = { static PyTypeObject OSSMixerType = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment