From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#5863: defadvice in byte compiled file does not work Date: Wed, 18 Nov 2020 19:23:05 -0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10047"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Andreas Schwab , 5863@debbugs.gnu.org, Lennart Borgman To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 19 04:24:12 2020 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 1kfaYN-0002Ux-BR for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Nov 2020 04:24:11 +0100 Original-Received: from localhost ([::1]:55370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfaYM-0002dU-DC for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Nov 2020 22:24:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfaYE-0002ci-Ge for bug-gnu-emacs@gnu.org; Wed, 18 Nov 2020 22:24:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54105) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kfaYE-0006aj-7v for bug-gnu-emacs@gnu.org; Wed, 18 Nov 2020 22:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kfaYE-0006NW-2g for bug-gnu-emacs@gnu.org; Wed, 18 Nov 2020 22:24:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 03:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5863 X-GNU-PR-Package: emacs Original-Received: via spool by 5863-submit@debbugs.gnu.org id=B5863.160575619524427 (code B ref 5863); Thu, 19 Nov 2020 03:24:02 +0000 Original-Received: (at 5863) by debbugs.gnu.org; 19 Nov 2020 03:23:15 +0000 Original-Received: from localhost ([127.0.0.1]:37412 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfaXS-0006Lv-PO for submit@debbugs.gnu.org; Wed, 18 Nov 2020 22:23:15 -0500 Original-Received: from mail-ed1-f49.google.com ([209.85.208.49]:39943) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfaXP-0006Le-RM for 5863@debbugs.gnu.org; Wed, 18 Nov 2020 22:23:12 -0500 Original-Received: by mail-ed1-f49.google.com with SMTP id d18so4294633edt.7 for <5863@debbugs.gnu.org>; Wed, 18 Nov 2020 19:23:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc; bh=y/tZ5X/HXJ79Rg9k4HZLCw/uxmYALrRaOIcTGyYuA5c=; b=VcZBli8wk0Sy66lGt+G3SIftZWszKVX7koIOn388Z2XWCTF/92McSzgODq60HdXInl JTKLdcY3rXisJkpAgbyh9WGJAlVz2pgsd5xjDl5Do2Odpx3oG8SdvTGLYJiLMVmpbdwu uq/I9v1Fhg5HxQcjI+Q/mmPhUrJ7t5ZLw7VjZDML0ftEM3Ifdwa0v3J6Yq4CabvIyB4N 13Oh81CidiVACE26GspGwua/2q+S4FES5okx/tz+LlXv+T90ZvqKyUyGtCxo46mBsRpn GxKkR948+aM8r2OI2X8mH5yMlIsH1a6hR88VkNKH6UIiDLYuabHwjMv+8yQMx59Z5FEi KFZg== X-Gm-Message-State: AOAM533/Iiw+ltH52ky81qESCau6UepFPbeqS0qtXLDtQ9krxbS/wIJe fheieV0tTt87noHR/XAcgtSRuR7K8hzTcInz5bA= X-Google-Smtp-Source: ABdhPJyho9zOW7tyGaq6QZQCKakkjDE/CqdtMN7dewo0uBAPX2HdyDh8KO1N6BZFxR4SdbjzbDUxJj3IumMqfyUDlJA= X-Received: by 2002:a05:6402:3089:: with SMTP id de9mr29570804edb.100.1605756186049; Wed, 18 Nov 2020 19:23:06 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 18 Nov 2020 19:23:05 -0800 In-Reply-To: (Stefan Monnier's message of "Thu, 08 Apr 2010 22:06:10 -0400") 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:193682 Archived-At: Stefan Monnier writes: >> The info page I pointed to says that defadvice should work for >> primitives called from lisp code. And that is what does not work for >> me here. > > For such uses, there are several categories of functions: > - functions that have their own byte-code (things like widen, car, cdr, ...). > - functions that are implemented in C but don't have their own > byte-code. > - other functions. > > Pieces of advice on the first kind of functions only work for > calls from interpreted Lisp code. > Pieces of advice on the second kind of functions only work for > calls from Lisp code (both interpreted and byte-compiled). BTW, it seems like advising primitives will work once we get native-comp merged: The result of this procedure is that each newly activated function will use the trampoline in place of the original primitive and the trampoline will execute the call going through funcall making the advice effective! This works so well that in-fact now is even possible to advice effectively what wasn't effective in byte-code (ex the + function). But hey, don't try this a home! https://akrl.sdf.org/gccemacs.html#org3b7398e I'm not sure how this would affect the status of this bug, if at all. Perhaps we could expand the description of why advising primitives is a bad idea in the Info node `(elisp) Advising Named Functions': It is possible to advise a primitive (*note What Is a Function::), but one should typically _not_ do so, for two reasons. Firstly, some primitives are used by the advice mechanism, and advising them could cause an infinite recursion. Secondly, many primitives are called directly from C, and such calls ignore advice; hence, one ends up in a confusing situation where some calls (occurring from Lisp code) obey the advice and other calls (from C code) do not. We could perhaps simply say that advice on primitives with their own bytecode will be ineffective if the code is run byte-compiled.