* [PATCH] Autoload and absolute paths.. Maybe after all
@ 2017-02-13 11:56 ` Sebastian Gniazdowski
2017-02-13 15:19 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2017-02-13 11:56 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 2907 bytes --]
Hello,
following doesn't work:
# mkdir ~/myfunctions
# mv /usr/local/share/zsh/5.3.1-dev-0/functions/calendar* ~/myfunctions
# autoload ~/myfunctions/calendar
# calendar
calendar:36: calendar_scandate: function definition file not found
called this a very big problem. Directory ~/myfunctions doesn't make
sense. Below is a patch that addresses this. Maybe the code looks good?
diff --git a/Src/builtin.c b/Src/builtin.c
index 394d206..16784d7 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3032,8 +3032,44 @@ add_autoload_function(Shfunc shf, char *funcname)
dircache_set(&shf->filename, NULL);
dircache_set(&shf->filename, dir);
shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
shfunctab->addnode(shfunctab, ztrdup(nam), shf);
} else {
+ Shfunc shf2;
+ Funcstack fs;
+ const char *calling_f = NULL;
+ char buf[PATH_MAX+1];
+
+ /* Find calling function */
+ for (fs = funcstack; fs; fs = fs->prev) {
+ if (fs->tp == FS_FUNC && fs->name && (!shf->node.nam || 0
!= strcmp(fs->name,shf->node.nam))) {
+ calling_f = fs->name;
+ break;
+ }
+ }
+
+ /* Get its directory */
+ if (calling_f) {
+ /* Should contain load directory, and be loaded via
absolute path */
+ if ((shf2 = (Shfunc) shfunctab->getnode2(shfunctab,
calling_f))
+ && (shf2->node.flags & PM_LOADDIR) &&
(shf2->node.flags & PM_ABSPATH_USED)
+ && shf2->filename)
+ {
+ if (strlen(shf2->filename) + strlen(funcname) + 1 <
PATH_MAX)
+ {
+ sprintf(buf, "%s/%s", shf2->filename, funcname);
+ /* Set containing directory if the function file
+ * exists (do normal FPATH processing otherwise) */
+ if (!access(buf, R_OK)) {
+ dircache_set(&shf->filename, NULL);
+ dircache_set(&shf->filename, shf2->filename);
+ shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
+ }
+ }
+ }
+ }
+
shfunctab->addnode(shfunctab, ztrdup(funcname), shf);
}
}
diff --git a/Src/zsh.h b/Src/zsh.h
index c387414..f2c2790 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1807,6 +1807,7 @@ struct tieddata {
#define PM_READONLY (1<<10) /* readonly
*/
#define PM_TAGGED (1<<11) /* tagged
*/
#define PM_EXPORTED (1<<12) /* exported
*/
+#define PM_ABSPATH_USED (1<<12) /* (function): loaded using absolute
path */
/* The following are the same since they *
* both represent -U option to typeset */
--
Sebastian Gniazdowski
psprint2@fastmail.com
[-- Attachment #2: autoload_patch.diff --]
[-- Type: text/plain, Size: 2448 bytes --]
diff --git a/Src/builtin.c b/Src/builtin.c
index 394d206..16784d7 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3032,8 +3032,44 @@ add_autoload_function(Shfunc shf, char *funcname)
dircache_set(&shf->filename, NULL);
dircache_set(&shf->filename, dir);
shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
shfunctab->addnode(shfunctab, ztrdup(nam), shf);
} else {
+ Shfunc shf2;
+ Funcstack fs;
+ const char *calling_f = NULL;
+ char buf[PATH_MAX+1];
+
+ /* Find calling function */
+ for (fs = funcstack; fs; fs = fs->prev) {
+ if (fs->tp == FS_FUNC && fs->name && (!shf->node.nam || 0 != strcmp(fs->name,shf->node.nam))) {
+ calling_f = fs->name;
+ break;
+ }
+ }
+
+ /* Get its directory */
+ if (calling_f) {
+ /* Should contain load directory, and be loaded via absolute path */
+ if ((shf2 = (Shfunc) shfunctab->getnode2(shfunctab, calling_f))
+ && (shf2->node.flags & PM_LOADDIR) && (shf2->node.flags & PM_ABSPATH_USED)
+ && shf2->filename)
+ {
+ if (strlen(shf2->filename) + strlen(funcname) + 1 < PATH_MAX)
+ {
+ sprintf(buf, "%s/%s", shf2->filename, funcname);
+ /* Set containing directory if the function file
+ * exists (do normal FPATH processing otherwise) */
+ if (!access(buf, R_OK)) {
+ dircache_set(&shf->filename, NULL);
+ dircache_set(&shf->filename, shf2->filename);
+ shf->node.flags |= PM_LOADDIR;
+ shf->node.flags |= PM_ABSPATH_USED;
+ }
+ }
+ }
+ }
+
shfunctab->addnode(shfunctab, ztrdup(funcname), shf);
}
}
diff --git a/Src/zsh.h b/Src/zsh.h
index c387414..f2c2790 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1807,6 +1807,7 @@ struct tieddata {
#define PM_READONLY (1<<10) /* readonly */
#define PM_TAGGED (1<<11) /* tagged */
#define PM_EXPORTED (1<<12) /* exported */
+#define PM_ABSPATH_USED (1<<12) /* (function): loaded using absolute path */
/* The following are the same since they *
* both represent -U option to typeset */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Autoload and absolute paths.. Maybe after all
2017-02-13 11:56 ` [PATCH] Autoload and absolute paths.. Maybe after all Sebastian Gniazdowski
@ 2017-02-13 15:19 ` Peter Stephenson
2017-02-13 16:00 ` Sebastian Gniazdowski
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2017-02-13 15:19 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: zsh-workers
On Mon, 13 Feb 2017 03:56:28 -0800
Sebastian Gniazdowski <psprint2@fastmail.com> wrote:
> Hello,
> following doesn't work:
>
> # mkdir ~/myfunctions
> # mv /usr/local/share/zsh/5.3.1-dev-0/functions/calendar* ~/myfunctions
> # autoload ~/myfunctions/calendar
> # calendar
> calendar:36: calendar_scandate: function definition file not found
>
> called this a very big problem. Directory ~/myfunctions doesn't make
> sense. Below is a patch that addresses this. Maybe the code looks good?
It's a fairly localised change, and all the existing tests still pass,
so I don't see a problem with it. There might be funny edge cases but
I don't propose to worry until they turn up.
pws
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 0a9021c..bdd1ad1 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -159,7 +159,10 @@ load from the file given (searching as usual for dump files in the given
location). The name of the function is the basename (non-directory
part) of the file. It is normally an error if the function is not found
in the given location; however, if the option tt(-d) is given, searching
-for the function defaults to tt($fpath).
+for the function defaults to tt($fpath). If a function is loaded by
+absolute path, any functions loaded from it that are marked for
+tt(autoload) without an absolute path have the load path of the parent
+function temporarily prepended to tt($fpath).
If the option tt(-r) or tt(-R) is given, the function is searched for
immediately and the location is recorded internally for use when the
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Autoload and absolute paths.. Maybe after all
2017-02-13 15:19 ` Peter Stephenson
@ 2017-02-13 16:00 ` Sebastian Gniazdowski
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2017-02-13 16:00 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
On Mon, Feb 13, 2017, at 07:19 AM, Peter Stephenson wrote:
> It's a fairly localised change, and all the existing tests still pass,
> so I don't see a problem with it. There might be funny edge cases but
> I don't propose to worry until they turn up.
>
> pws
Yeah, it uses existing control flow by preparing data in structure that
is examined by the control flow. Was condemned to that when was
replacing functions via module ;) Thanks.
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-13 16:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20170213115826epcas3p2b4e5f1c47646bcf67aeafef97d5d8acb@epcas3p2.samsung.com>
2017-02-13 11:56 ` [PATCH] Autoload and absolute paths.. Maybe after all Sebastian Gniazdowski
2017-02-13 15:19 ` Peter Stephenson
2017-02-13 16:00 ` Sebastian Gniazdowski
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).