We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 354

Summary: Extra variable in SDL_LoadFunction()
Product: SDL Reporter: Tolga Dalman <tdalman>
Component: loadsoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 1.2   
Hardware: x86   
OS: All   

Description Tolga Dalman 2006-10-31 11:12:28 UTC
I don't see any sense in using the variable _name, nor copying name into _name.
Here is a patch:

===================================================================
--- SDL_sysloadso.c     (revision 2609)
+++ SDL_sysloadso.c     (working copy)
@@ -46,11 +46,7 @@
        void *symbol = dlsym(handle, name);
        if ( symbol == NULL ) {
                size_t len = 1+SDL_strlen(name)+1;
-               char *_name = SDL_stack_alloc(char, len);
-               _name[0] = '_';
-               SDL_strlcpy(&_name[1], name, len);
                symbol = dlsym(handle, name);
-               SDL_stack_free(_name);
                if ( symbol == NULL ) {
                        SDL_SetError("Failed loading %s: %s", name, (const char *)dlerror());
                }
Comment 1 Ryan C. Gordon 2006-11-08 14:49:10 UTC
Hmm, this looks like it was meant to handle platforms that need a '_' prepended to the function's symbol, but it's not filled in properly.

Probably shouldn't be removed, but it's definitely a bug.

--ryan.

Comment 2 Tolga Dalman 2006-11-09 07:30:38 UTC
In that case, I propose the following patch, which disables that particular code
with a macro:

Index: SDL_sysloadso.c
===================================================================
--- SDL_sysloadso.c     (revision 2905)
+++ SDL_sysloadso.c     (working copy)
@@ -46,11 +46,15 @@
        void *symbol = dlsym(handle, name);
        if ( symbol == NULL ) {
                size_t len = 1+SDL_strlen(name)+1;
+#ifdef DLOPEN_NEED_UNDERSCORE
                char *_name = SDL_stack_alloc(char, len);
                _name[0] = '_';
                SDL_strlcpy(&_name[1], name, len);
+#endif
                symbol = dlsym(handle, name);
+#ifdef DLOPEN_NEED_UNDERSCORE
                SDL_stack_free(_name);
+#endif
                if ( symbol == NULL ) {
                        SDL_SetError("Failed loading %s: %s", name, (const char *)dlerror());
                }
Comment 3 Ryan C. Gordon 2007-02-03 03:18:17 UTC
Fixed in svn revision #2951 for 1.2 branch and #2952 for 1.3 branch.

--ryan.