Wrap memmove in glfw with a nice safe macro

This commit is contained in:
Kovid Goyal 2019-06-07 10:01:10 +05:30
parent 857a53e80f
commit 3c7a71772c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 8 deletions

View File

@ -516,10 +516,7 @@ remove_timer_at(size_t idx) {
Timer *t = timers + idx;
if (t->os_timer) { [t->os_timer invalidate]; t->os_timer = NULL; }
if (t->callback_data && t->free_callback_data) { t->free_callback_data(t->id, t->callback_data); t->callback_data = NULL; }
num_timers--;
if (idx < num_timers) {
memmove(timers + idx, timers + idx + 1, sizeof(timers[0]) * (num_timers - idx));
}
remove_i_from_array(timers, idx, num_timers);
}
}

6
glfw/internal.h vendored
View File

@ -196,6 +196,12 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void);
#error "No supported window creation API selected"
#endif
#define remove_i_from_array(array, i, count) { \
count--; \
if (i < count) { \
memmove(array + i, array + i + 1, sizeof(array[0]) * (count - 1)); \
}}
// Constructs a version number string from the public header macros
#define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
#define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)

5
glfw/monitor.c vendored
View File

@ -127,10 +127,7 @@ void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement)
{
if (_glfw.monitors[i] == monitor)
{
_glfw.monitorCount--;
memmove(_glfw.monitors + i,
_glfw.monitors + i + 1,
(_glfw.monitorCount - i) * sizeof(_GLFWmonitor*));
remove_i_from_array(_glfw.monitors, i, _glfw.monitorCount);
break;
}
}