Function pointer issues
Trying to compile modules with GCC 14.2(.1) revealed a potential issue in the way how BCC does function pointer stuff:
The error in openal.mod:
/home/ronny/Downloads/BlitzMax/mod/pub.mod/openal.mod/.bmx/openal.bmx.release.linux.x64.c:702:42: Fehler: Zuweisung an »BBINT (*)(BBBYTE *)« {alias »int (*)(unsigned char *)«} von inkompatiblem Zeigertyp »BBBYTE *« {alias »unsigned char *«} [-Wincompatible-pointer-types]
702 | pub_openal_alcCloseDevice=pub_openal_P((BBString*)&_s1);
|
On Linux this is run:
#include <dlfcn.h>
static void *openAL;
int LoadOpenAL(){
openAL=dlopen( "libopenal.so",RTLD_NOW );
if( !openAL ) openAL=dlopen( "libopenal.so.0",RTLD_NOW );
if( !openAL ) openAL=dlopen( "libopenal.so.0.0.8",RTLD_NOW );
return openAL!=0;
}
void *GetOpenALFunction( const char *fname ){
if( !openAL ) return 0;
return dlsym( openAL,fname );
}
and
Extern
Function LoadOpenAL()
Function GetOpenALFunction:Byte Ptr( fname$z )
End Extern
Function P:Byte Ptr(t:String)
Return GetOpenALFunction( t )
End Function
Global alcOpenDevice:Byte Ptr( devicename$z )=P("alcOpenDevice")
alcOpenDevice is defined as this:
ALCdevice* alcOpenDevice(const ALCchar *devicename);
Hey, The issue is an incorrect cast in the generated code, or more precisely the lack of a cast when assigning the result of this function to variables. The GetOpenALFunction function is returning values as void*. As this function is used to get function pointers so the result should be cast to the correct function pointer type (signature) to remove the 'error/warning'.
when changing the function to return "Int" instead of "Byte Ptr" it still is incorrect (I thought the Byte Ptr is the issue):
// Global alcOpenDevice:int( devicename$z )
// becomes
pub_openal_alcOpenDeviceSimple=(BBINT(* *)(BBBYTE *))(&brl_blitz_NullFunctionError);
which is still .. incorrect - yes?
https://github.com/bmx-ng/bcc/commit/6281ec166c512792a8a1fb9df9523b4c4d358169 and https://github.com/bmx-ng/bcc/commit/093bbe9a4cae1253d09ad4a49bacec92050c4e66
tackled a lof of this issue. It compiles now with the "default" code.
but if you split definition and assignment, it still fails (guess this is the only part left of the issue - so good job already):
Global alcOpenDevice:Byte Ptr( devicename$z )
alcOpenDevice=P("alcOpenDevice")
leads to:
/BlitzMax/mod/pub.mod/openal.mod/.bmx/openal.bmx.debug.linux.x64.c: In Funktion »__bb_pub_openal_openal«:
/BlitzMax/mod/pub.mod/openal.mod/.bmx/openal.bmx.debug.linux.x64.c:1314:41: Fehler: Zuweisung an »BBBYTE * (*)(BBBYTE *)« {alias »unsigned char * (*)(unsigned char *)«} von inkompatiblem Zeigertyp »BBBYTE *« {alias »unsigned char *«} [-Wincompatible-pointer-types]
1314 | pub_openal_alcOpenDevice=pub_openal_P((BBString*)&_s0);
|
Code is there:
// 2 line assignment
pub_openal__ok=LoadOpenAL();
pub_openal_alcOpenDevice=(BBBYTE*(*)(BBBYTE *))(BBBYTE*(* )(BBBYTE *))(&brl_blitz_NullFunctionError);
pub_openal_alcOpenDevice=pub_openal_P((BBString*)&_s0);
pub_openal_alcCloseDevice=(BBINT(*)(BBBYTE*))pub_openal_P((BBString*)&_s1);
// single line assignment
pub_openal__ok=LoadOpenAL();
pub_openal_alcOpenDevice=(BBBYTE*(*)(BBBYTE *))pub_openal_P((BBString*)&_s0);
pub_openal_alcCloseDevice=(BBINT(*)(BBBYTE*))pub_openal_P((BBString*)&_s1);
looks like the nullfunction thing is double casted and the assignment then misses the required assignment. Guess Brucey is already aware of it but yeah - better save than sorry (aka better report :D)