Support custom dynamic memory functions.

This commit is contained in:
Anthony Smith 2015-07-01 10:01:16 -07:00
parent cf10e318d6
commit 5d4f79f441
29 changed files with 248 additions and 115 deletions

View File

@ -43,6 +43,11 @@ extern "C" {
* This is the reference documentation for context related functions. For more * This is the reference documentation for context related functions. For more
* information, see the @ref context. * information, see the @ref context.
*/ */
/*! @defgroup memory Dynamic Memory
*
* This is the reference documentation for memory management related functions
* and types.
*/
/*! @defgroup init Initialization, version and errors /*! @defgroup init Initialization, version and errors
* *
* This is the reference documentation for initialization and termination of * This is the reference documentation for initialization and termination of
@ -587,6 +592,16 @@ extern "C" {
* the user, as appropriate. * the user, as appropriate.
*/ */
#define GLFW_FORMAT_UNAVAILABLE 0x00010009 #define GLFW_FORMAT_UNAVAILABLE 0x00010009
/*! @brief GLFW has been initialized.
*
* This occurs if a GLFW function was called that may not be called unless the
* library is not [initialized](@ref intro_init).
*
* @par Analysis
* Application programmer error. Terminate GLFW before calling any function
* that requires initialization.
*/
#define GLFW_INITIALIZED 0x00010010
/*! @} */ /*! @} */
#define GLFW_FOCUSED 0x00020001 #define GLFW_FOCUSED 0x00020001
@ -742,6 +757,38 @@ typedef struct GLFWcursor GLFWcursor;
*/ */
typedef void (* GLFWerrorfun)(int,const char*); typedef void (* GLFWerrorfun)(int,const char*);
/*! @brief The function signature for malloc-like memory callbacks.
*
* This is the function signature for allocating memory.
*
* @param[in] size The size in bytes that should be allocated.
*
* @ingroup memory
*
*/
typedef void* (* GLFWmallocfun)(size_t);
/*! @brief The function signature for calloc-like memory callbacks.
*
* This is the function signature for allocating memory calloc-style.
*
* @param[in] num The number of elements to allocate.
* @param[in] size The size of each element.
*
* @ingroup memory
*/
typedef void* (*GLFWcallocfun)(size_t, size_t);
/*! @brief The function signature for freeing allocated memory.
*
* This is the function signature for deallocating memory.
*
* @param[in] ptr The pointer that should be deallocated.
*
* @ingroup memory
*/
typedef void (* GLFWfreefun)(void*);
/*! @brief The function signature for window position callbacks. /*! @brief The function signature for window position callbacks.
* *
* This is the function signature for window position callback functions. * This is the function signature for window position callback functions.
@ -1046,6 +1093,26 @@ typedef struct GLFWimage
* GLFW API functions * GLFW API functions
*************************************************************************/ *************************************************************************/
/*! @brief Sets the memory functions of the GLFW library.
*
* This function sets the memory allocation/deallocation functions that the
* GLFW library will use. This function can be called before calling
* @ref glfwInit.
*
* If @ref glfwInit has already been called, @ref glfwTerminate must be called
* before the memory functions can be changed.
*
* @param[in] mallocfun The function to be called when malloc normally would.
* @param[in] callocfun The function to be called when calloc normally would.
* @param[in] freefun The function to be called when free normally would.
*
* @return 'GL_TRUE' if successful, or 'GL_FALSE' if an
* [error](@ref error_handling) occurred.
*
* @ingroup memory
*/
GLFWAPI int glfwSetMemoryFuncs(GLFWmallocfun mallocfun, GLFWcallocfun callocfun, GLFWfreefun freefun);
/*! @brief Initializes the GLFW library. /*! @brief Initializes the GLFW library.
* *
* This function initializes the GLFW library. Before most GLFW functions can * This function initializes the GLFW library. Before most GLFW functions can

View File

@ -9,7 +9,7 @@ set(common_HEADERS internal.h
"${GLFW_BINARY_DIR}/src/glfw_config.h" "${GLFW_BINARY_DIR}/src/glfw_config.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h")
set(common_SOURCES context.c init.c input.c monitor.c window.c) set(common_SOURCES context.c init.c input.c memory.c monitor.c window.c)
if (_GLFW_COCOA) if (_GLFW_COCOA)
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h iokit_joystick.h

View File

@ -241,7 +241,7 @@ void _glfwPlatformTerminate(void)
[_glfw.ns.cursor release]; [_glfw.ns.cursor release];
_glfw.ns.cursor = nil; _glfw.ns.cursor = nil;
free(_glfw.ns.clipboardString); _memory.free(_glfw.ns.clipboardString);
_glfwTerminateJoysticks(); _glfwTerminateJoysticks();
_glfwTerminateContextAPI(); _glfwTerminateContextAPI();

View File

@ -66,7 +66,7 @@ static char* getDisplayName(CGDirectDisplayID displayID)
size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value),
kCFStringEncodingUTF8); kCFStringEncodingUTF8);
name = calloc(size + 1, sizeof(char)); name = _memory.calloc(size + 1, sizeof(char));
CFStringGetCString(value, name, size, kCFStringEncodingUTF8); CFStringGetCString(value, name, size, kCFStringEncodingUTF8);
CFRelease(info); CFRelease(info);
@ -252,8 +252,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
*count = 0; *count = 0;
CGGetOnlineDisplayList(0, NULL, &displayCount); CGGetOnlineDisplayList(0, NULL, &displayCount);
displays = calloc(displayCount, sizeof(CGDirectDisplayID)); displays = _memory.calloc(displayCount, sizeof(CGDirectDisplayID));
monitors = calloc(displayCount, sizeof(_GLFWmonitor*)); monitors = _memory.calloc(displayCount, sizeof(_GLFWmonitor*));
CGGetOnlineDisplayList(displayCount, displays, &displayCount); CGGetOnlineDisplayList(displayCount, displays, &displayCount);
NSArray* screens = [NSScreen screens]; NSArray* screens = [NSScreen screens];
@ -287,13 +287,13 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
monitor = _glfwAllocMonitor(name, size.width, size.height); monitor = _glfwAllocMonitor(name, size.width, size.height);
monitor->ns.displayID = displays[i]; monitor->ns.displayID = displays[i];
free(name); _memory.free(name);
found++; found++;
monitors[found - 1] = monitor; monitors[found - 1] = monitor;
} }
free(displays); _memory.free(displays);
*count = found; *count = found;
return monitors; return monitors;
@ -327,7 +327,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
found = CFArrayGetCount(modes); found = CFArrayGetCount(modes);
result = calloc(found, sizeof(GLFWvidmode)); result = _memory.calloc(found, sizeof(GLFWvidmode));
for (i = 0; i < found; i++) for (i = 0; i < found; i++)
{ {
@ -373,7 +373,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{ {
uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID); uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID);
CGGammaValue* values = calloc(size * 3, sizeof(CGGammaValue)); CGGammaValue* values = _memory.calloc(size * 3, sizeof(CGGammaValue));
CGGetDisplayTransferByTable(monitor->ns.displayID, CGGetDisplayTransferByTable(monitor->ns.displayID,
size, size,
@ -391,13 +391,13 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
ramp->blue[i] = (unsigned short) (values[i + size * 2] * 65535); ramp->blue[i] = (unsigned short) (values[i + size * 2] * 65535);
} }
free(values); _memory.free(values);
} }
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{ {
int i; int i;
CGGammaValue* values = calloc(ramp->size * 3, sizeof(CGGammaValue)); CGGammaValue* values = _memory.calloc(ramp->size * 3, sizeof(CGGammaValue));
for (i = 0; i < ramp->size; i++) for (i = 0; i < ramp->size; i++)
{ {
@ -412,7 +412,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
values + ramp->size, values + ramp->size,
values + ramp->size * 2); values + ramp->size * 2);
free(values); _memory.free(values);
} }

View File

@ -612,7 +612,7 @@ static int translateKey(unsigned int key)
if (count) if (count)
{ {
NSEnumerator* e = [files objectEnumerator]; NSEnumerator* e = [files objectEnumerator];
char** paths = calloc(count, sizeof(char*)); char** paths = _memory.calloc(count, sizeof(char*));
int i; int i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -621,8 +621,8 @@ static int translateKey(unsigned int key)
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**) paths);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
free(paths[i]); _memory.free(paths[i]);
free(paths); _memory.free(paths);
} }
return YES; return YES;
@ -1285,7 +1285,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return NULL; return NULL;
} }
free(_glfw.ns.clipboardString); _memory.free(_glfw.ns.clipboardString);
_glfw.ns.clipboardString = strdup([object UTF8String]); _glfw.ns.clipboardString = strdup([object UTF8String]);
return _glfw.ns.clipboardString; return _glfw.ns.clipboardString;

View File

@ -100,10 +100,10 @@ static GLboolean chooseFBConfigs(const _GLFWctxconfig* ctxconfig,
return GL_FALSE; return GL_FALSE;
} }
nativeConfigs = calloc(nativeCount, sizeof(EGLConfig)); nativeConfigs = _memory.calloc(nativeCount, sizeof(EGLConfig));
eglGetConfigs(_glfw.egl.display, nativeConfigs, nativeCount, &nativeCount); eglGetConfigs(_glfw.egl.display, nativeConfigs, nativeCount, &nativeCount);
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig)); usableConfigs = _memory.calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0; usableCount = 0;
for (i = 0; i < nativeCount; i++) for (i = 0; i < nativeCount; i++)
@ -163,8 +163,8 @@ static GLboolean chooseFBConfigs(const _GLFWctxconfig* ctxconfig,
if (closest) if (closest)
*result = closest->egl; *result = closest->egl;
free(nativeConfigs); _memory.free(nativeConfigs);
free(usableConfigs); _memory.free(usableConfigs);
return closest ? GL_TRUE : GL_FALSE; return closest ? GL_TRUE : GL_FALSE;
} }

View File

@ -71,7 +71,7 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul
return GL_FALSE; return GL_FALSE;
} }
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig)); usableConfigs = _memory.calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0; usableCount = 0;
for (i = 0; i < nativeCount; i++) for (i = 0; i < nativeCount; i++)
@ -129,7 +129,7 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul
*result = closest->glx; *result = closest->glx;
XFree(nativeConfigs); XFree(nativeConfigs);
free(usableConfigs); _memory.free(usableConfigs);
return closest ? GL_TRUE : GL_FALSE; return closest ? GL_TRUE : GL_FALSE;
} }

View File

@ -28,9 +28,6 @@
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#if defined(_MSC_VER)
#include <malloc.h>
#endif
// Internal key state used for sticky keys // Internal key state used for sticky keys
#define _GLFW_STICK 3 #define _GLFW_STICK 3
@ -365,7 +362,7 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
cursor = calloc(1, sizeof(_GLFWcursor)); cursor = _memory.calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead; cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor; _glfw.cursorListHead = cursor;
@ -395,7 +392,7 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)
return NULL; return NULL;
} }
cursor = calloc(1, sizeof(_GLFWcursor)); cursor = _memory.calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead; cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor; _glfw.cursorListHead = cursor;
@ -440,7 +437,7 @@ GLFWAPI void glfwDestroyCursor(GLFWcursor* handle)
*prev = cursor->next; *prev = cursor->next;
} }
free(cursor); _memory.free(cursor);
} }
GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle) GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle)

View File

@ -69,6 +69,7 @@
#include "../deps/GL/glext.h" #include "../deps/GL/glext.h"
#endif #endif
typedef struct _GLFWmemory _GLFWmemory;
typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWwndconfig _GLFWwndconfig;
typedef struct _GLFWctxconfig _GLFWctxconfig; typedef struct _GLFWctxconfig _GLFWctxconfig;
typedef struct _GLFWfbconfig _GLFWfbconfig; typedef struct _GLFWfbconfig _GLFWfbconfig;
@ -151,6 +152,18 @@ typedef struct _GLFWcursor _GLFWcursor;
// Platform-independent structures // Platform-independent structures
//======================================================================== //========================================================================
/*! @brief Memory Configuration
*
* This is used to store the functions used for allocating and deallocating
* dynamic memory.
*/
struct _GLFWmemory
{
GLFWmallocfun malloc;
GLFWcallocfun calloc;
GLFWfreefun free;
};
/*! @brief Window configuration. /*! @brief Window configuration.
* *
* Parameters relating to the creation of the window but not directly related * Parameters relating to the creation of the window but not directly related
@ -370,6 +383,12 @@ extern GLboolean _glfwInitialized;
*/ */
extern _GLFWlibrary _glfw; extern _GLFWlibrary _glfw;
/*! @brief All global data protected by @ref _glfwInitialized.
* This should only be touched before a call to @ref glfwInit or after a call to
* @ref glfwTerminate.
*/
extern _GLFWmemory _memory;
//======================================================================== //========================================================================
// Platform API functions // Platform API functions

View File

@ -109,7 +109,7 @@ static void addJoystickElement(_GLFWjoydevice* joystick,
if (elementsArray) if (elementsArray)
{ {
_GLFWjoyelement* element = calloc(1, sizeof(_GLFWjoyelement)); _GLFWjoyelement* element = _memory.calloc(1, sizeof(_GLFWjoyelement));
CFArrayAppendValue(elementsArray, element); CFArrayAppendValue(elementsArray, element);
@ -171,22 +171,22 @@ static void removeJoystick(_GLFWjoydevice* joystick)
return; return;
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++) for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
free((void*) CFArrayGetValueAtIndex(joystick->axisElements, i)); _memory.free((void*) CFArrayGetValueAtIndex(joystick->axisElements, i));
CFArrayRemoveAllValues(joystick->axisElements); CFArrayRemoveAllValues(joystick->axisElements);
CFRelease(joystick->axisElements); CFRelease(joystick->axisElements);
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++) for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
free((void*) CFArrayGetValueAtIndex(joystick->buttonElements, i)); _memory.free((void*) CFArrayGetValueAtIndex(joystick->buttonElements, i));
CFArrayRemoveAllValues(joystick->buttonElements); CFArrayRemoveAllValues(joystick->buttonElements);
CFRelease(joystick->buttonElements); CFRelease(joystick->buttonElements);
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++) for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
free((void*) CFArrayGetValueAtIndex(joystick->hatElements, i)); _memory.free((void*) CFArrayGetValueAtIndex(joystick->hatElements, i));
CFArrayRemoveAllValues(joystick->hatElements); CFArrayRemoveAllValues(joystick->hatElements);
CFRelease(joystick->hatElements); CFRelease(joystick->hatElements);
free(joystick->axes); _memory.free(joystick->axes);
free(joystick->buttons); _memory.free(joystick->buttons);
memset(joystick, 0, sizeof(_GLFWjoydevice)); memset(joystick, 0, sizeof(_GLFWjoydevice));
} }
@ -311,9 +311,9 @@ static void matchCallback(void* context,
CFRelease(arrayRef); CFRelease(arrayRef);
joystick->axes = calloc(CFArrayGetCount(joystick->axisElements), joystick->axes = _memory.calloc(CFArrayGetCount(joystick->axisElements),
sizeof(float)); sizeof(float));
joystick->buttons = calloc(CFArrayGetCount(joystick->buttonElements) + joystick->buttons = _memory.calloc(CFArrayGetCount(joystick->buttonElements) +
CFArrayGetCount(joystick->hatElements) * 4, 1); CFArrayGetCount(joystick->hatElements) * 4, 1);
} }

View File

@ -97,8 +97,8 @@ static void openJoystickDevice(const char* path)
ioctl(fd, JSIOCGBUTTONS, &buttonCount); ioctl(fd, JSIOCGBUTTONS, &buttonCount);
_glfw.linux_js.js[joy].buttonCount = (int) buttonCount; _glfw.linux_js.js[joy].buttonCount = (int) buttonCount;
_glfw.linux_js.js[joy].axes = calloc(axisCount, sizeof(float)); _glfw.linux_js.js[joy].axes = _memory.calloc(axisCount, sizeof(float));
_glfw.linux_js.js[joy].buttons = calloc(buttonCount, 1); _glfw.linux_js.js[joy].buttons = _memory.calloc(buttonCount, 1);
_glfw.linux_js.js[joy].present = GL_TRUE; _glfw.linux_js.js[joy].present = GL_TRUE;
#endif // __linux__ #endif // __linux__
@ -146,10 +146,10 @@ static void pollJoystickEvents(void)
{ {
// The joystick was disconnected // The joystick was disconnected
free(_glfw.linux_js.js[i].axes); _memory.free(_glfw.linux_js.js[i].axes);
free(_glfw.linux_js.js[i].buttons); _memory.free(_glfw.linux_js.js[i].buttons);
free(_glfw.linux_js.js[i].name); _memory.free(_glfw.linux_js.js[i].name);
free(_glfw.linux_js.js[i].path); _memory.free(_glfw.linux_js.js[i].path);
memset(&_glfw.linux_js.js[i], 0, sizeof(_glfw.linux_js.js[i])); memset(&_glfw.linux_js.js[i], 0, sizeof(_glfw.linux_js.js[i]));
} }
@ -268,14 +268,14 @@ void _glfwTerminateJoysticks(void)
if (_glfw.linux_js.js[i].present) if (_glfw.linux_js.js[i].present)
{ {
close(_glfw.linux_js.js[i].fd); close(_glfw.linux_js.js[i].fd);
free(_glfw.linux_js.js[i].axes); _memory.free(_glfw.linux_js.js[i].axes);
free(_glfw.linux_js.js[i].buttons); _memory.free(_glfw.linux_js.js[i].buttons);
free(_glfw.linux_js.js[i].name); _memory.free(_glfw.linux_js.js[i].name);
free(_glfw.linux_js.js[i].path); _memory.free(_glfw.linux_js.js[i].path);
} }
} }
regfree(&_glfw.linux_js.regex); reg_memory.free(&_glfw.linux_js.regex);
if (_glfw.linux_js.inotify > 0) if (_glfw.linux_js.inotify > 0)
{ {

55
src/memory.c Normal file
View File

@ -0,0 +1,55 @@
//========================================================================
// GLFW 3.1 Wayland - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2015 Anthony Smith <asmith@anthonycodes.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
#include <malloc.h>
// initialize the global memory state to use
// the standard malloc, calloc and free functions
_GLFWmemory _memory = { malloc, calloc, free };
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
GLFWAPI int glfwSetMemoryFuncs(GLFWmallocfun mallocfun, GLFWcallocfun callocfun, GLFWfreefun freefun)
{
if(_glfwInitialized)
{
_glfwInputError(GLFW_INITIALIZED, NULL);
return GL_FALSE;
}
if(!mallocfun || !callocfun || !freefun)
{
_glfwInputError(GLFW_INVALID_VALUE, NULL);
return GL_FALSE;
}
_memory.malloc = mallocfun;
_memory.calloc = callocfun;
_memory.free = freefun;
return GL_TRUE;
}

View File

@ -58,7 +58,7 @@ int _glfwPlatformInit(void)
_glfwInitTimer(); _glfwInitTimer();
_glfwInitJoysticks(); _glfwInitJoysticks();
_glfw.mir.event_queue = calloc(1, sizeof(EventQueue)); _glfw.mir.event_queue = _memory.calloc(1, sizeof(EventQueue));
_glfwInitEventQueue(_glfw.mir.event_queue); _glfwInitEventQueue(_glfw.mir.event_queue);
error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL); error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL);

View File

@ -99,7 +99,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
if (out->output_id != monitor->mir.output_id) if (out->output_id != monitor->mir.output_id)
continue; continue;
modes = calloc(out->num_modes, sizeof(GLFWvidmode)); modes = _memory.calloc(out->num_modes, sizeof(GLFWvidmode));
for (*found = 0; *found < out->num_modes; (*found)++) for (*found = 0; *found < out->num_modes; (*found)++)
{ {

View File

@ -40,8 +40,8 @@ typedef struct EventNode
static void deleteNode(EventQueue* queue, EventNode* node) static void deleteNode(EventQueue* queue, EventNode* node)
{ {
free(node->event); _memory.free(node->event);
free(node); _memory.free(node);
} }
static int emptyEventQueue(EventQueue* queue) static int emptyEventQueue(EventQueue* queue)
@ -51,8 +51,8 @@ static int emptyEventQueue(EventQueue* queue)
static EventNode* newEventNode(MirEvent const* event, _GLFWwindow* context) static EventNode* newEventNode(MirEvent const* event, _GLFWwindow* context)
{ {
EventNode* new_node = calloc(1, sizeof(EventNode)); EventNode* new_node = _memory.calloc(1, sizeof(EventNode));
new_node->event = calloc(1, sizeof(MirEvent)); new_node->event = _memory.calloc(1, sizeof(MirEvent));
new_node->window = context; new_node->window = context;
memcpy(new_node->event, event, sizeof(MirEvent)); memcpy(new_node->event, event, sizeof(MirEvent));
@ -443,7 +443,7 @@ void _glfwDeleteEventQueue(EventQueue* queue)
node = node_next; node = node_next;
} }
free(queue); _memory.free(queue);
} }
} }

View File

@ -74,7 +74,7 @@ static int refreshVideoModes(_GLFWmonitor* monitor)
qsort(modes, modeCount, sizeof(GLFWvidmode), compareVideoModes); qsort(modes, modeCount, sizeof(GLFWvidmode), compareVideoModes);
free(monitor->modes); _memory.free(monitor->modes);
monitor->modes = modes; monitor->modes = modes;
monitor->modeCount = modeCount; monitor->modeCount = modeCount;
@ -165,7 +165,7 @@ void _glfwInputMonitorChange(void)
_GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM) _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM)
{ {
_GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor)); _GLFWmonitor* monitor = _memory.calloc(1, sizeof(_GLFWmonitor));
monitor->name = strdup(name); monitor->name = strdup(name);
monitor->widthMM = widthMM; monitor->widthMM = widthMM;
monitor->heightMM = heightMM; monitor->heightMM = heightMM;
@ -181,24 +181,24 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor)
_glfwFreeGammaArrays(&monitor->originalRamp); _glfwFreeGammaArrays(&monitor->originalRamp);
_glfwFreeGammaArrays(&monitor->currentRamp); _glfwFreeGammaArrays(&monitor->currentRamp);
free(monitor->modes); _memory.free(monitor->modes);
free(monitor->name); _memory.free(monitor->name);
free(monitor); _memory.free(monitor);
} }
void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size) void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size)
{ {
ramp->red = calloc(size, sizeof(unsigned short)); ramp->red = _memory.calloc(size, sizeof(unsigned short));
ramp->green = calloc(size, sizeof(unsigned short)); ramp->green = _memory.calloc(size, sizeof(unsigned short));
ramp->blue = calloc(size, sizeof(unsigned short)); ramp->blue = _memory.calloc(size, sizeof(unsigned short));
ramp->size = size; ramp->size = size;
} }
void _glfwFreeGammaArrays(GLFWgammaramp* ramp) void _glfwFreeGammaArrays(GLFWgammaramp* ramp)
{ {
free(ramp->red); _memory.free(ramp->red);
free(ramp->green); _memory.free(ramp->green);
free(ramp->blue); _memory.free(ramp->blue);
memset(ramp, 0, sizeof(GLFWgammaramp)); memset(ramp, 0, sizeof(GLFWgammaramp));
} }
@ -210,7 +210,7 @@ void _glfwFreeMonitors(_GLFWmonitor** monitors, int count)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
_glfwFreeMonitor(monitors[i]); _glfwFreeMonitor(monitors[i]);
free(monitors); _memory.free(monitors);
} }
const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,

View File

@ -28,7 +28,6 @@
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <assert.h> #include <assert.h>
@ -122,7 +121,7 @@ static GLboolean choosePixelFormat(_GLFWwindow* window,
NULL); NULL);
} }
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig)); usableConfigs = _memory.calloc(nativeCount, sizeof(_GLFWfbconfig));
usableCount = 0; usableCount = 0;
for (i = 0; i < nativeCount; i++) for (i = 0; i < nativeCount; i++)
@ -240,7 +239,7 @@ static GLboolean choosePixelFormat(_GLFWwindow* window,
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"WGL: The driver does not appear to support OpenGL"); "WGL: The driver does not appear to support OpenGL");
free(usableConfigs); _memory.free(usableConfigs);
return GL_FALSE; return GL_FALSE;
} }
@ -250,12 +249,12 @@ static GLboolean choosePixelFormat(_GLFWwindow* window,
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to find a suitable pixel format"); "WGL: Failed to find a suitable pixel format");
free(usableConfigs); _memory.free(usableConfigs);
return GL_FALSE; return GL_FALSE;
} }
*result = closest->wgl; *result = closest->wgl;
free(usableConfigs); _memory.free(usableConfigs);
return GL_TRUE; return GL_TRUE;
} }

View File

@ -28,7 +28,6 @@
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
@ -283,11 +282,11 @@ WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
if (!length) if (!length)
return NULL; return NULL;
target = calloc(length, sizeof(WCHAR)); target = _memory.calloc(length, sizeof(WCHAR));
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length)) if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length))
{ {
free(target); _memory.free(target);
return NULL; return NULL;
} }
@ -305,11 +304,11 @@ char* _glfwCreateUTF8FromWideString(const WCHAR* source)
if (!length) if (!length)
return NULL; return NULL;
target = calloc(length, sizeof(char)); target = _memory.calloc(length, sizeof(char));
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL)) if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL))
{ {
free(target); _memory.free(target);
return NULL; return NULL;
} }
@ -360,7 +359,7 @@ void _glfwPlatformTerminate(void)
UIntToPtr(_glfw.win32.foregroundLockTimeout), UIntToPtr(_glfw.win32.foregroundLockTimeout),
SPIF_SENDCHANGE); SPIF_SENDCHANGE);
free(_glfw.win32.clipboardString); _memory.free(_glfw.win32.clipboardString);
_glfwTerminateJoysticks(); _glfwTerminateJoysticks();
_glfwTerminateContextAPI(); _glfwTerminateContextAPI();

View File

@ -30,7 +30,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <malloc.h>
// These constants are missing on MinGW // These constants are missing on MinGW
#ifndef EDS_ROTATEDMODE #ifndef EDS_ROTATEDMODE
@ -150,7 +149,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
GetDeviceCaps(dc, VERTSIZE)); GetDeviceCaps(dc, VERTSIZE));
DeleteDC(dc); DeleteDC(dc);
free(name); _memory.free(name);
wcscpy(monitor->win32.adapterName, adapter.DeviceName); wcscpy(monitor->win32.adapterName, adapter.DeviceName);
wcscpy(monitor->win32.displayName, display.DeviceName); wcscpy(monitor->win32.displayName, display.DeviceName);

View File

@ -66,7 +66,6 @@
#include <dbt.h> #include <dbt.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <malloc.h>
#define strdup _strdup #define strdup _strdup
#endif #endif

View File

@ -28,7 +28,6 @@
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#include <windowsx.h> #include <windowsx.h>
#include <shellapi.h> #include <shellapi.h>
@ -601,7 +600,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
int i; int i;
const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0); const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0);
char** paths = calloc(count, sizeof(char*)); char** paths = _memory.calloc(count, sizeof(char*));
// Move the mouse to the position of the drop // Move the mouse to the position of the drop
DragQueryPoint(hDrop, &pt); DragQueryPoint(hDrop, &pt);
@ -610,19 +609,19 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
const UINT length = DragQueryFileW(hDrop, i, NULL, 0); const UINT length = DragQueryFileW(hDrop, i, NULL, 0);
WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); WCHAR* buffer = _memory.calloc(length + 1, sizeof(WCHAR));
DragQueryFileW(hDrop, i, buffer, length + 1); DragQueryFileW(hDrop, i, buffer, length + 1);
paths[i] = _glfwCreateUTF8FromWideString(buffer); paths[i] = _glfwCreateUTF8FromWideString(buffer);
free(buffer); _memory.free(buffer);
} }
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**) paths);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
free(paths[i]); _memory.free(paths[i]);
free(paths); _memory.free(paths);
DragFinish(hDrop); DragFinish(hDrop);
return 0; return 0;
@ -696,7 +695,7 @@ static int createWindow(_GLFWwindow* window,
GetModuleHandleW(NULL), GetModuleHandleW(NULL),
window); // Pass object to WM_CREATE window); // Pass object to WM_CREATE
free(wideTitle); _memory.free(wideTitle);
if (!window->win32.handle) if (!window->win32.handle)
{ {
@ -869,7 +868,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
} }
SetWindowTextW(window->win32.handle, wideTitle); SetWindowTextW(window->win32.handle, wideTitle);
free(wideTitle); _memory.free(wideTitle);
} }
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
@ -1224,7 +1223,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize); stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
if (!stringHandle) if (!stringHandle)
{ {
free(wideString); _memory.free(wideString);
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to allocate global handle for clipboard"); "Win32: Failed to allocate global handle for clipboard");
@ -1237,7 +1236,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
if (!OpenClipboard(window->win32.handle)) if (!OpenClipboard(window->win32.handle))
{ {
GlobalFree(stringHandle); GlobalFree(stringHandle);
free(wideString); _memory.free(wideString);
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard"); _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard");
return; return;
@ -1247,7 +1246,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
SetClipboardData(CF_UNICODETEXT, stringHandle); SetClipboardData(CF_UNICODETEXT, stringHandle);
CloseClipboard(); CloseClipboard();
free(wideString); _memory.free(wideString);
} }
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
@ -1270,7 +1269,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return NULL; return NULL;
} }
free(_glfw.win32.clipboardString); _memory.free(_glfw.win32.clipboardString);
_glfw.win32.clipboardString = _glfw.win32.clipboardString =
_glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); _glfwCreateUTF8FromWideString(GlobalLock(stringHandle));

View File

@ -153,7 +153,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
if (!_glfwIsValidContextConfig(&ctxconfig)) if (!_glfwIsValidContextConfig(&ctxconfig))
return NULL; return NULL;
window = calloc(1, sizeof(_GLFWwindow)); window = _memory.calloc(1, sizeof(_GLFWwindow));
window->next = _glfw.windowListHead; window->next = _glfw.windowListHead;
_glfw.windowListHead = window; _glfw.windowListHead = window;
@ -400,7 +400,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
*prev = window->next; *prev = window->next;
} }
free(window); _memory.free(window);
} }
GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle) GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle)

View File

@ -63,7 +63,7 @@ void _glfwTerminateJoysticks(void)
int i; int i;
for (i = 0; i < GLFW_JOYSTICK_LAST; i++) for (i = 0; i < GLFW_JOYSTICK_LAST; i++)
free(_glfw.winmm_js[i].name); _memory.free(_glfw.winmm_js[i].name);
} }
@ -169,7 +169,7 @@ const char* _glfwPlatformGetJoystickName(int joy)
if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
return NULL; return NULL;
free(_glfw.winmm_js[joy].name); _memory.free(_glfw.winmm_js[joy].name);
_glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname);
return _glfw.winmm_js[joy].name; return _glfw.winmm_js[joy].name;

View File

@ -554,7 +554,7 @@ int _glfwPlatformInit(void)
_glfw.wl.registry = wl_display_get_registry(_glfw.wl.display); _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display);
wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL); wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL);
_glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*)); _glfw.wl.monitors = _memory.calloc(4, sizeof(_GLFWmonitor*));
_glfw.wl.monitorsSize = 4; _glfw.wl.monitorsSize = 4;
_glfw.wl.xkb.context = xkb_context_new(0); _glfw.wl.xkb.context = xkb_context_new(0);

View File

@ -139,7 +139,7 @@ void _glfwAddOutput(uint32_t name, uint32_t version)
return; return;
} }
monitor->wl.modes = calloc(4, sizeof(_GLFWvidmodeWayland)); monitor->wl.modes = _memory.calloc(4, sizeof(_GLFWvidmodeWayland));
monitor->wl.modesSize = 4; monitor->wl.modesSize = 4;
monitor->wl.output = output; monitor->wl.output = output;
@ -173,12 +173,12 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
if (_glfw.wl.monitorsCount == 0) if (_glfw.wl.monitorsCount == 0)
goto err; goto err;
monitors = calloc(monitorsCount, sizeof(_GLFWmonitor*)); monitors = _memory.calloc(monitorsCount, sizeof(_GLFWmonitor*));
for (i = 0; i < monitorsCount; i++) for (i = 0; i < monitorsCount; i++)
{ {
_GLFWmonitor* origMonitor = _glfw.wl.monitors[i]; _GLFWmonitor* origMonitor = _glfw.wl.monitors[i];
monitor = calloc(1, sizeof(_GLFWmonitor)); monitor = _memory.calloc(1, sizeof(_GLFWmonitor));
monitor->modes = monitor->modes =
_glfwPlatformGetVideoModes(origMonitor, _glfwPlatformGetVideoModes(origMonitor,
@ -213,7 +213,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
GLFWvidmode *modes; GLFWvidmode *modes;
int i, modesCount = monitor->wl.modesCount; int i, modesCount = monitor->wl.modesCount;
modes = calloc(modesCount, sizeof(GLFWvidmode)); modes = _memory.calloc(modesCount, sizeof(GLFWvidmode));
for (i = 0; i < modesCount; i++) for (i = 0; i < modesCount; i++)
modes[i] = monitor->wl.modes[i].base; modes[i] = monitor->wl.modes[i].base;

View File

@ -187,13 +187,13 @@ createAnonymousFile(off_t size)
return -1; return -1;
} }
name = malloc(strlen(path) + sizeof(template)); name = _memory.malloc(strlen(path) + sizeof(template));
strcpy(name, path); strcpy(name, path);
strcat(name, template); strcat(name, template);
fd = createTmpfileCloexec(name); fd = createTmpfileCloexec(name);
free(name); _memory.free(name);
if (fd < 0) if (fd < 0)
return -1; return -1;

View File

@ -766,7 +766,7 @@ void _glfwPlatformTerminate(void)
_glfw.x11.cursor = (Cursor) 0; _glfw.x11.cursor = (Cursor) 0;
} }
free(_glfw.x11.clipboardString); _memory.free(_glfw.x11.clipboardString);
if (_glfw.x11.im) if (_glfw.x11.im)
{ {

View File

@ -214,7 +214,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
RROutput primary = XRRGetOutputPrimary(_glfw.x11.display, RROutput primary = XRRGetOutputPrimary(_glfw.x11.display,
_glfw.x11.root); _glfw.x11.root);
monitors = calloc(sr->noutput, sizeof(_GLFWmonitor*)); monitors = _memory.calloc(sr->noutput, sizeof(_GLFWmonitor*));
if (_glfw.x11.xinerama.available) if (_glfw.x11.xinerama.available)
screens = XineramaQueryScreens(_glfw.x11.display, &screenCount); screens = XineramaQueryScreens(_glfw.x11.display, &screenCount);
@ -286,14 +286,14 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
"X11: RandR monitor support seems broken"); "X11: RandR monitor support seems broken");
_glfw.x11.randr.monitorBroken = GL_TRUE; _glfw.x11.randr.monitorBroken = GL_TRUE;
free(monitors); _memory.free(monitors);
monitors = NULL; monitors = NULL;
} }
} }
if (!monitors) if (!monitors)
{ {
monitors = calloc(1, sizeof(_GLFWmonitor*)); monitors = _memory.calloc(1, sizeof(_GLFWmonitor*));
monitors[0] = _glfwAllocMonitor("Display", monitors[0] = _glfwAllocMonitor("Display",
DisplayWidthMM(_glfw.x11.display, DisplayWidthMM(_glfw.x11.display,
_glfw.x11.screen), _glfw.x11.screen),
@ -348,7 +348,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
result = calloc(oi->nmode, sizeof(GLFWvidmode)); result = _memory.calloc(oi->nmode, sizeof(GLFWvidmode));
for (i = 0; i < oi->nmode; i++) for (i = 0; i < oi->nmode; i++)
{ {
@ -379,7 +379,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
else else
{ {
*count = 1; *count = 1;
result = calloc(1, sizeof(GLFWvidmode)); result = _memory.calloc(1, sizeof(GLFWvidmode));
_glfwPlatformGetVideoMode(monitor, result); _glfwPlatformGetVideoMode(monitor, result);
} }

View File

@ -223,7 +223,7 @@ static char** parseUriList(char* text, int* count)
(*count)++; (*count)++;
char* path = calloc(strlen(line) + 1, 1); char* path = _memory.calloc(strlen(line) + 1, 1);
paths = realloc(paths, *count * sizeof(char*)); paths = realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path; paths[*count - 1] = path;
@ -672,7 +672,7 @@ static Atom writeTargetToProperty(const XSelectionRequestEvent* request)
static void handleSelectionClear(XEvent* event) static void handleSelectionClear(XEvent* event)
{ {
free(_glfw.x11.clipboardString); _memory.free(_glfw.x11.clipboardString);
_glfw.x11.clipboardString = NULL; _glfw.x11.clipboardString = NULL;
} }
@ -1202,8 +1202,8 @@ static void processEvent(XEvent *event)
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**) paths);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
free(paths[i]); _memory.free(paths[i]);
free(paths); _memory.free(paths);
} }
XFree(data); XFree(data);
@ -1853,7 +1853,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{ {
free(_glfw.x11.clipboardString); _memory.free(_glfw.x11.clipboardString);
_glfw.x11.clipboardString = strdup(string); _glfw.x11.clipboardString = strdup(string);
XSetSelectionOwner(_glfw.x11.display, XSetSelectionOwner(_glfw.x11.display,
@ -1884,7 +1884,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return _glfw.x11.clipboardString; return _glfw.x11.clipboardString;
} }
free(_glfw.x11.clipboardString); _memory.free(_glfw.x11.clipboardString);
_glfw.x11.clipboardString = NULL; _glfw.x11.clipboardString = NULL;
for (i = 0; i < formatCount; i++) for (i = 0; i < formatCount; i++)