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