Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: autoload with explicit path



Peter Stephenson wrote on Thu, Jan 12, 2017 at 12:56:02 +0000:
> The problem is the overloading of filename in struct shfunc.  If the
> function was alrady loaded, which is the case if it contains an
> explicit autoload -X (rather than one generated internally by looking
> at the flags for an undefined function), then the filename indicates the
> location of the source for the function.  If this came from a file with
> an absolute path, and there was no explicit directory path in the
> autoload -X statement, the file path was erroneously taken as a
> directory for loading.
> 
> This adds an explicit flag to indicate filename is being used for that
> purpose, unsetting it when the filename is set to the file's path.

I would suggest using two separate struct members, rather than one whose
semantics depend on a flag.  It'd be too easy to forget to check the
flag in some (existing or future) location.

E.g.,

struct shfunc {
    char *filename1;             /* Name of file located in */
    char *filename2;             /* Name of file to autoload from */
};

We could also put these two members in a union{} if they are mutually
exclusive (if at least one of them is NULL at all times).



Messages sorted by: Reverse Date, Date, Thread, Author