unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52451: 27.1; jka-compr-write-region produces wrong type argument error
@ 2021-12-12 14:09 Braun Gábor
  2021-12-12 14:28 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Braun Gábor @ 2021-12-12 14:09 UTC (permalink / raw)
  To: 52451

Hi,

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)))
  (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 "/tmp/test.gz")
  (let ((jka-compr-really-do-compress t) (debug-on-error t)) (jka-compr-write-
region "foo" nil "/tmp/test.gz"))
  eval((let ((jka-compr-really-do-compress t) (debug-on-error t)) (jka-compr-
write-region "foo" nil "/tmp/test.gz")) t)
  command-line-1(("-l" "jka-compr.el" "--eval" "(let ((jka-compr-really-do-
compress t) (debug-on-e..."))
  command-line()
  normal-top-level()


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.

Best wishes,

     Gábor Braun


In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo 
version 1.16.0)
 of 2021-03-28, modified by Debian built on x86-conova-01
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Devuan GNU/Linux 4 (chimaera)

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --enable-libsystemd --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/
local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/
site-lisp
 --with-sound=alsa --without-gconf --with-mailutils --build
 x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd
 --with-pop=yes
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/
local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/
site-lisp
 --with-sound=alsa --without-gconf --with-mailutils --with-cairo
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2
 -ffile-prefix-map=/build/emacs-LlFm6W/emacs-27.1+1=. -fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD
JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: hu_HU.UTF-8
  locale-coding-system: utf-8-unix








^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52451: 27.1; jka-compr-write-region produces wrong type argument error
  2021-12-12 14:09 bug#52451: 27.1; jka-compr-write-region produces wrong type argument error Braun Gábor
@ 2021-12-12 14:28 ` Eli Zaretskii
  2021-12-12 18:53   ` Braun Gábor
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-12-12 14:28 UTC (permalink / raw)
  To: Braun Gábor; +Cc: 52451

> From: Braun Gábor <braungb88@gmail.com>
> 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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52451: 27.1; jka-compr-write-region produces wrong type argument error
  2021-12-12 14:28 ` Eli Zaretskii
@ 2021-12-12 18:53   ` Braun Gábor
  2021-12-13 13:02     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Braun Gábor @ 2021-12-12 18:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 52451

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








^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52451: 27.1; jka-compr-write-region produces wrong type argument error
  2021-12-12 18:53   ` Braun Gábor
@ 2021-12-13 13:02     ` Eli Zaretskii
  2021-12-14 13:52       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-12-13 13:02 UTC (permalink / raw)
  To: Braun Gábor; +Cc: 52451

> From: Braun Gábor <braungb88@gmail.com>
> Cc: 52451@debbugs.gnu.org
> Date: Sun, 12 Dec 2021 19:53:38 +0100
> 
> > 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"))'                     

I'm not sure jka-compr is for supporting such use cases.  jka-compr is
a package for transparently visiting and editing compressed files, it
is not supposed to provide methods for writing arbitrary compressed
data to files that didn't exist.

Does anyone else have an opinion about this?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52451: 27.1; jka-compr-write-region produces wrong type argument error
  2021-12-13 13:02     ` Eli Zaretskii
@ 2021-12-14 13:52       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-14 13:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 52451, Braun Gábor

Eli Zaretskii <eliz@gnu.org> writes:

>> $ 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"))'                     
>
> I'm not sure jka-compr is for supporting such use cases.  jka-compr is
> a package for transparently visiting and editing compressed files, it
> is not supposed to provide methods for writing arbitrary compressed
> data to files that didn't exist.
>
> Does anyone else have an opinion about this?

It's certainly an odd use case, but `write-region' is documented to work
that way, so I think we should support it.  (If possible.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-14 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-12 14:09 bug#52451: 27.1; jka-compr-write-region produces wrong type argument error Braun Gábor
2021-12-12 14:28 ` Eli Zaretskii
2021-12-12 18:53   ` Braun Gábor
2021-12-13 13:02     ` Eli Zaretskii
2021-12-14 13:52       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).