Re: "Tear off this menu" in messages-history
Hi Edward, On 30/05/07, Edward L. Fox <[EMAIL PROTECTED]> wrote: To Yongwei: Does this patch solve your problem? To Bram: Please consider adding this patch. I think it is really a bug. Index: src/gui_w32.c === --- src/gui_w32.c (revision 296) +++ src/gui_w32.c (working copy) @@ -1051,7 +1051,7 @@ if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != 0 && GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1) { - msg(pMenu->strings[MENU_INDEX_TIP]); + msg_outtrans(pMenu->strings[MENU_INDEX_TIP]); setcursor(); out_flush(); did_menu_tip = TRUE; This patch seems to have solved my problem, and I have not found any side-effects so far. Thanks! Best regards, Yongwei -- Wu Yongwei URL: http://wyw.dcweb.cn/
Re: MSVC build option about default library MSVCRT
Hi Doug, On 18/05/07, Doug Cook <[EMAIL PROTECTED]> wrote: There is no such thing as a single-threaded Windows app. The programmer might only start one thread, but other system components might start other threads in the process, so the CRT needs to be aware of threads whether or not the programmer does any threading. That's why Microsoft stopped creating it -- they kept on running into bugs where the CRT screwed up because it didn't correctly handle the multithreaded stuff in Windows. I do not understand what you mean by this. Vim does not support the single-threaded C run-time, but I never heard that Microsoft stopped supporting it. And I do not know a MSVC version that does not have a LIBC.LIB. Please clarify. As far as using different CRTs, I'm talking about using them within the same executable. An EXE and a DLL can use different CRTs and still work together with no trouble (as long as they don't try to free each other's memory or share complex data structures). You can have Vim.exe safely load perl58.dll even though they use different CRTs because they are separate executable files. The problem is when Vim.exe uses two CRTs or perl58.dll uses two CRTs. If you link Vim.exe with both libcmt.lib and msvcrt.lib, you are in trouble. I agree (mostly). And this is what I try to avoid with /nodefaultlib:msvcrt. LIB files can contain many different kinds of records. One kind is the "import" or "dynamic" record, which says "if you want to call this function, you can find it in this DLL". Another kind is the "static" record, which says "if you want to call this function, add this code to your executable". If tcl84stub.lib contains any static records, it will add code to your executable, and if that code was compiled for the wrong CRT, you might have trouble. If perl58.lib contains only "import" records, then it won't put any code in your executable. It will only tell the linker to load the perl58.dll when necessary. This doesn't affect your executable's CRT. Tclstub84.lib is a 2106-byte file, and I do not expect it to contain significant code. However, I cannot gurantee that, without looking at its source code. You're right - I got _dup and strdup mixed up. Adding /nodefaultlib is probably better in your specific case. It forces those functions to be resolved from libcmt.lib instead of msvcrt.lib. However, you still have a problem because the code was compiled using the header declarations for msvcrt.lib. The header declarations for msvcrt.lib and libcmt.lib are mostly compatible (though with a tiny performance hit for the thunk), but it is not always compatible. Tcl84.dll can have a dependency on a different CRT with no trouble because it is a different executable. Mostly. Unless somebody defines the interface foolishly. I suppose that does not occur in such famous programs. I suppose that /nodefaultlib wouldn't hurt, in most cases. One thing is that it makes your warnings go away. The warnings are valid, and adding /nodefaultlib would make the warnings go away and you would have no idea that there was a problem. It not only removes the warnings, but also removes the wrong dependency on msvcr* dlls. In my experience, it is best to either avoid /nodefaultlib (and fix the problems) or to use /nodefaultlib with no library specified, which turns off all default libs. Why the latter? I think disabling specific libaries makes one clearer what he does. For the other question from the other email -- Microsoft can't fix the interface or even some of the bugs for msvcrt.dll. Microsoft does keep adding new methods to msvcrt.dll and fixing bugs. But the Microsoft guys know that hundreds of thousands of programs depend on it (sometimes they even depend on the bugs), so it can't change any behavior of the old version. Some of the things it does are wrong (according to the updated C standard or new security findings) since the interface was designed back in 1995. Microsoft can add new functions, but it can't remove old ones. It sometimes even has trouble fixing bugs because some programs stop working when the bug gets fixed. You also can't use new compilers with the old msvcrt.dll since the version on Windows 2000 or Windows XP doesn't work with Visual C++ 8.0's compiler. (Actually, the Windows Device Driver kit has a special set of libraries that lets you link against msvcrt.dll using VC 8.0, but that is unsupported and really not a good idea in most cases.) I agree with some of your points. But keep in mind the run-time behaviour of Microsoft run-time functions are not regarded as bugs nowadays. People having a cross-platform mind already know the limitations of these functions and always live within them when MSVC is encountered. Do we have any conclusions? It looks to me having /nodefaultlib:msvcrt is still better then not having it. Best regards, Yongwei -- Wu Yongwei URL: http://wyw.dcweb.cn/
[OT] MSVCRT and MSVCR71 (Was: Re: MSVC build option about default library MSVCRT)
On 18/05/07, Doug Cook <[EMAIL PROTECTED]> wrote: There's nothing wrong with msvcr71.dll or msvcr80.dll. In fact, they have many bug fixes and performance improvements over msvcrt.dll. Thinking more carefully on this, I tend to disagree. Only the interfaces in msvcrt.dll is more or less fixed, but Microsoft is free to fix bugs and improve performance in msvcrt.dll. As a matter of fact, MSVCRT.dll has version number 7.0.2600.2180 on my machine, and I believe it is 6.x on machinese earlier than Windows XP. The real difference is in the interface. Compared with MSVCRT.dll, MSVCR71.dll removed _ctype, ??_E__non_rtti_object@@[EMAIL PROTECTED], ??_Ebad_cast@@[EMAIL PROTECTED], etc., but added ?swprintf@@YAHPAGIPBGZZ, _CRT_RTC_INIT, __buffer_overrun, __pwctype_func, and so on. Best regards, Yongwei -- Wu Yongwei URL: http://wyw.dcweb.cn/
Re: MSVC build option about default library MSVCRT
Hi Doug, On 18/05/07, Doug Cook <[EMAIL PROTECTED]> wrote: If the lib is added explicitly, you're right -- it probably won't break anything. However, there are actually three CRTs. libc (single-threaded static), libcmt (multi-threaded static), and msvcrt (multi-threaded DLL). libc is no longer supported (there is no longer any such thing as a single-threaded Windows app because things like signals can come in on separate threads). So adding a nodefaultlib for msvcrt is not just like the nodefaultlib for libc. It would be like a nodefaultlib for libcmt. Points taken. (Though I think LIBC.lib and single-threaded Windows apps still make sense in some cases: not Vim.) Lib conflicts are scary. They work only because you are lucky and because the Microsoft CRT developers worked very hard to make things work ok most of the time. However, there are some functions that don't work ok, and the list of functions that don't work ok is subject to change at any time. And sometimes you might be using a function that mostly works ok except for some strange edge cases. Better to just avoid the whole issue if possible. How? I mean, perl58.dll, tcl84.dll, and msvcrt-ruby18.dll depends on msvcrt.dll, and python24.dll depends on msvcr71.dll, but nobody has reported issues (not even the build one) with using them in gvim.exe (linked with LIBCMT.lib). ONLY the Tcl84 lib has build warnings with the CONSOLE vim.exe. Both gvim.exe and vim.exe are linked with tcl84stub.lib, which contains the linker directive -defaultlib:MSVCRT. Why only vim.exe gives the warning? Anybody has insights on this? As for "allowing" multiple CRTs, I was referring to the warning. It warns when you link with multiple CRTs at the same time. In your case, the conflict looks scary because you have linked with _dup but not with free... (One gotcha: _dup is not strdup, so I do not see why you worry about free.) Still I do not like it. But the question is still How? Adding /nodefaultlib:msvcrt at least removes these ugly imported functions. You should only use one CRT in an EXE or DLL. Any time you use more than one within the same executable, you're in undefined territory and while things may work, things could go wrong at any time. There's nothing wrong with msvcr71.dll or msvcr80.dll. In fact, they have many bug fixes and performance improvements over msvcrt.dll. I agree with this. However, if you link against one of them, it has to be installed on the target machine or the EXE/DLL won't load, while msvcrt.dll is always present on every copy of Windows. That said, you might run into an old versions of msvcrt.dll that is missing functions you need (each new version of Windows has added new functions to msvcrt.dll), while you pretty much know what you are getting when you use msvcr71 or msvcr80. But it seems you did not get my point. Tcl84.dll has a dependency on MSVCRT.dll, but adding MSVCRT.LIB to the build (implicitly or explicitly) will make vim.exe dependent on MSVCR71.dll (instead of MSVCRT.dll) under MSVC 7.1. So we do not end up any better. The basic thing here is: Does /nodefaultlib:msvcrt do more good or more evil? While many of your points are good and some of mine are faulted, I still can see only good results instead of evil ones using it in building Vim. -Original Message- From: Yongwei Wu [mailto:[EMAIL PROTECTED] Sent: Thursday, May 17, 2007 7:15 AM To: Doug Cook Cc: Bram Moolenaar; Vim-dev mailing list Subject: Re: MSVC build option about default library MSVCRT Hi Doug, On 17/05/07, Doug Cook <[EMAIL PROTECTED]> wrote: > Bram is wise. No objection here ;-). > Adding a nodefaultlib:msvcrt could potentially break things if you > set USE_MSVCRT=1 to use the CRT DLL instead of statically linking > the CRT. The problem is that you're linking a static-CRT version > of Vim with DLL-CRT versions of ActiveState components. The > problem is not with Vim's makefile. Adding /nodefaultlib:msvcrt does not affect USE_MSVCRT=1, which will add the NON-default library msvcrt.lib explicitly. In fact, I think /nodefaultlib:msvcrt is really symmetrical with the current setting. We already have /nodefaultlib:libc, which disables the default static libc. Why should we allow default dynamic libc while disabling default static libc? > Generally, if you have lib conflicts, it means you've done > something wrong. In this case, you have one OBJ that was compiled > for use with the static CRT, and another OBJ that was compiled for > use with the dynamically-linked CRT. Each of them tell the linker > "you should probably link me with this particular CRT". Luckily, > the linker is smart enough to only allow one CRT at a time. Lib conflicts are something wrong, but not necessarily serious. It is a serious problem only if one does some foolish things like malloc in one CRT and free in another. Also, the linker
Re: MSVC build option about default library MSVCRT
Hi Doug, On 17/05/07, Doug Cook <[EMAIL PROTECTED]> wrote: Bram is wise. No objection here ;-). Adding a nodefaultlib:msvcrt could potentially break things if you set USE_MSVCRT=1 to use the CRT DLL instead of statically linking the CRT. The problem is that you're linking a static-CRT version of Vim with DLL-CRT versions of ActiveState components. The problem is not with Vim's makefile. Adding /nodefaultlib:msvcrt does not affect USE_MSVCRT=1, which will add the NON-default library msvcrt.lib explicitly. In fact, I think /nodefaultlib:msvcrt is really symmetrical with the current setting. We already have /nodefaultlib:libc, which disables the default static libc. Why should we allow default dynamic libc while disabling default static libc? Generally, if you have lib conflicts, it means you've done something wrong. In this case, you have one OBJ that was compiled for use with the static CRT, and another OBJ that was compiled for use with the dynamically-linked CRT. Each of them tell the linker "you should probably link me with this particular CRT". Luckily, the linker is smart enough to only allow one CRT at a time. Lib conflicts are something wrong, but not necessarily serious. It is a serious problem only if one does some foolish things like malloc in one CRT and free in another. Also, the linker does allow two CRTs at the same time, and which occurred to me, if I did not add /nodefaultlib:msvcrt. LibcMT will be linked, but the following five functions are imported from MSVCR71.dll: _fileno _chdir _fdopen _dup _putenv _stat _dup2 For a standalone program, statically linking with the CRT is generally the way to go, so Vim defaults to doing this. Using the CRT DLL saves about 150k in disk space, but the CRT DLL is 400-800k, depending on which version of Visual C++ you're using. The CRT is potentially already in memory in another process, so this may or may not save memory at runtime. For a program that interacts with other DLLs (such as loading Perl, Python, Ruby, etc. DLLs at runtime), the CRT DLL starts to make more sense. In addition to saving disk space (one CRT DLL instead of 150k of static CRT in each executable), you save memory (one CRT DLL loaded, and all modules share the same heap) and in some cases you avoid bugs (only one CRT so you don't have conflicting CRT settings like locale). However, you now have to redistribute the CRT with your product, and starting with VC 8.0, you have to get the CRT's manifest correctly embedded into your EXE and DLLs. Another problem with CRT DLL is that different MSVC versions will make the resulting executable dependent on different CRT DLLs. Linking with MSVCRT.LIB in MSVC 7.1 results in the dependency on MSVCR71.DLL instead of MSVCRT.DLL. This is not something we like, I suppose. Best regards, Yongwei -- Wu Yongwei URL: http://wyw.dcweb.cn/
Re: MSVC build option about default library MSVCRT
Hi Bram, On 15/05/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote: [redirecting to vim-dev] > I am wondering whether l. 705 of Make_mvc.mak in vim-7.1-extra.tar.gz > should be change from > > LINKARGS1 = $(linkdebug) $(conflags) /nodefaultlib:libc > > to > > LINKARGS1 = $(linkdebug) $(conflags) /nodefaultlib:libc /nodefaultlib:msvcrt > > I have been using it for maybe half a year and not found a single > problem yet. It will eliminate this message when building vim.exe: > > libcmt.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' > conflicts with use of other libs; use /NODEFAULTLIB:library > > Without /nodefaultlib:msvcrt vim.exe will have a dependency on > MSVCR71.DLL (I use MSVC 7.1). This added flag will not affect > gvim.exe. The command lines I used are: > > nmake -f Make_mvc.mak GUI=yes OLE=yes MBYTE=yes IME=yes GIME=yes > CSCOPE=yes PERL=C:\Perl DYNAMIC_PERL=yes PERL_VER=58 > PYTHON=C:\Python24 DYNAMIC_PYTHON=yes PYTHON_VER=24 RUBY=C:\ruby > DYNAMIC_RUBY=yes RUBY_VER=18 RUBY_VER_LONG=1.8 TCL=C:\Tcl > DYNAMIC_TCL=yes TCL_VER=84 TCL_VER_LONG=8.4 XPM=C:\xpm %* > nmake -f Make_mvc.mak MBYTE=yes CSCOPE=yes PERL=C:\Perl > DYNAMIC_PERL=yes PERL_VER=58 PYTHON=C:\Python24 DYNAMIC_PYTHON=yes > PYTHON_VER=24 RUBY=C:\ruby DYNAMIC_RUBY=yes RUBY_VER=18 > RUBY_VER_LONG=1.8 TCL=C:\Tcl DYNAMIC_TCL=yes TCL_VER=84 > TCL_VER_LONG=8.4 XPM=C:\xpm %* I'm very careful with these things. Make_mvc.mak is used for several versions of MSVC, starting at 4.1. You need to check all versions to make sure it doesn't cause any problems. Er ... I do not have access to such old versions. I work on 7.1, and can do so on 6.0 too. However, I believe MSVC versions are not significant here. See below. I suppose the error message you get is from some of the languages Ruby/Python/Tcl/ I don't get it, thus you can probably solve it by checking your included libraries. Perhaps one has not been build by MSVC? That usually causes trouble (not just an error message, but a crash at runtime). Try actually using all the languages. I noticed that you did not build vim.exe with the languages, which should be the reason you do not see the warning message. I have verified that removing ActiveTcl 8.4 from my build makes /nodefaultlib:msvcrt not necessary: in fact, then the option does not have any effect at all. I did actually try executing simple commands in Perl, Python, Tcl, and Ruby, and they all succeeded. I use the popular ActiveState builds for Perl, Python, and Tcl, and ruby185-21 from the Ruby web site. I believe they are all MSVC compatible. Best regards, Yongwei -- Wu Yongwei URL: http://wyw.dcweb.cn/