[IronPython] Updating globals()
dinov at exchange.microsoft.com
Wed Mar 29 19:08:24 CEST 2006
The statics actually come from all of the global variables referred to in the module. So for example in a case like:
from sys import *
min would become a static variable. When the import occurs we update the modules dictionary which will recognize that min is an extra key and we'll update the static variable instead of updating the underlying dictionary. Which brings me to your second question - there is an underlying dictionary that will be lazily created if a user tries to use keys that aren't otherwise present.
If the user deletes an extra key we will store a value of Uninitialize(attrName) for the value. We also check to see if the value is Uninitialized before handing it back to the user (and say it doesn't exist if it is Uninitialized). Uninitialized is a sealed class in the IronPython runtime and it's also used in other cases (for example when you delete a local we assign Uninitialized to it). And we do also check for Uninitialized after the ldsfld as well.
If you want to test it out and see if you can hit any corner cases that don't work that'd be great. I don't think the update should really block you too much as it's just one API that isn't available (everything else should just work).
Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of J. Merrill
Sent: Wednesday, March 29, 2006 8:21 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Updating globals()
Not all attributes can be stored as static variables, or you couldn't add new ones at runtime. So there must also be a dictionary in the CustomDict subclass -- right? Are the only attributes that are made into statics the "all modules have these" names? (That is, the names I would find if I create a new Module object and examine it?) Or does make the names assigned in the __init__ method static as well?
What happens if one of the static-var-stored dictionary entries gets removed from one of these CustomDict subclasses? Is there a value that can be stored in the corresponding static variable that means "do a name lookup within superclasses to find this when you get this value (and raise a NameError if it's not found)" so that removing an entry will work correctly? (If retrieving one of the static-var-stored values is really just ldsfld / stsfld, with no check for whether the value returned means "there's no entry here", can things work right?)
Maybe I should do some testing -- but it might not be fruitful until the just-discovered bug is fixed.
At 06:09 PM 3/28/2006, Dino Viehland wrote (in part)
>When you are running from a module we generate a module type which is a subclass of CustomDict. That CustomDict stores the field values as static variables which allows quicker access than requiring a dictionary lookup each time through (in particular the module gets to just do a ldsfld / stsfld in IL to get the value, but setting the value from outside of the module is still relatively expensive).
J. Merrill / Analytical Software Corp
users mailing list
users at lists.ironpython.com
More information about the Ironpython-users