1919 *
2020 */
2121
22- #include "Python.h"
23- #include "structmember.h"
24- #include "frameobject.h"
25- #ifndef PY_LONG_LONG
26- #define PY_LONG_LONG LONG_LONG
27- #endif
22+ #include "common.h"
2823#include "stdlib.h"
2924#include "alsa/asoundlib.h"
3025
31- #ifndef Py_RETURN_NONE
32- #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
33- #endif
34- #ifndef Py_RETURN_TRUE
35- #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
36- #endif
37- #ifndef Py_RETURN_FALSE
38- #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
39- #endif
26+ /*
27+ *
28+ */
4029
4130static PyObject * module ;
4231#if 0
@@ -47,25 +36,14 @@ static PyObject *buildin;
4736 *
4837 */
4938
50- #define PYCTL (v ) (((v) == Py_None) ? NULL : \
51- ((struct pyalsacontrol *)(v)))
39+ #define PYCTL (v ) \
40+ (((v) == Py_None) ? NULL : (( struct pyalsacontrol *)(v)))
5241
5342struct pyalsacontrol {
5443 PyObject_HEAD
5544 snd_ctl_t * handle ;
5645};
5746
58- static inline PyObject * get_bool (int val )
59- {
60- if (val ) {
61- Py_INCREF (Py_True );
62- return Py_True ;
63- } else {
64- Py_INCREF (Py_False );
65- return Py_False ;
66- }
67- }
68-
6947PyDoc_STRVAR (cardinfo__doc__ ,
7048"card_info() -- Return a dictionary with card specific information." );
7149
@@ -84,13 +62,13 @@ pyalsacontrol_cardinfo(struct pyalsacontrol *self, PyObject *args)
8462 }
8563 d = PyDict_New ();
8664 if (d ) {
87- PyDict_SetItem (d , PyString_FromString ("card" ), PyInt_FromLong (snd_ctl_card_info_get_card (info )));
88- PyDict_SetItem (d , PyString_FromString ("id" ), PyString_FromString (snd_ctl_card_info_get_id (info )));
89- PyDict_SetItem (d , PyString_FromString ("driver" ), PyString_FromString (snd_ctl_card_info_get_driver (info )));
90- PyDict_SetItem (d , PyString_FromString ("name" ), PyString_FromString (snd_ctl_card_info_get_driver (info )));
91- PyDict_SetItem (d , PyString_FromString ("longname" ), PyString_FromString (snd_ctl_card_info_get_longname (info )));
92- PyDict_SetItem (d , PyString_FromString ("mixername" ), PyString_FromString (snd_ctl_card_info_get_mixername (info )));
93- PyDict_SetItem (d , PyString_FromString ("components" ), PyString_FromString (snd_ctl_card_info_get_components (info )));
65+ PyDict_SetItem (d , PyUnicode_FromString ("card" ), PyInt_FromLong (snd_ctl_card_info_get_card (info )));
66+ PyDict_SetItem (d , PyUnicode_FromString ("id" ), PyUnicode_FromString (snd_ctl_card_info_get_id (info )));
67+ PyDict_SetItem (d , PyUnicode_FromString ("driver" ), PyUnicode_FromString (snd_ctl_card_info_get_driver (info )));
68+ PyDict_SetItem (d , PyUnicode_FromString ("name" ), PyUnicode_FromString (snd_ctl_card_info_get_driver (info )));
69+ PyDict_SetItem (d , PyUnicode_FromString ("longname" ), PyUnicode_FromString (snd_ctl_card_info_get_longname (info )));
70+ PyDict_SetItem (d , PyUnicode_FromString ("mixername" ), PyUnicode_FromString (snd_ctl_card_info_get_mixername (info )));
71+ PyDict_SetItem (d , PyUnicode_FromString ("components" ), PyUnicode_FromString (snd_ctl_card_info_get_components (info )));
9472 }
9573 return d ;
9674}
@@ -180,8 +158,6 @@ pyalsacontrol_dealloc(struct pyalsacontrol *self)
180158{
181159 if (self -> handle != NULL )
182160 snd_ctl_close (self -> handle );
183-
184- self -> ob_type -> tp_free (self );
185161}
186162
187163static PyGetSetDef pyalsacontrol_getseters [] = {
@@ -199,7 +175,7 @@ static PyMethodDef pyalsacontrol_methods[] = {
199175};
200176
201177static PyTypeObject pyalsacontrol_type = {
202- PyObject_HEAD_INIT ( 0 )
178+ PyVarObject_HEAD_INIT ( NULL , 0 )
203179 tp_name : "alsacontrol.Control" ,
204180 tp_basicsize : sizeof (struct pyalsacontrol ),
205181 tp_dealloc : (destructor )pyalsacontrol_dealloc ,
@@ -221,25 +197,26 @@ static PyMethodDef pyalsacontrolparse_methods[] = {
221197 {NULL }
222198};
223199
224- PyMODINIT_FUNC
225- initalsacontrol (void )
200+ MOD_INIT (alsacontrol )
226201{
227202 PyObject * d , * d1 , * l1 , * o ;
228203 int i ;
229204
205+ pyalsacontrol_type .tp_free = PyObject_GC_Del ;
206+
230207 if (PyType_Ready (& pyalsacontrol_type ) < 0 )
231- return ;
208+ return MOD_ERROR_VAL ;
232209
233- module = Py_InitModule3 ( "alsacontrol" , pyalsacontrolparse_methods , "libasound control wrapper" );
210+ MOD_DEF ( module , "alsacontrol" , "libasound control wrapper" , pyalsacontrolparse_methods );
234211 if (module == NULL )
235- return ;
212+ return MOD_ERROR_VAL ;
236213
237214#if 0
238215 buildin = PyImport_AddModule ("__buildin__" );
239216 if (buildin == NULL )
240- return ;
217+ return MOD_ERROR_VAL ;
241218 if (PyObject_SetAttrString (module , "__buildins__" , buildin ) < 0 )
242- return ;
219+ return MOD_ERROR_VAL ;
243220#endif
244221
245222 Py_INCREF (& pyalsacontrol_type );
@@ -273,7 +250,7 @@ initalsacontrol(void)
273250 l1 = PyList_New (0 );
274251
275252 for (i = 0 ; i <= SND_CTL_ELEM_IFACE_LAST ; i ++ ) {
276- o = PyString_FromString (snd_ctl_elem_iface_name (i ));
253+ o = PyUnicode_FromString (snd_ctl_elem_iface_name (i ));
277254 PyList_Append (l1 , o );
278255 Py_DECREF (o );
279256 }
@@ -301,4 +278,6 @@ initalsacontrol(void)
301278
302279 if (PyErr_Occurred ())
303280 Py_FatalError ("Cannot initialize module alsacontrol" );
281+
282+ return MOD_SUCCESS_VAL (module );
304283}
0 commit comments