mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Removed allocator.
This commit is contained in:
@@ -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;
|
||||
|
||||
+1
-43
@@ -35,30 +35,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// 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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+7
-7
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user