From 0709de08f2d4d387e16964b1075914a952dec5d3 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 2 Feb 2020 10:00:43 +0000 Subject: [PATCH] Remove remaining uses of the GLOBAL macro. We now have no remaining things in header files that switch from being a declaration to a definition depending on an awkward #define at the point of including that header. There are still a few mutable variables with external linkage, but at least now each one is defined in a specific source file file appropriate to its purpose and context. The remaining globals as of this commit were: - 'logctx' and 'term', which never needed to be globals in the first place, because they were never actually shared between source files. Now 'term' is just a static in window.c, and 'logctx' is a static in each of that and winplink.c. - 'hinst', which still has external linkage, but is now defined separately in each source file that sets it up (i.e. those with a WinMain) - osMajorVersion, osMinorVersion and osPlatformId, whose definitions now live in winmisc.c alongside the code which sets them up. (Actually they were defined there all along, it turns out, but every toolchain I've built with has commoned them together with the version defined by the GLOBAL in the header.) - 'hwnd', which nothing was actually _using_ any more after previous commits, so all this commit had to do was delete it. --- windows/window.c | 4 ++++ windows/winpgen.c | 3 ++- windows/winpgnt.c | 2 ++ windows/winplink.c | 1 + windows/winstuff.h | 23 +++++------------------ 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/windows/window.c b/windows/window.c index f8a7447b..5bddff03 100644 --- a/windows/window.c +++ b/windows/window.c @@ -147,6 +147,8 @@ enum { SYSMENU, CTXMENU }; static HMENU savedsess_menu; static Conf *conf; +static LogContext *logctx; +static Terminal *term; struct wm_netevent_params { /* Used to pass data to wm_netevent_callback */ @@ -473,6 +475,8 @@ const unsigned cmdline_tooltype = TOOLTYPE_PORT_ARG | TOOLTYPE_NO_VERBOSE_OPTION; +HINSTANCE hinst; + int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; diff --git a/windows/winpgen.c b/windows/winpgen.c index bb915810..d11e2758 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -1551,6 +1551,8 @@ void cleanup_exit(int code) exit(code); } +HINSTANCE hinst; + int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { int argc, i; @@ -1561,7 +1563,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) init_common_controls(); hinst = inst; - hwnd = NULL; /* * See if we can find our Help file. diff --git a/windows/winpgnt.c b/windows/winpgnt.c index 3c435255..87709caf 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -1187,6 +1187,8 @@ static const PageantListenerClientVtable winpgnt_vtable = { static struct winpgnt_client wpc[1]; +HINSTANCE hinst; + int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; diff --git a/windows/winplink.c b/windows/winplink.c index 794aa925..2f4cc043 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -30,6 +30,7 @@ BinarySink *stdout_bs, *stderr_bs; DWORD orig_console_mode; static Backend *backend; +static LogContext *logctx; static Conf *conf; static void plink_echoedit_update(Seat *seat, bool echo, bool edit) diff --git a/windows/winstuff.h b/windows/winstuff.h index c2f65827..0b558c7c 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -210,15 +210,11 @@ typedef void *Ssh_gss_name; #endif /* - * Window handles for the windows that can be running during a - * PuTTY session. + * The all-important instance handle, saved from WinMain in every GUI + * program and exported for other GUI code to pass back to the Windows + * API. */ -GLOBAL HWND hwnd; /* the main terminal window */ - -/* - * The all-important instance handle. - */ -GLOBAL HINSTANCE hinst; +extern HINSTANCE hinst; /* * Help file stuff in winhelp.c. @@ -230,15 +226,6 @@ void launch_help(HWND hwnd, const char *topic); void quit_help(HWND hwnd); int has_embedded_chm(void); /* 1 = yes, 0 = no, -1 = N/A */ -/* - * The terminal and logging context are notionally local to the - * Windows front end, but they must be shared between window.c and - * windlg.c. Likewise the Seat structure for the Windows GUI, and the - * Conf for the main session.. - */ -GLOBAL Terminal *term; -GLOBAL LogContext *logctx; - /* * GUI seat methods in windlg.c, so that the vtable definition in * window.c can refer to them. @@ -579,7 +566,7 @@ HWND event_log_window(void); /* * Exports from winmisc.c. */ -GLOBAL DWORD osMajorVersion, osMinorVersion, osPlatformId; +extern DWORD osMajorVersion, osMinorVersion, osPlatformId; void init_winver(void); void dll_hijacking_protection(void); HMODULE load_system32_dll(const char *libname);