[Bug: 21.5-b16] Wrong return value of encode/decode-coding-region

Lutz Euler lutz.euler at freenet.de
Mon Mar 8 15:47:31 EST 2004


================================================================
Dear Bug Team!

The return values of the functions "encode-coding-region" and
"decode-coding-region" are documented to return the length of the
encoded resp. the decoded text. Thus I didn't expect the following:

Start a (mule) xemacs with "xemacs -q" and encode the initial scratch
message with
  M-: (encode-coding-region (point-min) (point-max) 'utf-8)
The return value shown in the minibuffer is 0 but should be 394.
The same happens with decode-coding-region.

The reason is that the function "encode_decode_coding_region" in
"src/file-coding.c" measures the length of the output before flushing
the streams. Also it might be wrong to use the starting position of
"instream" as opposed to "lb_outstream" for this purpose -- of this
I am not sure.

Anyway, I suggest the following change that fixes the bug for me.
At the beginning of the last block of the function:

Old:
    Charcount retlen =
      lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
    Lstream_close (istr);
    Lstream_close (ostr);

New:
    Charcount retlen;

    /* Close the streams to flush through the data. Note that closing
       OSTR closes the complete chain from the front to the end. */
    Lstream_close (istr);
    Lstream_close (ostr);
    /* Only now can we calculate the length of the output for the
       return value. */ 
    retlen = lisp_buffer_stream_startpos (XLSTREAM (lb_outstream)) - b;

Before sending this in as a patch I wanted to make sure that this is
a safe way to deal with lstreams. Is it guaranteed that calling
"lisp_buffer_stream_startpos" on a closed lisp_buffer_output_stream
returns the correct value?

If not, I can only think of a more complicated fix, namely: close all
streams except lb_outstream in order, flush lb_outstream, hope that the
warning from lstream.c (the comment at the definition of Lstream_close):
   Note that, even if all data has already been flushed out, the act of
   closing a stream may generate more data -- for example, if the stream
   implements some sort of conversion, such as gzip, there may be special
   "end-data" that need to be written out when the file is closed.
does not apply and will never apply to lisp_buffer_output_streams,
calculate retlen the same way as above and then close lb_outstream.

Yours,

Lutz

================================================================

System Info to help track down your bug:
---------------------------------------

uname -a: Linux linux 2.4.21-201-default #1 Wed Feb 18 19:08:21 UTC 2004 x86_64 x86_64 x86_64 GNU/Linux

./configure  '--site-libraries=/lib64:/usr/lib64:/usr/X11R6/lib64' '--with-mule'


XEmacs 21.5-b16 "celeriac"  configured for `x86_64-unknown-linux'.


Compilation / Installation:
  Source code location:              /home/lutz/xemacs-21.5.16
  Installation prefix:               /usr/local
  Additional libraries:              /lib64 /usr/lib64 /usr/X11R6/lib64
  Operating system description file: `s/linux.h'
  Not using any machine description file
  Compiler:                          gcc -Wall -Wno-switch -Winline -Wmissing-prototypes -Wsign-compare -Wundef -Wstrict-prototypes -Wpacked -Wshadow -Wmissing-declarations -g -O3
  Relocating allocator for buffers:  no
  GNU version of malloc:             yes
    - Using Doug Lea's new malloc from the GNU C Library.

Window System:
  Compiling in support for the X window system:
    - X Windows headers location:                 /usr/X11/include
    - X Windows libraries location:               /usr/X11/lib
    - Handling WM_COMMAND properly.
  Using Lucid menubars.
  Using Lucid scrollbars.

TTY:
  Compiling in support for ncurses.
  Compiling in support for GPM (General Purpose Mouse).

Images:
  Compiling in support for GIF  images (builtin).
  Compiling in support for XPM  images.
  Compiling in support for PNG  images.
  Compiling in support for JPEG images.
  Compiling in support for TIFF images.

Sound:
  Compiling in support for sound (native).

Databases:

Internationalization:
  Compiling in support for Mule (multi-lingual Emacs).
  Compiling in support for XIM (X11R5+ I18N input method).
    - Using raw Xlib to provide XIM support.

Mail:
  Compiling in support for "dot-locking" mail spool file locking method.

Other Features:
  Inhibiting IPv6 canonicalization at startup.
  Compiling in support for dynamic shared object modules.
  Using the new portable dumper.
  Compiling in support for extra debugging code.
  WARNING: ---------------------------------------------------------
  WARNING: Compiling in support for runtime error checking.
  WARNING: XEmacs will run noticeably more slowly as a result.
  WARNING: Error checking is on by default for XEmacs beta releases.
  WARNING: ---------------------------------------------------------



Load-Path Lisp Shadows:
----------------------
(/usr/local/lib/xemacs/mule-packages/lisp/mule-base/ethio-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/ethio-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-base/china-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/china-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-base/japan-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/japan-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-base/korea-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/korea-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-base/cyril-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/cyril-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-base/viet-util
/usr/local/lib/xemacs-21.5-b16/lisp/mule/viet-util
/usr/local/lib/xemacs/mule-packages/lisp/mule-ucs/unicode
/usr/local/lib/xemacs-21.5-b16/lisp/unicode
/usr/local/lib/xemacs/xemacs-packages/lisp/build/build-report
/usr/local/lib/xemacs-21.5-b16/lisp/build-report)


Installed XEmacs Packages:
-------------------------
(zenirc ver: 1.15 upstream: 2.112)
(xslt-process ver: 1.11 upstream: regular)
(xslide ver: 1.09 upstream: 0.2.2)
(xemacs-devel ver: 1.61 upstream: No-Upstream-Ver)
(xemacs-base ver: 1.84 upstream: No-Upstream-Ver)
(x-symbol ver: 1.09 upstream: 4.5.1)
(w3 ver: 1.29 upstream: 4.0pre47)
(vm ver: 7.18 upstream: regular)
(viper ver: 1.37 upstream: 3.09)
(view-process ver: 1.13 upstream: 2.4)
(vhdl ver: 1.18 upstream: 3.31.20)
(vc-cc ver: 1.22 upstream: No-Upstream-Ver)
(vc ver: 1.38 upstream: No-Upstream-Ver)
(tramp ver: 1.17 upstream: 2.0.35)
(tpu ver: 1.14 upstream: 4.2X)
(tooltalk ver: 1.15 upstream: No-Upstream-Ver)
(tm ver: 1.37 upstream: No-Upstream-Ver)
(time ver: 1.14 upstream: 1.17)
(textools ver: 1.15 upstream: No-Upstream-Ver)
(text-modes ver: 1.73 upstream: No-Upstream-Ver)
(texinfo ver: 1.25 upstream: No-Upstream-Ver)
(supercite ver: 1.2 upstream: 3.55x3)
(strokes ver: 1.1 upstream: No-Upstream-Ver)
(speedbar ver: 1.27 upstream: 0.14beta4)
(sounds-wav ver: 1.12 upstream: No-Upstream-Ver)
(sounds-au ver: 1.12 upstream: No-Upstream-Ver)
(sml-mode ver: 0.11 upstream: 3.9.5)
(slider ver: 1.15 upstream: 0.3x1)
(sieve ver: 1.15 upstream: No-Upstream-Ver)
(sh-script ver: 1.18 upstream: 2.0e)
(sgml ver: 1.11 upstream: No-Upstream-Ver)
(semantic ver: 1.18 upstream: 1.4.2)
(scheme ver: 1.14 upstream: No-Upstream-Ver)
(sasl ver: 1.14 upstream: 1.14.4)
(ruby-modes ver: 1.02 upstream: 1.6.8)
(rmail ver: 1.14 upstream: No-Upstream-Ver)
(riece ver: 1.14 upstream: 0.1.7)
(reftex ver: 1.33 upstream: 4.21)
(python-modes ver: 1.03 upstream: No-Upstream-Ver)
(psgml-dtds ver: 1.03 upstream: No-Upstream-Ver)
(psgml ver: 1.42 upstream: 1.3.1)
(ps-print ver: 1.09 upstream: 6.5.6)
(prog-modes ver: 1.94 upstream: No-Upstream-Ver)
(pgg ver: 1.04 upstream: 0.1)
(perl-modes ver: 1.05 upstream: No-Upstream-Ver)
(pcomplete ver: 1.03 upstream: 1.1.6)
(pcl-cvs ver: 1.65 upstream: R-2_9_9)
(pc ver: 1.26 upstream: No-Upstream-Ver)
(os-utils ver: 1.35 upstream: No-Upstream-Ver)
(oo-browser ver: 1.04 upstream: 4.08)
(ocaml ver: 0.05 upstream: 3.06)
(net-utils ver: 1.38 upstream: N/A)
(mmm-mode ver: 1.01 upstream: 0.4.7)
(misc-games ver: 1.18 upstream: No-Upstream-Ver)
(mine ver: 1.16 upstream: 1.9)
(mh-e ver: 1.28 upstream: 7.4.2)
(mew ver: 1.18 upstream: 1.94.2)
(mailcrypt ver: 2.14 upstream: 3.5.8)
(mail-lib ver: 1.64 upstream: No-Upstream-Ver)
(liece ver: 1.13 upstream: 1.4.9)
(jde ver: 1.46 upstream: regular)
(ispell ver: 1.29 upstream: 3.6)
(ilisp ver: 1.33 upstream: 5.12.0)
(igrep ver: 1.12 upstream: 2.95)
(idlwave ver: 1.31 upstream: 5.1)
(ibuffer ver: 1.09 upstream: No-Upstream-Ver)
(hyperbole ver: 1.15 upstream: 4.18)
(hm--html-menus ver: 1.23 upstream: 5.9)
(haskell-mode ver: 1.06 upstream: 1.44)
(gnus ver: 1.79 upstream: 5.10.6)
(gnats ver: 1.16 upstream: 3.101)
(general-docs ver: 1.01 upstream: No-Upstream-Ver)
(games ver: 1.15 upstream: 1.04)
(fsf-compat ver: 1.14 upstream: No-Upstream-Ver)
(frame-icon ver: 1.11 upstream: No-Upstream-Ver)
(fortran-modes ver: 1.03 upstream: No-Upstream-Ver)
(forms ver: 1.15 upstream: 2.37)
(footnote ver: 1.16 upstream: 0.18x)
(eudc ver: 1.39 upstream: 1.32)
(eterm ver: 1.15 upstream: No-Upstream-Ver)
(ess ver: 1.07 upstream: 5.1.21)
(eshell ver: 1.06 upstream: 2.4.1)
(erc ver: 0.05 upstream: Version 4.0 Revision: 1.608)
(emerge ver: 1.11 upstream: No-Upstream-Ver)
(elib ver: 1.11 upstream: 1.0)
(eieio ver: 1.05 upstream: 0.17)
(efs ver: 1.32 upstream: 1.22)
(edt ver: 1.13 upstream: No-Upstream-Ver)
(edit-utils ver: 2.11 upstream: No-Upstream-Ver)
(ediff ver: 1.49 upstream: 2.75)
(edebug ver: 1.2 upstream: No-Upstream-Ver)
(ecrypto ver: 0.16 upstream: 2.0)
(ecb ver: 1.14 upstream: 2.11)
(docbookide ver: 0.07000000000000001 upstream: 0.1)
(dired ver: 1.15 upstream: 7.11)
(dictionary ver: 1.12 upstream: regular)
(debug ver: 1.17 upstream: No-Upstream-Ver)
(crisp ver: 1.14 upstream: 1.34)
(cookie ver: 1.15 upstream: No-Upstream-Ver)
(clearcase ver: 1.08 upstream: No-Upstream-Ver)
(cc-mode ver: 1.42 upstream: 5.30.8)
(calendar ver: 1.23 upstream: No-Upstream-Ver)
(calc ver: 1.24 upstream: 2.02fX3)
(c-support ver: 1.19 upstream: No-Upstream-Ver)
(build ver: 1.14 upstream: 2.02)
(bbdb ver: 1.24 upstream: 2.34)
(auctex ver: 1.36 upstream: 11.13)
(apel ver: 1.27 upstream: 10.2)
(ada ver: 1.14 upstream: 2.27)
(skk ver: 1.23 upstream: regular)
(mule-ucs ver: 1.05 upstream: 0.84)
(mule-base ver: 1.46 upstream: No-Upstream-Ver)
(lookup ver: 1.14 upstream: 1.0)
(locale ver: 1.21 upstream: No-Upstream-Ver)
(leim ver: 1.22 upstream: No-Upstream-Ver)
(latin-unity ver: 1.09 upstream: 1.09)
(egg-its ver: 1.27 upstream: No-Upstream-Ver)
(edict ver: 1.16 upstream: 0.9.9)



Installed Modules:
-----------------


Features:
--------

(mail-abbrevs xemacsbug shadow sendmail rfc822 cal-iso calendar x-compose
vm-mime vm-autoload vm-vars highlight-headers vm-startup vm-version vm
latin-unity-tables latin-unity-latin10 latin-unity-latin9 latin-unity-latin8
latin-unity-latin7 latin-unity-vars latin-unity info paren mic-paren timer
cus-face mwheel completer filladapt advice advice-preload uniquify iso-syntax
scroll-in-place zenirc-autoloads xslt-process-autoloads xslide-autoloads
xemacs-devel-autoloads xemacs-base-autoloads x-symbol-autoloads w3-autoloads
vm-autoloads viper-autoloads view-process-autoloads vhdl-autoloads
vc-cc-autoloads vc-autoloads tramp-autoloads tpu-autoloads tooltalk-autoloads
tm-autoloads time-autoloads textools-autoloads text-modes-autoloads
texinfo-autoloads supercite-autoloads strokes-autoloads speedbar-autoloads
sounds-wav-autoloads sounds-au-autoloads sml-mode-autoloads slider-autoloads
sieve-autoloads sh-script-autoloads sgml-autoloads semantic-autoloads
scheme-autoloads sasl-autoloads ruby-modes-autoloads rmail-autoloads
riece-autoloads reftex-autoloads python-modes-autoloads psgml-dtds-autoloads
psgml-autoloads ps-print-autoloads prog-modes-autoloads pgg-autoloads
perl-modes-autoloads pcomplete-autoloads pcl-cvs-autoloads pc-autoloads
os-utils-autoloads oo-browser-autoloads ocaml-autoloads net-utils-autoloads
mmm-mode-autoloads misc-games-autoloads mine-autoloads mh-e-autoloads
mew-autoloads mailcrypt-autoloads mail-lib-autoloads liece-autoloads
jde-autoloads ispell-autoloads ilisp-autoloads igrep-autoloads
idlwave-autoloads ibuffer-autoloads hyperbole-autoloads
hm--html-menus-autoloads haskell-mode-autoloads gnus-autoloads gnats-autoloads
general-docs-autoloads games-autoloads fsf-compat-autoloads
frame-icon-autoloads fortran-modes-autoloads forms-autoloads
footnote-autoloads eudc-autoloads eterm-autoloads ess-autoloads
eshell-autoloads erc-autoloads emerge-autoloads elib-autoloads eieio-autoloads
efs-autoloads edt-autoloads edit-utils-autoloads ediff-autoloads
edebug-autoloads ecrypto-autoloads ecb-autoloads docbookide-autoloads
dired-autoloads dictionary-autoloads debug-autoloads crisp-autoloads
cookie-autoloads clearcase-autoloads cc-mode-autoloads calendar-autoloads
calc-autoloads c-support-autoloads build-autoloads bbdb-autoloads
auctex-autoloads apel-autoloads ada-autoloads skk-autoloads mule-ucs-autoloads
mule-base-autoloads lookup-autoloads locale-autoloads leim-autoloads
latin-unity-autoloads egg-its-autoloads edict-autoloads modules-autoloads
mule-autoloads auto-autoloads loadhist rsz-minibuf auto-show fontl-hooks
x-iso8859-1 tibetan lao devanagari indian slovenian czech romanian ccl
code-cmds gutter-items menubar-items x-menubar mode-motion mouse behavior
itimer auto-save lisp-mode easymenu iso8859-1 page buff-menu lib-complete
cus-file derived newcomment env text-props frame obsolete cus-start custom
widget cl-extra mini-cl cl cl-19 packages backquote unicode lucid-scrollbars
cut-buffer lucid-menubars x c-balloon-help tty-frames tty toolbar native-sound
scrollbar unix-processes multicast network-streams subprocesses modules
menu-accelerator-support menubar md5 xemacs xim mule gutter tiff png gif jpeg
xpm xbm lisp-float-type file-coding linux devices window-system base64)


Recent keystrokes:
-----------------

M-x r e p o r t - x e m a c s - b u g RET


Recent messages (most recent first):
-----------------------------------

Parsing /home/lutz/.mailrc... done
Parsing /home/lutz/.mailrc...
Loading xemacsbug...done
Loading xemacsbug...
Loading x-compose...done
Loading x-compose...
Loading latin-unity...done
Loading latin-unity...
Loading cus-face...done
Loading cus-face...
Loading mwheel...done
Loading mwheel...
Loading completer...done
Loading completer...
Loading advice...done
Loading advice...
Loading dialog...done
Loading dialog...





More information about the XEmacs-Beta mailing list