public override void AddNoLock(ref DictionaryStorage storage, object key, object value) {            
     // add always needs to check...
     string strKey = key as string;
     if (strKey != null) {
         switch (strKey) {
             case "exc_type":
                 _setValues |= ExceptionStateFlags.Type;
                 _removedValues &= ~ExceptionStateFlags.Type;
                 _excType = value;
                 break;
             case "exc_value":
                 _setValues |= ExceptionStateFlags.Value;
                 _removedValues &= ~ExceptionStateFlags.Value;
                 _excValue = value;
                 break;
             case "exc_traceback":
                 _setValues |= ExceptionStateFlags.Traceback;
                 _removedValues &= ~ExceptionStateFlags.Traceback;
                 _excTraceback = value;
                 break;
         }
     }
     
     base.AddNoLock(ref storage, key, value);
 }
Exemplo n.º 2
0
        public override void AddNoLock(ref DictionaryStorage storage, object key, object value)
        {
            // add always needs to check...
            string strKey = key as string;

            if (strKey != null)
            {
                switch (strKey)
                {
                case "exc_type":
                    _setValues     |= ExceptionStateFlags.Type;
                    _removedValues &= ~ExceptionStateFlags.Type;
                    _excType        = value;
                    break;

                case "exc_value":
                    _setValues     |= ExceptionStateFlags.Value;
                    _removedValues &= ~ExceptionStateFlags.Value;
                    _excValue       = value;
                    break;

                case "exc_traceback":
                    _setValues     |= ExceptionStateFlags.Traceback;
                    _removedValues &= ~ExceptionStateFlags.Traceback;
                    _excTraceback   = value;
                    break;
                }
            }

            base.AddNoLock(ref storage, key, value);
        }
        public override bool Remove(ref DictionaryStorage storage, object key) {
            // check the strKey only if we have some exception info set
            ExceptionState exState = _exceptionState;
            if (exState != null || _setValues != 0) {
                string strKey = key as string;
                if (strKey != null) {
                    switch (strKey) {
                        case "exc_type":
                            lock (this) {
                                _excType = null;
                                _setValues &= ~ExceptionStateFlags.Type;
                                _removedValues |= ExceptionStateFlags.Type;
                            }
                            break;
                        case "exc_value":
                            lock (this) {
                                _excValue = null;
                                _setValues &= ~ExceptionStateFlags.Value;
                                _removedValues |= ExceptionStateFlags.Value;
                            }
                            break;
                        case "exc_traceback":
                            lock (this) {
                                _excTraceback = null;
                                _setValues &= ~ExceptionStateFlags.Traceback;
                                _removedValues |= ExceptionStateFlags.Traceback;
                            }
                            break;
                    }
                }
            }

            return base.Remove(ref storage, key);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds items from this dictionary into the other dictionary
        /// </summary>
        public virtual void CopyTo(DictionaryStorage/*!*/ into) {
            Debug.Assert(into != null);

            foreach (KeyValuePair<object, object> kvp in GetItems()) {
                into.Add(kvp.Key, kvp.Value);
            }
        }
        public override bool Remove(ref DictionaryStorage storage, object key) {
            if (_hidden.Contains(key)) {
                return false;
            }

            return _data.Remove(key);
        }
Exemplo n.º 6
0
        public override bool Remove(ref DictionaryStorage storage, object key) {
            if (key is string) {
                return TryRemoveExtraValue((string)key) ?? _storage.Remove(key);

            }
            return _storage.Remove(key);
        }
Exemplo n.º 7
0
        public DictionaryStorage CopyTo(DictionaryStorage into)
        {
            Debug.Assert(into != null);

            if (_buckets != null)
            {
                using (new OrderedLocker(this, into)) {
                    CommonDictionaryStorage commonInto = into as CommonDictionaryStorage;
                    if (commonInto != null)
                    {
                        CommonCopyTo(commonInto);
                    }
                    else
                    {
                        UncommonCopyTo(ref into);
                    }
                }
            }

            var nullValue = _nullValue;

            if (nullValue != null)
            {
                into.Add(ref into, null, nullValue.Value);
            }
            return(into);
        }
Exemplo n.º 8
0
 public override void Clear(ref DictionaryStorage storage)
 {
     foreach (var item in GetItems())
     {
         Remove(item.Key);
     }
 }
Exemplo n.º 9
0
 internal DictionaryKeyEnumerator(DictionaryStorage dict)
 {
     _dict = dict;
     _size = dict.Count;
     _keys = dict.GetKeys().GetEnumerator();
     _pos  = -1;
 }
Exemplo n.º 10
0
 public override bool Remove(ref DictionaryStorage storage, object key)
 {
     if (key is string)
     {
         return(TryRemoveExtraValue((string)key) ?? _storage.Remove(key));
     }
     return(_storage.Remove(key));
 }
 public override bool Remove(ref DictionaryStorage storage, object key) {
     try {
         PythonContext.GetContext(_context).DelIndex(_backing, key);
         return true;
     } catch (KeyNotFoundException) {
         return false;
     }
 }
Exemplo n.º 12
0
 public override void AddNoLock(ref DictionaryStorage storage, object key, object value)
 {
     if (key is string && TrySetExtraValue((string)key, value))
     {
         return;
     }
     _storage.AddNoLock(ref storage, key, value);
 }
Exemplo n.º 13
0
 public override bool Remove(ref DictionaryStorage storage, object key) {
     string strKey = key as string;
     if (strKey != null) {
         return _data.Remove(SymbolTable.StringToId(strKey));
     } else {
         return _data.RemoveObjectKey(key);
     }
 }
Exemplo n.º 14
0
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     string strKey = key as string;
     if (strKey != null) {
         _data[SymbolTable.StringToId(strKey)] = value;
     } else {
         _data.AddObjectKey(key, value);
     }
 }
Exemplo n.º 15
0
 public override void Clear(ref DictionaryStorage storage)
 {
     _storage.Clear(ref storage);
     foreach (var item in GetExtraItems())
     {
         TryRemoveExtraValue(item.Key);
     }
 }
Exemplo n.º 16
0
        public override void Clear(ref DictionaryStorage storage)
        {
            ICollection <object> keys = _data.Keys;

            foreach (object key in keys)
            {
                _data.RemoveObjectKey(key);
            }
        }
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            if (_hidden.Contains(key))
            {
                return(false);
            }

            return(_data.Remove(key));
        }
 public override bool Remove(ref DictionaryStorage storage, object key)
 {
     try {
         PythonContext.GetContext(_context).DelIndex(_backing, key);
         return(true);
     } catch (KeyNotFoundException) {
         return(false);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Adds items from this dictionary into the other dictionary
        /// </summary>
        public virtual void CopyTo(ref DictionaryStorage /*!*/ into)
        {
            Debug.Assert(into != null);

            foreach (KeyValuePair <object, object> kvp in GetItems())
            {
                into.Add(ref into, kvp.Key, kvp.Value);
            }
        }
Exemplo n.º 20
0
        public virtual bool TryRemoveValue(ref DictionaryStorage storage, object key, out object value)
        {
            if (TryGetValue(key, out value))
            {
                return(Remove(ref storage, key));
            }

            return(false);
        }
Exemplo n.º 21
0
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     string strKey = key as string;
     if (strKey != null) {
         PythonOps.ScopeSetMember(_context.SharedContext, _scope, strKey, value);
     } else {
         PythonScopeExtension ext = (PythonScopeExtension)_context.EnsureScopeExtension(_scope);
         ext.EnsureObjectKeys().Add(key, value);
     }
 }
Exemplo n.º 22
0
 public override void Clear(ref DictionaryStorage storage)
 {
     lock (this) {
         _exceptionState = null;
         _setValues      = 0;
         _removedValues  = 0;
         _excTraceback   = _excType = _excValue = null;
         base.Clear(ref storage);
     }
 }
Exemplo n.º 23
0
        internal PythonDictionary(IDictionary dict)
        {
            var storage = new CommonDictionaryStorage();

            foreach (DictionaryEntry de in dict)
            {
                storage.AddNoLock(de.Key, de.Value);
            }
            _storage = storage;
        }
 public override bool Remove(ref DictionaryStorage storage, object key) {
     string strkey = key as string;
     if (strkey != null) {
         if (strkey == "__import__") {
             _import = null;
         }
         _change(this, new ModuleChangeEventArgs(strkey, ModuleChangeType.Delete));
     }
     return base.Remove(ref storage, key);
 }
Exemplo n.º 25
0
 internal PythonDictionary(IDictionary dict)
 {
     _storage = new CommonDictionaryStorage();
     lock (_storage) {
         foreach (DictionaryEntry de in dict)
         {
             _storage.AddNoLock(de.Key, de.Value);
         }
     }
 }
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     string strkey = key as string;
     if (strkey != null) {
         if (strkey == "__import__") {
             _import = value;
         }
         _change(this, new ModuleChangeEventArgs(strkey, ModuleChangeType.Set, value));
     }
     base.Add(ref storage, key, value);
 }
Exemplo n.º 27
0
 private void UncommonCopyTo(ref DictionaryStorage into)
 {
     for (int i = 0; i < _buckets.Length; i++)
     {
         Bucket curBucket = _buckets[i];
         if (curBucket.Key != null && curBucket.Key != _removed)
         {
             into.AddNoLock(ref into, curBucket.Key, curBucket.Value);
         }
     }
 }
Exemplo n.º 28
0
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     lock (this) {
         string strKey = key as string;
         if (strKey != null) {
             _dict[strKey] = value;
         } else {
             EnsureObjectDictionary();
             _objDict[BaseSymbolDictionary.NullToObj(key)] = value;
         }
     }
 }
Exemplo n.º 29
0
        public override void Clear(ref DictionaryStorage storage) {
            lock (this) {
                if (storage == this) {
                    storage = EmptyDictionaryStorage.Instance;
                    return;
                }
            }

            // race, try again
            storage.Clear(ref storage);
        }
Exemplo n.º 30
0
 public override void Add(ref DictionaryStorage storage, object key, object value)
 {
     if (key is string strkey)
     {
         if (strkey == "__import__")
         {
             _import = value;
         }
         _change(this, new ModuleChangeEventArgs(strkey, ModuleChangeType.Set, value));
     }
     base.Add(ref storage, key, value);
 }
Exemplo n.º 31
0
 public override void Add(ref DictionaryStorage storage, object key, object value)
 {
     if (key is string strKey)
     {
         PythonOps.ScopeSetMember(_context.SharedContext, _scope, strKey, value);
     }
     else
     {
         PythonScopeExtension ext = (PythonScopeExtension)_context.EnsureScopeExtension(_scope);
         ext.EnsureObjectKeys().Add(key, value);
     }
 }
Exemplo n.º 32
0
 public override bool Remove(ref DictionaryStorage storage, object key)
 {
     if (key is string strkey)
     {
         if (strkey == "__import__")
         {
             _import = null;
         }
         _change(this, new ModuleChangeEventArgs(strkey, ModuleChangeType.Delete));
     }
     return(base.Remove(ref storage, key));
 }
Exemplo n.º 33
0
        public override void Add(ref DictionaryStorage storage, object key, object value)
        {
            _storage.Add(key, value);

            string s1 = key as string;
            string s2 = value as string;

            if (s1 != null && s2 != null)
            {
                Environment.SetEnvironmentVariable(s1, s2);
            }
        }
Exemplo n.º 34
0
 internal DictionaryItemEnumerator(DictionaryStorage dict)
 {
     _dict   = dict;
     _keys   = new List <object>(dict.Count);
     _values = new List <object>(dict.Count);
     foreach (KeyValuePair <object, object> kvp in dict.GetItems())
     {
         _keys.Add(kvp.Key);
         _values.Add(kvp.Value);
     }
     _size = _values.Count;
     _pos  = -1;
 }
Exemplo n.º 35
0
        public override void Clear(ref DictionaryStorage storage)
        {
            foreach (var x in GetItems())
            {
                string key = x.Key as string;
                if (key != null)
                {
                    Environment.SetEnvironmentVariable(key, string.Empty);
                }
            }

            _storage.Clear(ref storage);
        }
Exemplo n.º 36
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            bool res = _storage.Remove(key);

            string s = key as string;

            if (s != null)
            {
                Environment.SetEnvironmentVariable(s, string.Empty);
            }

            return(res);
        }
Exemplo n.º 37
0
        private void UncommonCopyTo(DictionaryStorage into)
        {
            for (int i = 0; i < _buckets.Length; i++)
            {
                Bucket curBucket = _buckets[i];
                while (curBucket != null)
                {
                    into.AddNoLock(curBucket.Key, curBucket.Value);

                    curBucket = curBucket.Next;
                }
            }
        }
Exemplo n.º 38
0
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     lock (this) {
         if (storage == this) {
             CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
             newStorage.AddNoLock(key, value);
             storage = newStorage;
             return;
         }
     }
     
     // race, try again...
     storage.Add(ref storage, key, value);
 }
Exemplo n.º 39
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            string strKey = key as string;

            if (strKey != null)
            {
                return(_data.Remove(SymbolTable.StringToId(strKey)));
            }
            else
            {
                return(_data.RemoveObjectKey(key));
            }
        }
Exemplo n.º 40
0
        internal DictionaryValueEnumerator(DictionaryStorage dict)
        {
            _dict   = dict;
            _size   = dict.Count;
            _values = new object[_size];
            int i = 0;

            foreach (KeyValuePair <object, object> kvp in dict.GetItems())
            {
                _values[i++] = kvp.Value;
            }
            _pos = -1;
        }
Exemplo n.º 41
0
        public override void Clear(ref DictionaryStorage storage)
        {
            lock (this) {
                if (storage == this)
                {
                    storage = EmptyDictionaryStorage.Instance;
                    return;
                }
            }

            // race, try again
            storage.Clear(ref storage);
        }
Exemplo n.º 42
0
        public override void Add(ref DictionaryStorage storage, object key, object value)
        {
            string strKey = key as string;

            if (strKey != null)
            {
                _data[SymbolTable.StringToId(strKey)] = value;
            }
            else
            {
                _data.AddObjectKey(key, value);
            }
        }
Exemplo n.º 43
0
        public override bool Remove(ref DictionaryStorage storage, object key) {
            lock (this) {
                string strKey = key as string;
                if (strKey != null) {
                    return _dict.Remove(strKey);
                }

                if (_objDict != null) {
                    return _objDict.Remove(BaseSymbolDictionary.NullToObj(key));
                }

                return false;
            }
        }
Exemplo n.º 44
0
        public override void Add(ref DictionaryStorage storage, object key, object value)
        {
            lock (this) {
                if (storage == this)
                {
                    CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
                    newStorage.AddNoLock(key, value);
                    storage = newStorage;
                    return;
                }
            }

            // race, try again...
            storage.Add(ref storage, key, value);
        }
        public override bool Remove(ref DictionaryStorage storage, object key) {
            string strKey = key as string;
            if (strKey == null) {
                return base.Remove(ref storage, key);
            }

            bool found = base.Remove(ref storage, key);
            object value;
            if (TryGetLazyValue(strKey, out value)) {
                // hide the deleted value
                base.Add(key, Uninitialized.Instance);
                found = true;
            }

            return found;
        }
Exemplo n.º 46
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            if (!(key is string strKey))
            {
                return(base.Remove(ref storage, key));
            }

            bool found = base.Remove(ref storage, key);

            if (TryGetLazyValue(strKey, out _))
            {
                // hide the deleted value
                Add(key, Uninitialized.Instance);
                found = true;
            }

            return(found);
        }
Exemplo n.º 47
0
        public override bool Remove(ref DictionaryStorage storage, object key) {
            if (_storage.Contains(key)) {
                lock (this) {
                    if (storage == this) {
                        var newStore = new CommonDictionaryStorage();
                        _storage.CopyTo(newStore);
                        newStore.Remove(key);
                        storage = newStore;
                        return true;
                    }
                }

                // race, try again
                return storage.Remove(ref storage, key);
            }
            
            return false;
        }
Exemplo n.º 48
0
        private void UncommonCopyTo(DictionaryStorage into) {
            for (int i = 0; i < _buckets.Length; i++) {
                Bucket curBucket = _buckets[i];
                while (curBucket != null) {
                    into.AddNoLock(curBucket.Key, curBucket.Value);

                    curBucket = curBucket.Next;
                }
            }
        }
Exemplo n.º 49
0
        public override void CopyTo(DictionaryStorage/*!*/ into) {
            Debug.Assert(into != null);

            if (_buckets != null) {
                using (new OrderedLocker(this, into)) {
                    CommonDictionaryStorage commonInto = into as CommonDictionaryStorage;
                    if (commonInto != null) {
                        CommonCopyTo(commonInto);
                    } else {
                        UncommonCopyTo(into);
                    }
                }
            }
        }
 public override void AddNoLock(ref DictionaryStorage storage, object key, object value) {
     if (key is string && TrySetExtraValue((string)key, value)) {
         return;
     }
     _storage.AddNoLock(ref storage, key, value);
 }
Exemplo n.º 51
0
 public override void Clear(ref DictionaryStorage storage) {
     GetStorage().Clear(ref storage);
 }
Exemplo n.º 52
0
 public override void Clear(ref DictionaryStorage storage) {
     foreach (var item in GetItems()) {
         Remove(item.Key);
     }
 }
Exemplo n.º 53
0
 public override bool Remove(ref DictionaryStorage storage, object key) {
     return Remove(key);
 }
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     AddNoLock(ref storage, key, value);
 }
 public override void Clear(ref DictionaryStorage storage) {
     _storage.Clear(ref storage);
     foreach (var item in GetExtraItems()) {
         TryRemoveExtraValue(item.Key);
     }
 }
Exemplo n.º 56
0
 public override void Add(ref DictionaryStorage storage, object key, object value) {
     GetStorage().Add(key, value);
 }
Exemplo n.º 57
0
 public override bool Remove(ref DictionaryStorage storage, object key) {
     return GetStorage().Remove(ref storage, key);
 }
Exemplo n.º 58
0
 public override void Clear(ref DictionaryStorage storage) {
     lock (this) {
         _dict.Clear();
         if (_objDict != null) {
             _objDict.Clear();
         }
     }
 }
 public override void Clear(ref DictionaryStorage storage) {
     _data = new Dictionary<object, object>();
     _hidden.Clear();
 }
        public override void AddNoLock(ref DictionaryStorage storage, object key, object value) {
            _hidden.Remove(key);

            _data[key] = value;
        }