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.
This commit is contained in:
Ozkan Sezer 2022-10-22 14:28:10 +03:00 committed by Sam Lantinga
parent 3d415bc5d6
commit 3f1b5efcca
1 changed files with 21 additions and 2 deletions

View File

@ -47,11 +47,20 @@ SDL_LoadObject(const char *sofile)
pszModName = OS2_UTF8ToSys(sofile); pszModName = OS2_UTF8ToSys(sofile);
ulRC = DosLoadModule(acError, sizeof(acError), pszModName, &hModule); 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) { if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading %s: %s (E%u)", sofile, acError, ulRC); SDL_SetError("Failed loading %s: %s (E%u)", sofile, acError, ulRC);
return NULL; hModule = NULLHANDLE;
} }
SDL_free(pszModName);
return (void *)hModule; return (void *)hModule;
} }
@ -63,6 +72,16 @@ SDL_LoadFunction(void *handle, const char *name)
PFN pFN; PFN pFN;
ulRC = DosQueryProcAddr((HMODULE)handle, 0, name, &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) { if (ulRC != NO_ERROR) {
SDL_SetError("Failed loading procedure %s (E%u)", name, ulRC); SDL_SetError("Failed loading procedure %s (E%u)", name, ulRC);
return NULL; return NULL;