From: Paul Eggert Date: Sun, 21 May 2017 08:45:34 +0000 (-0700) Subject: Pacify --enable-gcc-warnings without modules X-Git-Tag: emacs-26.0.90~521^2~329 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=97c7a61d90987e182c1d2ec40fbe0d1d7df844c5;p=emacs.git Pacify --enable-gcc-warnings without modules * src/print.c (print_vectorlike): New function, taken from part of print_object. This one is indented properly, and pacifies --enable-gcc-warnings by using a default case instead of listing all the enum values, sometimes incompletely. (print_object): Use it. --- diff --git a/src/print.c b/src/print.c index be2e16a7499..49408bbeb40 100644 --- a/src/print.c +++ b/src/print.c @@ -1346,6 +1346,371 @@ print_prune_string_charset (Lisp_Object string) return string; } +static bool +print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, + char *buf) +{ + switch (PSEUDOVECTOR_TYPE (XVECTOR (obj))) + { + case PVEC_PROCESS: + if (escapeflag) + { + print_c_string ("#name, printcharfun); + printchar ('>', printcharfun); + } + else + print_string (XPROCESS (obj)->name, printcharfun); + break; + + case PVEC_BOOL_VECTOR: + { + EMACS_INT size = bool_vector_size (obj); + ptrdiff_t size_in_chars = bool_vector_bytes (size); + ptrdiff_t real_size_in_chars = size_in_chars; + + int len = sprintf (buf, "#&%"pI"d\"", size); + strout (buf, len, len, printcharfun); + + /* Don't print more characters than the specified maximum. + Negative values of print-length are invalid. Treat them + like a print-length of nil. */ + if (NATNUMP (Vprint_length) + && XFASTINT (Vprint_length) < size_in_chars) + size_in_chars = XFASTINT (Vprint_length); + + for (ptrdiff_t i = 0; i < size_in_chars; i++) + { + maybe_quit (); + unsigned char c = bool_vector_uchar_data (obj)[i]; + if (c == '\n' && print_escape_newlines) + print_c_string ("\\n", printcharfun); + else if (c == '\f' && print_escape_newlines) + print_c_string ("\\f", printcharfun); + else if (c > '\177') + { + /* Use octal escapes to avoid encoding issues. */ + int len = sprintf (buf, "\\%o", c); + strout (buf, len, len, printcharfun); + } + else + { + if (c == '\"' || c == '\\') + printchar ('\\', printcharfun); + printchar (c, printcharfun); + } + } + + if (size_in_chars < real_size_in_chars) + print_c_string (" ...", printcharfun); + printchar ('\"', printcharfun); + } + break; + + case PVEC_SUBR: + print_c_string ("#symbol_name, printcharfun); + printchar ('>', printcharfun); + break; + + case PVEC_XWIDGET: case PVEC_XWIDGET_VIEW: + print_c_string ("#', printcharfun); + break; + + case PVEC_WINDOW: + { + int len = sprintf (buf, "#sequence_number); + strout (buf, len, len, printcharfun); + if (BUFFERP (XWINDOW (obj)->contents)) + { + print_c_string (" on ", printcharfun); + print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name), + printcharfun); + } + printchar ('>', printcharfun); + } + break; + + case PVEC_TERMINAL: + { + struct terminal *t = XTERMINAL (obj); + int len = sprintf (buf, "#id); + strout (buf, len, len, printcharfun); + if (t->name) + { + print_c_string (" on ", printcharfun); + print_c_string (t->name, printcharfun); + } + printchar ('>', printcharfun); + } + break; + + case PVEC_HASH_TABLE: + { + struct Lisp_Hash_Table *h = XHASH_TABLE (obj); + /* Implement a readable output, e.g.: + #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ + /* Always print the size. */ + int len = sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next)); + strout (buf, len, len, printcharfun); + + if (!NILP (h->test.name)) + { + print_c_string (" test ", printcharfun); + print_object (h->test.name, printcharfun, escapeflag); + } + + if (!NILP (h->weak)) + { + print_c_string (" weakness ", printcharfun); + print_object (h->weak, printcharfun, escapeflag); + } + + print_c_string (" rehash-size ", printcharfun); + print_object (Fhash_table_rehash_size (obj), + printcharfun, escapeflag); + + print_c_string (" rehash-threshold ", printcharfun); + print_object (Fhash_table_rehash_threshold (obj), + printcharfun, escapeflag); + + if (h->pure) + { + print_c_string (" purecopy ", printcharfun); + print_object (h->pure ? Qt : Qnil, printcharfun, escapeflag); + } + + print_c_string (" data ", printcharfun); + + /* Print the data here as a plist. */ + ptrdiff_t real_size = HASH_TABLE_SIZE (h); + ptrdiff_t size = real_size; + + /* Don't print more elements than the specified maximum. */ + if (NATNUMP (Vprint_length) && XFASTINT (Vprint_length) < size) + size = XFASTINT (Vprint_length); + + printchar ('(', printcharfun); + for (ptrdiff_t i = 0; i < size; i++) + if (!NILP (HASH_HASH (h, i))) + { + if (i) printchar (' ', printcharfun); + print_object (HASH_KEY (h, i), printcharfun, escapeflag); + printchar (' ', printcharfun); + print_object (HASH_VALUE (h, i), printcharfun, escapeflag); + } + + if (size < real_size) + print_c_string (" ...", printcharfun); + + print_c_string ("))", printcharfun); + } + break; + + case PVEC_BUFFER: + if (!BUFFER_LIVE_P (XBUFFER (obj))) + print_c_string ("#", printcharfun); + else if (escapeflag) + { + print_c_string ("#', printcharfun); + } + else + print_string (BVAR (XBUFFER (obj), name), printcharfun); + break; + + case PVEC_WINDOW_CONFIGURATION: + print_c_string ("#", printcharfun); + break; + + case PVEC_FRAME: + { + void *ptr = XFRAME (obj); + Lisp_Object frame_name = XFRAME (obj)->name; + + print_c_string ((FRAME_LIVE_P (XFRAME (obj)) + ? "#", ptr); + strout (buf, len, len, printcharfun); + } + break; + + case PVEC_FONT: + { + if (! FONT_OBJECT_P (obj)) + { + if (FONT_SPEC_P (obj)) + print_c_string ("# FONT_WIDTH_INDEX) + print_object (AREF (obj, i), printcharfun, escapeflag); + else + print_object (font_style_symbolic (obj, i, 0), + printcharfun, escapeflag); + } + } + else + { + print_c_string ("#', printcharfun); + } + break; + + case PVEC_THREAD: + print_c_string ("#name)) + print_string (XTHREAD (obj)->name, printcharfun); + else + { + int len = sprintf (buf, "%p", XTHREAD (obj)); + strout (buf, len, len, printcharfun); + } + printchar ('>', printcharfun); + break; + + case PVEC_MUTEX: + print_c_string ("#name)) + print_string (XMUTEX (obj)->name, printcharfun); + else + { + int len = sprintf (buf, "%p", XMUTEX (obj)); + strout (buf, len, len, printcharfun); + } + printchar ('>', printcharfun); + break; + + case PVEC_CONDVAR: + print_c_string ("#name)) + print_string (XCONDVAR (obj)->name, printcharfun); + else + { + int len = sprintf (buf, "%p", XCONDVAR (obj)); + strout (buf, len, len, printcharfun); + } + printchar ('>', printcharfun); + break; + + case PVEC_RECORD: + { + ptrdiff_t size = PVSIZE (obj); + + /* Don't print more elements than the specified maximum. */ + ptrdiff_t n + = (NATNUMP (Vprint_length) && XFASTINT (Vprint_length) < size + ? XFASTINT (Vprint_length) : size); + + print_c_string ("#s(", printcharfun); + for (ptrdiff_t i = 0; i < n; i ++) + { + if (i) printchar (' ', printcharfun); + print_object (AREF (obj, i), printcharfun, escapeflag); + } + if (n < size) + print_c_string (" ...", printcharfun); + printchar (')', printcharfun); + } + break; + + case PVEC_SUB_CHAR_TABLE: + case PVEC_COMPILED: + case PVEC_CHAR_TABLE: + case PVEC_NORMAL_VECTOR: + { + ptrdiff_t size = ASIZE (obj); + if (COMPILEDP (obj)) + { + printchar ('#', printcharfun); + size &= PSEUDOVECTOR_SIZE_MASK; + } + if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)) + { + /* Print a char-table as if it were a vector, + lumping the parent and default slots in with the + character slots. But add #^ as a prefix. */ + + /* Make each lowest sub_char_table start a new line. + Otherwise we'll make a line extremely long, which + results in slow redisplay. */ + if (SUB_CHAR_TABLE_P (obj) + && XSUB_CHAR_TABLE (obj)->depth == 3) + printchar ('\n', printcharfun); + print_c_string ("#^", printcharfun); + if (SUB_CHAR_TABLE_P (obj)) + printchar ('^', printcharfun); + size &= PSEUDOVECTOR_SIZE_MASK; + } + if (size & PSEUDOVECTOR_FLAG) + return false; + + printchar ('[', printcharfun); + + int idx = SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0; + Lisp_Object tem; + ptrdiff_t real_size = size; + + /* For a sub char-table, print heading non-Lisp data first. */ + if (SUB_CHAR_TABLE_P (obj)) + { + int i = sprintf (buf, "%d %d", XSUB_CHAR_TABLE (obj)->depth, + XSUB_CHAR_TABLE (obj)->min_char); + strout (buf, i, i, printcharfun); + } + + /* Don't print more elements than the specified maximum. */ + if (NATNUMP (Vprint_length) + && XFASTINT (Vprint_length) < size) + size = XFASTINT (Vprint_length); + + for (int i = idx; i < size; i++) + { + if (i) printchar (' ', printcharfun); + tem = AREF (obj, i); + print_object (tem, printcharfun, escapeflag); + } + if (size < real_size) + print_c_string (" ...", printcharfun); + printchar (']', printcharfun); + } + break; + +#ifdef HAVE_MODULES + case PVEC_MODULE_FUNCTION: + print_string (module_format_fun_env (XMODULE_FUNCTION (obj)), + printcharfun); + break; +#endif + + default: + emacs_abort (); + } + + return true; +} + static void print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) { @@ -1678,390 +2043,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) break; case Lisp_Vectorlike: - switch (PSEUDOVECTOR_TYPE (XVECTOR (obj))) { - case PVEC_PROCESS: - { - if (escapeflag) - { - print_c_string ("#name, printcharfun); - printchar ('>', printcharfun); - } - else - print_string (XPROCESS (obj)->name, printcharfun); - } - break; - - case PVEC_BOOL_VECTOR: - { - ptrdiff_t i; - unsigned char c; - EMACS_INT size = bool_vector_size (obj); - ptrdiff_t size_in_chars = bool_vector_bytes (size); - ptrdiff_t real_size_in_chars = size_in_chars; - - int len = sprintf (buf, "#&%"pI"d\"", size); - strout (buf, len, len, printcharfun); - - /* Don't print more characters than the specified maximum. - Negative values of print-length are invalid. Treat them - like a print-length of nil. */ - if (NATNUMP (Vprint_length) - && XFASTINT (Vprint_length) < size_in_chars) - size_in_chars = XFASTINT (Vprint_length); - - for (i = 0; i < size_in_chars; i++) - { - maybe_quit (); - c = bool_vector_uchar_data (obj)[i]; - if (c == '\n' && print_escape_newlines) - print_c_string ("\\n", printcharfun); - else if (c == '\f' && print_escape_newlines) - print_c_string ("\\f", printcharfun); - else if (c > '\177') - { - /* Use octal escapes to avoid encoding issues. */ - len = sprintf (buf, "\\%o", c); - strout (buf, len, len, printcharfun); - } - else - { - if (c == '\"' || c == '\\') - printchar ('\\', printcharfun); - printchar (c, printcharfun); - } - } - - if (size_in_chars < real_size_in_chars) - print_c_string (" ...", printcharfun); - printchar ('\"', printcharfun); - } - break; - - case PVEC_SUBR: - { - print_c_string ("#symbol_name, printcharfun); - printchar ('>', printcharfun); - } - break; - - case PVEC_XWIDGET: case PVEC_XWIDGET_VIEW: - { - print_c_string ("#', printcharfun); - } - break; - - case PVEC_WINDOW: - { - int len = sprintf (buf, "#sequence_number); - strout (buf, len, len, printcharfun); - if (BUFFERP (XWINDOW (obj)->contents)) - { - print_c_string (" on ", printcharfun); - print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name), - printcharfun); - } - printchar ('>', printcharfun); - } - break; - - case PVEC_TERMINAL: - { - struct terminal *t = XTERMINAL (obj); - int len = sprintf (buf, "#id); - strout (buf, len, len, printcharfun); - if (t->name) - { - print_c_string (" on ", printcharfun); - print_c_string (t->name, printcharfun); - } - printchar ('>', printcharfun); - } - break; - - case PVEC_HASH_TABLE: - { - struct Lisp_Hash_Table *h = XHASH_TABLE (obj); - ptrdiff_t i; - ptrdiff_t real_size, size; - int len; - /* Implement a readable output, e.g.: - #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ - /* Always print the size. */ - len = sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next)); - strout (buf, len, len, printcharfun); - - if (!NILP (h->test.name)) - { - print_c_string (" test ", printcharfun); - print_object (h->test.name, printcharfun, escapeflag); - } - - if (!NILP (h->weak)) - { - print_c_string (" weakness ", printcharfun); - print_object (h->weak, printcharfun, escapeflag); - } - - print_c_string (" rehash-size ", printcharfun); - print_object (Fhash_table_rehash_size (obj), - printcharfun, escapeflag); - - print_c_string (" rehash-threshold ", printcharfun); - print_object (Fhash_table_rehash_threshold (obj), - printcharfun, escapeflag); - - if (h->pure) - { - print_c_string (" purecopy ", printcharfun); - print_object (h->pure ? Qt : Qnil, printcharfun, escapeflag); - } - - print_c_string (" data ", printcharfun); - - /* Print the data here as a plist. */ - real_size = HASH_TABLE_SIZE (h); - size = real_size; - - /* Don't print more elements than the specified maximum. */ - if (NATNUMP (Vprint_length) - && XFASTINT (Vprint_length) < size) - size = XFASTINT (Vprint_length); - - printchar ('(', printcharfun); - for (i = 0; i < size; i++) - if (!NILP (HASH_HASH (h, i))) - { - if (i) printchar (' ', printcharfun); - print_object (HASH_KEY (h, i), printcharfun, escapeflag); - printchar (' ', printcharfun); - print_object (HASH_VALUE (h, i), printcharfun, escapeflag); - } - - if (size < real_size) - print_c_string (" ...", printcharfun); - - print_c_string ("))", printcharfun); - } - break; - - case PVEC_BUFFER: - { - if (!BUFFER_LIVE_P (XBUFFER (obj))) - print_c_string ("#", printcharfun); - else if (escapeflag) - { - print_c_string ("#', printcharfun); - } - else - print_string (BVAR (XBUFFER (obj), name), printcharfun); - } - break; - - case PVEC_WINDOW_CONFIGURATION: - print_c_string ("#", printcharfun); - break; - - case PVEC_FRAME: ; - { - int len; - void *ptr = XFRAME (obj); - Lisp_Object frame_name = XFRAME (obj)->name; - - print_c_string ((FRAME_LIVE_P (XFRAME (obj)) - ? "#", ptr); - strout (buf, len, len, printcharfun); - } - break; - - case PVEC_FONT: - { - int i; - - if (! FONT_OBJECT_P (obj)) - { - if (FONT_SPEC_P (obj)) - print_c_string ("# FONT_WIDTH_INDEX) - print_object (AREF (obj, i), printcharfun, escapeflag); - else - print_object (font_style_symbolic (obj, i, 0), - printcharfun, escapeflag); - } - } - else - { - print_c_string ("#', printcharfun); - } - break; - - case PVEC_THREAD: - { - print_c_string ("#name)) - print_string (XTHREAD (obj)->name, printcharfun); - else - { - int len = sprintf (buf, "%p", XTHREAD (obj)); - strout (buf, len, len, printcharfun); - } - printchar ('>', printcharfun); - } - break; - - case PVEC_MUTEX: - { - print_c_string ("#name)) - print_string (XMUTEX (obj)->name, printcharfun); - else - { - int len = sprintf (buf, "%p", XMUTEX (obj)); - strout (buf, len, len, printcharfun); - } - printchar ('>', printcharfun); - } - break; - - case PVEC_CONDVAR: - { - print_c_string ("#name)) - print_string (XCONDVAR (obj)->name, printcharfun); - else - { - int len = sprintf (buf, "%p", XCONDVAR (obj)); - strout (buf, len, len, printcharfun); - } - printchar ('>', printcharfun); - } - break; - - case PVEC_RECORD: - { - ptrdiff_t n, size = PVSIZE (obj); - int i; - - /* Don't print more elements than the specified maximum. */ - if (NATNUMP (Vprint_length) - && XFASTINT (Vprint_length) < size) - n = XFASTINT (Vprint_length); - else - n = size; - - print_c_string ("#s(", printcharfun); - for (i = 0; i < n; i ++) - { - if (i) printchar (' ', printcharfun); - print_object (AREF (obj, i), printcharfun, escapeflag); - } - if (n < size) - print_c_string (" ...", printcharfun); - printchar (')', printcharfun); - } - break; - - case PVEC_SUB_CHAR_TABLE: - case PVEC_COMPILED: - case PVEC_CHAR_TABLE: - case PVEC_NORMAL_VECTOR: ; - { - ptrdiff_t size = ASIZE (obj); - if (COMPILEDP (obj)) - { - printchar ('#', printcharfun); - size &= PSEUDOVECTOR_SIZE_MASK; - } - if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)) - { - /* We print a char-table as if it were a vector, - lumping the parent and default slots in with the - character slots. But we add #^ as a prefix. */ - - /* Make each lowest sub_char_table start a new line. - Otherwise we'll make a line extremely long, which - results in slow redisplay. */ - if (SUB_CHAR_TABLE_P (obj) - && XSUB_CHAR_TABLE (obj)->depth == 3) - printchar ('\n', printcharfun); - print_c_string ("#^", printcharfun); - if (SUB_CHAR_TABLE_P (obj)) - printchar ('^', printcharfun); - size &= PSEUDOVECTOR_SIZE_MASK; - } - if (size & PSEUDOVECTOR_FLAG) - goto badtype; - - printchar ('[', printcharfun); - { - int i, idx = SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0; - Lisp_Object tem; - ptrdiff_t real_size = size; - - /* For a sub char-table, print heading non-Lisp data first. */ - if (SUB_CHAR_TABLE_P (obj)) - { - i = sprintf (buf, "%d %d", XSUB_CHAR_TABLE (obj)->depth, - XSUB_CHAR_TABLE (obj)->min_char); - strout (buf, i, i, printcharfun); - } - - /* Don't print more elements than the specified maximum. */ - if (NATNUMP (Vprint_length) - && XFASTINT (Vprint_length) < size) - size = XFASTINT (Vprint_length); - - for (i = idx; i < size; i++) - { - if (i) printchar (' ', printcharfun); - tem = AREF (obj, i); - print_object (tem, printcharfun, escapeflag); - } - if (size < real_size) - print_c_string (" ...", printcharfun); - } - printchar (']', printcharfun); - } - break; - -#ifdef HAVE_MODULES - case PVEC_MODULE_FUNCTION: - print_string (module_format_fun_env (XMODULE_FUNCTION (obj)), - printcharfun); - break; -#endif - - case PVEC_OTHER: - case PVEC_FREE: - emacs_abort (); - } + if (! print_vectorlike (obj, printcharfun, escapeflag, buf)) + goto badtype; break; case Lisp_Misc: