all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Question about native compilation (bug?)
Date: Wed, 26 Jul 2023 21:32:52 +0000	[thread overview]
Message-ID: <SJ0PR10MB54885FB68D442A8AE4AC2ADDF300A@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)

I don't have native compilation for my laptop, but I received a bug report from a user of one of my libraries, and I get the feeling that native compilation (which this user has) is interfering and perhaps bugged.

1. My code, when loaded, saves the original definitions of some functions, such as `read-buffer', by creating a `defalias' for each of them, such as this one:

(defalias 'ORIG-read-buffer
          (symbol-function 'read-buffer)

2. I define a global minor mode that, when turned on, redefines those saved functions, such as `read-buffer', using `fset', to using definitions appropriate to the minor mode.  

3. When the minor mode is turned off I reset those function definitions to the saved (`defalias'ed) versions, using `fset'.

(I do this dance because I want the library to work properly also with older Emacs versions.  No comments, please, about its fragility or other weaknesses.)
___

This is the problem, reported in Emacs 28.2 with native compilation:

Emacs 28 added an additional optional arg to function `read-buffer' (which is defined in C).  My substitute version of `read-buffer', which is used when my minor mode is turned on, has only 1 required arg and 2 optional, not 1 required and 3 optional.

Obviously, for any code that will try to pass 4 args, I need to update my code to accommodate the 4th arg.  I haven't done that yet.

But my question is about code that ostensibly passes 3 or fewer args.  An error is nevertheless raised, saying that 4 args were passed and only 3 were allowed.  The standard code, whose vanilla source definition (in `window.el') passes only 3 args, in actuality, at runtime, passes 4 args, the 4th one being explicitly nil.

Recipe: the minor mode is turned on, and `C-x 5 b' is tried.  An error is raised:

Debugger entered--Lisp error: (wrong-number-of-arguments #<subr my-read-buffer> 4)
  read-buffer("Switch to buffer in other frame: " #<buffer foo> confirm-after-completion nil)
  read-buffer-to-switch("Switch to buffer in other frame: ")
  byte-code("\300\301!C\207" [read-buffer-to-switch "Switch to buffer in other frame: "] 2)
  call-interactively(switch-to-buffer-other-frame nil nil)
  command-execute(switch-to-buffer-other-frame)

I wouldn't have a clue to what is going on here from that backtrace, since function `my-read-buffer' accepts 3 args and the source code for `read-buffer-to-switch' passes 3 args.

I got a glue (I think), from this: For the reporting user `C-h k C-x 5 b' says this:

C-x 5 b runs the command switch-to-buffer-other-frame (found in global-map), which is an interactive native-compiled Lisp function in '/var/lib/snapd/snap/emacs/2031/usr/share/emacs/28.2/lisp/window.el'.

It's that "native-compiled" that makes me wonder.  If the user loads the Lisp source file, `window.el', there's no problem.  But it looks kinda like native compilation has "baked-in" the call to `read-buffer', passing an explicit 4th arg, nil, instead of passing only the 3 args that the source code says to pass.

Passing 4 args, the last of which is nil, isn't the same thing as passing 3 args, but it looks like native compilation takes a shortcut, assuming that it's the same thing.

Is this a native-compilation bug?  Is it some other Emacs bug?  Or is this just the way things are going to be from now on - "situation normale, rien à signaler"?

Let me know, if my guesses are near the target, or if I'm missing something.



             reply	other threads:[~2023-07-26 21:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26 21:32 Drew Adams [this message]
2023-07-27  4:45 ` Question about native compilation (bug?) Tassilo Horn
2023-07-27 15:25   ` [External] : " Drew Adams
2023-07-27  9:53 ` Andrea Corallo
2023-07-27 14:37   ` [External] : " Drew Adams
2023-07-27 16:15     ` Andrea Corallo
2023-07-27 17:05       ` Drew Adams
2023-07-27 17:51         ` Andrea Corallo
2023-07-27 18:14           ` Drew Adams
2023-07-27 18:38             ` Andrea Corallo
2023-07-27 19:11             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB54885FB68D442A8AE4AC2ADDF300A@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.