Skip to content

Commit

Permalink
win32: Use wide entry points
Browse files Browse the repository at this point in the history
The patch 8.1.1091 enables to support Unicode environment variables
inside Vim. However, we still cannot access external Unicode env var.
E.g.:

```
> set a=Ā
> gvim --clean --cmd "set enc=utf-8"
:echo $a
?  " should be Ā
```

This is because we use ANSI entry points: WinMain() for GUI and main()
for CUI. To fix this, we need to use wide entry points: wWinMain() for
GUI and wmain() for CUI.

This also moves the entry point for CUI from main.c to os_w32exe.c to
make the code simple.

Note: This requires the `-municode` option to MinGW, which means now
MinGW-w64 is needed.
  • Loading branch information
k-takata committed Apr 2, 2019
1 parent 0eb035c commit f3d1c8c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/Make_cyg.mak
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
#RUBY=/cygdribe/c/ruby


# Use MinGW(-w64) cross compiler.
# There are three MinGW packages in Cygwin:
# 32-bit: mingw-gcc-g++ and mingw64-i686-gcc-g++
# Use MinGW-w64 cross compiler.
# There are two MinGW-w64 packages in Cygwin:
# 32-bit: mingw64-i686-gcc-g++
# 64-bit: mingw64-x86_64-gcc-g++
# You may also need to set 'ARCH' in Make_cyg_ming.mak.
CROSS_COMPILE = i686-pc-mingw32-
#CROSS_COMPILE = i686-w64-mingw32-
CROSS_COMPILE = i686-w64-mingw32-
#CROSS_COMPILE = x86_64-w64-mingw32-


Expand Down
9 changes: 6 additions & 3 deletions src/Make_cyg_ming.mak
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ CFLAGS += -s
endif

LIB = -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomdlg32 -lcomctl32 -lnetapi32 -lversion
GUIOBJ = $(OUTDIR)/gui.o $(OUTDIR)/gui_w32.o $(OUTDIR)/gui_beval.o $(OUTDIR)/os_w32exe.o
GUIOBJ = $(OUTDIR)/gui.o $(OUTDIR)/gui_w32.o $(OUTDIR)/gui_beval.o
CUIOBJ = $(OUTDIR)/iscygpty.o
OBJ = \
$(OUTDIR)/arabic.o \
Expand Down Expand Up @@ -737,9 +737,9 @@ OBJ = \
$(OUTDIR)/normal.o \
$(OUTDIR)/ops.o \
$(OUTDIR)/option.o \
$(OUTDIR)/os_win32.o \
$(OUTDIR)/os_mswin.o \
$(OUTDIR)/winclip.o \
$(OUTDIR)/os_w32exe.o \
$(OUTDIR)/os_win32.o \
$(OUTDIR)/pathdef.o \
$(OUTDIR)/popupmnu.o \
$(OUTDIR)/quickfix.o \
Expand All @@ -759,6 +759,7 @@ OBJ = \
$(OUTDIR)/userfunc.o \
$(OUTDIR)/version.o \
$(OUTDIR)/vimrc.o \
$(OUTDIR)/winclip.o \
$(OUTDIR)/window.o

ifdef PERL
Expand Down Expand Up @@ -865,6 +866,8 @@ ifdef MZSCHEME
MZSCHEME_SUFFIX = Z
endif

LFLAGS += -municode

ifeq ($(GUI),yes)
TARGET := gvim$(DEBUG_SUFFIX).exe
DEFINES += $(DEF_GUI)
Expand Down
6 changes: 3 additions & 3 deletions src/Make_mvc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ OBJ = \
$(OUTDIR)\ops.obj \
$(OUTDIR)\option.obj \
$(OUTDIR)\os_mswin.obj \
$(OUTDIR)\winclip.obj \
$(OUTDIR)\os_w32exe.obj \
$(OUTDIR)\os_win32.obj \
$(OUTDIR)\pathdef.obj \
$(OUTDIR)\popupmnu.obj \
Expand All @@ -761,6 +761,7 @@ OBJ = \
$(OUTDIR)\ui.obj \
$(OUTDIR)\undo.obj \
$(OUTDIR)\userfunc.obj \
$(OUTDIR)\winclip.obj \
$(OUTDIR)\window.obj \
$(OUTDIR)\vim.res

Expand Down Expand Up @@ -799,8 +800,7 @@ GUI_INCL = \
GUI_OBJ = \
$(OUTDIR)\gui.obj \
$(OUTDIR)\gui_beval.obj \
$(OUTDIR)\gui_w32.obj \
$(OUTDIR)\os_w32exe.obj
$(OUTDIR)\gui_w32.obj
GUI_LIB = \
gdi32.lib version.lib $(IME_LIB) \
winspool.lib comctl32.lib advapi32.lib shell32.lib netapi32.lib \
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static char_u *start_dir = NULL; /* current working dir on startup */
static int has_dash_c_arg = FALSE;

int
# ifdef FEAT_GUI_MSWIN
# ifdef MSWIN
# ifdef __BORLANDC__
_cdecl
# endif
Expand Down
13 changes: 7 additions & 6 deletions src/os_w32exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ void _cdecl SaveInst(HINSTANCE hInst);
#endif

#ifndef PROTO
# ifdef FEAT_GUI
int WINAPI
WinMain(
wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst UNUSED,
LPSTR lpszCmdLine UNUSED,
LPWSTR lpszCmdLine UNUSED,
int nCmdShow UNUSED)
# else
wmain(int argc, WCHAR **argv)
# endif
{
int argc = 0;
char **argv = NULL;

# ifdef FEAT_GUI
SaveInst(hInstance);
# endif
VimMain(argc, argv);
VimMain(0, NULL);

return 0;
}
Expand Down

0 comments on commit f3d1c8c

Please sign in to comment.