[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using empty_string as the only "" string
From: |
Juanma Barranquero |
Subject: |
Re: using empty_string as the only "" string |
Date: |
Wed, 6 Jun 2007 13:04:20 +0200 |
On 6/6/07, Stefan Monnier <address@hidden> 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 <address@hidden>
+
+ * 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 <address@hidden>
+
+ * 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 <address@hidden>
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;
}