APPROVE COMMIT
NOTE: This patch has been committed.
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1514371767 0
# Wed Dec 27 10:49:27 2017 +0000
# Node ID 27f66ce6ab71265a93bc8c1bf642225f41b2a701
# Parent 714a6e9c1669a4ed929d87438abe9886a1c77f81
Write to Lisp streams instead of Eistrings(), events.c, keymap.c
src/ChangeLog addition:
2017-12-27 Aidan Kehoe <kehoea(a)parhasard.net>
Remove use of Eistring malloc buffers, have the corresponding
functions write to Lisp streams instead, as they were usually
ultimately doing anyway.
* event-Xt.c (emacs_Xt_format_magic_event):
Return a Bytecount here, helpful for its use as part of the
write-to-Lisp-stream infrastructure.
* event-gtk.c (emacs_gtk_format_magic_event):
Ditto.
* event-msw.c (emacs_mswindows_format_magic_event):
Dito.
* event-stream.c:
* event-stream.c (event_stream_format_magic_event):
Ditto.
* event-stream.c (echo_key_event):
Don't use an Eistring for the constructed string to echo the
event, build it directly into command_builder->echo_buf, using a
fixed_buffer Lisp output stream.
* event-tty.c (emacs_tty_format_magic_event):
Return zero, not void.
* events.c (print_event_1): Removed.
This mainly existed to provide a place to declare an Eistring.
* events.c (print_event):
Use write_ascstring() and format_event_object() as appropriate.
* events.c (format_event_object):
Return a Bytecount, and print into a Lisp stream, rather than an
Eistring.
* events.h:
Update the declaration of format_magic_event_cb(),
format_event_object(), event_stream_format_magic_event().
* events.h (struct event_stream):
* gui-x.c (button_item_to_widget_value):
Don't use an Eistring here, use a small Ibyte buffer; there's no
value to generating a long strong.
* gui.c (gui_item_display_flush_right):
Ditto.
* keymap.c:
* keymap.c (EXPOSE_FIXED_BUFFER_INTERNALS):
#define this when #including lstream.h, so where_is_to_Ibyte() can
create a stack-based Lstream object.
* keymap.c (Fsingle_key_description):
Use a resizing_buffer Lisp stream in this function rather than an
Eistring.
* keymap.c (Fwhere_is_internal):
Update the call to where_is_internal().
* keymap.c (where_is_to_Ibyte): Renamed from where_is_to_char().
Updated to use a stack fixed buffer lstream, and to return the
number of bytes that would have been written to the buffer, on the
model of emacs_asnprintf().
* keymap.c (raw_keys_to_keys):
Format into a stream, rather than an Eistring.
* keymap.c (format_raw_keys):
* keymap.c (where_is_recursive_mapper):
When TARGET-BUFFER is non-nil, format into it with
format_raw_keys(). Return the bytecount needed for them.
* lisp.h:
Rename and update the declaration of where_is_to_char() ->
where_is_to_Ibyte().
* lstream.h:
* lstream.h (INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM):
TThere was an issue in the name of the third argument to this
macro, correct it.
* menubar-gtk.c (menu_descriptor_to_widget_1):
Limit the printed name of this callback to 64 characters.
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/ChangeLog
--- a/src/ChangeLog Sat Dec 23 14:57:42 2017 +0000
+++ b/src/ChangeLog Wed Dec 27 10:49:27 2017 +0000
@@ -1,3 +1,70 @@
+2017-12-27 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ Remove use of Eistring malloc buffers, have the corresponding
+ functions write to Lisp streams instead, as they were usually
+ ultimately doing anyway.
+
+ * event-Xt.c (emacs_Xt_format_magic_event):
+ Return a Bytecount here, helpful for its use as part of the
+ write-to-Lisp-stream infrastructure.
+ * event-gtk.c (emacs_gtk_format_magic_event):
+ Ditto.
+ * event-msw.c (emacs_mswindows_format_magic_event):
+ Dito.
+ * event-stream.c:
+ * event-stream.c (event_stream_format_magic_event):
+ Ditto.
+ * event-stream.c (echo_key_event):
+ Don't use an Eistring for the constructed string to echo the
+ event, build it directly into command_builder->echo_buf, using a
+ fixed_buffer Lisp output stream.
+ * event-tty.c (emacs_tty_format_magic_event):
+ Return zero, not void.
+ * events.c (print_event_1): Removed.
+ This mainly existed to provide a place to declare an Eistring.
+ * events.c (print_event):
+ Use write_ascstring() and format_event_object() as appropriate.
+ * events.c (format_event_object):
+ Return a Bytecount, and print into a Lisp stream, rather than an
+ Eistring.
+ * events.h:
+ Update the declaration of format_magic_event_cb(),
+ format_event_object(), event_stream_format_magic_event().
+ * events.h (struct event_stream):
+ * gui-x.c (button_item_to_widget_value):
+ Don't use an Eistring here, use a small Ibyte buffer; there's no
+ value to generating a long strong.
+ * gui.c (gui_item_display_flush_right):
+ Ditto.
+ * keymap.c:
+ * keymap.c (EXPOSE_FIXED_BUFFER_INTERNALS):
+ #define this when #including lstream.h, so where_is_to_Ibyte() can
+ create a stack-based Lstream object.
+ * keymap.c (Fsingle_key_description):
+ Use a resizing_buffer Lisp stream in this function rather than an
+ Eistring.
+ * keymap.c (Fwhere_is_internal):
+ Update the call to where_is_internal().
+ * keymap.c (where_is_to_Ibyte): Renamed from where_is_to_char().
+ Updated to use a stack fixed buffer lstream, and to return the
+ number of bytes that would have been written to the buffer, on the
+ model of emacs_asnprintf().
+ * keymap.c (raw_keys_to_keys):
+ Format into a stream, rather than an Eistring.
+ * keymap.c (format_raw_keys):
+ * keymap.c (where_is_recursive_mapper):
+ When TARGET-BUFFER is non-nil, format into it with
+ format_raw_keys(). Return the bytecount needed for them.
+ * lisp.h:
+ Rename and update the declaration of where_is_to_char() ->
+ where_is_to_Ibyte().
+ * lstream.h:
+ * lstream.h (INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM):
+ TThere was an issue in the name of the third argument to this
+ macro, correct it.
+ * menubar-gtk.c (menu_descriptor_to_widget_1):
+ Limit the printed name of this callback to 64 characters.
+
2017-12-23 Aidan Kehoe <kehoea(a)parhasard.net>
* console-msw.c (mswindows_output_console_string):
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/event-Xt.c
--- a/src/event-Xt.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/event-Xt.c Wed Dec 27 10:49:27 2017 +0000
@@ -2837,13 +2837,17 @@
event. */
}
-static void
+static Bytecount
emacs_Xt_format_magic_event (Lisp_Event *event, Lisp_Object pstream)
{
Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
if (CONSOLE_X_P (XCONSOLE (console)))
- write_ascstring
- (pstream, x_event_name ((EVENT_MAGIC_X_EVENT (event)).type));
+ {
+ return write_ascstring
+ (pstream, x_event_name ((EVENT_MAGIC_X_EVENT (event)).type));
+ }
+
+ return 0;
}
static int
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/event-gtk.c
--- a/src/event-gtk.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/event-gtk.c Wed Dec 27 10:49:27 2017 +0000
@@ -310,14 +310,17 @@
enqueue_dispatch_event (emacs_event);
}
-static void
+static Bytecount
emacs_gtk_format_magic_event (Lisp_Event *emacs_event, Lisp_Object pstream)
{
Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (emacs_event));
if (CONSOLE_GTK_P (XCONSOLE (console)))
- write_cistring
- (pstream,
- gtk_event_name (EVENT_MAGIC_GDK_EVENT (emacs_event).type));
+ {
+ return write_cistring
+ (pstream,
+ gtk_event_name (EVENT_MAGIC_GDK_EVENT (emacs_event).type));
+ }
+ return 0;
}
static int
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/event-msw.c
--- a/src/event-msw.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/event-msw.c Wed Dec 27 10:49:27 2017 +0000
@@ -4279,11 +4279,14 @@
Fdeallocate_event (event);
}
-static void
+static Bytecount
emacs_mswindows_format_magic_event (Lisp_Event *emacs_event,
Lisp_Object pstream)
{
-#define FROB(msg) case msg: write_ascstring (pstream, "type=" #msg); break
+ Bytecount result = 0;
+#define FROB(msg) case msg: \
+ result += write_ascstring (pstream, "type=" #msg); \
+ break
switch (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event))
{
@@ -4300,9 +4303,11 @@
if (!NILP (EVENT_CHANNEL (emacs_event)))
{
- write_ascstring (pstream, " ");
- print_internal (EVENT_CHANNEL (emacs_event), pstream, 1);
+ result += write_fmt_string (pstream, " %S",
+ EVENT_CHANNEL (emacs_event));
}
+
+ return result;
}
static int
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/event-stream.c
--- a/src/event-stream.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/event-stream.c Wed Dec 27 10:49:27 2017 +0000
@@ -75,6 +75,8 @@
#include <config.h>
#include "lisp.h"
+#define EXPOSE_FIXED_BUFFER_INTERNALS 1
+#include "lstream.h"
#include "blocktype.h"
#include "buffer.h"
#include "commands.h"
@@ -85,7 +87,6 @@
#include "frame-impl.h"
#include "insdel.h" /* for buffer_reset_changes */
#include "keymap.h"
-#include "lstream.h"
#include "macros.h" /* for defining_keyboard_macro */
#include "menubar.h" /* #### for evil kludges. */
#include "process.h"
@@ -481,11 +482,11 @@
event_stream->handle_magic_event_cb (event);
}
-void
+Bytecount
event_stream_format_magic_event (Lisp_Event *event, Lisp_Object pstream)
{
check_event_stream_ok ();
- event_stream->format_magic_event_cb (event, pstream);
+ return event_stream->format_magic_event_cb (event, pstream);
}
int
@@ -644,9 +645,9 @@
Lisp_Object event)
{
/* This function can GC */
- DECLARE_EISTRING_MALLOC (buf);
Bytecount buf_fill_pointer = command_builder->echo_buf_fill_pointer;
- Bytecount len;
+ Bytecount len = 0;
+ DECLARE_STACK_FIXED_BUFFER_LSTREAM (stream);
if (buf_fill_pointer < 0)
{
@@ -654,28 +655,35 @@
clear_echo_area (selected_frame (), Qnil, 0);
}
- format_event_object (buf, event, 1);
- len = eilen (buf);
-
- if (NILP (command_builder->echo_buf) ||
- (len + buf_fill_pointer + 3 > XSTRING_LENGTH (command_builder->echo_buf)))
+ if (NILP (command_builder->echo_buf))
{
- eifree (buf);
return;
}
- eicat_ascii (buf, " - ");
-
- memcpy (XSTRING_DATA (command_builder->echo_buf) + buf_fill_pointer,
- eidata (buf), eilen (buf));
+ INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM
+ (stream, XSTRING_DATA (command_builder->echo_buf) + buf_fill_pointer,
+ XSTRING_LENGTH (command_builder->echo_buf) - buf_fill_pointer);
+
+ len += format_event_object (stream, event, 1);
+
+ if (len + buf_fill_pointer + 3 > XSTRING_LENGTH (command_builder->echo_buf))
+ {
+ memset (XSTRING_DATA (command_builder->echo_buf) + buf_fill_pointer, 0,
+ XSTRING_LENGTH (command_builder->echo_buf) - buf_fill_pointer);
+ return; /* Not enough space. */
+ }
+
+ write_ascstring (stream, " - ");
+
init_string_ascii_begin (command_builder->echo_buf);
bump_string_modiff (command_builder->echo_buf);
sledgehammer_check_ascii_begin (command_builder->echo_buf);
- command_builder->echo_buf_end = buf_fill_pointer + eilen (buf);
+ command_builder->echo_buf_end
+ = buf_fill_pointer + len + qxestrlen ((const Ibyte *) " - ");
/* Including the first space of the trailing " - ". */
- command_builder->echo_buf_fill_pointer = buf_fill_pointer + len + 1;
- eifree (buf);
+ command_builder->echo_buf_fill_pointer = buf_fill_pointer + len
+ + ichar_len (' ');
}
static void
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/event-tty.c
--- a/src/event-tty.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/event-tty.c Wed Dec 27 10:49:27 2017 +0000
@@ -247,11 +247,12 @@
}
}
-static void
+static Bytecount
emacs_tty_format_magic_event (Lisp_Event *UNUSED (emacs_event),
Lisp_Object UNUSED (pstream))
{
/* Nothing to do currently */
+ return 0;
}
static int
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/events.c
--- a/src/events.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/events.c Wed Dec 27 10:49:27 2017 +0000
@@ -288,16 +288,6 @@
}
static void
-print_event_1 (const Ascbyte *str, Lisp_Object obj, Lisp_Object printcharfun)
-{
- DECLARE_EISTRING_MALLOC (ei);
- write_ascstring (printcharfun, str);
- format_event_object (ei, obj, 0);
- write_eistring (printcharfun, ei);
- eifree (ei);
-}
-
-static void
print_event (Lisp_Object obj, Lisp_Object printcharfun,
int UNUSED (escapeflag))
{
@@ -307,17 +297,21 @@
switch (XEVENT (obj)->event_type)
{
case key_press_event:
- print_event_1 ("#<keypress-event ", obj, printcharfun);
+ write_ascstring (printcharfun, "#<keypress-event ");
+ format_event_object (printcharfun, obj, 0);
break;
case button_press_event:
- print_event_1 ("#<buttondown-event ", obj, printcharfun);
+ write_ascstring (printcharfun, "#<buttondown-event ");
+ format_event_object (printcharfun, obj, 0);
break;
case button_release_event:
- print_event_1 ("#<buttonup-event ", obj, printcharfun);
+ write_ascstring (printcharfun, "#<buttonup-event ");
+ format_event_object (printcharfun, obj, 0);
break;
case magic_event:
case magic_eval_event:
- print_event_1 ("#<magic-event ", obj, printcharfun);
+ write_ascstring (printcharfun, "#<magic-event ");
+ format_event_object (printcharfun, obj, 0);
break;
case pointer_motion_event:
{
@@ -327,39 +321,37 @@
Vy = Fevent_y_pixel (obj);
assert (FIXNUMP (Vy));
write_fmt_string (printcharfun, "#<motion-event %ld, %ld",
- (long) XFIXNUM (Vx), (long) XFIXNUM (Vy));
+ XFIXNUM (Vx), XFIXNUM (Vy));
break;
}
case process_event:
- write_fmt_string_lisp (printcharfun, "#<process-event %S",
- XEVENT_PROCESS_PROCESS (obj));
- break;
+ write_fmt_string_lisp (printcharfun, "#<process-event %S",
+ XEVENT_PROCESS_PROCESS (obj));
+ break;
case timeout_event:
- write_fmt_string_lisp (printcharfun, "#<timeout-event %S",
- XEVENT_TIMEOUT_OBJECT (obj));
- break;
+ write_fmt_string_lisp (printcharfun, "#<timeout-event %S",
+ XEVENT_TIMEOUT_OBJECT (obj));
+ break;
case empty_event:
- write_ascstring (printcharfun, "#<empty-event");
- break;
+ write_ascstring (printcharfun, "#<empty-event");
+ break;
case misc_user_event:
- write_fmt_string_lisp (printcharfun, "#<misc-user-event (%S",
- XEVENT_MISC_USER_FUNCTION (obj));
- write_fmt_string_lisp (printcharfun, " %S)",
- XEVENT_MISC_USER_OBJECT (obj));
- break;
+ write_fmt_string_lisp (printcharfun, "#<misc-user-event (%S %S)",
+ XEVENT_MISC_USER_FUNCTION (obj),
+ XEVENT_MISC_USER_OBJECT (obj));
+ break;
case eval_event:
- write_fmt_string_lisp (printcharfun, "#<eval-event (%S",
- XEVENT_EVAL_FUNCTION (obj));
- write_fmt_string_lisp (printcharfun, " %S)",
- XEVENT_EVAL_OBJECT (obj));
- break;
+ write_fmt_string_lisp (printcharfun, "#<eval-event (%S %S)",
+ XEVENT_EVAL_FUNCTION (obj),
+ XEVENT_EVAL_OBJECT (obj));
+ break;
case dead_event:
- write_ascstring (printcharfun, "#<DEALLOCATED-EVENT");
- break;
+ write_ascstring (printcharfun, "#<DEALLOCATED-EVENT");
+ break;
default:
- write_ascstring (printcharfun, "#<UNKNOWN-EVENT-TYPE");
- break;
- }
+ write_ascstring (printcharfun, "#<UNKNOWN-EVENT-TYPE");
+ break;
+ }
write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
}
@@ -1491,15 +1483,16 @@
}
-/* Concatenate a string description of EVENT onto the end of BUF. If
- BRIEF, use short forms for keys, e.g. C- instead of control-. */
-
-void
-format_event_object (Eistring *buf, Lisp_Object event, int brief)
+/* Write a string description of EVENT to PRINTCHARFUN. If BRIEF is
+ non-zero, use short forms for keys, e.g. C- instead of control-. */
+Bytecount
+format_event_object (Lisp_Object printcharfun, Lisp_Object event,
+ Boolint brief)
{
- int mouse_p = 0;
+ Boolint mouse_p = 0;
int mod = 0;
Lisp_Object key;
+ Bytecount result = 0;
switch (XEVENT_TYPE (event))
{
@@ -1512,7 +1505,7 @@
mod & (XEMACS_MOD_CONTROL | XEMACS_MOD_META | XEMACS_MOD_SUPER |
XEMACS_MOD_HYPER))
{
- int k = XCHAR (key);
+ Ichar k = XCHAR (key);
if (k >= 'a' && k <= 'z')
key = make_char (k - ('a' - 'A'));
else if (k >= 'A' && k <= 'Z')
@@ -1532,33 +1525,48 @@
}
case magic_event:
{
- Lisp_Object stream;
- struct gcpro gcpro1;
- GCPRO1 (stream);
-
- stream = make_resizing_buffer_output_stream ();
- event_stream_format_magic_event (XEVENT (event), stream);
- Lstream_flush (XLSTREAM (stream));
- eicat_raw (buf, resizing_buffer_stream_ptr (XLSTREAM (stream)),
- Lstream_byte_count (XLSTREAM (stream)));
- Lstream_delete (XLSTREAM (stream));
- UNGCPRO;
- return;
+ return event_stream_format_magic_event (XEVENT (event),
+ printcharfun);
+ }
+ case magic_eval_event:
+ {
+ return write_ascstring (printcharfun, "magic-eval");
+ }
+ case pointer_motion_event:
+ {
+ return write_ascstring (printcharfun, "motion");
+ }
+ case misc_user_event:
+ {
+ return write_ascstring (printcharfun, "misc-user");
}
- case magic_eval_event: eicat_ascii (buf, "magic-eval"); return;
- case pointer_motion_event: eicat_ascii (buf, "motion"); return;
- case misc_user_event: eicat_ascii (buf, "misc-user"); return;
- case eval_event: eicat_ascii (buf, "eval"); return;
- case process_event: eicat_ascii (buf, "process"); return;
- case timeout_event: eicat_ascii (buf, "timeout"); return;
- case empty_event: eicat_ascii (buf, "empty"); return;
- case dead_event: eicat_ascii (buf, "DEAD-EVENT"); return;
+ case eval_event:
+ {
+ return write_ascstring (printcharfun, "eval");
+ }
+ case process_event:
+ {
+ return write_ascstring (printcharfun, "process");
+ }
+ case timeout_event:
+ {
+ return write_ascstring (printcharfun, "timeout");
+ }
+ case empty_event:
+ {
+ return write_ascstring (printcharfun, "empty");
+ }
+ case dead_event:
+ {
+ return write_ascstring (printcharfun, "DEAD-EVENT");
+ }
default:
ABORT ();
- return;
+ return 0;
}
-#define modprint(x,y) \
- do { if (brief) eicat_ascii (buf, (y)); else eicat_ascii (buf, (x)); } while (0)
+#define modprint(x,y) \
+ do { if (brief) result += write_ascstring (printcharfun, (y)); \
+ else result += write_ascstring (printcharfun, (x)); } while (0)
if (mod & XEMACS_MOD_CONTROL) modprint ("control-", "C-");
if (mod & XEMACS_MOD_META) modprint ("meta-", "M-");
if (mod & XEMACS_MOD_SUPER) modprint ("super-", "S-");
@@ -1567,14 +1575,18 @@
if (mod & XEMACS_MOD_SHIFT) modprint ("shift-", "Sh-");
if (mouse_p)
{
- eicat_ascii (buf, "button");
+ result += write_ascstring (printcharfun, "button");
--mouse_p;
}
#undef modprint
if (CHARP (key))
- eicat_ch (buf, XCHAR (key));
+ {
+ Ibyte str[MAX_ICHAR_LEN];
+ result += write_string_1 (printcharfun, str,
+ set_itext_ichar (str, XCHAR (key)));
+ }
else if (SYMBOLP (key))
{
const Ascbyte *str = 0;
@@ -1589,14 +1601,21 @@
else if (EQ (key, QKbackspace)) str = "BS";
}
if (str)
- eicat_ascii (buf, str);
+ {
+ result += write_ascstring (printcharfun, str);
+ }
else
- eicat_lstr (buf, XSYMBOL (key)->name);
+ {
+ result += write_lisp_string (printcharfun, XSYMBOL (key)->name, 0,
+ XSTRING_LENGTH (XSYMBOL (key)->name));
+ }
}
else
ABORT ();
if (mouse_p)
- eicat_ascii (buf, "up");
+ result += write_ascstring (printcharfun, "up");
+
+ return result;
}
void
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/events.h
--- a/src/events.h Sat Dec 23 14:57:42 2017 +0000
+++ b/src/events.h Wed Dec 27 10:49:27 2017 +0000
@@ -44,7 +44,7 @@
int (*event_pending_p) (int);
void (*next_event_cb) (Lisp_Event *);
void (*handle_magic_event_cb) (Lisp_Event *);
- void (*format_magic_event_cb) (Lisp_Event *, Lisp_Object pstream);
+ Bytecount (*format_magic_event_cb) (Lisp_Event *, Lisp_Object pstream);
int (*compare_magic_event_cb) (Lisp_Event *, Lisp_Event *);
Hashcode (*hash_magic_event_cb)(Lisp_Event *);
int (*add_timeout_cb) (EMACS_TIME);
@@ -956,8 +956,8 @@
} character_to_event_meta_behavior;
/* from events.c */
-void format_event_object (Eistring *buf, Lisp_Object event, int brief);
-/*void format_event_data_object (Eistring *buf, Lisp_Object data, int brief);*/
+Bytecount format_event_object (Lisp_Object printcharfun, Lisp_Object event,
+ Boolint brief);
void character_to_event (Ichar, Lisp_Event *, struct console *,
character_to_event_meta_behavior meta_flag,
int do_backspace_mapping);
@@ -1004,7 +1004,8 @@
Lisp_Object dequeue_dispatch_event (void);
void enqueue_magic_eval_event (void (*fun) (Lisp_Object), Lisp_Object object);
void event_stream_handle_magic_event (Lisp_Event *event);
-void event_stream_format_magic_event (Lisp_Event *event, Lisp_Object pstream);
+Bytecount event_stream_format_magic_event (Lisp_Event *event,
+ Lisp_Object pstream);
int event_stream_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2);
Hashcode event_stream_hash_magic_event (Lisp_Event *e);
void event_stream_select_console (struct console *con);
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/gui-x.c
--- a/src/gui-x.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/gui-x.c Wed Dec 27 10:49:27 2017 +0000
@@ -487,14 +487,16 @@
}
else if (SYMBOLP (pgui->callback)) /* Show the binding of this command. */
{
- DECLARE_EISTRING_MALLOC (buf);
+ Ibyte buf[64];
/* #### Warning, dependency here on current_buffer and point */
- where_is_to_char (pgui->callback, buf);
- if (eilen (buf) > 0)
- wv->key = ITEXT_TO_EXTERNAL_MALLOC (eidata (buf), Qlwlib_encoding);
+ Bytecount blen = where_is_to_Ibyte (pgui->callback, buf, sizeof (buf));
+ if (blen > 0)
+ {
+ TO_EXTERNAL_FORMAT (DATA, (buf, blen), C_STRING_MALLOC, wv->key,
+ Qlwlib_encoding);
+ }
else
wv->key = 0;
- eifree (buf);
}
CHECK_SYMBOL (pgui->style);
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/gui.c
--- a/src/gui.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/gui.c Wed Dec 27 10:49:27 2017 +0000
@@ -550,13 +550,13 @@
/* See if we can derive keys out of callback symbol */
if (SYMBOLP (pgui_item->callback))
{
- DECLARE_EISTRING_MALLOC (buf);
- Lisp_Object str;
-
- where_is_to_char (pgui_item->callback, buf);
- str = eimake_string (buf);
- eifree (buf);
- return str;
+ Ibyte buf[64];
+ Bytecount blen
+ = where_is_to_Ibyte (pgui_item->callback, buf, sizeof (buf));
+ if (blen > 0)
+ {
+ return make_string (buf, blen);
+ }
}
/* No keys - no right flush display */
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/keymap.c
--- a/src/keymap.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/keymap.c Wed Dec 27 10:49:27 2017 +0000
@@ -27,6 +27,8 @@
#include <config.h>
#include "lisp.h"
+#define EXPOSE_FIXED_BUFFER_INTERNALS 1
+#include "lstream.h"
#include "buffer.h"
#include "bytecode.h"
#include "console-impl.h"
@@ -3564,14 +3566,13 @@
*/
(key))
{
+ Lisp_Object stream = make_resizing_buffer_output_stream ();
+
if (SYMBOLP (key))
key = Fcons (key, Qnil); /* sleaze sleaze */
if (EVENTP (key) || CHAR_OR_CHAR_INTP (key))
{
- DECLARE_EISTRING_MALLOC (buf);
- Lisp_Object str;
-
if (!EVENTP (key))
{
Lisp_Object event = Fmake_event (Qnil, Qnil);
@@ -3579,51 +3580,47 @@
character_to_event (XCHAR (key), XEVENT (event),
XCONSOLE (Vselected_console),
high_bit_is_meta, 1);
- format_event_object (buf, event, 1);
+ format_event_object (stream, event, 1);
Fdeallocate_event (event);
}
else
- format_event_object (buf, key, 1);
- str = eimake_string (buf);
- eifree (buf);
- return str;
+ format_event_object (stream, key, 1);
+
+ return resizing_buffer_to_lisp_string (XLSTREAM (stream));
}
if (CONSP (key))
{
- DECLARE_EISTRING (bufp);
-
EXTERNAL_LIST_LOOP_3 (keysym, key, rest)
{
- if (EQ (keysym, Qcontrol)) eicat_ascii (bufp, "C-");
- else if (EQ (keysym, Qctrl)) eicat_ascii (bufp, "C-");
- else if (EQ (keysym, Qmeta)) eicat_ascii (bufp, "M-");
- else if (EQ (keysym, Qsuper)) eicat_ascii (bufp, "S-");
- else if (EQ (keysym, Qhyper)) eicat_ascii (bufp, "H-");
- else if (EQ (keysym, Qalt)) eicat_ascii (bufp, "A-");
- else if (EQ (keysym, Qshift)) eicat_ascii (bufp, "Sh-");
+ if (EQ (keysym, Qcontrol)) write_ascstring (stream, "C-");
+ else if (EQ (keysym, Qctrl)) write_ascstring (stream, "C-");
+ else if (EQ (keysym, Qmeta)) write_ascstring (stream, "M-");
+ else if (EQ (keysym, Qsuper)) write_ascstring (stream, "S-");
+ else if (EQ (keysym, Qhyper)) write_ascstring (stream, "H-");
+ else if (EQ (keysym, Qalt)) write_ascstring (stream, "A-");
+ else if (EQ (keysym, Qshift)) write_ascstring (stream, "Sh-");
else if (CHAR_OR_CHAR_INTP (keysym))
- eicat_ch (bufp, XCHAR_OR_CHAR_INT (keysym));
+ {
+ Ibyte str[MAX_ICHAR_LEN];
+
+ write_string_1 (stream, str,
+ set_itext_ichar (str,
+ XCHAR_OR_CHAR_INT (keysym)));
+ }
else
{
CHECK_SYMBOL (keysym);
-#if 0 /* This is bogus */
- if (EQ (keysym, QKlinefeed)) eicat_ascii (bufp, "LFD");
- else if (EQ (keysym, QKtab)) eicat_ascii (bufp, "TAB");
- else if (EQ (keysym, QKreturn)) eicat_ascii (bufp, "RET");
- else if (EQ (keysym, QKescape)) eicat_ascii (bufp, "ESC");
- else if (EQ (keysym, QKdelete)) eicat_ascii (bufp, "DEL");
- else if (EQ (keysym, QKspace)) eicat_ascii (bufp, "SPC");
- else if (EQ (keysym, QKbackspace)) eicat_ascii (bufp, "BS");
- else
-#endif
- eicat_lstr (bufp, XSYMBOL (keysym)->name);
+ write_lisp_string (stream, XSYMBOL (keysym)->name, 0,
+ XSTRING_LENGTH (XSYMBOL (keysym)->name));
if (!NILP (XCDR (rest)))
invalid_argument ("Invalid key description", key);
}
}
- return eimake_string (bufp);
+
+ return resizing_buffer_to_lisp_string (XLSTREAM (stream));
}
+
return Fsingle_key_description
(wrong_type_argument (intern ("char-or-event-p"), key));
}
@@ -3742,7 +3739,7 @@
static Lisp_Object
where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
- Lisp_Object firstonly, Eistring *target_buffer);
+ Lisp_Object firstonly, Lisp_Object target_buffer);
DEFUN ("where-is-internal", Fwhere_is_internal, 1, 5, 0, /*
Return list of keys that invoke DEFINITION in KEYMAPS.
@@ -3813,22 +3810,23 @@
return Qnil;
}
- return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
+ return where_is_internal (definition, gubbish, nmaps, firstonly, Qnil);
}
/* This function is like
(key-description (where-is-internal definition nil t))
- except that it writes its output into a (char *) buffer that you
- provide; it doesn't cons (or allocate memory) at all, so it's
- very fast. This is used by menubar.c.
- */
-void
-where_is_to_char (Lisp_Object definition, Eistring *buffer)
+
+ except that it writes its output into an (Ibyte *) buffer that you
+ provide; it doesn't allocate heap memory for this, so it's fast. This is
+ used by GUI code when generating menu entries. */
+Bytecount
+where_is_to_Ibyte (Lisp_Object definition, Ibyte *buffer, Bytecount bufsize)
{
/* This function can GC */
- Lisp_Object maps[100];
+ Lisp_Object maps[100], result;
Lisp_Object *gubbish = maps;
int nmaps;
+ DECLARE_STACK_FIXED_BUFFER_LSTREAM (stream);
/* Get keymaps as an array */
nmaps = get_relevant_keymaps (Qnil, Qnil, countof (maps), gubbish);
@@ -3838,10 +3836,38 @@
nmaps = get_relevant_keymaps (Qnil, Qnil, nmaps, gubbish);
}
- where_is_internal (definition, maps, nmaps, Qt, buffer);
+ INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM (stream, buffer, bufsize);
+
+ result = where_is_internal (definition, maps, nmaps, Qt, stream);
+
+ if (NILP (result))
+ {
+ return 0;
+ }
+
+ if (XFIXNUM (result) >= bufsize)
+ {
+ Ibyte *bufp = buffer + bufsize;
+ unsigned jj = 0;
+
+ while (jj < sizeof (" ..."))
+ {
+ DEC_IBYTEPTR (bufp);
+ jj++;
+ }
+
+ bufp += set_itext_ichar (bufp, ' ');
+ bufp += set_itext_ichar (bufp, '.');
+ bufp += set_itext_ichar (bufp, '.');
+ bufp += set_itext_ichar (bufp, '.');
+ bufp += set_itext_ichar (bufp, 0);
+ return bufp - ichar_len (0) - buffer;
+ }
+
+ return XREALFIXNUM (result); /* Return the amount of space it would have
+ taken, on the model of snprintf(). */
}
-
static Lisp_Object
raw_keys_to_keys (Lisp_Key_Data *keys, int count)
{
@@ -3851,11 +3877,11 @@
return result;
}
-
-static void
-format_raw_keys (Lisp_Key_Data *keys, int count, Eistring *buf)
+static Bytecount
+format_raw_keys (Lisp_Key_Data *keys, int count, Lisp_Object stream)
{
int i;
+ Bytecount result = 0;
Lisp_Object event = Fmake_event (Qnil, Qnil);
XSET_EVENT_TYPE (event, key_press_event);
XSET_EVENT_CHANNEL (event, Vselected_console);
@@ -3863,11 +3889,15 @@
{
XSET_EVENT_KEY_KEYSYM (event, keys[i].keysym);
XSET_EVENT_KEY_MODIFIERS (event, KEY_DATA_MODIFIERS (&keys[i]));
- format_event_object (buf, event, 1);
+ result += format_event_object (stream, event, 1);
if (i < count - 1)
- eicat_ascii (buf, " ");
+ {
+ result += write_ascstring (stream, " ");
+ }
}
Fdeallocate_event (event);
+
+ return result;
}
@@ -3887,7 +3917,7 @@
(keys_so_far is a global buffer and the keys_count arg says how much
of it we're currently interested in.)
- If target_buffer is provided, then we write a key-description into it,
+ If target_buffer is non-nil, then we write a key-description into it,
to avoid consing a string. This only works with firstonly on.
*/
@@ -3899,7 +3929,7 @@
int firstonly;
int keys_count;
int modifiers_so_far;
- Eistring *target_buffer;
+ Lisp_Object target_buffer;
Lisp_Key_Data *keys_so_far;
int keys_so_far_total_size;
int keys_so_far_malloced;
@@ -3916,7 +3946,7 @@
const int firstonly = c->firstonly;
const int keys_count = c->keys_count;
const int modifiers_so_far = c->modifiers_so_far;
- Eistring *target_buffer = c->target_buffer;
+ Lisp_Object target_buffer = c->target_buffer;
Lisp_Object keys = Fgethash (definition,
XKEYMAP (map)->inverse_table,
Qnil);
@@ -3957,11 +3987,14 @@
}
/* OK, the key is for real */
- if (target_buffer)
+ if (!NILP (target_buffer))
{
+ Bytecount blen
+ = format_raw_keys (so_far, keys_count + 1, target_buffer);
+ /* Don't include the trailing ?\x00 in the bytecount. */
+ write_string_1 (target_buffer, (const Ibyte *) "\0", 1);
assert (firstonly);
- format_raw_keys (so_far, keys_count + 1, target_buffer);
- return Qone;
+ return make_fixnum (blen);
}
else if (firstonly)
return raw_keys_to_keys (so_far, keys_count + 1);
@@ -4072,7 +4105,7 @@
static Lisp_Object
where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
- Lisp_Object firstonly, Eistring *target_buffer)
+ Lisp_Object firstonly, Lisp_Object target_buffer)
{
/* This function can GC */
Lisp_Object result = Qnil;
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/lisp.h
--- a/src/lisp.h Sat Dec 23 14:57:42 2017 +0000
+++ b/src/lisp.h Wed Dec 27 10:49:27 2017 +0000
@@ -5663,7 +5663,7 @@
EXFUN (Fmake_sparse_keymap, 1);
EXFUN (Fset_keymap_parents, 2);
-void where_is_to_char (Lisp_Object, Eistring *);
+Bytecount where_is_to_Ibyte (Lisp_Object, Ibyte *, Bytecount);
/* Defined in lread.c */
EXFUN (Fread, 1);
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/lstream.h
--- a/src/lstream.h Sat Dec 23 14:57:42 2017 +0000
+++ b/src/lstream.h Wed Dec 27 10:49:27 2017 +0000
@@ -572,7 +572,7 @@
} lname##u; \
Lisp_Object lname = wrap_pointer_1 (&(lname##u.l)) \
-#define INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM(lname, buf, size) do \
+#define INIT_STACK_FIXED_BUFFER_OUTPUT_STREAM(lname, buf, bsize) do \
{ \
memset (lname##u.s, 0, max (sizeof (lname##u.s), \
sizeof (lname##u.l))); \
@@ -583,7 +583,7 @@
lname##u.l.flags = LSTR_IS_OPEN; \
lname##u.l.flags |= LSTR_WRITE; \
FIXED_BUFFER_STREAM_DATA (&(lname##u.l))->outbuf = buf; \
- FIXED_BUFFER_STREAM_DATA (&(lname##u.l))->size = size; \
+ FIXED_BUFFER_STREAM_DATA (&(lname##u.l))->size = bsize; \
} while (0)
#endif
diff -r 714a6e9c1669 -r 27f66ce6ab71 src/menubar-gtk.c
--- a/src/menubar-gtk.c Sat Dec 23 14:57:42 2017 +0000
+++ b/src/menubar-gtk.c Wed Dec 27 10:49:27 2017 +0000
@@ -736,20 +736,19 @@
}
else if (SYMBOLP (callback))
{
- DECLARE_EISTRING_MALLOC (buf);
-
+ Ibyte buf[64];
/* #### Warning, dependency here on current_buffer and point */
- where_is_to_char (callback, buf);
+ Bytecount blen
+ = where_is_to_Ibyte (callback, buf, sizeof (buf));
- if (eilen (buf) > 0)
- keys = eimake_string (buf);
+ if (blen > 0)
+ {
+ keys = make_string (buf, blen);
+ }
else
{
-
keys = Qnil;
}
-
- eifree (buf);
}
}
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)