Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#17 [PATCH] Deprecation fix for Mac OS X

closed
nobody
None
5
2012-09-15
2009-01-06
SnT2k
No

The Mac OS X version issues deprecation warnings with the NS-loading functions in mach-o/dyld.h, the recommendation is to switch to the dl functions in dlfcn.h. Here's the patch that incorporates it:

--- src/glew.old.c 2008-11-03 14:25:21.000000000 +0800
+++ src/glew.c 2009-01-06 10:42:52.000000000 +0800
@@ -66,29 +66,27 @@
#endif / GLEW_MX /

#if defined(APPLE)
-#include <mach-o dyld.h="">
+#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>

void NSGLGetProcAddress (const GLubyte name)
{
- static const struct mach_header image = NULL;
- NSSymbol symbol;
+ static void
image = NULL;
+ void symbol;
char
symbolName;
if (NULL == image)
{
- image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
+ image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
}
/ prepend a '_' for the Unix C symbol mangling convention /
symbolName = malloc(strlen((const char)name) + 2);
strcpy(symbolName+1, (const char
)name);
symbolName[0] = '_';
- symbol = NULL;
- / if (NSIsSymbolNameDefined(symbolName))
- symbol = NSLookupAndBindSymbol(symbolName);
/
- symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
+
+ symbol = (image ? dlsym(image, symbolName) : NULL);
free(symbolName);
- return symbol ? NSAddressOfSymbol(symbol) : NULL;
+ return symbol;
}
#endif / APPLE /

Discussion

  • It turns out that dlsym doesn't need functions to be prepended with an underscore so the actual block should look like:

    void NSGLGetProcAddress (const GLubyte name)
    {
    static void* image = NULL;

    if (NULL == image)
        image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
    
    return (image ? dlsym(image, (const char *)name) : NULL);
    

    }

     
  • Nigel Stewart
    Nigel Stewart
    2009-02-18

    Thanks for the report.

    In fact there is a related bug also: 2237657

    Would you mind verifying that the patch attached to 2237657 resolves the same issue?

     
  • SnT2k
    SnT2k
    2009-02-20

    The patch works fine except that its line numberings don't match with version 1.5.1
    File Added: glew.c.macosx.patch

     
  • Nigel Stewart
    Nigel Stewart
    2009-02-27

    Thanks for your feedback.

    I'll go with the 2237657 patch on the basis that it is more backwards compatible.

     
  • This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     


Anonymous


Cancel   Add attachments