From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#46933: Possible bugs in filepos-to-bufferpos / bufferpos-to-filepos Date: Sat, 27 Mar 2021 14:24:58 +0000 Message-ID: References: <874kgxtatr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8863"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46933@debbugs.gnu.org To: handa Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 27 15:26:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lQ9tB-0002C7-Fc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Mar 2021 15:26:09 +0100 Original-Received: from localhost ([::1]:59554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQ9tA-00075F-Dc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Mar 2021 10:26:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQ9t4-000756-Ld for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 10:26:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lQ9t4-0006hY-6j for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 10:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lQ9t4-0003uc-3K for bug-gnu-emacs@gnu.org; Sat, 27 Mar 2021 10:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Mar 2021 14:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46933 X-GNU-PR-Package: emacs Original-Received: via spool by 46933-submit@debbugs.gnu.org id=B46933.161685510514969 (code B ref 46933); Sat, 27 Mar 2021 14:26:02 +0000 Original-Received: (at 46933) by debbugs.gnu.org; 27 Mar 2021 14:25:05 +0000 Original-Received: from localhost ([127.0.0.1]:44724 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQ9s9-0003tN-DX for submit@debbugs.gnu.org; Sat, 27 Mar 2021 10:25:05 -0400 Original-Received: from heytings.org ([95.142.160.155]:43704) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQ9s5-0003ss-BL for 46933@debbugs.gnu.org; Sat, 27 Mar 2021 10:25:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20210101; t=1616855099; bh=D21hc5ey1cJdXCDIiGDYS+sgbISsaxa7h/rvb9PUZ+g=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=PM1FDb9I1RH9Ahkltxa0Ju5zzdfMpi+R24z0FqFvPOR2+g6+QzsFL1jWQUBTaDpsk CVxEv4jl9U4iSB/YeKsHf3O7LgYi9N22pUd6dgRao8OA7fD9Jfuc6eyZWmi97k8UHY zm9GRFyezWKVf6NfME728e249pfYv/S6qsKVeTIr+++s4b72FYWzhYwPq9UCmiOzt2 eh62H3a+4rJ35N1Gyq13o6V9kJ4951WKfBc0QrW5RxX0MEdk6OGQjhey+RN8cu5Bgi awWTWxWzzgpuwC86gYvk/+WyJy4FR8XycOXzOPsGc7G0D1W7NOAddiDGK2OtXvhrAe m+Vibf4f/XMiQ== In-Reply-To: <874kgxtatr.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:203128 Archived-At: >> Kenichi, why are these 6 bytes inserted by encode-coding-region, but >> not when we encode the same text as part of saving the buffer to its >> file? And why does it happen near the end of the text, between those 2 >> particular letters? > > There surely exists a bug. Could you please try the attached patch? > > The reason why that bug did not happen on file writing is that the code > in write_region calls encoding routine repeatedly without > CODING_MODE_LAST_BLOCK flag, and only in the case that flushing is > required (e.g. the case of iso-2022-jp), just for flushing, it calls > enoding routine again with CODING_MODE_LAST_BLOCK flag. In that case, > carryover does not happen in encode_coding (). > Thank you. I tried the patch, and it seems to fix the bufferpos-to-filepos bug, but not the filepos-to-bufferpos one. On the example file, (bufferpos-to-filepos (- (point-max) POS) 'exact) gives the expected results: POS = 0: 2997 POS = 1: 2995 POS = 2: 2993 POS = 3 (IDEOGRAPHIC FULL STOP): 2991 POS = 4 (HIRAGANA LETTER RU): 2989 But (goto-char (filepos-to-bufferpos POS 'exact)) gives: POS = 2985, 2986: last but one visible character (HIRAGANA LETTER RU) POS = 2987, 2988: last visible character (IDEOGRAPHIC FULL STOP) POS = 2989, 2990: first CRLF POS = 2991: second CRLF POS = 2992: point-max POS = 2993: first CRLF POS = 2994, 2995: second CRLF POS >= 2996: point-max where I would have expected: POS = 2989, 2990: last but one visible character (HIRAGANA LETTER RU) POS = 2991, 2992: last visible character (IDEOGRAPHIC FULL STOP) POS = 2993, 2994: first CRLF POS = 2995, 2996: second CRLF POS >= 2997: point-max