From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: MIYASHITA Hisashi(=?ISO-2022-JP?B?GyRCNVwyPBsoQiAbJEI+MBsoQjpISU1J?=) Newsgroups: gmane.emacs.devel Subject: Re: init_buffer PWD fix Date: Tue, 23 Apr 2002 15:14:31 +0900 Sender: emacs-devel-admin@gnu.org Message-ID: References: <200204220618.g3M6Icg23696@sic.twinsun.com> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: main.gmane.org 1019543420 30307 127.0.0.1 (23 Apr 2002 06:30:20 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 23 Apr 2002 06:30:20 +0000 (UTC) Cc: knagano@sodan.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16ztoi-0007si-00 for ; Tue, 23 Apr 2002 08:30:20 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16ztpm-0003EN-00 for ; Tue, 23 Apr 2002 08:31:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16ztaL-0004nu-00; Tue, 23 Apr 2002 02:15:29 -0400 Original-Received: from meadow.scphys.kyoto-u.ac.jp ([130.54.54.165]) by fencepost.gnu.org with smtp (Exim 3.34 #1 (Debian)) id 16ztZT-0004lL-00 for ; Tue, 23 Apr 2002 02:14:35 -0400 Original-Received: (qmail 32741 invoked from network); 23 Apr 2002 06:13:49 -0000 Original-Received: from meadow.scphys.kyoto-u.ac.jp (HELO MILCH.meadowy.org.meadowy.org) (root@130.54.54.165) by meadow.scphys.kyoto-u.ac.jp with SMTP; 23 Apr 2002 06:13:49 -0000 Original-To: emacs-devel@gnu.org, Paul Eggert In-Reply-To: <200204220618.g3M6Icg23696@sic.twinsun.com> (Paul Eggert's message of "Sun, 21 Apr 2002 23:18:38 -0700 (PDT)") Original-Lines: 115 User-Agent: T-gnus/6.15.4 (based on Oort Gnus v0.04) (revision 11) SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.1 (i386-msvc-nt5.1.2600) MULE/5.0 (SAKAKI) Meadow/1.99 Alpha1 (AWOFUCHI) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:3076 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:3076 Primarily, I suggested this change to the ML, but I don't explain the detail on that to Nagano-san. Sorry. Paul Eggert writes: >> From: Keiichiro Nagano (=?ISO-2022-JP?B?GyRCMUpMbjc9MGxPOhsoQg==?=) >> Date: Mon, 22 Apr 2002 05:15:17 +0900 >> >> init_buffer uses environmental variable PWD to identify current >> working directory. I think we should not use it on Windows. On >> Windows with Cygwin, PWD is unreliable and confusing > > PWD is unreliable on all platforms, but Emacs works around the problem > with a similar method on all platforms by statting $PWD and ".", and > using $PWD only if stat results agree. What is the problem with > this workaround on Windows? Yes, the current Emacs implementation compares the result of stat("."), but stat() of Windows could not strictly emulate the behavior especially on inode. So if "PWD" environment variable is wrongly set, default_directory would be also wrongly set. But, in the first place, is this code necessary on all platform? Even now, is it really efficient on almost all of the platforms? I don't think we should stick to such hacked code for the simple job to get the current directory. FYI, I've tested the following code on Debian GNU/Linux (sid) to check the efficiency. ---------------------------------------- #include #include #include #include #define MAXPATHLEN 2048 #ifndef DIRECTORY_SEP #define DIRECTORY_SEP '/' #endif #ifndef IS_DIRECTORY_SEP #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP) #endif #ifndef IS_DEVICE_SEP #ifndef DEVICE_SEP #define IS_DEVICE_SEP(_c_) 0 #else #define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP) #endif #endif char* getcwd_stat(char *buf) { char *pwd; struct stat pwdstat, dotstat; if ((pwd = getenv ("PWD")) != 0 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) && stat (pwd, &pwdstat) == 0 && stat (".", &dotstat) == 0 && dotstat.st_ino == pwdstat.st_ino && dotstat.st_dev == pwdstat.st_dev && strlen (pwd) < MAXPATHLEN) strcpy (buf, pwd); else return NULL; return buf; } char * getcwd_normal(char *buf) { return getcwd (buf, MAXPATHLEN + 1); } int main(int argc, char **argv) { char buf[MAXPATHLEN + 1]; char *pwd; int i; if (argv[1][0] == 's') { for (i = 0;i < 1000000;i++) getcwd_stat(buf); } else { for (i = 0;i < 1000000;i++) getcwd_normal(buf); } return 1; } ---------------------------------------- The result are [~:] time ./a.out s ./a.out s 1.22s user 2.68s system 100% cpu 3.883 total [~:] time ./a.out n ./a.out n 0.29s user 0.92s system 100% cpu 1.200 total ---------------------------------------- Of course, this check only covers narrow situation. It may depends on the file system the current directly locates. But at least, I could state there exist situations that the hacked code is much slower than simple getcwd() calling. Therefore, I'd like to propose to remove this hacked optimization from init_buffer(). Do you have any comments? With regards, from himi