Mercurial > hg > xemacs-beta
annotate src/print.c @ 5557:53c066311921
If XLookupKeysym() returned an XFree86 "special key", ignore it. Fixes Sh-F11.
src/ChangeLog addition:
2011-08-27 Aidan Kehoe <kehoea@parhasard.net>
* config.h.in: Make HAVE_X11_XF86KEYSYM_H available here.
* event-Xt.c: #include X11/XF86keysym.h if available.
* event-Xt.c (x_event_to_emacs_event):
If XLookupKeysym () returned one of the XFree86 "special action
keys" for the shifted keysym, treat that as NoSymbol, fixing a
long-standing bug with shifted function keys under X.org.
Details of why in:
http://mid.gmane.org/16960.15685.26911.644835@parhasard.net
ChangeLog addition:
2011-08-27 Aidan Kehoe <kehoea@parhasard.net>
* configure.ac: Check whether X11/XF86keysym.h is available, to
allow us to avoid a bug in the interaction of XKB and XLookupKeysym.
* configure: Regenerate.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 27 Aug 2011 20:35:23 +0100 |
| parents | b9167d522a9a |
| children | 58b38d5b32d0 |
| rev | line source |
|---|---|
| 428 | 1 /* Lisp object printing and output streams. |
| 2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc. | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2005, 2010 Ben Wing. |
| 428 | 4 |
| 5 This file is part of XEmacs. | |
| 6 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
| 428 | 8 under the terms of the GNU General Public License as published by the |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
10 option) any later version. |
| 428 | 11 |
| 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 15 for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 428 | 19 |
| 20 /* Synched up with: Not synched with FSF. */ | |
| 21 | |
| 22 /* This file has been Mule-ized. */ | |
| 23 | |
| 771 | 24 /* Seriously divergent from FSF by this point. |
| 25 | |
| 26 Seriously hacked on by Ben Wing for Mule. All stdio code also by Ben, | |
| 27 as well as the debugging code (initial version of debug_print(), though, | |
| 28 by Jamie Zawinski) and the _fmt interfaces. Also a fair amount of work | |
| 29 by Hrvoje, e.g. floating-point code and rewriting to avoid O(N^2) | |
| 30 consing when outputting to the echo area. Print-circularity code by | |
| 31 Martin? */ | |
| 428 | 32 |
| 33 #include <config.h> | |
| 34 #include "lisp.h" | |
| 35 | |
| 36 #include "backtrace.h" | |
| 37 #include "buffer.h" | |
| 38 #include "bytecode.h" | |
| 872 | 39 #include "device-impl.h" |
| 428 | 40 #include "extents.h" |
| 41 #include "frame.h" | |
| 42 #include "insdel.h" | |
| 43 #include "lstream.h" | |
| 771 | 44 #include "opaque.h" |
| 800 | 45 |
| 872 | 46 #include "console-tty-impl.h" |
| 47 #include "console-stream-impl.h" | |
| 442 | 48 #ifdef WIN32_NATIVE |
| 49 #include "console-msw.h" | |
| 50 #endif | |
| 428 | 51 |
| 800 | 52 #include "sysfile.h" |
| 53 | |
| 428 | 54 #include <float.h> |
| 55 /* Define if not in float.h */ | |
| 56 #ifndef DBL_DIG | |
| 57 #define DBL_DIG 16 | |
| 58 #endif | |
| 59 | |
| 60 Lisp_Object Vstandard_output, Qstandard_output; | |
| 61 | |
| 62 /* The subroutine object for external-debugging-output is kept here | |
| 63 for the convenience of the debugger. */ | |
| 442 | 64 Lisp_Object Qexternal_debugging_output, Qalternate_debugging_output; |
| 65 | |
| 66 #ifdef HAVE_MS_WINDOWS | |
| 67 Lisp_Object Qmswindows_debugging_output; | |
| 68 #endif | |
| 428 | 69 |
| 70 /* Avoid actual stack overflow in print. */ | |
| 71 static int print_depth; | |
| 72 | |
| 73 /* Detect most circularities to print finite output. */ | |
| 74 #define PRINT_CIRCLE 200 | |
| 75 static Lisp_Object being_printed[PRINT_CIRCLE]; | |
| 76 | |
| 77 /* Maximum length of list or vector to print in full; noninteger means | |
| 78 effectively infinity */ | |
| 79 | |
| 80 Lisp_Object Vprint_length; | |
| 81 Lisp_Object Qprint_length; | |
| 82 | |
| 83 /* Maximum length of string to print in full; noninteger means | |
| 84 effectively infinity */ | |
| 85 | |
| 86 Lisp_Object Vprint_string_length; | |
| 87 Lisp_Object Qprint_string_length; | |
| 88 | |
| 89 /* Maximum depth of list to print in full; noninteger means | |
| 90 effectively infinity. */ | |
| 91 | |
| 92 Lisp_Object Vprint_level; | |
| 93 | |
| 94 /* Label to use when making echo-area messages. */ | |
| 95 | |
| 96 Lisp_Object Vprint_message_label; | |
| 97 | |
| 98 /* Nonzero means print newlines in strings as \n. */ | |
| 99 | |
| 100 int print_escape_newlines; | |
| 101 int print_readably; | |
| 102 | |
| 103 /* Non-nil means print #: before uninterned symbols. | |
| 104 Neither t nor nil means so that and don't clear Vprint_gensym_alist | |
| 105 on entry to and exit from print functions. */ | |
| 106 Lisp_Object Vprint_gensym; | |
| 107 Lisp_Object Vprint_gensym_alist; | |
| 108 | |
| 109 Lisp_Object Qdisplay_error; | |
| 110 Lisp_Object Qprint_message_label; | |
| 111 | |
| 112 /* Force immediate output of all printed data. Used for debugging. */ | |
| 113 int print_unbuffered; | |
| 114 | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
115 /* Non-zero if in debug-printing */ |
|
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
116 int in_debug_print; |
|
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
117 |
| 428 | 118 FILE *termscript; /* Stdio stream being used for copy of all output. */ |
| 119 | |
| 1346 | 120 static void write_string_to_alternate_debugging_output (const Ibyte *str, |
| 771 | 121 Bytecount len); |
| 122 | |
| 1957 | 123 /* To avoid consing in debug_prin1, we package up variables we need to bind |
| 124 into an opaque object. */ | |
| 125 struct debug_bindings | |
| 126 { | |
| 2367 | 127 int inhibit_non_essential_conversion_operations; |
| 1957 | 128 int print_depth; |
| 129 int print_readably; | |
| 130 int print_unbuffered; | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
131 int in_debug_print; |
| 1957 | 132 int gc_currently_forbidden; |
| 133 Lisp_Object Vprint_length; | |
| 134 Lisp_Object Vprint_level; | |
| 135 Lisp_Object Vinhibit_quit; | |
| 136 }; | |
| 137 | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
138 static int begin_inhibit_non_essential_conversion_operations (void); |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
139 |
| 428 | 140 |
| 141 | |
| 142 int stdout_needs_newline; | |
| 1346 | 143 int stdout_clear_before_next_output; |
| 428 | 144 |
| 771 | 145 /* Basic function to actually write to a stdio stream or TTY console. */ |
| 146 | |
| 442 | 147 static void |
| 1346 | 148 write_string_to_stdio_stream_1 (FILE *stream, struct console *con, |
| 149 const Ibyte *ptr, Bytecount len, | |
| 150 int must_flush) | |
| 428 | 151 { |
| 771 | 152 Extbyte *extptr = 0; |
| 153 Bytecount extlen = 0; | |
| 154 int output_is_std_handle = | |
| 155 stream ? stream == stdout || stream == stderr : | |
| 156 CONSOLE_TTY_DATA (con)->is_stdio; | |
| 157 | |
| 158 if (stream || output_is_std_handle) | |
| 159 { | |
| 2367 | 160 if (initialized && !inhibit_non_essential_conversion_operations) |
| 771 | 161 TO_EXTERNAL_FORMAT (DATA, (ptr, len), |
| 162 ALLOCA, (extptr, extlen), | |
| 163 Qterminal); | |
| 164 else | |
| 165 { | |
| 2367 | 166 #ifdef NON_ASCII_INTERNAL_FORMAT |
| 167 #error Do something here | |
| 168 #else | |
| 771 | 169 extptr = (Extbyte *) ptr; |
| 170 extlen = (Bytecount) len; | |
| 2367 | 171 #endif |
| 771 | 172 } |
| 173 } | |
| 174 | |
| 428 | 175 if (stream) |
| 176 { | |
| 442 | 177 #ifdef WIN32_NATIVE |
| 178 HANDLE errhand = GetStdHandle (STD_INPUT_HANDLE); | |
| 179 int no_useful_stderr = errhand == 0 || errhand == INVALID_HANDLE_VALUE; | |
| 180 | |
| 181 if (!no_useful_stderr) | |
| 182 no_useful_stderr = !PeekNamedPipe (errhand, 0, 0, 0, 0, 0); | |
| 183 /* we typically have no useful stdout/stderr under windows if we're | |
| 184 being invoked graphically. */ | |
| 185 if (no_useful_stderr) | |
| 771 | 186 mswindows_output_console_string (ptr, len); |
| 442 | 187 else |
| 428 | 188 #endif |
| 442 | 189 { |
| 771 | 190 retry_fwrite (extptr, 1, extlen, stream); |
| 442 | 191 #ifdef WIN32_NATIVE |
| 192 /* Q122442 says that pipes are "treated as files, not as | |
| 193 devices", and that this is a feature. Before I found that | |
| 194 article, I thought it was a bug. Thanks MS, I feel much | |
| 195 better now. - kkm */ | |
| 196 must_flush = 1; | |
| 197 #endif | |
| 198 if (must_flush) | |
| 199 fflush (stream); | |
| 200 } | |
| 428 | 201 } |
| 202 else | |
| 771 | 203 /* The stream itself does conversion to external format */ |
| 204 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), ptr, len); | |
| 442 | 205 |
| 206 if (output_is_std_handle) | |
| 428 | 207 { |
| 208 if (termscript) | |
| 209 { | |
| 771 | 210 retry_fwrite (extptr, 1, extlen, termscript); |
| 428 | 211 fflush (termscript); |
| 212 } | |
| 1346 | 213 stdout_needs_newline = (ptr[len - 1] != '\n'); |
| 428 | 214 } |
| 215 } | |
| 216 | |
| 1346 | 217 /* Write to a stdio stream or TTY console, first clearing the left side |
| 218 if necessary. */ | |
| 219 | |
| 220 static void | |
| 221 write_string_to_stdio_stream (FILE *stream, struct console *con, | |
| 222 const Ibyte *ptr, Bytecount len, | |
| 223 int must_flush) | |
| 224 { | |
| 225 if (stdout_clear_before_next_output && | |
| 226 (stream ? stream == stdout || stream == stderr : | |
| 227 CONSOLE_TTY_DATA (con)->is_stdio)) | |
| 228 { | |
| 229 if (stdout_needs_newline) | |
| 230 write_string_to_stdio_stream_1 (stream, con, (Ibyte *) "\n", 1, | |
| 231 must_flush); | |
| 232 stdout_clear_before_next_output = 0; | |
| 233 } | |
| 234 | |
| 235 write_string_to_stdio_stream_1 (stream, con, ptr, len, must_flush); | |
| 236 } | |
| 237 | |
| 238 /* | |
| 239 EXT_PRINT_STDOUT = stdout or its equivalent (may be a | |
| 240 console window under MS Windows) | |
| 241 EXT_PRINT_STDERR = stderr or its equivalent (may be a | |
| 242 console window under MS Windows) | |
| 243 EXT_PRINT_ALTERNATE = an internal character array; see | |
| 244 `alternate-debugging-output' | |
| 245 EXT_PRINT_MSWINDOWS = Under MS Windows, the "debugging output" that | |
| 246 debuggers can hook into; uses OutputDebugString() | |
| 247 system call | |
| 248 EXT_PRINT_ALL = all of the above except stdout | |
| 249 */ | |
| 250 | |
| 251 enum ext_print | |
| 252 { | |
| 253 EXT_PRINT_STDOUT = 1, | |
| 254 EXT_PRINT_STDERR = 2, | |
| 255 EXT_PRINT_ALTERNATE = 4, | |
| 256 EXT_PRINT_MSWINDOWS = 8, | |
| 257 EXT_PRINT_ALL = 14 | |
| 258 }; | |
| 259 | |
| 260 static void | |
| 261 write_string_to_external_output (const Ibyte *ptr, Bytecount len, | |
| 262 int dest) | |
| 263 { | |
| 264 if (dest & EXT_PRINT_STDOUT) | |
| 265 write_string_to_stdio_stream (stdout, 0, ptr, len, 1); | |
| 266 if (dest & EXT_PRINT_STDERR) | |
| 267 write_string_to_stdio_stream (stderr, 0, ptr, len, 1); | |
| 268 if (dest & EXT_PRINT_ALTERNATE) | |
| 269 write_string_to_alternate_debugging_output (ptr, len); | |
| 270 #ifdef WIN32_NATIVE | |
| 271 if (dest & EXT_PRINT_MSWINDOWS) | |
| 272 write_string_to_mswindows_debugging_output (ptr, len); | |
| 273 #endif | |
| 274 } | |
| 275 | |
| 276 /* #### The following function should make use of a call to the | |
| 277 emacs_vsprintf_*() functions rather than just using vsprintf. This is | |
| 278 the only way to ensure that I18N3 works properly (many implementations | |
| 279 of the *printf() functions, including the ones included in glibc, do not | |
| 280 implement the %###$ argument-positioning syntax). | |
| 442 | 281 |
| 282 Note, however, that to do this, we'd have to | |
| 283 | |
| 284 1) pre-allocate all the lstreams and do whatever else was necessary | |
| 285 to make sure that no allocation occurs, since these functions may be | |
| 286 called from fatal_error_signal(). | |
| 287 | |
| 288 2) (to be really correct) make a new lstream that outputs using | |
| 1346 | 289 mswindows_output_console_string(). |
| 290 | |
| 291 3) A reasonable compromise might be to use emacs_vsprintf() when we're | |
| 292 in a safe state, and when not, use plain vsprintf(). */ | |
| 442 | 293 |
| 771 | 294 static void |
| 1346 | 295 write_string_to_external_output_va (const CIbyte *fmt, va_list args, |
| 296 int dest) | |
| 442 | 297 { |
| 867 | 298 Ibyte kludge[8192]; |
| 771 | 299 Bytecount kludgelen; |
| 300 | |
| 2367 | 301 if (initialized && !inhibit_non_essential_conversion_operations) |
| 771 | 302 fmt = GETTEXT (fmt); |
| 867 | 303 vsprintf ((CIbyte *) kludge, fmt, args); |
| 771 | 304 kludgelen = qxestrlen (kludge); |
| 1346 | 305 write_string_to_external_output (kludge, kludgelen, dest); |
| 442 | 306 } |
| 307 | |
| 771 | 308 /* Output portably to stderr or its equivalent (i.e. may be a console |
| 309 window under MS Windows); do external-format conversion and call GETTEXT | |
| 310 on the format string. Automatically flush when done. | |
| 442 | 311 |
| 2731 | 312 NOTE: CIbyte means "internal format" data. This includes the "..." |
| 313 arguments. For numerical arguments, we have to assume that vsprintf | |
| 314 will be a good boy and format them as ASCII. For Mule internal coding | |
| 315 (and UTF-8 internal coding, if/when we get it), it is safe to pass | |
| 316 string values in internal format to be formatted, because zero octets | |
| 317 only occur in the NUL character itself. Similarly, it is safe to pass | |
| 318 pure ASCII literal strings for these functions. *Everything else must | |
| 319 be converted, including all external data.* | |
| 320 | |
| 321 This function is safe to use even when not initialized or when dying -- | |
| 322 we don't do conversion in such cases. */ | |
| 771 | 323 |
| 324 void | |
| 867 | 325 stderr_out (const CIbyte *fmt, ...) |
| 442 | 326 { |
| 327 va_list args; | |
| 328 va_start (args, fmt); | |
| 1346 | 329 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR); |
| 442 | 330 va_end (args); |
| 331 } | |
| 332 | |
| 771 | 333 /* Output portably to stdout or its equivalent (i.e. may be a console |
| 334 window under MS Windows). Works like stderr_out(). */ | |
| 442 | 335 |
| 771 | 336 void |
| 867 | 337 stdout_out (const CIbyte *fmt, ...) |
| 442 | 338 { |
| 339 va_list args; | |
| 340 va_start (args, fmt); | |
| 1346 | 341 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDOUT); |
| 342 va_end (args); | |
| 343 } | |
| 344 | |
| 345 /* Output portably to print destination as specified by DEST. */ | |
| 346 | |
| 347 void | |
| 348 external_out (int dest, const CIbyte *fmt, ...) | |
| 349 { | |
| 350 va_list args; | |
| 351 va_start (args, fmt); | |
| 352 write_string_to_external_output_va (fmt, args, dest); | |
| 442 | 353 va_end (args); |
| 771 | 354 } |
| 355 | |
| 356 /* Output portably to stderr or its equivalent (i.e. may be a console | |
| 357 window under MS Windows), as well as alternate-debugging-output and | |
| 358 (under MS Windows) the C debugging output, i.e. OutputDebugString(). | |
| 359 Works like stderr_out(). */ | |
| 360 | |
| 361 void | |
| 867 | 362 debug_out (const CIbyte *fmt, ...) |
| 771 | 363 { |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
364 int depth = begin_inhibit_non_essential_conversion_operations (); |
| 771 | 365 va_list args; |
| 366 va_start (args, fmt); | |
| 1346 | 367 write_string_to_external_output_va (fmt, args, EXT_PRINT_ALL); |
| 771 | 368 va_end (args); |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
369 unbind_to (depth); |
| 442 | 370 } |
| 371 | |
| 372 DOESNT_RETURN | |
| 867 | 373 fatal (const CIbyte *fmt, ...) |
| 442 | 374 { |
| 375 va_list args; | |
| 376 va_start (args, fmt); | |
| 377 | |
| 771 | 378 stderr_out ("\nXEmacs: fatal error: "); |
| 1346 | 379 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR); |
| 442 | 380 stderr_out ("\n"); |
| 381 | |
| 382 va_end (args); | |
| 383 exit (1); | |
| 384 } | |
| 385 | |
| 428 | 386 /* Write a string to the output location specified in FUNCTION. |
| 387 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in | |
| 771 | 388 buffer_insert_string_1() in insdel.c. |
| 389 | |
| 390 FUNCTION is one of | |
| 391 | |
| 392 -- an lstream | |
| 393 -- a buffer (insert at point and advance point) | |
| 394 -- a marker (insert at marker and advance marker) | |
| 395 -- a frame (append to echo area; clear echo area first if | |
| 396 `print-message-label' has changed since the last time) | |
| 397 -- t or nil (send to stdout) | |
| 398 -- a Lisp function of one argument (call to get data output) | |
| 399 | |
| 400 Use Qexternal_debugging_output to get output to stderr. | |
| 401 */ | |
| 428 | 402 |
| 403 static void | |
| 867 | 404 output_string (Lisp_Object function, const Ibyte *nonreloc, |
| 428 | 405 Lisp_Object reloc, Bytecount offset, Bytecount len) |
| 406 { | |
| 407 /* This function can GC */ | |
| 408 Charcount cclen; | |
| 409 /* We change the value of nonreloc (fetching it from reloc as | |
| 410 necessary), but we don't want to pass this changed value on to | |
| 411 other functions that take both a nonreloc and a reloc, or things | |
| 412 may get confused and an assertion failure in | |
| 413 fixup_internal_substring() may get triggered. */ | |
| 867 | 414 const Ibyte *newnonreloc = nonreloc; |
| 428 | 415 struct gcpro gcpro1, gcpro2; |
| 416 | |
| 417 /* Emacs won't print while GCing, but an external debugger might */ | |
| 771 | 418 #ifdef NO_PRINT_DURING_GC |
| 428 | 419 if (gc_in_progress) return; |
| 771 | 420 #endif |
| 428 | 421 |
| 422 /* Perhaps not necessary but probably safer. */ | |
| 423 GCPRO2 (function, reloc); | |
| 424 | |
| 425 fixup_internal_substring (newnonreloc, reloc, offset, &len); | |
| 426 | |
| 427 if (STRINGP (reloc)) | |
| 771 | 428 { |
| 793 | 429 cclen = string_offset_byte_to_char_len (reloc, offset, len); |
| 771 | 430 newnonreloc = XSTRING_DATA (reloc); |
| 431 } | |
| 432 else | |
| 433 cclen = bytecount_to_charcount (newnonreloc + offset, len); | |
| 428 | 434 |
| 435 if (LSTREAMP (function)) | |
| 436 { | |
| 437 if (STRINGP (reloc)) | |
| 438 { | |
| 439 /* Protect against Lstream_write() causing a GC and | |
| 440 relocating the string. For small strings, we do it by | |
| 441 alloc'ing the string and using a copy; for large strings, | |
| 442 we inhibit GC. */ | |
| 443 if (len < 65536) | |
| 444 { | |
| 2367 | 445 Ibyte *copied = alloca_ibytes (len); |
| 428 | 446 memcpy (copied, newnonreloc + offset, len); |
| 447 Lstream_write (XLSTREAM (function), copied, len); | |
| 448 } | |
| 1957 | 449 else if (gc_currently_forbidden) |
| 450 { | |
| 451 /* Avoid calling begin_gc_forbidden, which conses. We can reach | |
| 452 this point from the cons debug code, which will get us into | |
| 453 an infinite loop if we cons again. */ | |
| 454 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); | |
| 455 } | |
| 428 | 456 else |
| 457 { | |
| 771 | 458 int speccount = begin_gc_forbidden (); |
| 428 | 459 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); |
| 771 | 460 unbind_to (speccount); |
| 428 | 461 } |
| 462 } | |
| 463 else | |
| 464 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); | |
| 465 | |
| 466 if (print_unbuffered) | |
| 467 Lstream_flush (XLSTREAM (function)); | |
| 468 } | |
| 469 else if (BUFFERP (function)) | |
| 470 { | |
| 471 CHECK_LIVE_BUFFER (function); | |
| 472 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len); | |
| 473 } | |
| 474 else if (MARKERP (function)) | |
| 475 { | |
| 476 /* marker_position() will err if marker doesn't point anywhere. */ | |
| 665 | 477 Charbpos spoint = marker_position (function); |
| 428 | 478 |
| 479 buffer_insert_string_1 (XMARKER (function)->buffer, | |
| 480 spoint, nonreloc, reloc, offset, len, | |
| 481 0); | |
| 482 Fset_marker (function, make_int (spoint + cclen), | |
| 483 Fmarker_buffer (function)); | |
| 484 } | |
| 485 else if (FRAMEP (function)) | |
| 486 { | |
| 487 /* This gets used by functions not invoking print_prepare(), | |
| 488 such as Fwrite_char, Fterpri, etc.. */ | |
| 489 struct frame *f = XFRAME (function); | |
| 490 CHECK_LIVE_FRAME (function); | |
| 491 | |
| 492 if (!EQ (Vprint_message_label, echo_area_status (f))) | |
| 493 clear_echo_area_from_print (f, Qnil, 1); | |
| 494 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label); | |
| 495 } | |
| 496 else if (EQ (function, Qt) || EQ (function, Qnil)) | |
| 497 { | |
| 771 | 498 write_string_to_stdio_stream (stdout, 0, newnonreloc + offset, len, |
| 499 print_unbuffered); | |
| 500 } | |
| 501 else if (EQ (function, Qexternal_debugging_output)) | |
| 502 { | |
| 503 /* This is not strictly necessary, and somewhat of a hack, but it | |
| 504 avoids having each character passed separately to | |
| 505 `external-debugging-output'. #### Why do we pass each character | |
| 506 separately, anyway? | |
| 507 */ | |
| 508 write_string_to_stdio_stream (stderr, 0, newnonreloc + offset, len, | |
| 509 print_unbuffered); | |
| 428 | 510 } |
| 511 else | |
| 512 { | |
| 771 | 513 Charcount ccoff; |
| 428 | 514 Charcount iii; |
| 515 | |
| 771 | 516 if (STRINGP (reloc)) |
| 793 | 517 ccoff = string_index_byte_to_char (reloc, offset); |
| 771 | 518 else |
| 519 ccoff = bytecount_to_charcount (newnonreloc, offset); | |
| 520 | |
| 521 if (STRINGP (reloc)) | |
| 428 | 522 { |
| 771 | 523 for (iii = ccoff; iii < cclen + ccoff; iii++) |
| 524 { | |
| 867 | 525 call1 (function, make_char (string_ichar (reloc, iii))); |
| 771 | 526 if (STRINGP (reloc)) |
| 527 newnonreloc = XSTRING_DATA (reloc); | |
| 528 } | |
| 529 } | |
| 530 else | |
| 531 { | |
| 532 for (iii = ccoff; iii < cclen + ccoff; iii++) | |
| 533 { | |
| 534 call1 (function, | |
| 867 | 535 make_char (itext_ichar_n (newnonreloc, iii))); |
| 771 | 536 } |
| 428 | 537 } |
| 538 } | |
| 539 | |
| 540 UNGCPRO; | |
| 541 } | |
| 542 | |
| 543 #define RESET_PRINT_GENSYM do { \ | |
| 544 if (!CONSP (Vprint_gensym)) \ | |
| 545 Vprint_gensym_alist = Qnil; \ | |
| 546 } while (0) | |
| 547 | |
| 1261 | 548 Lisp_Object |
| 428 | 549 canonicalize_printcharfun (Lisp_Object printcharfun) |
| 550 { | |
| 551 if (NILP (printcharfun)) | |
| 552 printcharfun = Vstandard_output; | |
| 553 | |
| 1261 | 554 if (!noninteractive && (EQ (printcharfun, Qt) || NILP (printcharfun))) |
| 428 | 555 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */ |
| 556 | |
| 557 return printcharfun; | |
| 558 } | |
| 559 | |
| 560 static Lisp_Object | |
| 561 print_prepare (Lisp_Object printcharfun, Lisp_Object *frame_kludge) | |
| 562 { | |
| 563 /* Emacs won't print while GCing, but an external debugger might */ | |
| 771 | 564 #ifdef NO_PRINT_DURING_GC |
| 428 | 565 if (gc_in_progress) |
| 566 return Qnil; | |
| 771 | 567 #endif |
| 568 | |
| 428 | 569 RESET_PRINT_GENSYM; |
| 570 | |
| 571 printcharfun = canonicalize_printcharfun (printcharfun); | |
| 572 | |
| 573 /* Here we could safely return the canonicalized PRINTCHARFUN. | |
| 574 However, if PRINTCHARFUN is a frame, printing of complex | |
| 575 structures becomes very expensive, because `append-message' | |
| 576 (called by echo_area_append) gets called as many times as | |
| 577 output_string() is called (and that's a *lot*). append-message | |
| 578 tries to keep top of the message-stack in sync with the contents | |
| 579 of " *Echo Area" buffer, consing a new string for each component | |
| 580 of the printed structure. For instance, if you print (a a), | |
| 581 append-message will cons up the following strings: | |
| 582 | |
| 583 "(" | |
| 584 "(a" | |
| 585 "(a " | |
| 586 "(a a" | |
| 587 "(a a)" | |
| 588 | |
| 589 and will use only the last one. With larger objects, this turns | |
| 590 into an O(n^2) consing frenzy that locks up XEmacs in incessant | |
| 591 garbage collection. | |
| 592 | |
| 593 We prevent this by creating a resizing_buffer stream and letting | |
| 594 the printer write into it. print_finish() will notice this | |
| 595 stream, and invoke echo_area_append() with the stream's buffer, | |
| 596 only once. */ | |
| 597 if (FRAMEP (printcharfun)) | |
| 598 { | |
| 599 CHECK_LIVE_FRAME (printcharfun); | |
| 600 *frame_kludge = printcharfun; | |
| 601 printcharfun = make_resizing_buffer_output_stream (); | |
| 602 } | |
| 603 | |
| 604 return printcharfun; | |
| 605 } | |
| 606 | |
| 607 static void | |
| 608 print_finish (Lisp_Object stream, Lisp_Object frame_kludge) | |
| 609 { | |
| 610 /* Emacs won't print while GCing, but an external debugger might */ | |
| 771 | 611 #ifdef NO_PRINT_DURING_GC |
| 428 | 612 if (gc_in_progress) |
| 613 return; | |
| 771 | 614 #endif |
| 615 | |
| 428 | 616 RESET_PRINT_GENSYM; |
| 617 | |
| 618 /* See the comment in print_prepare(). */ | |
| 619 if (FRAMEP (frame_kludge)) | |
| 620 { | |
| 621 struct frame *f = XFRAME (frame_kludge); | |
| 622 Lstream *str = XLSTREAM (stream); | |
| 623 CHECK_LIVE_FRAME (frame_kludge); | |
| 624 | |
| 625 Lstream_flush (str); | |
| 626 if (!EQ (Vprint_message_label, echo_area_status (f))) | |
| 627 clear_echo_area_from_print (f, Qnil, 1); | |
| 628 echo_area_append (f, resizing_buffer_stream_ptr (str), | |
| 629 Qnil, 0, Lstream_byte_count (str), | |
| 630 Vprint_message_label); | |
| 631 Lstream_delete (str); | |
| 632 } | |
| 633 } | |
| 634 | |
| 635 | |
| 771 | 636 /* Write internal-format data to STREAM. See output_string() for |
| 637 interpretation of STREAM. | |
| 638 | |
| 639 NOTE: Do not call this with the data of a Lisp_String, as | |
| 428 | 640 printcharfun might cause a GC, which might cause the string's data |
| 641 to be relocated. To princ a Lisp string, use: | |
| 642 | |
| 643 print_internal (string, printcharfun, 0); | |
| 644 | |
| 645 Also note that STREAM should be the result of | |
| 646 canonicalize_printcharfun() (i.e. Qnil means stdout, not | |
| 647 Vstandard_output, etc.) */ | |
| 648 void | |
| 867 | 649 write_string_1 (Lisp_Object stream, const Ibyte *str, Bytecount size) |
| 428 | 650 { |
| 651 /* This function can GC */ | |
| 800 | 652 #ifdef ERROR_CHECK_TEXT |
| 428 | 653 assert (size >= 0); |
| 654 #endif | |
| 655 output_string (stream, str, Qnil, 0, size); | |
| 656 } | |
| 657 | |
| 658 void | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
659 write_istring (Lisp_Object stream, const Ibyte *str) |
| 771 | 660 { |
| 661 /* This function can GC */ | |
| 826 | 662 write_string_1 (stream, str, qxestrlen (str)); |
| 771 | 663 } |
| 664 | |
| 665 void | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
666 write_cistring (Lisp_Object stream, const CIbyte *str) |
| 428 | 667 { |
| 668 /* This function can GC */ | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
669 write_istring (stream, (const Ibyte *) str); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
670 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
671 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
672 void |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
673 write_ascstring (Lisp_Object stream, const Ascbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
674 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
675 /* This function can GC */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
676 ASSERT_ASCTEXT_ASCII (str); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
677 write_istring (stream, (const Ibyte *) str); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
678 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
679 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
680 void |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
681 write_msg_istring (Lisp_Object stream, const Ibyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
682 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
683 /* This function can GC */ |
| 4973 | 684 write_istring (stream, IGETTEXT (str)); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
685 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
686 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
687 void |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
688 write_msg_cistring (Lisp_Object stream, const CIbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
689 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
690 /* This function can GC */ |
| 4973 | 691 write_msg_istring (stream, (const Ibyte *) str); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
692 } |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
693 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
694 void |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
695 write_msg_ascstring (Lisp_Object stream, const Ascbyte *str) |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
696 { |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
697 /* This function can GC */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
698 ASSERT_ASCTEXT_ASCII (str); |
| 4973 | 699 write_msg_istring (stream, (const Ibyte *) str); |
| 428 | 700 } |
| 701 | |
| 793 | 702 void |
| 826 | 703 write_eistring (Lisp_Object stream, const Eistring *ei) |
| 793 | 704 { |
| 826 | 705 write_string_1 (stream, eidata (ei), eilen (ei)); |
| 793 | 706 } |
| 707 | |
| 771 | 708 /* Write a printf-style string to STREAM; see output_string(). */ |
| 709 | |
| 710 void | |
| 867 | 711 write_fmt_string (Lisp_Object stream, const CIbyte *fmt, ...) |
| 771 | 712 { |
| 713 va_list va; | |
| 867 | 714 Ibyte *str; |
| 771 | 715 Bytecount len; |
| 716 int count; | |
| 717 | |
| 718 va_start (va, fmt); | |
| 719 str = emacs_vsprintf_malloc (fmt, va, &len); | |
| 720 va_end (va); | |
| 721 count = record_unwind_protect_freeing (str); | |
| 826 | 722 write_string_1 (stream, str, len); |
| 771 | 723 unbind_to (count); |
| 724 } | |
| 725 | |
| 726 /* Write a printf-style string to STREAM, where the arguments are | |
| 727 Lisp objects and not C strings or integers; see output_string(). | |
| 728 | |
| 729 #### It shouldn't be necessary to specify the number of arguments. | |
| 730 This would require some rewriting of the doprnt() functions, though. */ | |
| 731 | |
| 732 void | |
| 867 | 733 write_fmt_string_lisp (Lisp_Object stream, const CIbyte *fmt, int nargs, ...) |
| 771 | 734 { |
| 735 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
| 736 va_list va; | |
| 737 int i; | |
| 867 | 738 Ibyte *str; |
| 771 | 739 Bytecount len; |
| 740 int count; | |
| 741 | |
| 742 va_start (va, nargs); | |
| 743 for (i = 0; i < nargs; i++) | |
| 744 args[i] = va_arg (va, Lisp_Object); | |
| 745 va_end (va); | |
| 746 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len); | |
| 747 count = record_unwind_protect_freeing (str); | |
| 826 | 748 write_string_1 (stream, str, len); |
| 771 | 749 unbind_to (count); |
| 750 } | |
| 751 | |
| 752 void | |
| 867 | 753 stderr_out_lisp (const CIbyte *fmt, int nargs, ...) |
| 771 | 754 { |
| 755 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
| 756 va_list va; | |
| 757 int i; | |
| 867 | 758 Ibyte *str; |
| 771 | 759 Bytecount len; |
| 760 int count; | |
| 761 | |
| 762 va_start (va, nargs); | |
| 763 for (i = 0; i < nargs; i++) | |
| 764 args[i] = va_arg (va, Lisp_Object); | |
| 765 va_end (va); | |
| 766 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len); | |
| 767 count = record_unwind_protect_freeing (str); | |
| 826 | 768 write_string_1 (Qexternal_debugging_output, str, len); |
| 771 | 769 unbind_to (count); |
| 770 } | |
| 771 | |
| 428 | 772 |
| 773 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /* | |
| 444 | 774 Output character CHARACTER to stream STREAM. |
| 428 | 775 STREAM defaults to the value of `standard-output' (which see). |
| 776 */ | |
| 444 | 777 (character, stream)) |
| 428 | 778 { |
| 779 /* This function can GC */ | |
| 867 | 780 Ibyte str[MAX_ICHAR_LEN]; |
| 428 | 781 Bytecount len; |
| 782 | |
| 444 | 783 CHECK_CHAR_COERCE_INT (character); |
| 867 | 784 len = set_itext_ichar (str, XCHAR (character)); |
| 428 | 785 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len); |
| 444 | 786 return character; |
| 428 | 787 } |
| 788 | |
| 789 void | |
| 790 temp_output_buffer_setup (Lisp_Object bufname) | |
| 791 { | |
| 792 /* This function can GC */ | |
| 793 struct buffer *old = current_buffer; | |
| 794 Lisp_Object buf; | |
| 795 | |
| 796 #ifdef I18N3 | |
| 797 /* #### This function should accept a Lisp_Object instead of a char *, | |
| 798 so that proper translation on the buffer name can occur. */ | |
| 799 #endif | |
| 800 | |
| 801 Fset_buffer (Fget_buffer_create (bufname)); | |
| 802 | |
| 803 current_buffer->read_only = Qnil; | |
| 804 Ferase_buffer (Qnil); | |
| 805 | |
| 793 | 806 buf = wrap_buffer (current_buffer); |
| 428 | 807 specbind (Qstandard_output, buf); |
| 808 | |
| 809 set_buffer_internal (old); | |
| 810 } | |
| 811 | |
| 812 Lisp_Object | |
| 813 internal_with_output_to_temp_buffer (Lisp_Object bufname, | |
| 814 Lisp_Object (*function) (Lisp_Object arg), | |
| 815 Lisp_Object arg, | |
| 816 Lisp_Object same_frame) | |
| 817 { | |
| 818 int speccount = specpdl_depth (); | |
| 819 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 820 Lisp_Object buf = Qnil; | |
| 821 | |
| 822 GCPRO3 (buf, arg, same_frame); | |
| 823 | |
| 824 temp_output_buffer_setup (bufname); | |
| 825 buf = Vstandard_output; | |
| 826 | |
| 827 arg = (*function) (arg); | |
| 828 | |
| 829 temp_output_buffer_show (buf, same_frame); | |
| 830 UNGCPRO; | |
| 831 | |
| 771 | 832 return unbind_to_1 (speccount, arg); |
| 428 | 833 } |
| 834 | |
| 835 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /* | |
| 836 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer. | |
| 837 The buffer is cleared out initially, and marked as unmodified when done. | |
| 838 All output done by BODY is inserted in that buffer by default. | |
| 839 The buffer is displayed in another window, but not selected. | |
| 840 The value of the last form in BODY is returned. | |
| 841 If BODY does not finish normally, the buffer BUFNAME is not displayed. | |
| 842 | |
| 843 If variable `temp-buffer-show-function' is non-nil, call it at the end | |
| 844 to get the buffer displayed. It gets one argument, the buffer to display. | |
|
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
845 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
846 arguments: (BUFNAME &rest BODY) |
| 428 | 847 */ |
| 848 (args)) | |
| 849 { | |
| 850 /* This function can GC */ | |
| 851 Lisp_Object name = Qnil; | |
| 852 int speccount = specpdl_depth (); | |
| 853 struct gcpro gcpro1, gcpro2; | |
| 854 Lisp_Object val = Qnil; | |
| 855 | |
| 856 #ifdef I18N3 | |
| 857 /* #### should set the buffer to be translating. See print_internal(). */ | |
| 858 #endif | |
| 859 | |
| 860 GCPRO2 (name, val); | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
861 name = IGNORE_MULTIPLE_VALUES (Feval (XCAR (args))); |
| 428 | 862 |
| 863 CHECK_STRING (name); | |
| 864 | |
| 865 temp_output_buffer_setup (name); | |
| 866 UNGCPRO; | |
| 867 | |
| 868 val = Fprogn (XCDR (args)); | |
| 869 | |
| 870 temp_output_buffer_show (Vstandard_output, Qnil); | |
| 871 | |
| 771 | 872 return unbind_to_1 (speccount, val); |
| 428 | 873 } |
| 874 | |
| 875 DEFUN ("terpri", Fterpri, 0, 1, 0, /* | |
| 876 Output a newline to STREAM. | |
| 877 If STREAM is omitted or nil, the value of `standard-output' is used. | |
| 878 */ | |
| 879 (stream)) | |
| 880 { | |
| 881 /* This function can GC */ | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
882 write_ascstring (canonicalize_printcharfun (stream), "\n"); |
| 428 | 883 return Qt; |
| 884 } | |
| 885 | |
| 886 DEFUN ("prin1", Fprin1, 1, 2, 0, /* | |
| 887 Output the printed representation of OBJECT, any Lisp object. | |
| 888 Quoting characters are printed when needed to make output that `read' | |
| 889 can handle, whenever this is possible. | |
| 890 Output stream is STREAM, or value of `standard-output' (which see). | |
| 891 */ | |
| 892 (object, stream)) | |
| 893 { | |
| 894 /* This function can GC */ | |
| 895 Lisp_Object frame = Qnil; | |
| 896 struct gcpro gcpro1, gcpro2; | |
| 897 GCPRO2 (object, stream); | |
| 898 | |
| 899 stream = print_prepare (stream, &frame); | |
| 900 print_internal (object, stream, 1); | |
| 901 print_finish (stream, frame); | |
| 902 | |
| 903 UNGCPRO; | |
| 904 return object; | |
| 905 } | |
| 906 | |
|
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
907 Lisp_Object |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
908 prin1_to_string (Lisp_Object object, int noescape) |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
909 { |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
910 /* This function can GC */ |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
911 Lisp_Object result = Qnil; |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
912 Lisp_Object stream = make_resizing_buffer_output_stream (); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
913 Lstream *str = XLSTREAM (stream); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
914 /* gcpro OBJECT in case a caller forgot to do so */ |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
915 struct gcpro gcpro1, gcpro2, gcpro3; |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
916 GCPRO3 (object, stream, result); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
917 |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
918 print_internal (object, stream, !noescape); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
919 Lstream_flush (str); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
920 UNGCPRO; |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
921 result = make_string (resizing_buffer_stream_ptr (str), |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
922 Lstream_byte_count (str)); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
923 Lstream_delete (str); |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
924 return result; |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
925 } |
|
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
926 |
| 428 | 927 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /* |
| 928 Return a string containing the printed representation of OBJECT, | |
| 929 any Lisp object. Quoting characters are used when needed to make output | |
| 930 that `read' can handle, whenever this is possible, unless the optional | |
| 931 second argument NOESCAPE is non-nil. | |
| 932 */ | |
| 933 (object, noescape)) | |
| 934 { | |
| 935 /* This function can GC */ | |
| 936 Lisp_Object result = Qnil; | |
| 937 | |
| 938 RESET_PRINT_GENSYM; | |
|
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
939 result = prin1_to_string (object, !(EQ(noescape, Qnil))); |
| 428 | 940 RESET_PRINT_GENSYM; |
|
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
941 |
| 428 | 942 return result; |
| 943 } | |
| 944 | |
| 945 DEFUN ("princ", Fprinc, 1, 2, 0, /* | |
| 946 Output the printed representation of OBJECT, any Lisp object. | |
| 947 No quoting characters are used; no delimiters are printed around | |
| 948 the contents of strings. | |
| 444 | 949 Output stream is STREAM, or value of `standard-output' (which see). |
| 428 | 950 */ |
| 951 (object, stream)) | |
| 952 { | |
| 953 /* This function can GC */ | |
| 954 Lisp_Object frame = Qnil; | |
| 955 struct gcpro gcpro1, gcpro2; | |
| 956 | |
| 957 GCPRO2 (object, stream); | |
| 958 stream = print_prepare (stream, &frame); | |
| 959 print_internal (object, stream, 0); | |
| 960 print_finish (stream, frame); | |
| 961 UNGCPRO; | |
| 962 return object; | |
| 963 } | |
| 964 | |
| 965 DEFUN ("print", Fprint, 1, 2, 0, /* | |
| 966 Output the printed representation of OBJECT, with newlines around it. | |
| 967 Quoting characters are printed when needed to make output that `read' | |
| 968 can handle, whenever this is possible. | |
| 969 Output stream is STREAM, or value of `standard-output' (which see). | |
| 970 */ | |
| 971 (object, stream)) | |
| 972 { | |
| 973 /* This function can GC */ | |
| 974 Lisp_Object frame = Qnil; | |
| 975 struct gcpro gcpro1, gcpro2; | |
| 976 | |
| 977 GCPRO2 (object, stream); | |
| 978 stream = print_prepare (stream, &frame); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
979 write_ascstring (stream, "\n"); |
| 428 | 980 print_internal (object, stream, 1); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
981 write_ascstring (stream, "\n"); |
| 428 | 982 print_finish (stream, frame); |
| 983 UNGCPRO; | |
| 984 return object; | |
| 985 } | |
| 986 | |
| 987 /* Print an error message for the error DATA to STREAM. This is a | |
| 988 complete implementation of `display-error', which used to be in | |
| 989 Lisp (see prim/cmdloop.el). It was ported to C so it can be used | |
| 990 efficiently by Ferror_message_string. Fdisplay_error and | |
| 991 Ferror_message_string are trivial wrappers around this function. | |
| 992 | |
| 993 STREAM should be the result of canonicalize_printcharfun(). */ | |
| 994 static void | |
| 995 print_error_message (Lisp_Object error_object, Lisp_Object stream) | |
| 996 { | |
| 997 /* This function can GC */ | |
| 998 Lisp_Object type = Fcar_safe (error_object); | |
| 999 Lisp_Object method = Qnil; | |
| 1000 Lisp_Object tail; | |
| 1001 | |
| 1002 /* No need to GCPRO anything under the assumption that ERROR_OBJECT | |
| 1003 is GCPRO'd. */ | |
| 1004 | |
| 1005 if (! (CONSP (error_object) && SYMBOLP (type) | |
| 1006 && CONSP (Fget (type, Qerror_conditions, Qnil)))) | |
| 1007 goto error_throw; | |
| 1008 | |
| 1009 tail = XCDR (error_object); | |
| 1010 while (!NILP (tail)) | |
| 1011 { | |
| 1012 if (CONSP (tail)) | |
| 1013 tail = XCDR (tail); | |
| 1014 else | |
| 1015 goto error_throw; | |
| 1016 } | |
| 1017 tail = Fget (type, Qerror_conditions, Qnil); | |
| 1018 while (!NILP (tail)) | |
| 1019 { | |
| 1020 if (!(CONSP (tail) && SYMBOLP (XCAR (tail)))) | |
| 1021 goto error_throw; | |
| 1022 else if (!NILP (Fget (XCAR (tail), Qdisplay_error, Qnil))) | |
| 1023 { | |
| 1024 method = Fget (XCAR (tail), Qdisplay_error, Qnil); | |
| 1025 goto error_throw; | |
| 1026 } | |
| 1027 else | |
| 1028 tail = XCDR (tail); | |
| 1029 } | |
| 1030 /* Default method */ | |
| 1031 { | |
| 1032 int first = 1; | |
| 1033 int speccount = specpdl_depth (); | |
| 438 | 1034 Lisp_Object frame = Qnil; |
| 1035 struct gcpro gcpro1; | |
| 1036 GCPRO1 (stream); | |
| 428 | 1037 |
| 1038 specbind (Qprint_message_label, Qerror); | |
| 438 | 1039 stream = print_prepare (stream, &frame); |
| 1040 | |
| 428 | 1041 tail = Fcdr (error_object); |
| 1042 if (EQ (type, Qerror)) | |
| 1043 { | |
| 1044 print_internal (Fcar (tail), stream, 0); | |
| 1045 tail = Fcdr (tail); | |
| 1046 } | |
| 1047 else | |
| 1048 { | |
| 1049 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil); | |
| 1050 if (NILP (errmsg)) | |
| 1051 print_internal (type, stream, 0); | |
| 1052 else | |
| 1053 print_internal (LISP_GETTEXT (errmsg), stream, 0); | |
| 1054 } | |
| 1055 while (!NILP (tail)) | |
| 1056 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1057 write_ascstring (stream, first ? ": " : ", "); |
| 563 | 1058 /* Most errors have an explanatory string as their first argument, |
| 1059 and it looks better not to put the quotes around it. */ | |
| 1060 print_internal (Fcar (tail), stream, | |
| 1061 !(first && STRINGP (Fcar (tail))) || | |
| 1062 !NILP (Fget (type, Qerror_lacks_explanatory_string, | |
| 1063 Qnil))); | |
| 428 | 1064 tail = Fcdr (tail); |
| 1065 first = 0; | |
| 1066 } | |
| 438 | 1067 print_finish (stream, frame); |
| 1068 UNGCPRO; | |
| 771 | 1069 unbind_to (speccount); |
| 428 | 1070 return; |
| 1071 /* not reached */ | |
| 1072 } | |
| 1073 | |
| 1074 error_throw: | |
| 1075 if (NILP (method)) | |
| 1076 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1077 write_ascstring (stream, GETTEXT ("Peculiar error ")); |
| 428 | 1078 print_internal (error_object, stream, 1); |
| 1079 return; | |
| 1080 } | |
| 1081 else | |
| 1082 { | |
| 1083 call2 (method, error_object, stream); | |
| 1084 } | |
| 1085 } | |
| 1086 | |
| 1087 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /* | |
| 1088 Convert ERROR-OBJECT to an error message, and return it. | |
| 1089 | |
| 1090 The format of ERROR-OBJECT should be (ERROR-SYMBOL . DATA). The | |
| 1091 message is equivalent to the one that would be issued by | |
| 1092 `display-error' with the same argument. | |
| 1093 */ | |
| 1094 (error_object)) | |
| 1095 { | |
| 1096 /* This function can GC */ | |
| 1097 Lisp_Object result = Qnil; | |
| 1098 Lisp_Object stream = make_resizing_buffer_output_stream (); | |
| 1099 struct gcpro gcpro1; | |
| 1100 GCPRO1 (stream); | |
| 1101 | |
| 1102 print_error_message (error_object, stream); | |
| 1103 Lstream_flush (XLSTREAM (stream)); | |
| 1104 result = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)), | |
| 1105 Lstream_byte_count (XLSTREAM (stream))); | |
| 1106 Lstream_delete (XLSTREAM (stream)); | |
| 1107 | |
| 1108 UNGCPRO; | |
| 1109 return result; | |
| 1110 } | |
| 1111 | |
| 1112 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /* | |
| 1113 Display ERROR-OBJECT on STREAM in a user-friendly way. | |
| 1114 */ | |
| 1115 (error_object, stream)) | |
| 1116 { | |
| 1117 /* This function can GC */ | |
| 1118 print_error_message (error_object, canonicalize_printcharfun (stream)); | |
| 1119 return Qnil; | |
| 1120 } | |
| 1121 | |
| 1122 | |
| 1123 Lisp_Object Vfloat_output_format; | |
| 1124 | |
| 1125 /* | |
| 1126 * This buffer should be at least as large as the max string size of the | |
| 440 | 1127 * largest float, printed in the biggest notation. This is undoubtedly |
| 428 | 1128 * 20d float_output_format, with the negative of the C-constant "HUGE" |
| 1129 * from <math.h>. | |
| 1130 * | |
| 1131 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. | |
| 1132 * | |
| 1133 * I assume that IEEE-754 format numbers can take 329 bytes for the worst | |
| 1134 * case of -1e307 in 20d float_output_format. What is one to do (short of | |
| 1135 * re-writing _doprnt to be more sane)? | |
| 1136 * -wsr | |
| 1137 */ | |
| 1138 void | |
| 1139 float_to_string (char *buf, double data) | |
| 1140 { | |
| 867 | 1141 Ibyte *cp, c; |
| 428 | 1142 int width; |
| 1143 | |
| 1144 if (NILP (Vfloat_output_format) | |
| 1145 || !STRINGP (Vfloat_output_format)) | |
| 1146 lose: | |
| 1147 sprintf (buf, "%.16g", data); | |
| 1148 else /* oink oink */ | |
| 1149 { | |
| 1150 /* Check that the spec we have is fully valid. | |
| 1151 This means not only valid for printf, | |
| 1152 but meant for floats, and reasonable. */ | |
| 1153 cp = XSTRING_DATA (Vfloat_output_format); | |
| 1154 | |
| 1155 if (cp[0] != '%') | |
| 1156 goto lose; | |
| 1157 if (cp[1] != '.') | |
| 1158 goto lose; | |
| 1159 | |
| 1160 cp += 2; | |
| 1161 for (width = 0; (c = *cp, isdigit (c)); cp++) | |
| 1162 { | |
| 1163 width *= 10; | |
| 1164 width += c - '0'; | |
| 1165 } | |
| 1166 | |
| 1167 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G') | |
| 1168 goto lose; | |
| 1169 | |
| 1170 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG) | |
| 1171 goto lose; | |
| 1172 | |
| 1173 if (cp[1] != 0) | |
| 1174 goto lose; | |
| 1175 | |
| 1176 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format), | |
| 1177 data); | |
| 1178 } | |
| 1179 | |
| 1180 /* added by jwz: don't allow "1.0" to print as "1"; that destroys | |
| 1181 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do | |
| 1182 not do the same thing, so it's important that the printed | |
| 1183 representation of that form not be corrupted by the printer. | |
| 1184 */ | |
| 1185 { | |
| 867 | 1186 Ibyte *s = (Ibyte *) buf; /* don't use signed chars here! |
| 428 | 1187 isdigit() can't hack them! */ |
| 1188 if (*s == '-') s++; | |
| 1189 for (; *s; s++) | |
| 1190 /* if there's a non-digit, then there is a decimal point, or | |
| 1191 it's in exponential notation, both of which are ok. */ | |
| 1192 if (!isdigit (*s)) | |
| 1193 goto DONE_LABEL; | |
| 1194 /* otherwise, we need to hack it. */ | |
| 1195 *s++ = '.'; | |
| 1196 *s++ = '0'; | |
| 1197 *s = 0; | |
| 1198 } | |
| 1199 DONE_LABEL: | |
| 1200 | |
| 1201 /* Some machines print "0.4" as ".4". I don't like that. */ | |
| 1202 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.')) | |
| 1203 { | |
| 1204 int i; | |
| 1205 for (i = strlen (buf) + 1; i >= 0; i--) | |
| 1206 buf [i+1] = buf [i]; | |
| 1207 buf [(buf [0] == '-' ? 1 : 0)] = '0'; | |
| 1208 } | |
| 1209 } | |
| 1210 | |
| 2500 | 1211 #define ONE_DIGIT(figure) *p++ = (char) (n / (figure) + '0') |
| 577 | 1212 #define ONE_DIGIT_ADVANCE(figure) (ONE_DIGIT (figure), n %= (figure)) |
| 1213 | |
| 1214 #define DIGITS_1(figure) ONE_DIGIT (figure) | |
| 1215 #define DIGITS_2(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_1 ((figure) / 10) | |
| 1216 #define DIGITS_3(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_2 ((figure) / 10) | |
| 1217 #define DIGITS_4(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_3 ((figure) / 10) | |
| 1218 #define DIGITS_5(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_4 ((figure) / 10) | |
| 1219 #define DIGITS_6(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_5 ((figure) / 10) | |
| 1220 #define DIGITS_7(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_6 ((figure) / 10) | |
| 1221 #define DIGITS_8(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_7 ((figure) / 10) | |
| 1222 #define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10) | |
| 1223 #define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10) | |
| 1224 | |
| 1225 /* DIGITS_<11-20> are only used on machines with 64-bit longs. */ | |
| 428 | 1226 |
| 577 | 1227 #define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10) |
| 1228 #define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10) | |
| 1229 #define DIGITS_13(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_12 ((figure) / 10) | |
| 1230 #define DIGITS_14(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_13 ((figure) / 10) | |
| 1231 #define DIGITS_15(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_14 ((figure) / 10) | |
| 1232 #define DIGITS_16(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_15 ((figure) / 10) | |
| 1233 #define DIGITS_17(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_16 ((figure) / 10) | |
| 1234 #define DIGITS_18(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_17 ((figure) / 10) | |
| 1235 #define DIGITS_19(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_18 ((figure) / 10) | |
| 1236 | |
| 1237 /* Print NUMBER to BUFFER in base 10. This is completely equivalent | |
| 1238 to `sprintf(buffer, "%ld", number)', only much faster. | |
| 1239 | |
| 1240 The speedup may make a difference in programs that frequently | |
| 1241 convert numbers to strings. Some implementations of sprintf, | |
| 1242 particularly the one in GNU libc, have been known to be extremely | |
| 1243 slow compared to this function. | |
| 1244 | |
| 1245 BUFFER should accept as many bytes as you expect the number to take | |
| 1246 up. On machines with 64-bit longs the maximum needed size is 24 | |
| 1247 bytes. That includes the worst-case digits, the optional `-' sign, | |
| 1248 and the trailing \0. */ | |
| 1249 | |
| 1250 void | |
| 428 | 1251 long_to_string (char *buffer, long number) |
| 1252 { | |
| 577 | 1253 char *p = buffer; |
| 1254 long n = number; | |
| 1255 | |
| 428 | 1256 #if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8) |
| 577 | 1257 /* We are running in a strange or misconfigured environment. Let |
| 1258 sprintf cope with it. */ | |
| 1259 sprintf (buffer, "%ld", n); | |
| 1260 #else /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */ | |
| 428 | 1261 |
| 577 | 1262 if (n < 0) |
| 428 | 1263 { |
| 1264 *p++ = '-'; | |
| 577 | 1265 n = -n; |
| 428 | 1266 } |
| 1267 | |
| 577 | 1268 if (n < 10) { DIGITS_1 (1); } |
| 1269 else if (n < 100) { DIGITS_2 (10); } | |
| 1270 else if (n < 1000) { DIGITS_3 (100); } | |
| 1271 else if (n < 10000) { DIGITS_4 (1000); } | |
| 1272 else if (n < 100000) { DIGITS_5 (10000); } | |
| 1273 else if (n < 1000000) { DIGITS_6 (100000); } | |
| 1274 else if (n < 10000000) { DIGITS_7 (1000000); } | |
| 1275 else if (n < 100000000) { DIGITS_8 (10000000); } | |
| 1276 else if (n < 1000000000) { DIGITS_9 (100000000); } | |
| 1277 #if SIZEOF_LONG == 4 | |
| 1278 /* ``if (1)'' serves only to preserve editor indentation. */ | |
| 1279 else if (1) { DIGITS_10 (1000000000); } | |
| 1280 #else /* SIZEOF_LONG != 4 */ | |
| 1281 else if (n < 10000000000L) { DIGITS_10 (1000000000L); } | |
| 1282 else if (n < 100000000000L) { DIGITS_11 (10000000000L); } | |
| 1283 else if (n < 1000000000000L) { DIGITS_12 (100000000000L); } | |
| 1284 else if (n < 10000000000000L) { DIGITS_13 (1000000000000L); } | |
| 1285 else if (n < 100000000000000L) { DIGITS_14 (10000000000000L); } | |
| 1286 else if (n < 1000000000000000L) { DIGITS_15 (100000000000000L); } | |
| 1287 else if (n < 10000000000000000L) { DIGITS_16 (1000000000000000L); } | |
| 1288 else if (n < 100000000000000000L) { DIGITS_17 (10000000000000000L); } | |
| 1289 else if (n < 1000000000000000000L) { DIGITS_18 (100000000000000000L); } | |
| 1290 else { DIGITS_19 (1000000000000000000L); } | |
| 1291 #endif /* SIZEOF_LONG != 4 */ | |
| 1292 | |
| 428 | 1293 *p = '\0'; |
| 1294 #endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */ | |
| 1295 } | |
| 577 | 1296 |
| 1297 #undef ONE_DIGIT | |
| 1298 #undef ONE_DIGIT_ADVANCE | |
| 1299 | |
| 1300 #undef DIGITS_1 | |
| 1301 #undef DIGITS_2 | |
| 1302 #undef DIGITS_3 | |
| 1303 #undef DIGITS_4 | |
| 1304 #undef DIGITS_5 | |
| 1305 #undef DIGITS_6 | |
| 1306 #undef DIGITS_7 | |
| 1307 #undef DIGITS_8 | |
| 1308 #undef DIGITS_9 | |
| 1309 #undef DIGITS_10 | |
| 1310 #undef DIGITS_11 | |
| 1311 #undef DIGITS_12 | |
| 1312 #undef DIGITS_13 | |
| 1313 #undef DIGITS_14 | |
| 1314 #undef DIGITS_15 | |
| 1315 #undef DIGITS_16 | |
| 1316 #undef DIGITS_17 | |
| 1317 #undef DIGITS_18 | |
| 1318 #undef DIGITS_19 | |
| 428 | 1319 |
|
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1320 void |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1321 ulong_to_bit_string (char *p, unsigned long number) |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1322 { |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1323 int i, seen_high_order = 0;; |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1324 |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1325 for (i = ((SIZEOF_LONG * 8) - 1); i >= 0; --i) |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1326 { |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1327 if (number & (unsigned long)1 << i) |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1328 { |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1329 seen_high_order = 1; |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1330 *p++ = '1'; |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1331 } |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1332 else |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1333 { |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1334 if (seen_high_order) |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1335 { |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1336 *p++ = '0'; |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1337 } |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1338 } |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1339 } |
|
5295
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1340 |
|
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1341 if (!seen_high_order) |
|
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1342 { |
|
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1343 *p++ = '0'; |
|
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1344 } |
|
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1345 |
|
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1346 *p = '\0'; |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1347 } |
|
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1348 |
| 428 | 1349 static void |
| 442 | 1350 print_vector_internal (const char *start, const char *end, |
| 428 | 1351 Lisp_Object obj, |
| 1352 Lisp_Object printcharfun, int escapeflag) | |
| 1353 { | |
| 1354 /* This function can GC */ | |
| 1355 int i; | |
| 1356 int len = XVECTOR_LENGTH (obj); | |
| 1357 int last = len; | |
| 1358 struct gcpro gcpro1, gcpro2; | |
| 1359 GCPRO2 (obj, printcharfun); | |
| 1360 | |
| 1361 if (INTP (Vprint_length)) | |
| 1362 { | |
| 1363 int max = XINT (Vprint_length); | |
| 1364 if (max < len) last = max; | |
| 1365 } | |
| 1366 | |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1367 write_cistring (printcharfun, start); |
| 428 | 1368 for (i = 0; i < last; i++) |
| 1369 { | |
| 1370 Lisp_Object elt = XVECTOR_DATA (obj)[i]; | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1371 if (i != 0) write_ascstring (printcharfun, " "); |
| 428 | 1372 print_internal (elt, printcharfun, escapeflag); |
| 1373 } | |
| 1374 UNGCPRO; | |
| 1375 if (last != len) | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1376 write_ascstring (printcharfun, " ..."); |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1377 write_cistring (printcharfun, end); |
| 428 | 1378 } |
| 1379 | |
| 1380 void | |
| 1381 print_cons (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
| 1382 { | |
| 1383 /* This function can GC */ | |
| 1384 struct gcpro gcpro1, gcpro2; | |
| 1385 | |
| 1386 /* If print_readably is on, print (quote -foo-) as '-foo- | |
| 1387 (Yeah, this should really be what print-pretty does, but we | |
| 1388 don't have the rest of a pretty printer, and this actually | |
| 1389 has non-negligible impact on size/speed of .elc files.) | |
| 1390 */ | |
| 1391 if (print_readably && | |
| 1392 EQ (XCAR (obj), Qquote) && | |
| 1393 CONSP (XCDR (obj)) && | |
| 1394 NILP (XCDR (XCDR (obj)))) | |
| 1395 { | |
| 1396 obj = XCAR (XCDR (obj)); | |
| 1397 GCPRO2 (obj, printcharfun); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1398 write_ascstring (printcharfun, "\'"); |
| 428 | 1399 UNGCPRO; |
| 1400 print_internal (obj, printcharfun, escapeflag); | |
| 1401 return; | |
| 1402 } | |
| 1403 | |
| 1404 GCPRO2 (obj, printcharfun); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1405 write_ascstring (printcharfun, "("); |
| 428 | 1406 |
| 1407 { | |
| 1408 int len; | |
| 1409 int max = INTP (Vprint_length) ? XINT (Vprint_length) : INT_MAX; | |
| 1410 Lisp_Object tortoise; | |
| 1411 /* Use tortoise/hare to make sure circular lists don't infloop */ | |
| 1412 | |
| 1413 for (tortoise = obj, len = 0; | |
| 1414 CONSP (obj); | |
| 1415 obj = XCDR (obj), len++) | |
| 1416 { | |
| 1417 if (len > 0) | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1418 write_ascstring (printcharfun, " "); |
| 428 | 1419 if (EQ (obj, tortoise) && len > 0) |
| 1420 { | |
| 1421 if (print_readably) | |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1422 printing_unreadable_object_fmt ("circular list"); |
| 428 | 1423 else |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1424 write_ascstring (printcharfun, "... <circular list>"); |
| 428 | 1425 break; |
| 1426 } | |
| 1427 if (len & 1) | |
| 1428 tortoise = XCDR (tortoise); | |
| 1429 if (len > max) | |
| 1430 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1431 write_ascstring (printcharfun, "..."); |
| 428 | 1432 break; |
| 1433 } | |
| 1434 print_internal (XCAR (obj), printcharfun, escapeflag); | |
| 1435 } | |
| 1436 } | |
| 1437 if (!LISTP (obj)) | |
| 1438 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1439 write_ascstring (printcharfun, " . "); |
| 428 | 1440 print_internal (obj, printcharfun, escapeflag); |
| 1441 } | |
| 1442 UNGCPRO; | |
| 1443 | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1444 write_ascstring (printcharfun, ")"); |
| 428 | 1445 return; |
| 1446 } | |
| 1447 | |
| 1448 void | |
| 1449 print_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
| 1450 { | |
| 1451 print_vector_internal ("[", "]", obj, printcharfun, escapeflag); | |
| 1452 } | |
| 1453 | |
| 1454 void | |
| 1455 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
| 1456 { | |
| 1457 /* We distinguish between Bytecounts and Charcounts, to make | |
| 1458 Vprint_string_length work correctly under Mule. */ | |
| 826 | 1459 Charcount size = string_char_length (obj); |
| 428 | 1460 Charcount max = size; |
| 793 | 1461 Bytecount bcmax = XSTRING_LENGTH (obj); |
| 428 | 1462 struct gcpro gcpro1, gcpro2; |
| 1463 GCPRO2 (obj, printcharfun); | |
| 1464 | |
| 1465 if (INTP (Vprint_string_length) && | |
| 1466 XINT (Vprint_string_length) < max) | |
| 1467 { | |
| 1468 max = XINT (Vprint_string_length); | |
| 793 | 1469 bcmax = string_index_char_to_byte (obj, max); |
| 428 | 1470 } |
| 1471 if (max < 0) | |
| 1472 { | |
| 1473 max = 0; | |
| 1474 bcmax = 0; | |
| 1475 } | |
| 1476 | |
| 1477 if (!escapeflag) | |
| 1478 { | |
| 1479 /* This deals with GC-relocation and Mule. */ | |
| 1480 output_string (printcharfun, 0, obj, 0, bcmax); | |
| 1481 if (max < size) | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1482 write_ascstring (printcharfun, " ..."); |
| 428 | 1483 } |
| 1484 else | |
| 1485 { | |
| 1486 Bytecount i, last = 0; | |
| 1487 | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1488 write_ascstring (printcharfun, "\""); |
| 428 | 1489 for (i = 0; i < bcmax; i++) |
| 1490 { | |
| 867 | 1491 Ibyte ch = string_byte (obj, i); |
| 428 | 1492 if (ch == '\"' || ch == '\\' |
| 1493 || (ch == '\n' && print_escape_newlines)) | |
| 1494 { | |
| 1495 if (i > last) | |
| 1496 { | |
| 1497 output_string (printcharfun, 0, obj, last, | |
| 1498 i - last); | |
| 1499 } | |
| 1500 if (ch == '\n') | |
| 1501 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1502 write_ascstring (printcharfun, "\\n"); |
| 428 | 1503 } |
| 1504 else | |
| 1505 { | |
| 867 | 1506 Ibyte temp[2]; |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1507 write_ascstring (printcharfun, "\\"); |
| 428 | 1508 /* This is correct for Mule because the |
| 1509 character is either \ or " */ | |
| 826 | 1510 temp[0] = string_byte (obj, i); |
| 1511 temp[1] = '\0'; | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1512 write_istring (printcharfun, temp); |
| 428 | 1513 } |
| 1514 last = i + 1; | |
| 1515 } | |
| 1516 } | |
| 1517 if (bcmax > last) | |
| 1518 { | |
| 1519 output_string (printcharfun, 0, obj, last, | |
| 1520 bcmax - last); | |
| 1521 } | |
| 1522 if (max < size) | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1523 write_ascstring (printcharfun, " ..."); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1524 write_ascstring (printcharfun, "\""); |
| 428 | 1525 } |
| 1526 UNGCPRO; | |
| 1527 } | |
| 1528 | |
| 4846 | 1529 DOESNT_RETURN |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1530 printing_unreadable_object_fmt (const Ascbyte *fmt, ...) |
| 4846 | 1531 { |
| 1532 Lisp_Object obj; | |
| 1533 va_list args; | |
| 1534 | |
| 1535 va_start (args, fmt); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1536 obj = emacs_vsprintf_string (GETTEXT (fmt), args); |
| 4846 | 1537 va_end (args); |
| 1538 | |
| 1539 /* Fsignal GC-protects its args */ | |
| 1540 signal_error (Qprinting_unreadable_object, 0, obj); | |
| 1541 } | |
| 1542 | |
| 1543 DOESNT_RETURN | |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1544 printing_unreadable_lisp_object (Lisp_Object obj, const Ibyte *name) |
| 428 | 1545 { |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1546 struct lrecord_header *header = (struct lrecord_header *) XPNTR (obj); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1547 const struct lrecord_implementation *imp = |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1548 XRECORD_LHEADER_IMPLEMENTATION (obj); |
| 428 | 1549 |
| 4846 | 1550 if (name) |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1551 printing_unreadable_object_fmt ("#<%s %s 0x%x>", imp->name, name, header->uid); |
| 4846 | 1552 else |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1553 printing_unreadable_object_fmt ("#<%s 0x%x>", imp->name, header->uid); |
| 4846 | 1554 } |
| 1555 | |
| 1556 void | |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1557 external_object_printer (Lisp_Object obj, Lisp_Object printcharfun, |
|
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1558 int UNUSED (escapeflag)) |
| 4846 | 1559 { |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1560 struct lrecord_header *header = (struct lrecord_header *) XPNTR (obj); |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1561 const struct lrecord_implementation *imp = |
|
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1562 XRECORD_LHEADER_IMPLEMENTATION (obj); |
| 4846 | 1563 |
| 1564 if (print_readably) | |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1565 printing_unreadable_lisp_object (obj, 0); |
| 428 | 1566 |
|
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1567 write_fmt_string (printcharfun, "#<%s 0x%x>", imp->name, header->uid); |
| 428 | 1568 } |
| 1569 | |
| 1570 void | |
| 1571 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun, | |
| 2286 | 1572 int UNUSED (escapeflag)) |
| 428 | 1573 { |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1574 if (print_readably) |
|
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1575 printing_unreadable_object_fmt |
|
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1576 ("#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>", |
|
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1577 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, LISP_OBJECT_UID (obj)); |
|
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1578 |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1579 /* Internal objects shouldn't normally escape to the Lisp level; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1580 that's why we say "XEmacs bug?". This can happen, however, when |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1581 printing backtraces. */ |
| 800 | 1582 write_fmt_string (printcharfun, |
|
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1583 "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>", |
| 800 | 1584 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, |
|
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1585 LISP_OBJECT_UID (obj)); |
| 428 | 1586 } |
| 1587 | |
| 1204 | 1588 enum printing_badness |
| 1589 { | |
| 1590 BADNESS_INTEGER_OBJECT, | |
| 1591 BADNESS_POINTER_OBJECT, | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1592 BADNESS_POINTER_OBJECT_WITH_DATA, |
| 1204 | 1593 BADNESS_NO_TYPE |
| 1594 }; | |
| 1595 | |
| 1596 static void | |
| 1597 printing_major_badness (Lisp_Object printcharfun, | |
|
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1598 const Ascbyte *badness_string, int type, void *val, |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1599 void *val2, enum printing_badness badness) |
| 1204 | 1600 { |
| 1601 Ibyte buf[666]; | |
| 1602 | |
| 1603 switch (badness) | |
| 1604 { | |
| 1605 case BADNESS_INTEGER_OBJECT: | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1606 qxesprintf (buf, "%s type %d object %ld", badness_string, type, |
| 1204 | 1607 (EMACS_INT) val); |
| 1608 break; | |
| 1609 | |
| 1610 case BADNESS_POINTER_OBJECT: | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1611 qxesprintf (buf, "%s type %d object %p", badness_string, type, val); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1612 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1613 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1614 case BADNESS_POINTER_OBJECT_WITH_DATA: |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1615 qxesprintf (buf, "%s type %d object %p data %p", badness_string, type, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1616 val, val2); |
| 1204 | 1617 break; |
| 1618 | |
| 1619 case BADNESS_NO_TYPE: | |
| 1620 qxesprintf (buf, "%s object %p", badness_string, val); | |
| 1621 break; | |
| 1622 } | |
| 1623 | |
| 1624 /* Don't abort or signal if called from debug_print() or already | |
| 1625 crashing */ | |
| 2367 | 1626 if (!inhibit_non_essential_conversion_operations) |
| 1204 | 1627 { |
| 1628 #ifdef ERROR_CHECK_TYPES | |
| 2500 | 1629 ABORT (); |
| 1204 | 1630 #else /* not ERROR_CHECK_TYPES */ |
| 1631 if (print_readably) | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1632 signal_ferror (Qinternal_error, "SERIOUS XEMACS BUG: printing %s; " |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1633 "save your buffers immediately and please report " |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1634 "this bug", buf); |
| 1204 | 1635 #endif /* not ERROR_CHECK_TYPES */ |
| 1636 } | |
| 1637 write_fmt_string (printcharfun, | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1638 "#<SERIOUS XEMACS BUG: %s Save your buffers immediately " |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1639 "and please report this bug>", buf); |
| 1204 | 1640 } |
| 1641 | |
| 428 | 1642 void |
| 1643 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
| 1644 { | |
| 1645 /* This function can GC */ | |
| 2001 | 1646 int specdepth = 0; |
| 1204 | 1647 struct gcpro gcpro1, gcpro2; |
| 428 | 1648 |
| 1649 QUIT; | |
| 1650 | |
| 771 | 1651 #ifdef NO_PRINT_DURING_GC |
| 428 | 1652 /* Emacs won't print while GCing, but an external debugger might */ |
| 1653 if (gc_in_progress) return; | |
| 771 | 1654 #endif |
| 1655 | |
| 1204 | 1656 /* Just to be safe ... */ |
| 1657 GCPRO2 (obj, printcharfun); | |
| 428 | 1658 |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1659 /* WARNING WARNING WARNING!!! Don't put anything here that might |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1660 dereference memory. Instead, put it down inside of |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1661 the case Lisp_Type_Record, after the appropriate checks to make sure |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1662 we're not dereferencing bad memory. The idea is that, ideally, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1663 calling debug_print() should *NEVER* make the program crash, even when |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1664 something very bad has happened. --ben */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1665 |
| 428 | 1666 #ifdef I18N3 |
| 1667 /* #### Both input and output streams should have a flag associated | |
| 1668 with them indicating whether output to that stream, or strings | |
| 1669 read from the stream, get translated using Fgettext(). Such a | |
| 1670 stream is called a "translating stream". For the minibuffer and | |
| 1671 external-debugging-output this is always true on output, and | |
| 1672 with-output-to-temp-buffer sets the flag to true for the buffer | |
| 1673 it creates. This flag should also be user-settable. Perhaps it | |
| 1674 should be split up into two flags, one for input and one for | |
| 1675 output. */ | |
| 1676 #endif | |
| 1677 | |
| 1678 being_printed[print_depth] = obj; | |
| 1679 | |
| 1957 | 1680 /* Avoid calling internal_bind_int, which conses, when called from |
| 1681 debug_prin1. In that case, we have bound print_depth to 0 anyway. */ | |
| 2367 | 1682 if (!inhibit_non_essential_conversion_operations) |
| 1957 | 1683 { |
| 1684 specdepth = internal_bind_int (&print_depth, print_depth + 1); | |
| 1685 | |
| 1686 if (print_depth > PRINT_CIRCLE) | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1687 signal_error (Qstack_overflow, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1688 "Apparently circular structure being printed", Qunbound); |
| 1957 | 1689 } |
| 428 | 1690 |
| 1691 switch (XTYPE (obj)) | |
| 1692 { | |
| 1693 case Lisp_Type_Int_Even: | |
| 1694 case Lisp_Type_Int_Odd: | |
| 1695 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1696 Ascbyte buf[DECIMAL_PRINT_SIZE (EMACS_INT)]; |
| 428 | 1697 long_to_string (buf, XINT (obj)); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1698 write_ascstring (printcharfun, buf); |
| 428 | 1699 break; |
| 1700 } | |
| 1701 | |
| 1702 case Lisp_Type_Char: | |
| 1703 { | |
| 1704 /* God intended that this be #\..., you know. */ | |
| 1705 char buf[16]; | |
| 867 | 1706 Ichar ch = XCHAR (obj); |
| 428 | 1707 char *p = buf; |
| 1708 *p++ = '?'; | |
| 434 | 1709 if (ch < 32) |
| 1710 { | |
| 1711 *p++ = '\\'; | |
| 1712 switch (ch) | |
| 1713 { | |
| 1714 case '\t': *p++ = 't'; break; | |
| 1715 case '\n': *p++ = 'n'; break; | |
| 1716 case '\r': *p++ = 'r'; break; | |
| 1717 default: | |
| 1718 *p++ = '^'; | |
| 1719 *p++ = ch + 64; | |
| 1720 if ((ch + 64) == '\\') | |
| 1721 *p++ = '\\'; | |
| 1722 break; | |
| 1723 } | |
| 1724 } | |
| 1725 else if (ch < 127) | |
| 428 | 1726 { |
| 434 | 1727 /* syntactically special characters should be escaped. */ |
| 1728 switch (ch) | |
| 1729 { | |
| 1730 case ' ': | |
| 1731 case '"': | |
| 1732 case '#': | |
| 1733 case '\'': | |
| 1734 case '(': | |
| 1735 case ')': | |
| 1736 case ',': | |
| 1737 case '.': | |
| 1738 case ';': | |
| 1739 case '?': | |
| 1740 case '[': | |
| 1741 case '\\': | |
| 1742 case ']': | |
| 1743 case '`': | |
| 1744 *p++ = '\\'; | |
| 1745 } | |
| 1746 *p++ = ch; | |
| 428 | 1747 } |
| 1748 else if (ch == 127) | |
| 434 | 1749 { |
| 1750 *p++ = '\\', *p++ = '^', *p++ = '?'; | |
| 1751 } | |
| 1752 else if (ch < 160) | |
| 428 | 1753 { |
| 1754 *p++ = '\\', *p++ = '^'; | |
| 867 | 1755 p += set_itext_ichar ((Ibyte *) p, ch + 64); |
| 428 | 1756 } |
| 1757 else | |
| 434 | 1758 { |
| 867 | 1759 p += set_itext_ichar ((Ibyte *) p, ch); |
| 434 | 1760 } |
| 440 | 1761 |
| 867 | 1762 output_string (printcharfun, (Ibyte *) buf, Qnil, 0, p - buf); |
| 434 | 1763 |
| 428 | 1764 break; |
| 1765 } | |
| 1766 | |
| 1767 case Lisp_Type_Record: | |
| 1768 { | |
| 1769 struct lrecord_header *lheader = XRECORD_LHEADER (obj); | |
| 1204 | 1770 |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1771 /* Try to check for various sorts of bogus pointers or bad memory |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1772 if we're in a situation where it may be likely -- i.e. called |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1773 from debug_print() or we're already crashing. In such cases, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1774 (further) crashing is counterproductive. |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1775 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1776 We don't normally do these because they may be expensive or |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1777 weird (e.g. under Unix we typically have to set a SIGSEGV |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1778 handler and try to trigger a seg fault). */ |
| 428 | 1779 |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1780 if (!lheader) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1781 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1782 /* i.e. EQ Qnull_pointer */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1783 printing_major_badness (printcharfun, "NULL POINTER LRECORD", 0, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1784 0, 0, BADNESS_NO_TYPE); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1785 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1786 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1787 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1788 /* First check to see if the lrecord header itself is garbage. */ |
| 2367 | 1789 if (inhibit_non_essential_conversion_operations && |
| 1204 | 1790 !debug_can_access_memory (lheader, sizeof (*lheader))) |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1791 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1792 printing_major_badness (printcharfun, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1793 "BAD MEMORY in LRECORD HEADER", 0, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1794 lheader, 0, BADNESS_NO_TYPE); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1795 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1796 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1797 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1798 /* Check to see if the lrecord type is garbage. */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1799 #ifndef NEW_GC |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1800 if (lheader->type == lrecord_type_free) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1801 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1802 printing_major_badness (printcharfun, "FREED LRECORD", 0, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1803 lheader, 0, BADNESS_NO_TYPE); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1804 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1805 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1806 if (lheader->type == lrecord_type_undefined) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1807 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1808 printing_major_badness (printcharfun, "LRECORD_TYPE_UNDEFINED", 0, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1809 lheader, 0, BADNESS_NO_TYPE); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1810 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1811 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1812 #endif /* not NEW_GC */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1813 if ((int) (lheader->type) >= lrecord_type_count) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1814 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1815 printing_major_badness (printcharfun, "ILLEGAL LRECORD TYPE", |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1816 (int) (lheader->type), |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1817 lheader, 0, BADNESS_POINTER_OBJECT); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1818 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1819 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1820 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1821 /* Check to see if the lrecord implementation is missing or garbage. */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1822 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1823 const struct lrecord_implementation *imp = |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1824 LHEADER_IMPLEMENTATION (lheader); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1825 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1826 if (!imp) |
| 1204 | 1827 { |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1828 printing_major_badness |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1829 (printcharfun, "NO IMPLEMENTATION FOR LRECORD TYPE", |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1830 (int) (lheader->type), |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1831 lheader, 0, BADNESS_POINTER_OBJECT); |
| 1204 | 1832 break; |
| 1833 } | |
| 1834 | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1835 if (inhibit_non_essential_conversion_operations) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1836 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1837 if (!debug_can_access_memory (imp, sizeof (*imp))) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1838 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1839 printing_major_badness |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1840 (printcharfun, "BAD MEMORY IN LRECORD IMPLEMENTATION", |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1841 (int) (lheader->type), |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1842 lheader, 0, BADNESS_POINTER_OBJECT); |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1843 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1844 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1845 } |
| 428 | 1846 |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1847 /* Check to see if any of the memory of the lrecord is inaccessible. |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1848 Note that we already checked above to see if the first part of |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1849 the lrecord (the header) is inaccessible, which will catch most |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1850 cases of a totally bad pointer. */ |
| 1204 | 1851 |
| 2367 | 1852 if (inhibit_non_essential_conversion_operations) |
| 1204 | 1853 { |
| 1854 if (!debug_can_access_memory | |
| 1855 (lheader, detagged_lisp_object_size (lheader))) | |
| 1856 { | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1857 printing_major_badness (printcharfun, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1858 "BAD MEMORY IN LRECORD", |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1859 (int) (lheader->type), |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1860 lheader, 0, BADNESS_POINTER_OBJECT); |
| 1204 | 1861 break; |
| 1862 } | |
| 1863 | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1864 /* For strings, also check the data of the string itself. */ |
| 1204 | 1865 if (STRINGP (obj)) |
| 1866 { | |
| 3092 | 1867 #ifdef NEW_GC |
| 1868 if (!debug_can_access_memory (XSTRING_DATA (obj), | |
| 1869 XSTRING_LENGTH (obj))) | |
| 1870 { | |
| 1871 write_fmt_string | |
| 1872 (printcharfun, | |
| 1873 "#<EMACS BUG: %p (BAD STRING DATA %p)>", | |
| 1874 lheader, XSTRING_DATA (obj)); | |
| 1875 break; | |
| 1876 } | |
| 1877 #else /* not NEW_GC */ | |
| 1204 | 1878 Lisp_String *l = (Lisp_String *) lheader; |
|
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5189
diff
changeset
|
1879 if (l->size_ && !debug_can_access_memory (l->data_, l->size_)) |
| 1204 | 1880 { |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1881 printing_major_badness (printcharfun, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1882 "BAD STRING DATA", (int) (lheader->type), |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1883 lheader, l->data_, |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1884 BADNESS_POINTER_OBJECT_WITH_DATA); |
| 1204 | 1885 break; |
| 1886 } | |
| 3092 | 1887 #endif /* not NEW_GC */ |
| 1204 | 1888 } |
| 1889 } | |
| 1890 | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1891 /* Detect circularities and truncate them. |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1892 No need to offer any alternative--this is better than an error. */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1893 if (CONSP (obj) || VECTORP (obj) || COMPILED_FUNCTIONP (obj)) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1894 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1895 int i; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1896 for (i = 0; i < print_depth - 1; i++) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1897 if (EQ (obj, being_printed[i])) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1898 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1899 Ascbyte buf[DECIMAL_PRINT_SIZE (long) + 1]; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1900 *buf = '#'; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1901 long_to_string (buf + 1, i); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1902 write_ascstring (printcharfun, buf); |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1903 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1904 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1905 if (i < print_depth - 1) /* Did we print something? */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1906 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1907 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1908 |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1909 if (CONSP (obj) || VECTORP (obj)) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1910 { |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1911 /* If deeper than spec'd depth, print placeholder. */ |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1912 if (INTP (Vprint_level) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1913 && print_depth > XINT (Vprint_level)) |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1914 { |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1915 write_ascstring (printcharfun, "..."); |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1916 break; |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1917 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1918 } |
|
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1919 |
|
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1920 /* Either use a custom-written printer, or use |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1921 internal_object_printer or external_object_printer, depending on |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1922 whether the object is internal (not visible at Lisp level) or |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1923 external. */ |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1924 assert (LHEADER_IMPLEMENTATION (lheader)->printer); |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1925 ((LHEADER_IMPLEMENTATION (lheader)->printer) |
|
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1926 (obj, printcharfun, escapeflag)); |
| 428 | 1927 break; |
| 1928 } | |
| 1929 | |
| 1930 default: | |
| 1931 { | |
| 1932 /* We're in trouble if this happens! */ | |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1933 printing_major_badness (printcharfun, "ILLEGAL LISP OBJECT TAG TYPE", |
| 5013 | 1934 XTYPE (obj), STORE_LISP_IN_VOID (obj), 0, |
|
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1935 BADNESS_INTEGER_OBJECT); |
| 428 | 1936 break; |
| 1937 } | |
| 1938 } | |
| 1939 | |
| 2367 | 1940 if (!inhibit_non_essential_conversion_operations) |
| 1957 | 1941 unbind_to (specdepth); |
| 1204 | 1942 UNGCPRO; |
| 428 | 1943 } |
| 1944 | |
| 1945 void | |
| 2286 | 1946 print_float (Lisp_Object obj, Lisp_Object printcharfun, |
| 1947 int UNUSED (escapeflag)) | |
| 428 | 1948 { |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1949 Ascbyte pigbuf[350]; /* see comments in float_to_string */ |
| 428 | 1950 |
| 1951 float_to_string (pigbuf, XFLOAT_DATA (obj)); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1952 write_ascstring (printcharfun, pigbuf); |
| 428 | 1953 } |
| 1954 | |
| 1955 void | |
| 1956 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
| 1957 { | |
| 1958 /* This function can GC */ | |
| 1959 /* #### Bug!! (intern "") isn't printed in some distinguished way */ | |
| 1960 /* #### (the reader also loses on it) */ | |
| 793 | 1961 Lisp_Object name = symbol_name (XSYMBOL (obj)); |
| 1962 Bytecount size = XSTRING_LENGTH (name); | |
| 428 | 1963 struct gcpro gcpro1, gcpro2; |
| 1964 | |
| 1965 if (!escapeflag) | |
| 1966 { | |
| 1967 /* This deals with GC-relocation */ | |
| 793 | 1968 output_string (printcharfun, 0, name, 0, size); |
| 428 | 1969 return; |
| 1970 } | |
| 1971 GCPRO2 (obj, printcharfun); | |
| 1972 | |
| 1973 /* If we print an uninterned symbol as part of a complex object and | |
| 1974 the flag print-gensym is non-nil, prefix it with #n= to read the | |
| 1975 object back with the #n# reader syntax later if needed. */ | |
| 1976 if (!NILP (Vprint_gensym) | |
| 442 | 1977 /* #### Test whether this produces a noticeable slow-down for |
| 428 | 1978 printing when print-gensym is non-nil. */ |
| 1979 && !EQ (obj, oblookup (Vobarray, | |
| 793 | 1980 XSTRING_DATA (symbol_name (XSYMBOL (obj))), |
| 1981 XSTRING_LENGTH (symbol_name (XSYMBOL (obj)))))) | |
| 428 | 1982 { |
| 1983 if (print_depth > 1) | |
| 1984 { | |
| 1985 Lisp_Object tem = Fassq (obj, Vprint_gensym_alist); | |
| 1986 if (CONSP (tem)) | |
| 1987 { | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1988 write_ascstring (printcharfun, "#"); |
| 428 | 1989 print_internal (XCDR (tem), printcharfun, escapeflag); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1990 write_ascstring (printcharfun, "#"); |
| 446 | 1991 UNGCPRO; |
| 428 | 1992 return; |
| 1993 } | |
| 1994 else | |
| 1995 { | |
| 1996 if (CONSP (Vprint_gensym_alist)) | |
| 1997 { | |
| 1998 /* Vprint_gensym_alist is exposed to Lisp, so we | |
| 1999 have to be careful. */ | |
| 2000 CHECK_CONS (XCAR (Vprint_gensym_alist)); | |
| 2001 CHECK_INT (XCDR (XCAR (Vprint_gensym_alist))); | |
| 793 | 2002 tem = make_int (XINT (XCDR (XCAR (Vprint_gensym_alist))) + 1); |
| 428 | 2003 } |
| 2004 else | |
| 793 | 2005 tem = make_int (1); |
| 428 | 2006 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist); |
| 2007 | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2008 write_ascstring (printcharfun, "#"); |
| 428 | 2009 print_internal (tem, printcharfun, escapeflag); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2010 write_ascstring (printcharfun, "="); |
| 428 | 2011 } |
| 2012 } | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2013 write_ascstring (printcharfun, "#:"); |
| 428 | 2014 } |
| 2015 | |
| 2016 /* Does it look like an integer or a float? */ | |
| 2017 { | |
| 867 | 2018 Ibyte *data = XSTRING_DATA (name); |
| 428 | 2019 Bytecount confusing = 0; |
| 2020 | |
| 2021 if (size == 0) | |
| 2022 goto not_yet_confused; /* Really confusing */ | |
| 2023 else if (isdigit (data[0])) | |
| 2024 confusing = 0; | |
| 2025 else if (size == 1) | |
| 2026 goto not_yet_confused; | |
| 2027 else if (data[0] == '-' || data[0] == '+') | |
| 2028 confusing = 1; | |
| 2029 else | |
| 2030 goto not_yet_confused; | |
| 2031 | |
| 2032 for (; confusing < size; confusing++) | |
| 2033 { | |
|
5243
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2034 if (!isdigit (data[confusing]) && '/' != data[confusing]) |
| 428 | 2035 { |
| 2036 confusing = 0; | |
| 2037 break; | |
| 2038 } | |
| 2039 } | |
| 2040 not_yet_confused: | |
| 2041 | |
| 2042 if (!confusing) | |
| 2043 /* #### Ugh, this is needlessly complex and slow for what we | |
| 2044 need here. It might be a good idea to copy equivalent code | |
| 2045 from FSF. --hniksic */ | |
|
5243
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2046 confusing = isfloat_string ((char *) data) |
|
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2047 || isratio_string ((char *) data); |
| 428 | 2048 if (confusing) |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2049 write_ascstring (printcharfun, "\\"); |
| 428 | 2050 } |
| 2051 | |
| 2052 { | |
| 2053 Bytecount i; | |
| 2054 Bytecount last = 0; | |
| 2055 | |
| 2056 for (i = 0; i < size; i++) | |
| 2057 { | |
| 826 | 2058 switch (string_byte (name, i)) |
| 428 | 2059 { |
| 2060 case 0: case 1: case 2: case 3: | |
| 2061 case 4: case 5: case 6: case 7: | |
| 2062 case 8: case 9: case 10: case 11: | |
| 2063 case 12: case 13: case 14: case 15: | |
| 2064 case 16: case 17: case 18: case 19: | |
| 2065 case 20: case 21: case 22: case 23: | |
| 2066 case 24: case 25: case 26: case 27: | |
| 2067 case 28: case 29: case 30: case 31: | |
| 2068 case ' ': case '\"': case '\\': case '\'': | |
| 2069 case ';': case '#' : case '(' : case ')': | |
| 2070 case ',': case '.' : case '`' : | |
| 2071 case '[': case ']' : case '?' : | |
| 2072 if (i > last) | |
| 793 | 2073 output_string (printcharfun, 0, name, last, i - last); |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2074 write_ascstring (printcharfun, "\\"); |
| 428 | 2075 last = i; |
| 2076 } | |
| 2077 } | |
| 793 | 2078 output_string (printcharfun, 0, name, last, size - last); |
| 428 | 2079 } |
| 2080 UNGCPRO; | |
| 2081 } | |
| 2082 | |
| 2083 | |
| 442 | 2084 /* Useful on systems or in places where writing to stdout is unavailable or |
| 2085 not working. */ | |
| 428 | 2086 |
| 2087 static int alternate_do_pointer; | |
| 1957 | 2088 static int alternate_do_size; |
| 2089 static char *alternate_do_string; | |
| 428 | 2090 |
| 2091 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /* | |
| 2092 Append CHARACTER to the array `alternate_do_string'. | |
| 2093 This can be used in place of `external-debugging-output' as a function | |
| 2094 to be passed to `print'. Before calling `print', set `alternate_do_pointer' | |
| 2095 to 0. | |
| 2096 */ | |
| 2097 (character)) | |
| 2098 { | |
| 867 | 2099 Ibyte str[MAX_ICHAR_LEN]; |
| 428 | 2100 Bytecount len; |
| 2101 | |
| 2102 CHECK_CHAR_COERCE_INT (character); | |
| 867 | 2103 len = set_itext_ichar (str, XCHAR (character)); |
| 771 | 2104 write_string_to_alternate_debugging_output (str, len); |
| 2105 | |
| 2106 return character; | |
| 2107 } | |
| 2108 | |
| 2109 static void | |
| 1346 | 2110 write_string_to_alternate_debugging_output (const Ibyte *str, Bytecount len) |
| 771 | 2111 { |
| 2112 int extlen; | |
| 2113 const Extbyte *extptr; | |
| 2114 #if 0 /* We want to see the internal representation, don't we? */ | |
| 2367 | 2115 if (initialized && !inhibit_non_essential_conversion_operations) |
| 771 | 2116 TO_EXTERNAL_FORMAT (DATA, (str, len), |
| 2117 ALLOCA, (extptr, extlen), | |
| 2118 Qterminal); | |
| 2119 else | |
| 2120 #endif /* 0 */ | |
| 2121 { | |
| 2122 extlen = len; | |
| 2123 extptr = (Extbyte *) str; | |
| 2124 } | |
| 1957 | 2125 |
| 2126 /* If not yet initialized, just skip it. */ | |
| 2127 if (alternate_do_string == NULL) | |
| 2128 return; | |
| 2129 | |
| 2130 if (alternate_do_pointer + extlen >= alternate_do_size) | |
| 2131 { | |
| 2132 alternate_do_size = | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2133 max (alternate_do_size * 2, alternate_do_pointer + extlen + 1); |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2134 XREALLOC_ARRAY (alternate_do_string, CIbyte, alternate_do_size); |
| 1957 | 2135 } |
| 428 | 2136 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen); |
| 2137 alternate_do_pointer += extlen; | |
| 2138 alternate_do_string[alternate_do_pointer] = 0; | |
| 2139 } | |
| 2140 | |
| 1346 | 2141 |
| 2142 DEFUN ("set-device-clear-left-side", Fset_device_clear_left_side, 2, 2, 0, /* | |
| 2143 Set whether to output a newline before the next output to a stream device. | |
| 2144 This will happen only if the most recently-outputted character was not | |
| 2145 a newline -- i.e. it will make sure the left side is "clear" of text. | |
| 2146 */ | |
| 2147 (device, value)) | |
| 2148 { | |
| 2149 if (!NILP (device)) | |
| 2150 CHECK_LIVE_DEVICE (device); | |
| 2151 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device))) | |
| 2152 /* #### This should be per-device */ | |
| 2153 stdout_clear_before_next_output = !NILP (value); | |
| 2154 return Qnil; | |
| 2155 } | |
| 2156 | |
| 2157 DEFUN ("device-left-side-clear-p", Fdevice_left_side_clear_p, 0, 1, 0, /* | |
| 2158 For stream devices, true if the most recent-outputted character was a newline. | |
| 2159 */ | |
| 2160 (device)) | |
| 2161 { | |
| 2162 if (!NILP (device)) | |
| 2163 CHECK_LIVE_DEVICE (device); | |
| 2164 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device))) | |
| 2165 /* #### This should be per-device */ | |
| 2166 return stdout_needs_newline ? Qt : Qnil; | |
| 2167 return Qnil; | |
| 2168 } | |
| 2169 | |
| 428 | 2170 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /* |
| 2171 Write CHAR-OR-STRING to stderr or stdout. | |
| 2172 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write | |
| 2173 to stderr. You can use this function to write directly to the terminal. | |
| 2174 This function can be used as the STREAM argument of Fprint() or the like. | |
| 2175 | |
| 442 | 2176 Under MS Windows, this writes output to the console window (which is |
| 2177 created, if necessary), unless XEmacs is being run noninteractively | |
| 2178 \(i.e. using the `-batch' argument). | |
| 2179 | |
| 428 | 2180 If you have opened a termscript file (using `open-termscript'), then |
| 2181 the output also will be logged to this file. | |
| 2182 */ | |
| 2183 (char_or_string, stdout_p, device)) | |
| 2184 { | |
| 2185 FILE *file = 0; | |
| 2186 struct console *con = 0; | |
| 2187 | |
| 2188 if (NILP (device)) | |
| 2189 { | |
| 2190 if (!NILP (stdout_p)) | |
| 2191 file = stdout; | |
| 2192 else | |
| 2193 file = stderr; | |
| 2194 } | |
| 2195 else | |
| 2196 { | |
| 2197 CHECK_LIVE_DEVICE (device); | |
| 2198 if (!DEVICE_TTY_P (XDEVICE (device)) && | |
| 2199 !DEVICE_STREAM_P (XDEVICE (device))) | |
| 563 | 2200 wtaerror ("Must be tty or stream device", device); |
| 428 | 2201 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device))); |
| 2202 if (DEVICE_TTY_P (XDEVICE (device))) | |
| 2203 file = 0; | |
| 2204 else if (!NILP (stdout_p)) | |
| 2205 file = CONSOLE_STREAM_DATA (con)->out; | |
| 2206 else | |
| 2207 file = CONSOLE_STREAM_DATA (con)->err; | |
| 2208 } | |
| 2209 | |
| 2210 if (STRINGP (char_or_string)) | |
| 2211 write_string_to_stdio_stream (file, con, | |
| 2212 XSTRING_DATA (char_or_string), | |
| 771 | 2213 XSTRING_LENGTH (char_or_string), |
| 2214 print_unbuffered); | |
| 428 | 2215 else |
| 2216 { | |
| 867 | 2217 Ibyte str[MAX_ICHAR_LEN]; |
| 428 | 2218 Bytecount len; |
| 2219 | |
| 2220 CHECK_CHAR_COERCE_INT (char_or_string); | |
| 867 | 2221 len = set_itext_ichar (str, XCHAR (char_or_string)); |
| 771 | 2222 write_string_to_stdio_stream (file, con, str, len, print_unbuffered); |
| 428 | 2223 } |
| 2224 | |
| 2225 return char_or_string; | |
| 2226 } | |
| 2227 | |
| 2228 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /* | |
| 444 | 2229 Start writing all terminal output to FILENAME as well as the terminal. |
| 2230 FILENAME = nil means just close any termscript file currently open. | |
| 428 | 2231 */ |
| 444 | 2232 (filename)) |
| 428 | 2233 { |
| 2234 /* This function can GC */ | |
| 2235 if (termscript != 0) | |
| 2236 { | |
| 771 | 2237 retry_fclose (termscript); |
| 444 | 2238 termscript = 0; |
| 2239 } | |
| 2240 | |
| 2241 if (! NILP (filename)) | |
| 2242 { | |
| 2243 filename = Fexpand_file_name (filename, Qnil); | |
| 771 | 2244 termscript = qxe_fopen (XSTRING_DATA (filename), "w"); |
| 428 | 2245 if (termscript == NULL) |
| 563 | 2246 report_file_error ("Opening termscript", filename); |
| 428 | 2247 } |
| 2248 return Qnil; | |
| 2249 } | |
| 2250 | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2251 static Lisp_Object |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2252 restore_inhibit_non_essential_conversion_operations (Lisp_Object obj) |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2253 { |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2254 inhibit_non_essential_conversion_operations = XINT (obj); |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2255 return Qnil; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2256 } |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2257 |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2258 /* Bind the value of inhibit_non_essential_conversion_operations to 1 |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2259 in a way that involves no consing. */ |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2260 static int |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2261 begin_inhibit_non_essential_conversion_operations (void) |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2262 { |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2263 int depth = |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2264 record_unwind_protect |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2265 (restore_inhibit_non_essential_conversion_operations, |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2266 make_int (inhibit_non_essential_conversion_operations)); |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2267 inhibit_non_essential_conversion_operations = 1; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2268 return depth; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2269 } |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2270 |
| 440 | 2271 static int debug_print_length = 50; |
| 2272 static int debug_print_level = 15; | |
| 2273 static int debug_print_readably = -1; | |
| 428 | 2274 |
| 1957 | 2275 /* Restore values temporarily bound by debug_prin1. We use this approach to |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2276 avoid consing in debug_prin1. That is verboten, since debug_print can be |
| 1957 | 2277 called by cons debugging code. */ |
| 2278 static Lisp_Object | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2279 debug_print_exit (Lisp_Object val) |
| 1957 | 2280 { |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2281 struct debug_bindings *bindings = |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2282 (struct debug_bindings *) GET_VOID_FROM_LISP (val); |
| 2367 | 2283 inhibit_non_essential_conversion_operations = |
| 2284 bindings->inhibit_non_essential_conversion_operations; | |
| 1957 | 2285 print_depth = bindings->print_depth; |
| 2286 print_readably = bindings->print_readably; | |
| 2287 print_unbuffered = bindings->print_unbuffered; | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2288 in_debug_print = bindings->in_debug_print; |
| 1957 | 2289 gc_currently_forbidden = bindings->gc_currently_forbidden; |
| 2290 Vprint_length = bindings->Vprint_length; | |
| 2291 Vprint_level = bindings->Vprint_level; | |
| 2292 Vinhibit_quit = bindings->Vinhibit_quit; | |
| 2293 return Qnil; | |
| 2294 } | |
| 2295 | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2296 /* Save values and bind them to new values suitable for debug output. We |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2297 try very hard to avoid any Lisp allocation (i.e. consing) during the |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2298 operation of debug printing, since we might be calling it from inside GC |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2299 or other sensitive places. This means we have to be a bit careful with |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2300 record_unwind_protect to not create any temporary Lisp objects. */ |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2301 |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2302 static int |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2303 debug_print_enter (struct debug_bindings *bindings) |
| 428 | 2304 { |
| 853 | 2305 /* by doing this, we trick various things that are non-essential |
| 2306 but might cause crashes into not getting executed. */ | |
| 1957 | 2307 int specdepth; |
| 853 | 2308 |
| 2367 | 2309 bindings->inhibit_non_essential_conversion_operations = |
| 2310 inhibit_non_essential_conversion_operations; | |
| 1957 | 2311 bindings->print_depth = print_depth; |
| 2312 bindings->print_readably = print_readably; | |
| 2313 bindings->print_unbuffered = print_unbuffered; | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2314 bindings->in_debug_print = in_debug_print; |
| 1957 | 2315 bindings->gc_currently_forbidden = gc_currently_forbidden; |
| 2316 bindings->Vprint_length = Vprint_length; | |
| 2317 bindings->Vprint_level = Vprint_level; | |
| 2318 bindings->Vinhibit_quit = Vinhibit_quit; | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2319 specdepth = record_unwind_protect (debug_print_exit, |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2320 STORE_VOID_IN_LISP (bindings)); |
| 1957 | 2321 |
| 2367 | 2322 inhibit_non_essential_conversion_operations = 1; |
| 1957 | 2323 print_depth = 0; |
| 2324 print_readably = debug_print_readably != -1 ? debug_print_readably : 0; | |
| 2325 print_unbuffered++; | |
|
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2326 in_debug_print = 1; |
|
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2327 gc_currently_forbidden = 1; |
| 428 | 2328 if (debug_print_length > 0) |
| 1957 | 2329 Vprint_length = make_int (debug_print_length); |
| 428 | 2330 if (debug_print_level > 0) |
| 1957 | 2331 Vprint_level = make_int (debug_print_level); |
| 2332 Vinhibit_quit = Qt; | |
| 1346 | 2333 |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2334 return specdepth; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2335 } |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2336 |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2337 /* Print an object, `prin1'-style, to various possible debugging outputs. |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2338 Make sure it's completely unbuffered so that, in the event of a crash |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2339 somewhere, we see as much as possible that happened before it. |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2340 */ |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2341 static void |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2342 debug_prin1 (Lisp_Object debug_print_obj, int flags) |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2343 { |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2344 /* This function cannot GC, since GC is forbidden */ |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2345 struct debug_bindings bindings; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2346 int specdepth = debug_print_enter (&bindings); |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2347 |
| 1346 | 2348 if ((flags & EXT_PRINT_STDOUT) || (flags & EXT_PRINT_STDERR)) |
| 2349 print_internal (debug_print_obj, Qexternal_debugging_output, 1); | |
| 2350 if (flags & EXT_PRINT_ALTERNATE) | |
| 2351 print_internal (debug_print_obj, Qalternate_debugging_output, 1); | |
| 442 | 2352 #ifdef WIN32_NATIVE |
| 1346 | 2353 if (flags & EXT_PRINT_MSWINDOWS) |
| 2354 { | |
| 2355 /* Write out to the debugger, as well */ | |
| 2356 print_internal (debug_print_obj, Qmswindows_debugging_output, 1); | |
| 2357 } | |
| 442 | 2358 #endif |
| 440 | 2359 |
| 802 | 2360 unbind_to (specdepth); |
| 428 | 2361 } |
| 2362 | |
| 2363 void | |
| 1204 | 2364 debug_p4 (Lisp_Object obj) |
| 2365 { | |
| 2366 if (STRINGP (obj)) | |
| 2367 debug_out ("\"%s\"", XSTRING_DATA (obj)); | |
| 2368 else if (CONSP (obj)) | |
| 2369 { | |
| 2370 int first = 1; | |
| 2371 do { | |
| 2372 debug_out (first ? "(" : " "); | |
| 2373 first = 0; | |
| 2374 debug_p4 (XCAR (obj)); | |
| 2375 obj = XCDR (obj); | |
| 2376 } while (CONSP (obj)); | |
| 2377 if (NILP (obj)) | |
| 2378 debug_out (")"); | |
| 2379 else | |
| 2380 { | |
| 2381 debug_out (" . "); | |
| 2382 debug_p4 (obj); | |
| 2383 debug_out (")"); | |
| 2384 } | |
| 2385 } | |
| 2386 else if (VECTORP (obj)) | |
| 2387 { | |
| 2388 int size = XVECTOR_LENGTH (obj); | |
| 2389 int i; | |
| 2390 int first = 1; | |
| 2391 | |
| 2392 for (i = 0; i < size; i++) | |
| 2393 { | |
| 2394 debug_out (first ? "[" : " "); | |
| 2395 first = 0; | |
| 2396 debug_p4 (XVECTOR_DATA (obj)[i]); | |
| 2397 debug_out ("]"); | |
| 2398 } | |
| 2399 } | |
| 2400 else if (SYMBOLP (obj)) | |
| 2401 { | |
| 2402 Lisp_Object name = XSYMBOL_NAME (obj); | |
| 2403 if (!STRINGP (name)) | |
| 2404 debug_out ("<<bad symbol>>"); | |
| 2405 else | |
| 2406 debug_out ("%s", XSTRING_DATA (name)); | |
| 2407 } | |
| 2408 else if (INTP (obj)) | |
| 2409 { | |
| 2410 debug_out ("%ld", XINT (obj)); | |
| 2411 } | |
| 2412 else if (FLOATP (obj)) | |
| 2413 { | |
| 2414 debug_out ("%g", XFLOAT_DATA (obj)); | |
| 2415 } | |
| 2416 else | |
| 2417 { | |
| 2418 struct lrecord_header *header = | |
| 2419 (struct lrecord_header *) XPNTR (obj); | |
| 2420 | |
| 2421 if (header->type >= lrecord_type_last_built_in_type) | |
| 2422 debug_out ("<< bad object type=%d 0x%lx>>", header->type, | |
| 2423 (EMACS_INT) header); | |
| 2424 else | |
| 3063 | 2425 debug_out ("#<%s addr=0x%lx uid=0x%lx>", |
| 2720 | 2426 LHEADER_IMPLEMENTATION (header)->name, |
| 3063 | 2427 (EMACS_INT) header, |
| 2720 | 2428 (EMACS_INT) ((struct lrecord_header *) header)->uid); |
| 1204 | 2429 } |
| 2430 } | |
| 2431 | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2432 static int |
| 1346 | 2433 ext_print_begin (int dest) |
| 2434 { | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2435 int depth = begin_inhibit_non_essential_conversion_operations (); |
| 1346 | 2436 if (dest & EXT_PRINT_ALTERNATE) |
| 2437 alternate_do_pointer = 0; | |
| 2438 if (dest & (EXT_PRINT_STDERR | EXT_PRINT_STDOUT)) | |
| 2439 stdout_clear_before_next_output = 1; | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2440 return depth; |
| 1346 | 2441 } |
| 2442 | |
| 2443 static void | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2444 ext_print_end (int dest, int depth) |
| 1346 | 2445 { |
| 2446 if (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR | EXT_PRINT_STDOUT)) | |
| 2447 external_out (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR | | |
| 2448 EXT_PRINT_STDOUT), "\n"); | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2449 unbind_to (depth); |
| 1346 | 2450 } |
| 2451 | |
| 2452 static void | |
| 2453 external_debug_print (Lisp_Object object, int dest) | |
| 2454 { | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2455 int depth = ext_print_begin (dest); |
| 1346 | 2456 debug_prin1 (object, dest); |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2457 ext_print_end (dest, depth); |
| 1346 | 2458 } |
| 2459 | |
| 1204 | 2460 void |
| 2461 debug_p3 (Lisp_Object obj) | |
| 2462 { | |
| 2463 debug_p4 (obj); | |
| 2464 debug_out ("\n"); | |
| 2465 } | |
| 2466 | |
| 2467 void | |
| 428 | 2468 debug_print (Lisp_Object debug_print_obj) |
| 2469 { | |
| 1346 | 2470 external_debug_print (debug_print_obj, EXT_PRINT_ALL); |
| 428 | 2471 } |
| 2472 | |
|
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2473 /* Printf-style output when the objects being printed are Lisp objects. |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2474 Calling style is e.g. |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2475 |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2476 debug_out_lisp ("Called foo(%s %s)\n", 2, arg0, arg1) |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2477 */ |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2478 |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2479 void |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2480 debug_out_lisp (const CIbyte *format, int nargs, ...) |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2481 { |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2482 /* This function cannot GC, since GC is forbidden */ |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2483 struct debug_bindings bindings; |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2484 int specdepth = debug_print_enter (&bindings); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2485 Lisp_Object *args = alloca_array (Lisp_Object, nargs); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2486 va_list va; |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2487 int i; |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2488 Ibyte *msgout; |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2489 |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2490 va_start (va, nargs); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2491 for (i = 0; i < nargs; i++) |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2492 args[i] = va_arg (va, Lisp_Object); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2493 va_end (va); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2494 msgout = emacs_vsprintf_malloc_lisp (format, Qnil, nargs, args, NULL); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2495 debug_out ("%s", msgout); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2496 xfree (msgout); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2497 unbind_to (specdepth); |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2498 } |
|
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2499 |
| 1204 | 2500 /* Getting tired of typing debug_print() ... */ |
| 2501 void dp (Lisp_Object debug_print_obj); | |
| 2502 void | |
| 2503 dp (Lisp_Object debug_print_obj) | |
| 2504 { | |
| 2505 debug_print (debug_print_obj); | |
| 2506 } | |
| 2507 | |
| 1346 | 2508 /* Alternate debug printer: Return a char * pointer to the output */ |
| 2509 char *dpa (Lisp_Object debug_print_obj); | |
| 2510 char * | |
| 2511 dpa (Lisp_Object debug_print_obj) | |
| 2512 { | |
| 2513 external_debug_print (debug_print_obj, EXT_PRINT_ALTERNATE); | |
| 2514 | |
| 2515 return alternate_do_string; | |
| 2516 } | |
| 2517 | |
| 428 | 2518 /* Debugging kludge -- unbuffered */ |
| 2519 /* This function provided for the benefit of the debugger. */ | |
| 2520 void | |
| 2521 debug_backtrace (void) | |
| 2522 { | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2523 /* This function cannot GC, since GC is forbidden */ |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2524 struct debug_bindings bindings; |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2525 int specdepth = debug_print_enter (&bindings); |
| 428 | 2526 |
| 2527 Fbacktrace (Qexternal_debugging_output, Qt); | |
| 2528 stderr_out ("\n"); | |
| 2529 | |
| 802 | 2530 unbind_to (specdepth); |
| 428 | 2531 } |
| 2532 | |
| 1204 | 2533 /* Getting tired of typing debug_backtrace() ... */ |
| 2534 void db (void); | |
| 2535 void | |
| 2536 db (void) | |
| 2537 { | |
| 2538 debug_backtrace (); | |
| 2539 } | |
| 2540 | |
| 428 | 2541 void |
| 2542 debug_short_backtrace (int length) | |
| 2543 { | |
| 2544 int first = 1; | |
| 2545 struct backtrace *bt = backtrace_list; | |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2546 |
| 771 | 2547 debug_out (" ["); |
| 428 | 2548 while (length > 0 && bt) |
| 2549 { | |
| 2550 if (!first) | |
| 2551 { | |
| 771 | 2552 debug_out (", "); |
| 428 | 2553 } |
| 2554 if (COMPILED_FUNCTIONP (*bt->function)) | |
| 2555 { | |
| 1346 | 2556 #if defined (COMPILED_FUNCTION_ANNOTATION_HACK) |
| 428 | 2557 Lisp_Object ann = |
| 2558 compiled_function_annotation (XCOMPILED_FUNCTION (*bt->function)); | |
| 2559 #else | |
| 2560 Lisp_Object ann = Qnil; | |
| 2561 #endif | |
| 2562 if (!NILP (ann)) | |
| 2563 { | |
| 771 | 2564 debug_out ("<compiled-function from "); |
| 1346 | 2565 debug_prin1 (ann, EXT_PRINT_ALL); |
| 771 | 2566 debug_out (">"); |
| 428 | 2567 } |
| 2568 else | |
| 2569 { | |
| 771 | 2570 debug_out ("<compiled-function of unknown origin>"); |
| 428 | 2571 } |
| 2572 } | |
| 2573 else | |
| 1346 | 2574 debug_prin1 (*bt->function, EXT_PRINT_ALL); |
| 428 | 2575 first = 0; |
| 2576 length--; | |
| 2577 bt = bt->next; | |
| 2578 } | |
| 771 | 2579 debug_out ("]\n"); |
| 428 | 2580 } |
| 2581 | |
| 2582 | |
| 2583 void | |
| 2584 syms_of_print (void) | |
| 2585 { | |
| 563 | 2586 DEFSYMBOL (Qstandard_output); |
| 428 | 2587 |
| 563 | 2588 DEFSYMBOL (Qprint_length); |
| 428 | 2589 |
| 563 | 2590 DEFSYMBOL (Qprint_string_length); |
| 428 | 2591 |
| 563 | 2592 DEFSYMBOL (Qdisplay_error); |
| 2593 DEFSYMBOL (Qprint_message_label); | |
| 428 | 2594 |
| 2595 DEFSUBR (Fprin1); | |
| 2596 DEFSUBR (Fprin1_to_string); | |
| 2597 DEFSUBR (Fprinc); | |
| 2598 DEFSUBR (Fprint); | |
| 2599 DEFSUBR (Ferror_message_string); | |
| 2600 DEFSUBR (Fdisplay_error); | |
| 2601 DEFSUBR (Fterpri); | |
| 2602 DEFSUBR (Fwrite_char); | |
| 2603 DEFSUBR (Falternate_debugging_output); | |
| 1346 | 2604 DEFSUBR (Fset_device_clear_left_side); |
| 2605 DEFSUBR (Fdevice_left_side_clear_p); | |
| 428 | 2606 DEFSUBR (Fexternal_debugging_output); |
| 2607 DEFSUBR (Fopen_termscript); | |
| 563 | 2608 DEFSYMBOL (Qexternal_debugging_output); |
| 2609 DEFSYMBOL (Qalternate_debugging_output); | |
| 442 | 2610 #ifdef HAVE_MS_WINDOWS |
| 563 | 2611 DEFSYMBOL (Qmswindows_debugging_output); |
| 442 | 2612 #endif |
| 428 | 2613 DEFSUBR (Fwith_output_to_temp_buffer); |
| 2614 } | |
| 2615 | |
| 2616 void | |
| 2617 reinit_vars_of_print (void) | |
| 2618 { | |
| 2619 alternate_do_pointer = 0; | |
| 2620 } | |
| 2621 | |
| 2622 void | |
| 2623 vars_of_print (void) | |
| 2624 { | |
| 2625 DEFVAR_LISP ("standard-output", &Vstandard_output /* | |
| 2626 Output stream `print' uses by default for outputting a character. | |
| 2627 This may be any function of one argument. | |
| 2628 It may also be a buffer (output is inserted before point) | |
| 2629 or a marker (output is inserted and the marker is advanced) | |
| 2630 or the symbol t (output appears in the minibuffer line). | |
| 2631 */ ); | |
| 2632 Vstandard_output = Qt; | |
| 2633 | |
| 2634 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /* | |
| 2635 The format descriptor string that lisp uses to print floats. | |
| 2636 This is a %-spec like those accepted by `printf' in C, | |
| 2637 but with some restrictions. It must start with the two characters `%.'. | |
| 2638 After that comes an integer precision specification, | |
| 2639 and then a letter which controls the format. | |
| 2640 The letters allowed are `e', `f' and `g'. | |
| 2641 Use `e' for exponential notation "DIG.DIGITSeEXPT" | |
| 2642 Use `f' for decimal point notation "DIGITS.DIGITS". | |
| 2643 Use `g' to choose the shorter of those two formats for the number at hand. | |
| 2644 The precision in any of these cases is the number of digits following | |
| 2645 the decimal point. With `f', a precision of 0 means to omit the | |
| 2646 decimal point. 0 is not allowed with `f' or `g'. | |
| 2647 | |
| 2648 A value of nil means to use `%.16g'. | |
| 2649 | |
| 2650 Regardless of the value of `float-output-format', a floating point number | |
| 2651 will never be printed in such a way that it is ambiguous with an integer; | |
| 2652 that is, a floating-point number will always be printed with a decimal | |
| 2653 point and/or an exponent, even if the digits following the decimal point | |
| 2654 are all zero. This is to preserve read-equivalence. | |
| 2655 */ ); | |
| 2656 Vfloat_output_format = Qnil; | |
| 2657 | |
| 2658 DEFVAR_LISP ("print-length", &Vprint_length /* | |
| 2659 Maximum length of list or vector to print before abbreviating. | |
| 2660 A value of nil means no limit. | |
| 2661 */ ); | |
| 2662 Vprint_length = Qnil; | |
| 2663 | |
| 2664 DEFVAR_LISP ("print-string-length", &Vprint_string_length /* | |
| 2665 Maximum length of string to print before abbreviating. | |
| 2666 A value of nil means no limit. | |
| 2667 */ ); | |
| 2668 Vprint_string_length = Qnil; | |
| 2669 | |
| 2670 DEFVAR_LISP ("print-level", &Vprint_level /* | |
| 2671 Maximum depth of list nesting to print before abbreviating. | |
| 2672 A value of nil means no limit. | |
| 2673 */ ); | |
| 2674 Vprint_level = Qnil; | |
| 2675 | |
| 2676 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /* | |
| 2677 Non-nil means print newlines in strings as backslash-n. | |
| 2678 */ ); | |
| 2679 print_escape_newlines = 0; | |
| 2680 | |
| 2681 DEFVAR_BOOL ("print-readably", &print_readably /* | |
| 2682 If non-nil, then all objects will be printed in a readable form. | |
| 2683 If an object has no readable representation, then an error is signalled. | |
| 2684 When print-readably is true, compiled-function objects will be written in | |
| 2685 #[...] form instead of in #<compiled-function [...]> form, and two-element | |
| 2686 lists of the form (quote object) will be written as the equivalent 'object. | |
| 2687 Do not SET this variable; bind it instead. | |
| 2688 */ ); | |
| 2689 print_readably = 0; | |
| 2690 | |
| 2691 /* #### I think this should default to t. But we'd better wait | |
| 2692 until we see that it works out. */ | |
| 2693 DEFVAR_LISP ("print-gensym", &Vprint_gensym /* | |
| 2694 If non-nil, then uninterned symbols will be printed specially. | |
| 2695 Uninterned symbols are those which are not present in `obarray', that is, | |
| 2696 those which were made with `make-symbol' or by calling `intern' with a | |
| 2697 second argument. | |
| 2698 | |
| 2699 When print-gensym is true, such symbols will be preceded by "#:", | |
| 2700 which causes the reader to create a new symbol instead of interning | |
| 2701 and returning an existing one. Beware: the #: syntax creates a new | |
| 2702 symbol each time it is seen, so if you print an object which contains | |
| 2703 two pointers to the same uninterned symbol, `read' will not duplicate | |
| 2704 that structure. | |
| 2705 | |
| 2706 If the value of `print-gensym' is a cons cell, then in addition | |
| 2707 refrain from clearing `print-gensym-alist' on entry to and exit from | |
| 2708 printing functions, so that the use of #...# and #...= can carry over | |
| 2709 for several separately printed objects. | |
| 2710 */ ); | |
| 2711 Vprint_gensym = Qnil; | |
| 2712 | |
| 2713 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist /* | |
| 2714 Association list of elements (GENSYM . N) to guide use of #N# and #N=. | |
| 2715 In each element, GENSYM is an uninterned symbol that has been associated | |
| 2716 with #N= for the specified value of N. | |
| 2717 */ ); | |
| 2718 Vprint_gensym_alist = Qnil; | |
| 2719 | |
| 2720 DEFVAR_LISP ("print-message-label", &Vprint_message_label /* | |
| 2721 Label for minibuffer messages created with `print'. This should | |
| 2722 generally be bound with `let' rather than set. (See `display-message'.) | |
| 2723 */ ); | |
| 2724 Vprint_message_label = Qprint; | |
| 1957 | 2725 |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2726 /* The exact size doesn't matter since we realloc when necessary. |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2727 Use CIbyte instead of Ibyte so that debuggers show the associated |
|
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2728 string automatically. */ |
| 1957 | 2729 alternate_do_size = 5000; |
|
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2730 alternate_do_string = xnew_array (CIbyte, 5000); |
| 428 | 2731 } |
