From 501199a3dbccc83f91a561c6664ae4c1d3dde20a Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 8 Oct 2012 04:53:18 -0800 Subject: [PATCH] Code cleanup for cygw32 --- src/ChangeLog | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.in | 2 +- src/cygw32.c | 8 ++++---- src/cygw32.h | 5 ----- src/emacs.c | 9 ++++---- src/unexcw.c | 1 + src/unexw32.c | 1 + src/w32.c | 1 + src/w32common.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ src/w32console.c | 2 +- src/w32fns.c | 19 ++++++++++------- src/w32heap.c | 16 +-------------- src/w32heap.h | 23 --------------------- src/w32menu.c | 2 +- src/w32proc.c | 1 + src/w32select.c | 2 +- src/w32select.h | 2 -- src/w32term.h | 6 +++--- 18 files changed, 139 insertions(+), 67 deletions(-) create mode 100644 src/w32common.h diff --git a/src/ChangeLog b/src/ChangeLog index 9e8377c2f7c..b252f5deef8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -9,6 +9,59 @@ 'const char *'. (x_to_w32_color): Don't modify the argument, modify a copy instead. +2012-10-08 Daniel Colascione + + * w32term.h (WM_EMACS_BRINGTOTOP, WM_EMACS_INPUT_READY) + (WM_EMACS_END): Change WM_EMACS_BRINGTOTOP from 22 to 21 to close + accidental message numbering hole. Change other messages to + match. + + * w32select.h (HAVE_W32SELECT): Remove. + + * w32select.c, w32proc.c, w32menu.c, w32console.c, w32.c: Include + w32common.h instead of w32heap.h + + * w32heap.h (ROUND_UP, ROUND_DOWN, get_page_size) + (get_allocation_unit, get_processor_type, get_w32_major_version) + (get_w32_minor_version, sysinfo_cache, osinfo_cache) + (w32_major_version, w32_minor_version, w32_build_number, OS_9X) + (OS_NT, os_subtype, cache_system_info): Move declarations to + w32common. + + * w32heap.c: Include w32common.h. + (sysinfo_cache, syspage_mask, osinfo_cache, w32_major_version) + (w32_minor_version, w32_build_number, w32_subtype): Remove + duplicate definitions. + + * w32fns.c: Include w32common.h; include w32heap.h only in + WINDOWSNT. + + (Fx_file_dialog): Clarify comment on GetOpenFileName structure. + Use `report_file_error' instead of `error' in order to better + inform users of what went wrong. Increase NTGUI_UNICODE file + dialog box file name length to 32k, the maximum allowed by the NT + kernel. + + * w32common.h: New file. + (ROUND_UP, ROUND_DOWN, get_page_size) + (get_allocation_unit, get_processor_type, get_w32_major_version) + (get_w32_minor_version, sysinfo_cache, osinfo_cache) + (w32_major_version, w32_minor_version, w32_build_number, OS_9X) + (OS_NT, os_subtype, cache_system_info): Move here. + + * unexw32.c, unexcw.c: Include w32common.h. + + * emacs.c (main): Use (defined (WINDOWSNT) || defined + HAVE_NTGUI) instead of removed HAVE_W32SELECT to decide whether + to call syms_of_w32select. + + * cygw32.h: Remove obsolete EXFUN declarations. + + * cygw32.c (Qutf_16_le): Rename to Qutf_16le. + + * Makefile.in (SOME_MACHINE_OBJECTS): Reverse accidental removal + of w32inevt.o from SOME_MACHINE_OBJECTS. + 2012-10-08 Daniel Colascione * image.c: Permanent fix for JPEG compilation issue --- limit diff --git a/src/Makefile.in b/src/Makefile.in index e704f2f5c0c..c24e421bbbc 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -357,7 +357,7 @@ SOME_MACHINE_OBJECTS = dosfns.o msdos.o \ xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ fontset.o dbusbind.o cygw32.o \ nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \ - w32.o w32console.o w32fns.o w32heap.o \ + w32.o w32console.o w32fns.o w32heap.o w32inevt.o \ w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ w16select.o widget.o xfont.o ftfont.o xftfont.o ftxfont.o gtkutil.o \ xsettings.o xgselect.o termcap.o diff --git a/src/cygw32.c b/src/cygw32.c index ab7ee91a138..c45a45648e9 100644 --- a/src/cygw32.c +++ b/src/cygw32.c @@ -22,7 +22,7 @@ along with GNU Emacs. If not, see . */ #include "buffer.h" #include #include -static Lisp_Object Qutf_16_le; +static Lisp_Object Qutf_16le; static Lisp_Object fchdir_unwind (Lisp_Object dir_fd) @@ -117,13 +117,13 @@ from_unicode (Lisp_Object str) str = Fsubstring (str, make_number (0), make_number (-1)); } - return code_convert_string_norecord (str, Qutf_16_le, 0); + return code_convert_string_norecord (str, Qutf_16le, 0); } wchar_t * to_unicode (Lisp_Object str, Lisp_Object *buf) { - *buf = code_convert_string_norecord (str, Qutf_16_le, 1); + *buf = code_convert_string_norecord (str, Qutf_16le, 1); /* We need to make a another copy (in addition to the one made by code_convert_string_norecord) to ensure that the final string is _doubly_ zero terminated --- that is, that the string is @@ -163,7 +163,7 @@ void syms_of_cygw32 (void) { /* No, not utf-16-le: that one has a BOM. */ - DEFSYM (Qutf_16_le, "utf-16le"); + DEFSYM (Qutf_16le, "utf-16le"); defsubr (&Scygwin_convert_path_from_windows); defsubr (&Scygwin_convert_path_to_windows); } diff --git a/src/cygw32.h b/src/cygw32.h index 22b6f5692da..78e77a9a141 100644 --- a/src/cygw32.h +++ b/src/cygw32.h @@ -46,11 +46,6 @@ extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf); object, to a multi-byte Emacs string, and return it. */ extern Lisp_Object from_unicode (Lisp_Object str); -/* *** Path conversion. *** */ - -EXFUN (Fcygwin_convert_path_to_windows, 2); -EXFUN (Fcygwin_convert_path_from_windows, 2); - /* *** Misc *** */ extern void syms_of_cygw32 (void); extern char * w32_strerror (int error_no); diff --git a/src/emacs.c b/src/emacs.c index 0a9cc484f7a..203514fe204 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1415,9 +1415,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem syms_of_fontset (); #endif /* HAVE_NTGUI */ -#ifdef HAVE_W32SELECT +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) syms_of_w32select (); -#endif /* HAVE_W32SELECT */ +#endif /* WINDOWSNT || HAVE_NTGUI */ #ifdef MSDOS syms_of_xmenu (); @@ -1465,9 +1465,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem globals_of_w32menu (); #endif /* HAVE_NTGUI */ -#ifdef HAVE_W32SELECT +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) globals_of_w32select (); -#endif /* HAVE_W32SELECT */ +#endif /* WINDOWSNT || HAVE_NTGUI */ + } init_charset (); diff --git a/src/unexcw.c b/src/unexcw.c index 96c4b4a9aec..8c5d574530d 100644 --- a/src/unexcw.c +++ b/src/unexcw.c @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see . */ #include #include "unexec.h" +#include "w32common.h" #include #include diff --git a/src/unexw32.c b/src/unexw32.c index d57378b2421..82671d0f120 100644 --- a/src/unexw32.c +++ b/src/unexw32.c @@ -22,6 +22,7 @@ along with GNU Emacs. If not, see . */ #include #include "unexec.h" +#include "w32common.h" #include #include diff --git a/src/w32.c b/src/w32.c index 85210cb8e4c..b50cd13517d 100644 --- a/src/w32.c +++ b/src/w32.c @@ -173,6 +173,7 @@ typedef struct _REPARSE_DATA_BUFFER { #include "w32.h" #include "ndir.h" +#include "w32common.h" #include "w32heap.h" #include "systime.h" #include "dispextern.h" /* for xstrcasecmp */ diff --git a/src/w32common.h b/src/w32common.h new file mode 100644 index 00000000000..50724e5553c --- /dev/null +++ b/src/w32common.h @@ -0,0 +1,53 @@ +/* Common functions for Microsoft Windows builds of Emacs + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Emacs. + +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +GNU Emacs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Emacs. If not, see . + +*/ + +#ifndef W32COMMON_H +#define W32COMMON_H + +#include + +#define ROUND_UP(p, align) (((DWORD_PTR)(p) + (align)-1) & ~((DWORD_PTR)(align)-1)) +#define ROUND_DOWN(p, align) ((DWORD_PTR)(p) & ~((DWORD_PTR)(align)-1)) + +#define get_page_size() sysinfo_cache.dwPageSize +#define get_allocation_unit() sysinfo_cache.dwAllocationGranularity +#define get_processor_type() sysinfo_cache.dwProcessorType +#define get_w32_major_version() w32_major_version +#define get_w32_minor_version() w32_minor_version + +extern SYSTEM_INFO sysinfo_cache; +extern OSVERSIONINFO osinfo_cache; +extern unsigned long syspage_mask; + +extern int w32_major_version; +extern int w32_minor_version; +extern int w32_build_number; + +enum { + OS_9X = 1, + OS_NT +}; + +extern int os_subtype; + +/* Cache system info, e.g., the NT page size. */ +extern void cache_system_info (void); + +#endif /* W32COMMON_H */ diff --git a/src/w32console.c b/src/w32console.c index 5a44d3748a2..f0574689bf1 100644 --- a/src/w32console.c +++ b/src/w32console.c @@ -37,7 +37,7 @@ along with GNU Emacs. If not, see . */ #include "termchar.h" #include "dispextern.h" #include "w32term.h" -#include "w32heap.h" /* for os_subtype */ +#include "w32common.h" /* for os_subtype */ #include "w32inevt.h" /* from window.c */ diff --git a/src/w32fns.c b/src/w32fns.c index 8620fa8b1e8..e728d19a9b3 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -45,7 +45,11 @@ along with GNU Emacs. If not, see . */ #include "systime.h" #include "termhooks.h" +#include "w32common.h" + +#ifdef WINDOWSNT #include "w32heap.h" +#endif /* WINDOWSNT */ #if CYGWIN #include "cygw32.h" @@ -6111,7 +6115,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) } new_file_details; #ifdef NTGUI_UNICODE - wchar_t filename_buf[MAX_PATH + 1]; + wchar_t filename_buf[32*1024 + 1]; // NT kernel maximum OPENFILENAMEW * file_details = &new_file_details.details; #else /* not NTGUI_UNICODE */ char filename_buf[MAX_PATH + 1]; @@ -6173,11 +6177,12 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) unixtodos_filename (SDATA (filename)); #endif /* NTGUI_UNICODE */ - /* Fill in the structure for the call to GetOpenFileName below. For - NTGUI_UNICODE builds (which run only on NT), we just use the - actual size of the structure. For non-NTGUI_UNICODE builds, we - tell the OS we're using an old version of the structure if it's not - new enough to support the newer version. */ + /* Fill in the structure for the call to GetOpenFileName below. + For NTGUI_UNICODE builds (which run only on NT), we just use + the actual size of the structure. For non-NTGUI_UNICODE + builds, we tell the OS we're using an old version of the + structure if the OS isn't new enough to support the newer + version. */ memset (&new_file_details, 0, sizeof (new_file_details)); if (w32_major_version > 4 && w32_major_version < 95) @@ -6187,7 +6192,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) /* Set up the inout parameter for the selected file name. */ if (SBYTES (filename) + 1 > sizeof (filename_buf)) - error ("filename too long"); + report_file_error ("filename too long", default_filename); memcpy (filename_buf, SDATA (filename), SBYTES (filename) + 1); file_details->lpstrFile = filename_buf; diff --git a/src/w32heap.c b/src/w32heap.c index 0ff473fb0a8..311e1064434 100644 --- a/src/w32heap.c +++ b/src/w32heap.c @@ -23,26 +23,12 @@ along with GNU Emacs. If not, see . */ #include #include +#include "w32common.h" #include "w32heap.h" #include "lisp.h" /* for VALMASK */ #define RVA_TO_PTR(rva) ((unsigned char *)((DWORD_PTR)(rva) + (DWORD_PTR)GetModuleHandle (NULL))) -/* This gives us the page size and the size of the allocation unit on NT. */ -SYSTEM_INFO sysinfo_cache; - -/* This gives us version, build, and platform identification. */ -extern unsigned long syspage_mask; -OSVERSIONINFO osinfo_cache; - -/* The major and minor versions of NT. */ -int w32_major_version; -int w32_minor_version; -int w32_build_number; - -/* Distinguish between Windows NT and Windows 95. */ -int os_subtype; - /* Emulate getpagesize. */ int getpagesize (void) diff --git a/src/w32heap.h b/src/w32heap.h index aae4845b4cc..1630864875f 100644 --- a/src/w32heap.h +++ b/src/w32heap.h @@ -24,9 +24,6 @@ along with GNU Emacs. If not, see . #include -#define ROUND_UP(p, align) (((DWORD_PTR)(p) + (align)-1) & ~((DWORD_PTR)(align)-1)) -#define ROUND_DOWN(p, align) ((DWORD_PTR)(p) & ~((DWORD_PTR)(align)-1)) - /* * Heap related stuff. */ @@ -34,28 +31,11 @@ along with GNU Emacs. If not, see . #define get_committed_heap_size() (get_data_end () - get_data_start ()) #define get_heap_start() get_data_start () #define get_heap_end() get_data_end () -#define get_page_size() sysinfo_cache.dwPageSize -#define get_allocation_unit() sysinfo_cache.dwAllocationGranularity -#define get_processor_type() sysinfo_cache.dwProcessorType -#define get_w32_major_version() w32_major_version -#define get_w32_minor_version() w32_minor_version extern unsigned char *get_data_start (void); extern unsigned char *get_data_end (void); extern size_t reserved_heap_size; -extern SYSTEM_INFO sysinfo_cache; -extern OSVERSIONINFO osinfo_cache; extern BOOL using_dynamic_heap; -extern int w32_major_version; -extern int w32_minor_version; -extern int w32_build_number; - -enum { - OS_9X = 1, - OS_NT -}; - -extern int os_subtype; /* Emulation of Unix sbrk(). */ extern void *sbrk (ptrdiff_t size); @@ -66,9 +46,6 @@ extern void init_heap (void); /* Round the heap to this size. */ extern void round_heap (size_t size); -/* Cache system info, e.g., the NT page size. */ -extern void cache_system_info (void); - /* ----------------------------------------------------------------- */ /* Useful routines for manipulating memory-mapped files. */ diff --git a/src/w32menu.c b/src/w32menu.c index 40ee82d42d5..36bf9574fdc 100644 --- a/src/w32menu.c +++ b/src/w32menu.c @@ -56,7 +56,7 @@ along with GNU Emacs. If not, see . */ #include "dispextern.h" -#include "w32heap.h" /* for osinfo_cache */ +#include "w32common.h" /* for osinfo_cache */ #undef HAVE_DIALOGS /* TODO: Implement native dialogs. */ diff --git a/src/w32proc.c b/src/w32proc.c index 7d0039d0d5e..7e8183b0e82 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -51,6 +51,7 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD); #include "lisp.h" #include "w32.h" +#include "w32common.h" #include "w32heap.h" #include "systime.h" #include "syswait.h" diff --git a/src/w32select.c b/src/w32select.c index 1690c3b7824..ee0e6d16b11 100644 --- a/src/w32select.c +++ b/src/w32select.c @@ -75,7 +75,7 @@ along with GNU Emacs. If not, see . */ #include #include "lisp.h" #include "w32term.h" /* for all of the w32 includes */ -#include "w32heap.h" /* os_subtype */ +#include "w32common.h" /* os_subtype */ #include "blockinput.h" #include "charset.h" #include "coding.h" diff --git a/src/w32select.h b/src/w32select.h index 6924d4d51ae..e895c3d9bf2 100644 --- a/src/w32select.h +++ b/src/w32select.h @@ -21,8 +21,6 @@ along with GNU Emacs. If not, see . */ #define W32SELECT_H #include -#define HAVE_W32SELECT 1 - extern void syms_of_w32select (void); extern void globals_of_w32select (void); extern void term_w32select (void); diff --git a/src/w32term.h b/src/w32term.h index 9fb37b9f030..83f9e7b98dc 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -619,9 +619,9 @@ do { \ #define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18) #define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) #define WM_EMACS_PAINT (WM_EMACS_START + 20) -#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 22) -#define WM_EMACS_INPUT_READY (WM_EMACS_START + 23) -#define WM_EMACS_END (WM_EMACS_START + 24) +#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21) +#define WM_EMACS_INPUT_READY (WM_EMACS_START + 22) +#define WM_EMACS_END (WM_EMACS_START + 23) #define WND_FONTWIDTH_INDEX (0) #define WND_LINEHEIGHT_INDEX (4) -- 2.39.2