Subject: bug#52451: 27.1; jka-compr-write-region produces wrong type argument error

From: Braun Gábor <[email-masked]>
Date: Sun, 12 Dec 2021 19:53:38 +0100

Hi Eli,

> When will write-region invoke jka-commpr-write-region if it is called
> with the first argument a string?

OK, here is a recipe.

$ echo FOO >test
$ gzip test
$ emacs -Q --batch -l jka-compr.el --eval '(let ((debug-on-error t)) (find-file 
"test.gz") (write-region "foo" nil "foo.gz"))'                     
uncompressing jka-compr.el.gz...
uncompressing jka-compr.el.gz...done
uncompressing test.gz...
uncompressing test.gz...done
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  -(nil "foo")
  (= (- end start) (buffer-size))
  (or (null start) (= (- end start) (buffer-size)))
  (and jka-compr-really-do-compress (or (null start) (= (- end start) (buffer-
size))))
  (if (and jka-compr-really-do-compress (or (null start) (= (- end start) 
(buffer-size)))) (setq magic nil))
  (let* ((filename (expand-file-name file)) (visit-file (if (stringp visit) 
(expand-file-name visit) filename)) (info (jka-compr-get-compression-info visit-
file)) (magic (and info (jka-compr-info-file-magic-bytes info)))) (if (and jka-
compr-really-do-compress (or (null start) (= (- end start) (buffer-size)))) 
(setq magic nil)) (if (and info (not (and magic (equal (if (stringp start) 
(substring start 0 ...) (let* ... ...)) magic)))) (let ((can-append (jka-
compr-info-can-append info)) (compress-program (jka-compr-info-compress-
program info)) (compress-message (jka-compr-info-compress-message info)) 
(compress-args (jka-compr-info-compress-args info)) (base-name (file-name-
nondirectory visit-file)) temp-file temp-buffer (coding-system-used last-coding-
system-used)) (or compress-program (error "No compression program defined")) 
(setq temp-buffer (get-buffer-create " *jka-compr-wr-temp*")) (save-current-
buffer (set-buffer temp-buffer) (widen) (erase-buffer)) (if (and append (not can-
append) (file-exists-p filename)) (let* ((local-copy (file-local-copy filename)) 
(local-file (or local-copy filename))) (setq temp-file local-file)) (setq temp-file 
(jka-compr-make-temp-name))) (and compress-message jka-compr-verbose (message 
"%s %s..." compress-message base-name)) (jka-compr-run-real-handler 'write-
region (list start end temp-file t 'dont)) (setq coding-system-used last-
coding-system-used) (let ((coding-system-for-read 'no-conversion)) (jka-compr-
call-process compress-program (concat compress-message " " base-name) temp-file 
temp-buffer nil compress-args)) (save-current-buffer (set-buffer temp-buffer) (let 
((coding-system-for-write 'no-conversion)) (jka-compr-run-real-handler 'write-
region (list (point-min) (point-max) filename (and append can-append) 'dont 
lockname mustbenew)) (erase-buffer))) (delete-file temp-file) (and compress-
message jka-compr-verbose (message "%s %s...done" compress-message base-
name)) (cond ((eq visit t) (setq buffer-file-name filename) (setq jka-compr-
really-do-compress t) (set-visited-file-modtime)) ((stringp visit) (setq buffer-
file-name visit) (let ((buffer-file-name filename)) (set-visited-file-modtime)))) 
(and (or (eq visit t) (eq visit nil) (stringp visit)) (message "Wrote %s" 
visit-file)) (setq last-coding-system-used coding-system-used) nil) (jka-compr-
run-real-handler 'write-region (list start end filename append visit lockname 
mustbenew))))
  jka-compr-write-region("foo" nil "/dev/shm/foo.gz" nil nil "/dev/shm/foo.gz" 
nil)
  apply(jka-compr-write-region ("foo" nil "/dev/shm/foo.gz" nil nil "/dev/shm/
foo.gz" nil))
  (if (and jka-op (not jka-compr-inhibit)) (apply jka-op args) (jka-compr-run-
real-handler operation args))
  (let ((jka-op (get operation 'jka-compr))) (if (and jka-op (not jka-compr-
inhibit)) (apply jka-op args) (jka-compr-run-real-handler operation args)))
  (progn (let ((jka-op (get operation 'jka-compr))) (if (and jka-op (not jka-
compr-inhibit)) (apply jka-op args) (jka-compr-run-real-handler operation 
args))))
  (unwind-protect (progn (let ((jka-op (get operation 'jka-compr))) (if (and 
jka-op (not jka-compr-inhibit)) (apply jka-op args) (jka-compr-run-real-
handler operation args)))) (set-match-data save-match-data-internal 
'evaporate))
  (let ((save-match-data-internal (match-data))) (unwind-protect (progn (let 
((jka-op (get operation 'jka-compr))) (if (and jka-op (not jka-compr-inhibit)) 
(apply jka-op args) (jka-compr-run-real-handler operation args)))) (set-match-
data save-match-data-internal 'evaporate)))
  jka-compr-handler(write-region "foo" nil "/dev/shm/foo.gz" nil nil "/dev/
shm/foo.gz" nil)
  write-region("foo" nil "foo.gz")
  (let ((debug-on-error t)) (find-file "test.gz") (write-region "foo" nil 
"foo.gz"))
  eval((let ((debug-on-error t)) (find-file "test.gz") (write-region "foo" nil 
"foo.gz")) t)
  command-line-1(("-l" "jka-compr.el" "--eval" "(let ((debug-on-error t)) 
(find-file \"test.gz\") (w..."))
  command-line()
  normal-top-level()

Best wishes,

	Gábor