Skip to content

Commit

Permalink
Make struct init symbols zero
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jul 3, 2023
1 parent 45c9e69 commit 702cd9c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion source/glfw3/api.d
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ struct GLFWgamepadstate {
/** The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
* to 1.0 inclusive.
*/
float[6] axes;
float[6] axes = 0.0;
}


Expand Down
10 changes: 7 additions & 3 deletions source/glfw3/internal.d
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ enum VkResult {
struct VkAllocationCallbacks;

struct VkExtensionProperties{
char[256] extensionName;
char[256] extensionName = '\0';
uint specVersion;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ struct _GLFWerror
{
_GLFWerror* next;
int code;
char[_GLFW_MESSAGE_SIZE] description;
char[_GLFW_MESSAGE_SIZE] description = '\0';
}

// Initialization configuration
Expand Down Expand Up @@ -356,7 +356,8 @@ struct _GLFWwindow
char[GLFW_MOUSE_BUTTON_LAST + 1] mouseButtons = 0;
char[GLFW_KEY_LAST + 1] keys = 0;
// Virtual cursor position when cursor is disabled
double virtualCursorPosX;double virtualCursorPosY;
double virtualCursorPosX = 0.0;
double virtualCursorPosY = 0.0;
GLFWbool rawMouseMotion;

_GLFWcontext context;
Expand Down Expand Up @@ -475,6 +476,9 @@ struct _GLFWmutex
mixin _GLFW_PLATFORM_MUTEX_STATE;
}

// Don't want to emit 137Kb init symbol
static assert(__traits(isZeroInit, _GLFWlibrary), _GLFWlibrary.init);

// Library global data
//
struct _GLFWlibrary
Expand Down
2 changes: 1 addition & 1 deletion source/glfw3/win32_platform.d
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ extern(Windows) {
alias VkFlags VkWin32SurfaceCreateFlagsKHR;

struct VkWin32SurfaceCreateInfoKHR {
VkStructureType sType;
VkStructureType sType = void;
const(void)* pNext;
VkWin32SurfaceCreateFlagsKHR flags;
HINSTANCE hinstance;
Expand Down
44 changes: 22 additions & 22 deletions source/glfw3/x11_header.d
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ struct _XkbNewKeyboardNotify {
int old_min_key_code;
int old_max_key_code;
uint changed;
char req_major;
char req_minor;
char req_major = 0;
char req_minor = 0;
}
alias _XkbNewKeyboardNotify XkbNewKeyboardNotifyEvent;
struct _XkbMapNotifyEvent {
Expand Down Expand Up @@ -527,9 +527,9 @@ struct _XkbStateNotifyEvent {
ubyte compat_lookup_mods;
int ptr_buttons;
KeyCode keycode;
char event_type;
char req_major;
char req_minor;
char event_type = 0;
char req_major = 0;
char req_minor = 0;
}
alias _XkbStateNotifyEvent XkbStateNotifyEvent;
struct _XkbControlsNotify {
Expand All @@ -545,9 +545,9 @@ struct _XkbControlsNotify {
uint enabled_ctrl_changes;
int num_groups;
KeyCode keycode;
char event_type;
char req_major;
char req_minor;
char event_type = 0;
char req_major = 0;
char req_minor = 0;
}
alias _XkbControlsNotify XkbControlsNotifyEvent;
struct _XkbIndicatorNotify {
Expand Down Expand Up @@ -629,7 +629,7 @@ struct _XkbActionMessage {
Bool key_event_follows;
int group;
uint mods;
char[XkbActionMessageLength + 1] message;
char[XkbActionMessageLength + 1] message = '\0';
}
alias _XkbActionMessage XkbActionMessageEvent;
struct _XkbAccessXNotify {
Expand Down Expand Up @@ -979,7 +979,7 @@ struct XGCValues {
int clip_y_origin;
Pixmap clip_mask;
int dash_offset;
char dashes;
char dashes = 0;
}
alias _XGC* GC;
struct Visual {
Expand Down Expand Up @@ -1144,7 +1144,7 @@ struct XKeyboardState {
uint bell_pitch, bell_duration;
c_ulong led_mask;
int global_auto_repeat;
char[32] auto_repeats;
char[32] auto_repeats = '\0';
}
struct XTimeCoord {
Time time;
Expand Down Expand Up @@ -1204,7 +1204,7 @@ struct XMotionEvent {
int x, y;
int x_root, y_root;
uint state;
char is_hint;
char is_hint = 0;
Bool same_screen;
}
alias XMotionEvent XPointerMovedEvent;
Expand Down Expand Up @@ -1244,7 +1244,7 @@ struct XKeymapEvent {
Bool send_event;
Display* display;
Window window;
char[32] key_vector;
char[32] key_vector = '\0';
}
struct XExposeEvent {
int type;
Expand Down Expand Up @@ -1465,7 +1465,7 @@ struct XClientMessageEvent {
Atom message_type;
int format;
union _data {
char[20] b;
char[20] b = '\0';
short[10] s;
c_long[5] l;
}
Expand Down Expand Up @@ -4068,10 +4068,10 @@ struct XIDeviceEvent {
Window root;
Window event;
Window child;
double root_x;
double root_y;
double event_x;
double event_y;
double root_x = 0.0;
double root_y = 0.0;
double event_x = 0.0;
double event_y = 0.0;
int flags;
XIButtonState buttons;
XIValuatorState valuators;
Expand Down Expand Up @@ -4107,10 +4107,10 @@ struct XIEnterEvent {
Window root;
Window event;
Window child;
double root_x;
double root_y;
double event_x;
double event_y;
double root_x = 0;
double root_y = 0;
double event_x = 0;
double event_y = 0;
int mode;
Bool focus;
Bool same_screen;
Expand Down
24 changes: 15 additions & 9 deletions source/glfw3/x11_platform.d
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ alias VkFlags VkXlibSurfaceCreateFlagsKHR;
alias VkFlags VkXcbSurfaceCreateFlagsKHR;

struct VkXlibSurfaceCreateInfoKHR {
VkStructureType sType;
VkStructureType sType = void;
const(void)* pNext;
VkXlibSurfaceCreateFlagsKHR flags;
Display* dpy;
Window window;
}

struct VkXcbSurfaceCreateInfoKHR {
VkStructureType sType;
VkStructureType sType = void;
const(void)* pNext;
VkXcbSurfaceCreateFlagsKHR flags;
xcb_connection_t* connection;
Expand Down Expand Up @@ -205,13 +205,17 @@ struct _GLFWwindowX11 {
GLFWbool transparent;

// Cached position and size used to filter out duplicate events
int width;int height;
int xpos;int ypos;
int width;
int height;
int xpos;
int ypos;

// The last received cursor position, regardless of source
int lastCursorPosX;int lastCursorPosY;
int lastCursorPosX;
int lastCursorPosY;
// The last position the cursor was warped to by GLFW
int warpCursorPosX;int warpCursorPosY;
int warpCursorPosX;
int warpCursorPosY;

// The time of the last KeyPress event
Time lastKeyTime;
Expand All @@ -226,7 +230,8 @@ struct _GLFWlibraryX11 {
Window root;

// System content scale
float contentScaleX;float contentScaleY;
float contentScaleX = 0.0;
float contentScaleY = 0.0;
// Helper window for IPC
Window helperWindowHandle;
// Invisible cursor for hidden cursor mode
Expand All @@ -242,13 +247,14 @@ struct _GLFWlibraryX11 {
// Clipboard string (while the selection is owned)
char* clipboardString;
// Key name string
char[5][GLFW_KEY_LAST + 1] keynames;
char[5][GLFW_KEY_LAST + 1] keynames = '\0';
// X11 keycode to GLFW key LUT
int[256] keycodes;
// GLFW key to X11 keycode LUT
int[GLFW_KEY_LAST + 1] scancodes;
// Where to place the cursor when re-enabled
double restoreCursorPosX;double restoreCursorPosY;
double restoreCursorPosX = 0.0;
double restoreCursorPosY = 0.0;
// The window whose disabled cursor mode is active
_GLFWwindow* disabledCursorWindow;

Expand Down

0 comments on commit 702cd9c

Please sign in to comment.