Subject: Re: bug#45342: 28.0.50; Native compiled function returns raw bytes, not string

From: Alexander Miller <[email-masked]>
Date: Mon, 21 Dec 2020 14:45:04 +0100

Hi Andrea,

I can confirm that 72c1a41573 fixes the issue.

However there's still another problem that I thought was related, but
apparently it isn't. (I can open another bug for it if you like).

It looks like eval-when-compile is not working as expected. I am also
using small xpms for my modeline that are defined like this:

(defconst selected-window-xpm
    (eval-when-compile (doom-modeline--make-xpm 'modeline-xpm-face 5 30)))

The generating code looks like this:

(defun doom-modeline--make-xpm (face width height)
   "Create an XPM bitmap via FACE, WIDTH and HEIGHT. Inspired by 
`powerline''s `pl/make-xpm'."
   (when (and (display-graphic-p)
              (image-type-available-p 'xpm))
     (propertize
      " " 'display
      (let ((data (make-list height (make-list width 1)))
            (color (or (face-background face nil t) "None")))
        (ignore-errors
          (create-image
           (concat
            (format
             "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 
1\",\n\". c %s\",\n\"  c %s\","
             (length (car data)) (length data) color color)
            (apply #'concat
                   (cl-loop with idx = 0
                            with len = (length data)
                            for dl in data
                            do (cl-incf idx)
                            collect
                            (concat
                             "\""
                             (cl-loop for d in dl
                                      if (= d 0) collect (string-to-char 
" ")
                                      else collect (string-to-char "."))
                             (if (eq idx len) "\"};" "\",\n")))))
   'xpm t :ascent 'center))))))

When native-compiling I only get nil, with byte-compiling it works
without problems. The correct value should look like this:

#(" " 0 1
(display
(image :type xpm :data "/* XPM */
static char * percent[] = {
\"5 30 2 1\",
\". c #559955\",
\" c #559955\",\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\",
\".....\"};" :scale 1 :ascent center)))