@@ -55,7 +55,7 @@ adevice_state_dealloc(PGAudioDeviceStateObject *self)
5555}
5656
5757static PyMemberDef adevice_state_members [] = {
58- {"id" , Py_T_INT , offsetof(PGAudioDeviceStateObject , devid ), Py_READONLY ,
58+ {"id" , Py_T_UINT , offsetof(PGAudioDeviceStateObject , devid ), Py_READONLY ,
5959 NULL },
6060 {NULL } /* Sentinel */
6161};
@@ -127,6 +127,7 @@ pg_audio_get_audio_device_channel_map(PyObject *module, PyObject *arg)
127127 SDL_free (channel_map );
128128 Py_DECREF (item );
129129 Py_DECREF (channel_map_list );
130+ return NULL ;
130131 }
131132 }
132133
@@ -250,6 +251,7 @@ pg_audio_open_audio_device(PyObject *module, PyObject *const *args,
250251 (PGAudioDeviceStateObject * )adevice_state_type -> tp_alloc (
251252 adevice_state_type , 0 );
252253 if (device == NULL ) {
254+ SDL_CloseAudioDevice (logical_id );
253255 return NULL ;
254256 }
255257 device -> devid = logical_id ;
@@ -331,6 +333,11 @@ pg_audio_create_audio_stream(PyObject *module, PyObject *const *args,
331333 PGAudioStreamStateObject * stream_state =
332334 (PGAudioStreamStateObject * )astream_state_type -> tp_alloc (
333335 astream_state_type , 0 );
336+
337+ if (stream_state == NULL ) {
338+ SDL_DestroyAudioStream (stream );
339+ return NULL ;
340+ }
334341 stream_state -> stream = stream ;
335342
336343 return (PyObject * )stream_state ;
@@ -476,19 +483,19 @@ pg_audio_put_audio_stream_data(PyObject *module, PyObject *const *args,
476483 }
477484
478485 void * buf ;
479- int len ;
486+ Py_ssize_t len ;
480487
481- if (PyBytes_AsStringAndSize (bytes , (char * * )& buf , (Py_ssize_t * )& len ) !=
482- 0 ) {
488+ if (PyBytes_AsStringAndSize (bytes , (char * * )& buf , & len ) != 0 ) {
483489 Py_DECREF (bytes );
484490 return NULL ;
485491 }
486492
487- if (!SDL_PutAudioStreamData (stream , buf , len )) {
493+ if (!SDL_PutAudioStreamData (stream , buf , ( int ) len )) {
488494 Py_DECREF (bytes );
489495 return RAISE (pgExc_SDLError , SDL_GetError ());
490496 }
491497
498+ Py_DECREF (bytes );
492499 Py_RETURN_NONE ;
493500}
494501
@@ -762,8 +769,8 @@ pg_audio_get_drivers(PyObject *module, PyObject *_null)
762769 for (int i = 0 ; i < num_drivers ; i ++ ) {
763770 driver = SDL_GetAudioDriver (i );
764771 if (driver == NULL ) {
765- return RAISE (pgExc_SDLError , SDL_GetError ());
766772 Py_DECREF (driver_list );
773+ return RAISE (pgExc_SDLError , SDL_GetError ());
767774 }
768775 item = PyUnicode_FromString (driver );
769776 if (item == NULL ) {
@@ -863,13 +870,13 @@ pg_audio_load_wav(PyObject *module, PyObject *arg)
863870 return RAISE (pgExc_SDLError , SDL_GetError ());
864871 }
865872
866- PyObject * bytes = PyBytes_FromStringAndSize (audio_buf , audio_len );
873+ PyObject * bytes = PyBytes_FromStringAndSize (( char * ) audio_buf , audio_len );
867874 SDL_free (audio_buf );
868875 if (bytes == NULL ) {
869876 return NULL ;
870877 }
871878
872- return Py_BuildValue ("Oiii " , bytes , spec .format , spec .channels , spec .freq );
879+ return Py_BuildValue ("Niii " , bytes , spec .format , spec .channels , spec .freq );
873880}
874881
875882static PyObject *
@@ -882,6 +889,9 @@ pg_audio_get_default_playback_device_state(PyObject *module, PyObject *_null)
882889 PGAudioDeviceStateObject * device =
883890 (PGAudioDeviceStateObject * )adevice_state_type -> tp_alloc (
884891 adevice_state_type , 0 );
892+ if (device == NULL ) {
893+ return NULL ;
894+ }
885895 device -> devid = SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK ;
886896
887897 return (PyObject * )device ;
@@ -897,6 +907,9 @@ pg_audio_get_default_recording_device_state(PyObject *module, PyObject *_null)
897907 PGAudioDeviceStateObject * device =
898908 (PGAudioDeviceStateObject * )adevice_state_type -> tp_alloc (
899909 adevice_state_type , 0 );
910+ if (device == NULL ) {
911+ return NULL ;
912+ }
900913 device -> devid = SDL_AUDIO_DEVICE_DEFAULT_RECORDING ;
901914
902915 return (PyObject * )device ;
@@ -1028,23 +1041,25 @@ pg_audio_exec(PyObject *module)
10281041 audio_state * state = GET_STATE (module );
10291042 state -> audio_initialized = false;
10301043
1031- PyObject * audio_device_state_type =
1044+ state -> audio_device_state_type =
10321045 PyType_FromModuleAndSpec (module , & adevice_state_spec , NULL );
1033- if (PyModule_AddObjectRef (module , "AudioDeviceState" ,
1034- audio_device_state_type ) < 0 ) {
1046+ if (state -> audio_device_state_type == NULL ) {
1047+ return -1 ;
1048+ }
1049+ if (PyModule_AddType (module ,
1050+ (PyTypeObject * )state -> audio_device_state_type ) < 0 ) {
10351051 return -1 ;
10361052 }
10371053
1038- state -> audio_device_state_type = audio_device_state_type ;
1039-
1040- PyObject * audio_stream_state_type =
1054+ state -> audio_stream_state_type =
10411055 PyType_FromModuleAndSpec (module , & astream_state_spec , NULL );
1042- if (PyModule_AddObjectRef (module , "AudioStreamState" ,
1043- audio_stream_state_type ) < 0 ) {
1056+ if (state -> audio_stream_state_type == NULL ) {
1057+ return -1 ;
1058+ }
1059+ if (PyModule_AddType (module ,
1060+ (PyTypeObject * )state -> audio_stream_state_type ) < 0 ) {
10441061 return -1 ;
10451062 }
1046-
1047- state -> audio_stream_state_type = audio_stream_state_type ;
10481063
10491064 return 0 ;
10501065}
0 commit comments