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