zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH and comments Re: PATCH: autoloaded parameters
@ 1999-04-30  9:09 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-04-30  9:09 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> First comment:  This new code does not link with --disable-dynamic.

Grrr, Sven, Wake Up.

> Patch below.

Thanks.

> On Apr 28, 11:51am, Sven Wischnowsky wrote:
> } Subject: PATCH: autoloaded parameters
> }
> } Autoloaded parameters are stored in it like normal parameters, but
> } with a new flag (PM_AUTOLOAD). Then I changed the getnode-functions of 
> } paramtab to use a new function getparamnode() which calls
> } gethashnode2() and then checks if the Param returned has the
> } PM_AUTOLOAD flag set. If it has, the module is loaded.
> [...]
> }   - To avoid having a `local' with the name of a parameter that will
> }     be autoloaded trigger the loading of the module, I had to change
> }     calls like `paramtab->getnode()' to `gethashnode2(paramtab,...)'
> 
> Hrm.  Is this really the only place to hook this in?  Seems like doing
> it there means that you load the module as soon as anybody references
> the parameter, even if all that's done is to test whether it's set.
> 
> Heck, it means the module gets loaded if "unset ..." is used on the
> parameter!

No, it doesn't. Because I've also hooked it into createparam().

But, yes, parameters are autoloaded when tested for settedness (err,
well, you know what I mean). Somehow I liked that... To change this,
we would, as you know, have to fiddle some more in paramsubst().

> And what happens in createparamtable() if there's an environment variable
> with the same name as one of the autoloaded parameters?  Or is it not
> possible to have an autoloaded parameter at that point?

Well, setupvals()->createparamtable() is called before
init_bltinmods() registers autoloaded modules. So, currently there
shouldn't be a problem.

> }   - For now, I made `typeset' without arguments not print the
> }     autoloaded parameters because we have virtually no information
> }     about them as long as the module is not loaded. But since `which'
> }     reports builtins even when their module isn't loaded yet, we might
> }     want to change this. (What exactly should it print then?)
> 
> It should probably show the type as "undefined" the same as is done for
> autoloaded functions.

Hm, yes, sounds reasonable.

Bye
 Sven

--- os/params.c	Thu Apr 29 11:57:27 1999
+++ Src/params.c	Fri Apr 30 11:07:42 1999
@@ -2717,11 +2717,13 @@
     Param p = (Param) hn;
     char *t, **u;
 
-    if (p->flags & (PM_UNSET | PM_AUTOLOAD))
+    if (p->flags & PM_UNSET)
 	return;
 
     /* Print the attributes of the parameter */
     if (printflags & PRINT_TYPE) {
+	if (p->flags & PM_AUTOLOAD)
+	    printf("undefined ");
 	if (p->flags & PM_INTEGER)
 	    printf("integer ");
 	else if (p->flags & PM_ARRAY)
@@ -2755,6 +2757,11 @@
     }
 
     quotedzputs(p->nam, stdout);
+
+    if (p->flags & PM_AUTOLOAD) {
+	putchar('\n');
+	return;
+    }
     if (printflags & PRINT_KV_PAIR)
 	putchar(' ');
     else

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH and comments Re: PATCH: autoloaded parameters
  1999-04-28  9:51 Sven Wischnowsky
@ 1999-04-30  6:23 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-04-30  6:23 UTC (permalink / raw)
  To: zsh-workers

First comment:  This new code does not link with --disable-dynamic.

params.o: In function `getparamnode':
/usr/src/local/zsh/zsh-3.1.5-build/Src/../../zsh-3.1.5/Src/params.c:291:
undefined reference to `load_module'

Patch below.

On Apr 28, 11:51am, Sven Wischnowsky wrote:
} Subject: PATCH: autoloaded parameters
}
} Autoloaded parameters are stored in it like normal parameters, but
} with a new flag (PM_AUTOLOAD). Then I changed the getnode-functions of 
} paramtab to use a new function getparamnode() which calls
} gethashnode2() and then checks if the Param returned has the
} PM_AUTOLOAD flag set. If it has, the module is loaded.
[...]
}   - To avoid having a `local' with the name of a parameter that will
}     be autoloaded trigger the loading of the module, I had to change
}     calls like `paramtab->getnode()' to `gethashnode2(paramtab,...)'

Hrm.  Is this really the only place to hook this in?  Seems like doing
it there means that you load the module as soon as anybody references
the parameter, even if all that's done is to test whether it's set.

Heck, it means the module gets loaded if "unset ..." is used on the
parameter!

And what happens in createparamtable() if there's an environment variable
with the same name as one of the autoloaded parameters?  Or is it not
possible to have an autoloaded parameter at that point?

(If it's not, perhaps it should be.  See another message, to follow.)

}   - For now, I made `typeset' without arguments not print the
}     autoloaded parameters because we have virtually no information
}     about them as long as the module is not loaded. But since `which'
}     reports builtins even when their module isn't loaded yet, we might
}     want to change this. (What exactly should it print then?)

It should probably show the type as "undefined" the same as is done for
autoloaded functions.

Here's the patch.

Index: Src/params.c
===================================================================
--- params.c	1999/04/30 05:53:26	1.34
+++ params.c	1999/04/30 06:08:13
@@ -257,6 +257,10 @@
 /**/
 HashTable paramtab, realparamtab;
 
+#ifndef DYNAMIC
+#define getparamnode gethashnode2
+#endif /* DYNAMIC */
+
 /**/
 HashTable
 newparamtable(int size, char const *name)
@@ -278,6 +282,7 @@
     return ht;
 }
 
+#ifdef DYNAMIC
 /**/
 static HashNode
 getparamnode(HashTable ht, char *nam)
@@ -294,6 +299,7 @@
     }
     return hn;
 }
+#endif /* DYNAMIC */
 
 /* Copy a parameter hash table */
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-04-30  9:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-30  9:09 PATCH and comments Re: PATCH: autoloaded parameters Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-04-28  9:51 Sven Wischnowsky
1999-04-30  6:23 ` PATCH and comments " Bart Schaefer

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).