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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 12 Dec 2021 16:28:09 +0200

> From: Braun Gábor <[email-masked]>
> Date: Sun, 12 Dec 2021 15:09:08 +0100
> 
> Start Emacs via the command
> 
>  emacs -Q --batch -l jka-compr.el --eval '(let ((jka-compr-really-do-compress 
> t) (debug-on-error t)) (jka-compr-write-region "foo" nil "/tmp/test.gz"))'        
> 
> 
> This should run without any error.
> Instead the following appears on the terminal:
> 
> 
> uncompressing jka-compr.el.gz...
> uncompressing jka-compr.el.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)))

Why did you assume that jka-compr-write-region supports compressing a
string, not just a portion of a buffer?  I don't see it documented
anywhere.

> My guess is that the debugger refers to the following snippet
> in function `jka-commpr-write-region':
> 
>     ;; If we uncompressed this file when visiting it,
>     ;; then recompress it when writing it
>     ;; even if the contents look compressed already.
>     (if (and jka-compr-really-do-compress
>              (or (null start)
>                  (= (- end start) (buffer-size))))
> 	(setq magic nil))
> 
> This seems to falsely assume that START is nil or a buffer position,
> even though the docstring of `write-region' explicitly allows it to be a
> string.

When will write-region invoke jka-commpr-write-region if it is called
with the first argument a string?  That's the use case we should
discuss, not the direct invocation of jka-commpr-write-region in your
recipe, I think.