From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.devel Subject: Re: using empty_string as the only "" string Date: Wed, 6 Jun 2007 13:04:20 +0200 Message-ID: References: <462EE947.000007.15251@camay.yandex.ru> <4631CA91.9020806@yandex.ru> <46330BC7.8040102@yandex.ru> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1181127871 26822 80.91.229.12 (6 Jun 2007 11:04:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2007 11:04:31 +0000 (UTC) Cc: dmantipov@yandex.ru, rms@gnu.org, emacs-devel@gnu.org To: "Stefan Monnier" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 06 13:04:28 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HvtJT-0000IU-Cu for ged-emacs-devel@m.gmane.org; Wed, 06 Jun 2007 13:04:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HvtJS-0003MB-Tx for ged-emacs-devel@m.gmane.org; Wed, 06 Jun 2007 07:04:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HvtJP-0003M5-R3 for emacs-devel@gnu.org; Wed, 06 Jun 2007 07:04:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HvtJO-0003Lt-6H for emacs-devel@gnu.org; Wed, 06 Jun 2007 07:04:22 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HvtJO-0003Lp-10 for emacs-devel@gnu.org; Wed, 06 Jun 2007 07:04:22 -0400 Original-Received: from wx-out-0506.google.com ([66.249.82.237]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HvtJN-0001hm-7V for emacs-devel@gnu.org; Wed, 06 Jun 2007 07:04:21 -0400 Original-Received: by wx-out-0506.google.com with SMTP id h26so89761wxd for ; Wed, 06 Jun 2007 04:04:20 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=eKZXS0tfpRKbhZzBseLMqV3SyMbi9q7n/DOzOkE/Qtruorfon+fycZjffHNNuHrfYIe4EKfYhTofD3YXqC+LsY/1OARpCK7I7QjUj6JaIpYNlLBdnY6elIpW84EYlgbVnp+nEKRsbl16VGwB1cZU8SWqucYLsjZzDmhnZp+FXVc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ObldtzlUcN+Va+tttQPZAdMvR+faxUbQb53QxHkRxkZgvWKbEVl8sKQK4nbNpmfR7hJtY4F+alHwA2seGiqvhh0DoZvtoKG0it3IKZKAKjg8Kkus4fqCvU2RuAnvzZhpXbmPO5cARlUtVMrdqOtFqSgDav8bl2ciqWkXTjhyEFY= Original-Received: by 10.90.34.3 with SMTP id h3mr191895agh.1181127860515; Wed, 06 Jun 2007 04:04:20 -0700 (PDT) Original-Received: by 10.90.103.8 with HTTP; Wed, 6 Jun 2007 04:04:20 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: Linux 2.4-2.6 (Google crawlbot) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:72322 Archived-At: On 6/6/07, Stefan Monnier wrote: > I believe empty_string should be called empty_unibyte_string, so as to make > sure that people choose the right multibyteness. Here's the patch I'm using. It'd be good if people could test it in non-Windows builds. BTW, Dmitry's contribution (other than the original idea, of course :) is about 5 changed lines, 8 added, 2 removed. He has a previous tiny patch (5 lines changed, 1 added, plus comment). I'm not sure whether that requires signed papers or not. Juanma Index: src/ChangeLog =================================================================== RCS file: /cvsroot/emacs/emacs/src/ChangeLog,v retrieving revision 1.5692 diff -u -2 -r1.5692 ChangeLog --- src/ChangeLog 6 Jun 2007 08:33:32 -0000 1.5692 +++ src/ChangeLog 6 Jun 2007 10:34:41 -0000 @@ -1,2 +1,42 @@ +2007-06-06 Juanma Barranquero + + * sunfns.c (sel_read): + * xdisp.c (Fformat_mode_line): + * xselect.c (Fx_get_atom_name): Use empty_unibyte_string, + not make_string. + + * callint.c (Fcall_interactively): + * editfns.c (Fdelete_and_extract_region): + * fns.c (Fmapconcat): + * keyboard.c (cmd_error_internal): + * lread.c (openp): + * xterm.c (x_term_init): Use empty_unibyte_string, not build_string. + + * fileio.c (Fread_file_name): + * keymap.c (Fkey_description): + * minibuf.c (read_minibuf): + * search.c (wordify): + * xdisp.c (syms_of_xdisp): + * xfns.c (x_default_scroll_bar_color_parameter): + * xmenu.c (menu_help_callback): Use empty_unibyte_string, + not empty_string. + +2007-06-06 Dmitry Antipov + + * alloc.c (init_strings): Initialize canonical empty strings. + (make_uninit_string, make_uninit_multibyte_string): Return appropriate + canonical empty string when the requested size is 0. + + * emacs.c (empty_unibyte_string): Rename from empty_string. + (empty_multibyte_string): New canonical empty string. + (syms_of_emacs): Don't initialize empty_string. + + * lisp.h (STRING_SET_UNIBYTE): Return the canonical empty unibyte + string, if appropriate. + (empty_unibyte_string, empty_multibyte_string): New externs. + (empty_string): Remove extern. + + * lread.c (syms_of_lread): Use empty_unibyte_string, not build_string. + 2007-06-06 YAMAMOTO Mitsuharu Index: src/alloc.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/alloc.c,v retrieving revision 1.409 diff -u -2 -r1.409 alloc.c --- src/alloc.c 16 Apr 2007 03:09:33 -0000 1.409 +++ src/alloc.c 6 Jun 2007 08:03:03 -0000 @@ -1757,4 +1757,6 @@ n_string_blocks = 0; string_free_list = NULL; + empty_unibyte_string = make_pure_string ("", 0, 0, 0); + empty_multibyte_string = make_pure_string ("", 0, 0, 1); } @@ -2480,4 +2482,7 @@ { Lisp_Object val; + + if (!length) + return empty_unibyte_string; val = make_uninit_multibyte_string (length, length); STRING_SET_UNIBYTE (val); @@ -2498,4 +2503,6 @@ if (nchars < 0) abort (); + if (!nbytes) + return empty_multibyte_string; s = allocate_string (); Index: src/callint.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/callint.c,v retrieving revision 1.150 diff -u -2 -r1.150 callint.c --- src/callint.c 14 Jan 2007 03:24:37 -0000 1.150 +++ src/callint.c 6 Jun 2007 08:09:48 -0000 @@ -586,5 +586,5 @@ default to directory alone. */ args[i] = Fread_file_name (callint_message, - Qnil, Qnil, Qnil, build_string (""), Qnil); + Qnil, Qnil, Qnil, empty_unibyte_string, Qnil); break; Index: src/editfns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/editfns.c,v retrieving revision 1.440 diff -u -2 -r1.440 editfns.c --- src/editfns.c 8 May 2007 02:05:46 -0000 1.440 +++ src/editfns.c 6 Jun 2007 08:10:09 -0000 @@ -3043,5 +3043,5 @@ validate_region (&start, &end); if (XINT (start) == XINT (end)) - return build_string (""); + return empty_unibyte_string; return del_range_1 (XINT (start), XINT (end), 1, 1); } Index: src/emacs.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/emacs.c,v retrieving revision 1.401 diff -u -2 -r1.401 emacs.c --- src/emacs.c 3 Apr 2007 15:25:28 -0000 1.401 +++ src/emacs.c 6 Jun 2007 08:03:41 -0000 @@ -134,6 +134,6 @@ Lisp_Object Vkill_emacs_hook; -/* An empty lisp string. To avoid having to build any other. */ -Lisp_Object empty_string; +/* Empty lisp strings. To avoid having to build any others. */ +Lisp_Object empty_unibyte_string, empty_multibyte_string; /* Search path separator. */ @@ -2469,7 +2469,4 @@ Vkill_emacs_hook = Qnil; - empty_string = build_string (""); - staticpro (&empty_string); - DEFVAR_INT ("emacs-priority", &emacs_priority, doc: /* Priority for Emacs to run at. Index: src/fileio.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/fileio.c,v retrieving revision 1.580 diff -u -2 -r1.580 fileio.c --- src/fileio.c 22 Mar 2007 12:15:04 -0000 1.580 +++ src/fileio.c 6 Jun 2007 08:07:28 -0000 @@ -6431,5 +6431,5 @@ add_to_history = 1; - val = empty_string; + val = empty_unibyte_string; } Index: src/fns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/fns.c,v retrieving revision 1.425 diff -u -2 -r1.425 fns.c --- src/fns.c 26 May 2007 17:21:14 -0000 1.425 +++ src/fns.c 6 Jun 2007 08:10:25 -0000 @@ -3135,5 +3135,5 @@ leni = XINT (len); nargs = leni + leni - 1; - if (nargs < 0) return build_string (""); + if (nargs < 0) return empty_unibyte_string; SAFE_ALLOCA_LISP (args, nargs); Index: src/keyboard.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keyboard.c,v retrieving revision 1.904 diff -u -2 -r1.904 keyboard.c --- src/keyboard.c 3 Jun 2007 00:57:11 -0000 1.904 +++ src/keyboard.c 6 Jun 2007 08:18:22 -0000 @@ -1250,5 +1250,5 @@ if (!NILP (Vcommand_error_function)) call3 (Vcommand_error_function, data, - build_string (context ? context : ""), + context ? build_string (context) : empty_unibyte_string, Vsignaling_function); /* If the window system or terminal frame hasn't been initialized Index: src/keymap.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keymap.c,v retrieving revision 1.354 diff -u -2 -r1.354 keymap.c --- src/keymap.c 7 May 2007 20:49:55 -0000 1.354 +++ src/keymap.c 6 Jun 2007 08:07:58 -0000 @@ -2189,5 +2189,5 @@ } else if (len == 0) - return empty_string; + return empty_unibyte_string; return Fconcat (len - 1, args); } Index: src/lisp.h =================================================================== RCS file: /cvsroot/emacs/emacs/src/lisp.h,v retrieving revision 1.576 diff -u -2 -r1.576 lisp.h --- src/lisp.h 20 May 2007 02:44:05 -0000 1.576 +++ src/lisp.h 6 Jun 2007 08:02:24 -0000 @@ -702,5 +702,8 @@ /* Mark STR as a unibyte string. */ -#define STRING_SET_UNIBYTE(STR) (XSTRING (STR)->size_byte = -1) +#define STRING_SET_UNIBYTE(STR) \ + do { if (EQ (STR, empty_multibyte_string)) \ + (STR) = empty_unibyte_string; \ + else XSTRING (STR)->size_byte = -1; } while (0) /* Get text properties. */ @@ -3061,5 +3064,6 @@ extern Lisp_Object decode_env_path P_ ((char *, char *)); extern Lisp_Object Vinvocation_name, Vinvocation_directory; -extern Lisp_Object Vinstallation_directory, empty_string; +extern Lisp_Object Vinstallation_directory; +extern Lisp_Object empty_unibyte_string, empty_multibyte_string; EXFUN (Fkill_emacs, 1); #if HAVE_SETLOCALE Index: src/lread.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/lread.c,v retrieving revision 1.370 diff -u -2 -r1.370 lread.c --- src/lread.c 28 Apr 2007 17:24:22 -0000 1.370 +++ src/lread.c 6 Jun 2007 08:10:43 -0000 @@ -1200,5 +1200,5 @@ /* Loop over suffixes. */ - for (tail = NILP (suffixes) ? Fcons (build_string (""), Qnil) : suffixes; + for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; CONSP (tail); tail = XCDR (tail)) { @@ -4071,6 +4071,5 @@ the loading functions recognize as compression suffixes, you should customize `jka-compr-load-suffixes' rather than the present variable. */); - /* We don't use empty_string because it's not initialized yet. */ - Vload_file_rep_suffixes = Fcons (build_string (""), Qnil); + Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil); DEFVAR_BOOL ("load-in-progress", &load_in_progress, Index: src/minibuf.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/minibuf.c,v retrieving revision 1.329 diff -u -2 -r1.329 minibuf.c --- src/minibuf.c 19 Apr 2007 22:20:47 -0000 1.329 +++ src/minibuf.c 6 Jun 2007 08:08:10 -0000 @@ -530,5 +530,5 @@ if (!STRINGP (prompt)) - prompt = empty_string; + prompt = empty_unibyte_string; if (!enable_recursive_minibuffers Index: src/search.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/search.c,v retrieving revision 1.221 diff -u -2 -r1.221 search.c --- src/search.c 14 Jan 2007 03:24:37 -0000 1.221 +++ src/search.c 6 Jun 2007 08:37:46 -0000 @@ -2096,5 +2096,5 @@ word_count++; if (!word_count) - return empty_string; + return empty_unibyte_string; adjust = - punct_count + 5 * (word_count - 1) + 4; Index: src/sunfns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/sunfns.c,v retrieving revision 1.32 diff -u -2 -r1.32 sunfns.c --- src/sunfns.c 21 Jan 2007 04:18:15 -0000 1.32 +++ src/sunfns.c 6 Jun 2007 08:16:51 -0000 @@ -288,5 +288,5 @@ register char *cp; - Current_Selection = make_string ("", 0); + Current_Selection = empty_unibyte_string; if (sel->sel_items <= 0) return (0); Index: src/xdisp.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xdisp.c,v retrieving revision 1.1153 diff -u -2 -r1.1153 xdisp.c --- src/xdisp.c 29 May 2007 23:19:43 -0000 1.1153 +++ src/xdisp.c 6 Jun 2007 08:15:05 -0000 @@ -17343,5 +17343,5 @@ if (NILP (format)) - return build_string (""); + return empty_unibyte_string; if (no_props) @@ -17401,5 +17401,5 @@ mode_line_string_list = Fnreverse (mode_line_string_list); str = Fmapconcat (intern ("identity"), mode_line_string_list, - make_string ("", 0)); + empty_unibyte_string); } @@ -24082,5 +24082,5 @@ = Fcons (intern ("multiple-frames"), Fcons (build_string ("%b"), - Fcons (Fcons (empty_string, + Fcons (Fcons (empty_unibyte_string, Fcons (intern ("invocation-name"), Fcons (build_string ("@"), Index: src/xfns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xfns.c,v retrieving revision 1.682 diff -u -2 -r1.682 xfns.c --- src/xfns.c 1 Jun 2007 04:00:27 -0000 1.682 +++ src/xfns.c 6 Jun 2007 08:08:40 -0000 @@ -1842,7 +1842,7 @@ ? "foreground" : "background"), - empty_string, + empty_unibyte_string, build_string ("verticalScrollBar"), - empty_string); + empty_unibyte_string); if (!STRINGP (tem)) { Index: src/xmenu.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xmenu.c,v retrieving revision 1.318 diff -u -2 -r1.318 xmenu.c --- src/xmenu.c 27 Apr 2007 06:25:58 -0000 1.318 +++ src/xmenu.c 6 Jun 2007 08:08:50 -0000 @@ -3429,5 +3429,5 @@ else if (EQ (first_item[0], Qquote)) /* This shouldn't happen, see xmenu_show. */ - pane_name = empty_string; + pane_name = empty_unibyte_string; else pane_name = first_item[MENU_ITEMS_ITEM_NAME]; Index: src/xselect.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xselect.c,v retrieving revision 1.168 diff -u -2 -r1.168 xselect.c --- src/xselect.c 6 Mar 2007 06:11:01 -0000 1.168 +++ src/xselect.c 6 Jun 2007 08:15:53 -0000 @@ -2679,5 +2679,5 @@ if (atom && name) XFree (name); - if (NILP (ret)) ret = make_string ("", 0); + if (NILP (ret)) ret = empty_unibyte_string; UNBLOCK_INPUT; Index: src/xterm.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xterm.c,v retrieving revision 1.946 diff -u -2 -r1.946 xterm.c --- src/xterm.c 22 May 2007 08:29:09 -0000 1.946 +++ src/xterm.c 6 Jun 2007 10:21:55 -0000 @@ -10650,5 +10650,5 @@ dpyinfo->kboard->Vsystem_key_alist = call1 (Qvendor_specific_keysyms, - build_string (vendor ? vendor : "")); + vendor ? build_string (vendor) : empty_unibyte_string); BLOCK_INPUT; }