multiple mikmod player fixes from default (2.0) branch SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 06 Oct 2018 23:20:10 +0300
branchSDL-1.2
changeset 8653ffb22a2755b
parent 864 c8dc1ec196f5
child 866 9b5e07988c0f
multiple mikmod player fixes from default (2.0) branch
CHANGES
dynamic_mod.c
dynamic_mod.h
music_mod.c
     1.1 --- a/CHANGES	Sat Oct 06 22:41:10 2018 +0300
     1.2 +++ b/CHANGES	Sat Oct 06 23:20:10 2018 +0300
     1.3 @@ -1,3 +1,7 @@
     1.4 +1.2.13:
     1.5 +Paul P Komkoff Jr - Sun Jul 22 16:12:28 PDT 2012
     1.6 + * Fixed malloc/free mismatch in the MikMod driver
     1.7 +
     1.8  1.2.12:
     1.9  Sam Lantinga - Sat Jan 14 22:00:29 2012 -0500
    1.10   * Fixed seek offset with SMPEG (was relative, should be absolute)
     2.1 --- a/dynamic_mod.c	Sat Oct 06 22:41:10 2018 +0300
     2.2 +++ b/dynamic_mod.c	Sat Oct 06 23:20:10 2018 +0300
     2.3 @@ -59,7 +59,7 @@
     2.4  			return -1;
     2.5  		}
     2.6  		mikmod.MikMod_Init =
     2.7 -			(BOOL (*)(CHAR*))
     2.8 +			(int (*)(MIKMOD3_CONST CHAR*))
     2.9  			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
    2.10  		if ( mikmod.MikMod_Init == NULL ) {
    2.11  			SDL_UnloadObject(mikmod.handle);
    2.12 @@ -87,12 +87,19 @@
    2.13  			return -1;
    2.14  		}
    2.15  		mikmod.MikMod_strerror =
    2.16 -			(char* (*)(int))
    2.17 +			(MIKMOD3_CONST char* (*)(int))
    2.18  			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
    2.19  		if ( mikmod.MikMod_strerror == NULL ) {
    2.20  			SDL_UnloadObject(mikmod.handle);
    2.21  			return -1;
    2.22  		}
    2.23 +		mikmod.MikMod_free =
    2.24 +			(void (*)(void*))
    2.25 +			SDL_LoadFunction(mikmod.handle, "MikMod_free");
    2.26 +		if ( mikmod.MikMod_free == NULL ) {
    2.27 +			/* libmikmod 3.1 and earlier doesn't have it */
    2.28 +			mikmod.MikMod_free = free;
    2.29 +		}
    2.30  		mikmod.Player_Active =
    2.31  			(BOOL (*)(void))
    2.32  			SDL_LoadFunction(mikmod.handle, "Player_Active");
    2.33 @@ -239,6 +246,12 @@
    2.34  		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
    2.35  		mikmod.MikMod_errno = &MikMod_errno;
    2.36  		mikmod.MikMod_strerror = MikMod_strerror;
    2.37 +#if (LIBMIKMOD_VERSION < 0x030200) || !defined(DMODE_NOISEREDUCTION)
    2.38 +		/* libmikmod 3.2.0-beta2 or older */
    2.39 +		mikmod.MikMod_free = free;
    2.40 +#else
    2.41 +		mikmod.MikMod_free = MikMod_free;
    2.42 +#endif
    2.43  		mikmod.Player_Active = Player_Active;
    2.44  		mikmod.Player_Free = Player_Free;
    2.45  		mikmod.Player_LoadGeneric = Player_LoadGeneric;
     3.1 --- a/dynamic_mod.h	Sat Oct 06 22:41:10 2018 +0300
     3.2 +++ b/dynamic_mod.h	Sat Oct 06 23:20:10 2018 +0300
     3.3 @@ -23,6 +23,13 @@
     3.4  
     3.5  #include "mikmod.h"
     3.6  
     3.7 +/* libmikmod >= 3.3.2 constified several funcs */
     3.8 +#if (LIBMIKMOD_VERSION < 0x030302)
     3.9 +#define MIKMOD3_CONST
    3.10 +#else
    3.11 +#define MIKMOD3_CONST const
    3.12 +#endif
    3.13 +
    3.14  typedef struct {
    3.15  	int loaded;
    3.16  	void *handle;
    3.17 @@ -30,11 +37,12 @@
    3.18  	void (*MikMod_Exit)(void);
    3.19  	CHAR* (*MikMod_InfoDriver)(void);
    3.20  	CHAR* (*MikMod_InfoLoader)(void);
    3.21 -	BOOL (*MikMod_Init)(CHAR*);
    3.22 +	int (*MikMod_Init)(MIKMOD3_CONST CHAR*);
    3.23  	void (*MikMod_RegisterAllLoaders)(void);
    3.24  	void (*MikMod_RegisterDriver)(struct MDRIVER*);
    3.25  	int* MikMod_errno;
    3.26 -	char* (*MikMod_strerror)(int);
    3.27 +	MIKMOD3_CONST char* (*MikMod_strerror)(int);
    3.28 +	void (*MikMod_free)(void*);
    3.29  	BOOL (*Player_Active)(void);
    3.30  	void (*Player_Free)(MODULE*);
    3.31  	MODULE* (*Player_LoadGeneric)(MREADER*,int,BOOL);
     4.1 --- a/music_mod.c	Sat Oct 06 22:41:10 2018 +0300
     4.2 +++ b/music_mod.c	Sat Oct 06 23:20:10 2018 +0300
     4.3 @@ -109,13 +109,13 @@
     4.4  
     4.5  	list = mikmod.MikMod_InfoDriver();
     4.6  	if ( list )
     4.7 -	  free(list);
     4.8 +	  mikmod.MikMod_free(list);
     4.9  	else
    4.10  	  mikmod.MikMod_RegisterDriver(mikmod.drv_nos);
    4.11  
    4.12  	list = mikmod.MikMod_InfoLoader();
    4.13  	if ( list )
    4.14 -	  free(list);
    4.15 +	  mikmod.MikMod_free(list);
    4.16  	else
    4.17  	  mikmod.MikMod_RegisterAllLoaders();
    4.18  
    4.19 @@ -144,18 +144,25 @@
    4.20  typedef struct
    4.21  {
    4.22  	MREADER mr;
    4.23 +	/* struct MREADER in libmikmod <= 3.2.0-beta2
    4.24 +	 * doesn't have iobase members. adding them here
    4.25 +	 * so that if we compile against 3.2.0-beta2, we
    4.26 +	 * can still run OK against 3.2.0b3 and newer. */
    4.27 +	long iobase, prev_iobase;
    4.28  	long offset;
    4.29  	long eof;
    4.30  	SDL_RWops *rw;
    4.31  } LMM_MREADER;
    4.32  
    4.33 -BOOL LMM_Seek(struct MREADER *mr,long to,int dir)
    4.34 +int LMM_Seek(struct MREADER *mr,long to,int dir)
    4.35  {
    4.36  	LMM_MREADER* lmmmr = (LMM_MREADER*)mr;
    4.37  	if ( dir == SEEK_SET ) {
    4.38  		to += lmmmr->offset;
    4.39 +		if (to < lmmmr->offset)
    4.40 +			return -1;
    4.41  	}
    4.42 -	return (SDL_RWseek(lmmmr->rw, to, dir) < lmmmr->offset);
    4.43 +	return (SDL_RWseek(lmmmr->rw, to, dir) < lmmmr->offset)? -1 : 0;
    4.44  }
    4.45  long LMM_Tell(struct MREADER *mr)
    4.46  {