unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* string-to-unibyte in image-jpeg-p
@ 2018-05-23 10:21 Thien-Thi Nguyen
  2018-05-23 19:43 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Thien-Thi Nguyen @ 2018-05-23 10:21 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1655 bytes --]


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)))
   ...)

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"))
     tem))

However, the original call ignores errors, so this:

 (setq data (ignore-errors (FAKE-string-to-unibyte data)))

can be simplified to this:

 (setq data (FAKE/NOERROR-string-to-unibyte data))

by defining:

 (defun FAKE/NOERROR-string-to-unibyte (s)
   (let ((tem (encode-coding-string s 'binary)))
     (unless (string-match-p "\xc2" tem)
       tem)))

The last step is to simply inline the definition:

 (setq data (let ((tem (encode-coding-string data 'binary)))
              (unless (string-match-p "\xc2" tem)
                tem)))

My questions are:
- Is my reasoning correct?  In particular, i'd like to confirm
  that the "error" detection via "\xc2" is a valid strategy.
- If so, which branch gets the change, ‘emacs-26’ or ‘master’?
- If not, what am i missing?

-- 
Thien-Thi Nguyen -----------------------------------------------
 (defun responsep (query)
   (pcase (context query)
     (`(technical ,ml) (correctp ml))
     ...))                              748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

end of thread, other threads:[~2018-05-31 15:17 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-23 10:21 string-to-unibyte in image-jpeg-p Thien-Thi Nguyen
2018-05-23 19:43 ` Stefan Monnier
2018-05-23 20:01 ` Eli Zaretskii
2018-05-23 20:17 ` Andreas Schwab
2018-05-23 20:29   ` Stefan Monnier
2018-05-23 20:46     ` Paul Eggert
2018-05-24  8:51       ` Robert Pluim
2018-05-24 15:19         ` Eli Zaretskii
2018-05-24 15:31           ` Robert Pluim
2018-05-24 17:09             ` Eli Zaretskii
2018-05-24 19:51             ` Stefan Monnier
2018-05-25  6:10               ` Eli Zaretskii
2018-05-25 18:01                 ` Stefan Monnier
2018-05-25 19:13                   ` Eli Zaretskii
2018-05-25 20:39                     ` Stefan Monnier
2018-05-26  8:27                       ` Eli Zaretskii
2018-05-31 10:40               ` Robert Pluim
2018-05-31 14:50                 ` Eli Zaretskii
2018-05-31 15:17                   ` Robert Pluim
2018-05-24 15:59           ` Stefan Monnier
2018-05-24 17:00             ` Eli Zaretskii
2018-05-24 19:51               ` Stefan Monnier
2018-05-25  6:10                 ` Eli Zaretskii
2018-05-26 21:02                   ` Stefan Monnier
2018-05-24 16:57           ` Eli Zaretskii

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).