From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: How does one find out what file a library has been loaded from? Date: Wed, 20 Jul 2022 20:34:05 +0000 Message-ID: References: <83bktlnuog.fsf@gnu.org> <83sfmxm79z.fsf@gnu.org> <83fsiwncem.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24104"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 20 22:34:55 2022 Return-path: Envelope-to: ged-emacs-devel@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 1oEGPH-00061H-BI for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jul 2022 22:34:55 +0200 Original-Received: from localhost ([::1]:48336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEGPF-00071N-T7 for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jul 2022 16:34:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEGOZ-0006Lq-6M for emacs-devel@gnu.org; Wed, 20 Jul 2022 16:34:11 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:30515 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1oEGOW-0006Yf-RX for emacs-devel@gnu.org; Wed, 20 Jul 2022 16:34:10 -0400 Original-Received: (qmail 78118 invoked by uid 3782); 20 Jul 2022 20:34:06 -0000 Original-Received: from acm.muc.de (p4fe15de5.dip0.t-ipconnect.de [79.225.93.229]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 20 Jul 2022 22:34:06 +0200 Original-Received: (qmail 8065 invoked by uid 1000); 20 Jul 2022 20:34:05 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:292320 Archived-At: Hello, Eli. On Wed, Jul 20, 2022 at 11:47:11 +0000, Alan Mackenzie wrote: > On Tue, Jul 19, 2022 at 22:13:53 +0300, Eli Zaretskii wrote: > > > Date: Tue, 19 Jul 2022 17:07:09 +0000 > > > Cc: emacs-devel@gnu.org > > > From: Alan Mackenzie [ .... ] > If it loads a .eln file, and says it has loaded a .elc file, that is an > untruth. Not a "sort of not quite true", but a blatant untruth. I had > a look at the relevant code in lread.c some while ago. > > But if you are bothered by that detail, I'm okay with having a note > > there regarding *.eln files. (Somehow, I'm not sure you will settle > > for that.) > I will write a patch for the doc string and another for the Elisp manual. > I'm not happy with the state of things, but will probably have to accept > it. [ .... ] Here's a first preliminary effort at amending loading.texi: diff --git a/doc/lispref/loading.texi b/doc/lispref/loading.texi index 54fc16ec9f..32ab08fcfd 100644 --- a/doc/lispref/loading.texi +++ b/doc/lispref/loading.texi @@ -1033,11 +1033,11 @@ Where Defined @cindex where was a symbol defined @defun symbol-file symbol &optional type -This function returns the name of the file that defined @var{symbol}. -If @var{type} is @code{nil}, then any kind of definition is acceptable. -If @var{type} is @code{defun}, @code{defvar}, or @code{defface}, that -specifies function definition, variable definition, or face definition -only. +This function returns a file name associated with the file that +defined @var{symbol} (@pxref{eln files}). If @var{type} is +@code{nil}, then any kind of definition is acceptable. If @var{type} +is @code{defun}, @code{defvar}, or @code{defface}, that specifies +function definition, variable definition, or face definition only. The value is normally an absolute file name. It can also be @code{nil}, if the definition is not associated with any file. If @var{symbol} @@ -1049,14 +1049,15 @@ Where Defined @code{load-history}. @defvar load-history -The value of this variable is an alist that associates the names of -loaded library files with the names of the functions and variables -they defined, as well as the features they provided or required. +The value of this variable is an alist that associates names +associated with loaded library files (@pxref{eln files}) with the +names of the functions and variables the files defined, as well as the +features they provided or required. Each element in this alist describes one loaded library (including libraries that are preloaded at startup). It is a list whose @sc{car} -is the absolute file name of the library (a string). The rest of the -list elements have these forms: +is an absolute file name associated with the library (a string) +(@pxref{eln files}). The rest of the list elements have these forms: @table @code @item @var{var} @@ -1083,9 +1084,30 @@ Where Defined @code{eval-buffer} on a buffer that is not visiting a file. @end defvar - The command @code{eval-region} updates @code{load-history}, but does so -by adding the symbols defined to the element for the file being visited, -rather than replacing that element. @xref{Eval}. +@anchor{eln files} For backwards compatibility, @code{load-history} +stores and @code{symbol-file} returns the name of a notional byte +compiled @file{.elc} file in the same directory as its source file +when the real file loaded from is a natively compiled file elsewhere. +This @file{.elc} file may or may not actually exist. For other files, +their absolute file names are used. If you want to find the actual +file loaded from, and you suspect if may really be a native compiled +file, something like the following should help. You need to know the +name of a function which hasn't been advised, say @var{foo}, defined +in the suspected native compiled file. Then + +@lisp +(let ((foo-fun (symbol-function #'FOO))) + (and foo-fun (subr-native-elisp-p foo-fun) + (native-comp-unit-file (subr-native-comp-unit foo-fun)))) +@end lisp + +@noindent +will return either the name of the native compiled file defining +@var{foo}, or @code{nil} if there is no such file. + +The command @code{eval-region} updates @code{load-history}, but does +so by adding the symbols defined to the element for the file being +visited, rather than replacing that element. @xref{Eval}. @kindex function-history @r{(function symbol property)} In addition to @code{load-history}, every function keeps track of its -- Alan Mackenzie (Nuremberg, Germany).