From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: string-to-unibyte in image-jpeg-p Date: Wed, 23 May 2018 15:43:10 -0400 Message-ID: References: <87zi0q3c5b.fsf@gnuvola.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1527104485 27718 195.159.176.226 (23 May 2018 19:41:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 23 May 2018 19:41:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 23 21:41:20 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fLZdQ-00078W-RI for ged-emacs-devel@m.gmane.org; Wed, 23 May 2018 21:41:20 +0200 Original-Received: from localhost ([::1]:35159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLZfX-0003DH-QS for ged-emacs-devel@m.gmane.org; Wed, 23 May 2018 15:43:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLZfO-0003Cz-Cq for emacs-devel@gnu.org; Wed, 23 May 2018 15:43:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLZfL-0000uW-BB for emacs-devel@gnu.org; Wed, 23 May 2018 15:43:22 -0400 Original-Received: from [195.159.176.226] (port=50817 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fLZfL-0000sh-3w for emacs-devel@gnu.org; Wed, 23 May 2018 15:43:19 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fLZdB-0006sC-SA for emacs-devel@gnu.org; Wed, 23 May 2018 21:41:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 39 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:iFwpGNYJtQc/7LfgCP5OGo63GJA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225626 Archived-At: > One of the last ‘string-to-unibyte’ (deprecated for a while) > calls is in ‘image-jpeg-p’: > > (defun image-jpeg-p (data) > "..." > (setq data (ignore-errors (string-to-unibyte data))) > ...) To figure out the best fix, we need to know: - Why are errors ignored? - Why/when is data a multibyte string? > We can simulate ‘string-to-unibyte’ (except for error message > particulars) with ‘FAKE-string-to-unibyte’, which uses the > modern ‘encode-coding-string’: > > (defun FAKE-string-to-unibyte (s) > (let ((tem (encode-coding-string s 'binary))) > (when (string-match-p "\xc2" tem) > (error "badness")) You can't really detect a "non-ascii non-rawbyte input" by looking at the output of encode-coding-string, so this is not the right approach. You could try something like: (unless (unibyte-string-p data) (setq data ;; \x3fffnn encode "raw bytes" in multibyte strings. (if (string-match "[^\x00-\xff\x3fff80-\x3fffff]" data) nil (encode-coding-string data 'binary)))) > - If so, which branch gets the change, ‘emacs-26’ or ‘master’? Definitely not emacs-26 Stefan