os2 loadso improvements:

- SDL_LoadObject: upon failure, strip the .dll extension and retry,
  but only if module name has no path.
- SDL_LoadFunction: upon failure, retry with an underscore prepended,
  e.g. for gcc-built dlls.

(cherry-picked from commit 3f1b5efcca)
This commit is contained in:
Ozkan Sezer 2022-10-22 14:28:10 +03:00
parent 92937ff5e0
commit eb43d57880

View file

@ -47,11 +47,20 @@ SDL_LoadObject(const char *sofile)
pszModName = OS2_UTF8ToSys(sofile);
ulRC = DosLoadModule(acError, sizeof(acError), pszModName, &hModule);
SDL_free(pszModName);
if (ulRC != NO_ERROR && !SDL_strrchr(pszModName, '\\') && !SDL_strrchr(pszModName, '/')) {
/* strip .dll extension and retry only if name has no path. */
size_t len = SDL_strlen(pszModName);
if (len > 4 && SDL_strcasecmp(&pszModName[len - 4], ".dll") == 0) {
pszModName[len - 4] = '\0';
ulRC = DosLoadModule(acError, sizeof(acError), pszModName, &hModule);
}
}
if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading %s: %s (E%u)", sofile, acError, ulRC);
return NULL;
hModule = NULLHANDLE;
}
SDL_free(pszModName);
return (void *)hModule;
}
@ -63,6 +72,16 @@ SDL_LoadFunction(void *handle, const char *name)
PFN pFN;
ulRC = DosQueryProcAddr((HMODULE)handle, 0, name, &pFN);
if (ulRC != NO_ERROR) {
/* retry with an underscore prepended, e.g. for gcc-built dlls. */
SDL_bool isstack;
size_t len = SDL_strlen(name) + 1;
char *_name = SDL_small_alloc(char, len + 1, &isstack);
_name[0] = '_';
SDL_memcpy(&_name[1], name, len);
ulRC = DosQueryProcAddr((HMODULE)handle, 0, _name, &pFN);
SDL_small_free(_name, isstack);
}
if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading procedure %s (E%u)", name, ulRC);
return NULL;