sourcemm/sourcemm.cpp
author David Anderson <dvander@alliedmods.net>
Thu Oct 20 14:37:47 2005 +0000 (2005-10-20)
changeset 138 dfa3b31cc042
parent 125 5cccffcd65a6
child 141 84488512ee3a
permissions -rw-r--r--
initial import of new events system
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2005 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): David "BAILOPAN" Anderson
     8 * Contributor(s): Scott "Damaged Soul" Ehlert
     9 *				: Pavol "PM OnoTo" Marko
    10 * ============================
    11 */
    12 
    13 #include <interface.h>
    14 #include <eiface.h>
    15 #include "sourcemm.h"
    16 #include "concommands.h"
    17 #include "CSmmAPI.h"
    18 #include "CPlugin.h"
    19 #include "util.h"
    20 
    21 using namespace SourceMM;
    22 
    23 /**
    24  * @brief Implementation of main SourceMM GameDLL functionality
    25  * @file sourcemm.cpp
    26  */
    27 
    28 SH_DECL_HOOK4(IServerGameDLL, DLLInit, SH_NOATTRIB, false, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
    29 SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
    30 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    31 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    32 bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
    33 void DLLShutdown_handler();
    34 void LevelShutdown_handler();
    35 bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    36 
    37 GameDllInfo g_GameDll = {false, NULL, NULL, NULL};
    38 EngineInfo g_Engine;
    39 SourceHook::CSourceHookImpl g_SourceHook;
    40 SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
    41 SourceHook::String g_ModPath;
    42 SourceHook::String g_BinPath;
    43 PluginId g_PLID = Pl_Console;		//Technically, SourceMM is the "Console" plugin... :p
    44 bool bInFirstLevel = true;
    45 bool gParsedGameInfo = false;
    46 SourceHook::List<GameDllInfo *> gamedll_list;
    47 SourceHook::CallClass<IServerGameDLL> *dllExec;
    48 
    49 void ClearGamedllList();
    50 
    51 //helper macro
    52 #define	IFACE_MACRO(orig,nam) \
    53 	CPluginManager::CPlugin *pl; \
    54 	SourceHook::List<IMetamodListener *>::iterator event; \
    55 	IMetamodListener *api; \
    56 	int mret = 0; \
    57 	void *val = NULL; \
    58 	for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
    59 		pl = (*iter); \
    60 		for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
    61 			api = (*event); \
    62 			mret = IFACE_FAILED; \
    63 			if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
    64 				if (ret) *ret = mret; \
    65 				return val; \
    66 			} \
    67 		} \
    68 	} \
    69 	return (orig)(iface, ret);
    70 
    71 ///////////////////////////////////
    72 // Main code for HL2 Interaction //
    73 ///////////////////////////////////
    74 
    75 //Initialize everything here
    76 void InitMainStates()
    77 {
    78 	char full_path[260] = {0};
    79 	GetFileOfAddress(g_GameDll.factory, full_path, sizeof(full_path)-1);
    80 	g_BinPath.assign(full_path);
    81 
    82 	UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
    83 
    84 	//Like metamod, reload plugins at the end of the map.
    85 	//This is so plugins can hook everything on load, BUT, new plugins will be reloaded
    86 	// if the server is shut down (silly, but rare case).
    87 	bInFirstLevel = true;
    88 
    89 	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit, false);
    90 	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, g_GameDll.pGameDLL, DLLShutdown_handler, false);
    91 	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, g_GameDll.pGameDLL, LevelShutdown_handler, true);
    92 	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelInit, g_GameDll.pGameDLL, LevelInit_handler, true);
    93 }
    94 
    95 bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
    96 {
    97 	g_Engine.engineFactory = engineFactory;
    98 	g_Engine.fileSystemFactory = filesystemFactory;
    99 	g_Engine.physicsFactory = physicsFactory;
   100 	g_Engine.pGlobals = pGlobals;
   101 
   102 	g_Engine.engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
   103 	if (!g_Engine.engine)
   104 	{
   105 		Error("Could not find IVEngineServer! Metamod cannot load.");
   106 		return false;
   107 	}
   108 	g_Engine.icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION , NULL));
   109 	if (!g_Engine.icvar)
   110 	{
   111 		Error("Could not find ICvar! Metamod cannot load.");
   112 		return false;
   113 	}
   114 
   115 	g_Engine.loaded = true;
   116 
   117 	//Initialize our console hooks
   118 	ConCommandBaseMgr::OneTimeInit(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
   119 
   120 	if (!g_SmmAPI.CacheCmds())
   121 	{
   122 		LogMessage("[META] Warning: Failed to initialize Con_Printf.  Defaulting to Msg().");
   123 		LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
   124 	}
   125 
   126 	char full_path[260];
   127 	UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
   128 
   129 	LoadPluginsFromFile(full_path);
   130 
   131 	g_PluginMngr.SetAllLoaded();
   132 
   133 	bInFirstLevel = true;
   134 
   135 	dllExec = SH_GET_CALLCLASS(g_GameDll.pGameDLL);
   136 
   137 	RETURN_META_VALUE(MRES_IGNORED, true);
   138 }
   139 
   140 //This is where the magic happens
   141 SMM_API void *CreateInterface(const char *iface, int *ret)
   142 {
   143 	if (!gParsedGameInfo)
   144 	{
   145 		gParsedGameInfo = true;
   146 		char curpath[260] = {0};
   147 		char dllpath[260] = {0};
   148 		getcwd(curpath, sizeof(curpath)-1);
   149 		if (!GetFileOfAddress((void *)CreateInterface, dllpath, sizeof(dllpath)-1))
   150 		{
   151 			Error("GetFileOfAddress() failed! Metamod cannot load.");
   152 			return NULL;
   153 		}
   154 		SourceHook::String s_dllpath(dllpath);
   155 		//begin the heuristics for searching for the mod path (these are quite ugly).
   156 		//for OS compatibility purposes, we're going to do case insensitivity on windows.
   157 		size_t path_len = strlen(curpath);
   158 		size_t dll_len = strlen(dllpath);
   159 
   160 		//strip the dll path off
   161 		//:TODO: with path stuff - in Linux, \ can exist in a file path as a non-seperator!
   162 		for (size_t i=dll_len-1; i>0; i--)
   163 		{
   164 			if (dllpath[i] == '\\' || dllpath[i] == '/')
   165 			{
   166 				if (i == dll_len-1)
   167 					break;
   168 				//save path by stripping off file name and ending terminator
   169 				dllpath[i] = '\0';
   170 				dll_len = i;
   171 				break;
   172 			}
   173 		}
   174 
   175 		//strip absolute path terminators if any!
   176 		if (curpath[path_len-1] == '/' || curpath[path_len-1] == '\\')
   177 			curpath[--path_len] = '\0';
   178 
   179 		//if the base path doesn't fit into the module path, something is wrong!
   180 		// ex: c:\games\srcds
   181 		//     c:\gaben.dll
   182 		if (path_len > dll_len)
   183 		{
   184 			Error("Could not detect GameDLL path! Metamod cannot load[1].");
   185 			return NULL;
   186 		}
   187 
   188 		//we are now in such a position that the two dir names SHOULD MATCH!
   189 		typedef int (*STRNCMP)(const char *str1, const char *str2, size_t n);
   190 		STRNCMP cmp = 
   191 #ifdef WIN32
   192 			strnicmp;
   193 #else
   194 			strncmp;
   195 #endif
   196 		//are they equal?
   197 		if ( ((cmp)(curpath, dllpath, path_len)) != 0 )
   198 		{
   199 			//:TODO: In this case, we should read /proc/self/maps and find srcds!
   200 			Error("Could not detect GameDLL path! Metamod cannot load[2].");
   201 			return NULL;
   202 		}
   203 		//this will skip past the dir and its separator char
   204 		char *ptr = &(dllpath[path_len+1]);
   205 		path_len = strlen(ptr);
   206 		for (size_t i=0; i<path_len; i++)
   207 		{
   208 			if (ptr[i] == '/' || ptr[i] == '\\')
   209 			{
   210 				if (i == 0)
   211 				{
   212 					Error("Could not detect GameDLL path! Metamod cannot load[3].");
   213 					return NULL;
   214 				} else {
   215 					ptr[i] = '\0';
   216 					path_len = i+1;
   217 					break;
   218 				}
   219 			}
   220 		}
   221 		//WE NOW HAVE A GUESS AT THE MOD DIR.  OH MY GOD.
   222 		char temp_path[260];
   223 		snprintf(temp_path, sizeof(temp_path)-1, 
   224 			"%s%s%s", 
   225 			curpath, 
   226 			PATH_SEP_STR, 
   227 			ptr);
   228 
   229 		g_ModPath.assign(temp_path);
   230 
   231 		snprintf(temp_path, sizeof(temp_path)-1, 
   232 			"%s%s%s", 
   233 			g_ModPath.c_str(),
   234 			PATH_SEP_STR,
   235 			"gameinfo.txt");
   236 
   237 		FILE *fp = fopen(temp_path, "rt");
   238 		if (!fp)
   239 		{
   240 			Error("Unable to open gameinfo.txt!  Metamod cannot load.");
   241 			return NULL;
   242 		}
   243 		char buffer[255];
   244 		char key[128], val[128];
   245 		size_t len = 0;
   246 		const char *gameinfo = "|gameinfo_path|";
   247 		size_t gameinfo_len = strlen(gameinfo);
   248 		bool search = false;
   249 		bool gamebin = false;
   250 		const char *lptr;
   251 		while (!feof(fp))
   252 		{
   253 			buffer[0] = '\0';
   254 			fgets(buffer, sizeof(buffer)-1, fp);
   255 			len = strlen(buffer);
   256 			if (buffer[len-1] == '\n')
   257 				buffer[--len] = '\0';
   258 			UTIL_TrimComments(buffer);
   259 			UTIL_TrimLeft(buffer);
   260 			UTIL_TrimRight(buffer);
   261 			if (stricmp(buffer, "SearchPaths") == 0)
   262 				search = true;
   263 			if (!search)
   264 				continue;
   265 			UTIL_KeySplit(buffer, key, sizeof(key)-1, val, sizeof(val)-1);
   266 			if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
   267 			{
   268 				if (stricmp(key, "Game") == 0)
   269 					gamebin = false;
   270 				else
   271 					gamebin = true;
   272 
   273 				if (strncmp(val, gameinfo, gameinfo_len) == 0)
   274 				{
   275 					ptr = &(val[gameinfo_len]);
   276 					if (ptr[0] == '.')
   277 						ptr++;
   278 					lptr = g_ModPath.c_str();
   279 				} else {
   280 					lptr = curpath;
   281 					ptr = val;
   282 				}
   283 				size_t ptr_len = strlen(ptr);
   284 				if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
   285 					ptr[--ptr_len] = '\0';
   286 				//no need to append "bin"
   287 				if (gamebin)
   288 				{
   289 					UTIL_PathFmt(temp_path, sizeof(temp_path)-1, "%s/%s/%s", lptr, ptr, SERVER_DLL);
   290 				} else {
   291 					UTIL_PathFmt(temp_path, sizeof(temp_path)-1, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
   292 				}
   293 				if (!UTIL_PathCmp(s_dllpath.c_str(), temp_path))
   294 				{
   295 					FILE *fp = fopen(temp_path, "rb");
   296 					if (!fp)
   297 						continue;
   298 					//:TODO: Optimize this a bit!
   299 					SourceHook::List<GameDllInfo *>::iterator iter;
   300 					GameDllInfo *pCheck;
   301 					bool found = false;
   302 					for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
   303 					{
   304 						pCheck = (*iter);
   305 						if (GetFileOfAddress(pCheck->factory, buffer, sizeof(buffer)-1))
   306 						{
   307 							if (UTIL_PathCmp(temp_path, buffer))
   308 							{
   309 								found = true;
   310 								break;
   311 							}
   312 						}
   313 					}
   314 					if (found)
   315 						continue;
   316 					fclose(fp);
   317 					HINSTANCE gamedll = dlmount(temp_path);
   318 					if (gamedll == NULL)
   319 						continue;
   320 					CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
   321 					if (fn == NULL)
   322 					{
   323 						dlclose(gamedll);
   324 						continue;
   325 					}
   326 					GameDllInfo *pInfo = new GameDllInfo;
   327 					pInfo->factory = fn;
   328 					pInfo->lib = gamedll;
   329 					pInfo->loaded = true;
   330 					pInfo->pGameDLL = NULL;
   331 					gamedll_list.push_back(pInfo);
   332 				}
   333 			}
   334 		}
   335 		fclose(fp);
   336 	}
   337 
   338 	if (!g_GameDll.loaded)
   339 	{
   340 		const char *str = "ServerGameDLL";
   341 		size_t len = strlen(str);
   342 
   343 		if (strncmp(iface, str, len) == 0)
   344 		{
   345 			//This is the interface we want!  Right now we support versions 3 and 4.
   346 			int version = atoi(&(iface[len]));
   347 			if (version < MIN_GAMEDLL_VERSION || version > MAX_GAMEDLL_VERSION)
   348 			{
   349 				Error("GameDLL version %d is not supported by Metamod!", version);
   350 				return NULL;
   351 			}
   352 			SourceHook::List<GameDllInfo *>::iterator iter;
   353 			GameDllInfo *pInfo = NULL;
   354 			void *ptr;
   355 			for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
   356 			{
   357 				pInfo = (*iter);
   358 				ptr = (pInfo->factory)(iface, ret);
   359 				if (ptr)
   360 				{
   361 					//this is our gamedll.  unload the others.
   362 					gamedll_list.erase(iter);
   363 					ClearGamedllList();
   364 					pInfo->pGameDLL = static_cast<IServerGameDLL *>(ptr);
   365 					g_GameDll = *pInfo;
   366 					delete pInfo;
   367 					break;
   368 				}
   369 			}
   370 			if (g_GameDll.loaded)
   371 			{
   372 				InitMainStates();
   373 			} else {
   374 				if (ret)
   375 					*ret = IFACE_FAILED;
   376 				return NULL;
   377 			}
   378 		} else {
   379 			//wtf do we do...
   380 			//:TODO: .. something a bit more intelligent?
   381 			Error("Engine requested unknown interface before GameDLL was known!");
   382 			return NULL;
   383 		}
   384 	}
   385 
   386 	//if we got here, there's definitely a gamedll.
   387 	IFACE_MACRO(g_GameDll.factory, GameDLL);
   388 }
   389 
   390 void ClearGamedllList()
   391 {
   392 	SourceHook::List<GameDllInfo *>::iterator iter;
   393 
   394 	GameDllInfo *pInfo;
   395 	for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
   396 	{
   397 		pInfo = (*iter);
   398 		dlclose(pInfo->lib);
   399 		delete pInfo;
   400 	}
   401 
   402 	gamedll_list.clear();
   403 }
   404 
   405 void DLLShutdown_handler()
   406 {
   407 	//Unload plugins
   408 	g_PluginMngr.UnloadAll();
   409 
   410 	// Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly
   411 	g_SMConVarAccessor.MarkCommandsAsGameDLL();
   412 	g_SMConVarAccessor.UnregisterGameDLLCommands();
   413 
   414 	SH_CALL(dllExec, &IServerGameDLL::DLLShutdown)();
   415 
   416 	SH_RELEASE_CALLCLASS(dllExec);
   417 	dllExec = NULL;
   418 
   419 	g_SourceHook.CompleteShutdown();
   420 
   421 	if (g_GameDll.lib && g_GameDll.loaded)
   422 		dlclose(g_GameDll.lib);
   423 	memset(&g_GameDll, 0, sizeof(GameDllInfo));
   424 
   425 	RETURN_META(MRES_SUPERCEDE);
   426 }
   427 
   428 int LoadPluginsFromFile(const char *file)
   429 {
   430 	FILE *fp;
   431 	int total = 0, skipped=0;
   432 	PluginId id;
   433 	bool already;
   434 
   435 	fp = fopen(file, "rt");
   436 	if (!fp)
   437 	{
   438 		LogMessage("[META] Could not open plugins file %s\n", file);
   439 		return -1;
   440 	}
   441 
   442 	char buffer[255], error[255], full_path[128];
   443 	const char *ptr, *ext;
   444 	size_t length;
   445 	while (!feof(fp))
   446 	{
   447 		buffer[0] = '\0';
   448 		fgets(buffer, sizeof(buffer)-1, fp);
   449 		length = strlen(buffer);
   450 		if (!length)
   451 			continue;
   452 		if (buffer[length-1] == '\n')
   453 			buffer[length-1] = '\0';
   454 
   455 		UTIL_TrimLeft(buffer);
   456 		UTIL_TrimRight(buffer);
   457 
   458 		if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
   459 			continue;
   460 		//First find if it's an absolute path or not...
   461 		if (buffer[0] == '/' || strncmp(&(buffer[1]), ":\\", 2) == 0)
   462 		{
   463 			//If we're in an absolute path, ignore our normal heuristics
   464 			id = g_PluginMngr.Load(buffer, Pl_File, already, error, sizeof(error)-1);
   465 			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   466 			{
   467 				LogMessage("[META] Failed to load plugin %s.  %s", buffer, error);
   468 			} else {
   469 				if (already)
   470 					skipped++;
   471 				else
   472 					total++;
   473 			}
   474 		} else {
   475 			//Attempt to find a file extension
   476 			ptr = UTIL_GetExtension(buffer);
   477 			//Add an extension if there's none there
   478 			if (!ptr)
   479 			{
   480 #if defined WIN32 || defined _WIN32
   481 				ext = ".dll";
   482 #else
   483 				ext = "_i486.so";
   484 #endif
   485 			} else {
   486 				ext = "";
   487 			}
   488 			//Format the new path
   489 			UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), buffer, ext);
   490 			id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error)-1);
   491 			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   492 			{
   493 				LogMessage("[META] Failed to load plugin %s.  %s", buffer, error);
   494 			} else {
   495 				if (already)
   496 					skipped++;
   497 				else
   498 					total++;
   499 			}
   500 		}
   501 	}
   502 	fclose(fp);
   503 
   504 	if (skipped)
   505 	{
   506 		LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
   507 	} else {
   508 		LogMessage("[META] Loaded %d plugins from file.", total);
   509 	}
   510 	
   511 	return total;
   512 }
   513 
   514 //Wrapper function.  This is called when the GameDLL thinks it's using
   515 // the engine's real engineFactory.
   516 void *EngineFactory(const char *iface, int *ret)
   517 {
   518 	IFACE_MACRO(g_Engine.engineFactory, Engine);
   519 }
   520 
   521 //Wrapper function.  This is called when the GameDLL thinks it's using
   522 // the engine's real physicsFactory.
   523 void *PhysicsFactory(const char *iface, int *ret)
   524 {
   525 	IFACE_MACRO(g_Engine.physicsFactory, Physics);
   526 }
   527 
   528 //Wrapper function.  This is called when the GameDLL thinks it's using
   529 // the engine's real fileSystemFactory.
   530 void *FileSystemFactory(const char *iface, int *ret)
   531 {
   532 	IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
   533 }
   534 
   535 void LogMessage(const char *msg, ...)
   536 {
   537 	va_list ap;
   538 	static char buffer[2048];
   539 
   540 	buffer[0] = '\0';
   541 
   542 	va_start(ap, msg);
   543 	vsnprintf(buffer, sizeof(buffer)-5, msg, ap);
   544 	strcat(buffer, "\n");
   545 	va_end(ap);
   546 
   547 	if (!g_Engine.engine)
   548 	{
   549 		fprintf(stdout, "%s", buffer);
   550 	} else {
   551 		g_Engine.engine->LogPrint(buffer);
   552 	}
   553 }
   554 
   555 void LevelShutdown_handler(void)
   556 {
   557 	if (!bInFirstLevel)
   558 	{
   559 		char full_path[255];
   560 #if defined WIN32 || defined _WIN32
   561 		snprintf(full_path, sizeof(full_path)-1, "%s\\addons\\metamod\\%s", g_ModPath.c_str(), "metaplugins.ini");
   562 #else
   563 		snprintf(full_path, sizeof(full_path)-1, "%s/addons/metamod/%s", g_ModPath.c_str(), "metaplugins.ini");
   564 #endif
   565 		LoadPluginsFromFile(full_path);
   566 	} else {
   567 		bInFirstLevel = false;
   568 	}
   569 }
   570 
   571 bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
   572 { 
   573 	if (!g_SmmAPI.CacheSuccessful())
   574 	{
   575 		LogMessage("[META] Warning: Failed to initialize Con_Printf.  Defaulting to Msg().");
   576 		LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
   577 	}
   578 
   579 	RETURN_META_VALUE(MRES_IGNORED, false);
   580 }
   581 
   582 #if defined __GNUC__ && (__GNUC__ == 3)
   583 void * ::operator new(size_t size) {
   584 	return(calloc(1, size)); 
   585 }
   586 
   587 void * ::operator new[](size_t size) {
   588 	return(calloc(1, size)); 
   589 }
   590 
   591 void ::operator delete(void * ptr) {
   592 	if(ptr)
   593 		free(ptr);
   594 }
   595 
   596 void ::operator delete[](void * ptr) {
   597 	if(ptr)
   598 		free(ptr);
   599 }
   600 #endif