# HG changeset patch # User Aidan Kehoe # Date 1426464586 0 # Node ID 15041705c1968f6ca0959a47600cdc31f9c65d36 # Parent 5b799fa6d75ef0346bc9cde0d71cc11d264d6a96 Provide `char-code-limit', implement the GNU equivalent in terms of it. src/ChangeLog addition: 2015-03-15 Aidan Kehoe * text.h: Make CHAR_CODE_LIMIT available as a #define. * text.h (valid_ichar_p): Use it. * text.c: Make a fixnum Vchar_code_limit available here. * text.c (non_ascii_valid_ichar_p): Use CHAR_CODE_LIMIT. * text.c (vars_of_text): Make `char-code-limit' available to Lisp. tests/ChangeLog addition: 2015-03-15 Aidan Kehoe * automated/mule-tests.el (test-chars): Use char-code-limit explicitly here, instead of hardcoding the corresponding values. lisp/ChangeLog addition: 2015-03-16 Aidan Kehoe * obsolete.el (max-char): Make this available for compatiblity with GNU, implement it in terms of char-code-limit. diff -r 5b799fa6d75e -r 15041705c196 lisp/ChangeLog --- a/lisp/ChangeLog Sun Mar 15 21:13:23 2015 +0000 +++ b/lisp/ChangeLog Mon Mar 16 00:09:46 2015 +0000 @@ -1,3 +1,9 @@ +2015-03-16 Aidan Kehoe + + * obsolete.el (max-char): + Make this available for compatiblity with GNU, implement it in + terms of char-code-limit. + 2015-03-15 Aidan Kehoe * tty-init.el (make-frame-after-init-entry-point): diff -r 5b799fa6d75e -r 15041705c196 lisp/obsolete.el --- a/lisp/obsolete.el Sun Mar 15 21:13:23 2015 +0000 +++ b/lisp/obsolete.el Mon Mar 16 00:09:46 2015 +0000 @@ -485,5 +485,15 @@ (make-obsolete 'remrassoc "use delete* with :test #'equal, :key #'cdr") (make-obsolete 'remrassq "use delete* with :test #'eq, :key #'cdr") +(defun max-char () + "Return a fixnum one less than `char-code-limit'. + +In contrast with GNU Emacs, this is not necessarily a valid character, but it +is an inclusive upper bound on the possible values returned by `char-int'." + (1- char-code-limit)) +(make-compatible + 'max-char + "consider `char-code-limit', which gives an exclusive upper bound") + (provide 'obsolete) ;;; obsolete.el ends here diff -r 5b799fa6d75e -r 15041705c196 man/ChangeLog --- a/man/ChangeLog Sun Mar 15 21:13:23 2015 +0000 +++ b/man/ChangeLog Mon Mar 16 00:09:46 2015 +0000 @@ -1,3 +1,8 @@ +2015-03-15 Aidan Kehoe + + * lispref/strings.texi (Character Codes): + Document `char-code-limit' here too. + 2015-03-14 Aidan Kehoe * lispref/help.texi (Help Functions): diff -r 5b799fa6d75e -r 15041705c196 man/lispref/strings.texi --- a/man/lispref/strings.texi Sun Mar 15 21:13:23 2015 +0000 +++ b/man/lispref/strings.texi Mon Mar 16 00:09:46 2015 +0000 @@ -330,6 +330,17 @@ @code{nil} is returned. @end defun +@defvar char-code-limit +This is a constant integer describing an exclusive upper bound on the +results return by @code{char-int} and that set of integers (fixnums) for +which @code{int-char} will give non-nil. Without @sc{mule} +(internationalization) support this will be @code{#x100}, as described +under @code{char-int}, but with @sc{mule} support the range of values is +much bigger, at least 21 bits' worth. If an integer is less than +@var{char-code-limit}, it may still not have an associated character, it +is still necessary to check with the next function, @code{char-int-p}. +@end defvar + @defun char-int-p object This function returns @code{t} if @var{object} is an integer that can be converted into a character. diff -r 5b799fa6d75e -r 15041705c196 src/ChangeLog --- a/src/ChangeLog Sun Mar 15 21:13:23 2015 +0000 +++ b/src/ChangeLog Mon Mar 16 00:09:46 2015 +0000 @@ -1,3 +1,12 @@ +2015-03-15 Aidan Kehoe + + * text.h: Make CHAR_CODE_LIMIT available as a #define. + * text.h (valid_ichar_p): Use it. + * text.c: Make a fixnum Vchar_code_limit available here. + * text.c (non_ascii_valid_ichar_p): Use CHAR_CODE_LIMIT. + * text.c (vars_of_text): Make `char-code-limit' available to + Lisp. + 2015-03-14 Aidan Kehoe * general-slots.h (Qno_character_typed): New error symbol. diff -r 5b799fa6d75e -r 15041705c196 src/text.c --- a/src/text.c Sun Mar 15 21:13:23 2015 +0000 +++ b/src/text.c Mon Mar 16 00:09:46 2015 +0000 @@ -1322,6 +1322,7 @@ Lisp_Object QSin_char_byte_conversion; Lisp_Object QSin_internal_external_conversion; +Fixnum Vchar_code_limit; /************************************************************************/ /* qxestr***() functions */ @@ -4677,7 +4678,7 @@ int f1, f2, f3; /* Must have only lowest 21 bits set */ - if (ch & ~0x1FFFFF) + if (ch & ~(CHAR_CODE_LIMIT - 1)) return 0; f1 = ichar_field1 (ch); @@ -5143,6 +5144,14 @@ build_defer_string ("(in internal-external conversion)"); staticpro (&QSin_internal_external_conversion); + DEFVAR_CONST_INT ("char-code-limit", &Vchar_code_limit /* +Exclusive upper bound on the values return by `char-int'. + +Note that not every fixnum with a value below `char-code-limit' has an +associated character; check with `char-int-p' if necessary. +*/); + Vchar_code_limit = CHAR_CODE_LIMIT; + #ifdef ENABLE_COMPOSITE_CHARS /* #### not dumped properly */ composite_char_row_next = 32; diff -r 5b799fa6d75e -r 15041705c196 src/text.h --- a/src/text.h Sun Mar 15 21:13:23 2015 +0000 +++ b/src/text.h Mon Mar 16 00:09:46 2015 +0000 @@ -121,6 +121,8 @@ #define rep_bytes_by_first_byte(fb) 1 #define byte_ascii_p(byte) 1 #define MAX_ICHAR_LEN 1 +/* Exclusive upper bound on character codes. */ +#define CHAR_CODE_LIMIT 0x100 #else /* MULE */ @@ -212,12 +214,12 @@ #define ichar_ascii_p(c) (!ichar_multibyte_p (c)) -/* Maximum number of bytes per Emacs character when represented as text, in - any format. - */ - +/* Maximum number of bytes per Ichar when represented as text. */ #define MAX_ICHAR_LEN 4 +/* Exclusive upper bound on char codes. */ +#define CHAR_CODE_LIMIT 0x200000 + #endif /* not MULE */ #ifdef MULE @@ -239,7 +241,7 @@ /* This works when CH is negative, and correctly returns non-zero only when CH is in the range [0, 255], inclusive. */ -#define valid_ichar_p(ch) (! (ch & ~0xFF)) +#define valid_ichar_p(ch) (! (ch & ~(CHAR_CODE_LIMIT - 1))) #endif /* not MULE */ diff -r 5b799fa6d75e -r 15041705c196 tests/ChangeLog --- a/tests/ChangeLog Sun Mar 15 21:13:23 2015 +0000 +++ b/tests/ChangeLog Mon Mar 16 00:09:46 2015 +0000 @@ -1,3 +1,9 @@ +2015-03-15 Aidan Kehoe + + * automated/mule-tests.el (test-chars): + Use char-code-limit explicitly here, instead of hardcoding the + corresponding values. + 2015-03-04 Aidan Kehoe * automated/lisp-tests.el: diff -r 5b799fa6d75e -r 15041705c196 tests/automated/mule-tests.el --- a/tests/automated/mule-tests.el Sun Mar 15 21:13:23 2015 +0000 +++ b/tests/automated/mule-tests.el Mon Mar 16 00:09:46 2015 +0000 @@ -46,10 +46,9 @@ If FOR-TEST-HARNESS is specified, a temporary buffer is used, and the Assert macro checks for correctness." - (let ((max (expt 2 (if (featurep 'mule) 21 8))) - (list nil) + (let ((list nil) (i 0)) - (while (< i max) + (while (< i char-code-limit) (and (not for-test-harness) (zerop (% i 1000)) (message "%d" i))