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