2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-25 03:11:06 +01:00

filesystem: set malloc like attribute for imported zone memory allocator functions

This commit is contained in:
Alibek Omarov 2024-09-30 01:23:16 +03:00
parent 1b335fd945
commit 2e5bc31c9e
2 changed files with 47 additions and 36 deletions

View File

@ -125,6 +125,16 @@ static void FS_BackupFileName( file_t *file, const char *path, uint options ) {}
static void FS_InitMemory( void );
static void FS_Purge( file_t* file );
void _Mem_Free( void *data, const char *filename, int fileline )
{
g_engfuncs._Mem_Free( data, filename, fileline );
}
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
{
return g_engfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline );
}
/*
=============================================================================
@ -1412,34 +1422,34 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll
return true;
}
static poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline )
static poolhandle_t Mem_AllocPoolStub( const char *name, const char *filename, int fileline )
{
return (poolhandle_t)0xDEADC0DE;
}
static void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline )
static void Mem_FreePoolStub( poolhandle_t *poolptr, const char *filename, int fileline )
{
// stub
}
static void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
static void *Mem_AllocStub( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
{
void *ptr = malloc( size );
if( clear ) memset( ptr, 0, size );
return ptr;
}
static void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
static void *Mem_ReallocStub( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
{
return realloc( memptr, size );
}
static void _Mem_Free( void *data, const char *filename, int fileline )
static void Mem_FreeStub( void *data, const char *filename, int fileline )
{
free( data );
}
static void _Con_Printf( const char *fmt, ... )
static void Con_PrintfStub( const char *fmt, ... )
{
va_list ap;
@ -1448,7 +1458,7 @@ static void _Con_Printf( const char *fmt, ... )
va_end( ap );
}
static void _Sys_Error( const char *fmt, ... )
static void Sys_ErrorStub( const char *fmt, ... )
{
va_list ap;
@ -1459,7 +1469,7 @@ static void _Sys_Error( const char *fmt, ... )
exit( 1 );
}
static void *Sys_GetNativeObject_stub( const char *object )
static void *Sys_GetNativeObjectStub( const char *object )
{
return NULL;
}
@ -2524,7 +2534,7 @@ byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean ga
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
{
return FS_LoadFile_( path, filesizeptr, gamedironly, g_engfuncs._Mem_Alloc != _Mem_Alloc );
return FS_LoadFile_( path, filesizeptr, gamedironly, true );
}
qboolean CRC32_File( dword *crcvalue, const char *filename )
@ -2936,14 +2946,6 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
return search;
}
static const char *FS_ArchivePath( file_t *f )
{
if( f->searchpath )
return f->searchpath->filename;
return "plain";
}
static qboolean FS_IsArchiveExtensionSupported( const char *ext, uint flags )
{
int i;
@ -2971,16 +2973,16 @@ void FS_InitMemory( void )
fs_interface_t g_engfuncs =
{
_Con_Printf,
_Con_Printf,
_Con_Printf,
_Sys_Error,
_Mem_AllocPool,
_Mem_FreePool,
_Mem_Alloc,
_Mem_Realloc,
_Mem_Free,
Sys_GetNativeObject_stub
Con_PrintfStub,
Con_PrintfStub,
Con_PrintfStub,
Sys_ErrorStub,
Mem_AllocPoolStub,
Mem_FreePoolStub,
Mem_AllocStub,
Mem_ReallocStub,
Mem_FreeStub,
Sys_GetNativeObjectStub,
};
static qboolean FS_InitInterface( int version, const fs_interface_t *engfuncs )

View File

@ -19,6 +19,7 @@ GNU General Public License for more details.
#ifndef FILESYSTEM_INTERNAL_H
#define FILESYSTEM_INTERNAL_H
#include <stdlib.h>
#include "xash3d_types.h"
#include "filesystem.h"
@ -129,10 +130,10 @@ extern const fs_archive_t g_archives[];
#define GI FI.GameInfo
#define Mem_Malloc( pool, size ) g_engfuncs._Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
#define Mem_Calloc( pool, size ) g_engfuncs._Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
#define Mem_Realloc( pool, ptr, size ) g_engfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
#define Mem_Free( mem ) g_engfuncs._Mem_Free( mem, __FILE__, __LINE__ )
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
#define Mem_AllocPool( name ) g_engfuncs._Mem_AllocPool( name, __FILE__, __LINE__ )
#define Mem_FreePool( pool ) g_engfuncs._Mem_FreePool( pool, __FILE__, __LINE__ )
@ -148,6 +149,9 @@ extern const fs_archive_t g_archives[];
qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char *basedir, const char *gamedir, const char *rodir );
void FS_ShutdownStdio( void );
searchpath_t *FS_AddArchive_Fullpath( const fs_archive_t *archive, const char *file, int flags );
void _Mem_Free( void *data, const char *filename, int fileline );
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
// search path utils
void FS_Rescan( void );
@ -155,7 +159,8 @@ void FS_ClearSearchPath( void );
void FS_AllowDirectPaths( qboolean enable );
void FS_AddGameDirectory( const char *dir, uint flags );
void FS_AddGameHierarchy( const char *dir, uint flags );
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly );
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
int FS_SetCurrentDirectory( const char *path );
void FS_Path_f( void );
@ -163,14 +168,15 @@ void FS_Path_f( void );
void FS_LoadGameInfo( const char *rootfolder );
// file ops
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly );
int FS_Close( file_t *file );
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly )
MALLOC_LIKE( FS_Close, 1 ) WARN_UNUSED_RESULT;
fs_offset_t FS_Write( file_t *file, const void *data, size_t datasize );
fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize );
int FS_Seek( file_t *file, fs_offset_t offset, int whence );
fs_offset_t FS_Tell( file_t *file );
qboolean FS_Eof( file_t *file );
int FS_Flush( file_t *file );
int FS_Close( file_t *file );
int FS_Gets( file_t *file, char *string, size_t bufsize );
int FS_UnGetc( file_t *file, char c );
int FS_Getc( file_t *file );
@ -181,9 +187,12 @@ fs_offset_t FS_FileLength( file_t *f );
qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize );
// file buffer ops
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly );
byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly );
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr );
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
MALLOC_LIKE( free, 1 ) WARN_UNUSED_RESULT;
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len );
// file hashing