Issues with SDL_mixer interface

75 views
Skip to first unread message

d4v3y_5c0n3s

unread,
Apr 28, 2020, 6:59:40 AM4/28/20
to ats-lang-users
     Ever since my previous question, I've been running into two issues with my SDL_mixer bindings.  The first, is that I get a warning message whenever I use the function Mix_GetError() (the definition for this function may be found here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/SDL2/SDL_mixer.sats).  The warning is as follows:
g_audio_dats.c: In function 'audio_sound_play':
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:35: warning: assignment discards 'const' qualifier fr
om pointer target type [-Wdiscarded-qualifiers]
#define ATSINSmove(tmp, val) (tmp = val)
While this is only a warning, I would still like to know what is going wrong here.  I looked at ATS-contrib's SDL binding, and found that the SDL_GetError() function there had the exact same problem.  (The file for this function definition may be found here: https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/SDL2/SATS/SDL_error.sats)

     The second issue that I'm running into has to do with my Mix_FadeInMusic() function (which is defined here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/SDL2/SDL_mixer.sats).  When I use this function, I get the following error message:
g_audio_dats.c: In function 'audio_music_play':
g_audio_dats.c:931:11: error: storage size of 'tmpref41' isn't known
ATStmpdec(tmpref41, Mix_Music) ;
          ^~~~~~~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:209:33: note: in definition of macro 'ATStmpdec'
#define ATStmpdec(tmp, hit) hit tmp
                                ^~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:217:29: error: dereferencing pointer to incomplete type '
Mix_Music' {aka 'struct _Mix_Music'}
#define ATSderef(pmv, hit) (*(hit*)pmv)

     The file where I've been receiving these errors is available here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/g_audio.dats.  My full source code is available on Github here: https://github.com/d4v3y5c0n3s/Goldelish-Engine.

     Any help is appreciated, and if you'd like me to provide any more information, please ask for it.  Also, if anyone knows of a great resource for understanding how the internals of ATS work, please let me know.  I have a feeling that if I better understood how ATS worked, I would also better understand what to do when I encounter error messages such as these.

Hongwei Xi

unread,
Apr 28, 2020, 2:15:56 PM4/28/20
to ats-lan...@googlegroups.com
Hi,

Here is what I spotted:

fun Mix_FadeInMusic {l:addr} ( music: Mix_Music, loops: int, ms: int ) : int = "mac#Mix_FadeInMusic"

should probably be declared as follows:

fun Mix_FadeInMusic ( music: &Mix_Music, loops: int, ms: int ) : int = "mac#Mix_FadeInMusic"

because Mix_Music is a struct in C.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/e3db4fac-0969-406f-aaa5-02b3b2145a84%40googlegroups.com.

Hongwei Xi

unread,
Apr 28, 2020, 2:26:04 PM4/28/20
to ats-lan...@googlegroups.com
>>Ever since my previous question, I've been running into two issues with my SDL_mixer bindings.  The first, is that I get a warning message whenever I use the function Mix_GetError() (the definition for this function may be found here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/SDL2/SDL_mixer.sats).  The warning is as follows:
g_audio_dats.c: In function 'audio_sound_play':
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:35: warning: assignment discards 'const' qualifier fr
om pointer target type [-Wdiscarded-qualifiers]
#define ATSINSmove(tmp, val) (tmp = val)
While this is only a warning, I would still like to know what is going wrong here.  I looked at ATS-contrib's SDL binding, and found that the SDL_GetError() function there had the exact same problem.  (The file for this function definition may be found here: https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/SDL2/SATS/SDL_error.sats)

Here is my guess:

Mx_GetError() returns a const string; but it is assigned to a variable (tmp) which is not declared to be a const.

I did the following:

#define atscntrb_SDL2_SDL_GetError SDL_GetError

which should probably be changed to the following:

#define atscntrb_SDL2_SDL_GetError() ((char*)(SDL_GetError()))

so as to suppress warnings like the one you encountered.

--Hongwei





On Tue, Apr 28, 2020 at 6:59 AM d4v3y_5c0n3s <tmj...@gmail.com> wrote:
--

d4v3y_5c0n3s

unread,
Apr 29, 2020, 7:31:27 AM4/29/20
to ats-lang-users
     So, I made the changes which you suggested, but unfortunately, this didn't resolve the issues.  First, I tried modifying the macro for Mix_GetError() in the SDL_mixer.cats file to what you suggested, but this didn't seem to change the error message.  Perhaps I missed something, because I don't have a solid understanding of more complex C macros.  My changes can be seen here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/SDL2/SDL_local.cats

     Next, I tried modifying the function definition for Mix_FadeInMusic() in SDL_mixer.sats to match your suggested modifacation, but this didn't fix the issue.  Your suggestion is actually how I had previously written the function, but I had changed it while experimenting to find the cause of the issue I was encountering.  When I pushed my changes to Github, I forgot to revert that function to what it had been previously.  My changes can be seen here: https://github.com/d4v3y5c0n3s/Goldelish-Engine/blob/master/source/SDL2/SDL_mixer.sats

I appreciate the help, so thank you.

Here are the errors which I am currently getting after incorporating the changes you suggested:
In file included from g_audio_dats.c:15:
g_audio_dats.c: In function 'audio_sound_play':
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:35: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 #define ATSINSmove(tmp, val) (tmp = val)
                                   ^
g_audio_dats.c:753:1: note: in expansion of macro 'ATSINSmove'
 ATSINSmove(tmp36, Mix_GetError()) ;
 ^~~~~~~~~~
g_audio_dats.c: In function 'audio_music_play':
g_audio_dats.c:931:11: error: storage size of 'tmpref41' isn't known
 ATStmpdec(tmpref41, Mix_Music) ;
           ^~~~~~~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:209:33: note: in definition of macro 'ATStmpdec'
 #define ATStmpdec(tmp, hit) hit tmp
                                 ^~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:217:29: error: dereferencing pointer to incomplete type 'Mix_Music' {aka 'struct _Mix_Music'}
 #define ATSderef(pmv, hit) (*(hit*)pmv)
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:37: note: in definition of macro 'ATSINSmove'
 #define ATSINSmove(tmp, val) (tmp = val)
                                     ^~~
g_audio_dats.c:960:22: note: in expansion of macro 'ATSSELrecsin'
 ATSINSmove(tmpref41, ATSSELrecsin(ATSderef(arg0, Mix_Music), Mix_Music, atslab__handle)) ;
                      ^~~~~~~~~~~~
g_audio_dats.c:960:35: note: in expansion of macro 'ATSderef'
 ATSINSmove(tmpref41, ATSSELrecsin(ATSderef(arg0, Mix_Music), Mix_Music, atslab__handle)) ;
                                   ^~~~~~~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:35: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 #define ATSINSmove(tmp, val) (tmp = val)
                                   ^
g_audio_dats.c:999:1: note: in expansion of macro 'ATSINSmove'
 ATSINSmove(tmp50, Mix_GetError()) ;
 ^~~~~~~~~~
make: *** [Makefile:63: obj/g_audio_dats.o] Error 1
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lan...@googlegroups.com.

d4v3y_5c0n3s

unread,
Apr 29, 2020, 5:54:42 PM4/29/20
to ats-lang-users
Actually, I think I've figured out (at least partially) what's wrong with my code.  I will post my results once I get the opportunity to test my theory out.

d4v3y_5c0n3s

unread,
Apr 29, 2020, 8:39:26 PM4/29/20
to ats-lang-users
Yea, so, the reason that the suggestion you had for Mix_GetError() wasn't working for me was that in the function definition I put "... = "mac#Mix_GetError"" at the end which was causing the macro to not apply to the function.  To fix this, I changed it to "... = "mac#%"", which caused it to work without a hitch.  I will see if the same issue is partially behind the issue I am having with Mix_FadeInMusic().

d4v3y_5c0n3s

unread,
Apr 29, 2020, 9:28:01 PM4/29/20
to ats-lang-users
Okay, so Mix_FadeInMusic() is still producing errors.  I will update my Github repo shortly, and here are the current error messages that I am receiving:
g_audio_dats.c: In function 'audio_music_play':
g_audio_dats.c:931:11: error: storage size of 'tmpref41' isn't known
 ATStmpdec(tmpref41, Mix_Music) ;
           ^~~~~~~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:209:33: note: in definition of macro 'ATStmpdec'
 #define ATStmpdec(tmp, hit) hit tmp
                                 ^~~
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:217:29: error: dereferencing pointer to incomplete type 'Mix_Music' {aka 'struct _Mix_Music'}
 #define ATSderef(pmv, hit) (*(hit*)pmv)
/home/d4v3y/ATS2-Postiats-0.4.0/ccomp/runtime/pats_ccomp_instrset.h:276:37: note: in definition of macro 'ATSINSmove'
 #define ATSINSmove(tmp, val) (tmp = val)
                                     ^~~
g_audio_dats.c:960:22: note: in expansion of macro 'ATSSELrecsin'
 ATSINSmove(tmpref41, ATSSELrecsin(ATSderef(arg0, Mix_Music), Mix_Music, atslab__handle)) ;
                      ^~~~~~~~~~~~
g_audio_dats.c:960:35: note: in expansion of macro 'ATSderef'
 ATSINSmove(tmpref41, ATSSELrecsin(ATSderef(arg0, Mix_Music), Mix_Music, atslab__handle)) ;
                                   ^~~~~~~~
make: *** [Makefile:63: obj/g_audio_dats.o] Error 1

Thank you for your help, and I will continue to investigate this issue.

Chris Double

unread,
Apr 29, 2020, 11:59:21 PM4/29/20
to ats-lan...@googlegroups.com
On Thu, Apr 30, 2020 at 1:28 PM d4v3y_5c0n3s <tmj...@gmail.com> wrote:
>
> Okay, so Mix_FadeInMusic() is still producing errors. I will update my Github repo shortly, and here are the current error messages that I am receiving:

I believe this problem is because 'Mix_Music' is declared as a
"$extype" which represents the flat structure, so the "handle" field
of 'music' is a structure not a pointer. Then Creating a "var:
Mix_Music = m.handle" is trying to assign that flat structure to a
pointer. Or something like that. An easy fix (I think) is to make
"Mix_Music" a pointer, and change functions that use it to take it
directly rather than via reference:

typedef Mix_Music = ptr
fun Mix_FadeInMusic ( music: Mix_Music, loops: int, ms: int ) : int = "mac#%"

implement audio_music_play ( m ) = let
val chan = Mix_FadeInMusic(m.handle, ~1, fade_time);
in
if (chan = ~1) then println!("unable to play music: ", Mix_GetError())
end

--
https://bluishcoder.co.nz

d4v3y_5c0n3s

unread,
Apr 30, 2020, 7:37:28 AM4/30/20
to ats-lang-users
Thanks so much, this fixed the issue!
Reply all
Reply to author
Forward
0 new messages