From 3e936bbd880e4bfae13068a07184f496a14e1218 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 25 Jan 2007 09:19:38 +0000 Subject: [PATCH] initial import of linux support --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40356 --- core/CDbgReporter.cpp | 3 +- core/CDbgReporter.h | 3 +- core/CLogger.cpp | 12 ++++- core/CTextParsers.cpp | 48 ++++++++--------- core/CTranslator.cpp | 3 +- core/Makefile | 90 +++++++++++++++++++++++++++++++ core/sm_stringutil.cpp | 3 +- core/smn_filesystem.cpp | 12 ++--- core/smn_float.cpp | 3 +- core/smn_player.cpp | 3 +- core/smn_string.cpp | 2 +- core/systems/ExtensionSys.cpp | 2 +- core/systems/ForwardSys.cpp | 10 ++-- core/systems/HandleSys.cpp | 4 +- core/systems/LibrarySys.cpp | 39 +++++++------- core/systems/LibrarySys.h | 4 +- core/systems/PluginInfoDatabase.h | 2 +- core/systems/PluginSys.cpp | 7 ++- core/vm/sp_vm_basecontext.cpp | 6 +-- core/vm/sp_vm_engine.cpp | 6 +-- core/vm/sp_vm_engine.h | 4 +- core/vm/sp_vm_function.cpp | 1 + public/ITextParsers.h | 4 +- public/sm_platform.h | 9 +++- public/sourcepawn/sp_typeutil.h | 3 +- public/sourcepawn/sp_vm_base.h | 3 +- 26 files changed, 203 insertions(+), 83 deletions(-) create mode 100644 core/Makefile diff --git a/core/CDbgReporter.cpp b/core/CDbgReporter.cpp index 0a0d1dcf..29d81794 100644 --- a/core/CDbgReporter.cpp +++ b/core/CDbgReporter.cpp @@ -70,4 +70,5 @@ int CDbgReporter::_GetPluginIndex(IPluginContext *ctx) iter->Release(); return -1; -} \ No newline at end of file +} + diff --git a/core/CDbgReporter.h b/core/CDbgReporter.h index 7d296a46..650550e1 100644 --- a/core/CDbgReporter.h +++ b/core/CDbgReporter.h @@ -16,4 +16,5 @@ private: int _GetPluginIndex(IPluginContext *ctx); }; -#endif // _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ \ No newline at end of file +#endif // _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ + diff --git a/core/CLogger.cpp b/core/CLogger.cpp index 3817a419..65354f49 100644 --- a/core/CLogger.cpp +++ b/core/CLogger.cpp @@ -2,7 +2,7 @@ #include "sourcemod.h" #include "sourcemm_api.h" #include "CLogger.h" -#include "systems/Librarysys.h" +#include "systems/LibrarySys.h" #include "sm_version.h" CLogger g_Logger; @@ -128,6 +128,11 @@ void CLogger::InitLogger(LoggingMode mode, bool startlogging) m_DailyPrintHdr = true; break; } + default: + { + /* do nothing... */ + break; + } } } @@ -280,6 +285,11 @@ void CLogger::MapChange(const char *mapname) _NewMapFile(); break; } + default: + { + /* Do nothing... */ + break; + } } if (m_ErrMapStart) diff --git a/core/CTextParsers.cpp b/core/CTextParsers.cpp index 296be553..48f630b6 100644 --- a/core/CTextParsers.cpp +++ b/core/CTextParsers.cpp @@ -14,20 +14,20 @@ static int g_ws_chartable[255] = {0}; CTextParsers::CTextParsers() { - g_ini_chartable1['_'] = 1; - g_ini_chartable1['-'] = 1; - g_ini_chartable1[','] = 1; - g_ini_chartable1['+'] = 1; - g_ini_chartable1['.'] = 1; - g_ini_chartable1['$'] = 1; - g_ini_chartable1['?'] = 1; - g_ini_chartable1['/'] = 1; - g_ws_chartable['\n'] = 1; - g_ws_chartable['\v'] = 1; - g_ws_chartable['\r'] = 1; - g_ws_chartable['\t'] = 1; - g_ws_chartable['\f'] = 1; - g_ws_chartable[' '] = 1; + g_ini_chartable1[(unsigned)'_'] = 1; + g_ini_chartable1[(unsigned)'-'] = 1; + g_ini_chartable1[(unsigned)','] = 1; + g_ini_chartable1[(unsigned)'+'] = 1; + g_ini_chartable1[(unsigned)'.'] = 1; + g_ini_chartable1[(unsigned)'$'] = 1; + g_ini_chartable1[(unsigned)'?'] = 1; + g_ini_chartable1[(unsigned)'/'] = 1; + g_ws_chartable[(unsigned)'\n'] = 1; + g_ws_chartable[(unsigned)'\v'] = 1; + g_ws_chartable[(unsigned)'\r'] = 1; + g_ws_chartable[(unsigned)'\t'] = 1; + g_ws_chartable[(unsigned)'\f'] = 1; + g_ws_chartable[(unsigned)' '] = 1; } void CTextParsers::OnSourceModAllInitialized() @@ -121,10 +121,10 @@ SMCParseError CTextParsers::ParseFile_SMC(const char *file, ITextListener_SMC *s struct StringInfo { StringInfo() : quoted(false), ptr(NULL), end(NULL), special(false) { } + bool quoted; char *ptr; char *end; bool special; - bool quoted; }; const char *FixupString(StringInfo &data) @@ -366,13 +366,13 @@ SMCParseError CTextParsers::ParseStream_SMC(void *stream, } } else { /* Check if we're whitespace or not */ - if (!g_ws_chartable[c]) + if (!g_ws_chartable[(unsigned)c]) { bool restage = false; /* Check various special tokens: * ; * // - * /* + * / * * { * } */ @@ -402,7 +402,7 @@ SMCParseError CTextParsers::ParseStream_SMC(void *stream, ignoring = true; ml_comment = true; /* yes, we restage, meaning that: - * STR/*stuff* /ING (space because ml comments don't nest in C++) + * STR/ *stuff* /ING (space because ml comments don't nest in C++) * will not generate 'STRING', but rather 'STR' and 'ING'. * This should be a rare occurrence and is done here for convenience. */ @@ -656,7 +656,7 @@ bool CTextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listen ***************************************************/ /* First strip beginning whitespace */ - while (*ptr != '\0' && g_ws_chartable[*ptr] != 0) + while (*ptr != '\0' && g_ws_chartable[(unsigned)*ptr] != 0) { ptr++; } @@ -709,7 +709,7 @@ bool CTextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listen /* Lastly, strip ending whitespace off */ for (size_t i=len-1; i>=0 && i #include +#include #include "CTranslator.h" #include "CLogger.h" #include "CTextParsers.h" @@ -336,7 +337,7 @@ SMCParseResult CPhraseFile::ReadSMC_KeyValue(const char *key, const char *value, *out_ptr++ = '%'; } /* Check length ... */ - if (out_ptr - fmt_buf >= sizeof(fmt_buf) - 1) + if ((unsigned)(out_ptr - fmt_buf) >= sizeof(fmt_buf) - 1) { ParseWarning("Format property contains format string that exceeds maximum length on line %d, phrase will be ignored.", m_CurLine); diff --git a/core/Makefile b/core/Makefile new file mode 100644 index 00000000..9c9c6b6e --- /dev/null +++ b/core/Makefile @@ -0,0 +1,90 @@ +#(C)2004-2006 SourceMM Development Team +# Makefile written by David "BAILOPAN" Anderson + +SMM_BASE = ../../../sourcemm +SMM_TRUNK = $(SMM_BASE)/trunk +HL2SDK = $(SMM_BASE)/hl2sdk +SMSDK = .. +SRCDS = ~/srcds + +### EDIT BELOW FOR OTHER PROJECTS ### + +OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing +GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden +DEBUG_FLAGS = -g -ggdb3 +CPP = gcc-4.1 +BINARY = sourcemod_mm.so + +HL2PUB = $(HL2SDK)/public +HL2LIB = $(HL2SDK)/linux_sdk + +OBJECTS = sourcemm_api.cpp sourcemod.cpp AdminCache.cpp CDbgReporter.cpp CLogger.cpp \ + CPlayer.cpp CPlayerManager.cpp CTextParsers.cpp CTranslator.cpp \ + sm_autonatives.cpp sm_memtable.cpp sm_srvcmds.cpp sm_trie.cpp \ + sm_stringutil.cpp smn_filesystem.cpp smn_float.cpp smn_handles.cpp \ + smn_player.cpp smn_string.cpp smn_textparse.cpp \ + systems/ExtensionSys.cpp systems/ForwardSys.cpp systems/HandleSys.cpp \ + systems/LibrarySys.cpp systems/PluginInfoDatabase.cpp \ + systems/PluginSys.cpp systems/ShareSys.cpp vm/sp_vm_basecontext.cpp \ + vm/sp_vm_engine.cpp vm/sp_vm_function.cpp +OBJECTS += zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/deflate.c zlib/gzio.c \ + zlib/infback.c zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c \ + zlib/uncompr.c zlib/zutil.c + +LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc + +INCLUDE = -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/dlls -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ + -I$(HL2PUB)/vstdlib -I$(HL2SDK)/tier1 -I$(SMM_TRUNK) -I$(SMM_TRUNK)/sourcehook -I$(SMM_TRUNK)/sourcemm \ + -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(SMSDK)/public/extensions \ + -Isystems + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS = $(DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS = $(OPT_FLAGS) +endif + +GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) + +CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -fPIC -msse -DSOURCEMOD_BUILD +CPPFLAGS = -Wno-non-virtual-dtor -fno-exceptions -fno-rtti + +ifeq "$(GCC_VERSION)" "4" + CPPFLAGS += $(GCC4_FLAGS) +endif + +OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) +OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< + +$(BIN_DIR)/%.o: %.c + $(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR)/systems + mkdir -p $(BIN_DIR)/vm + mkdir -p $(BIN_DIR)/zlib + ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so + ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so + $(MAKE) sourcemod + rm -rf $(BINARY) + ln -sf $(BIN_DIR)/$(BINARY) $(BINARY) + +sourcemod: $(OBJ_LINUX) + $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) all DEBUG=true + +default: all + +clean: + rm -rf Release/*.o + rm -rf Release/$(BINARY) + rm -rf Debug/*.o + rm -rf Debug/$(BINARY) + diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index c6798224..32e0fcfa 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -644,4 +644,5 @@ size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) va_end(ap); return (len >= maxlength) ? (maxlength - 1) : len; -} \ No newline at end of file +} + diff --git a/core/smn_filesystem.cpp b/core/smn_filesystem.cpp index 2777de27..0eaa876c 100644 --- a/core/smn_filesystem.cpp +++ b/core/smn_filesystem.cpp @@ -268,7 +268,7 @@ static cell_t sm_FileExists(IPluginContext *pContext, const cell_t *params) return 1; } return 0; -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX struct stat s; if (stat(realpath, &s) != 0) { @@ -304,7 +304,7 @@ static cell_t sm_RenameFile(IPluginContext *pContext, const cell_t *params) #ifdef PLATFORM_WINDOWS return (MoveFileA(old_realpath, new_realpath)) ? 1 : 0; -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX return (rename(old_realpath, new_realpath)) ? 0 : 1; #endif } @@ -332,7 +332,7 @@ static cell_t sm_DirExists(IPluginContext *pContext, const cell_t *params) return 1; } return 0; -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX struct stat s; if (stat(realpath, &s) != 0) { @@ -369,7 +369,7 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params) return static_cast(s.st_size); } return -1; -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX struct stat s; if (stat(realpath, &s) != 0) { @@ -465,7 +465,7 @@ static cell_t sm_LogToGame(IPluginContext *pContext, const cell_t *params) static cell_t sm_LogMessage(IPluginContext *pContext, const cell_t *params) { char buffer[1024]; - size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1); IPlugin *pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); g_Logger.LogMessage("[%s] %s", pPlugin->GetFilename(), buffer); @@ -476,7 +476,7 @@ static cell_t sm_LogMessage(IPluginContext *pContext, const cell_t *params) static cell_t sm_LogError(IPluginContext *pContext, const cell_t *params) { char buffer[1024]; - size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1); + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1); IPlugin *pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); g_Logger.LogError("[%s] %s", pPlugin->GetFilename(), buffer); diff --git a/core/smn_float.cpp b/core/smn_float.cpp index baadc443..806349ff 100644 --- a/core/smn_float.cpp +++ b/core/smn_float.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "sm_autonatives.h" #include "sp_vm_api.h" #include "sp_typeutil.h" @@ -255,4 +256,4 @@ REGISTER_NATIVES(floatnatives) {"ArcSine", sm_ArcSine}, {"ArcTangent2", sm_ArcTangent2}, {NULL, NULL} -}; \ No newline at end of file +}; diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 62f22cae..52a974e5 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -199,4 +199,5 @@ REGISTER_NATIVES(playernatives) {"PrintToServer", sm_PrintToServer}, {"PrintToConsole", sm_PrintToConsole}, {NULL, NULL} -}; \ No newline at end of file +}; + diff --git a/core/smn_string.cpp b/core/smn_string.cpp index 2fbfca82..eaa874ae 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -10,7 +10,7 @@ inline const char *_strstr(const char *str, const char *substr) { #ifdef PLATFORM_WINDOWS return strstr(str, substr); -#elif PLATFORM_LINUX +#elif defined PLATFORM_LINUX return (const char *)strstr(str, substr); #endif } diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index b459649a..ed97c5de 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -707,7 +707,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco if (argcount > 4 && pExt->unload_code) { const char *unload = g_RootMenu.GetArgument(4); - if (pExt->unload_code == atoi(unload)) + if (pExt->unload_code == (unsigned)atoi(unload)) { char filename[PLATFORM_MAX_PATH+1]; snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); diff --git a/core/systems/ForwardSys.cpp b/core/systems/ForwardSys.cpp index 70de62cf..124ac058 100644 --- a/core/systems/ForwardSys.cpp +++ b/core/systems/ForwardSys.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "ForwardSys.h" #include "PluginSys.h" #include "ShareSys.h" @@ -179,7 +181,7 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu { for (unsigned int i=0; i +#include HandleSystem g_HandleSys; @@ -408,7 +409,6 @@ HandleError HandleSystem::GetHandle(Handle_t handle, } QHandle *pHandle = &m_Handles[index]; - QHandleType *pType = &m_Types[pHandle->type]; if (!pHandle->set || (pHandle->set == HandleSet_Freed && !ignoreFree)) @@ -694,7 +694,7 @@ void HandleSystem::ReleasePrimHandle(unsigned int index) if (set == HandleSet_Identity) { /* Extra work to do. We need to find everything connected to this identity and release it. */ - unsigned int ch_index, old_index = 0; + unsigned int ch_index; while ((ch_index = pHandle->ch_next) != 0) { pLocal = &m_Handles[ch_index]; diff --git a/core/systems/LibrarySys.cpp b/core/systems/LibrarySys.cpp index e43449c6..fa1df0dc 100644 --- a/core/systems/LibrarySys.cpp +++ b/core/systems/LibrarySys.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include "LibrarySys.h" LibrarySystem g_LibSys; @@ -9,7 +12,7 @@ CLibrary::~CLibrary() { #if defined PLATFORM_WINDOWS FreeLibrary(m_lib); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX dlclose(m_lib); #endif m_lib = NULL; @@ -30,7 +33,7 @@ void *CLibrary::GetSymbolAddress(const char *symname) { #if defined PLATFORM_WINDOWS return GetProcAddress(m_lib, symname); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX return dlsym(m_lib, symname); #endif } @@ -51,12 +54,12 @@ CDirectory::CDirectory(const char *path) { m_fd.cFileName[0] = '\0'; } -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX m_dir = opendir(path); if (IsValid()) { /* :TODO: we need to read past "." and ".."! */ - ep = readdir(dp); + ep = readdir(m_dir); snprintf(m_origpath, PLATFORM_MAX_PATH, "%s", path); } else { ep = NULL; @@ -70,7 +73,7 @@ CDirectory::~CDirectory() { #if defined PLATFORM_WINDOWS FindClose(m_dir); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX closedir(m_dir); #endif } @@ -84,8 +87,8 @@ void CDirectory::NextEntry() FindClose(m_dir); m_dir = INVALID_HANDLE_VALUE; } -#else if defined PLATFORM_POSIX - if ((ep=readdir(m_dir) == NULL) +#elif defined PLATFORM_POSIX + if ((ep=readdir(m_dir)) == NULL) { closedir(m_dir); m_dir = NULL; @@ -102,10 +105,10 @@ bool CDirectory::IsEntryDirectory() { #if defined PLATFORM_WINDOWS return ((m_fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY); -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX char temppath[PLATFORM_MAX_PATH]; snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); - return g_LibrarySys.IsPathDirectory(temppath); + return g_LibSys.IsPathDirectory(temppath); #endif } @@ -113,10 +116,10 @@ bool CDirectory::IsEntryFile() { #if defined PLATFORM_WINDOWS return !(m_fd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX char temppath[PLATFORM_MAX_PATH]; snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); - return g_LibrarySys.IsPathFile(temppath); + return g_LibSys.IsPathFile(temppath); #endif } @@ -124,7 +127,7 @@ const char *CDirectory::GetEntryName() { #if defined PLATFORM_WINDOWS return m_fd.cFileName; -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX return ep ? ep->d_name : ""; #endif } @@ -138,7 +141,7 @@ bool CDirectory::IsValid() { #if defined PLATFORM_WINDOWS return (m_dir != INVALID_HANDLE_VALUE); -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX return (m_dir != NULL); #endif } @@ -155,7 +158,7 @@ bool LibrarySystem::PathExists(const char *path) DWORD attr = GetFileAttributesA(path); return (attr != INVALID_FILE_ATTRIBUTES); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX struct stat s; return (stat(path, &s) == 0); @@ -178,7 +181,7 @@ bool LibrarySystem::IsPathFile(const char *path) } return true; -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX struct stat s; if (stat(path, &s) != 0) @@ -205,7 +208,7 @@ bool LibrarySystem::IsPathDirectory(const char *path) return true; } -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_LINUX struct stat s; if (stat(path, &s) != 0) @@ -249,7 +252,7 @@ void LibrarySystem::GetPlatformError(char *error, size_t err_max) (LPSTR)error, err_max, NULL); -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX snprintf(error, err_max, "%s", strerror(errno)); #endif } @@ -270,7 +273,7 @@ ILibrary *LibrarySystem::OpenLibrary(const char *path, char *error, size_t err_m GetPlatformError(error, err_max); return false; } -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX lib = dlopen(path, RTLD_NOW); if (!lib) { diff --git a/core/systems/LibrarySys.h b/core/systems/LibrarySys.h index 352a6b9b..bea6b4df 100644 --- a/core/systems/LibrarySys.h +++ b/core/systems/LibrarySys.h @@ -8,7 +8,7 @@ using namespace SourceMod; #if defined PLATFORM_WINDOWS typedef HMODULE LibraryHandle; -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX typedef void * LibraryHandle; #endif @@ -30,7 +30,7 @@ private: #if defined PLATFORM_WINDOWS HANDLE m_dir; WIN32_FIND_DATAA m_fd; -#else if defined PLATFORM_LINUX +#elif defined PLATFORM_POSIX DIR *m_dir; struct dirent *ep; char m_origpath[PLATFORM_MAX_PATH]; diff --git a/core/systems/PluginInfoDatabase.h b/core/systems/PluginInfoDatabase.h index 572bb7b7..9c088e69 100644 --- a/core/systems/PluginInfoDatabase.h +++ b/core/systems/PluginInfoDatabase.h @@ -64,7 +64,7 @@ private: int m_errmsg; bool in_plugins; bool in_options; - unsigned int m_infodb; + int m_infodb; size_t m_infodb_count; size_t m_infodb_size; int cur_plugin; diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index f0bc50e9..40850787 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -456,7 +456,7 @@ time_t CPlugin::GetFileTimeStamp() #ifdef PLATFORM_WINDOWS struct _stat s; if (_stat(path, &s) != 0) -#else if defined PLATFORM_POSIX +#elif defined PLATFORM_POSIX struct stat s; if (stat(path, &s) != 0) #endif @@ -1165,7 +1165,7 @@ bool CPluginManager::TestAliasMatch(const char *alias, const char *localpath) if (*aliasptr == '*') { /* First, see if this is the last character */ - if (aliasptr - alias == alias_len - 1) + if ((unsigned)(aliasptr - alias) == alias_len - 1) { /* If so, there's no need to match anything else */ return true; @@ -1369,7 +1369,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc assert(pl->GetStatus() != Plugin_Created); int len = 0; const sm_plugininfo_t *info = pl->GetPublicInfo(); - if (pl->GetStatus() != Pl_Running) + if (pl->GetStatus() != Plugin_Running) { len += UTIL_Format(buffer, sizeof(buffer), " %02d <%s>", id, GetStatusText(pl->GetStatus())); } else { @@ -1448,7 +1448,6 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc return; } - int id = 1; int num = atoi(g_RootMenu.GetArgument(3)); if (num < 1 || num > (int)GetPluginCount()) { diff --git a/core/vm/sp_vm_basecontext.cpp b/core/vm/sp_vm_basecontext.cpp index ed6ca5c9..f1c0fae5 100644 --- a/core/vm/sp_vm_basecontext.cpp +++ b/core/vm/sp_vm_basecontext.cpp @@ -285,7 +285,7 @@ int BaseContext::HeapPop(cell_t local_addr) addr = (cell_t *)(ctx->memory + local_addr); cellcount = (*addr) * sizeof(cell_t); /* check if this memory count looks valid */ - if (ctx->hp - cellcount - sizeof(cell_t) != local_addr) + if ((signed)(ctx->hp - cellcount - sizeof(cell_t)) != local_addr) { return SP_ERROR_INVALID_ADDRESS; } @@ -596,8 +596,6 @@ int BaseContext::PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t ar int BaseContext::LocalToString(cell_t local_addr, char **addr) { - int len = 0; - if (((local_addr >= ctx->hp) && (local_addr < ctx->sp)) || (local_addr < 0) || ((ucell_t)local_addr >= ctx->mem_size)) { return SP_ERROR_INVALID_ADDRESS; @@ -855,7 +853,7 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id) m_priv_funcs[func_id] = new CFunction(save, this); pFunc = m_priv_funcs[func_id]; } -#endif 0 +#endif assert(false); } diff --git a/core/vm/sp_vm_engine.cpp b/core/vm/sp_vm_engine.cpp index e39e0e52..fda2d009 100644 --- a/core/vm/sp_vm_engine.cpp +++ b/core/vm/sp_vm_engine.cpp @@ -10,7 +10,7 @@ #if defined WIN32 #define WIN32_LEAN_AND_MEAN #include -#else if defined __GNUC__ +#elif defined __GNUC__ #include #endif @@ -85,7 +85,7 @@ void *SourcePawnEngine::ExecAlloc(size_t size) { #if defined WIN32 return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); -#else if defined __GNUC__ +#elif defined __GNUC__ void *base = memalign(sysconf(_SC_PAGESIZE), size); if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) { @@ -100,7 +100,7 @@ void SourcePawnEngine::ExecFree(void *address) { #if defined WIN32 VirtualFree(address, 0, MEM_RELEASE); -#else if defined __GNUC__ +#elif defined __GNUC__ free(address); #endif } diff --git a/core/vm/sp_vm_engine.h b/core/vm/sp_vm_engine.h index 4ad0f715..f30d0b0e 100644 --- a/core/vm/sp_vm_engine.h +++ b/core/vm/sp_vm_engine.h @@ -27,10 +27,10 @@ public: virtual void ResetTrace(); virtual const char *GetLastNative(uint32_t *index); private: + int m_Error; + const char *m_pMsg; TracedCall *m_pStart; TracedCall *m_pIterator; - const char *m_pMsg; - int m_Error; uint32_t m_Native; }; diff --git a/core/vm/sp_vm_function.cpp b/core/vm/sp_vm_function.cpp index 13b419b4..ceb78dc4 100644 --- a/core/vm/sp_vm_function.cpp +++ b/core/vm/sp_vm_function.cpp @@ -1,4 +1,5 @@ #include +#include #include "PluginSys.h" /******************** diff --git a/public/ITextParsers.h b/public/ITextParsers.h index 8a583a82..cae293a1 100644 --- a/public/ITextParsers.h +++ b/public/ITextParsers.h @@ -106,7 +106,7 @@ namespace SourceMod * * The SMC file format is defined as: * WHITESPACE: 0x20, \n, \t, \r - * IDENTIFIER: Any ASCII character EXCLUDING ", {, }, ;, //, /*, or WHITESPACE. + * IDENTIFIER: Any ASCII character EXCLUDING ", {, }, ;, //, / *, or WHITESPACE. * STRING: Any set of symbols enclosed in quotes. * Note: if a STRING does not have quotes, it is parsed as an IDENTIFIER. * @@ -138,7 +138,7 @@ namespace SourceMod * unless they are inside literal strings: * ; * // - * /* */ + * / * */ enum SMCParseResult { diff --git a/public/sm_platform.h b/public/sm_platform.h index 05171cd8..8f672d37 100644 --- a/public/sm_platform.h +++ b/public/sm_platform.h @@ -24,11 +24,14 @@ #define PLATFORM_SEP_CHAR '\\' #define PLATFORM_SEP_ALTCHAR '/' #define PLATFORM_EXTERN_C extern "C" __declspec(dllexport) -#else if defined __linux__ +#elif defined __linux__ #define PLATFORM_LINUX #define PLATFORM_POSIX +#include #include #include +#include +#include #define PLATFORM_MAX_PATH PATH_MAX #define PLATFORM_LIB_EXT "so" #define PLATFORM_SEP_CHAR '/' @@ -36,4 +39,8 @@ #define PLATFORM_EXTERN_C extern "C" __attribute__((visibility("default"))) #endif +#if !defined SOURCEMOD_BUILD +#define SOURCEMOD_BUILD +#endif + #endif //_INCLUDE_SOURCEMOD_PLATFORM_H_ diff --git a/public/sourcepawn/sp_typeutil.h b/public/sourcepawn/sp_typeutil.h index 921f9f74..f5146bb2 100644 --- a/public/sourcepawn/sp_typeutil.h +++ b/public/sourcepawn/sp_typeutil.h @@ -12,4 +12,5 @@ inline float sp_ctof(cell_t val) return *(float *)&val; } -#endif //_INCLUDE_SOURCEPAWN_VM_TYPEUTIL_H_ \ No newline at end of file +#endif //_INCLUDE_SOURCEPAWN_VM_TYPEUTIL_H_ + diff --git a/public/sourcepawn/sp_vm_base.h b/public/sourcepawn/sp_vm_base.h index 4fff0f4c..5d295d62 100644 --- a/public/sourcepawn/sp_vm_base.h +++ b/public/sourcepawn/sp_vm_base.h @@ -7,10 +7,11 @@ #if defined WIN32 #define EXPORT_LINK extern "C" __declspec(dllexport) -#else if defined __GNUC__ +#elif defined __GNUC__ #define EXPORT_LINK extern "C" __attribute__((visibility("default"))) #endif typedef SourcePawn::IVirtualMachine *(*SP_GETVM_FUNC)(SourcePawn::ISourcePawnEngine *); #endif //_INCLUDE_SOURCEPAWN_VM_BASE_H_ +