Skip to content

Commit 2a88c1f

Browse files
committed
Port to musl libc
Closes nillerusr#72 and uses some patches from nillerusr#193 for better portability between UNIXes. Also this patch replaces so many NULLs with 0 or '\0' because musl headers redefines it and anyway it is better practice. Moreover, due to very "cool" code from Valve, some modules comes with disabled fortify which distributes with build-base in Alpine (fortify is something like compile-time checking for memory bounds)
1 parent f2fa241 commit 2a88c1f

File tree

112 files changed

+294
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+294
-314
lines changed

appframework/sdlmgr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class CSDLMgr : public ILauncherMgr
270270

271271
// Get the next N events. The function returns the number of events that were filled into your array.
272272
virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false );
273-
#if defined(LINUX) || defined(PLATFORM_BSD)
273+
#if defined(POSIX) && !defined(OSX)
274274
virtual int PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvent = false );
275275
#endif
276276

@@ -1004,7 +1004,7 @@ int CSDLMgr::GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debug
10041004
return nToWrite;
10051005
}
10061006

1007-
#if defined(LINUX) || defined(PLATFORM_BSD)
1007+
#if defined(POSIX) && !defined(OSX)
10081008

10091009
int CSDLMgr::PeekAndRemoveKeyboardEvents( bool *pbEsc, bool *pbReturn, bool *pbSpace, bool debugEvent )
10101010
{

appframework/wscript

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def build(bld):
4141

4242
includes = [
4343
'.',
44+
'../common',
4445
'../public',
4546
'../public/tier0',
4647
'../public/tier1'

common/freetype/config/ftconfig.h

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#ifdef ANDROID
55
#include <sys/cdefs.h>
6-
#elif defined(OSX) || defined(PLATFORM_BSD)
7-
#include <stdint.h>
86
#else
97
#include <bits/wordsize.h>
108
#endif

common/vgui_surfacelib/FontManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#endif
1313

1414
#include <vgui/VGUI.h>
15-
#include "vgui_surfacelib/FontAmalgam.h"
15+
#include "common/vgui_surfacelib/FontAmalgam.h"
1616
#include "materialsystem/imaterialsystem.h"
1717
#include "filesystem.h"
1818
#include "vguifont.h"

engine/audio/snd_mix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ void CChannelCullList::Initialize( CChannelList &list )
19991999
else
20002000
{
20012001
m_channelInfo[i].m_vol = -1;
2002-
m_channelInfo[i].m_nameHash = NULL; // doesn't matter
2002+
m_channelInfo[i].m_nameHash = 0; // doesn't matter
20032003
}
20042004
}
20052005

engine/bugreporter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
#define BUG_REPOSITORY_URL "\\\\fileserver\\bugs"
111111
#elif defined(OSX)
112112
#define BUG_REPOSITORY_URL "/Volumes/bugs"
113-
#elif defined(LINUX) || defined(PLATFORM_BSD)
113+
#elif defined(POSIX)
114114
#define BUG_REPOSITORY_URL "\\\\fileserver\\bugs"
115115
#else
116116
//#error
@@ -2257,7 +2257,7 @@ void NonFileSystem_CreatePath (const char *path)
22572257
}
22582258
}
22592259

2260-
#if defined(LINUX) || defined(PLATFORM_BSD)
2260+
#if defined(POSIX) && !defined(OSX)
22612261
#define COPYFILE_ALL 0
22622262
#define BSIZE 65535
22632263
int copyfile( const char *local, const char *remote, void *ignored, int ignoredFlags )

engine/disp_interface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ int DispInfo_ComputeIndex( HDISPINFOARRAY hArray, IDispInfo* pInfo )
12981298
{
12991299
CDispArray *pArray = static_cast<CDispArray*>( hArray );
13001300
if( !pArray )
1301-
return NULL;
1301+
return 0;
13021302

13031303
intp iElement = ((intp)pInfo - (intp)(pArray->m_pDispInfos)) / sizeof(CDispInfo);
13041304

engine/disp_mapload.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ CDispInfo::CDispInfo()
801801

802802
m_pMesh = NULL;
803803

804-
m_Tag = NULL;
804+
m_Tag = 0;
805805
m_pDispArray = NULL;
806806

807807
m_FirstDecal = DISP_DECAL_HANDLE_INVALID;

engine/downloadthread.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ static size_t curlHeaderFn( void *ptr, size_t size, size_t nmemb, void *stream)
587587
char *pszValue = NULL;
588588
RequestContext_t *pRC = (RequestContext_t *) stream;
589589

590-
pszHeader[ ( size * nmemb - 1 ) ] = NULL;
590+
pszHeader[ ( size * nmemb - 1 ) ] = '\0';
591591
pszValue = Q_strstr( pszHeader, ":" );
592592
if ( pszValue )
593593
{
594594
// null terminate the header name, and point pszValue at it's value
595-
*pszValue = NULL;
595+
*pszValue = '\0';
596596
pszValue++;
597597
Q_StrTrim( pszValue );
598598
}

engine/saverestore_filesystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CSaveDirectory
7979
pBuffer = NULL;
8080
pCompressedBuffer = NULL;
8181
nSize = 0;
82-
nCompressedSize = NULL;
82+
nCompressedSize = 0;
8383
}
8484

8585

engine/sys_dll.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1578,22 +1578,22 @@ CON_COMMAND( star_memory, "Dump memory stats" )
15781578
{
15791579
// get a current stat of available memory
15801580
// 32 MB is reserved and fixed by OS, so not reporting to allow memory loggers sync
1581-
#ifdef LINUX
1581+
#ifdef PLATFORM_GLIBC
15821582
struct mallinfo memstats = mallinfo( );
15831583
Msg( "sbrk size: %.2f MB, Used: %.2f MB, #mallocs = %d\n",
15841584
memstats.arena / ( 1024.0 * 1024.0), memstats.uordblks / ( 1024.0 * 1024.0 ), memstats.hblks );
15851585
#elif OSX
15861586
struct mstats memstats = mstats( );
15871587
Msg( "Available %.2f MB, Used: %.2f MB, #mallocs = %lu\n",
15881588
memstats.bytes_free / ( 1024.0 * 1024.0), memstats.bytes_used / ( 1024.0 * 1024.0 ), memstats.chunks_used );
1589-
#elif PLATFORM_BSD
1590-
# warning TODO: Implement memory stats (peace of sheet of course)
1591-
#else // Win32
1589+
#elif _WIN32
15921590
MEMORYSTATUS stat;
15931591
GlobalMemoryStatus( &stat );
15941592
Msg( "Available: %.2f MB, Used: %.2f MB, Free: %.2f MB\n",
15951593
stat.dwTotalPhys/( 1024.0f*1024.0f ) - 32.0f,
15961594
( stat.dwTotalPhys - stat.dwAvailPhys )/( 1024.0f*1024.0f ) - 32.0f,
15971595
stat.dwAvailPhys/( 1024.0f*1024.0f ) );
1596+
#else
1597+
# warning TODO: Implement memory stats (peace of sheet of course)
15981598
#endif
15991599
}

engine/sys_dll2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void posix_signal_handler( int i )
279279
#define DO_TRY if ( sigsetjmp( g_mark, 1 ) == 0 )
280280
#define DO_CATCH else
281281

282-
#if defined( OSX ) || defined(PLATFORM_BSD)
282+
#if !defined(PLATFORM_GLIBC)
283283
#define __sighandler_t sig_t
284284
#endif
285285

engine/sys_mainwind.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#elif defined(_X360)
2626
// nothing to include for 360
2727
#elif defined(OSX)
28-
#elif defined(LINUX) || defined(PLATFORM_BSD)
29-
#include "tier0/dynfunction.h"
30-
#elif defined(_WIN32)
28+
#elif defined(POSIX) || defined(_WIN32)
3129
#include "tier0/dynfunction.h"
3230
#else
3331
#error
@@ -833,7 +831,7 @@ LRESULT CGame::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
833831
// return 0 if handled message, 1 if not
834832
return lRet;
835833
}
836-
#elif defined(OSX) || defined(LINUX) || defined(_WIN32) || defined(PLATFORM_BSD)
834+
#elif defined(POSIX) || defined(_WIN32)
837835

838836
#else
839837
#error

game/client/wscript

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def build(bld):
7777
includes += game["includes"]
7878
defines = game["defines"]
7979

80+
defines.append('_FORTIFY_SOURCE=0')
8081
defines.remove('PROTECTED_THINGS_ENABLE')
8182

8283
bld.shlib(

game/server/ai_basenpc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8803,7 +8803,7 @@ void CAI_BaseNPC::DrawDebugGeometryOverlays(void)
88038803
{
88048804
float r,g,b;
88058805
char debugText[255];
8806-
debugText[0] = NULL;
8806+
debugText[0] = '\0';
88078807

88088808
if (npcEnemy == GetEnemy())
88098809
{

game/server/ai_hint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ int CAI_HintManager::FindAllHints( CAI_BaseNPC *pNPC, const Vector &position, co
311311
// If we have no hints, bail
312312
int c = CAI_HintManager::gm_AllHints.Count();
313313
if ( !c )
314-
return NULL;
314+
return 0;
315315

316316
// Remove the nearest flag. It makes now sense with random.
317317
bool hadNearest = hintCriteria.HasFlag( bits_HINT_NODE_NEAREST );

game/server/ai_pathfinder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ AI_Waypoint_t *CAI_Pathfinder::BuildRadialRoute( const Vector &vStartPos, const
15141514
vNextPos.y += flRadius * sin( flCurAngle );
15151515

15161516
// Build a route from the last position to the current one
1517-
pNextRoute = BuildLocalRoute( vLastPos, vNextPos, NULL, NULL, NO_NODE, fRouteBits, goalTolerance);
1517+
pNextRoute = BuildLocalRoute( vLastPos, vNextPos, 0, 0, NO_NODE, fRouteBits, goalTolerance);
15181518

15191519
// If we can't find a route, we failed
15201520
if ( pNextRoute == NULL )
@@ -1547,7 +1547,7 @@ AI_Waypoint_t *CAI_Pathfinder::BuildRadialRoute( const Vector &vStartPos, const
15471547
return NULL;
15481548

15491549
// Append a path to the final position
1550-
pLastRoute = BuildLocalRoute( vLastPos, vGoalPos, NULL, NULL, NO_NODE, bAirRoute ? bits_BUILD_FLY : bits_BUILD_GROUND, goalTolerance );
1550+
pLastRoute = BuildLocalRoute( vLastPos, vGoalPos, 0, 0, NO_NODE, bAirRoute ? bits_BUILD_FLY : bits_BUILD_GROUND, goalTolerance );
15511551
if ( pLastRoute == NULL )
15521552
return NULL;
15531553

game/server/genericactor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void CGenericActor::HandleAnimEvent( animevent_t *pEvent )
9292
//=========================================================
9393
int CGenericActor::GetSoundInterests ( void )
9494
{
95-
return NULL;
95+
return 0;
9696
}
9797

9898
//=========================================================

game/server/genericmonster.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void CGenericNPC::HandleAnimEvent( animevent_t *pEvent )
127127
//=========================================================
128128
int CGenericNPC::GetSoundInterests ( void )
129129
{
130-
return NULL;
130+
return 0;
131131
}
132132

133133
//=========================================================

game/server/hl2/npc_breen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void CNPC_Breen::HandleAnimEvent( animevent_t *pEvent )
6969
//-----------------------------------------------------------------------------
7070
int CNPC_Breen::GetSoundInterests ( void )
7171
{
72-
return NULL;
72+
return 0;
7373
}
7474

7575
//-----------------------------------------------------------------------------

game/server/hl2/npc_eli.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void CNPC_Eli::HandleAnimEvent( animevent_t *pEvent )
7272
//-----------------------------------------------------------------------------
7373
int CNPC_Eli::GetSoundInterests ( void )
7474
{
75-
return NULL;
75+
return 0;
7676
}
7777

7878
//-----------------------------------------------------------------------------

game/server/hl2/npc_gman.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void CNPC_GMan::HandleAnimEvent( animevent_t *pEvent )
8484
//-----------------------------------------------------------------------------
8585
int CNPC_GMan::GetSoundInterests ( void )
8686
{
87-
return NULL;
87+
return 0;
8888
}
8989

9090

game/server/hl2/npc_kleiner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void CNPC_Kleiner::HandleAnimEvent( animevent_t *pEvent )
7070
//-----------------------------------------------------------------------------
7171
int CNPC_Kleiner::GetSoundInterests ( void )
7272
{
73-
return NULL;
73+
return 0;
7474
}
7575

7676
//-----------------------------------------------------------------------------

game/server/hl2/npc_mossman.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void CNPC_Mossman::HandleAnimEvent( animevent_t *pEvent )
8282
//-----------------------------------------------------------------------------
8383
int CNPC_Mossman::GetSoundInterests ( void )
8484
{
85-
return NULL;
85+
return 0;
8686
}
8787

8888
//-----------------------------------------------------------------------------

game/server/player.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ void CBasePlayer::PackDeadPlayerItems( void )
14591459
int iPW = 0;// index into packweapons array
14601460
int iPA = 0;// index into packammo array
14611461

1462-
memset(rgpPackWeapons, NULL, sizeof(rgpPackWeapons) );
1462+
memset(rgpPackWeapons, 0, sizeof(rgpPackWeapons) );
14631463
memset(iPackAmmo, -1, sizeof(iPackAmmo) );
14641464

14651465
// get the game rules

game/server/sceneentity.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CSceneManager : public CBaseEntity
147147
CRestoreSceneSound()
148148
{
149149
actor = NULL;
150-
soundname[ 0 ] = NULL;
150+
soundname[ 0 ] = '\0';
151151
soundlevel = SNDLVL_NORM;
152152
time_in_past = 0.0f;
153153
}

game/server/wscript

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def build(bld):
6767
includes += game["includes"]
6868
defines = game["defines"]
6969

70+
defines.append('_FORTIFY_SOURCE=0')
7071
defines.remove('PROTECTED_THINGS_ENABLE')
7172

7273
bld.shlib(

game/shared/particle_parse.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void ParseParticleEffectsMap( const char *pMapName, bool bLoadSheets, IFileList
172172
CUtlVector<CUtlString> files;
173173
char szMapManifestFilename[MAX_PATH];
174174

175-
szMapManifestFilename[0] = NULL;
175+
szMapManifestFilename[0] = '\0';
176176

177177
if ( pMapName && *pMapName )
178178
{

game/shared/soundenvelope.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEn
10561056
CSoundPatch *pSound = new CSoundPatch;
10571057

10581058
// FIXME: This is done so we don't have to futz with the public interface
1059-
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL;
1059+
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : 0;
10601060
pSound->Init( &filter, hEnt.Get(), CHAN_AUTO, pSoundName, SNDLVL_NORM );
10611061

10621062
return pSound;
@@ -1073,7 +1073,7 @@ CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEn
10731073
#endif
10741074

10751075
CSoundPatch *pSound = new CSoundPatch;
1076-
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL;
1076+
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : 0;
10771077
pSound->Init( &filter, hEnt.Get(), channel, pSoundName, ATTN_TO_SNDLVL( attenuation ) );
10781078

10791079
return pSound;
@@ -1090,7 +1090,7 @@ CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEn
10901090
#endif
10911091

10921092
CSoundPatch *pSound = new CSoundPatch;
1093-
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL;
1093+
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : 0;
10941094
pSound->Init( &filter, hEnt.Get(), channel, pSoundName, soundlevel );
10951095

10961096
return pSound;
@@ -1101,7 +1101,7 @@ CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEn
11011101
CSoundPatch *pSound = new CSoundPatch;
11021102

11031103
// FIXME: This is done so we don't have to futz with the public interface
1104-
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL;
1104+
EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : 0;
11051105
pSound->Init( &filter, hEnt.Get(), es.m_nChannel, es.m_pSoundName, es.m_SoundLevel );
11061106
pSound->ChangeVolume( es.m_flVolume, 0 );
11071107
pSound->ChangePitch( es.m_nPitch, 0 );

0 commit comments

Comments
 (0)