1.1 --- a/metamod/mplugin.cpp Sat Aug 21 16:13:14 2004 +0000
1.2 +++ b/metamod/mplugin.cpp Thu Nov 11 23:21:08 2004 +0000
1.3 @@ -396,14 +396,34 @@
1.4 return(NULL);
1.5 }
1.6
1.7 +
1.8 +// Check if a passed string starts with a known platform postfix.
1.9 +// It does not check beyond the period in order to work for both
1.10 +// Linux and Win32.
1.11 +static mBOOL is_platform_postfix(char* pf)
1.12 +{
1.13 + if ( NULL == pf ) return mFALSE;
1.14 +
1.15 + if ( 0 == strncmp(pf, "_i386.", 6) ) return mTRUE;
1.16 + if ( 0 == strncmp(pf, "_i486.", 6) ) return mTRUE;
1.17 + if ( 0 == strncmp(pf, "_i586.", 6) ) return mTRUE;
1.18 + if ( 0 == strncmp(pf, "_i686.", 6) ) return mTRUE;
1.19 + if ( 0 == strncmp(pf, "_amd64.", 7) ) return mTRUE;
1.20 +
1.21 + return mFALSE;
1.22 +}
1.23 +
1.24 +
1.25 // Check if a given plugin is the same but possibly for a
1.26 // different platform. A match is considered to be found if
1.27 // 1. the filename without the path is the same, or
1.28 // 2a. for an attached plugin the logtag is the same, or
1.29 // 2b. the description is the same, or
1.30 // 3. a significant part of the filename is the same.
1.31 -// A significant part of a plugin name is currently defined to
1.32 -// the the part up to the last underscore, if one exists.
1.33 +// A significant part of a plugin name is currently defined to:
1.34 +// the part up to a known platform postfix as determined by
1.35 +// the is_platform_postfix() function (see above), or
1.36 +// the part up to the last dot, if one exists.
1.37 // meta_errno values:
1.38 // - none
1.39 mBOOL MPlugin::platform_match(MPlugin* other) {
1.40 @@ -419,9 +439,9 @@
1.41 if(*desc != '\0' && strcasecmp(desc,other->desc) == 0) return mTRUE;
1.42
1.43 end=strrchr(file, '_');
1.44 - if(end == NULL) end=strrchr(file, '.');
1.45 + if(end == NULL || !is_platform_postfix(end)) end=strrchr(file, '.');
1.46 other_end=strrchr(other->file, '_');
1.47 - if(other_end == NULL) other_end=strrchr(other->file, '.');
1.48 + if(other_end == NULL || !is_platform_postfix(other_end)) other_end=strrchr(other->file, '.');
1.49
1.50 if(end == NULL || other_end == NULL) return mFALSE;
1.51
1.52 @@ -944,9 +964,32 @@
1.53
1.54 // Reload a plugin; unload and load again.
1.55 // meta_errno values:
1.56 +// - ME_NOTALLOWED plugin not loadable after startup
1.57 +// - errno's from check_input()
1.58 // - errno's from unload()
1.59 // - errno's from load()
1.60 mBOOL MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) {
1.61 + if(!check_input()) {
1.62 + // details logged, meta_errno set in check_input()
1.63 + RETURN_ERRNO(mFALSE, ME_ARGUMENT);
1.64 + }
1.65 + // Are we allowed to load this plugin at this time?
1.66 + // If we cannot load the plugin after unloading it, we keep it.
1.67 + if(info->loadable < now) {
1.68 + if(info->loadable > PT_STARTUP) {
1.69 + META_DEBUG(2, ("dll: Delaying reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
1.70 + // caller should give message to user
1.71 + // try to reload again at next opportunity
1.72 + RETURN_ERRNO(mFALSE, ME_DELAYED);
1.73 + }
1.74 + else {
1.75 + META_DEBUG(2, ("dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
1.76 + // don't try to reload again later
1.77 + action=PA_NONE;
1.78 + RETURN_ERRNO(mFALSE, ME_NOTALLOWED);
1.79 + }
1.80 + }
1.81 +
1.82 if(!unload(now, reason)) {
1.83 META_ERROR("dll: Failed to unload plugin '%s' for reloading", desc);
1.84 // meta_errno should be set already in unload()
1.85 @@ -1043,6 +1086,12 @@
1.86
1.87 if(gamedll_funcs.dllapi_table) free(gamedll_funcs.dllapi_table);
1.88 if(gamedll_funcs.newapi_table) free(gamedll_funcs.newapi_table);
1.89 + if(dllapi_table) free(dllapi_table);
1.90 + if(dllapi_post_table) free(dllapi_post_table);
1.91 + if(newapi_table) free(newapi_table);
1.92 + if(newapi_post_table) free(newapi_post_table);
1.93 + if(engine_table) free(engine_table);
1.94 + if(engine_post_table) free(engine_post_table);
1.95
1.96 status=PL_EMPTY;
1.97 action=PA_NULL;
1.98 @@ -1055,6 +1104,8 @@
1.99 newapi_post_table=NULL;
1.100 engine_table=NULL;
1.101 engine_post_table=NULL;
1.102 + gamedll_funcs.dllapi_table = NULL;
1.103 + gamedll_funcs.newapi_table = NULL;
1.104 return(mTRUE);
1.105 }
1.106