diff --git a/examples/boing.c b/examples/boing.c index 8cf5b1dc..33696e46 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -569,7 +569,7 @@ int main( void ) GLFWwindow window; /* Init GLFW */ - if( !glfwInit(NULL) ) + if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); diff --git a/examples/gears.c b/examples/gears.c index cbf9eab9..53d601f3 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) { GLFWwindow window; - if( !glfwInit(NULL) ) + if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); diff --git a/examples/heightmap.c b/examples/heightmap.c index a55df291..f4bec28c 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -573,7 +573,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "ERROR: Unable to initialize GLFW\n"); usage(); diff --git a/examples/splitview.c b/examples/splitview.c index 3fcdd1d8..2cd43fdf 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -442,7 +442,7 @@ int main(void) GLFWwindow window; // Initialise GLFW - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/examples/triangle.c b/examples/triangle.c index e952cc70..e61ea9ab 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -15,7 +15,7 @@ int main(void) GLFWwindow window; // Initialise GLFW - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/examples/wave.c b/examples/wave.c index 9ffcd3f7..1eb8b855 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -379,7 +379,7 @@ int main(int argc, char* argv[]) GLFWwindow window; double t, dt_total, t_old; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "GLFW initialization failed\n"); exit(EXIT_FAILURE); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 59bd6fdb..e84bdbba 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -478,8 +478,6 @@ typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); typedef void (* GLFWscrollfun)(GLFWwindow,int,int); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); -typedef void* (* GLFWmallocfun)(size_t); -typedef void (* GLFWfreefun)(void*); /* The video mode structure used by glfwGetVideoModes */ typedef struct @@ -499,20 +497,13 @@ typedef struct unsigned short blue[GLFW_GAMMA_RAMP_SIZE]; } GLFWgammaramp; -/* Custom memory allocator interface */ -typedef struct -{ - GLFWmallocfun malloc; - GLFWfreefun free; -} GLFWallocator; - /************************************************************************* * Prototypes *************************************************************************/ /* Initialization, termination and version querying */ -GLFWAPI int glfwInit(GLFWallocator* allocator); +GLFWAPI int glfwInit(void); GLFWAPI void glfwTerminate(void); GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); GLFWAPI const char* glfwGetVersionString(void); diff --git a/readme.html b/readme.html index e342a91d..36f0ce47 100644 --- a/readme.html +++ b/readme.html @@ -272,7 +272,6 @@ version of GLFW.

  • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • -
  • Added GLFWallocator type and glfwInit parameter for pluggable memory allocator
  • Added glfwCopyContext function for copying OpenGL state categories between contexts
  • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 0aa10a4a..a167692f 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -152,7 +152,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement) long number; CFTypeRef refType; - _glfwJoystickElement* element = (_glfwJoystickElement*) _glfwMalloc(sizeof(_glfwJoystickElement)); + _glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement)); CFArrayAppendValue(elementsArray, element); @@ -242,7 +242,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* axes = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i); - _glfwFree(axes); + free(axes); } CFArrayRemoveAllValues(joystick->axes); joystick->numAxes = 0; @@ -251,7 +251,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i); - _glfwFree(button); + free(button); } CFArrayRemoveAllValues(joystick->buttons); joystick->numButtons = 0; @@ -260,7 +260,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i); - _glfwFree(hat); + free(hat); } CFArrayRemoveAllValues(joystick->hats); joystick->hats = 0; diff --git a/src/init.c b/src/init.c index 8a28b5cc..336cfe25 100644 --- a/src/init.c +++ b/src/init.c @@ -35,30 +35,6 @@ #include -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -//======================================================================== -// Allocate memory using the allocator -//======================================================================== - -void* _glfwMalloc(size_t size) -{ - return _glfwLibrary.allocator.malloc(size); -} - - -//======================================================================== -// Free memory using the allocator -//======================================================================== - -void _glfwFree(void* ptr) -{ - _glfwLibrary.allocator.free(ptr); -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// @@ -67,31 +43,13 @@ void _glfwFree(void* ptr) // Initialize various GLFW state //======================================================================== -GLFWAPI int glfwInit(GLFWallocator* allocator) +GLFWAPI int glfwInit(void) { if (_glfwInitialized) return GL_TRUE; memset(&_glfwLibrary, 0, sizeof(_glfwLibrary)); - if (allocator) - { - // Verify that the specified model is complete - if (!allocator->malloc || !allocator->free) - { - _glfwSetError(GLFW_INVALID_VALUE, NULL); - return GL_FALSE; - } - - _glfwLibrary.allocator = *allocator; - } - else - { - // Use the libc malloc and free - _glfwLibrary.allocator.malloc = malloc; - _glfwLibrary.allocator.free = free; - } - // Not all window hints have zero as their default value, so this // needs to be here despite the memset above _glfwSetDefaultWindowHints(); diff --git a/src/internal.h b/src/internal.h index ec88b814..1f13ac02 100644 --- a/src/internal.h +++ b/src/internal.h @@ -241,8 +241,6 @@ struct _GLFWlibrary GLFWkeyfun keyCallback; GLFWcharfun charCallback; - GLFWallocator allocator; - GLFWgammaramp currentRamp; GLFWgammaramp originalRamp; int originalRampSize; @@ -325,10 +323,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long // Prototypes for platform independent internal functions //======================================================================== -// Memory management (init.c) -void* _glfwMalloc(size_t size); -void _glfwFree(void* ptr); - // Fullscren management (fullscreen.c) void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); diff --git a/src/win32_window.c b/src/win32_window.c index 6ebe07b4..caf66645 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -47,11 +47,11 @@ static WCHAR* createWideStringFromUTF8(const char* source) if (!length) return NULL; - target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); + target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1)); if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) { - _glfwFree(target); + free(target); return NULL; } @@ -220,7 +220,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) return NULL; } - result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count); + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -1282,13 +1282,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig) closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!closest) { - _glfwFree(fbconfigs); + free(fbconfigs); return 0; } pixelFormat = (int) closest->platformID; - _glfwFree(fbconfigs); + free(fbconfigs); fbconfigs = NULL; closest = NULL; @@ -1383,7 +1383,7 @@ static int createWindow(_GLFWwindow* window, return GL_FALSE; } - _glfwFree(wideTitle); + free(wideTitle); window->WGL.DC = GetDC(window->Win32.handle); if (!window->WGL.DC) @@ -1614,7 +1614,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) SetWindowText(window->Win32.handle, wideTitle); - _glfwFree(wideTitle); + free(wideTitle); } diff --git a/src/window.c b/src/window.c index de89b069..433275b1 100644 --- a/src/window.c +++ b/src/window.c @@ -291,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, height = 480; } - window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow)); + window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow)); if (!window) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -492,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle) *prev = window->next; } - _glfwFree(window); + free(window); } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index bb0a3d53..e71c2a2b 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) return 0; } - rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount); + rgbarray = (int*) malloc(sizeof(int) * viscount); rgbcount = 0; // Build RGB array @@ -387,7 +387,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); sizelist = XRRConfigSizes(sc, &sizecount); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount); for (k = 0; k < sizecount; k++) { @@ -407,7 +407,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount); for (k = 0; k < modecount; k++) { @@ -436,7 +436,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) if (!resarray) { rescount = 1; - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * rescount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount); resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen); resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen); @@ -459,8 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) XFree(vislist); - _glfwFree(resarray); - _glfwFree(rgbarray); + free(resarray); + free(rgbarray); return count; } diff --git a/src/x11_window.c b/src/x11_window.c index 7ad34d05..37915f6a 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -316,7 +316,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) } } - result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count); + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -1415,12 +1415,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!result) { - _glfwFree(fbconfigs); + free(fbconfigs); return GL_FALSE; } closest = *result; - _glfwFree(fbconfigs); + free(fbconfigs); } if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID)) diff --git a/tests/accuracy.c b/tests/accuracy.c index 38f1374e..f235cf75 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -59,7 +59,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/defaults.c b/tests/defaults.c index b50abaaa..d7c5a02c 100644 --- a/tests/defaults.c +++ b/tests/defaults.c @@ -69,7 +69,7 @@ int main(void) int i, width, height; GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/dynamic.c b/tests/dynamic.c index b4257271..8bc5568b 100644 --- a/tests/dynamic.c +++ b/tests/dynamic.c @@ -59,7 +59,7 @@ int main(void) exit(EXIT_FAILURE); } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/tests/events.c b/tests/events.c index 41928db7..fffd9f58 100644 --- a/tests/events.c +++ b/tests/events.c @@ -330,7 +330,7 @@ int main(void) setlocale(LC_ALL, ""); - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/fsaa.c b/tests/fsaa.c index e2fcf387..6cdb77e0 100644 --- a/tests/fsaa.c +++ b/tests/fsaa.c @@ -81,7 +81,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/fsfocus.c b/tests/fsfocus.c index bf634d54..951409a6 100644 --- a/tests/fsfocus.c +++ b/tests/fsfocus.c @@ -75,7 +75,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/gamma.c b/tests/gamma.c index ef8e0b49..b8ec6c45 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -111,7 +111,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index e7ff0294..369e6a96 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -183,7 +183,7 @@ int main(int argc, char** argv) glfwSetErrorCallback(error_callback); - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/iconify.c b/tests/iconify.c index 1ee235f1..6d001ea5 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -90,7 +90,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/joysticks.c b/tests/joysticks.c index d777d431..23ac88a3 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -94,7 +94,7 @@ int main(void) double update; /* Initialise GLFW */ - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/listmodes.c b/tests/listmodes.c index 6962974d..a4648ef6 100644 --- a/tests/listmodes.c +++ b/tests/listmodes.c @@ -21,7 +21,7 @@ int main(void) GLFWvidmode dtmode, modes[400]; int modecount, i; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/peter.c b/tests/peter.c index 7c808229..5ae7ba5d 100644 --- a/tests/peter.c +++ b/tests/peter.c @@ -111,7 +111,7 @@ static GLboolean open_window(void) int main(void) { - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/reopen.c b/tests/reopen.c index 484be996..2922cb84 100644 --- a/tests/reopen.c +++ b/tests/reopen.c @@ -84,7 +84,7 @@ static GLboolean open_window(int width, int height, int mode) { double base; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); return GL_FALSE; diff --git a/tests/sharing.c b/tests/sharing.c index 02b852ef..7d774151 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -115,7 +115,7 @@ int main(int argc, char** argv) GLuint texture; int x, y; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/tearing.c b/tests/tearing.c index 044f8ecc..10170b0f 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -44,7 +44,7 @@ int main(void) float position; GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/title.c b/tests/title.c index 35344a04..7b342d94 100644 --- a/tests/title.c +++ b/tests/title.c @@ -41,7 +41,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/windows.c b/tests/windows.c index f5844762..c7ff32b2 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -46,7 +46,7 @@ int main(void) GLboolean running = GL_TRUE; GLFWwindow windows[4]; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));