@@ -921,46 +921,43 @@ static PyMethodDef oss_mixer_methods[] = {
921921 { NULL , NULL }
922922};
923923
924+ static PyMemberDef oss_members [] = {
925+ {"name" , T_STRING , offsetof(oss_audio_t , devicename ), READONLY , NULL },
926+ {NULL }
927+ };
928+
924929static PyObject *
925- oss_getattro (oss_audio_t * self , PyObject * nameobj )
930+ oss_closed_getter (oss_audio_t * self , void * closure )
926931{
927- const char * name = "" ;
928- PyObject * rval = NULL ;
929-
930- if (PyUnicode_Check (nameobj )) {
931- name = PyUnicode_AsUTF8 (nameobj );
932- if (name == NULL )
933- return NULL ;
934- }
932+ return PyBool_FromLong (self -> fd == -1 );
933+ }
935934
936- if (strcmp (name , "closed" ) == 0 ) {
937- rval = (self -> fd == -1 ) ? Py_True : Py_False ;
938- Py_INCREF (rval );
939- }
940- else if (strcmp (name , "name" ) == 0 ) {
941- rval = PyUnicode_FromString (self -> devicename );
942- }
943- else if (strcmp (name , "mode" ) == 0 ) {
944- /* No need for a "default" in this switch: from newossobject(),
945- self->mode can only be one of these three values. */
946- switch (self -> mode ) {
947- case O_RDONLY :
948- rval = PyUnicode_FromString ("r" );
949- break ;
950- case O_RDWR :
951- rval = PyUnicode_FromString ("rw" );
952- break ;
953- case O_WRONLY :
954- rval = PyUnicode_FromString ("w" );
955- break ;
956- }
957- }
958- else {
959- rval = PyObject_GenericGetAttr ((PyObject * )self , nameobj );
935+ static PyObject *
936+ oss_mode_getter (oss_audio_t * self , void * closure )
937+ {
938+ switch (self -> mode ) {
939+ case O_RDONLY :
940+ return PyUnicode_FromString ("r" );
941+ break ;
942+ case O_RDWR :
943+ return PyUnicode_FromString ("rw" );
944+ break ;
945+ case O_WRONLY :
946+ return PyUnicode_FromString ("w" );
947+ break ;
948+ default :
949+ /* From newossobject(), self->mode can only be one
950+ of these three values. */
951+ Py_UNREACHABLE ();
960952 }
961- return rval ;
962953}
963954
955+ static PyGetSetDef oss_getsetlist [] = {
956+ {"closed" , (getter )oss_closed_getter , (setter )NULL , NULL },
957+ {"mode" , (getter )oss_mode_getter , (setter )NULL , NULL },
958+ {NULL },
959+ };
960+
964961static PyTypeObject OSSAudioType = {
965962 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
966963 "ossaudiodev.oss_audio_device" , /*tp_name*/
@@ -979,7 +976,7 @@ static PyTypeObject OSSAudioType = {
979976 0 , /*tp_hash*/
980977 0 , /*tp_call*/
981978 0 , /*tp_str*/
982- ( getattrofunc ) oss_getattro , /*tp_getattro*/
979+ 0 , /*tp_getattro*/
983980 0 , /*tp_setattro*/
984981 0 , /*tp_as_buffer*/
985982 Py_TPFLAGS_DEFAULT , /*tp_flags*/
@@ -991,6 +988,8 @@ static PyTypeObject OSSAudioType = {
991988 0 , /*tp_iter*/
992989 0 , /*tp_iternext*/
993990 oss_methods , /*tp_methods*/
991+ oss_members , /*tp_members*/
992+ oss_getsetlist , /*tp_getset*/
994993};
995994
996995static PyTypeObject OSSMixerType = {
0 commit comments